X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/62014ea9ffc6c31f053863a89d783475a3937d74..b09da87b6557610325d46e3294ea0b6aba69ebf0:/Cycript.y?ds=sidebyside diff --git a/Cycript.y b/Cycript.y index 31fd1bc..e51a0ec 100644 --- a/Cycript.y +++ b/Cycript.y @@ -11,23 +11,29 @@ typedef struct { bool newline_; union { + bool bool_; + CYArgument *argument_; CYBoolean *boolean_; CYClause *clause_; CYCatch *catch_; + CYCompound *compound_; CYDeclaration *declaration_; CYDeclarations *declarations_; CYElement *element_; CYExpression *expression_; CYFalse *false_; + CYField *field_; CYForInitialiser *for_; CYForInInitialiser *forin_; + CYFunctionParameter *functionParameter_; CYIdentifier *identifier_; CYLiteral *literal_; + CYMessage *message_; + CYMessageParameter *messageParameter_; CYName *name_; CYNull *null_; CYNumber *number_; - CYParameter *parameter_; CYProperty *property_; CYSelectorPart *selector_; CYSource *source_; @@ -119,7 +125,9 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %token OpenBracket "[" %token CloseBracket "]" +%token AtClass "@class" %token AtSelector "@selector" +%token AtEnd "@end" %token Break "break" %token Case "case" @@ -150,6 +158,38 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %token While "while" %token With "with" +%token Abstract "abstract" +%token Boolean "boolean" +%token Byte "byte" +%token Char "char" +%token Class "class" +%token Const "const" +%token Debugger "debugger" +%token Double "double" +%token Enum "enum" +%token Export "export" +%token Extends "extends" +%token Final "final" +%token Float "float" +%token Goto "goto" +%token Implements "implements" +%token Import "import" +%token Int "int" +%token Interface "interface" +%token Long "long" +%token Native "native" +%token Package "package" +%token Private "private" +%token Protected "protected" +%token Public "public" +%token Short "short" +%token Static "static" +%token Super "super" +%token Synchronized "synchronized" +%token Throws "throws" +%token Transient "transient" +%token Volatile "volatile" + %token Identifier %token NumericLiteral %token StringLiteral @@ -182,6 +222,11 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type CaseClause %type CaseClausesOpt %type CatchOpt +%type ClassDeclaration +%type ClassMessageDeclaration +%type ClassMessageDeclarationListOpt +%type ClassSuperOpt +%type ClassFieldList %type ConditionalExpression %type ConditionalExpressionNoBF %type ConditionalExpressionNoIn @@ -199,10 +244,10 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type EqualityExpressionNoIn %type Expression %type ExpressionOpt -%type Expression_ +%type Expression_ %type ExpressionNoBF %type ExpressionNoIn -%type ExpressionNoIn_ +%type ExpressionNoIn_ %type ExpressionNoInOpt %type ExpressionStatement %type FinallyOpt @@ -210,8 +255,8 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type ForStatementInitialiser %type ForInStatement %type ForInStatementInitialiser -%type FormalParameterList -%type FormalParameterList_ +%type FormalParameterList +%type FormalParameterList_ %type FunctionBody %type FunctionDeclaration %type FunctionExpression @@ -236,6 +281,11 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type MemberExpression %type MemberExpression_ %type MemberExpressionNoBF +%type MessageParameter +%type MessageParameters +%type MessageParameterList +%type MessageParameterListOpt +%type MessageScope %type MultiplicativeExpression %type MultiplicativeExpressionNoBF %type NewExpression @@ -270,6 +320,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type SwitchStatement %type ThrowStatement %type TryStatement +%type TypeOpt %type UnaryExpression %type UnaryExpression_ %type UnaryExpressionNoBF @@ -291,6 +342,19 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type SelectorList %type VariadicCall +%left "*" "/" "%" +%left "+" "-" +%left "<<" ">>" ">>>" +%left "<" ">" "<=" ">=" "instanceof" "in" +%left "==" "!=" "===" "!==" +%left "&" +%left "^" +%left "|" +%left "&&" +%left "||" + +%right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|=" + %nonassoc "if" %nonassoc "else" @@ -327,32 +391,63 @@ WordOpt Word : Identifier { $$ = $1; } + | "abstract" { $$ = $1; } + | "boolean" { $$ = $1; } | "break" NewLineOpt { $$ = $1; } + | "byte" { $$ = $1; } | "case" { $$ = $1; } | "catch" { $$ = $1; } + | "char" { $$ = $1; } + | "class" { $$ = $1; } + | "const" { $$ = $1; } | "continue" NewLineOpt { $$ = $1; } + | "debugger" { $$ = $1; } | "default" { $$ = $1; } | "delete" { $$ = $1; } | "do" { $$ = $1; } + | "double" { $$ = $1; } | "else" { $$ = $1; } + | "enum" { $$ = $1; } + | "export" { $$ = $1; } + | "extends" { $$ = $1; } | "false" { $$ = $1; } + | "final" { $$ = $1; } | "finally" { $$ = $1; } + | "float" { $$ = $1; } | "for" { $$ = $1; } | "function" { $$ = $1; } + | "goto" { $$ = $1; } | "if" { $$ = $1; } + | "implements" { $$ = $1; } + | "import" { $$ = $1; } /* XXX: | "in" { $$ = $1; } */ /* XXX: | "instanceof" { $$ = $1; } */ + | "int" { $$ = $1; } + | "interface" { $$ = $1; } + | "long" { $$ = $1; } + | "native" { $$ = $1; } | "new" { $$ = $1; } | "null" { $$ = $1; } + | "package" { $$ = $1; } + | "private" { $$ = $1; } + | "protected" { $$ = $1; } + | "public" { $$ = $1; } | "return" NewLineOpt { $$ = $1; } + | "short" { $$ = $1; } + | "static" { $$ = $1; } + | "super" { $$ = $1; } | "switch" { $$ = $1; } + | "synchronized" { $$ = $1; } | "this" { $$ = $1; } | "throw" NewLineOpt { $$ = $1; } + | "throws" { $$ = $1; } + | "transient" { $$ = $1; } | "true" { $$ = $1; } | "try" { $$ = $1; } | "typeof" { $$ = $1; } | "var" { $$ = $1; } | "void" { $$ = $1; } + | "volatile" { $$ = $1; } | "while" { $$ = $1; } | "with" { $$ = $1; } ; @@ -398,7 +493,7 @@ PrimaryExpressionNoBF /* }}} */ /* 11.1.4 Array Initialiser {{{ */ ArrayLiteral - : "[" ElementList "]" { $$ = new(driver.pool_) CYArray($2); } + : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); } ; Element @@ -791,12 +886,12 @@ AssignmentExpressionNoBF ; Expression_ - : "," Expression { $$ = $2; } + : "," Expression { $$ = new(driver.pool_) CYCompound($2); } | { $$ = NULL; } ; ExpressionNoIn_ - : "," ExpressionNoIn { $$ = $2; } + : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); } | { $$ = NULL; } ; @@ -811,15 +906,15 @@ ExpressionNoInOpt ; Expression - : AssignmentExpression Expression_ { if ($1) { $1->SetNext($2); $$ = $1; } else $$ = $2; } + : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } ; ExpressionNoIn - : AssignmentExpressionNoIn ExpressionNoIn_ { if ($1) { $1->SetNext($2); $$ = $1; } else $$ = $2; } + : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } ; ExpressionNoBF - : AssignmentExpressionNoBF Expression_ { if ($1) { $1->SetNext($2); $$ = $1; } else $$ = $2; } + : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; } ; Statement @@ -1024,7 +1119,7 @@ FormalParameterList_ ; FormalParameterList - : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYParameter($1, $2); } + : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); } | { $$ = NULL; } ; @@ -1047,6 +1142,60 @@ SourceElement ; /* Objective-C Extensions {{{ */ +ClassSuperOpt + : ":" MemberExpressionNoBF { $$ = $2; } + | { $$ = NULL; } + ; + +ClassFieldList + : "{" "}" { $$ = NULL; } + ; + +MessageScope + : "+" { $$ = false; } + | "-" { $$ = true; } + ; + +TypeOpt + : "(" Expression ")" { $$ = $2; } + | { $$ = NULL; } + ; + +MessageParameter + : Word ":" TypeOpt Identifier { $$ = new CYMessageParameter($1, $3, $4); } + ; + +MessageParameterListOpt + : MessageParameterList { $$ = $1; } + | { $$ = NULL; } + ; + +MessageParameterList + : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; } + ; + +MessageParameters + : MessageParameterList { $$ = $1; } + | Word { $$ = new CYMessageParameter($1, NULL, NULL); } + ; + +ClassMessageDeclaration + : MessageScope TypeOpt MessageParameters "{" FunctionBody "}" { $$ = new CYMessage($1, $2, $3, $5); } + ; + +ClassMessageDeclarationListOpt + : ClassMessageDeclarationListOpt ClassMessageDeclaration { if ($1) { $1->SetNext($2); $$ = $1; } else $$ = $2; } + | { $$ = NULL; } + ; + +ClassDeclaration + : "@class" Identifier ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new CYClass($2, $3, $4, $5); } + ; + +SourceElement + : ClassDeclaration { $$ = $1; } + ; + VariadicCall : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); } | { $$ = NULL; } @@ -1067,7 +1216,7 @@ SelectorList ; MessageExpression - : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYMessage($2, $3); } + : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSend($2, $3); } ; SelectorExpressionOpt