X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/5befe15eb839184507218ab3feb9e375edf335c3..bce8339b629582dd04df0570468ac746adc0fcf7:/Cycript.y diff --git a/Cycript.y b/Cycript.y index 46e81a4..a82e7f8 100644 --- a/Cycript.y +++ b/Cycript.y @@ -1,3 +1,42 @@ +/* Cycript - Remove Execution Server and Disassembler + * Copyright (C) 2009 Jay Freeman (saurik) +*/ + +/* Modified BSD License {{{ */ +/* + * Redistribution and use in source and binary + * forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the + * above copyright notice, this list of conditions + * and the following disclaimer. + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions + * and the following disclaimer in the documentation + * and/or other materials provided with the + * distribution. + * 3. The name of the author may not be used to endorse + * or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/* }}} */ + %code top { #include "Cycript.tab.hh" #define scanner driver.scanner_ @@ -11,25 +50,31 @@ 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_; - CYSelector *selector_; + CYSelectorPart *selector_; CYSource *source_; CYStatement *statement_; CYString *string_; @@ -119,7 +164,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 +197,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 +261,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 +283,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 +294,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 +320,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 +359,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 +381,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 +430,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 +532,7 @@ PrimaryExpressionNoBF /* }}} */ /* 11.1.4 Array Initialiser {{{ */ ArrayLiteral - : "[" ElementList "]" { $$ = new(driver.pool_) CYArray($2); } + : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); } ; Element @@ -791,12 +925,12 @@ AssignmentExpressionNoBF ; Expression_ - : "," Expression { $$ = $2; } + : "," Expression { $$ = new(driver.pool_) CYCompound($2); } | { $$ = NULL; } ; ExpressionNoIn_ - : "," ExpressionNoIn { $$ = $2; } + : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); } | { $$ = NULL; } ; @@ -811,15 +945,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 +1158,7 @@ FormalParameterList_ ; FormalParameterList - : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYParameter($1, $2); } + : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); } | { $$ = NULL; } ; @@ -1047,6 +1181,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 { $2->SetNext($1); $$ = $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 +1255,7 @@ SelectorList ; MessageExpression - : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYMessage($2, $3); } + : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSend($2, $3); } ; SelectorExpressionOpt @@ -1076,17 +1264,17 @@ SelectorExpressionOpt ; SelectorExpression_ - : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelector($1, true, $3); } + : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); } ; SelectorExpression : SelectorExpression_ { $$ = $1; } - | Word { $$ = new(driver.pool_) CYSelector($1, false, NULL); } + | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); } ; PrimaryExpression_ : MessageExpression { $$ = $1; } - | "@selector" "(" SelectorExpression ")" { $$ = $3; } + | "@selector" "(" SelectorExpression ")" { $$ = new CYSelector($3); } ; /* }}} */