+/* 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_
bool newline_;
union {
+ bool bool_;
+
CYArgument *argument_;
CYBoolean *boolean_;
CYClause *clause_;
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_;
%token OpenBracket "["
%token CloseBracket "]"
+%token AtClass "@class"
%token AtSelector "@selector"
-%token AtImplementation "@implementation"
%token AtEnd "@end"
%token <word_> Break "break"
%type <clause_> CaseClause
%type <clause_> CaseClausesOpt
%type <catch_> CatchOpt
+%type <source_> ClassDeclaration
+%type <message_> ClassMessageDeclaration
+%type <message_> ClassMessageDeclarationListOpt
+%type <expression_> ClassSuperOpt
+%type <field_> ClassFieldList
%type <expression_> ConditionalExpression
%type <expression_> ConditionalExpressionNoBF
%type <expression_> ConditionalExpressionNoIn
%type <for_> ForStatementInitialiser
%type <statement_> ForInStatement
%type <forin_> ForInStatementInitialiser
-%type <parameter_> FormalParameterList
-%type <parameter_> FormalParameterList_
+%type <functionParameter_> FormalParameterList
+%type <functionParameter_> FormalParameterList_
%type <source_> FunctionBody
%type <source_> FunctionDeclaration
%type <expression_> FunctionExpression
%type <expression_> MemberExpression
%type <expression_> MemberExpression_
%type <expression_> MemberExpressionNoBF
+%type <messageParameter_> MessageParameter
+%type <messageParameter_> MessageParameters
+%type <messageParameter_> MessageParameterList
+%type <messageParameter_> MessageParameterListOpt
+%type <bool_> MessageScope
%type <expression_> MultiplicativeExpression
%type <expression_> MultiplicativeExpressionNoBF
%type <expression_> NewExpression
%type <statement_> SwitchStatement
%type <statement_> ThrowStatement
%type <statement_> TryStatement
+%type <expression_> TypeOpt
%type <expression_> UnaryExpression
%type <expression_> UnaryExpression_
%type <expression_> UnaryExpressionNoBF
%type <argument_> SelectorList
%type <argument_> VariadicCall
+%left "*" "/" "%"
+%left "+" "-"
+%left "<<" ">>" ">>>"
+%left "<" ">" "<=" ">=" "instanceof" "in"
+%left "==" "!=" "===" "!=="
+%left "&"
+%left "^"
+%left "|"
+%left "&&"
+%left "||"
+
+%right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="
+
%nonassoc "if"
%nonassoc "else"
;
FormalParameterList
- : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYParameter($1, $2); }
+ : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); }
| { $$ = NULL; }
;
;
/* 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; }
;
MessageExpression
- : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYMessage($2, $3); }
+ : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSend($2, $3); }
;
SelectorExpressionOpt