CYBoolean *boolean_;
CYClause *clause_;
CYCatch *catch_;
- CYClass *class_;
CYClassName *className_;
CYComprehension *comprehension_;
CYCompound *compound_;
CYExpression *expression_;
CYFalse *false_;
CYField *field_;
+ CYFinally *finally_;
CYForInitialiser *for_;
CYForInInitialiser *forin_;
CYFunctionParameter *functionParameter_;
CYMessageParameter *messageParameter_;
CYNull *null_;
CYNumber *number_;
+ CYProgram *program_;
CYProperty *property_;
CYPropertyName *propertyName_;
CYSelectorPart *selector_;
- CYSource *source_;
CYStatement *statement_;
CYString *string_;
CYThis *this_;
%parse-param { CYDriver &driver }
%lex-param { void *scanner }
+%token At "@"
+
%token Ampersand "&"
%token AmpersandAmpersand "&&"
%token AmpersandEqual "&="
%type <clause_> CaseClausesOpt
%type <catch_> CatchOpt
%type <statement_> CategoryStatement
-%type <class_> ClassDefinition
+%type <expression_> ClassExpression
%type <message_> ClassMessageDeclaration
%type <message_> ClassMessageDeclarationListOpt
%type <className_> ClassName
%type <className_> ClassNameOpt
+%type <statement_> ClassStatement
%type <expression_> ClassSuperOpt
%type <field_> ClassFieldList
%type <comprehension_> ComprehensionList
%type <compound_> ExpressionNoIn_
%type <expression_> ExpressionNoInOpt
%type <statement_> ExpressionStatement
-%type <statement_> FinallyOpt
+%type <finally_> FinallyOpt
%type <comprehension_> ForComprehension
%type <statement_> ForStatement
%type <for_> ForStatementInitialiser
%type <forin_> ForInStatementInitialiser
%type <functionParameter_> FormalParameterList
%type <functionParameter_> FormalParameterList_
-%type <source_> FunctionBody
-%type <source_> FunctionDeclaration
+%type <statement_> FunctionBody
+%type <statement_> FunctionDeclaration
%type <expression_> FunctionExpression
%type <identifier_> Identifier
%type <identifier_> IdentifierOpt
%type <expression_> PrimaryExpression
%type <expression_> PrimaryExpression_
%type <expression_> PrimaryExpressionNoBF
-%type <source_> Program
+%type <statement_> Program
%type <propertyName_> PropertyName
%type <property_> PropertyNameAndValueList
%type <property_> PropertyNameAndValueList_
%type <selector_> SelectorExpressionOpt
%type <expression_> ShiftExpression
%type <expression_> ShiftExpressionNoBF
-%type <source_> SourceElement
-%type <source_> SourceElements
+%type <statement_> SourceElement
+%type <statement_> SourceElements
%type <statement_> Statement
+%type <statement_> Statement_
%type <statement_> StatementList
%type <statement_> StatementListOpt
%type <statement_> SwitchStatement
%%
-TerminatorOpt
+StrictSemi
+ : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
+ ;
+
+Terminator_
: ";"
- | "\n"
- | error { yyerrok; driver.errors_.pop_back(); }
+ | "\n" StrictSemi
+ ;
+
+TerminatorOpt
+ : Terminator_
+ | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
;
Terminator
- : ";"
- | "\n"
- | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } }
+ : Terminator_
+ | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
;
/*CommaOpt
| "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
| "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
| "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
- | "+" UnaryExpression { $$ = $2; }
+ | "+" UnaryExpression { $$ = new(driver.pool_) CYAffirm($2); }
| "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); }
| "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); }
| "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); }
/* }}} */
/* 12 Statements {{{ */
-Statement
+Statement_
: Block { $$ = $1; }
| VariableStatement { $$ = $1; }
| EmptyStatement { $$ = $1; }
| ThrowStatement { $$ = $1; }
| TryStatement { $$ = $1; }
;
+
+Statement
+ : Statement_ { $$ = $1; }
+ ;
/* }}} */
/* 12.1 Block {{{ */
Block_
/* }}} */
/* 12.12 Labelled Statements {{{ */
LabelledStatement
- : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; }
+ : Identifier ":" Statement { $$ = new(driver.pool_) CYLabel($1, $3); }
;
/* }}} */
/* 12.13 The throw Statement {{{ */
;
FinallyOpt
- : "finally" Block_ { $$ = $2; }
+ : "finally" Block_ { $$ = new(driver.pool_) CYFinally($2); }
| { $$ = NULL; }
;
/* }}} */
/* 13 Function Definition {{{ */
FunctionDeclaration
- : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunction($2, $4, $7); }
+ : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); }
;
FunctionExpression
- : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYLambda($2, $4, $7); }
+ : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); }
;
FormalParameterList_
/* }}} */
/* 14 Program {{{ */
Program
- : SourceElements { driver.source_ = $1; }
+ : SourceElements { driver.program_ = new(driver.pool_) CYProgram($1); }
;
SourceElements
;
SourceElement
- : Statement { $$ = $1; }
+ : Statement_ { $$ = $1; }
| FunctionDeclaration { $$ = $1; }
;
/* }}} */
| { $$ = NULL; }
;
-ClassDefinition
- : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClass($2, $3, $4, $5); }
+ClassExpression
+ : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassExpression($2, $3, $4, $5); }
+ ;
+
+ClassStatement
+ : "@class" ClassName ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassStatement($2, $3, $4, $5); }
;
CategoryStatement
;
PrimaryExpression
- : ClassDefinition { $$ = $1; }
+ : ClassExpression { $$ = $1; }
;
-Statement
- : ClassDefinition { $$ = $1; }
+Statement_
+ : ClassStatement { $$ = $1; }
| CategoryStatement { $$ = $1; }
;
/* }}} */
;
MemberAccess
- : "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); }
+ : "->" "[" Expression "]" { $$ = new(driver.pool_) CYIndirectMember(NULL, $3); }
+ | "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); }
;
/* }}} */
/* ECMAScript5: Object Literal Trailing Comma {{{ */
: "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForEachIn($4, $6, $8); }
;
/* }}} */
-/* JavaScript 1.7: Let Statements {{{ *//*
+/* JavaScript 1.7: let Statements {{{ *//*
LetStatement
: "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); }
;
: LetStatement
;
*//* }}} */
+/* JavaScript FTW: Function Statements {{{ */
+Statement
+ : FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $1; }
+ ;
+/* }}} */
%%