bool bool_;
CYArgument *argument_;
+ CYAssignment *assignment_;
CYBoolean *boolean_;
CYClause *clause_;
CYCatch *catch_;
+ CYClassName *className_;
CYCompound *compound_;
CYDeclaration *declaration_;
CYDeclarations *declarations_;
CYForInInitialiser *forin_;
CYFunctionParameter *functionParameter_;
CYIdentifier *identifier_;
+ CYInfix *infix_;
CYLiteral *literal_;
+ CYMember *member_;
CYMessage *message_;
CYMessageParameter *messageParameter_;
- CYName *name_;
CYNull *null_;
CYNumber *number_;
CYProperty *property_;
+ CYPropertyName *propertyName_;
CYSelectorPart *selector_;
CYSource *source_;
CYStatement *statement_;
%type <argument_> ArgumentListOpt
%type <argument_> Arguments
%type <literal_> ArrayLiteral
+%type <expression_> AssigneeExpression
+%type <expression_> AssigneeExpression_
+%type <expression_> AssigneeExpressionNoBF
%type <expression_> AssignmentExpression
+%type <assignment_> AssignmentExpression_
%type <expression_> AssignmentExpressionNoBF
%type <expression_> AssignmentExpressionNoIn
%type <expression_> BitwiseANDExpression
%type <clause_> CaseClause
%type <clause_> CaseClausesOpt
%type <catch_> CatchOpt
-%type <source_> ClassDeclaration
+%type <statement_> CategoryStatement
+%type <expression_> ClassExpression
%type <message_> ClassMessageDeclaration
%type <message_> ClassMessageDeclarationListOpt
+%type <className_> ClassName
+%type <className_> ClassNameOpt
%type <expression_> ClassSuperOpt
%type <field_> ClassFieldList
%type <expression_> ConditionalExpression
%type <statement_> IterationStatement
%type <statement_> LabelledStatement
%type <expression_> LeftHandSideExpression
-%type <expression_> LeftHandSideExpression_
%type <expression_> LeftHandSideExpressionNoBF
%type <literal_> Literal
%type <expression_> LogicalANDExpression
%type <expression_> LogicalORExpression
%type <expression_> LogicalORExpressionNoBF
%type <expression_> LogicalORExpressionNoIn
+%type <member_> MemberAccess
%type <expression_> MemberExpression
%type <expression_> MemberExpression_
%type <expression_> MemberExpressionNoBF
%type <expression_> PrimaryExpression_
%type <expression_> PrimaryExpressionNoBF
%type <source_> Program
-%type <name_> PropertyName
+%type <propertyName_> PropertyName
%type <property_> PropertyNameAndValueList
%type <property_> PropertyNameAndValueList_
%type <property_> PropertyNameAndValueListOpt
%type <expression_> RelationalExpression
+%type <infix_> RelationalExpression_
%type <expression_> RelationalExpressionNoBF
%type <expression_> RelationalExpressionNoIn
+%type <infix_> RelationalExpressionNoIn_
%type <statement_> ReturnStatement
%type <selector_> SelectorExpression
%type <selector_> SelectorExpression_
: "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); }
;
+MemberAccess
+ : "[" Expression "]" { $$ = new(driver.pool_) CYDirectMember(NULL, $2); }
+ | "." Identifier { $$ = new(driver.pool_) CYDirectMember(NULL, new(driver.pool_) CYString($2)); }
+ ;
+
MemberExpression
: PrimaryExpression { $$ = $1; }
| FunctionExpression { $$ = $1; }
- | MemberExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
- | MemberExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
+ | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
| MemberExpression_ { $$ = $1; }
;
MemberExpressionNoBF
: PrimaryExpressionNoBF { $$ = $1; }
- | MemberExpressionNoBF "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
- | MemberExpressionNoBF "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
+ | MemberExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
| MemberExpression_ { $$ = $1; }
;
CallExpression
: MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
| CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
- | CallExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
- | CallExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
+ | CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
;
CallExpressionNoBF
: MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
| CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
- | CallExpressionNoBF "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
- | CallExpressionNoBF "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
+ | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
;
ArgumentList_
LeftHandSideExpression
: NewExpression { $$ = $1; }
| CallExpression { $$ = $1; }
- | LeftHandSideExpression_ { $$ = $1; }
;
LeftHandSideExpressionNoBF
: NewExpressionNoBF { $$ = $1; }
| CallExpressionNoBF { $$ = $1; }
- | LeftHandSideExpression_ { $$ = $1; }
;
PostfixExpression
- : LeftHandSideExpression { $$ = $1; }
+ : AssigneeExpression { $$ = $1; }
| LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
| LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
;
PostfixExpressionNoBF
- : LeftHandSideExpressionNoBF { $$ = $1; }
+ : AssigneeExpressionNoBF { $$ = $1; }
| LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
| LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
;
| ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
;
+RelationalExpressionNoIn_
+ : "<" ShiftExpression { $$ = new(driver.pool_) CYLess(NULL, $2); }
+ | ">" ShiftExpression { $$ = new(driver.pool_) CYGreater(NULL, $2); }
+ | "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual(NULL, $2); }
+ | ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual(NULL, $2); }
+ | "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf(NULL, $2); }
+ ;
+
+RelationalExpression_
+ : RelationalExpressionNoIn_ { $$ = $1; }
+ | "in" ShiftExpression { $$ = new(driver.pool_) CYIn(NULL, $2); }
+ ;
+
RelationalExpression
: ShiftExpression { $$ = $1; }
- | RelationalExpression "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
- | RelationalExpression ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
- | RelationalExpression "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
- | RelationalExpression ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
- | RelationalExpression "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
- | RelationalExpression "in" ShiftExpression { $$ = new(driver.pool_) CYIn($1, $3); }
+ | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
;
RelationalExpressionNoIn
: ShiftExpression { $$ = $1; }
- | RelationalExpressionNoIn "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
- | RelationalExpressionNoIn ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
- | RelationalExpressionNoIn "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
- | RelationalExpressionNoIn ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
- | RelationalExpressionNoIn "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
+ | RelationalExpressionNoIn RelationalExpressionNoIn_ { $2->SetLeft($1); $$ = $2; }
;
RelationalExpressionNoBF
: ShiftExpressionNoBF { $$ = $1; }
- | RelationalExpressionNoBF "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
- | RelationalExpressionNoBF ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
- | RelationalExpressionNoBF "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
- | RelationalExpressionNoBF ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
- | RelationalExpressionNoBF "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
- | RelationalExpressionNoBF "in" ShiftExpression { $$ = new(driver.pool_) CYIn($1, $3); }
+ | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
;
EqualityExpression
| LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
;
+AssignmentExpression_
+ : "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign(NULL, $2); }
+ | "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign(NULL, $2); }
+ | "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign(NULL, $2); }
+ | "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign(NULL, $2); }
+ | "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign(NULL, $2); }
+ | "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign(NULL, $2); }
+ | "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign(NULL, $2); }
+ | ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign(NULL, $2); }
+ | ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign(NULL, $2); }
+ | "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign(NULL, $2); }
+ | "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign(NULL, $2); }
+ | "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign(NULL, $2); }
+ ;
+
+AssigneeExpression
+ : LeftHandSideExpression { $$ = $1; }
+ | AssigneeExpression_ { $$ = $1; }
+ ;
+
+AssigneeExpressionNoBF
+ : LeftHandSideExpressionNoBF { $$ = $1; }
+ | AssigneeExpression_ { $$ = $1; }
+ ;
+
AssignmentExpression
: ConditionalExpression { $$ = $1; }
- | LeftHandSideExpression "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign($1, $3); }
- | LeftHandSideExpression "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
- | LeftHandSideExpression "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
- | LeftHandSideExpression "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
- | LeftHandSideExpression "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign($1, $3); }
- | LeftHandSideExpression "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
- | LeftHandSideExpression "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
- | LeftHandSideExpression ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
- | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
- | LeftHandSideExpression "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
- | LeftHandSideExpression "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
- | LeftHandSideExpression "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
+ | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
;
AssignmentExpressionNoIn
: ConditionalExpressionNoIn { $$ = $1; }
- | LeftHandSideExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
- | LeftHandSideExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
- | LeftHandSideExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
- | LeftHandSideExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
- | LeftHandSideExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
- | LeftHandSideExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
- | LeftHandSideExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
- | LeftHandSideExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
- | LeftHandSideExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
- | LeftHandSideExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
- | LeftHandSideExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
- | LeftHandSideExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
+ | AssigneeExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
+ | AssigneeExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
+ | AssigneeExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
+ | AssigneeExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
+ | AssigneeExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
+ | AssigneeExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
+ | AssigneeExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
+ | AssigneeExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
+ | AssigneeExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
+ | AssigneeExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
+ | AssigneeExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
+ | AssigneeExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
;
AssignmentExpressionNoBF
: ConditionalExpressionNoBF { $$ = $1; }
- | LeftHandSideExpressionNoBF "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign($1, $3); }
- | LeftHandSideExpressionNoBF "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
- | LeftHandSideExpressionNoBF "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
- | LeftHandSideExpressionNoBF "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
- | LeftHandSideExpressionNoBF "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign($1, $3); }
- | LeftHandSideExpressionNoBF "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
- | LeftHandSideExpressionNoBF "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
- | LeftHandSideExpressionNoBF ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
- | LeftHandSideExpressionNoBF ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
- | LeftHandSideExpressionNoBF "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
- | LeftHandSideExpressionNoBF "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
- | LeftHandSideExpressionNoBF "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
+ | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
;
Expression_
;
Block
- : "{" StatementListOpt "}" { $$ = $2 ?: new(driver.pool_) CYEmpty(); }
+ : "{" StatementListOpt "}" { if ($2) $$ = new(driver.pool_) CYBlock($2); else $$ = new(driver.pool_) CYEmpty(); }
;
StatementList
| { $$ = NULL; }
;
-ClassDeclaration
- : "@class" Identifier ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new CYClass($2, $3, $4, $5); }
+ClassName
+ : Identifier { $$ = $1; }
+ | "(" AssignmentExpression ")" { $$ = $2; }
;
-SourceElement
- : ClassDeclaration { $$ = $1; }
+ClassNameOpt
+ : ClassName { $$ = $1; }
+ | { $$ = NULL; }
+ ;
+
+ClassExpression
+ : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new CYClass($2, $3, $4, $5); }
+ ;
+
+CategoryStatement
+ : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new CYCategory($2, $3); }
+ ;
+
+PrimaryExpression_
+ : ClassExpression { $$ = $1; }
+ ;
+
+Statement
+ : CategoryStatement
;
VariadicCall
;
/* }}} */
-LeftHandSideExpression_
- : "*" LeftHandSideExpression { $$ = new(driver.pool_) CYIndirect($2); }
+AssigneeExpression_
+ : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); }
;
UnaryExpression_
: "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); }
;
+MemberAccess
+ : "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); }
+ ;
+
+/*
+
+IfComprehension
+ : "if" "(" Expression ")"
+ ;
+
+ForComprehension
+ : "for" "(" ForInStatementInitialiser "in" Expression ")"
+ ;
+
+ComprehensionListOpt
+ : ComprehensionList
+ | IfComprehension
+ |
+ ;
+
+ComprehensionList
+ : ForComprehension ComprehensionListOpt
+ ;
+
+PrimaryExpression_
+ : "[" AssignmentExpression ComprehensionList "]"
+ ;
+
+*/
+
%%