X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/24ffc58c2367143a1cad64e4340e0fb5e863637a..1fdd7c7aa3b4b5775135c4c58e535caf102207c1:/Parser.ypp.in diff --git a/Parser.ypp.in b/Parser.ypp.in index c2f48ce..c3f2379 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -55,6 +55,7 @@ %union { CYClassTail *classTail_; } %union { CYComprehension *comprehension_; } %union { CYElement *element_; } +%union { CYEnumConstant *constant_; } %union { CYExpression *expression_; } %union { CYFalse *false_; } %union { CYVariable *variable_; } @@ -227,6 +228,9 @@ type; }) case CYMarkModule: driver.hold_ = yytranslate_(token::MarkModule); break; + case CYMarkExpression: + driver.hold_ = yytranslate_(token::MarkExpression); + break; } }; @@ -669,9 +673,13 @@ type; }) %type YieldExpression @begin C +%type EnumConstantListOpt_ +%type EnumConstantListOpt +%type IntegerNumber %type IntegerType %type IntegerTypeOpt %type PrefixedType +%type PrimitiveReference %type PrimitiveType %type StructFieldListOpt %type SuffixedType @@ -690,6 +698,7 @@ type; }) %type TypedIdentifierField %type TypedIdentifierMaybe %type TypedIdentifierNo +%type TypedIdentifierTagged %type TypedIdentifierYes %type TypedParameterList_ %type TypedParameterList @@ -762,12 +771,14 @@ type; }) %start Program %token MarkModule %token MarkScript +%token MarkExpression %% Program : MarkScript Script | MarkModule Module + | MarkExpression Expression[expression] { driver.context_ = $expression; } ; /* Lexer State {{{ */ @@ -2109,6 +2120,21 @@ StructFieldListOpt | { $$ = NULL; } ; +IntegerNumber + : NumericLiteral[pass] { $$ = $pass; } + | "-" NumericLiteral[positive] { $$ = $positive; $$->value_ = -$$->value_; } + ; + +EnumConstantListOpt_ + : "," EnumConstantListOpt[pass] { $$ = $pass; } + | { $$ = NULL; } + ; + +EnumConstantListOpt + : IdentifierType[name] "=" IntegerNumber[value] EnumConstantListOpt_[next] { $$ = CYNew CYEnumConstant($name, $value, $next); } + | { $$ = NULL; } + ; + TypeSigning : { $$ = CYTypeNeutral; } | "signed" { $$ = CYTypeSigned; } @@ -2120,13 +2146,20 @@ PrimitiveType | IntegerType[pass] { $$ = $pass; } | TypeSigning[signing] "char" { $$ = CYNew CYTypeCharacter($signing); } | TypeSigning[signing] "__int128" { $$ = CYNew CYTypeInt128($signing); } - | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); } + ; + +PrimitiveReference + : PrimitiveType[pass] { $$ = $pass; } + | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference(CYTypeReferenceStruct, $name); } + | "enum" IdentifierType[name] { $$ = CYNew CYTypeReference(CYTypeReferenceEnum, $name); } + | "struct" AutoComplete { driver.mode_ = CYDriver::AutoStruct; YYACCEPT; } + | "enum" AutoComplete { driver.mode_ = CYDriver::AutoEnum; YYACCEPT; } ; TypedIdentifierMaybe : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); } - | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + | TypeQualifierLeftOpt[modifier] PrimitiveReference[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } ; TypedIdentifierYes @@ -2137,19 +2170,26 @@ TypedIdentifierNo : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } ; +TypedIdentifierTagged + : TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + | TypeQualifierLeftOpt[modifier] "enum" ":" PrimitiveType[specifier] "{" EnumConstantListOpt[constants] "}" TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeEnum(NULL, $specifier, $constants); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + ; + TypedIdentifierField : TypedIdentifierYes[pass] { $$ = $pass; } - | TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + | TypedIdentifierTagged[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; } ; TypedIdentifierEncoding : TypedIdentifierNo[pass] { $$ = $pass; } - | TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + | TypedIdentifierTagged[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } + | "void" TypeSignifierNone[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); } ; TypedIdentifierDefinition : TypedIdentifierYes[pass] { $$ = $pass; } | TypeQualifierLeftOpt[modifier] "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct($name, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } + | "void" TypeSignifier[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); } ; PrimaryExpression @@ -2406,7 +2446,8 @@ Statement__ ; PrimaryExpression - : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); } + : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference(CYTypeReferenceStruct, $name); $$ = CYNew CYTypeExpression($typed); } + | "(" LexOf "struct" NewLineOpt AutoComplete { driver.mode_ = CYDriver::AutoStruct; YYACCEPT; } ; /* }}} */ /* Cycript (C): Type Definitions {{{ */