附录A:文法摘要
2018-06-16 15:50 更新
词法
SourceCharacter :: 任意 Unicode 编码单元
InputElementDiv :: WhiteSpace LineTerminator Comment Token DivPunctuator
InputElementRegExp :: WhiteSpace LineTerminator Comment Token RegularExpressionLiteral
WhiteSpace :: <TAB> <VT> <FF> <SP> <#x0a> <BOM> <USP>
LineTerminator :: <LF> <CR> <LS> <PS>
LineTerminatorSequence :: <LF> <CR> [lookahead ∉ ] <LS> <PS> <CR> <LF>
Comment :: MultiLineComment SingleLineComment
MultiLineComment :: /* MultiLineCommentCharsopt */
MultiLineCommentChars :: MultiLineNotAsteriskChar MultiLineCommentCharsopt * PostAsteriskCommentCharsopt
PostAsteriskCommentChars :: MultiLineNotForwardSlashorAsteriskChar MultiLineCommentCharsopt * PostAsteriskCommentCharsopt
MultiLineNotAsteriskChar :: SourceCharacter 但非 星号 *
MultiLineNotForwardSlashorAsteriskChar :: SourceCharacter 但非 正斜杠 / 或 星号 *
SingleLineComment :: // SingleLineCommentCharsopt
SingleLineCommentChars :: SingleLineCommentChar SingleLineCommentCharsopt
SingleLineCommentChar :: SourceCharacter 但非 LineTerminator
Token :: IdentifierName Punctuator NumericLiteral StringLiteral
Identifier :: IdentifierName 但非 ReservedWord
IdentifierName :: IdentifierStart IdentifierName IdentifierPart
IdentifierStart :: UnicodeLetter $ _ \ UnicodeEscapeSequence
IdentifierPart :: IdentifierStart UnicodeCombiningMark UnicodeDigit UnicodeConnectorPunctuation <ZWNJ> <ZWJ>
UnicodeLetter 在以下 Unicode 分类中的字符:“Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, 或 “Letter number (Nl)”.
UnicodeCombiningMark 在以下 Unicode 分类中的字符:“Non-spacing mark (Mn)” 或 “Combining spacing mark (Mc)”
UnicodeDigit 在以下 Unicode 分类中的字符:“Decimal number (Nd)”
UnicodeConnectorPunctuation 在以下 Unicode 分类中的字符:“Connector punctuation (Pc)”
ReservedWord :: Keyword FutureReservedWord NullLiteral BooleanLiteral
Keyword :: 以下之一 break do instanceof typeof case else new var catch finally return void continue for switch while debugger function this with default if throw delete in try
FutureReservedWord :: 以下之一 class enum extends super const export import
或在严格模式下以下之一 implements let private public interface package protected static yield
Punctuator :: 以下之一 { } ( ) [ ] . ; , < > <= >= == != === !== + - * % ++ -- << >> >>> & | ^ ! ~ && || ? : = += -= *= %= <<= >>= >>>= &= |= ^=
DivPunctuator :: 以下之一 / /=
Literal :: NullLiteral BooleanLiteral NumericLiteral StringLiteral RegularExpressionLiteral
NullLiteral :: null
BooleanLiteral :: true false
NumericLiteral :: DecimalLiteral HexIntegerLiteral
DecimalLiteral :: DecimalIntegerLiteral . DecimalDigitsopt ExponentPartopt . DecimalDigits ExponentPartopt DecimalIntegerLiteral ExponentPartopt
DecimalIntegerLiteral :: 0 NonZeroDigit DecimalDigitsopt
DecimalDigits :: DecimalDigit DecimalDigits DecimalDigit
DecimalDigit :: 以下之一 0 1 2 3 4 5 6 7 8 9
NonZeroDigit:: 以下之一 1 2 3 4 5 6 7 8 9
ExponentPart:: ExponentIndicator SignedInteger
ExponentIndicator :: 以下之一 e E
SignedInteger :: DecimalDigits + DecimalDigits - DecimalDigits
HexIntegerLiteral :: 0x HexDigit 0X HexDigit HexIntegerLiteral HexDigit
HexDigit :: 以下之一 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
StringLiteral :: "DoubleStringCharactersopt " 'SingleStringCharactersopt '
DoubleStringCharacters :: DoubleStringCharacter DoubleStringCharactersopt
SingleStringCharacters :: SingleStringCharacter SingleStringCharactersopt
DoubleStringCharacter :: SourceCharacter 但非 double-quote " 或 backslash \ 或 LineTerminator \ EscapeSequence LineContinuation
SingleStringCharacter :: SourceCharacter 但非 single-quote ' 或 backslash \ 或 LineTerminator \ EscapeSequence LineContinuation
LineContinuation :: \ LineTerminatorSequence
EscapeSequence :: CharacterEscapeSequence 0 [lookahead ∉ DecimalDigit] HexEscapeSequence UnicodeEscapeSequence
CharacterEscapeSequence :: SingleEscapeCharacter NonEscapeCharacter
SingleEscapeCharacter :: 以下之一 ' " \ b f n r t v
NonEscapeCharacter :: SourceCharacter 但非 EscapeCharacter 或 LineTerminator
EscapeCharacter :: SingleEscapeCharacter DecimalDigit x u
HexEscapeSequence :: x HexDigit HexDigit
UnicodeEscapeSequence :: u HexDigit HexDigit HexDigit HexDigit
RegularExpressionLiteral :: / RegularExpressionBody / RegularExpressionFlags
RegularExpressionBody :: RegularExpressionFirstChar RegularExpressionChars
RegularExpressionChars :: [empty] RegularExpressionChars RegularExpressionChar
RegularExpressionFirstChar :: RegularExpressionNonTerminator 但非 * 或 \ 或 / 或 [ RegularExpressionBackslashSequence RegularExpressionClass
RegularExpressionChar :: RegularExpressionNonTerminator 但非 \ 或 / 或 [ RegularExpressionBackslashSequence RegularExpressionClass
RegularExpressionBackslashSequence :: \ RegularExpressionNonTerminator
RegularExpressionNonTerminator :: SourceCharacter 但非 LineTerminator
RegularExpressionClass :: [ RegularExpressionClassChars ]
RegularExpressionClassChars :: [ 空 ] RegularExpressionClassChars RegularExpressionClassChar
RegularExpressionClassChar :: RegularExpressionNonTerminator 但非 ] 或 \ RegularExpressionBackslashSequence
RegularExpressionFlags :: [ 空 ] RegularExpressionFlags IdentifierPart
数字转换
StringNumericLiteral ::: StrWhiteSpaceopt StrWhiteSpaceoptStrNumericLiteral StrWhiteSpaceopt
StrWhiteSpace ::: StrWhiteSpaceChar StrWhiteSpaceopt
StrWhiteSpaceChar ::: WhiteSpace LineTerminator
StrNumericLiteral ::: StrDecimalLiteral HexIntegerLiteral
StrDecimalLiteral ::: StrUnsignedDecimalLiteral + StrUnsignedDecimalLiteral - StrUnsignedDecimalLiteral
StrUnsignedDecimalLiteral ::: Infinity DecimalDigits . DecimalDigitsopt ExponentPartopt . DecimalDigits ExponentPartopt DecimalDigits ExponentPartopt
DecimalDigits ::: DecimalDigit DecimalDigits DecimalDigit
DecimalDigit ::: 以下之一 0 1 2 3 4 5 6 7 8 9
ExponentPart ::: ExponentIndicator SignedInteger
ExponentIndicator ::: 以下之一 e E
SignedInteger ::: DecimalDigits + DecimalDigits - DecimalDigits
HexIntegerLiteral ::: 0x HexDigit 0X HexDigit HexIntegerLiteral HexDigit
HexDigit ::: 以下之一 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
表达式
PrimaryExpression : this Identifier Literal ArrayLiteral ObjectLiteral ( Expression )
ArrayLiteral : [ Elisionopt ] [ ElementList ] [ ElementList , Elisionopt ]
ElementList : ElisionoptAssignmentExpression ElementList , ElisionoptAssignmentExpression
Elision : , Elision ,
ObjectLiteral : { } { PropertyNameAndValueList } { PropertyNameAndValueList , }
PropertyNameAndValueList : PropertyAssignment PropertyNameAndValueList , PropertyAssignment
PropertyAssignment : PropertyName : AssignmentExpression get PropertyName() { FunctionBody } set PropertyName( PropertySetParameterList ) { FunctionBody }
PropertyName : IdentifierName StringLiteral NumericLiteral
PropertySetParameterList : Identifier
MemberExpression : PrimaryExpression FunctionExpression MemberExpression [ Expression ] MemberExpression . IdentifierName new MemberExpression Arguments
NewExpression : MemberExpression new NewExpression
CallExpression : MemberExpression Arguments CallExpression Arguments CallExpression [ Expression ] CallExpression . IdentifierName
Arguments : ( ) ( ArgumentList )
ArgumentList : AssignmentExpression ArgumentList , AssignmentExpression
LeftHandSideExpression : NewExpression CallExpression
PostfixExpression : LeftHandSideExpression LeftHandSideExpression [ 此处无换行 ] ++ LeftHandSideExpression [ 此处无换行 ] --
UnaryExpression : PostfixExpression delete UnaryExpression void UnaryExpression typeof UnaryExpression ++ UnaryExpression -- UnaryExpression + UnaryExpression - UnaryExpression ~ UnaryExpression ! UnaryExpression
MultiplicativeExpression : UnaryExpression MultiplicativeExpression * UnaryExpression MultiplicativeExpression / UnaryExpression MultiplicativeExpression % UnaryExpression
AdditiveExpression : MultiplicativeExpression AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression
ShiftExpression : AdditiveExpression ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression
RelationalExpression : ShiftExpression RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression RelationalExpression instanceof ShiftExpression RelationalExpression in ShiftExpression
RelationalExpressionNoIn : ShiftExpression RelationalExpressionNoIn < ShiftExpression RelationalExpressionNoIn > ShiftExpression RelationalExpressionNoIn <= ShiftExpression RelationalExpressionNoIn >= ShiftExpression RelationalExpressionNoIn instanceof ShiftExpression
EqualityExpression : RelationalExpression EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression EqualityExpression === RelationalExpression EqualityExpression !== RelationalExpression
EqualityExpressionNoIn : RelationalExpressionNoIn EqualityExpressionNoIn == RelationalExpressionNoIn EqualityExpressionNoIn != RelationalExpressionNoIn EqualityExpressionNoIn === RelationalExpressionNoIn EqualityExpressionNoIn !== RelationalExpressionNoIn
BitwiseANDExpression : EqualityExpression BitwiseANDExpression & EqualityExpression
BitwiseANDExpressionNoIn : EqualityExpressionNoIn BitwiseANDExpressionNoIn & EqualityExpressionNoIn
BitwiseXORExpression : BitwiseANDExpression BitwiseXORExpression ^ BitwiseANDExpression
BitwiseXORExpressionNoIn : BitwiseANDExpressionNoIn BitwiseXORExpressionNoIn ^ BitwiseANDExpressionNoIn
BitwiseORExpression : BitwiseXORExpression BitwiseORExpression | BitwiseXORExpression
BitwiseORExpressionNoIn : BitwiseXORExpressionNoIn BitwiseORExpressionNoIn | BitwiseXORExpressionNoIn
LogicalANDExpression : BitwiseORExpression LogicalANDExpression && BitwiseORExpression
LogicalANDExpressionNoIn : BitwiseORExpressionNoIn LogicalANDExpressionNoIn && BitwiseORExpressionNoIn
LogicalORExpression : LogicalANDExpression LogicalORExpression || LogicalANDExpression
LogicalORExpressionNoIn : LogicalANDExpressionNoIn LogicalORExpressionNoIn || LogicalANDExpressionNoIn
ConditionalExpression : LogicalORExpression LogicalORExpression ? AssignmentExpression : AssignmentExpression
ConditionalExpressionNoIn : LogicalORExpressionNoIn LogicalORExpressionNoIn ? AssignmentExpressionNoIn : AssignmentExpressionNoIn
AssignmentExpression : ConditionalExpression LeftHandSideExpression AssignmentOperator AssignmentExpression
AssignmentExpressionNoIn : ConditionalExpressionNoIn LeftHandSideExpression AssignmentOperator AssignmentExpressionNoIn AssignmentOperator : 以下之一 = *= /= %= += -= <<= >>= >>>= &= ^= |=
Expression : AssignmentExpression Expression , AssignmentExpression
ExpressionNoIn : AssignmentExpressionNoIn ExpressionNoIn , AssignmentExpressionNoIn
语句
Statement : Block VariableStatement EmptyStatement ExpressionStatement IfStatement IterationStatement ContinueStatement BreakStatement ReturnStatement WithStatement LabelledStatement SwitchStatement ThrowStatement TryStatement DebuggerStatement
Block : { StatementListopt }
StatementList : Statement StatementList Statement
VariableStatement : var VariableDeclarationList ;
VariableDeclarationList : VariableDeclaration VariableDeclarationList , VariableDeclaration
VariableDeclarationListNoIn : VariableDeclarationNoIn VariableDeclarationListNoIn , VariableDeclarationNoIn
VariableDeclaration : Identifier Initialiseropt
VariableDeclarationNoIn : Identifier InitialiserNoInopt
Initialiser : = AssignmentExpression
InitialiserNoIn : = AssignmentExpressionNoIn
EmptyStatement : ;
ExpressionStatement : [lookahead ∉ {{, function}]Expression ;
IfStatement : if ( Expression ) Statement else Statement if ( Expression ) Statement
IterationStatement : do Statement while ( Expression ); while ( Expression ) Statement for ( ExpressionNoInopt; Expressionopt ; Expressionopt ) Statement for ( var VariableDeclarationListNoIn; Expressionopt ; Expressionopt ) Statement for ( LeftHandSideExpression in Expression ) Statement for ( var VariableDeclarationNoIn in Expression ) Statement
ContinueStatement : continue [ 此处无换行 ]Identifieropt ;
BreakStatement : break [ 此处无换行 ]Identifieropt ;
ReturnStatement : return [ 此处无换行 ]Expressionopt ;
WithStatement : with ( Expression ) Statement
SwitchStatement : switch ( Expression ) CaseBlock
CaseBlock : { CaseClausesopt } { CaseClausesoptDefaultClause CaseClausesopt }
CaseClauses : CaseClause CaseClauses CaseClause
CaseClause : case Expression : StatementListopt
DefaultClause : default : StatementListopt
LabelledStatement : Identifier : Statement
ThrowStatement : throw [noLineTerminator here] Expression ;
TryStatement : try Block Catch try Block Finally try Block Catch Finally
Catch : catch ( Identifier ) Block
Finally : finally Block
DebuggerStatement : debugger ;
函数和程序
FunctionDeclaration : function Identifier ( FormalParameterListopt ) { FunctionBody }
FunctionExpression : function Identifieropt ( FormalParameterListopt ) { FunctionBody }
FormalParameterList : Identifier FormalParameterList , Identifier
FunctionBody : SourceElementsopt
Program : SourceElementsopt
SourceElements : SourceElement SourceElements SourceElement
SourceElement : Statement FunctionDeclaration
统一资源定位符字符分类
uri ::: uriCharactersopt
uriCharacters ::: uriCharacter uriCharactersopt
uriCharacter ::: uriReserved uriUnescaped uriEscaped
uriReserved ::: 以下之一 ; / ? : @ & = + $ ,
uriUnescaped ::: uriAlpha DecimalDigit uriMark
uriEscaped ::: % HexDigit HexDigit
uriAlpha ::: 以下之一 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
uriMark ::: 以下之一 - _ . ! ~ * ‘ ( )
正则表达式
Pattern :: Disjunction
Disjunction :: Alternative Alternative | Disjunction
Alternative :: [ 空 ] Alternative Term
Term :: Assertion Atom Atom Quantifier
Assertion :: ^ $ \ b \ B ( ? = Disjunction ) ( ? ! Disjunction )
Quantifier :: QuantifierPrefix QuantifierPrefix ?
QuantifierPrefix :: * + ? { DecimalDigits } { DecimalDigits , } { DecimalDigits , DecimalDigits }
Atom :: PatternCharacter . \ AtomEscape CharacterClass ( Disjunction ) ( ? : Disjunction )
PatternCharacter :: SourceCharacter 但非以下之一 : ^ $ \ . * + ? ( ) [ ] { } |
AtomEscape :: DecimalEscape CharacterEscape CharacterClassEscape
CharacterEscape :: ControlEscape c ControlLetter HexEscapeSequence UnicodeEscapeSequence IdentityEscape
ControlEscape :: 以下之一 f n r t v
ControlLetter :: 以下之一 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
IdentityEscape :: SourceCharacter but not IdentifierPart
DecimalEscape :: DecimalIntegerLiteral [lookahead ∉ DecimalDigit]
CharacterClassEscape :: 以下之一 d D s S w W
CharacterClass :: [ [lookahead ∉ {^}] ClassRanges ] [ ^ ClassRanges ]
ClassRanges :: [empty] NonemptyClassRanges
NonemptyClassRanges :: ClassAtom ClassAtom NonemptyClassRangesNoDash ClassAtom – ClassAtom ClassRanges
NonemptyClassRangesNoDash :: ClassAtom ClassAtomNoDash NonemptyClassRangesNoDash ClassAtomNoDash – ClassAtom ClassRanges
ClassAtom :: - ClassAtomNoDash
ClassAtomNoDash :: SourceCharacter 但非以下之一 \ 或 ] 或 - \ ClassEscape
ClassEscape :: DecimalEscape b CharacterEscape CharacterClassEscape
JSON
JSON词法
JSONWhiteSpace :: <TAB> <CR> <LF> <SP>
JSONString :: " JSONStringCharactersopt "
JSONStringCharacters :: JSONStringCharacter JSONStringCharactersopt
JSONStringCharacter :: SourceCharacter 但非 双引号 " 或反斜杠 \ 或 U+0000 抑或是 U+001F \ JSONEscapeSequence
JSONEscapeSequence :: JSONEscapeCharacter UnicodeEscapeSequence
JSONEscapeCharacter :: 以下之一 " / \ b f n r t
JSONNumber :: -optDecimalIntegerLiteral JSONFractionopt ExponentPartopt
JSONFraction :: . DecimalDigits
JSONNullLiteral :: NullLiteral
JSONBooleanLiteral :: BooleanLiteral
JSON语法
JSONText : JSONValue
JSONValue : JSONNullLiteral JSONBooleanLiteral JSONObject JSONArray JSONString JSONNumber
JSONObject : { } { JSONMemberList }
JSONMember : JSONString : JSONValue
JSONMemberList : JSONMember JSONMemberList , JSONMember
JSONArray : [ ] [ JSONElementList ]
JSONElementList : JSONValue JSONElementList , JSONValue
以上内容是否对您有帮助:
← 错误
更多建议: