X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/d15b59f5d4f43d12719c5ce37518246058b405c6..561ac4181ec3ad1e1e207e840f70d5017ba9a1ed:/Cycript.y.in diff --git a/Cycript.y.in b/Cycript.y.in index 37e7611..37b9203 100644 --- a/Cycript.y.in +++ b/Cycript.y.in @@ -309,6 +309,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type AdditiveExpression %type AdditiveExpressionNoBF +%type AdditiveExpressionNoWC %type ArgumentList %type ArgumentList_ %type ArgumentListOpt @@ -316,22 +317,27 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type ArrayLiteral %type AssigneeExpression %type AssigneeExpressionNoBF +%type AssigneeExpressionNoWC %type AssignmentExpression %type AssignmentExpression_ %type AssignmentExpressionNoBF %type AssignmentExpressionNoIn +%type AssignmentExpressionNoWC %type BitwiseANDExpression %type BitwiseANDExpressionNoBF %type BitwiseANDExpressionNoIn +%type BitwiseANDExpressionNoWC %type Block %type Block_ %type BooleanLiteral %type BitwiseORExpression %type BitwiseORExpressionNoBF %type BitwiseORExpressionNoIn +%type BitwiseORExpressionNoWC %type BitwiseXORExpression %type BitwiseXORExpressionNoBF %type BitwiseXORExpressionNoIn +%type BitwiseXORExpressionNoWC %type BreakStatement %type CallExpression %type CallExpressionNoBF @@ -344,6 +350,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type ConditionalExpression %type ConditionalExpressionNoBF %type ConditionalExpressionNoIn +%type ConditionalExpressionNoWC %type ContinueStatement %type DefaultClause %type DoWhileStatement @@ -356,6 +363,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type EqualityExpression %type EqualityExpressionNoBF %type EqualityExpressionNoIn +%type EqualityExpressionNoWC %type Expression %type ExpressionOpt %type Expression_ @@ -375,6 +383,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type FunctionBody %type FunctionDeclaration %type FunctionExpression +%type FunctionExpression_ %type Identifier %type IdentifierOpt %type IfComprehension @@ -387,31 +396,45 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type LabelledStatement %type LeftHandSideExpression %type LeftHandSideExpressionNoBF +%type LeftHandSideExpressionNoWC //%type LetStatement %type Literal +%type LiteralNoRE +%type LiteralRE %type LogicalANDExpression %type LogicalANDExpressionNoBF %type LogicalANDExpressionNoIn +%type LogicalANDExpressionNoWC %type LogicalORExpression %type LogicalORExpressionNoBF %type LogicalORExpressionNoIn +%type LogicalORExpressionNoWC %type MemberAccess %type MemberExpression %type MemberExpression_ %type MemberExpressionNoBF +%type MemberExpressionNoWC %type MultiplicativeExpression %type MultiplicativeExpressionNoBF +%type MultiplicativeExpressionNoWC %type NewExpression %type NewExpression_ %type NewExpressionNoBF +%type NewExpressionNoWC %type NullLiteral %type ObjectLiteral %type PostfixExpression %type PostfixExpressionNoBF +%type PostfixExpressionNoWC %type PrimaryExpression -%type PrimaryExpression_ +%type PrimaryExpressionNo %type PrimaryExpressionNoBF -%type PrimaryExpressionNoBF_ +%type PrimaryExpressionNoWC +%type PrimaryExpressionNoWC_ +@begin E4X +%type PrimaryExpressionWC +@end +%type PrimaryExpressionBF %type Program %type PropertyName %type PropertyNameAndValueList @@ -421,10 +444,12 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type RelationalExpression_ %type RelationalExpressionNoBF %type RelationalExpressionNoIn +%type RelationalExpressionNoWC %type RelationalExpressionNoIn_ %type ReturnStatement %type ShiftExpression %type ShiftExpressionNoBF +%type ShiftExpressionNoWC %type SourceElement %type SourceElement_ %type SourceElements @@ -439,6 +464,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type UnaryExpression %type UnaryExpression_ %type UnaryExpressionNoBF +%type UnaryExpressionNoWC %type VariableDeclaration %type VariableDeclarationNoIn %type VariableDeclarationList @@ -579,7 +605,7 @@ Word | "extends" { $$ = $1; } | "false" { $$ = $1; } | "finally" { $$ = $1; } - | "for" { $$ = $1; } + /* XXX: | "for" { $$ = $1; } */ | "function" { $$ = $1; } | "if" { $$ = $1; } | "import" { $$ = $1; } @@ -641,12 +667,20 @@ IdentifierOpt | { $$ = NULL; } ; -Literal +LiteralNoRE : NullLiteral { $$ = $1; } | BooleanLiteral { $$ = $1; } | NumericLiteral { $$ = $1; } | StringLiteral { $$ = $1; } - | RegularExpressionLiteral { $$ = $1; } + ; + +LiteralRE + : RegularExpressionLiteral { $$ = $1; } + ; + +Literal + : LiteralNoRE { $$ = $1; } + | LiteralRE { $$ = $1; } ; NullLiteral @@ -659,12 +693,30 @@ BooleanLiteral ; /* 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; } @@ -672,12 +724,8 @@ PrimaryExpressionNoBF_ | "(" Expression ")" { $$ = $2; } ; -PrimaryExpression - : LexSetRegExp PrimaryExpression_ { $$ = $2; } - ; - -PrimaryExpressionNoBF - : PrimaryExpressionNoBF_ { $$ = $1; } +PrimaryExpressionBF + : ObjectLiteral { $$ = $1; } ; /* }}} */ /* 11.1.4 Array Initialiser {{{ */ @@ -753,6 +801,13 @@ MemberExpressionNoBF | 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); } ; @@ -767,8 +822,13 @@ NewExpressionNoBF | 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; } ; @@ -806,6 +866,11 @@ LeftHandSideExpressionNoBF : NewExpressionNoBF { $$ = $1; } | CallExpressionNoBF { $$ = $1; } ; + +LeftHandSideExpressionNoWC + : NewExpressionNoWC { $$ = $1; } + | CallExpression { $$ = $1; } + ; /* }}} */ /* 11.3 Postfix Expressions {{{ */ PostfixExpression @@ -819,6 +884,12 @@ PostfixExpressionNoBF | 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_ @@ -844,6 +915,11 @@ UnaryExpressionNoBF : PostfixExpressionNoBF { $$ = $1; } | UnaryExpression_ { $$ = $1; } ; + +UnaryExpressionNoWC + : PostfixExpressionNoWC { $$ = $1; } + | LexSetRegExp UnaryExpression_ { $$ = $2; } + ; /* }}} */ /* 11.5 Multiplicative Operators {{{ */ MultiplicativeExpression @@ -859,6 +935,13 @@ MultiplicativeExpressionNoBF | 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 @@ -872,6 +955,12 @@ AdditiveExpressionNoBF | 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 @@ -887,6 +976,13 @@ ShiftExpressionNoBF | 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_ @@ -916,6 +1012,11 @@ RelationalExpressionNoBF : ShiftExpressionNoBF { $$ = $1; } | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; } ; + +RelationalExpressionNoWC + : ShiftExpressionNoWC { $$ = $1; } + | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; } + ; /* }}} */ /* 11.9 Equality Operators {{{ */ EqualityExpression @@ -941,6 +1042,14 @@ EqualityExpressionNoBF | 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 @@ -958,6 +1067,11 @@ BitwiseANDExpressionNoBF | 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); } @@ -973,6 +1087,11 @@ BitwiseXORExpressionNoBF | 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); } @@ -987,6 +1106,11 @@ BitwiseORExpressionNoBF : 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 @@ -1004,6 +1128,11 @@ LogicalANDExpressionNoBF | 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); } @@ -1018,6 +1147,11 @@ LogicalORExpressionNoBF : 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 @@ -1034,6 +1168,11 @@ ConditionalExpressionNoBF : 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_ @@ -1061,6 +1200,11 @@ AssigneeExpressionNoBF | UnaryAssigneeExpression { $$ = $1; } ; +AssigneeExpressionNoWC + : LeftHandSideExpressionNoWC { $$ = $1; } + | LexSetRegExp UnaryAssigneeExpression { $$ = $2; } + ; + AssignmentExpression : ConditionalExpression { $$ = $1; } | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } @@ -1086,6 +1230,11 @@ AssignmentExpressionNoBF : ConditionalExpressionNoBF { $$ = $1; } | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } ; + +AssignmentExpressionNoWC + : ConditionalExpressionNoWC { $$ = $1; } + | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } + ; /* }}} */ /* 11.14 Comma Operator {{{ */ Expression_ @@ -1345,8 +1494,12 @@ FunctionDeclaration : "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_ @@ -1454,7 +1607,7 @@ CategoryStatement : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); } ; -PrimaryExpression_ +PrimaryExpressionBF : ClassExpression { $$ = $1; } ; @@ -1484,7 +1637,7 @@ SelectorList ; 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); } ; @@ -1502,7 +1655,7 @@ SelectorExpression | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); } ; -PrimaryExpressionNoBF_ +PrimaryExpressionNo : MessageExpression { $$ = $1; } | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); } ; @@ -1512,7 +1665,7 @@ PrimaryExpressionNoBF_ @begin C /* Cycript (C): Pointer Indirection/Addressing {{{ */ UnaryAssigneeExpression - : "^" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); } + : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); } ; UnaryExpression_ @@ -1572,7 +1725,7 @@ XMLMarkup ; /* }}} */ /* 11.1 Primary Expressions {{{ */ -PrimaryExpressionNoBF_ +PrimaryExpressionWC : PropertyIdentifier { $$ = $1; } | XMLInitialiser { $$ = $1; } | XMLListInitialiser { $$ = $1; } @@ -1731,7 +1884,7 @@ ComprehensionList : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; } ; -PrimaryExpressionNoBF_ +PrimaryExpressionNo : "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); } ; /* }}} */