Created
August 13, 2010 15:37
-
-
Save yyfrankyy/523064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Name" = 'JavaScript Grammar' | |
"Author" = 'M.Schnoor-Matriciani' | |
"Version" = '0.9' | |
"About" = 'JavaScript Grammar, Subset of ECMA Edition 3' | |
"Start Symbol" = <Program> | |
"Case Sensitive" = 'True' | |
! ------------------------------------------------- Sets | |
{ID Head} = {Letter} + [_] + [$] | |
{ID Tail} = {Alphanumeric} + [_] + [$] | |
{String Chars1} = {Printable} + {HT} - ["\] | |
{String Chars2} = {Printable} + {HT} - [\''] | |
{Hex Digit} = {Digit} + [ABCDEF] + [abcdef] | |
{RegExp Chars} = {Letter}+{Digit}+['^']+['$']+['*']+['+']+['?']+['{']+['}']+['|']+['-']+['.']+[',']+['#']+['[']+[']']+['_']+['<']+['>'] | |
{Non Terminator} = {String Chars1} - {CR} - {LF} | |
{Non Zero Digits}={Digit}-[0] | |
! ------------------------------------------------- Terminals | |
Identifier = {ID Head}{ID Tail}* | |
StringLiteral = '"' ( {String Chars1} | '\' {Printable} )* '"' | '' ( {String Chars2} | '\' {Printable} )* '' | |
HexIntegerLiteral = '0x' {Hex Digit}+ | |
RegExp = '/' ({RegExp Chars} | '\' {Non Terminator})+ '/' ( 'g' | 'i' | 'm' )* | |
DecimalLiteral= {Non Zero Digits}+ '.' {Digit}* ('e' | 'E' ) {Non Zero Digits}+ {Digit}* | {Non Zero Digits}+ '.' {Digit}* | '0' '.' {Digit}+ ('e' | 'E' ) {Non Zero Digits}+ {Digit}* | {Non Zero Digits}+ {Digit}* | '0' | '0' '.' {Digit}+ | |
Comment Start = '/*' | |
Comment End = '*/' | |
Comment Line = '//' | |
! ------------------------------------------------- Rules | |
<Literal> ::= <Null Literal> | |
| <Boolean Literal> | |
| <Numeric Literal> | |
| StringLiteral | |
<Null Literal> ::= null | |
<Boolean Literal> ::= 'true' | |
| 'false' | |
<Numeric Literal> ::= DecimalLiteral | |
| HexIntegerLiteral | |
<Regular Expression Literal> ::= RegExp | |
<Primary Expression> ::= 'this' | |
| Identifier | |
| <Literal> | |
| <Array Literal> | |
| <Object Literal> | |
| '(' <Expression> ')' | |
| <Regular Expression Literal> | |
<Array Literal> ::= '[' ']' | |
| '[' <Elision> ']' | |
| '[' <Element List> ']' | |
| '[' <Element List> ',' <Elision> ']' | |
<Elision> ::= ',' | |
| <Elision> ',' | |
<Element List> ::= <Elision> <Assignment Expression> | |
| <Element List> ',' <Elision> <Assignment Expression> | |
| <Element List> ',' <Assignment Expression> | |
| <Assignment Expression> | |
<Object Literal> ::= '{' <Property Name and Value List> '}' | |
<Property Name and Value List> ::= <Property Name> ':' <Assignment Expression> | |
| <Property Name and Value List> ',' <Property Name> ':' <Assignment Expression> | |
<Property Name> ::= Identifier | |
| StringLiteral | |
| <Numeric Literal> | |
<Member Expression > ::= <Primary Expression> | |
| <Function Expression> | |
| <Member Expression> '[' <Expression> ']' | |
| <Member Expression> '.' Identifier | |
| 'new' <Member Expression> <Arguments> | |
<New Expression> ::= <Member Expression> | |
| new <New Expression> | |
<Call Expression> ::= <Member Expression> <Arguments> | |
| <Call Expression> <Arguments> | |
| <Call Expression> '[' <Expression> ']' | |
| <Call Expression> '.' Identifier | |
<Arguments> ::= '(' ')' | |
| '(' <Argument List> ')' | |
<Argument List> ::= <Assignment Expression> | |
| <Argument List> ',' <Assignment Expression> | |
<Left Hand Side Expression> ::= <New Expression> | |
| <Call Expression> | |
<Postfix Expression> ::= <Left Hand Side Expression> | |
| <Postfix Expression> '++' | |
| <Postfix Expression> '--' | |
<Unary Expression> ::= <Postfix Expression> | |
| 'delete' <Unary Expression> | |
| 'void' <Unary Expression> | |
| 'typeof' <Unary Expression> | |
| '++' <Unary Expression> | |
| '--' <Unary Expression> | |
| '+' <Unary Expression> | |
| '-' <Unary Expression> | |
| '~' <Unary Expression> | |
| '!' <Unary Expression> | |
<Multiplicative Expression> ::= <Unary Expression> | |
| <Unary Expression> '*' <Multiplicative Expression> | |
| <Unary Expression> '/' <Multiplicative Expression> | |
| <Unary Expression> '%' <Multiplicative Expression> | |
<Additive Expression> ::= <Additive Expression>'+'<Multiplicative Expression> | |
| <Additive Expression>'-'<Multiplicative Expression> | |
| <Multiplicative Expression> | |
<Shift Expression> ::= <Shift Expression> '<<' <Additive Expression> | |
| <Shift Expression> '>>' <Additive Expression> | |
| <Shift Expression> '>>>' <Additive Expression> | |
| <Additive Expression> | |
<Relational Expression>::= <Shift Expression> | |
| <Relational Expression> '<' <Shift Expression> | |
| <Relational Expression> '>' <Shift Expression> | |
| <Relational Expression> '<=' <Shift Expression> | |
| <Relational Expression> '>=' <Shift Expression> | |
| <Relational Expression> 'instanceof' <Shift Expression> | |
<Equality Expression> ::= <Relational Expression> | |
| <Equality Expression> '==' <Relational Expression> | |
| <Equality Expression> '!=' <Relational Expression> | |
| <Equality Expression> '===' <Relational Expression> | |
| <Equality Expression> '!==' <Relational Expression> | |
<Bitwise And Expression> ::= <Equality Expression> | |
| <Bitwise And Expression> '&' <Equality Expression> | |
<Bitwise XOr Expression> ::= <Bitwise And Expression> | |
| <Bitwise XOr Expression> '^' <Bitwise And Expression> | |
<Bitwise Or Expression> ::= <Bitwise XOr Expression> | |
| <Bitwise Or Expression> '|' <Bitwise XOr Expression> | |
<Logical And Expression> ::= <Bitwise Or Expression> | |
| <Logical And Expression> '&&' <Bitwise Or Expression> | |
<Logical Or Expression> ::= <Logical And Expression> | |
| <Logical Or Expression> '||' <Logical And Expression> | |
<Conditional Expression> ::= <Logical Or Expression> | |
| <Logical Or Expression> '?' <Assignment Expression> ':' <Assignment Expression> | |
<Assignment Expression> ::= <Conditional Expression> | |
| <Left Hand Side Expression> <Assignment Operator> <Assignment Expression> | |
<Assignment Operator> ::= '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|=' | |
<Expression> ::= <Assignment Expression> | |
| <Expression> ',' <Assignment Expression> | |
<Statement> ::= <Block> | |
| <Variable Statement> | |
| <Empty Statement> | |
| <If Statement> | |
| <If Else Statement> | |
| <Iteration Statement> | |
| <Continue Statement> | |
| <Break Statement> | |
| <Return Statement> | |
| <With Statement> | |
| <Labelled Statement> | |
| <Switch Statement> | |
| <Throw Statement> | |
| <Try Statement> | |
| <Expression> | |
<Block > ::= '{' '}' | |
| '{' <Statement List> '}' | |
<Statement List> ::= <Statement> | |
| <Statement List> <Statement> | |
<Variable Statement> ::= var <Variable Declaration List> ';' | |
<Variable Declaration List> ::= <Variable Declaration> | |
| <Variable Declaration List> ',' <Variable Declaration> | |
<Variable Declaration> ::= Identifier | |
| Identifier <Initializer> | |
<Initializer> ::= '=' <Assignment Expression> | |
<Empty Statement> ::= ';' | |
<If Statement> ::= 'if' '(' <Expression> ')' <Statement> | |
<If Else Statement> ::= 'if' '(' <Expression> ')' <Statement> 'else' <Statement> | |
<Iteration Statement> ::= 'do' <Statement> 'while' '(' <Expression> ')' ';' | |
| 'while' '(' <Expression> ')' <Statement> | |
| 'for' '(' <Expression> ';' <Expression> ';' <Expression> ')' <Statement> | |
| 'for' '(' 'var' <Variable Declaration List> ';' <Expression> ';' <Expression> ')' <Statement> | |
| 'for' '(' <Left Hand Side Expression> in <Expression> ')' <Statement> | |
| 'for' '(' 'var' <Variable Declaration> in <Expression> ')' <Statement> | |
<Continue Statement> ::= 'continue' ';' | |
| 'continue' Identifier ';' | |
<Break Statement> ::= 'break' ';' | |
| 'break' Identifier ';' | |
<Return Statement> ::= 'return' ';' | |
| 'return' <Expression> ';' | |
<With Statement> ::= 'with' '(' <Expression> ')' <Statement> ';' | |
<Switch Statement> ::= 'switch' '(' <Expression> ')' <Case Block> | |
<Case Block> ::= '{' '}' | |
| '{' <Case Clauses> '}' | |
| '{' <Case Clauses> <Default Clause> '}' | |
| '{' <Case Clauses> <Default Clause> <Case Clauses> '}' | |
| '{' <Default Clause> <Case Clauses> '}' | |
| '{' <Default Clause> '}' | |
<Case Clauses> ::= <Case Clause> | |
| <Case Clauses> <Case Clause> | |
<Case Clause> ::= 'case' <Expression> ':' <Statement List> | |
| 'case' <Expression> ':' | |
<Default Clause> ::= 'default' ':' | |
| 'default' ':' <Statement List> | |
<Labelled Statement> ::= Identifier ':' <Statement> | |
<Throw Statement> ::= 'throw' <Expression> | |
<Try Statement> ::= 'try' <Block> <Catch> | |
| 'try' <Block> <Finally> | |
| 'try' <Block> <Catch> <Finally> | |
<Catch> ::= 'catch' '(' Identifier ')' <Block> | |
<Finally> ::= 'finally' <Block> | |
<Function Declaration> ::= 'function' Identifier '(' <Formal Parameter List> ')' '{' <Function Body> '}' | |
| 'function' Identifier '(' ')' '{' <Function Body> '}' | |
<Function Expression> ::= 'function' '(' ')' '{' <Function Body> '}' | |
| 'function' '(' <Formal Parameter List> ')' '{' <Function Body> '}' | |
<Formal Parameter List> ::= Identifier | |
| <Formal Parameter List> ',' Identifier | |
<Function Body> ::= <Source Elements> | |
| | |
<Program> ::= <Source Elements> | |
<Source Elements> ::= <Source Element> | |
| <Source Elements> <Source Element> | |
<Source Element> ::= <Statement> | |
| <Function Declaration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment