X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/c5aeb567fb12928016baaadce256700e21e1f5bc..2ca4dab349cc3f91032b17ced6b76023b4e67115:/Cycript.yy.in diff --git a/Cycript.yy.in b/Cycript.yy.in index d9b9a1d..29a3755 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -19,15 +19,12 @@ **/ /* }}} */ -@if Bison23 %{ - -@if Bison24 %code top { +%code top { #define cyscanner driver.scanner_ #define YYSTACKEXPANDABLE 1 -@if Bison23 #define yyerrok (yyerrstatus_ = 0) -@if Bison24 } +} -@if Bison24 %code requires { +%code requires { #include "Driver.hpp" #include "Parser.hpp" #define CYNew new($pool) @@ -110,23 +107,15 @@ typedef struct { } YYSTYPE; #define YYSTYPE YYSTYPE +} -@if Bison24 %code provides { -int cylex(YYSTYPE *, cy::location *, void *); -@if Bison24 } - -@if Bison23 %} -@if Bison23 %union { -@if Bison23 } -@if Bison23 %{ +%code provides { +int cylex(YYSTYPE *, CYLocation *, void *); +} -@if Bison24 } -@if Bison23 %} +%name-prefix "cy" -%name-prefix="cy" - -@if Bison23 %skeleton "lalr1.cc" -@if Bison24 %language "C++" +%language "C++" %initial-action { @$.begin.filename = @$.end.filename = &driver.filename_; @@ -135,6 +124,8 @@ int cylex(YYSTYPE *, cy::location *, void *); %locations %defines +%define api.location.type { CYLocation } + //%glr-parser //%expect 1 @@ -245,6 +236,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %token Typedef "typedef" %token Unsigned "unsigned" %token Signed "signed" +%token Extern "extern" @end @begin C @@ -443,7 +435,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type NullLiteral %type ObjectLiteral %type Parenthetical -%type ParentheticalOpt +//%type ParentheticalOpt %type PostfixExpression %type PrimaryExpression %type Program @@ -481,20 +473,18 @@ int cylex(YYSTYPE *, cy::location *, void *); %type VariableStatement %type WithStatement %type Word +@begin ObjectiveC %type WordOpt +@end %type Variable @begin C -%type ArrayedType -%type EncodedType -%type FunctionedType %type IntegerType %type IntegerTypeOpt %type PrefixedType %type PrimitiveType -%type TypeParenthetical -%type TypeSignifier %type SuffixedType +%type TypeSignifier %type TypeQualifierLeft %type TypeQualifierRight %type TypedIdentifier @@ -524,7 +514,6 @@ int cylex(YYSTYPE *, cy::location *, void *); %type MessageParameterList %type MessageParameterListOpt %type MessageScope -%type ModifiedType %type SelectorCall_ %type SelectorCall %type SelectorExpression_ @@ -532,7 +521,7 @@ int cylex(YYSTYPE *, cy::location *, void *); %type SelectorExpressionOpt %type SelectorList %type SelectorWordOpt -%type TypeOpt +%type TypeOpt %type VariadicCall @end @@ -587,16 +576,16 @@ LexSetRegExp ; LexNoBrace - : { if (yychar == yyempty_) driver.no_.OpenBrace = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; } + : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); } ; LexNoFunction - : { if (yychar == yyempty_) driver.no_.Function = true; else if (yychar == token::Function) yychar = token::Function_; } + : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::Function)) yyla.type = yytranslate_(token::Function_); } ; LexNoAtImplementation : @begin ObjectiveC - { if (yychar == yyempty_) driver.no_.AtImplementation = true; else if (yychar == token::AtImplementation) yychar = token::AtImplementation_; } + { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::AtImplementation)) yyla.type = yytranslate_(token::AtImplementation_); } @end ; @@ -671,10 +660,12 @@ Word | "with" { $$ = $1; } ; +@begin ObjectiveC WordOpt : Word { $$ = $1; } | { $$ = NULL; } ; +@end IdentifierType : Identifier_ { $$ = $1; } @@ -719,6 +710,7 @@ Identifier | "typedef" { $$ = $1; } | "unsigned" { $$ = $1; } | "signed" { $$ = $1; } + | "extern" { $$ = $1; } @end @begin ObjectiveC | "YES" { $$ = $1; } @@ -759,12 +751,12 @@ BooleanLiteral /* 7.9 Automatic Semicolon Insertion {{{ */ StrictSemi - : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); } + : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); } ; Terminator : ";" - | error { if (yychar != yyeof_ && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi + | error { if (yyla.type_get() != yyeof_ && yyla.type != token::CloseBrace && !yyla.value.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi ; TerminatorOpt @@ -778,10 +770,10 @@ Parenthetical : "(" LexPushInOff Expression ")" LexPopIn { $$ = $3; } ; -ParentheticalOpt +/*ParentheticalOpt : Parenthetical { $$ = $1; } | { $$ = NULL; } - ; + ;*/ Variable : Identifier { $$ = CYNew CYVariable($1); } @@ -1412,30 +1404,18 @@ ProgramBodyOpt @begin C /* Cycript (C): Type Encoding {{{ */ -TypeParenthetical - : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; } - ; - TypeSignifier - : IdentifierType { $$ = CYNew CYTypedIdentifier($1); } - | TypeParenthetical { $$ = $1; } - ; - -ArrayedType - : ArrayedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); } - | TypeSignifier { $$ = $1; } - | { $$ = CYNew CYTypedIdentifier(); } - ; - -FunctionedType - : "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypeFunctionWith($3); } + : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); } + | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; } ; SuffixedType - : ArrayedType { $$ = $1; } + : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); } | "(" 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; } + | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); } + | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); } + | TypeSignifier { $$ = $1; } + | { $$ = CYNew CYTypedIdentifier(@$); } ; PrefixedType @@ -1481,12 +1461,8 @@ TypedIdentifier : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; } ; -EncodedType - : TypedIdentifier { $$ = CYNew CYEncodedType($1); } - ; - PrimaryExpression - : "@encode" "(" EncodedType ")" { $$ = $3; } + : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); } ; /* }}} */ @end @@ -1514,7 +1490,7 @@ MessageScope ; TypeOpt - : "(" LexSetRegExp EncodedType ")" { $$ = $3; } + : "(" LexSetRegExp TypedIdentifier ")" { $$ = $3; } | { $$ = NULL; } ; @@ -1677,13 +1653,8 @@ PrimaryExpression ; /* }}} */ /* Cycript (Objective-C): Block Expressions {{{ */ -ModifiedType - : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->specifier_ = $2; $$->modifier_ = $1; } - | ModifiedType "*" { $$ = $1; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } - ; - PrimaryExpression - : "^" ModifiedType "(" LexPushInOff TypedParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYObjCBlock($2, $5, $10); } + : "^" TypedIdentifier { if ($2->identifier_ != NULL) error($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else error($2->location_, "expected parameters"); } ; /* }}} */ /* Cycript (Objective-C): Instance Literals {{{ */ @@ -1735,9 +1706,15 @@ PrimaryExpression /* }}} */ /* Cycript (C): Type Definitions {{{ */ Statement__ - : "typedef" TypedIdentifier Terminator { $$ = CYNew CYTypeDefinition($2); } + : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); } ; /* }}} */ +/* Cycript (C): extern "C" {{{ */ +Statement__ + : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) YYABORT; } TypedIdentifier { if ($4->identifier_ == NULL) error($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); } + ; +/* }}} */ + @end /* YUI: Documentation Comments {{{ */