2 #include "Cycript.tab.hh"
 
   3 int cylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
 
   4 #define scanner driver->scanner_
 
  12     CYArgument *argument_;
 
  16     CYDeclaration *declaration_;
 
  17     CYDeclarations *declarations_;
 
  19     CYExpression *expression_;
 
  21     CYForInitialiser *for_;
 
  22     CYForInInitialiser *forin_;
 
  23     CYIdentifier *identifier_;
 
  28     CYParameter *parameter_;
 
  29     CYProperty *property_;
 
  31     CYStatement *statement_;
 
  49 %parse-param { CYParser *driver }
 
  50 %lex-param { void *scanner }
 
  53 %token AmpersandAmpersand "&&"
 
  54 %token AmpersandEqual "&="
 
  56 %token CarrotEqual "^="
 
  58 %token EqualEqual "=="
 
  59 %token EqualEqualEqual "==="
 
  60 %token Exclamation "!"
 
  61 %token ExclamationEqual "!="
 
  62 %token ExclamationEqualEqual "!=="
 
  64 %token HyphenEqual "-="
 
  65 %token HyphenHyphen "--"
 
  66 %token HyphenRight "->"
 
  70 %token LeftLeftEqual "<<="
 
  72 %token PercentEqual "%="
 
  81 %token RightEqual ">="
 
  82 %token RightRight ">>"
 
  83 %token RightRightEqual ">>="
 
  84 %token RightRightRight ">>>"
 
  85 %token RightRightRightEqual ">>>="
 
  87 %token SlashEqual "/="
 
 101 %token CloseBrace "}"
 
 103 %token OpenBracket "["
 
 104 %token CloseBracket "]"
 
 106 %token <word_> Break "break"
 
 107 %token <word_> Case "case"
 
 108 %token <word_> Catch "catch"
 
 109 %token <word_> Continue "continue"
 
 110 %token <word_> Default "default"
 
 111 %token <word_> Delete "delete"
 
 112 %token <word_> Do "do"
 
 113 %token <word_> Else "else"
 
 114 %token <false_> False "false"
 
 115 %token <word_> Finally "finally"
 
 116 %token <word_> For "for"
 
 117 %token <word_> Function "function"
 
 118 %token <word_> If "if"
 
 119 %token <word_> In "in"
 
 120 %token <word_> InstanceOf "instanceof"
 
 121 %token <word_> New "new"
 
 122 %token <null_> Null "null"
 
 123 %token <word_> Return "return"
 
 124 %token <word_> Switch "switch"
 
 125 %token <this_> This "this"
 
 126 %token <word_> Throw "throw"
 
 127 %token <true_> True "true"
 
 128 %token <word_> Try "try"
 
 129 %token <word_> TypeOf "typeof"
 
 130 %token <word_> Var "var"
 
 131 %token <word_> Void "void"
 
 132 %token <word_> While "while"
 
 133 %token <word_> With "with"
 
 135 %token <identifier_> Identifier
 
 136 %token <number_> NumericLiteral
 
 137 %token <string_> StringLiteral
 
 139 %type <expression_> AdditiveExpression
 
 140 %type <argument_> ArgumentList
 
 141 %type <argument_> ArgumentList_
 
 142 %type <argument_> ArgumentListOpt
 
 143 %type <argument_> Arguments
 
 144 %type <literal_> ArrayLiteral
 
 145 %type <expression_> AssignmentExpression
 
 146 %type <expression_> BitwiseANDExpression
 
 147 %type <statement_> Block
 
 148 %type <boolean_> BooleanLiteral
 
 149 %type <expression_> BitwiseORExpression
 
 150 %type <expression_> BitwiseXORExpression
 
 151 %type <statement_> BreakStatement
 
 152 %type <expression_> CallExpression
 
 153 %type <clause_> CaseBlock
 
 154 %type <clause_> CaseClause
 
 155 %type <clause_> CaseClausesOpt
 
 156 %type <catch_> CatchOpt
 
 157 %type <expression_> ConditionalExpression
 
 158 %type <statement_> ContinueStatement
 
 159 %type <clause_> DefaultClause
 
 160 %type <statement_> DoWhileStatement
 
 161 %type <expression_> Element
 
 162 %type <element_> ElementList
 
 163 %type <element_> ElementList_
 
 164 %type <statement_> ElseStatementOpt
 
 165 %type <statement_> EmptyStatement
 
 166 %type <expression_> EqualityExpression
 
 167 %type <expression_> Expression
 
 168 %type <expression_> Expression_
 
 169 %type <expression_> ExpressionOpt
 
 170 %type <statement_> ExpressionStatement
 
 171 %type <statement_> FinallyOpt
 
 172 %type <statement_> ForStatement
 
 173 %type <for_> ForStatementInitialiser
 
 174 %type <statement_> ForInStatement
 
 175 %type <forin_> ForInStatementInitialiser
 
 176 %type <parameter_> FormalParameterList
 
 177 %type <parameter_> FormalParameterList_
 
 178 %type <source_> FunctionBody
 
 179 %type <source_> FunctionDeclaration
 
 180 %type <expression_> FunctionExpression
 
 181 %type <identifier_> IdentifierOpt
 
 182 %type <statement_> IfStatement
 
 183 %type <expression_> Initialiser
 
 184 %type <expression_> InitialiserOpt
 
 185 %type <statement_> IterationStatement
 
 186 %type <statement_> LabelledStatement
 
 187 %type <expression_> LeftHandSideExpression
 
 188 %type <literal_> Literal
 
 189 %type <expression_> LogicalANDExpression
 
 190 %type <expression_> LogicalORExpression
 
 191 %type <expression_> MemberExpression
 
 192 %type <expression_> MultiplicativeExpression
 
 193 %type <expression_> NewExpression
 
 194 %type <null_> NullLiteral
 
 195 %type <literal_> ObjectLiteral
 
 196 %type <expression_> MessageExpression
 
 197 %type <expression_> PostfixExpression
 
 198 %type <expression_> PrimaryExpression
 
 199 %type <source_> Program
 
 200 %type <name_> PropertyName
 
 201 %type <property_> PropertyNameAndValueList
 
 202 %type <property_> PropertyNameAndValueList_
 
 203 %type <property_> PropertyNameAndValueListOpt
 
 204 %type <expression_> RelationalExpression
 
 205 %type <statement_> ReturnStatement
 
 206 %type <argument_> SelectorCall
 
 207 %type <argument_> SelectorCall_
 
 208 %type <argument_> SelectorList
 
 209 %type <expression_> ShiftExpression
 
 210 %type <source_> SourceElement
 
 211 %type <source_> SourceElements
 
 212 %type <statement_> Statement
 
 213 %type <statement_> StatementListOpt
 
 214 %type <statement_> SwitchStatement
 
 215 %type <statement_> ThrowStatement
 
 216 %type <statement_> TryStatement
 
 217 %type <expression_> UnaryExpression
 
 218 %type <declaration_> VariableDeclaration
 
 219 %type <declarations_> VariableDeclarationList
 
 220 %type <declarations_> VariableDeclarationList_
 
 221 %type <statement_> VariableStatement
 
 222 %type <argument_> VariadicCall
 
 223 %type <statement_> WhileStatement
 
 224 %type <statement_> WithStatement
 
 226 %type <word_> WordOpt
 
 238     : Identifier { $$ = $1; }
 
 239     | "break" { $$ = $1; }
 
 240     | "case" { $$ = $1; }
 
 241     | "catch" { $$ = $1; }
 
 242     | "continue" { $$ = $1; }
 
 243     | "default" { $$ = $1; }
 
 244     | "delete" { $$ = $1; }
 
 246     | "else" { $$ = $1; }
 
 247     | "false" { $$ = $1; }
 
 248     | "finally" { $$ = $1; }
 
 250     | "function" { $$ = $1; }
 
 253     | "instanceof" { $$ = $1; }
 
 255     | "null" { $$ = $1; }
 
 256     | "return" { $$ = $1; }
 
 257     | "switch" { $$ = $1; }
 
 258     | "this" { $$ = $1; }
 
 259     | "throw" { $$ = $1; }
 
 260     | "true" { $$ = $1; }
 
 262     | "typeof" { $$ = $1; }
 
 264     | "void" { $$ = $1; }
 
 265     | "while" { $$ = $1; }
 
 266     | "with" { $$ = $1; }
 
 270     : Identifier { $$ = $1; }
 
 275     : NullLiteral { $$ = $1; }
 
 276     | BooleanLiteral { $$ = $1; }
 
 277     | NumericLiteral { $$ = $1; }
 
 278     | StringLiteral { $$ = $1; }
 
 282     : "null" { $$ = $1; }
 
 286     : "true" { $$ = $1; }
 
 287     | "false" { $$ = $1; }
 
 290 /* Objective-C Extensions {{{ */
 
 292     : "," AssignmentExpression VariadicCall { $$ = new CYArgument(NULL, $2, $3); }
 
 297     : SelectorCall { $$ = $1; }
 
 298     | VariadicCall { $$ = $1; }
 
 302     : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new CYArgument($1 ?: new CYBlank(), $3, $4); }
 
 306     : SelectorCall { $$ = $1; }
 
 307     | Word { $$ = new CYArgument($1, NULL); }
 
 311     : "[" AssignmentExpression SelectorList "]" { $$ = new CYMessage($2, $3); }
 
 315 /* 11.1 Primary Expressions {{{ */
 
 317     : "this" { $$ = $1; }
 
 318     | Identifier { $$ = new CYVariable($1); }
 
 319     | Literal { $$ = $1; }
 
 320     | ArrayLiteral { $$ = $1; }
 
 321     | ObjectLiteral { $$ = $1; }
 
 322     | "(" Expression ")" { $$ = $2; }
 
 323     | MessageExpression { $$ = $1; }
 
 326 /* 11.1.4 Array Initialiser {{{ */
 
 328     : "[" ElementList "]" { $$ = $2; }
 
 332     : AssignmentExpression { $$ = $1; }
 
 337     : "," ElementList { $$ = $2; }
 
 342     : Element ElementList_ { $$ = new CYElement($1, $2); }
 
 345 /* 11.1.5 Object Initialiser {{{ */
 
 347     : "{" PropertyNameAndValueListOpt "}" { $$ = $2; }
 
 350 PropertyNameAndValueList_
 
 351     : "," PropertyNameAndValueList { $$ = $2; }
 
 355 PropertyNameAndValueListOpt
 
 356     : PropertyNameAndValueList { $$ = $1; }
 
 360 PropertyNameAndValueList
 
 361     : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new CYProperty($1, $3, $4); }
 
 365     : Identifier { $$ = $1; }
 
 366     | StringLiteral { $$ = $1; }
 
 367     | NumericLiteral { $$ = $1; }
 
 372     : PrimaryExpression { $$ = $1; }
 
 373     | FunctionExpression { $$ = $1; }
 
 374     | MemberExpression "[" Expression "]" { $$ = new CYMember($1, $3); }
 
 375     | MemberExpression "." Identifier { $$ = new CYMember($1, new CYString($3)); }
 
 376     | "new" MemberExpression Arguments { $$ = new CYNew($2, $3); }
 
 380     : MemberExpression { $$ = $1; }
 
 381     | "new" NewExpression { $$ = new CYNew($2, NULL); }
 
 385     : MemberExpression Arguments { $$ = new CYCall($1, $2); }
 
 386     | CallExpression Arguments { $$ = new CYCall($1, $2); }
 
 387     | CallExpression "[" Expression "]" { $$ = new CYMember($1, $3); }
 
 388     | CallExpression "." Identifier { $$ = new CYMember($1, new CYString($3)); }
 
 392     : "," ArgumentList { $$ = $2; }
 
 397     : ArgumentList { $$ = $1; }
 
 402     : AssignmentExpression ArgumentList_ { $$ = new CYArgument(NULL, $1, $2); }
 
 406     : "(" ArgumentListOpt ")" { $$ = $2; }
 
 409 LeftHandSideExpression
 
 410     : NewExpression { $$ = $1; }
 
 411     | CallExpression { $$ = $1; }
 
 415     : LeftHandSideExpression { $$ = $1; }
 
 416     | LeftHandSideExpression "++" { $$ = new CYPostIncrement($1); }
 
 417     | LeftHandSideExpression "--" { $$ = new CYPostDecrement($1); }
 
 421     : PostfixExpression { $$ = $1; }
 
 422     | "delete" UnaryExpression { $$ = new CYDelete($2); }
 
 423     | "void" UnaryExpression { $$ = new CYVoid($2); }
 
 424     | "typeof" UnaryExpression { $$ = new CYTypeOf($2); }
 
 425     | "++" UnaryExpression { $$ = new CYPreIncrement($2); }
 
 426     | "--" UnaryExpression { $$ = new CYPreDecrement($2); }
 
 427     | "+" UnaryExpression { $$ = $2; }
 
 428     | "-" UnaryExpression { $$ = new CYNegate($2); }
 
 429     | "~" UnaryExpression { $$ = new CYBitwiseNot($2); }
 
 430     | "!" UnaryExpression { $$ = new CYLogicalNot($2); }
 
 431     | "*" UnaryExpression { $$ = new CYIndirect($2); }
 
 432     | "&" UnaryExpression { $$ = new CYAddressOf($2); }
 
 435 MultiplicativeExpression
 
 436     : UnaryExpression { $$ = $1; }
 
 437     | MultiplicativeExpression "*" UnaryExpression { $$ = new CYMultiply($1, $3); }
 
 438     | MultiplicativeExpression "/" UnaryExpression { $$ = new CYDivide($1, $3); }
 
 439     | MultiplicativeExpression "%" UnaryExpression { $$ = new CYModulus($1, $3); }
 
 443     : MultiplicativeExpression { $$ = $1; }
 
 444     | AdditiveExpression "+" MultiplicativeExpression { $$ = new CYAdd($1, $3); }
 
 445     | AdditiveExpression "-" MultiplicativeExpression { $$ = new CYSubtract($1, $3); }
 
 449     : AdditiveExpression { $$ = $1; }
 
 450     | ShiftExpression "<<" AdditiveExpression { $$ = new CYShiftLeft($1, $3); }
 
 451     | ShiftExpression ">>" AdditiveExpression { $$ = new CYShiftRightSigned($1, $3); }
 
 452     | ShiftExpression ">>>" AdditiveExpression { $$ = new CYShiftRightUnsigned($1, $3); }
 
 456     : ShiftExpression { $$ = $1; }
 
 457     | RelationalExpression "<" ShiftExpression { $$ = new CYLess($1, $3); }
 
 458     | RelationalExpression ">" ShiftExpression { $$ = new CYGreater($1, $3); }
 
 459     | RelationalExpression "<=" ShiftExpression { $$ = new CYLessOrEqual($1, $3); }
 
 460     | RelationalExpression ">=" ShiftExpression { $$ = new CYGreaterOrEqual($1, $3); }
 
 461     | RelationalExpression "instanceof" ShiftExpression { $$ = new CYInstanceOf($1, $3); }
 
 462     | RelationalExpression "in" ShiftExpression { $$ = new CYIn($1, $3); }
 
 466     : RelationalExpression { $$ = $1; }
 
 467     | EqualityExpression "==" RelationalExpression { $$ = new CYEqual($1, $3); }
 
 468     | EqualityExpression "!=" RelationalExpression { $$ = new CYNotEqual($1, $3); }
 
 469     | EqualityExpression "===" RelationalExpression { $$ = new CYIdentical($1, $3); }
 
 470     | EqualityExpression "!==" RelationalExpression { $$ = new CYNotIdentical($1, $3); }
 
 474     : EqualityExpression { $$ = $1; }
 
 475     | BitwiseANDExpression "&" EqualityExpression { $$ = new CYBitwiseAnd($1, $3); }
 
 479     : BitwiseANDExpression { $$ = $1; }
 
 480     | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new CYBitwiseXOr($1, $3); }
 
 484     : BitwiseXORExpression { $$ = $1; }
 
 485     | BitwiseORExpression "|" BitwiseXORExpression { $$ = new CYBitwiseOr($1, $3); }
 
 489     : BitwiseORExpression { $$ = $1; }
 
 490     | LogicalANDExpression "&&" BitwiseORExpression { $$ = new CYLogicalAnd($1, $3); }
 
 494     : LogicalANDExpression { $$ = $1; }
 
 495     | LogicalORExpression "||" LogicalANDExpression { $$ = new CYLogicalOr($1, $3); }
 
 498 ConditionalExpression
 
 499     : LogicalORExpression { $$ = $1; }
 
 500     | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new CYCondition($1, $3, $5); }
 
 504     : ConditionalExpression { $$ = $1; }
 
 505     | LeftHandSideExpression "=" AssignmentExpression { $$ = new CYAssign($1, $3); }
 
 506     | LeftHandSideExpression "*=" AssignmentExpression { $$ = new CYMultiplyAssign($1, $3); }
 
 507     | LeftHandSideExpression "/=" AssignmentExpression { $$ = new CYDivideAssign($1, $3); }
 
 508     | LeftHandSideExpression "%=" AssignmentExpression { $$ = new CYModulusAssign($1, $3); }
 
 509     | LeftHandSideExpression "+=" AssignmentExpression { $$ = new CYAddAssign($1, $3); }
 
 510     | LeftHandSideExpression "-=" AssignmentExpression { $$ = new CYSubtractAssign($1, $3); }
 
 511     | LeftHandSideExpression "<<=" AssignmentExpression { $$ = new CYShiftLeftAssign($1, $3); }
 
 512     | LeftHandSideExpression ">>=" AssignmentExpression { $$ = new CYShiftRightSignedAssign($1, $3); }
 
 513     | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = new CYShiftRightUnsignedAssign($1, $3); }
 
 514     | LeftHandSideExpression "&=" AssignmentExpression { $$ = new CYBitwiseAndAssign($1, $3); }
 
 515     | LeftHandSideExpression "^=" AssignmentExpression { $$ = new CYBitwiseXOrAssign($1, $3); }
 
 516     | LeftHandSideExpression "|=" AssignmentExpression { $$ = new CYBitwiseOrAssign($1, $3); }
 
 520     : "," Expression { $$ = $2; }
 
 525     : Expression { $$ = $1; }
 
 530     : AssignmentExpression Expression_ { $1->SetNext($2); $$ = $1; }
 
 535     | VariableStatement { $$ = $1; }
 
 536     | EmptyStatement { $$ = $1; }
 
 537     | ExpressionStatement { $$ = $1; }
 
 538     | IfStatement { $$ = $1; }
 
 539     | IterationStatement { $$ = $1; }
 
 540     | ContinueStatement { $$ = $1; }
 
 541     | BreakStatement { $$ = $1; }
 
 542     | ReturnStatement { $$ = $1; }
 
 543     | WithStatement { $$ = $1; }
 
 544     | LabelledStatement { $$ = $1; }
 
 545     | SwitchStatement { $$ = $1; }
 
 546     | ThrowStatement { $$ = $1; }
 
 547     | TryStatement { $$ = $1; }
 
 551     : "{" StatementListOpt "}" { $$ = $2 ?: new CYEmpty(); }
 
 555     : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
 
 560     : "var" VariableDeclarationList ";" { $$ = $2; }
 
 563 VariableDeclarationList_
 
 564     : "," VariableDeclarationList { $$ = $2; }
 
 568 VariableDeclarationList
 
 569     : VariableDeclaration VariableDeclarationList_ { $$ = new CYDeclarations($1, $2); }
 
 573     : Identifier InitialiserOpt { $$ = new CYDeclaration($1, $2); }
 
 577     : Initialiser { $$ = $1; }
 
 582     : "=" AssignmentExpression { $$ = $2; }
 
 586     : ";" { $$ = new CYEmpty(); }
 
 590     : Expression ";" { $$ = $1; }
 
 594     : "else" Statement { $$ = $2; }
 
 599     : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new CYIf($3, $5, $6); }
 
 603     : DoWhileStatement { $$ = $1; }
 
 604     | WhileStatement { $$ = $1; }
 
 605     | ForStatement { $$ = $1; }
 
 606     | ForInStatement { $$ = $1; }
 
 610     : "do" Statement "while" "(" Expression ")" ";" { $$ = new CYDoWhile($5, $2); }
 
 614     : "while" "(" Expression ")" Statement { $$ = new CYWhile($3, $5); }
 
 618     : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new CYFor($3, $5, $7, $9); }
 
 621 ForStatementInitialiser
 
 622     : ExpressionOpt { $$ = $1; }
 
 623     | "var" VariableDeclarationList { $$ = $2; }
 
 627     : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new CYForIn($3, $5, $7); }
 
 630 ForInStatementInitialiser
 
 631     : LeftHandSideExpression { $$ = $1; }
 
 632     | "var" VariableDeclaration { $$ = $2; }
 
 636     : "continue" IdentifierOpt ";" { $$ = new CYContinue($2); }
 
 640     : "break" IdentifierOpt ";" { $$ = new CYBreak($2); }
 
 644     : "return" ExpressionOpt ";" { $$ = new CYReturn($2); }
 
 648     : "with" "(" Expression ")" Statement { $$ = new CYWith($3, $5); }
 
 652     : "switch" "(" Expression ")" CaseBlock { $$ = new CYSwitch($3, $5); }
 
 656     : "{" CaseClausesOpt "}" { $$ = $2; }
 
 660     : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
 
 661     | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
 
 666     : "case" Expression ":" StatementListOpt { $$ = new CYClause($2, $4); }
 
 670     : "default" ":" StatementListOpt { $$ = new CYClause(NULL, $3); }
 
 674     : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; }
 
 678     : "throw" Expression ";" { $$ = new CYThrow($2); }
 
 682     : "try" Block CatchOpt FinallyOpt { $$ = new CYTry($2, $3, $4); }
 
 686     : "catch" "(" Identifier ")" Block { $$ = new CYCatch($3, $5); }
 
 691     : "finally" Block { $$ = $2; }
 
 696     : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new CYFunction($2, $4, $7); }
 
 700     : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new CYLambda($2, $4, $7); }
 
 704     : "," FormalParameterList { $$ = $2; }
 
 709     : Identifier FormalParameterList_ { $$ = new CYParameter($1, $2); }
 
 714     : SourceElements { $$ = $1; }
 
 718     : SourceElements { $$ = $1; }
 
 722     : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
 
 727     : Statement { $$ = $1; }
 
 728     | FunctionDeclaration { $$ = $1; }