From 3ea7eed0e5ab3447a2cc73016594971b507a2344 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 6 Jun 2012 13:43:23 -0700 Subject: [PATCH] Remove redundant grammar rules: NoRE, NoIn, NoBF. --- Cycript.l.in | 332 +++++++++++++-------------- Cycript.yy.in | 605 ++++++++++++-------------------------------------- Parser.cpp | 2 + Parser.hpp | 6 +- 4 files changed, 317 insertions(+), 628 deletions(-) diff --git a/Cycript.l.in b/Cycript.l.in index dca452a..e109ca9 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -28,19 +28,25 @@ typedef cy::parser::token tk; #define YY_EXTRA_TYPE CYDriver * +#define F(value) do { \ + int token(value); \ + yyextra->statement_ = false; \ + return token; \ +} while (false) + #define A new($pool) #define Y apr_pstrmemdup($pool, yytext, yyleng) -#define I(type, Type, Name) do { \ +#define I(type, Type, value) do { \ yylval->type ## _ = A CY ## Type; \ - return tk::Name; \ + F(value); \ } while (false) #define T yylval->newline_ = yyextra->state_ == CYNewLine; BEGIN(Div); #define C T yyextra->state_ = CYClear; #define R T yyextra->state_ = CYRestricted; -#define E L C I(literal, RegEx(Y), RegularExpressionLiteral); +#define E L C I(literal, RegEx(Y), tk::RegularExpressionLiteral); #define N \ if (yyextra->state_ != CYNewLine) { \ @@ -48,7 +54,7 @@ typedef cy::parser::token tk; yyextra->state_ = CYNewLine; \ else { \ yyextra->state_ = CYClear; \ - return tk::NewLine; \ + F(tk::NewLine); \ } \ } @@ -147,191 +153,191 @@ XMLName {XMLNameStart}{XMLNamePart}* /* http://ostermiller.org/findcomment.html */ /* XXX: unify these two rules using !? */ -\/\*!([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/ V() C I(comment, Comment(Y), Comment); +\/\*!([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/ V() C I(comment, Comment(Y), tk::Comment); \/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/ V(N) @begin E4X -"<>" L return tk::LeftRight; -"" L return tk::LeftSlashRight; +"<>" L F(tk::LeftRight); +"" L F(tk::LeftSlashRight); -\])*]]> V() return tk::XMLCDATA; -\ V() return tk::XMLComment; -\])*?> V() return tk::XMLPI; +\])*]]> V() F(tk::XMLCDATA); +\ V() F(tk::XMLComment); +\])*?> V() F(tk::XMLPI); -"=" L return tk::Equal; -">" L return tk::Right; -"/>" L return tk::SlashRight; -"{" L return tk::OpenBrace; +"=" L F(tk::Equal); +">" L F(tk::Right); +"/>" L F(tk::SlashRight); +"{" L F(tk::OpenBrace); -\"(\n|[^"])*\"|'(\n|[^'])*' V() return tk::XMLAttributeValue; -{XMLName} L return tk::XMLName; -[ \t\r\n] V() return tk::XMLWhitespace; +\"(\n|[^"])*\"|'(\n|[^'])*' V() F(tk::XMLAttributeValue); +{XMLName} L F(tk::XMLName); +[ \t\r\n] V() F(tk::XMLWhitespace); -"{" L return tk::OpenBrace; -"<" L return tk::Left; -""{" L F(tk::OpenBrace); +"<" L F(tk::Left); +"newline_ ? tk::HyphenHyphen_ : tk::HyphenHyphen; -"->" L C return tk::HyphenRight; -"<" L C return tk::Left; -"<=" L C return tk::LeftEqual; -"<<" L C return tk::LeftLeft; -"<<=" L C return tk::LeftLeftEqual; -"%" L C return tk::Percent; -"%=" L C return tk::PercentEqual; -"." L C return tk::Period; -"|" L C return tk::Pipe; -"|=" L C return tk::PipeEqual; -"||" L C return tk::PipePipe; -"+" L C return tk::Plus; -"+=" L C return tk::PlusEqual; -"++" L C return yylval->newline_ ? tk::PlusPlus_ : tk::PlusPlus; -">" L C return tk::Right; -">=" L C return tk::RightEqual; -">>" L C return tk::RightRight; -">>=" L C return tk::RightRightEqual; -">>>" L C return tk::RightRightRight; -">>>=" L C return tk::RightRightRightEqual; -"*" L C return tk::Star; -"*=" L C return tk::StarEqual; -"~" L C return tk::Tilde; - -
"/" L C return tk::Slash; -
"/=" L C return tk::SlashEqual; - -":" L C return tk::Colon; -"," L C return tk::Comma; -"?" L C return tk::Question; -";" L C return tk::SemiColon; - -"(" L C return tk::OpenParen; -")" L C return tk::CloseParen; - -"{" L C return yylval->newline_ ? tk::OpenBrace_ : tk::OpenBrace; -"}" L C return tk::CloseBrace; - -"[" L C return tk::OpenBracket; -"]" L C return tk::CloseBracket; +"&" L C F(tk::Ampersand); +"&&" L C F(tk::AmpersandAmpersand); +"&=" L C F(tk::AmpersandEqual); +"^" L C F(tk::Carrot); +"^=" L C F(tk::CarrotEqual); +"=" L C F(tk::Equal); +"==" L C F(tk::EqualEqual); +"===" L C F(tk::EqualEqualEqual); +"!" L C F(tk::Exclamation); +"!=" L C F(tk::ExclamationEqual); +"!==" L C F(tk::ExclamationEqualEqual); +"-" L C F(tk::Hyphen); +"-=" L C F(tk::HyphenEqual); +"--" L C F(yylval->newline_ ? tk::HyphenHyphen_ : tk::HyphenHyphen); +"->" L C F(tk::HyphenRight); +"<" L C F(tk::Left); +"<=" L C F(tk::LeftEqual); +"<<" L C F(tk::LeftLeft); +"<<=" L C F(tk::LeftLeftEqual); +"%" L C F(tk::Percent); +"%=" L C F(tk::PercentEqual); +"." L C F(tk::Period); +"|" L C F(tk::Pipe); +"|=" L C F(tk::PipeEqual); +"||" L C F(tk::PipePipe); +"+" L C F(tk::Plus); +"+=" L C F(tk::PlusEqual); +"++" L C F(yylval->newline_ ? tk::PlusPlus_ : tk::PlusPlus); +">" L C F(tk::Right); +">=" L C F(tk::RightEqual); +">>" L C F(tk::RightRight); +">>=" L C F(tk::RightRightEqual); +">>>" L C F(tk::RightRightRight); +">>>=" L C F(tk::RightRightRightEqual); +"*" L C F(tk::Star); +"*=" L C F(tk::StarEqual); +"~" L C F(tk::Tilde); + +
"/" L C F(tk::Slash); +
"/=" L C F(tk::SlashEqual); + +":" L C F(tk::Colon); +"," L C F(tk::Comma); +"?" L C F(tk::Question); +";" L C F(tk::SemiColon); + +"(" L C F(tk::OpenParen); +")" L C F(tk::CloseParen); + +"{" L C F(yyextra->statement_ ? tk::OpenBrace__ : yylval->newline_ ? tk::OpenBrace_ : tk::OpenBrace); +"}" L C F(tk::CloseBrace); + +"[" L C F(tk::OpenBracket); +"]" L C F(tk::CloseBracket); @begin Java -"@class" L C return tk::AtClass; +"@class" L C F(tk::AtClass); @end @begin ObjectiveC -"@end" L C return tk::AtEnd; -"@implementation" L C return tk::AtImplementation; -"@import" L C return tk::AtImport; -"@selector" L C return tk::AtSelector; +"@end" L C F(tk::AtEnd); +"@implementation" L C F(yyextra->statement_ ? tk::AtImplementation_ : tk::AtImplementation); +"@import" L C F(tk::AtImport); +"@selector" L C F(tk::AtSelector); @end -"false" L C I(false, False(), False); -"null" L C I(null, Null(), Null); -"true" L C I(true, True(), True); - -"break" L R I(word, Word("break"), Break); -"case" L C I(word, Word("case"), Case); -"catch" L C I(word, Word("catch"), Catch); -"continue" L R I(word, Word("continue"), Continue); -"default" L C I(word, Word("default"), Default); -"delete" L C I(word, Word("delete"), Delete); -"do" L C I(word, Word("do"), Do); -"else" L C I(word, Word("else"), Else); -"finally" L C I(word, Word("finally"), Finally); -"for" L C I(word, Word("for"), For); -"function" L C I(word, Word("function"), Function); -"if" L C I(word, Word("if"), If); -"in" L C I(word, Word("in"), In); -"instanceof" L C I(word, Word("instanceof"), InstanceOf); -"new" L C I(word, Word("new"), New); -"return" L R I(word, Word("return"), Return); -"switch" L C I(word, Word("switch"), Switch); -"this" L C I(this, This(), This); -"throw" L R I(word, Word("throw"), Throw); -"try" L C I(word, Word("try"), Try); -"typeof" L C I(word, Word("typeof"), TypeOf); -"var" L C I(word, Word("var"), Var); -"void" L C I(word, Word("void"), Void); -"while" L C I(word, Word("while"), While); -"with" L C I(word, Word("with"), With); - -"debugger" L C I(word, Word("debugger"), Debugger); - -"const" L C I(word, Word("const"), Const); - -"class" L C I(word, Word("class"), Class); -"enum" L C I(word, Word("enum"), Enum); -"export" L C I(word, Word("export"), Export); -"extends" L C I(word, Word("extends"), Extends); -"import" L C I(word, Word("import"), Import); -"super" L C I(word, Word("super"), Super); - -"implements" L C I(identifier, Identifier("implements"), Implements); -"interface" L C I(identifier, Identifier("interface"), Interface); -"package" L C I(identifier, Identifier("package"), Package); -"private" L C I(identifier, Identifier("private"), Private); -"protected" L C I(identifier, Identifier("protected"), Protected); -"public" L C I(identifier, Identifier("public"), Public); -"static" L C I(identifier, Identifier("static"), Static); - -"abstract" L C I(identifier, Identifier("abstract"), Abstract); -"boolean" L C I(identifier, Identifier("boolean"), Boolean); -"byte" L C I(identifier, Identifier("byte"), Byte); -"char" L C I(identifier, Identifier("char"), Char); -"double" L C I(identifier, Identifier("double"), Double); -"final" L C I(identifier, Identifier("final"), Final); -"float" L C I(identifier, Identifier("float"), Float); -"goto" L C I(identifier, Identifier("goto"), Goto); -"int" L C I(identifier, Identifier("int"), Int); -"long" L C I(identifier, Identifier("long"), Long); -"native" L C I(identifier, Identifier("native"), Native); -"short" L C I(identifier, Identifier("short"), Short); -"synchronized" L C I(identifier, Identifier("synchronized"), Synchronized); -"throws" L C I(identifier, Identifier("throws"), Throws); -"transient" L C I(identifier, Identifier("transient"), Transient); -"volatile" L C I(identifier, Identifier("volatile"), Volatile); - -"let" L C I(identifier, Identifier("let"), Let); -"yield" L C I(identifier, Identifier("yield"), Yield); - -"each" L C I(identifier, Identifier("each"), Each); +"false" L C I(false, False(), tk::False); +"null" L C I(null, Null(), tk::Null); +"true" L C I(true, True(), tk::True); + +"break" L R I(word, Word("break"), tk::Break); +"case" L C I(word, Word("case"), tk::Case); +"catch" L C I(word, Word("catch"), tk::Catch); +"continue" L R I(word, Word("continue"), tk::Continue); +"default" L C I(word, Word("default"), tk::Default); +"delete" L C I(word, Word("delete"), tk::Delete); +"do" L C I(word, Word("do"), tk::Do); +"else" L C I(word, Word("else"), tk::Else); +"finally" L C I(word, Word("finally"), tk::Finally); +"for" L C I(word, Word("for"), tk::For); +"function" L C I(word, Word("function"), yyextra->statement_ ? tk::Function_ : tk::Function); +"if" L C I(word, Word("if"), tk::If); +"in" L C I(word, Word("in"), yyextra->in_.top() ? tk::In_ : tk::In); +"instanceof" L C I(word, Word("instanceof"), tk::InstanceOf); +"new" L C I(word, Word("new"), tk::New); +"return" L R I(word, Word("return"), tk::Return); +"switch" L C I(word, Word("switch"), tk::Switch); +"this" L C I(this, This(), tk::This); +"throw" L R I(word, Word("throw"), tk::Throw); +"try" L C I(word, Word("try"), tk::Try); +"typeof" L C I(word, Word("typeof"), tk::TypeOf); +"var" L C I(word, Word("var"), tk::Var); +"void" L C I(word, Word("void"), tk::Void); +"while" L C I(word, Word("while"), tk::While); +"with" L C I(word, Word("with"), tk::With); + +"debugger" L C I(word, Word("debugger"), tk::Debugger); + +"const" L C I(word, Word("const"), tk::Const); + +"class" L C I(word, Word("class"), tk::Class); +"enum" L C I(word, Word("enum"), tk::Enum); +"export" L C I(word, Word("export"), tk::Export); +"extends" L C I(word, Word("extends"), tk::Extends); +"import" L C I(word, Word("import"), tk::Import); +"super" L C I(word, Word("super"), tk::Super); + +"implements" L C I(identifier, Identifier("implements"), tk::Implements); +"interface" L C I(identifier, Identifier("interface"), tk::Interface); +"package" L C I(identifier, Identifier("package"), tk::Package); +"private" L C I(identifier, Identifier("private"), tk::Private); +"protected" L C I(identifier, Identifier("protected"), tk::Protected); +"public" L C I(identifier, Identifier("public"), tk::Public); +"static" L C I(identifier, Identifier("static"), tk::Static); + +"abstract" L C I(identifier, Identifier("abstract"), tk::Abstract); +"boolean" L C I(identifier, Identifier("boolean"), tk::Boolean); +"byte" L C I(identifier, Identifier("byte"), tk::Byte); +"char" L C I(identifier, Identifier("char"), tk::Char); +"double" L C I(identifier, Identifier("double"), tk::Double); +"final" L C I(identifier, Identifier("final"), tk::Final); +"float" L C I(identifier, Identifier("float"), tk::Float); +"goto" L C I(identifier, Identifier("goto"), tk::Goto); +"int" L C I(identifier, Identifier("int"), tk::Int); +"long" L C I(identifier, Identifier("long"), tk::Long); +"native" L C I(identifier, Identifier("native"), tk::Native); +"short" L C I(identifier, Identifier("short"), tk::Short); +"synchronized" L C I(identifier, Identifier("synchronized"), tk::Synchronized); +"throws" L C I(identifier, Identifier("throws"), tk::Throws); +"transient" L C I(identifier, Identifier("transient"), tk::Transient); +"volatile" L C I(identifier, Identifier("volatile"), tk::Volatile); + +"let" L C I(identifier, Identifier("let"), tk::Let); +"yield" L C I(identifier, Identifier("yield"), tk::Yield); + +"each" L C I(identifier, Identifier("each"), tk::Each); @begin E4X -"namespace" L C I(identifier, Identifier("namespace"), Namespace); -"xml" L C I(identifier, Identifier("xml"), XML); +"namespace" L C I(identifier, Identifier("namespace"), tk::Namespace); +"xml" L C I(identifier, Identifier("xml"), tk::XML); @end -{IdentifierStart}{IdentifierPart}* L C I(identifier, Identifier(Y), Identifier_); +{IdentifierStart}{IdentifierPart}* L C I(identifier, Identifier(Y), tk::Identifier_); -(\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?){Exponent}? L C I(number, Number(strtod(yytext, NULL)), NumericLiteral); +(\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?){Exponent}? L C I(number, Number(strtod(yytext, NULL)), tk::NumericLiteral); -0[xX][0-9a-fA-F]+ L C I(number, Number(strtoull(yytext + 2, NULL, 16)), NumericLiteral); -0[0-7]+ L C I(number, Number(strtoull(yytext + 1, NULL, 8)), NumericLiteral); -0[bB][0-1]+ L C I(number, Number(strtoull(yytext + 2, NULL, 2)), NumericLiteral); +0[xX][0-9a-fA-F]+ L C I(number, Number(strtoull(yytext + 2, NULL, 16)), tk::NumericLiteral); +0[0-7]+ L C I(number, Number(strtoull(yytext + 1, NULL, 8)), tk::NumericLiteral); +0[bB][0-1]+ L C I(number, Number(strtoull(yytext + 2, NULL, 2)), tk::NumericLiteral); \"([^"\\\n]|{Escape})*\"|'([^'\\\n]|{Escape})*' L C { char *value(A char[yyleng]); @@ -364,14 +370,14 @@ XMLName {XMLNameStart}{XMLNamePart}* } *local = '\0'; - I(string, String(value, local - value), StringLiteral); + I(string, String(value, local - value), tk::StringLiteral); } -\r?\n yylloc->end.lines(); yylloc->step(); N +\r?\n|\r|\xe2\x80[\xa8\xa9] yylloc->end.lines(); yylloc->step(); N [ \t] L -<> if (yyextra->auto_) { yyextra->auto_ = false; return tk::AutoComplete; } L yyterminate(); +<> if (yyextra->auto_) { yyextra->auto_ = false; F(tk::AutoComplete); } L yyterminate(); . L { CYDriver::Error error; diff --git a/Cycript.yy.in b/Cycript.yy.in index d8ec64a..492ab29 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -209,6 +209,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %token OpenBrace "{" %token OpenBrace_ "\n{" +%token OpenBrace__ ";{" %token CloseBrace "}" %token OpenBracket "[" @@ -220,6 +221,7 @@ int cylex(YYSTYPE *, cy::location *, void *); @begin ObjectiveC %token AtImplementation "@implementation" +%token AtImplementation_ ";@implementation" %token AtImport "@import" %token AtEnd "@end" %token AtSelector "@selector" @@ -241,8 +243,10 @@ int cylex(YYSTYPE *, cy::location *, void *); %token Finally "finally" %token For "for" %token Function "function" +%token Function_ ";function" %token If "if" %token In "in" +%token In_ "!in" %token InstanceOf "instanceof" %token New "new" %token Return "return" @@ -318,36 +322,25 @@ int cylex(YYSTYPE *, cy::location *, void *); %token RegularExpressionLiteral %type AdditiveExpression -%type AdditiveExpressionNoBF %type ArgumentList_ %type ArgumentList %type ArgumentListOpt %type Arguments %type ArrayLiteral -%type AssigneeExpression -%type AssigneeExpressionNoBF %type AssignmentExpression_ %type AssignmentExpression -%type AssignmentExpressionNoBF -%type AssignmentExpressionNoIn %type BindingIdentifier %type BitwiseANDExpression -%type BitwiseANDExpressionNoBF -%type BitwiseANDExpressionNoIn %type Block_ %type Block %type BooleanLiteral %type BindingElement %type BitwiseORExpression -%type BitwiseORExpressionNoBF -%type BitwiseORExpressionNoIn %type BitwiseXORExpression -%type BitwiseXORExpressionNoBF -%type BitwiseXORExpressionNoIn %type BreakStatement %type BreakableStatement +%type CallExpression_ %type CallExpression -%type CallExpressionNoBF %type CaseBlock %type CaseClause %type CaseClausesOpt @@ -355,10 +348,10 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ComprehensionList %type ComprehensionListOpt %type ConditionalExpression -%type ConditionalExpressionNoBF -%type ConditionalExpressionNoIn %type ContinueStatement %type DebuggerStatement +%type Declaration__ +%type Declaration_ %type Declaration %type DefaultClause %type DoWhileStatement @@ -369,15 +362,9 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ElseStatementOpt %type EmptyStatement %type EqualityExpression -%type EqualityExpressionNoBF -%type EqualityExpressionNoIn %type Expression_ %type Expression %type ExpressionOpt -%type ExpressionNoBF -%type ExpressionNoIn_ -%type ExpressionNoIn -%type ExpressionNoInOpt %type ExpressionStatement %type FinallyOpt %type ForComprehension @@ -398,42 +385,25 @@ int cylex(YYSTYPE *, cy::location *, void *); %type IfStatement %type Initialiser %type InitialiserOpt -%type InitialiserNoIn -%type InitialiserNoInOpt %type IterationStatement %type LabelledStatement %type LeftHandSideExpression -%type LeftHandSideExpressionNoBF -//%type LetExpression %type LetStatement %type LexicalDeclaration %type Literal %type LiteralNoRE -%type LiteralRE %type LogicalANDExpression -%type LogicalANDExpressionNoBF -%type LogicalANDExpressionNoIn %type LogicalORExpression -%type LogicalORExpressionNoBF -%type LogicalORExpressionNoIn %type MemberAccess %type MemberExpression_ %type MemberExpression -%type MemberExpressionNoBF %type MultiplicativeExpression -%type MultiplicativeExpressionNoBF -%type NewExpression_ %type NewExpression -%type NewExpressionNoBF %type NullLiteral %type ObjectLiteral +%type Parenthetical %type PostfixExpression -%type PostfixExpressionNoBF %type PrimaryExpression -%type PrimaryExpressionNo -%type PrimaryExpressionNoBF -%type PrimaryExpressionNoRE -%type PrimaryExpressionBF %type Program %type ProgramBody %type ProgramBodyOpt @@ -442,21 +412,17 @@ int cylex(YYSTYPE *, cy::location *, void *); %type PropertyNameAndValueList_ %type PropertyNameAndValueList %type PropertyNameAndValueListOpt -%type RelationalExpression_ +%type RelationalExpression_ %type RelationalExpression -%type RelationalExpressionNoBF -%type RelationalExpressionNoIn_ -%type RelationalExpressionNoIn %type ReturnStatement %type RubyProcExpression -%type RubyProcExpressionNoOA %type RubyProcParameterList_ %type RubyProcParameterList %type RubyProcParameters %type RubyProcParametersOpt %type ShiftExpression -%type ShiftExpressionNoBF %type SingleNameBinding +%type Statement__ %type Statement_ %type Statement %type StatementList @@ -467,26 +433,15 @@ int cylex(YYSTYPE *, cy::location *, void *); %type TryStatement %type UnaryExpression_ %type UnaryExpression -%type UnaryExpressionNoBF %type VariableDeclaration -%type VariableDeclarationNoIn %type VariableDeclarationList_ %type VariableDeclarationList -%type VariableDeclarationListNoIn_ -%type VariableDeclarationListNoIn %type VariableStatement %type WhileStatement %type WithStatement @begin C -%type AssigneeExpressionNoRE -%type CallExpressionNoRE -%type LeftHandSideExpressionNoRE -%type MemberExpressionNoRE -%type NewExpressionNoRE -%type PostfixExpressionNoRE %type UnaryAssigneeExpression -%type UnaryExpressionNoRE @end @begin ObjectiveC @@ -542,38 +497,52 @@ int cylex(YYSTYPE *, cy::location *, void *); %type XMLInitialiser @end -%nonassoc Identifier_ "abstract" "boolean" "break" "byte" "case" "catch" "char" "class" "const" "continue" "debugger" "default" "delete" "do" "double" "each" "enum" "export" "extends" "false" "final" "finally" "float" /*"for"*/ "function" "goto" "implements" "import" /*"in"*/ /*"instanceof"*/ "int" "interface" "let" "long" "namespace" "native" "new" "null" "package" "private" "protected" "public" "return" "short" "super" "static" "switch" "synchronized" "this" "throw" "throws" "transient" "true" "try" "typeof" "var" "void" "volatile" "while" "with" "xml" "yield" +%nonassoc "" +%left "++" "--" %nonassoc "if" %nonassoc "else" -%nonassoc "++" "--" -%nonassoc "(" "[" - -%left "*" "/" "%" -%left "+" "-" -%left "<<" ">>" ">>>" -%left "<" ">" "<=" ">=" "instanceof" "in" -%left "==" "!=" "===" "!==" -%left "&" -%left "^" -%left "|" -%left "&&" -%left "||" - -%right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|=" - %start Program %% /* Lexer State {{{ */ +LexPushInOn + : { driver.in_.push(true); } + ; + +LexPushInOff + : { driver.in_.push(false); } + ; + +LexPopIn + : { driver.in_.pop(); } + ; + LexSetRegExp : { driver.SetCondition(CYDriver::RegExpCondition); } ; + +LexSetStatement + : { + if (yychar == 0) + driver.statement_ = true; + else switch (yychar) { + case cy::parser::token::Function: + yychar = cy::parser::token::Function_; + break; + + case cy::parser::token::OpenBrace: + case cy::parser::token::OpenBrace_: + yychar = cy::parser::token::OpenBrace__; + break; + } + } + ; /* }}} */ -Brace +BRACE : "{" | "\n{" ; @@ -653,11 +622,11 @@ WordOpt | { $$ = NULL; } ; -PrimaryExpressionNo +PrimaryExpression : "@" LiteralNoRE { $$ = CYNew CYBox($2); } | "@" ArrayLiteral { $$ = CYNew CYBox($2); } | "@" ObjectLiteral { $$ = CYNew CYBox($2); } - | "@" "(" Expression ")" { $$ = CYNew CYBox($3); } + | "@" Parenthetical { $$ = CYNew CYBox($2); } ; @end @@ -707,13 +676,9 @@ LiteralNoRE | StringLiteral { $$ = $1; } ; -LiteralRE - : RegularExpressionLiteral { $$ = $1; } - ; - Literal : LiteralNoRE { $$ = $1; } - | LiteralRE { $$ = $1; } + | RegularExpressionLiteral { $$ = $1; } ; NullLiteral @@ -726,35 +691,24 @@ BooleanLiteral ; /* 11.1 Primary Expressions {{{ */ -PrimaryExpression - : LexSetRegExp PrimaryExpressionNoRE { $$ = $2; } - ; - -PrimaryExpressionNoBF - : PrimaryExpressionNo { $$ = $1; } +Parenthetical + : "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; } ; -PrimaryExpressionNoRE - : PrimaryExpressionBF { $$ = $1; } - | PrimaryExpressionNo { $$ = $1; } - ; - -PrimaryExpressionNo +PrimaryExpression : "this" { $$ = $1; } | Identifier { $$ = CYNew CYVariable($1); } - | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; } | Literal { $$ = $1; } | ArrayLiteral { $$ = $1; } - | "(" Expression ")" { $$ = $2; } - ; - -PrimaryExpressionBF - : ObjectLiteral { $$ = $1; } + | ObjectLiteral { $$ = $1; } + | FunctionExpression { $$ = $1; } + | Parenthetical { $$ = $1; } + | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; } ; /* }}} */ -/* 11.1.4 Array Initialiser {{{ */ +/* 11.1.4.1 Array Initialiser {{{ */ ArrayLiteral - : "[" ElementListOpt "]" { $$ = CYNew CYArray($2); } + : "[" LexPushInOff ElementListOpt LexPopIn "]" { $$ = CYNew CYArray($3); } ; Element @@ -778,7 +732,7 @@ ElementListOpt /* }}} */ /* 11.1.5 Object Initialiser {{{ */ ObjectLiteral - : Brace PropertyNameAndValueListOpt "}" { $$ = CYNew CYObject($2); } + : BRACE LexPushInOff PropertyNameAndValueListOpt LexPopIn "}" { $$ = CYNew CYObject($3); } ; PropertyNameAndValueList_ @@ -808,77 +762,40 @@ PropertyName /* 11.2 Left-Hand-Side Expressions {{{ */ MemberAccess - : "[" Expression "]" { $$ = CYNew CYDirectMember(NULL, $2); } + : "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYDirectMember(NULL, $3); } | "." Identifier { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); } | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; } ; MemberExpression_ - : "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($2, $3); } + : MemberExpression { $$ = $1; } + //| "super" { $$ = $1; } ; MemberExpression - : PrimaryExpression { $$ = $1; } - | LexSetRegExp FunctionExpression { $$ = $2; } - | MemberExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } - | LexSetRegExp MemberExpression_ { $$ = $2; } - ; - -MemberExpressionNoBF - : PrimaryExpressionNoBF { $$ = $1; } - | MemberExpressionNoBF { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } - | MemberExpression_ { $$ = $1; } - ; - -@begin C -MemberExpressionNoRE - : PrimaryExpressionNoRE { $$ = $1; } - | FunctionExpression { $$ = $1; } - | MemberExpressionNoRE { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } - | MemberExpression_ { $$ = $1; } - ; -@end - -NewExpression_ - : "new" NewExpression { $$ = CYNew cy::Syntax::New($2, NULL); } + : LexSetRegExp PrimaryExpression { $$ = $2; } + | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } + | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); } ; NewExpression : MemberExpression { $$ = $1; } - | LexSetRegExp NewExpression_ { $$ = $2; } - ; - -NewExpressionNoBF - : MemberExpressionNoBF { $$ = $1; } - | NewExpression_ { $$ = $1; } + | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); } ; -@begin C -NewExpressionNoRE - : MemberExpressionNoRE { $$ = $1; } - | NewExpression_ { $$ = $1; } +CallExpression_ + : MemberExpression_ + | CallExpression ; -@end CallExpression - : MemberExpression Arguments { $$ = CYNew CYCall($1, $2); } - | CallExpression Arguments { $$ = CYNew CYCall($1, $2); } + : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); } | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } ; -CallExpressionNoBF - : MemberExpressionNoBF Arguments { $$ = CYNew CYCall($1, $2); } - | CallExpressionNoBF Arguments { $$ = CYNew CYCall($1, $2); } - | CallExpressionNoBF { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } - ; - -@begin C -CallExpressionNoRE - : MemberExpressionNoRE Arguments { $$ = CYNew CYCall($1, $2); } - | CallExpressionNoRE Arguments { $$ = CYNew CYCall($1, $2); } - | CallExpressionNoRE { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; } +Arguments + : "(" LexPushInOff ArgumentListOpt LexPopIn ")" { $$ = $3; } ; -@end ArgumentList_ : "," ArgumentList { $$ = $2; } @@ -894,47 +811,17 @@ ArgumentListOpt | LexSetRegExp { $$ = NULL; } ; -Arguments - : "(" ArgumentListOpt ")" { $$ = $2; } - ; - LeftHandSideExpression : NewExpression { $$ = $1; } | CallExpression { $$ = $1; } ; - -LeftHandSideExpressionNoBF - : NewExpressionNoBF { $$ = $1; } - | CallExpressionNoBF { $$ = $1; } - ; - -@begin C -LeftHandSideExpressionNoRE - : NewExpressionNoRE { $$ = $1; } - | CallExpressionNoRE { $$ = $1; } - ; -@end /* }}} */ /* 11.3 Postfix Expressions {{{ */ PostfixExpression - : AssigneeExpression { $$ = $1; } + : %prec "" LeftHandSideExpression { $$ = $1; } | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); } | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); } ; - -PostfixExpressionNoBF - : AssigneeExpressionNoBF { $$ = $1; } - | LeftHandSideExpressionNoBF "++" { $$ = CYNew CYPostIncrement($1); } - | LeftHandSideExpressionNoBF "--" { $$ = CYNew CYPostDecrement($1); } - ; - -@begin C -PostfixExpressionNoRE - : AssigneeExpressionNoRE { $$ = $1; } - | LeftHandSideExpressionNoRE "++" { $$ = CYNew CYPostIncrement($1); } - | LeftHandSideExpressionNoRE "--" { $$ = CYNew CYPostDecrement($1); } - ; -@end /* }}} */ /* 11.4 Unary Operators {{{ */ UnaryExpression_ @@ -955,18 +842,6 @@ UnaryExpression : PostfixExpression { $$ = $1; } | LexSetRegExp UnaryExpression_ { $$ = $2; } ; - -UnaryExpressionNoBF - : PostfixExpressionNoBF { $$ = $1; } - | UnaryExpression_ { $$ = $1; } - ; - -@begin C -UnaryExpressionNoRE - : PostfixExpressionNoRE { $$ = $1; } - | UnaryExpression_ { $$ = $1; } - ; -@end /* }}} */ /* 11.5 Multiplicative Operators {{{ */ MultiplicativeExpression @@ -975,13 +850,6 @@ MultiplicativeExpression | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); } | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); } ; - -MultiplicativeExpressionNoBF - : UnaryExpressionNoBF { $$ = $1; } - | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); } - | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); } - | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); } - ; /* }}} */ /* 11.6 Additive Operators {{{ */ AdditiveExpression @@ -989,12 +857,6 @@ AdditiveExpression | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); } | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); } ; - -AdditiveExpressionNoBF - : MultiplicativeExpressionNoBF { $$ = $1; } - | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); } - | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); } - ; /* }}} */ /* 11.7 Bitwise Shift Operators {{{ */ ShiftExpression @@ -1003,41 +865,20 @@ ShiftExpression | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); } | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); } ; - -ShiftExpressionNoBF - : AdditiveExpressionNoBF { $$ = $1; } - | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); } - | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); } - | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); } - ; /* }}} */ /* 11.8 Relational Operators {{{ */ RelationalExpression_ - : RelationalExpressionNoIn_ { $$ = $1; } - | "in" ShiftExpression { $$ = CYNew CYIn(NULL, $2); } - ; - -RelationalExpression - : ShiftExpression { $$ = $1; } - | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; } - ; - -RelationalExpressionNoIn_ - : "<" ShiftExpression { $$ = CYNew CYLess(NULL, $2); } - | ">" ShiftExpression { $$ = CYNew CYGreater(NULL, $2); } - | "<=" ShiftExpression { $$ = CYNew CYLessOrEqual(NULL, $2); } - | ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual(NULL, $2); } - | "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf(NULL, $2); } - ; - -RelationalExpressionNoIn : ShiftExpression { $$ = $1; } - | RelationalExpressionNoIn RelationalExpressionNoIn_ { $2->SetLeft($1); $$ = $2; } ; -RelationalExpressionNoBF - : ShiftExpressionNoBF { $$ = $1; } - | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; } +RelationalExpression + : RelationalExpression_ { $$ = $1; } + | RelationalExpression "<" RelationalExpression_ { $$ = CYNew CYLess($1, $3); } + | RelationalExpression ">" RelationalExpression_ { $$ = CYNew CYGreater($1, $3); } + | RelationalExpression "<=" RelationalExpression_ { $$ = CYNew CYLessOrEqual($1, $3); } + | RelationalExpression ">=" RelationalExpression_ { $$ = CYNew CYGreaterOrEqual($1, $3); } + | RelationalExpression "instanceof" RelationalExpression_ { $$ = CYNew CYInstanceOf($1, $3); } + | RelationalExpression "in" RelationalExpression_ { $$ = CYNew CYIn($1, $3); } ; /* }}} */ /* 11.9 Equality Operators {{{ */ @@ -1048,22 +889,6 @@ EqualityExpression | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); } | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); } ; - -EqualityExpressionNoIn - : RelationalExpressionNoIn { $$ = $1; } - | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = CYNew CYEqual($1, $3); } - | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = CYNew CYNotEqual($1, $3); } - | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = CYNew CYIdentical($1, $3); } - | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = CYNew CYNotIdentical($1, $3); } - ; - -EqualityExpressionNoBF - : RelationalExpressionNoBF { $$ = $1; } - | EqualityExpressionNoBF "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); } - | EqualityExpressionNoBF "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); } - | EqualityExpressionNoBF "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); } - | EqualityExpressionNoBF "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); } - ; /* }}} */ /* 11.10 Binary Bitwise Operators {{{ */ BitwiseANDExpression @@ -1071,45 +896,15 @@ BitwiseANDExpression | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); } ; -BitwiseANDExpressionNoIn - : EqualityExpressionNoIn { $$ = $1; } - | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = CYNew CYBitwiseAnd($1, $3); } - ; - -BitwiseANDExpressionNoBF - : EqualityExpressionNoBF { $$ = $1; } - | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); } - ; - BitwiseXORExpression : BitwiseANDExpression { $$ = $1; } | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); } ; -BitwiseXORExpressionNoIn - : BitwiseANDExpressionNoIn { $$ = $1; } - | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = CYNew CYBitwiseXOr($1, $3); } - ; - -BitwiseXORExpressionNoBF - : BitwiseANDExpressionNoBF { $$ = $1; } - | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); } - ; - BitwiseORExpression : BitwiseXORExpression { $$ = $1; } | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); } ; - -BitwiseORExpressionNoIn - : BitwiseXORExpressionNoIn { $$ = $1; } - | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = CYNew CYBitwiseOr($1, $3); } - ; - -BitwiseORExpressionNoBF - : BitwiseXORExpressionNoBF { $$ = $1; } - | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); } - ; /* }}} */ /* 11.11 Binary Logical Operators {{{ */ LogicalANDExpression @@ -1117,45 +912,15 @@ LogicalANDExpression | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); } ; -LogicalANDExpressionNoIn - : BitwiseORExpressionNoIn { $$ = $1; } - | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = CYNew CYLogicalAnd($1, $3); } - ; - -LogicalANDExpressionNoBF - : BitwiseORExpressionNoBF { $$ = $1; } - | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); } - ; - LogicalORExpression : LogicalANDExpression { $$ = $1; } | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); } ; - -LogicalORExpressionNoIn - : LogicalANDExpressionNoIn { $$ = $1; } - | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = CYNew CYLogicalOr($1, $3); } - ; - -LogicalORExpressionNoBF - : LogicalANDExpressionNoBF { $$ = $1; } - | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); } - ; /* }}} */ /* 11.12 Conditional Operator ( ? : ) {{{ */ ConditionalExpression : LogicalORExpression { $$ = $1; } - | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = CYNew CYCondition($1, $3, $5); } - ; - -ConditionalExpressionNoIn - : LogicalORExpressionNoIn { $$ = $1; } - | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = CYNew CYCondition($1, $3, $5); } - ; - -ConditionalExpressionNoBF - : LogicalORExpressionNoBF { $$ = $1; } - | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = CYNew CYCondition($1, $3, $5); } + | LogicalORExpression "?" LexPushInOff AssignmentExpression LexPopIn ":" AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); } ; /* }}} */ /* 11.13 Assignment Operators {{{ */ @@ -1174,51 +939,15 @@ AssignmentExpression_ | "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign(NULL, $2); } ; -AssigneeExpression - : LeftHandSideExpression { $$ = $1; } -@begin C - | LexSetRegExp UnaryAssigneeExpression { $$ = $2; } -@end - ; - -AssigneeExpressionNoBF - : LeftHandSideExpressionNoBF { $$ = $1; } @begin C - | UnaryAssigneeExpression { $$ = $1; } -@end - ; - -@begin C -AssigneeExpressionNoRE - : LeftHandSideExpressionNoRE { $$ = $1; } - | UnaryAssigneeExpression { $$ = $1; } +LeftHandSideExpression + : LexSetRegExp UnaryAssigneeExpression { $$ = $2; } ; @end AssignmentExpression : ConditionalExpression { $$ = $1; } - | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } - ; - -AssignmentExpressionNoIn - : ConditionalExpressionNoIn { $$ = $1; } - | AssigneeExpression "=" AssignmentExpressionNoIn { $$ = CYNew CYAssign($1, $3); } - | AssigneeExpression "*=" AssignmentExpressionNoIn { $$ = CYNew CYMultiplyAssign($1, $3); } - | AssigneeExpression "/=" AssignmentExpressionNoIn { $$ = CYNew CYDivideAssign($1, $3); } - | AssigneeExpression "%=" AssignmentExpressionNoIn { $$ = CYNew CYModulusAssign($1, $3); } - | AssigneeExpression "+=" AssignmentExpressionNoIn { $$ = CYNew CYAddAssign($1, $3); } - | AssigneeExpression "-=" AssignmentExpressionNoIn { $$ = CYNew CYSubtractAssign($1, $3); } - | AssigneeExpression "<<=" AssignmentExpressionNoIn { $$ = CYNew CYShiftLeftAssign($1, $3); } - | AssigneeExpression ">>=" AssignmentExpressionNoIn { $$ = CYNew CYShiftRightSignedAssign($1, $3); } - | AssigneeExpression ">>>=" AssignmentExpressionNoIn { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); } - | AssigneeExpression "&=" AssignmentExpressionNoIn { $$ = CYNew CYBitwiseAndAssign($1, $3); } - | AssigneeExpression "^=" AssignmentExpressionNoIn { $$ = CYNew CYBitwiseXOrAssign($1, $3); } - | AssigneeExpression "|=" AssignmentExpressionNoIn { $$ = CYNew CYBitwiseOrAssign($1, $3); } - ; - -AssignmentExpressionNoBF - : ConditionalExpressionNoBF { $$ = $1; } - | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } + | LeftHandSideExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } ; /* }}} */ /* 11.14 Comma Operator {{{ */ @@ -1235,32 +964,13 @@ ExpressionOpt : Expression { $$ = $1; } | LexSetRegExp { $$ = NULL; } ; - -ExpressionNoIn_ - : "," ExpressionNoIn { $$ = CYNew CYCompound($2); } - | { $$ = NULL; } - ; - -ExpressionNoIn - : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } - ; - -ExpressionNoInOpt - : ExpressionNoIn { $$ = $1; } - | LexSetRegExp { $$ = NULL; } - ; - -ExpressionNoBF - : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } - ; /* }}} */ /* 12 Statements {{{ */ -Statement_ +Statement__ : Block { $$ = $1; } | VariableStatement { $$ = $1; } | EmptyStatement { $$ = $1; } - | ExpressionStatement { $$ = $1; } | IfStatement { $$ = $1; } | BreakableStatement { $$ = $1; } | ContinueStatement { $$ = $1; } @@ -1273,15 +983,28 @@ Statement_ | DebuggerStatement { $$ = $1; } ; +Statement_ + : LexSetRegExp Statement__ { $$ = $2; } + | ExpressionStatement { $$ = $1; } + ; + Statement - : LexSetRegExp Statement_ { $$ = $2; } + : LexSetStatement Statement_ { $$ = $2; } ; -Declaration +Declaration__ : FunctionDeclaration { $$ = $1; } | LexicalDeclaration { $$ = $1; } ; +Declaration_ + : LexSetRegExp Declaration__ { $$ = $2; } + ; + +Declaration + : LexSetStatement Declaration_ { $$ = $2; } + ; + BreakableStatement : IterationStatement { $$ = $1; } | SwitchStatement { $$ = $1; } @@ -1289,11 +1012,11 @@ BreakableStatement /* }}} */ /* 12.1 Block {{{ */ Block_ - : Brace StatementListOpt "}" { $$ = $2; } + : BRACE StatementListOpt "}" { $$ = $2; } ; Block - : Block_ { $$ = CYNew CYBlock($1); } + : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); } ; StatementList @@ -1307,7 +1030,7 @@ StatementListOpt StatementListItem : Statement { $$ = $1; } - | LexSetRegExp Declaration { $$ = $2; } + | Declaration { $$ = $1; } ; /* }}} */ /* 12.2 Declarations {{{ */ @@ -1341,25 +1064,11 @@ VariableDeclarationList : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); } ; -VariableDeclarationListNoIn_ - : "," VariableDeclarationListNoIn { $$ = $2; } - | { $$ = NULL; } - ; - -VariableDeclarationListNoIn - : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = CYNew CYDeclarations($1, $2); } - ; - VariableDeclaration : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); } // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); } ; -VariableDeclarationNoIn - : BindingIdentifier InitialiserNoInOpt { $$ = CYNew CYDeclaration($1, $2); } - // XXX: | BindingPattern InitialiserNoIn { $$ = CYNew CYDeclaration($1, $2); } - ; - Initialiser : "=" AssignmentExpression { $$ = $2; } ; @@ -1368,15 +1077,6 @@ InitialiserOpt : Initialiser { $$ = $1; } | { $$ = NULL; } ; - -InitialiserNoIn - : "=" AssignmentExpressionNoIn { $$ = $2; } - ; - -InitialiserNoInOpt - : InitialiserNoIn { $$ = $1; } - | { $$ = NULL; } - ; /* }}} */ /* 12.2.4 Destructuring Binding Patterns {{{ */ // XXX: * @@ -1396,7 +1096,7 @@ EmptyStatement /* }}} */ /* 12.4 Expression Statement {{{ */ ExpressionStatement - : ExpressionNoBF Terminator { $$ = CYNew CYExpress($1); } + : Expression Terminator { $$ = CYNew CYExpress($1); } ; /* }}} */ /* 12.5 The if Statement {{{ */ @@ -1430,22 +1130,22 @@ WhileStatement /* }}} */ /* 12.6.3 The for Statement {{{ */ ForStatement - : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($3, $5, $7, $9); } + : "for" "(" LexPushInOn ForStatementInitialiser LexPopIn ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); } ; ForStatementInitialiser - : ExpressionNoInOpt { $$ = $1; } - | LexSetRegExp "var" VariableDeclarationListNoIn { $$ = CYNew CYForDeclarations($3); } + : ExpressionOpt { $$ = $1; } + | LexSetRegExp "var" VariableDeclarationList { $$ = CYNew CYForDeclarations($3); } ; /* }}} */ /* 12.6.4 The for-in Statement {{{ */ ForInStatement - : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = CYNew CYForIn($3, $5, $7); } + : "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); } ; ForInStatementInitialiser : LeftHandSideExpression { $$ = $1; } - | LexSetRegExp "var" VariableDeclarationNoIn { $$ = $3; } + | LexSetRegExp "var" VariableDeclaration { $$ = $3; } ; /* }}} */ @@ -1476,7 +1176,7 @@ SwitchStatement ; CaseBlock - : Brace CaseClausesOpt "}" { $$ = $2; } + : BRACE CaseClausesOpt "}" { $$ = $2; } ; CaseClause @@ -1526,11 +1226,11 @@ DebuggerStatement /* 13 Function Definition {{{ */ FunctionDeclaration - : "function" Identifier "(" FormalParameterListOpt ")" Brace FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); } + : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); } ; FunctionExpression - : "function" IdentifierOpt "(" FormalParameterListOpt ")" Brace FunctionBody "}" { $$ = CYNew CYFunctionExpression($2, $4, $7); } + : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYFunctionExpression($2, $5, $10); } ; FormalParameterList_ @@ -1578,8 +1278,8 @@ ProgramBodyOpt @begin ObjectiveC /* Cycript (Objective-C): @class Declaration {{{ */ ClassSuperOpt - /* XXX: why the hell did I choose MemberExpressionNoBF? */ - : ":" LexSetRegExp MemberExpressionNoBF { $$ = $3; } + /* XXX: why the hell did I choose MemberExpression? */ + : ":" LexSetRegExp MemberExpression { $$ = $3; } | { $$ = NULL; } ; @@ -1588,7 +1288,7 @@ ClassField ; ClassFieldList - : Brace ClassFieldListOpt "}" { $$ = NULL; } + : BRACE ClassFieldListOpt "}" { $$ = NULL; } ; ClassFieldListOpt @@ -1626,7 +1326,7 @@ MessageParameters ; ClassMessageDeclaration - : MessageScope TypeOpt MessageParameters Brace FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); } + : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); } ; ClassMessageDeclarationListOpt @@ -1661,11 +1361,11 @@ ClassProtocolListOpt ; ClassExpression - : "@implementation" ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassExpression($2, $3, $4, $5, $6); } + : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); } ; ClassStatement - : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } + : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); } ; CategoryName @@ -1673,14 +1373,14 @@ CategoryName ; CategoryStatement - : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); } + : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); } ; -PrimaryExpressionBF +PrimaryExpression : ClassExpression { $$ = $1; } ; -Statement_ +Statement__ : ClassStatement { $$ = $1; } | CategoryStatement { $$ = $1; } ; @@ -1711,8 +1411,8 @@ SelectorList ; MessageExpression - : "[" AssignmentExpression { driver.contexts_.push_back($2); } SelectorList "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($2, $4); } - | "[" LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" { $$ = CYNew CYSendSuper($5); } + : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList LexPopIn "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); } + | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList LexPopIn "]" { $$ = CYNew CYSendSuper($6); } ; SelectorExpression_ @@ -1729,9 +1429,9 @@ SelectorExpressionOpt | { $$ = NULL; } ; -PrimaryExpressionNo +PrimaryExpression : MessageExpression { $$ = $1; } - | "@selector" "(" SelectorExpression ")" { $$ = CYNew CYSelector($3); } + | "@selector" "(" LexPushInOff SelectorExpression LexPopIn ")" { $$ = CYNew CYSelector($4); } ; /* }}} */ /* Cycript (Objective-C): @import Directive {{{ */ @@ -1756,7 +1456,7 @@ StatementListItem @begin C /* Cycript (C): Pointer Indirection/Addressing {{{ */ UnaryAssigneeExpression - : "*" UnaryExpressionNoRE { $$ = CYNew CYIndirect($2); } + : "*" UnaryExpression { $$ = CYNew CYIndirect($2); } ; UnaryExpression_ @@ -1772,7 +1472,7 @@ MemberAccess @end /* YUI: Documentation Comments {{{ */ -Statement_ +Statement__ : Comment { $$ = $1; } ; /* }}} */ @@ -1823,7 +1523,7 @@ XMLMarkup ; /* }}} */ /* 11.1 Primary Expressions {{{ */ -PrimaryExpressionNo +PrimaryExpression : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); } | XMLInitialiser { $$ = $1; } | XMLListInitialiser { $$ = $1; } @@ -1842,7 +1542,7 @@ AttributeIdentifier PropertySelector_ : PropertySelector { $$ = $1; } - | "[" Expression "]" { $$ = CYNew CYSelector($2); } + | "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYSelector($3); } ; PropertySelector @@ -1872,8 +1572,8 @@ XMLInitialiser ; XMLElement - : "<" XMLTagContent "/>" LexPop - | "<" XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "" LexPop + : "<" LexPushInOff XMLTagContent LexPop LexPopIn "/>" + | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "" ; XMLTagContent @@ -1881,7 +1581,7 @@ XMLTagContent ; XMLExpression - : Brace LexPushRegExp Expression "}" LexPop + : BRACE LexPushRegExp Expression LexPop "}" ; XMLTagName @@ -1922,7 +1622,7 @@ XMLElementContentOpt /* }}} */ /* 11.1.5 XMLList Initialiser {{{ */ XMLListInitialiser - : "<>" LexPushXMLContent XMLElementContent "" LexPop { $$ = CYNew CYXMLList($3); } + : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop LexPopIn "" { $$ = CYNew CYXMLList($4); } ; /* }}} */ /* 11.2 Left-Hand-Side Expressions {{{ */ @@ -1942,7 +1642,7 @@ MemberAccess : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); } ; -Statement_ +Statement__ : DefaultXMLNamespaceStatement { $$ = $1; } ; */ /* }}} */ @@ -1960,8 +1660,8 @@ IfComprehension ; ForComprehension - : "for" "(" Identifier "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); } - | "for" "each" "(" Identifier "in" Expression ")" { $$ = CYNew CYForEachInComprehension($4, $6); } + : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); } + | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForEachInComprehension($5, $8); } ; ComprehensionList @@ -1974,30 +1674,21 @@ ComprehensionListOpt | { $$ = NULL; } ; -PrimaryExpressionNo - : "[" AssignmentExpression ComprehensionList "]" { $$ = CYNew CYArrayComprehension($2, $3); } +PrimaryExpression + : "[" LexPushInOff AssignmentExpression ComprehensionList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); } ; /* }}} */ /* JavaScript 1.7: for each {{{ */ ForInStatement - : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = CYNew CYForEachIn($4, $6, $8); } + : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForEachIn($5, $8, $10); } ; /* }}} */ -/* JavaScript 1.7: let Expressions {{{ */ -/*LetExpression - : "let" "(" VariableDeclarationList ")" Expression { $$ = CYNew CYLetExpression($3, $5); } - ; - -MemberExpression - : LexSetRegExp LetExpression { $$ = $2; } - ;*/ -/* }}} */ /* JavaScript 1.7: let Statements {{{ */ LetStatement : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); } ; -Statement_ +Statement__ : LetStatement ; /* }}} */ @@ -2027,27 +1718,13 @@ RubyProcExpression : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); } ; -RubyProcExpressionNoOA - : "{" RubyProcParameters StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); } - ; - -PrimaryExpressionNo - : RubyProcExpressionNoOA { $$ = $1; } - ; - -LeftHandSideExpression - : LeftHandSideExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); } - ; - -LeftHandSideExpressionNoBF - : LeftHandSideExpressionNoBF RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); } +PrimaryExpression + : "{" LexPushInOff RubyProcParameters StatementListOpt LexPopIn "}" { $$ = CYNew CYRubyProc($3, $4); } ; -@begin C -LeftHandSideExpressionNoRE - : LeftHandSideExpressionNoRE RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); } +CallExpression + : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); } ; -@end /* }}} */ %% diff --git a/Parser.cpp b/Parser.cpp index 8646c7c..2e951f3 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -28,6 +28,7 @@ CYRange WordEndRange_ (0x3ff001000000000LLU, 0x7fffffe87fffffeLLU); // A-Za-z_$ CYDriver::CYDriver(const std::string &filename) : state_(CYClear), + statement_(false), data_(NULL), size_(0), file_(NULL), @@ -38,6 +39,7 @@ CYDriver::CYDriver(const std::string &filename) : context_(NULL), mode_(AutoNone) { + in_.push(false); ScannerInit(); } diff --git a/Parser.hpp b/Parser.hpp index a5d1148..d809e77 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -447,9 +448,12 @@ enum CYState { class CYDriver { public: - CYState state_; void *scanner_; + CYState state_; + bool statement_; + std::stack in_; + const char *data_; size_t size_; FILE *file_; -- 2.45.2