-/* Cycript - Remote Execution Server and Disassembler
+/* Cycript - Inlining/Optimizing JavaScript Compiler
* Copyright (C) 2009 Jay Freeman (saurik)
*/
#include "Parser.hpp"
@begin ObjectiveC
-#include "ObjectiveC.hpp"
+#include "ObjectiveC/Syntax.hpp"
@end
@begin E4X
CYAssignment *assignment_;
CYBoolean *boolean_;
CYClause *clause_;
- CYCatch *catch_;
+ cy::Syntax::Catch *catch_;
CYComprehension *comprehension_;
CYCompound *compound_;
CYDeclaration *declaration_;
%type <expression_> AdditiveExpression
%type <expression_> AdditiveExpressionNoBF
+%type <expression_> AdditiveExpressionNoWC
%type <argument_> ArgumentList
%type <argument_> ArgumentList_
%type <argument_> ArgumentListOpt
%type <literal_> ArrayLiteral
%type <expression_> AssigneeExpression
%type <expression_> AssigneeExpressionNoBF
+%type <expression_> AssigneeExpressionNoWC
%type <expression_> AssignmentExpression
%type <assignment_> AssignmentExpression_
%type <expression_> AssignmentExpressionNoBF
%type <expression_> AssignmentExpressionNoIn
+%type <expression_> AssignmentExpressionNoWC
%type <expression_> BitwiseANDExpression
%type <expression_> BitwiseANDExpressionNoBF
%type <expression_> BitwiseANDExpressionNoIn
+%type <expression_> BitwiseANDExpressionNoWC
%type <statement_> Block
%type <statement_> Block_
%type <boolean_> BooleanLiteral
%type <expression_> BitwiseORExpression
%type <expression_> BitwiseORExpressionNoBF
%type <expression_> BitwiseORExpressionNoIn
+%type <expression_> BitwiseORExpressionNoWC
%type <expression_> BitwiseXORExpression
%type <expression_> BitwiseXORExpressionNoBF
%type <expression_> BitwiseXORExpressionNoIn
+%type <expression_> BitwiseXORExpressionNoWC
%type <statement_> BreakStatement
%type <expression_> CallExpression
%type <expression_> CallExpressionNoBF
%type <expression_> ConditionalExpression
%type <expression_> ConditionalExpressionNoBF
%type <expression_> ConditionalExpressionNoIn
+%type <expression_> ConditionalExpressionNoWC
%type <statement_> ContinueStatement
%type <clause_> DefaultClause
%type <statement_> DoWhileStatement
%type <expression_> EqualityExpression
%type <expression_> EqualityExpressionNoBF
%type <expression_> EqualityExpressionNoIn
+%type <expression_> EqualityExpressionNoWC
%type <expression_> Expression
%type <expression_> ExpressionOpt
%type <compound_> Expression_
%type <statement_> FunctionBody
%type <statement_> FunctionDeclaration
%type <expression_> FunctionExpression
+%type <expression_> FunctionExpression_
%type <identifier_> Identifier
%type <identifier_> IdentifierOpt
%type <comprehension_> IfComprehension
%type <statement_> LabelledStatement
%type <expression_> LeftHandSideExpression
%type <expression_> LeftHandSideExpressionNoBF
+%type <expression_> LeftHandSideExpressionNoWC
//%type <statement_> LetStatement
%type <literal_> Literal
+%type <literal_> LiteralNoRE
+%type <literal_> LiteralRE
%type <expression_> LogicalANDExpression
%type <expression_> LogicalANDExpressionNoBF
%type <expression_> LogicalANDExpressionNoIn
+%type <expression_> LogicalANDExpressionNoWC
%type <expression_> LogicalORExpression
%type <expression_> LogicalORExpressionNoBF
%type <expression_> LogicalORExpressionNoIn
+%type <expression_> LogicalORExpressionNoWC
%type <member_> MemberAccess
%type <expression_> MemberExpression
%type <expression_> MemberExpression_
%type <expression_> MemberExpressionNoBF
+%type <expression_> MemberExpressionNoWC
%type <expression_> MultiplicativeExpression
%type <expression_> MultiplicativeExpressionNoBF
+%type <expression_> MultiplicativeExpressionNoWC
%type <expression_> NewExpression
%type <expression_> NewExpression_
%type <expression_> NewExpressionNoBF
+%type <expression_> NewExpressionNoWC
%type <null_> NullLiteral
%type <literal_> ObjectLiteral
%type <expression_> PostfixExpression
%type <expression_> PostfixExpressionNoBF
+%type <expression_> PostfixExpressionNoWC
%type <expression_> PrimaryExpression
-%type <expression_> PrimaryExpression_
+%type <expression_> PrimaryExpressionNo
%type <expression_> PrimaryExpressionNoBF
-%type <expression_> PrimaryExpressionNoBF_
+%type <expression_> PrimaryExpressionNoWC
+%type <expression_> PrimaryExpressionNoWC_
+@begin E4X
+%type <expression_> PrimaryExpressionWC
+@end
+%type <expression_> PrimaryExpressionBF
%type <statement_> Program
%type <propertyName_> PropertyName
%type <property_> PropertyNameAndValueList
%type <infix_> RelationalExpression_
%type <expression_> RelationalExpressionNoBF
%type <expression_> RelationalExpressionNoIn
+%type <expression_> RelationalExpressionNoWC
%type <infix_> RelationalExpressionNoIn_
%type <statement_> ReturnStatement
%type <expression_> ShiftExpression
%type <expression_> ShiftExpressionNoBF
+%type <expression_> ShiftExpressionNoWC
%type <statement_> SourceElement
%type <statement_> SourceElement_
%type <statement_> SourceElements
%type <expression_> UnaryExpression
%type <expression_> UnaryExpression_
%type <expression_> UnaryExpressionNoBF
+%type <expression_> UnaryExpressionNoWC
%type <declaration_> VariableDeclaration
%type <declaration_> VariableDeclarationNoIn
%type <declarations_> VariableDeclarationList
| "extends" { $$ = $1; }
| "false" { $$ = $1; }
| "finally" { $$ = $1; }
- | "for" { $$ = $1; }
+ /* XXX: | "for" { $$ = $1; } */
| "function" { $$ = $1; }
| "if" { $$ = $1; }
| "import" { $$ = $1; }
| { $$ = NULL; }
;
-Literal
+LiteralNoRE
: NullLiteral { $$ = $1; }
| BooleanLiteral { $$ = $1; }
| NumericLiteral { $$ = $1; }
| StringLiteral { $$ = $1; }
- | RegularExpressionLiteral { $$ = $1; }
+ ;
+
+LiteralRE
+ : RegularExpressionLiteral { $$ = $1; }
+ ;
+
+Literal
+ : LiteralNoRE { $$ = $1; }
+ | LiteralRE { $$ = $1; }
;
NullLiteral
;
/* 11.1 Primary Expressions {{{ */
-PrimaryExpression_
- : ObjectLiteral { $$ = $1; }
- | PrimaryExpressionNoBF_ { $$ = $1; }
+PrimaryExpression
+ : PrimaryExpressionNoWC { $$ = $1; }
+@begin E4X
+ | LexSetRegExp PrimaryExpressionWC { $$ = $1; }
+@end
;
-PrimaryExpressionNoBF_
+PrimaryExpressionNoBF
+ : PrimaryExpressionNo { $$ = $1; }
+@begin E4X
+ | PrimaryExpressionWC { $$ = $1; }
+@end
+ ;
+
+PrimaryExpressionNoWC_
+ : PrimaryExpressionBF { $$ = $1; }
+ | PrimaryExpressionNo { $$ = $1; }
+ ;
+
+PrimaryExpressionNoWC
+ : LexSetRegExp PrimaryExpressionNoWC_ { $$ = $2; }
+ ;
+
+PrimaryExpressionNo
: "this" { $$ = $1; }
| Identifier { $$ = new(driver.pool_) CYVariable($1); }
| Literal { $$ = $1; }
| "(" Expression ")" { $$ = $2; }
;
-PrimaryExpression
- : LexSetRegExp PrimaryExpression_ { $$ = $2; }
- ;
-
-PrimaryExpressionNoBF
- : PrimaryExpressionNoBF_ { $$ = $1; }
+PrimaryExpressionBF
+ : ObjectLiteral { $$ = $1; }
;
/* }}} */
/* 11.1.4 Array Initialiser {{{ */
| MemberExpression_ { $$ = $1; }
;
+MemberExpressionNoWC
+ : PrimaryExpressionNoWC { $$ = $1; }
+ | FunctionExpression { $$ = $1; }
+ | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
+ | LexSetRegExp MemberExpression_ { $$ = $2; }
+ ;
+
NewExpression_
: "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
;
| NewExpression_ { $$ = $1; }
;
+NewExpressionNoWC
+ : MemberExpressionNoWC { $$ = $1; }
+ | LexSetRegExp NewExpression_ { $$ = $2; }
+ ;
+
CallExpression
- : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
+ : PrimaryExpressionNoWC Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
| CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
| CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
;
: NewExpressionNoBF { $$ = $1; }
| CallExpressionNoBF { $$ = $1; }
;
+
+LeftHandSideExpressionNoWC
+ : NewExpressionNoWC { $$ = $1; }
+ | CallExpression { $$ = $1; }
+ ;
/* }}} */
/* 11.3 Postfix Expressions {{{ */
PostfixExpression
| LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
| LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
;
+
+PostfixExpressionNoWC
+ : AssigneeExpressionNoWC { $$ = $1; }
+ | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
+ | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
+ ;
/* }}} */
/* 11.4 Unary Operators {{{ */
UnaryExpression_
: PostfixExpressionNoBF { $$ = $1; }
| UnaryExpression_ { $$ = $1; }
;
+
+UnaryExpressionNoWC
+ : PostfixExpressionNoWC { $$ = $1; }
+ | LexSetRegExp UnaryExpression_ { $$ = $2; }
+ ;
/* }}} */
/* 11.5 Multiplicative Operators {{{ */
MultiplicativeExpression
| MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
| MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
;
+
+MultiplicativeExpressionNoWC
+ : UnaryExpressionNoWC { $$ = $1; }
+ | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
+ | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
+ | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
+ ;
/* }}} */
/* 11.6 Additive Operators {{{ */
AdditiveExpression
| AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
| AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
;
+
+AdditiveExpressionNoWC
+ : MultiplicativeExpressionNoWC{ $$ = $1; }
+ | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
+ | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
+ ;
/* }}} */
/* 11.7 Bitwise Shift Operators {{{ */
ShiftExpression
| ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
| ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
;
+
+ShiftExpressionNoWC
+ : AdditiveExpressionNoWC { $$ = $1; }
+ | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
+ | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
+ | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
+ ;
/* }}} */
/* 11.8 Relational Operators {{{ */
RelationalExpressionNoIn_
: ShiftExpressionNoBF { $$ = $1; }
| RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
;
+
+RelationalExpressionNoWC
+ : ShiftExpressionNoWC { $$ = $1; }
+ | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
+ ;
/* }}} */
/* 11.9 Equality Operators {{{ */
EqualityExpression
| EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
| EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
;
+
+EqualityExpressionNoWC
+ : RelationalExpressionNoWC { $$ = $1; }
+ | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
+ | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
+ | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
+ | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
+ ;
/* }}} */
/* 11.10 Binary Bitwise Operators {{{ */
BitwiseANDExpression
| BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
;
+BitwiseANDExpressionNoWC
+ : EqualityExpressionNoWC { $$ = $1; }
+ | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
+ ;
+
BitwiseXORExpression
: BitwiseANDExpression { $$ = $1; }
| BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
| BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
;
+BitwiseXORExpressionNoWC
+ : BitwiseANDExpressionNoWC { $$ = $1; }
+ | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
+ ;
+
BitwiseORExpression
: BitwiseXORExpression { $$ = $1; }
| BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
: BitwiseXORExpressionNoBF { $$ = $1; }
| BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
;
+
+BitwiseORExpressionNoWC
+ : BitwiseXORExpressionNoWC { $$ = $1; }
+ | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
+ ;
/* }}} */
/* 11.11 Binary Logical Operators {{{ */
LogicalANDExpression
| LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
;
+LogicalANDExpressionNoWC
+ : BitwiseORExpressionNoWC { $$ = $1; }
+ | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
+ ;
+
LogicalORExpression
: LogicalANDExpression { $$ = $1; }
| LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
: LogicalANDExpressionNoBF { $$ = $1; }
| LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
;
+
+LogicalORExpressionNoWC
+ : LogicalANDExpressionNoWC { $$ = $1; }
+ | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
+ ;
/* }}} */
/* 11.12 Conditional Operator ( ? : ) {{{ */
ConditionalExpression
: LogicalORExpressionNoBF { $$ = $1; }
| LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
;
+
+ConditionalExpressionNoWC
+ : LogicalORExpressionNoWC { $$ = $1; }
+ | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
+ ;
/* }}} */
/* 11.13 Assignment Operators {{{ */
AssignmentExpression_
| UnaryAssigneeExpression { $$ = $1; }
;
+AssigneeExpressionNoWC
+ : LeftHandSideExpressionNoWC { $$ = $1; }
+ | LexSetRegExp UnaryAssigneeExpression { $$ = $2; }
+ ;
+
AssignmentExpression
: ConditionalExpression { $$ = $1; }
| AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
: ConditionalExpressionNoBF { $$ = $1; }
| AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
;
+
+AssignmentExpressionNoWC
+ : ConditionalExpressionNoWC { $$ = $1; }
+ | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
+ ;
/* }}} */
/* 11.14 Comma Operator {{{ */
Expression_
/* }}} */
/* 12.13 The throw Statement {{{ */
ThrowStatement
- : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); }
+ : "throw" Expression Terminator { $$ = new(driver.pool_) cy::Syntax::Throw($2); }
;
/* }}} */
/* 12.14 The try Statement {{{ */
TryStatement
- : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); }
+ : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) cy::Syntax::Try($2, $3, $4); }
;
CatchOpt
- : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) CYCatch($3, $5); }
+ : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) cy::Syntax::Catch($3, $5); }
| { $$ = NULL; }
;
: "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); }
;
+FunctionExpression_
+ : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); }
+ ;
+
FunctionExpression
- : LexSetRegExp "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($3, $5, $8); }
+ : LexSetRegExp FunctionExpression_ { $$ = $2; }
;
FormalParameterList_
: "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
;
-PrimaryExpression_
+PrimaryExpressionBF
: ClassExpression { $$ = $1; }
;
;
MessageExpression
- : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSendDirect($2, $3); }
+ : "[" AssignmentExpressionNoWC SelectorList "]" { $$ = new(driver.pool_) CYSendDirect($2, $3); }
| "[" LexSetRegExp "super" SelectorList "]" { $$ = new(driver.pool_) CYSendSuper($4); }
;
| Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
;
-PrimaryExpressionNoBF_
+PrimaryExpressionNo
: MessageExpression { $$ = $1; }
| "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); }
;
@begin C
/* Cycript (C): Pointer Indirection/Addressing {{{ */
UnaryAssigneeExpression
- : "^" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); }
+ : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); }
;
UnaryExpression_
;
/* }}} */
/* 11.1 Primary Expressions {{{ */
-PrimaryExpressionNoBF_
+PrimaryExpressionWC
: PropertyIdentifier { $$ = $1; }
| XMLInitialiser { $$ = $1; }
| XMLListInitialiser { $$ = $1; }
: ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
;
-PrimaryExpressionNoBF_
+PrimaryExpressionNo
: "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); }
;
/* }}} */