**/
/* }}} */
-@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)
} 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_;
%locations
%defines
+%define api.location.type { CYLocation }
+
//%glr-parser
//%expect 1
%token <identifier_> Typedef "typedef"
%token <identifier_> Unsigned "unsigned"
%token <identifier_> Signed "signed"
+%token <identifier_> Extern "extern"
@end
@begin C
%type <null_> NullLiteral
%type <literal_> ObjectLiteral
%type <compound_> Parenthetical
-%type <compound_> ParentheticalOpt
+//%type <compound_> ParentheticalOpt
%type <expression_> PostfixExpression
%type <expression_> PrimaryExpression
%type <statement_> Program
%type <statement_> VariableStatement
%type <statement_> WithStatement
%type <word_> Word
+@begin ObjectiveC
%type <word_> WordOpt
+@end
%type <expression_> Variable
@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 <typedIdentifier_> TypeSignifier
%type <modifier_> TypeQualifierLeft
%type <typedIdentifier_> TypeQualifierRight
%type <typedIdentifier_> TypedIdentifier
%type <messageParameter_> MessageParameterList
%type <messageParameter_> MessageParameterListOpt
%type <bool_> MessageScope
-%type <typedIdentifier_> ModifiedType
%type <argument_> SelectorCall_
%type <argument_> SelectorCall
%type <selector_> SelectorExpression_
%type <selector_> SelectorExpressionOpt
%type <argument_> SelectorList
%type <word_> SelectorWordOpt
-%type <expression_> TypeOpt
+%type <typedIdentifier_> TypeOpt
%type <argument_> VariadicCall
@end
;
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
;
| "with" { $$ = $1; }
;
+@begin ObjectiveC
WordOpt
: Word { $$ = $1; }
| { $$ = NULL; }
;
+@end
IdentifierType
: Identifier_ { $$ = $1; }
| "typedef" { $$ = $1; }
| "unsigned" { $$ = $1; }
| "signed" { $$ = $1; }
+ | "extern" { $$ = $1; }
@end
@begin ObjectiveC
| "YES" { $$ = $1; }
/* 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
: "(" LexPushInOff Expression ")" LexPopIn { $$ = $3; }
;
-ParentheticalOpt
+/*ParentheticalOpt
: Parenthetical { $$ = $1; }
| { $$ = NULL; }
- ;
+ ;*/
Variable
: Identifier { $$ = CYNew CYVariable($1); }
@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
: 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
;
TypeOpt
- : "(" LexSetRegExp EncodedType ")" { $$ = $3; }
+ : "(" LexSetRegExp TypedIdentifier ")" { $$ = $3; }
| { $$ = NULL; }
;
;
/* }}} */
/* 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 {{{ */
/* }}} */
/* 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 {{{ */