X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/37954781d9756ece500551055562183a1e28e943..8628b7b54274e0d246ebbe99d19895faa1fdecf5:/Cycript.y.in diff --git a/Cycript.y.in b/Cycript.y.in index 4c25b82..79d277d 100644 --- a/Cycript.y.in +++ b/Cycript.y.in @@ -1,4 +1,4 @@ -/* Cycript - Remote Execution Server and Disassembler +/* Cycript - Inlining/Optimizing JavaScript Compiler * Copyright (C) 2009 Jay Freeman (saurik) */ @@ -51,7 +51,7 @@ @end @begin E4X -#include "E4X.hpp" +#include "E4X/Syntax.hpp" @end typedef struct { @@ -103,6 +103,8 @@ typedef struct { @begin E4X CYAttribute *attribute_; + CYPropertyIdentifier *propertyIdentifier_; + CYSelector *selector_; @end }; } YYSTYPE; @@ -151,11 +153,14 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %token SlashRight "/>" %token LeftSlash " ArrayLiteral %type AssigneeExpression %type AssigneeExpressionNoBF +%type AssigneeExpressionNoRE %type AssignmentExpression %type AssignmentExpression_ %type AssignmentExpressionNoBF @@ -335,6 +341,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type BreakStatement %type CallExpression %type CallExpressionNoBF +%type CallExpressionNoRE %type CaseBlock %type CaseClause %type CaseClausesOpt @@ -387,8 +394,11 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type LabelledStatement %type LeftHandSideExpression %type LeftHandSideExpressionNoBF +%type LeftHandSideExpressionNoRE //%type LetStatement %type Literal +%type LiteralNoRE +%type LiteralRE %type LogicalANDExpression %type LogicalANDExpressionNoBF %type LogicalANDExpressionNoIn @@ -399,21 +409,26 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type MemberExpression %type MemberExpression_ %type MemberExpressionNoBF +%type MemberExpressionNoRE %type MultiplicativeExpression %type MultiplicativeExpressionNoBF %type NewExpression %type NewExpression_ %type NewExpressionNoBF +%type NewExpressionNoRE %type NullLiteral %type ObjectLiteral %type PostfixExpression %type PostfixExpressionNoBF +%type PostfixExpressionNoRE %type PrimaryExpression -%type PrimaryExpression_ +%type PrimaryExpressionNo %type PrimaryExpressionNoBF -%type PrimaryExpressionNoBF_ +%type PrimaryExpressionNoRE +%type PrimaryExpressionBF %type Program %type PropertyName +%type PropertyName_ %type PropertyNameAndValueList %type PropertyNameAndValueList_ %type PropertyNameAndValueListOpt @@ -439,6 +454,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type UnaryExpression %type UnaryExpression_ %type UnaryExpressionNoBF +%type UnaryExpressionNoRE %type VariableDeclaration %type VariableDeclarationNoIn %type VariableDeclarationList @@ -478,9 +494,9 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); @end @begin E4X -%type PropertyIdentifier_ -%type PropertySelector -%type PropertySelector_ +%type PropertyIdentifier_ +%type PropertySelector +%type PropertySelector_ %type QualifiedIdentifier %type QualifiedIdentifier_ %type WildcardIdentifier @@ -492,13 +508,20 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type XMLPI %type AttributeIdentifier -%type DefaultXMLNamespaceStatement +/* XXX: %type DefaultXMLNamespaceStatement */ %type PropertyIdentifier %type XMLListInitialiser %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 "if" +%nonassoc "else" + +%nonassoc "++" "--" +%nonassoc "(" "[" + %left "*" "/" "%" %left "+" "-" %left "<<" ">>" ">>>" @@ -511,10 +534,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %left "||" %right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|=" -*/ - -%nonassoc "if" -%nonassoc "else" %start Program @@ -579,7 +598,7 @@ Word | "extends" { $$ = $1; } | "false" { $$ = $1; } | "finally" { $$ = $1; } - | "for" { $$ = $1; } + /* XXX: | "for" { $$ = $1; } */ | "function" { $$ = $1; } | "if" { $$ = $1; } | "import" { $$ = $1; } @@ -641,12 +660,21 @@ IdentifierOpt | { $$ = NULL; } ; -Literal +LiteralNoRE : NullLiteral { $$ = $1; } | BooleanLiteral { $$ = $1; } | NumericLiteral { $$ = $1; } | StringLiteral { $$ = $1; } - | RegularExpressionLiteral { $$ = $1; } + | "@" StringLiteral { $$ = $2; } + ; + +LiteralRE + : RegularExpressionLiteral { $$ = $1; } + ; + +Literal + : LiteralNoRE { $$ = $1; } + | LiteralRE { $$ = $1; } ; NullLiteral @@ -659,12 +687,20 @@ BooleanLiteral ; /* 11.1 Primary Expressions {{{ */ -PrimaryExpression_ - : ObjectLiteral { $$ = $1; } - | PrimaryExpressionNoBF_ { $$ = $1; } +PrimaryExpression + : LexSetRegExp PrimaryExpressionNoRE { $$ = $2; } + ; + +PrimaryExpressionNoBF + : PrimaryExpressionNo { $$ = $1; } + ; + +PrimaryExpressionNoRE + : PrimaryExpressionBF { $$ = $1; } + | PrimaryExpressionNo { $$ = $1; } ; -PrimaryExpressionNoBF_ +PrimaryExpressionNo : "this" { $$ = $1; } | Identifier { $$ = new(driver.pool_) CYVariable($1); } | Literal { $$ = $1; } @@ -672,12 +708,8 @@ PrimaryExpressionNoBF_ | "(" Expression ")" { $$ = $2; } ; -PrimaryExpression - : LexSetRegExp PrimaryExpression_ { $$ = $2; } - ; - -PrimaryExpressionNoBF - : PrimaryExpressionNoBF_ { $$ = $1; } +PrimaryExpressionBF + : ObjectLiteral { $$ = $1; } ; /* }}} */ /* 11.1.4 Array Initialiser {{{ */ @@ -723,11 +755,15 @@ PropertyNameAndValueList : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); } ; -PropertyName +PropertyName_ : Identifier { $$ = $1; } | StringLiteral { $$ = $1; } | NumericLiteral { $$ = $1; } ; + +PropertyName + : LexSetRegExp PropertyName_ { $$ = $2; } + ; /* }}} */ /* 11.2 Left-Hand-Side Expressions {{{ */ @@ -742,7 +778,7 @@ MemberAccess MemberExpression : PrimaryExpression { $$ = $1; } - | FunctionExpression { $$ = $1; } + | LexSetRegExp FunctionExpression { $$ = $2; } | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; } | LexSetRegExp MemberExpression_ { $$ = $2; } ; @@ -753,6 +789,13 @@ MemberExpressionNoBF | MemberExpression_ { $$ = $1; } ; +MemberExpressionNoRE + : PrimaryExpressionNoRE { $$ = $1; } + | FunctionExpression { $$ = $1; } + | MemberExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; } + | MemberExpression_ { $$ = $1; } + ; + NewExpression_ : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); } ; @@ -767,6 +810,11 @@ NewExpressionNoBF | NewExpression_ { $$ = $1; } ; +NewExpressionNoRE + : MemberExpressionNoRE { $$ = $1; } + | NewExpression_ { $$ = $1; } + ; + CallExpression : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); } | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); } @@ -779,6 +827,12 @@ CallExpressionNoBF | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; } ; +CallExpressionNoRE + : MemberExpressionNoRE Arguments { $$ = new(driver.pool_) CYCall($1, $2); } + | CallExpressionNoRE Arguments { $$ = new(driver.pool_) CYCall($1, $2); } + | CallExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; } + ; + ArgumentList_ : "," ArgumentList { $$ = $2; } | { $$ = NULL; } @@ -806,6 +860,11 @@ LeftHandSideExpressionNoBF : NewExpressionNoBF { $$ = $1; } | CallExpressionNoBF { $$ = $1; } ; + +LeftHandSideExpressionNoRE + : NewExpressionNoRE { $$ = $1; } + | CallExpressionNoRE { $$ = $1; } + ; /* }}} */ /* 11.3 Postfix Expressions {{{ */ PostfixExpression @@ -819,6 +878,12 @@ PostfixExpressionNoBF | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); } | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); } ; + +PostfixExpressionNoRE + : AssigneeExpressionNoRE { $$ = $1; } + | LeftHandSideExpressionNoRE "++" { $$ = new(driver.pool_) CYPostIncrement($1); } + | LeftHandSideExpressionNoRE "--" { $$ = new(driver.pool_) CYPostDecrement($1); } + ; /* }}} */ /* 11.4 Unary Operators {{{ */ UnaryExpression_ @@ -844,6 +909,11 @@ UnaryExpressionNoBF : PostfixExpressionNoBF { $$ = $1; } | UnaryExpression_ { $$ = $1; } ; + +UnaryExpressionNoRE + : PostfixExpressionNoRE { $$ = $1; } + | UnaryExpression_ { $$ = $1; } + ; /* }}} */ /* 11.5 Multiplicative Operators {{{ */ MultiplicativeExpression @@ -1061,6 +1131,11 @@ AssigneeExpressionNoBF | UnaryAssigneeExpression { $$ = $1; } ; +AssigneeExpressionNoRE + : LeftHandSideExpressionNoRE { $$ = $1; } + | UnaryAssigneeExpression { $$ = $1; } + ; + AssignmentExpression : ConditionalExpression { $$ = $1; } | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; } @@ -1346,7 +1421,7 @@ FunctionDeclaration ; FunctionExpression - : LexSetRegExp "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($3, $5, $8); } + : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); } ; FormalParameterList_ @@ -1454,7 +1529,7 @@ CategoryStatement : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); } ; -PrimaryExpression_ +PrimaryExpressionBF : ClassExpression { $$ = $1; } ; @@ -1502,7 +1577,7 @@ SelectorExpression | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); } ; -PrimaryExpressionNoBF_ +PrimaryExpressionNo : MessageExpression { $$ = $1; } | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); } ; @@ -1512,7 +1587,7 @@ PrimaryExpressionNoBF_ @begin C /* Cycript (C): Pointer Indirection/Addressing {{{ */ UnaryAssigneeExpression - : "^" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); } + : "*" UnaryExpressionNoRE { $$ = new(driver.pool_) CYIndirect($2); } ; UnaryExpression_ @@ -1572,8 +1647,8 @@ XMLMarkup ; /* }}} */ /* 11.1 Primary Expressions {{{ */ -PrimaryExpressionNoBF_ - : PropertyIdentifier { $$ = $1; } +PrimaryExpressionNo + : PropertyIdentifier { $$ = new(driver.pool_) CYPropertyVariable($1); } | XMLInitialiser { $$ = $1; } | XMLListInitialiser { $$ = $1; } ; @@ -1590,23 +1665,23 @@ AttributeIdentifier ; PropertySelector_ - : PropertySelector - | "[" Expression "]" + : PropertySelector { $$ = $1; } + | "[" Expression "]" { $$ = new(driver.pool_) CYSelector($2); } ; PropertySelector - : Word { $$ = $1; } + : Identifier { $$ = new(driver.pool_) CYSelector($1); } | WildcardIdentifier { $$ = $1; } ; /* }}} */ /* 11.1.2 Qualified Identifiers {{{ */ QualifiedIdentifier_ - : PropertySelector_ { $$ = $1; } + : PropertySelector_ { $$ = new(driver.pool_) CYQualified(NULL, $1); } | QualifiedIdentifier { $$ = $1; } ; QualifiedIdentifier - : PropertySelector "::" PropertySelector_ { $$ = new(driver.pool_) CYQName($1, $3); } + : PropertySelector "::" PropertySelector_ { $$ = new(driver.pool_) CYQualified($1, $3); } ; /* }}} */ /* 11.1.3 Wildcard Identifiers {{{ */ @@ -1621,16 +1696,12 @@ XMLInitialiser ; XMLElement - : "<" XMLTagContent_ "/>" LexPop - | "<" XMLTagContent_ ">" LexSetXMLContent XMLElementContentOpt "" LexPop - ; - -XMLTagContent_ - : LexPushXMLTag XMLTagContent XMLWhitespaceOpt + : "<" XMLTagContent "/>" LexPop + | "<" XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "" LexPop ; XMLTagContent - : XMLTagName XMLAttributesOpt + : LexPushXMLTag XMLTagName XMLAttributes ; XMLExpression @@ -1642,14 +1713,14 @@ XMLTagName | XMLName ; -XMLAttributes - : XMLWhitespace XMLExpression - | XMLAttributeOpt XMLAttributes +XMLAttributes_ + : XMLAttributes_ XMLAttribute + | ; -XMLAttributesOpt - : XMLAttributes - | +XMLAttributes + : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt + | XMLAttributes_ XMLWhitespaceOpt ; XMLAttributeValue_ @@ -1661,11 +1732,6 @@ XMLAttribute : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_ ; -XMLAttributeOpt - : XMLAttribute - | - ; - XMLElementContent : XMLExpression XMLElementContentOpt | XMLMarkup XMLElementContentOpt @@ -1685,7 +1751,7 @@ XMLListInitialiser /* }}} */ /* 11.2 Left-Hand-Side Expressions {{{ */ PropertyIdentifier_ - : Word { $$ = $1; } + : Identifier { $$ = $1; } | PropertyIdentifier { $$ = $1; } ; @@ -1696,13 +1762,13 @@ MemberAccess ; /* }}} */ /* 12.1 The default xml namespace Statement {{{ */ -DefaultXMLNamespaceStatement +/* XXX: DefaultXMLNamespaceStatement : "default" "xml" "namespace" "=" Expression Terminator { $$ = new(driver.pool_) CYDefaultXMLNamespace($5); } ; Statement_ : DefaultXMLNamespaceStatement { $$ = $1; } - ; + ; */ /* }}} */ @end @@ -1731,7 +1797,7 @@ ComprehensionList : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; } ; -PrimaryExpressionNoBF_ +PrimaryExpressionNo : "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); } ; /* }}} */