-/* Cycript - Remote Execution Server and Disassembler
+/* Cycript - Inlining/Optimizing JavaScript Compiler
* Copyright (C) 2009 Jay Freeman (saurik)
*/
@end
@begin E4X
-#include "E4X.hpp"
+#include "E4X/Syntax.hpp"
@end
typedef struct {
CYAssignment *assignment_;
CYBoolean *boolean_;
CYClause *clause_;
- CYCatch *catch_;
+ cy::Syntax::Catch *catch_;
CYComprehension *comprehension_;
CYCompound *compound_;
CYDeclaration *declaration_;
@begin E4X
CYAttribute *attribute_;
+ CYPropertyIdentifier *propertyIdentifier_;
+ CYSelector *selector_;
@end
};
} YYSTYPE;
%token SlashRight "/>"
%token LeftSlash "</"
-%token At "@"
%token ColonColon "::"
%token PeriodPeriod ".."
@end
+@begin E4X ObjectiveC
+%token At "@"
+@end
+
%token Ampersand "&"
%token AmpersandAmpersand "&&"
%token AmpersandEqual "&="
%type <literal_> ArrayLiteral
%type <expression_> AssigneeExpression
%type <expression_> AssigneeExpressionNoBF
+%type <expression_> AssigneeExpressionNoRE
%type <expression_> AssignmentExpression
%type <assignment_> AssignmentExpression_
%type <expression_> AssignmentExpressionNoBF
%type <statement_> BreakStatement
%type <expression_> CallExpression
%type <expression_> CallExpressionNoBF
+%type <expression_> CallExpressionNoRE
%type <clause_> CaseBlock
%type <clause_> CaseClause
%type <clause_> CaseClausesOpt
%type <statement_> LabelledStatement
%type <expression_> LeftHandSideExpression
%type <expression_> LeftHandSideExpressionNoBF
+%type <expression_> LeftHandSideExpressionNoRE
//%type <statement_> LetStatement
%type <literal_> Literal
+%type <literal_> LiteralNoRE
+%type <literal_> LiteralRE
%type <expression_> LogicalANDExpression
%type <expression_> LogicalANDExpressionNoBF
%type <expression_> LogicalANDExpressionNoIn
%type <expression_> MemberExpression
%type <expression_> MemberExpression_
%type <expression_> MemberExpressionNoBF
+%type <expression_> MemberExpressionNoRE
%type <expression_> MultiplicativeExpression
%type <expression_> MultiplicativeExpressionNoBF
%type <expression_> NewExpression
%type <expression_> NewExpression_
%type <expression_> NewExpressionNoBF
+%type <expression_> NewExpressionNoRE
%type <null_> NullLiteral
%type <literal_> ObjectLiteral
%type <expression_> PostfixExpression
%type <expression_> PostfixExpressionNoBF
+%type <expression_> PostfixExpressionNoRE
%type <expression_> PrimaryExpression
-%type <expression_> PrimaryExpression_
+%type <expression_> PrimaryExpressionNo
%type <expression_> PrimaryExpressionNoBF
-%type <expression_> PrimaryExpressionNoBF_
+%type <expression_> PrimaryExpressionNoRE
+%type <expression_> PrimaryExpressionBF
%type <statement_> Program
%type <propertyName_> PropertyName
+%type <propertyName_> PropertyName_
%type <property_> PropertyNameAndValueList
%type <property_> PropertyNameAndValueList_
%type <property_> PropertyNameAndValueListOpt
%type <expression_> UnaryExpression
%type <expression_> UnaryExpression_
%type <expression_> UnaryExpressionNoBF
+%type <expression_> UnaryExpressionNoRE
%type <declaration_> VariableDeclaration
%type <declaration_> VariableDeclarationNoIn
%type <declarations_> VariableDeclarationList
@end
@begin E4X
-%type <identifier_> PropertyIdentifier_
-%type <identifier_> PropertySelector
-%type <identifier_> PropertySelector_
+%type <propertyIdentifier_> PropertyIdentifier_
+%type <selector_> PropertySelector
+%type <selector_> PropertySelector_
%type <identifier_> QualifiedIdentifier
%type <identifier_> QualifiedIdentifier_
%type <identifier_> WildcardIdentifier
%type <identifier_> XMLPI
%type <attribute_> AttributeIdentifier
-%type <statement_> DefaultXMLNamespaceStatement
+/* XXX: %type <statement_> DefaultXMLNamespaceStatement */
%type <expression_> PropertyIdentifier
%type <expression_> XMLListInitialiser
%type <expression_> 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 "<<" ">>" ">>>"
%left "||"
%right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="
-*/
-
-%nonassoc "if"
-%nonassoc "else"
%start Program
| "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; }
+ | "@" StringLiteral { $$ = $2; }
+ ;
+
+LiteralRE
+ : RegularExpressionLiteral { $$ = $1; }
+ ;
+
+Literal
+ : LiteralNoRE { $$ = $1; }
+ | LiteralRE { $$ = $1; }
;
NullLiteral
;
/* 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; }
| "(" Expression ")" { $$ = $2; }
;
-PrimaryExpression
- : LexSetRegExp PrimaryExpression_ { $$ = $2; }
- ;
-
-PrimaryExpressionNoBF
- : PrimaryExpressionNoBF_ { $$ = $1; }
+PrimaryExpressionBF
+ : ObjectLiteral { $$ = $1; }
;
/* }}} */
/* 11.1.4 Array Initialiser {{{ */
: 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 {{{ */
MemberExpression
: PrimaryExpression { $$ = $1; }
- | FunctionExpression { $$ = $1; }
+ | LexSetRegExp FunctionExpression { $$ = $2; }
| MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
| LexSetRegExp MemberExpression_ { $$ = $2; }
;
| MemberExpression_ { $$ = $1; }
;
+MemberExpressionNoRE
+ : PrimaryExpressionNoRE { $$ = $1; }
+ | FunctionExpression { $$ = $1; }
+ | MemberExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; }
+ | MemberExpression_ { $$ = $1; }
+ ;
+
NewExpression_
: "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
;
| NewExpression_ { $$ = $1; }
;
+NewExpressionNoRE
+ : MemberExpressionNoRE { $$ = $1; }
+ | NewExpression_ { $$ = $1; }
+ ;
+
CallExpression
: MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
| CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
| 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; }
: NewExpressionNoBF { $$ = $1; }
| CallExpressionNoBF { $$ = $1; }
;
+
+LeftHandSideExpressionNoRE
+ : NewExpressionNoRE { $$ = $1; }
+ | CallExpressionNoRE { $$ = $1; }
+ ;
/* }}} */
/* 11.3 Postfix Expressions {{{ */
PostfixExpression
| 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_
: PostfixExpressionNoBF { $$ = $1; }
| UnaryExpression_ { $$ = $1; }
;
+
+UnaryExpressionNoRE
+ : PostfixExpressionNoRE { $$ = $1; }
+ | UnaryExpression_ { $$ = $1; }
+ ;
/* }}} */
/* 11.5 Multiplicative Operators {{{ */
MultiplicativeExpression
| UnaryAssigneeExpression { $$ = $1; }
;
+AssigneeExpressionNoRE
+ : LeftHandSideExpressionNoRE { $$ = $1; }
+ | UnaryAssigneeExpression { $$ = $1; }
+ ;
+
AssignmentExpression
: ConditionalExpression { $$ = $1; }
| AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
/* }}} */
/* 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; }
;
;
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_
: "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
;
-PrimaryExpression_
+PrimaryExpressionBF
: ClassExpression { $$ = $1; }
;
| 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); }
+ : "*" UnaryExpressionNoRE { $$ = new(driver.pool_) CYIndirect($2); }
;
UnaryExpression_
;
/* }}} */
/* 11.1 Primary Expressions {{{ */
-PrimaryExpressionNoBF_
- : PropertyIdentifier { $$ = $1; }
+PrimaryExpressionNo
+ : PropertyIdentifier { $$ = new(driver.pool_) CYPropertyVariable($1); }
| XMLInitialiser { $$ = $1; }
| XMLListInitialiser { $$ = $1; }
;
;
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 {{{ */
;
XMLElement
- : "<" XMLTagContent_ "/>" LexPop
- | "<" XMLTagContent_ ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt ">" LexPop
- ;
-
-XMLTagContent_
- : LexPushXMLTag XMLTagContent XMLWhitespaceOpt
+ : "<" XMLTagContent "/>" LexPop
+ | "<" XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt ">" LexPop
;
XMLTagContent
- : XMLTagName XMLAttributesOpt
+ : LexPushXMLTag XMLTagName XMLAttributes
;
XMLExpression
| XMLName
;
-XMLAttributes
- : XMLWhitespace XMLExpression
- | XMLAttributeOpt XMLAttributes
+XMLAttributes_
+ : XMLAttributes_ XMLAttribute
+ |
;
-XMLAttributesOpt
- : XMLAttributes
- |
+XMLAttributes
+ : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
+ | XMLAttributes_ XMLWhitespaceOpt
;
XMLAttributeValue_
: XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
;
-XMLAttributeOpt
- : XMLAttribute
- |
- ;
-
XMLElementContent
: XMLExpression XMLElementContentOpt
| XMLMarkup XMLElementContentOpt
/* }}} */
/* 11.2 Left-Hand-Side Expressions {{{ */
PropertyIdentifier_
- : Word { $$ = $1; }
+ : Identifier { $$ = $1; }
| PropertyIdentifier { $$ = $1; }
;
;
/* }}} */
/* 12.1 The default xml namespace Statement {{{ */
-DefaultXMLNamespaceStatement
+/* XXX: DefaultXMLNamespaceStatement
: "default" "xml" "namespace" "=" Expression Terminator { $$ = new(driver.pool_) CYDefaultXMLNamespace($5); }
;
Statement_
: DefaultXMLNamespaceStatement { $$ = $1; }
- ;
+ ; */
/* }}} */
@end
: ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
;
-PrimaryExpressionNoBF_
+PrimaryExpressionNo
: "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); }
;
/* }}} */