CYTrue *true_;
CYWord *word_;
+@begin C
+ CYTypeModifier *modifier_;
+ CYTypeSpecifier *specifier_;
+ CYTypedIdentifier *typedIdentifier_;
+ CYTypedParameter *typedParameter_;
+@end
+
@begin ObjectiveC
CYClassName *className_;
CYField *field_;
CYMessageParameter *messageParameter_;
CYProtocol *protocol_;
CYSelectorPart *selector_;
- CYTypeModifier *modifier_;
- CYTypedIdentifier *typedIdentifier_;
- CYTypedParameter *typedParameter_;
@end
@begin E4X
@begin E4X ObjectiveC
%token At "@"
+%token Pound "#"
@end
%token Ampersand "&"
@begin C
%token <identifier_> Typedef "typedef"
+%token <identifier_> Unsigned "unsigned"
+%token <identifier_> Signed "signed"
+@end
+
+@begin C
+%token AtEncode "@encode"
@end
@begin ObjectiveC
%token AtImplementation "@implementation"
%token AtImplementation_ ";@implementation"
%token AtImport "@import"
-%token AtEncode "@encode"
%token AtEnd "@end"
%token AtSelector "@selector"
%token <identifier_> Yes "YES"
%type <argument_> ArgumentList
%type <argument_> ArgumentListOpt
%type <argument_> Arguments
+%type <expression_> ArrayComprehension
+%type <expression_> ArrayInitialiser
%type <literal_> ArrayLiteral
%type <expression_> ArrowFunction
%type <functionParameter_> ArrowParameters
%type <clause_> CaseClause
%type <clause_> CaseClausesOpt
%type <catch_> CatchOpt
-%type <comprehension_> ComprehensionForList
-%type <comprehension_> ComprehensionForListOpt
-%type <comprehension_> ComprehensionList
-%type <comprehension_> ComprehensionListOpt
+%type <expression_> Comprehension
+%type <comprehension_> ComprehensionFor
+%type <comprehension_> ComprehensionIf
+%type <comprehension_> ComprehensionTail
%type <expression_> ConditionalExpression
%type <statement_> ContinueStatement
%type <statement_> ConciseBody
%type <expression_> ExpressionOpt
%type <statement_> ExpressionStatement
%type <finally_> FinallyOpt
-%type <comprehension_> ForComprehension
%type <for_> ForStatementInitialiser
%type <forin_> ForInStatementInitialiser
%type <declaration_> FormalParameter
%type <expression_> FunctionExpression
%type <identifier_> Identifier
%type <identifier_> IdentifierOpt
+%type <identifier_> IdentifierType
%type <word_> IdentifierName
-%type <comprehension_> IfComprehension
%type <statement_> IfStatement
%type <expression_> Initialiser
%type <expression_> InitialiserOpt
%type <member_> MemberAccess
%type <expression_> MemberExpression_
%type <expression_> MemberExpression
+%type <module_> Module
%type <expression_> MultiplicativeExpression
%type <expression_> NewExpression
%type <null_> NullLiteral
%type <word_> WordOpt
%type <expression_> Variable
-@begin ObjectiveC
+@begin C
%type <typedIdentifier_> ArrayedType
+%type <expression_> EncodedType
+%type <modifier_> FunctionedType
+%type <specifier_> IntegerType
+%type <specifier_> IntegerTypeOpt
+%type <typedIdentifier_> PrefixedType
+%type <specifier_> PrimitiveType
+%type <typedIdentifier_> TypeParenthetical
+%type <typedIdentifier_> TypeSignifier
+%type <typedIdentifier_> SuffixedType
+%type <modifier_> TypeQualifierLeft
+%type <typedIdentifier_> TypeQualifierRight
+%type <typedIdentifier_> TypedIdentifier
+%type <typedParameter_> TypedParameterList_
+%type <typedParameter_> TypedParameterList
+%type <typedParameter_> TypedParameterListOpt
+@end
+
+@begin ObjectiveC
%type <expression_> BoxableExpression
%type <statement_> CategoryStatement
%type <expression_> ClassExpression
%type <protocol_> ClassProtocolListOpt
%type <protocol_> ClassProtocols
%type <protocol_> ClassProtocolsOpt
-%type <expression_> EncodedType
-%type <modifier_> FunctionedType
%type <expression_> MessageExpression
%type <messageParameter_> MessageParameter
%type <messageParameter_> MessageParameters
%type <messageParameter_> MessageParameterListOpt
%type <bool_> MessageScope
%type <typedIdentifier_> ModifiedType
-%type <module_> Module
-%type <typedIdentifier_> PrefixedType
-%type <expression_> PrimitiveType
%type <argument_> SelectorCall_
%type <argument_> SelectorCall
%type <selector_> SelectorExpression_
%type <selector_> SelectorExpressionOpt
%type <argument_> SelectorList
%type <word_> SelectorWordOpt
-%type <typedIdentifier_> SuffixedType
%type <expression_> TypeOpt
-%type <typedIdentifier_> TypeParenthetical
-%type <modifier_> TypeQualifierLeft
-%type <typedIdentifier_> TypeQualifierRight
-%type <typedIdentifier_> TypeSignifier
-%type <typedIdentifier_> TypedIdentifier
-%type <typedParameter_> TypedParameterList_
-%type <typedParameter_> TypedParameterList
-%type <typedParameter_> TypedParameterListOpt
%type <argument_> VariadicCall
@end
| { $$ = NULL; }
;
-Identifier
+IdentifierType
: Identifier_ { $$ = $1; }
-@begin C
- | "typedef" { $$ = $1; }
- | "YES" { $$ = $1; }
- | "NO" { $$ = $1; }
-@end
-
| "implements" { $$ = $1; }
| "interface" { $$ = $1; }
| "package" { $$ = $1; }
| "abstract" { $$ = $1; }
| "boolean" { $$ = $1; }
| "byte" { $$ = $1; }
- | "char" { $$ = $1; }
| "double" { $$ = $1; }
| "final" { $$ = $1; }
| "float" { $$ = $1; }
| "goto" { $$ = $1; }
- | "int" { $$ = $1; }
- | "long" { $$ = $1; }
| "native" { $$ = $1; }
- | "short" { $$ = $1; }
| "synchronized" { $$ = $1; }
| "throws" { $$ = $1; }
| "transient" { $$ = $1; }
- | "volatile" { $$ = $1; }
// XXX: currently I only have this as Word
// | "let" { $$ = $1; }
| "of" { $$ = $1; }
;
+Identifier
+ : IdentifierType
+ | "char" { $$ = $1; }
+ | "int" { $$ = $1; }
+ | "long" { $$ = $1; }
+ | "short" { $$ = $1; }
+ | "volatile" { $$ = $1; }
+@begin C
+ | "typedef" { $$ = $1; }
+ | "unsigned" { $$ = $1; }
+ | "signed" { $$ = $1; }
+@end
+@begin ObjectiveC
+ | "YES" { $$ = $1; }
+ | "NO" { $$ = $1; }
+@end
+ ;
+
IdentifierOpt
: Identifier { $$ = $1; }
| { $$ = NULL; }
: "this" { $$ = $1; }
| Variable { $$ = $1; }
| Literal { $$ = $1; }
- | ArrayLiteral { $$ = $1; }
+ | ArrayInitialiser { $$ = $1; }
| ObjectLiteral { $$ = $1; }
| Parenthetical { $$ = $1; }
| AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
;
/* }}} */
-/* 11.1.4.1 Array Initialiser {{{ */
+/* 11.1.4 Array Initializer {{{ */
+ArrayInitialiser
+ : ArrayLiteral { $$ = $1; }
+ | ArrayComprehension { $$ = $1; }
+ ;
+/* }}} */
+/* 11.1.4.1 Array Literal {{{ */
ArrayLiteral
: "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
;
;
/* }}} */
/* 11.1.4.2 Array Comprehension {{{ */
-PrimaryExpression
- : "[" LexPushInOff AssignmentExpression ComprehensionForList "]" LexPopIn { $$ = CYNew CYArrayComprehension($3, $4); }
+ArrayComprehension
+ : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
;
-ComprehensionForList
- : "for" Binding "in" Expression ComprehensionForListOpt { $$ = CYNew CYForInComprehension($2, $4, $5); }
- | "for" Binding "of" Expression ComprehensionForListOpt { $$ = CYNew CYForOfComprehension($2, $4, $5); }
+Comprehension
+ : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
;
-ComprehensionForListOpt
- : ComprehensionForList { $$ = $1; }
- | "if" Expression { $$ = CYNew CYIfComprehension($2); }
- | { $$ = NULL; }
+ComprehensionTail
+ : { $$ = NULL; }
+ | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
+ | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
+ ;
+
+ComprehensionFor
+ : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
+ ;
+
+ComprehensionIf
+ : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
;
/* }}} */
/* 11.1.5 Object Initialiser {{{ */
ConditionalExpression
: LogicalORExpression { $$ = $1; }
| LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
+ | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
;
/* }}} */
/* 11.13 Assignment Operators {{{ */
/* 11.14 Comma Operator {{{ */
Expression_
: "," Expression { $$ = $2; }
- | { $$ = CYNew CYCompound(); }
+ | { $$ = NULL; }
;
Expression
- : AssignmentExpression Expression_ { $2->AddPrev($1); $$ = $2; }
+ : AssignmentExpression Expression_ { $$ = CYNew CYCompound($1, $2); }
;
ExpressionOpt
;
/* }}} */
-@begin ObjectiveC
-/* Cycript (Objective-C): Type Encoding {{{ */
+@begin C
+/* Cycript (C): Type Encoding {{{ */
TypeParenthetical
: "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
;
TypeSignifier
- : Identifier { $$ = CYNew CYTypedIdentifier($1); }
+ : IdentifierType { $$ = CYNew CYTypedIdentifier($1); }
| TypeParenthetical { $$ = $1; }
;
SuffixedType
: ArrayedType { $$ = $1; }
+ | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
| TypeParenthetical FunctionedType { $$ = $1; CYSetLast($2) = $$->modifier_; $$->modifier_ = $2; }
| FunctionedType { $$ = CYNew CYTypedIdentifier(); CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
;
;
TypeQualifierLeft
- : "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
- /* XXX: | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); } */
- | { $$ = NULL; }
+ : { $$ = NULL; }
+ | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
+ | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
;
TypeQualifierRight
- : "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
- | PrefixedType { $$ = $1; }
+ : PrefixedType { $$ = $1; }
| SuffixedType { $$ = $1; }
+ | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
+ | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
+ ;
+
+IntegerType
+ : "int" { $$ = CYNew CYTypeVariable("int"); }
+ | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
+ | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
+ | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
+ | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
+ ;
+
+IntegerTypeOpt
+ : IntegerType { $$ = $1; }
+ | { $$ = CYNew CYTypeVariable("int"); }
;
PrimitiveType
- : Variable { $$ = $1; }
- | "void" { $$ = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); }
+ : IdentifierType { $$ = CYNew CYTypeVariable($1); }
+ | IntegerType { $$ = $1; }
+ | "void" { $$ = CYNew CYTypeVoid(); }
+ | "char" { $$ = CYNew CYTypeVariable("char"); }
+ | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
+ | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
;
TypedIdentifier
- : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->type_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
+ : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
;
EncodedType
;
PrimaryExpression
- : AtEncode "(" EncodedType ")" { $$ = $3; }
+ : "@encode" "(" EncodedType ")" { $$ = $3; }
;
/* }}} */
+@end
+
+@begin ObjectiveC
/* Cycript (Objective-C): @class Declaration {{{ */
ClassSuperOpt
/* XXX: why the hell did I choose MemberExpression? */
;
ClassFieldListOpt
- : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); }
+ : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $3); }
| LexSetRegExp { $$ = NULL; }
;
| "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
;
/* }}} */
-/* Cycript (Objective-C): @import Directive {{{ */
+@end
+
+/* Cycript: @import Directive {{{ */
Module
: Module "." Word { $$ = CYNew CYModule($3, $1); }
| Word { $$ = CYNew CYModule($1); }
: "@import" Module { $$ = CYNew CYImport($2); }
;
/* }}} */
+
+@begin ObjectiveC
/* Cycript (Objective-C): Boxed Expressions {{{ */
BoxableExpression
: NullLiteral { $$ = $1; }
/* }}} */
/* Cycript (Objective-C): Block Expressions {{{ */
ModifiedType
- : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->type_ = $2; $$->modifier_ = $1; }
+ : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->specifier_ = $2; $$->modifier_ = $1; }
| ModifiedType "*" { $$ = $1; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
;
: "^" ModifiedType "(" LexPushInOff TypedParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYObjCBlock($2, $5, $10); }
;
/* }}} */
+/* Cycript (Objective-C): Instance Literals {{{ */
+PrimaryExpression
+ : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
+ ;
+/* }}} */
@end
@begin C
@end
/* JavaScript 1.7: Array Comprehensions {{{ */
-IfComprehension
- : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
- ;
-
-ForComprehension
- : "for" "(" Identifier "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
- | "for" "each" "(" Identifier "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
+Comprehension
+ : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
;
-ComprehensionList
- : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
- ;
-
-ComprehensionListOpt
- : ComprehensionList { $$ = $1; }
- | IfComprehension { $$ = $1; }
- | { $$ = NULL; }
- ;
-
-PrimaryExpression
- : "[" LexPushInOff AssignmentExpression ComprehensionList "]" LexPopIn { $$ = CYNew CYArrayComprehension($3, $4); }
+ComprehensionFor
+ : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
+ | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
;
/* }}} */
/* JavaScript 1.7: for each {{{ */