X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/b3aa25d897b2ce3672a306f238c053467fb23df5..fa3c5be836cc074bdc12ba66298764a1da026e48:/Cycript.yy.in diff --git a/Cycript.yy.in b/Cycript.yy.in index 983802f..0f16b6e 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -85,6 +85,13 @@ typedef struct { CYTrue *true_; CYWord *word_; +@begin C + CYTypeModifier *modifier_; + CYTypeSpecifier *specifier_; + CYTypedIdentifier *typedIdentifier_; + CYTypedParameter *typedParameter_; +@end + @begin ObjectiveC CYClassName *className_; CYField *field_; @@ -92,9 +99,6 @@ typedef struct { CYMessageParameter *messageParameter_; CYProtocol *protocol_; CYSelectorPart *selector_; - CYTypeModifier *modifier_; - CYTypedIdentifier *typedIdentifier_; - CYTypedParameter *typedParameter_; @end @begin E4X @@ -160,6 +164,7 @@ int cylex(YYSTYPE *, cy::location *, void *); @begin E4X ObjectiveC %token At "@" +%token Pound "#" @end %token Ampersand "&" @@ -233,6 +238,8 @@ int cylex(YYSTYPE *, cy::location *, void *); @begin C %token Typedef "typedef" +%token Unsigned "unsigned" +%token Signed "signed" @end @begin ObjectiveC @@ -405,6 +412,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type FunctionExpression %type Identifier %type IdentifierOpt +%type IdentifierType %type IdentifierName %type IfStatement %type Initialiser @@ -421,6 +429,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type MemberAccess %type MemberExpression_ %type MemberExpression +%type Module %type MultiplicativeExpression %type NewExpression %type NullLiteral @@ -467,8 +476,26 @@ int cylex(YYSTYPE *, cy::location *, void *); %type WordOpt %type Variable -@begin ObjectiveC +@begin C %type ArrayedType +%type EncodedType +%type FunctionedType +%type IntegerType +%type IntegerTypeOpt +%type PrefixedType +%type PrimitiveType +%type TypeParenthetical +%type TypeSignifier +%type SuffixedType +%type TypeQualifierLeft +%type TypeQualifierRight +%type TypedIdentifier +%type TypedParameterList_ +%type TypedParameterList +%type TypedParameterListOpt +@end + +@begin ObjectiveC %type BoxableExpression %type CategoryStatement %type ClassExpression @@ -483,8 +510,6 @@ int cylex(YYSTYPE *, cy::location *, void *); %type ClassProtocolListOpt %type ClassProtocols %type ClassProtocolsOpt -%type EncodedType -%type FunctionedType %type MessageExpression %type MessageParameter %type MessageParameters @@ -492,9 +517,6 @@ int cylex(YYSTYPE *, cy::location *, void *); %type MessageParameterListOpt %type MessageScope %type ModifiedType -%type Module -%type PrefixedType -%type PrimitiveType %type SelectorCall_ %type SelectorCall %type SelectorExpression_ @@ -502,16 +524,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type SelectorExpressionOpt %type SelectorList %type SelectorWordOpt -%type SuffixedType %type TypeOpt -%type TypeParenthetical -%type TypeQualifierLeft -%type TypeQualifierRight -%type TypeSignifier -%type TypedIdentifier -%type TypedParameterList_ -%type TypedParameterList -%type TypedParameterListOpt %type VariadicCall @end @@ -655,15 +668,9 @@ WordOpt | { $$ = NULL; } ; -Identifier +IdentifierType : Identifier_ { $$ = $1; } -@begin C - | "typedef" { $$ = $1; } - | "YES" { $$ = $1; } - | "NO" { $$ = $1; } -@end - | "implements" { $$ = $1; } | "interface" { $$ = $1; } | "package" { $$ = $1; } @@ -675,19 +682,14 @@ Identifier | "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; } @@ -698,6 +700,24 @@ Identifier | "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; } @@ -1018,6 +1038,7 @@ LogicalORExpression 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 {{{ */ @@ -1041,11 +1062,11 @@ AssignmentExpression /* 11.14 Comma Operator {{{ */ Expression_ : "," Expression { $$ = $2; } - | { $$ = CYNew CYCompound(); } + | { $$ = NULL; } ; Expression - : AssignmentExpression Expression_ { $2->AddPrev($1); $$ = $2; } + : AssignmentExpression Expression_ { $$ = CYNew CYCompound($1, $2); } ; ExpressionOpt @@ -1381,14 +1402,14 @@ ProgramBodyOpt ; /* }}} */ -@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; } ; @@ -1414,24 +1435,42 @@ PrefixedType ; 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 @@ -1439,9 +1478,12 @@ 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? */ @@ -1450,7 +1492,7 @@ ClassSuperOpt ; ClassFieldListOpt - : Expression Identifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $2, $4); } + : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $3); } | LexSetRegExp { $$ = NULL; } ; @@ -1595,7 +1637,9 @@ PrimaryExpression | "@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); } @@ -1605,6 +1649,8 @@ Declaration__ : "@import" Module { $$ = CYNew CYImport($2); } ; /* }}} */ + +@begin ObjectiveC /* Cycript (Objective-C): Boxed Expressions {{{ */ BoxableExpression : NullLiteral { $$ = $1; } @@ -1624,7 +1670,7 @@ PrimaryExpression /* }}} */ /* 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_); } ; @@ -1632,6 +1678,11 @@ PrimaryExpression : "^" 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