[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fwd: javascript grammar
From: "Uwe Hoffmann" <uwe@iamaze.com>
I'm converting the fesi ecmascript grammar from javacc to sablecc (I just
like sablecc better).
http://home.worldcom.ch:80/~jmlugrin/fesi/
I've gotten pretty far but I still have to resolve some shift/reduce
conflicts.
Can anyone take a look at this and help me ? The shift/reduce I'm stuck
right now puzzles me. I don't know yet how to postpone the reduce...
thanks,
uwe
Helpers
unicode_input_character = [0..0xffff];
ht = 0x0009;
lf = 0x000a;
ff = 0x000c;
cr = 0x000d;
sp = ' ';
line_terminator = lf | cr | cr lf;
input_character = [unicode_input_character - [cr + lf]];
not_star = [input_character - '*'] | line_terminator;
not_star_not_slash = [input_character - ['*' + '/']] | line_terminator;
unicode_letter =
[0x0041..0x005a] | [0x0061..0x007a] | [0x00aa..0x00aa] | [0x00b5..0x00b5] |
[0x00ba..0x00ba] | [0x00c0..0x00d6] | [0x00d8..0x00f6] | [0x00f8..0x01f5] |
[0x01fa..0x0217] | [0x0250..0x02a8] | [0x02b0..0x02b8] | [0x02bb..0x02c1] |
[0x02d0..0x02d1] | [0x02e0..0x02e4] | [0x037a..0x037a] | [0x0386..0x0386] |
[0x0388..0x038a] | [0x038c..0x038c] | [0x038e..0x03a1] | [0x03a3..0x03ce] |
[0x03d0..0x03d6] | [0x03da..0x03da] | [0x03dc..0x03dc] | [0x03de..0x03de] |
[0x03e0..0x03e0] | [0x03e2..0x03f3] | [0x0401..0x040c] | [0x040e..0x044f] |
[0x0451..0x045c] | [0x045e..0x0481] | [0x0490..0x04c4] | [0x04c7..0x04c8] |
[0x04cb..0x04cc] | [0x04d0..0x04eb] | [0x04ee..0x04f5] | [0x04f8..0x04f9] |
[0x0531..0x0556] | [0x0559..0x0559] | [0x0561..0x0587] | [0x05d0..0x05ea] |
[0x05f0..0x05f2] | [0x0621..0x063a] | [0x0640..0x064a] | [0x0671..0x06b7] |
[0x06ba..0x06be] | [0x06c0..0x06ce] | [0x06d0..0x06d3] | [0x06d5..0x06d5] |
[0x06e5..0x06e6] | [0x0905..0x0939] | [0x093d..0x093d] | [0x0958..0x0961] |
[0x0985..0x098c] | [0x098f..0x0990] | [0x0993..0x09a8] | [0x09aa..0x09b0] |
[0x09b2..0x09b2] | [0x09b6..0x09b9] | [0x09dc..0x09dd] | [0x09df..0x09e1] |
[0x09f0..0x09f1] | [0x0a05..0x0a0a] | [0x0a0f..0x0a10] | [0x0a13..0x0a28] |
[0x0a2a..0x0a30] | [0x0a32..0x0a33] | [0x0a35..0x0a36] | [0x0a38..0x0a39] |
[0x0a59..0x0a5c] | [0x0a5e..0x0a5e] | [0x0a72..0x0a74] | [0x0a85..0x0a8b] |
[0x0a8d..0x0a8d] | [0x0a8f..0x0a91] | [0x0a93..0x0aa8] | [0x0aaa..0x0ab0] |
[0x0ab2..0x0ab3] | [0x0ab5..0x0ab9] | [0x0abd..0x0abd] | [0x0ae0..0x0ae0] |
[0x0b05..0x0b0c] | [0x0b0f..0x0b10] | [0x0b13..0x0b28] | [0x0b2a..0x0b30] |
[0x0b32..0x0b33] | [0x0b36..0x0b39] | [0x0b3d..0x0b3d] | [0x0b5c..0x0b5d] |
[0x0b5f..0x0b61] | [0x0b85..0x0b8a] | [0x0b8e..0x0b90] | [0x0b92..0x0b95] |
[0x0b99..0x0b9a] | [0x0b9c..0x0b9c] | [0x0b9e..0x0b9f] | [0x0ba3..0x0ba4] |
[0x0ba8..0x0baa] | [0x0bae..0x0bb5] | [0x0bb7..0x0bb9] | [0x0c05..0x0c0c] |
[0x0c0e..0x0c10] | [0x0c12..0x0c28] | [0x0c2a..0x0c33] | [0x0c35..0x0c39] |
[0x0c60..0x0c61] | [0x0c85..0x0c8c] | [0x0c8e..0x0c90] | [0x0c92..0x0ca8] |
[0x0caa..0x0cb3] | [0x0cb5..0x0cb9] | [0x0cde..0x0cde] | [0x0ce0..0x0ce1] |
[0x0d05..0x0d0c] | [0x0d0e..0x0d10] | [0x0d12..0x0d28] | [0x0d2a..0x0d39] |
[0x0d60..0x0d61] | [0x0e01..0x0e2e] | [0x0e30..0x0e30] | [0x0e32..0x0e33] |
[0x0e40..0x0e46] | [0x0e81..0x0e82] | [0x0e84..0x0e84] | [0x0e87..0x0e88] |
[0x0e8a..0x0e8a] | [0x0e8d..0x0e8d] | [0x0e94..0x0e97] | [0x0e99..0x0e9f] |
[0x0ea1..0x0ea3] | [0x0ea5..0x0ea5] | [0x0ea7..0x0ea7] | [0x0eaa..0x0eab] |
[0x0ead..0x0eae] | [0x0eb0..0x0eb0] | [0x0eb2..0x0eb3] | [0x0ebd..0x0ebd] |
[0x0ec0..0x0ec4] | [0x0ec6..0x0ec6] | [0x0edc..0x0edd] | [0x0f40..0x0f47] |
[0x0f49..0x0f69] | [0x10a0..0x10c5] | [0x10d0..0x10f6] | [0x1100..0x1159] |
[0x115f..0x11a2] | [0x11a8..0x11f9] | [0x1e00..0x1e9b] | [0x1ea0..0x1ef9] |
[0x1f00..0x1f15] | [0x1f18..0x1f1d] | [0x1f20..0x1f45] | [0x1f48..0x1f4d] |
[0x1f50..0x1f57] | [0x1f59..0x1f59] | [0x1f5b..0x1f5b] | [0x1f5d..0x1f5d] |
[0x1f5f..0x1f7d] | [0x1f80..0x1fb4] | [0x1fb6..0x1fbc] | [0x1fbe..0x1fbe] |
[0x1fc2..0x1fc4] | [0x1fc6..0x1fcc] | [0x1fd0..0x1fd3] | [0x1fd6..0x1fdb] |
[0x1fe0..0x1fec] | [0x1ff2..0x1ff4] | [0x1ff6..0x1ffc] | [0x207f..0x207f] |
[0x2102..0x2102] | [0x2107..0x2107] | [0x210a..0x2113] | [0x2115..0x2115] |
[0x2118..0x211d] | [0x2124..0x2124] | [0x2126..0x2126] | [0x2128..0x2128] |
[0x212a..0x2131] | [0x2133..0x2138] | [0x3005..0x3005] | [0x3031..0x3035] |
[0x3041..0x3094] | [0x309b..0x309e] | [0x30a1..0x30fa] | [0x30fc..0x30fe] |
[0x3105..0x312c] | [0x3131..0x318e] | [0x4e00..0x9fa5] | [0xac00..0xd7a3] |
[0xf900..0xfa2d] | [0xfb00..0xfb06] | [0xfb13..0xfb17] | [0xfb1f..0xfb28] |
[0xfb2a..0xfb36] | [0xfb38..0xfb3c] | [0xfb3e..0xfb3e] | [0xfb40..0xfb41] |
[0xfb43..0xfb44] | [0xfb46..0xfbb1] | [0xfbd3..0xfd3d] | [0xfd50..0xfd8f] |
[0xfd92..0xfdc7] | [0xfdf0..0xfdfb] | [0xfe70..0xfe72] | [0xfe74..0xfe74] |
[0xfe76..0xfefc] | [0xff21..0xff3a] | [0xff41..0xff5a] | [0xff66..0xffbe] |
[0xffc2..0xffc7] | [0xffca..0xffcf] | [0xffd2..0xffd7] | [0xffda..0xffdc];
unicode_digit =
[0x0030..0x0039] | [0x0660..0x0669] | [0x06f0..0x06f9] | [0x0966..0x096f] |
[0x09e6..0x09ef] | [0x0a66..0x0a6f] | [0x0ae6..0x0aef] | [0x0b66..0x0b6f] |
[0x0be7..0x0bef] | [0x0c66..0x0c6f] | [0x0ce6..0x0cef] | [0x0d66..0x0d6f] |
[0x0e50..0x0e59] | [0x0ed0..0x0ed9] | [0x0f20..0x0f29] | [0xff10..0xff19];
java_letter = unicode_letter | '$' | '_';
java_letter_or_digit = unicode_letter | unicode_digit | '$' | '_';
non_zero_digit = ['1'..'9'];
digit = ['0'..'9'];
hex_digit = ['0'..'9'] | ['a'..'f'] | ['A'..'F'];
octal_digit = ['0'..'7'];
zero_to_three = ['0'..'3'];
decimal_numeral = '0' | non_zero_digit digit*;
hex_numeral = '0' ('x' | 'X') hex_digit+;
octal_numeral = '0' octal_digit+;
integer_type_suffix = 'l' | 'L';
exponent_part = ('e' | 'E') ('+' | '-')? digit+;
float_type_suffix = 'f' | 'F' | 'd' | 'D';
single_character = [input_character - [''' + '\']];
octal_escape = '\' (octal_digit octal_digit? | zero_to_three octal_digit octal_digit);
escape_sequence = '\b' | '\t' | '\n' | '\f' | '\r' | '\"' | '\' ''' | '\\' | octal_escape;
string_character = [input_character - ['"' + '\']] | escape_sequence;
Tokens
white_space = (sp | ht | ff | line_terminator)*;
traditional_comment = '/*' not_star+ '*'+ (not_star_not_slash not_star* '*'+)* '/';
documentation_comment = '/**' '*'* (not_star_not_slash not_star* '*'+)* '/';
end_of_line_comment = '//' input_character* line_terminator?;
break = 'break';
continue = 'continue';
delete = 'delete';
else = 'else';
for = 'for';
function = 'function';
if = 'if';
in = 'in';
new = 'new';
return = 'return';
this = 'this';
typeof = 'typeof';
var = 'var';
void = 'void';
while = 'while';
with = 'with';
case = 'case';
catch = 'catch';
class = 'class';
const = 'const';
debugger = 'debugger';
default = 'default';
do = 'do';
enum = 'enum';
export = 'export';
extends = 'extends';
finally = 'finally';
import = 'import';
super = 'super';
switch = 'switch';
throw = 'throw';
try = 'try';
true = 'true';
false = 'false';
null = 'null';
decimal_integer_literal = decimal_numeral integer_type_suffix?;
hex_integer_literal = hex_numeral integer_type_suffix?;
octal_integer_literal = octal_numeral integer_type_suffix?;
floating_point_literal =
digit+ '.' digit* exponent_part? float_type_suffix? |
'.' digit+ exponent_part? float_type_suffix? |
digit+ exponent_part float_type_suffix? |
digit+ exponent_part? float_type_suffix;
string_literal = '"' string_character* '"';
identifier = java_letter java_letter_or_digit*;
lparen = '(';
rparen = ')';
lbrace = '{';
rbrace = '}';
lbracket = '[';
rbracket = ']';
semicolon = ';';
comma = ',';
dot = '.';
assign = '=';
gt = '>';
lt = '<';
bang = '!';
tilde = '~';
hook = '?';
colon = ':';
eq = '==';
le = '<=';
ge = '>=';
ne = '!=';
sc_or = '||';
sc_and = '&&';
incr = '++';
decr = '--';
plus = '+';
minus = '-';
star = '*';
slash = '/';
bit_and = '&';
bit_or = '|';
xor = '^';
rem = '%';
lshift = '<<';
rsignedshift = '>>';
runsignedshift = '>>>';
plusassign = '+=';
minusassign = '-=';
starassign = '*=';
slashassign = '/=';
andassign = '&=';
orassign = '|=';
xorassign = '^=';
remassign = '%=';
lshiftassign = '<<=';
rsignedshiftassign = '>>=';
runsignedshiftassign = '>>>=';
Ignored Tokens
white_space,
traditional_comment,
documentation_comment,
end_of_line_comment;
Productions
program =
{statement} statement program |
{function_declaration} function_declaration program |
{empty} ;
statement =
{block} block |
{variable_statement} variable_statement |
{empty_statement} empty_statement |
{expression_statement} expression_statement |
{if_statement} if_statement |
{iteration_statement} iteration_statement |
{continue_statement} continue_statement |
{break_statement} break_statement |
{return_statement} return_statement |
{with_statement} with_statement;
block =
{statement_list} lbrace statement_list rbrace;
statement_list =
{statement} statement statement_list |
{empty} ;
variable_statement =
{variable_declaration_list} var variable_declaration variable_declaration_list semicolon;
variable_declaration_list =
{multi_variables} variable_declaration_list comma variable_declaration |
{one_variable} variable_declaration |
{empty} ;
empty_statement =
{empty_statement} semicolon;
if_statement =
{if} if lparen expression rparen statement |
{if_else} if lparen expression rparen [if_case]:statement else [else_case]:statement;
iteration_statement =
{while} while_statement |
{for} for_statement |
{for_var} for_var_statement |
{for_in} for_in_statement |
{for_var_in} for_var_in_statement;
while_statement =
{while} while lparen expression rparen statement;
for_statement =
{for1} for lparen [one_sc]:semicolon [two_sc]:semicolon rparen statement |
{for2} for lparen [one_sc]:semicolon
[two_sc]:semicolon [final]:expression rparen statement |
{for3} for lparen [one_sc]:semicolon [incr]:expression
[two_sc]:semicolon rparen statement |
{for4} for lparen [one_sc]:semicolon [incr]:expression
[two_sc]:semicolon [final]:expression rparen statement |
{for5} for lparen [init]:expression [one_sc]:semicolon
[two_sc]:semicolon rparen statement |
{for6} for lparen [init]:expression [one_sc]:semicolon
[two_sc]:semicolon [final]:expression rparen statement |
{for7} for lparen [init]:expression [one_sc]:semicolon [incr]:expression
[two_sc]:semicolon rparen statement |
{for8} for lparen [init]:expression [one_sc]:semicolon [incr]:expression
[two_sc]:semicolon [final]:expression rparen statement;
for_var_statement =
{for_var1} for lparen var variable_declaration_list [one_sc]:semicolon
[two_sc]:semicolon rparen statement |
{for_var2} for lparen var variable_declaration_list [one_sc]:semicolon
[two_sc]:semicolon [final]:expression rparen statement |
{for_var3} for lparen var variable_declaration_list [one_sc]:semicolon [incr]:expression
[two_sc]:semicolon rparen statement |
{for_var4} for lparen var variable_declaration_list [one_sc]:semicolon [incr]:expression
[two_sc]:semicolon [final]:expression rparen statement;
for_in_statement =
{for_in} for lparen in expression rparen statement;
for_var_in_statement =
{for_var_in1} for lparen identifier initializer in expression rparen statement |
{for_var_in2} for lparen identifier in expression rparen statement;
continue_statement =
{continue} continue semicolon;
break_statement =
{break} break semicolon;
return_statement =
{return1} return expression semicolon |
{return2} return semicolon;
with_statement =
{with} with lparen expression rparen statement;
expression_statement =
{expr_statement} expression semicolon;
postfix_op =
{incr} incr |
{decr} decr;
postfix_expression =
{primary1} primary_expression postfix_op |
{primary2} primary_expression;
unary_op =
{delete} delete |
{void} void |
{typeof} typeof |
{incr} incr |
{decr} decr |
{plus} plus |
{minus} minus |
{tilde} tilde |
{bang} bang;
unary_expression =
{post} postfix_expression |
{unary} unary_op unary_expression;
mul_op =
{star} star |
{slash} slash |
{rem} rem;
multiplicative_expression =
{multiplicative} unary_expression mul_tail |
{multiplicative_empty} unary_expression;
mul_tail =
{list} mul_tail mul_op unary_expression |
{item} mul_op unary_expression;
add_op =
{plus} plus |
{minus} minus;
additive_expression =
{additive} multiplicative_expression add_tail |
{additive_empty} multiplicative_expression;
add_tail =
{list} add_tail add_op multiplicative_expression |
{item} add_op multiplicative_expression;
shift_op =
{lshift} lshift |
{rsignedshift} rsignedshift |
{runsignedshift} runsignedshift;
shift_expression =
{shift} additive_expression shift_tail |
{shift_empty} additive_expression;
shift_tail =
{list} shift_tail shift_op additive_expression |
{item} shift_op additive_expression;
rel_op =
{lt} lt |
{gt} gt |
{le} le |
{ge} ge;
relational_expression =
{relational} shift_expression relational_tail |
{relational_empty} shift_expression;
relational_tail =
{list} relational_tail rel_op shift_expression |
{item} rel_op shift_expression;
equal_op =
{eq} eq |
{ne} ne;
equality_expression =
{equality} relational_expression equality_tail |
{equality_empty} relational_expression;
equality_tail =
{list} equality_tail equal_op relational_expression |
{item} equal_op relational_expression;
bitwise_and_op =
{bit_and} bit_and;
bitwise_and_expression =
{bitwise_and} equality_expression bit_and_tail |
{bitwise_and_empty} equality_expression;
bit_and_tail =
{list} bit_and_tail bitwise_and_op equality_expression |
{item} bitwise_and_op equality_expression;
bitwise_xor_op =
{bit_xor} xor;
bitwise_xor_expression =
{bitwise_xor} bitwise_and_expression bit_xor_tail |
{bitwise_xor_empty} bitwise_and_expression;
bit_xor_tail =
{list} bit_xor_tail bitwise_xor_op bitwise_and_expression |
{item} bitwise_xor_op bitwise_and_expression;
bitwise_or_op =
{bit_or} bit_or;
bitwise_or_expression =
{bit_or} bitwise_xor_expression bit_or_tail |
{bit_or_tail} bitwise_xor_expression;
bit_or_tail =
{list} bit_or_tail bitwise_or_op bitwise_xor_expression |
{item} bitwise_or_op bitwise_xor_expression;
logical_and_expression =
{logic_and} bitwise_or_expression logical_and_tail |
{logic_and_empty} bitwise_or_expression;
logical_and_tail =
{list} logical_and_tail sc_and bitwise_or_expression |
{item} sc_and bitwise_or_expression;
logical_or_expression =
{logic_or} logical_and_expression logical_or_tail |
{logic_or_empty} logical_and_expression;
logical_or_tail =
{list} logical_or_tail sc_or logical_and_expression |
{item} sc_or logical_and_expression;
conditional_expression =
{cond_tail} logical_or_expression cond_tail |
{cond} logical_or_expression;
cond_tail =
{hook} hook expression colon conditional_expression;
assignment_op =
{assign} assign |
{starassign} starassign |
{slashassign} slashassign |
{remassign} remassign |
{plusassign} plusassign |
{minusassign} minusassign |
{lshiftassign} lshiftassign |
{rsignedshiftassign} rsignedshiftassign |
{runsignedshiftassign} runsignedshiftassign |
{andassign} andassign |
{orassign} orassign |
{xorassign} xorassign;
assignment_expression =
{cond_assign} conditional_expression assignment_op assignment_expression |
{cond} conditional_expression;
expression =
{expr} assignment_expression expression_tail |
{expr_empty} assignment_expression;
expression_tail =
{list} expression_tail comma assignment_expression |
{item} comma assignment_expression;
function_declaration =
{def1} function identifier lparen formal_parameter_list rparen block |
{def2} function identifier lparen rparen block |
{def3} function lparen formal_parameter_list rparen block |
{def4} function lparen rparen block;
formal_parameter_list =
{def} identifier formal_list_tail |
{def_empty} identifier;
formal_list_tail =
{list} formal_list_tail comma identifier |
{item} comma identifier;
variable_declaration =
{def1} identifier initializer |
{def2} identifier;
initializer =
{def} assign assignment_expression;
primary_expression =
{allocation} allocation_expression |
{this_def} this primary_suffix_tail |
{this_empty} this |
{identifier} identifier primary_suffix_tail |
{identifier_empty} identifier |
{literal} literal |
{expression} lparen expression rparen primary_suffix_tail |
{expression_empty} lparen expression rparen;
primary_suffix_tail =
{list} primary_suffix_tail primary_suffix |
{item} primary_suffix;
primary_suffix =
{args} arguments |
{expr} lbracket expression rbracket |
{identifier} dot identifier;
arguments =
{empty} lparen rparen |
{list} lparen argument_list rparen;
argument_list =
{def} assignment_expression argument_list_tail;
argument_list_tail =
{list} argument_list_tail comma assignment_expression |
{item} comma assignment_expression |
{empty} ;
new_suffix =
{def} dot identifier;
new_suffix_list =
{list} new_suffix_list new_suffix |
{item} new_suffix;
allocation_expression =
{def1} new this new_suffix_list arguments |
{def1_empty} new this arguments |
{def2} new this new_suffix_list |
{def2_empty} new this |
{def3} new identifier new_suffix_list arguments |
{def3_empty} new identifier arguments |
{def4} new identifier new_suffix_list |
{def4_empty} new identifier;
literal =
{decimal} decimal_integer_literal |
{octal} octal_integer_literal |
{hex} hex_integer_literal |
{float} floating_point_literal |
{string} string_literal |
{true} true |
{false} false |
{null} null;