|
@ -94,13 +94,13 @@ typedef struct jb_record |
|
|
|
|
|
|
|
|
jb_record *jbs= NULL; |
|
|
jb_record *jbs= NULL; |
|
|
|
|
|
|
|
|
#define jbRecPush() \ |
|
|
|
|
|
struct jb_record jbrec; \ |
|
|
|
|
|
|
|
|
#define jbRecPush() \ |
|
|
|
|
|
struct jb_record jbrec; \ |
|
|
jbrec.next= jbs; \ |
|
|
jbrec.next= jbs; \ |
|
|
jbs= &jbrec |
|
|
jbs= &jbrec |
|
|
|
|
|
|
|
|
#define jbRecPop() \ |
|
|
|
|
|
assert(jbs == &jbrec); \ |
|
|
|
|
|
|
|
|
#define jbRecPop() \ |
|
|
|
|
|
assert(jbs == &jbrec); \ |
|
|
jbs= jbrec.next |
|
|
jbs= jbrec.next |
|
|
|
|
|
|
|
|
// this is the global scope |
|
|
// this is the global scope |
|
@ -902,6 +902,7 @@ oop new_C_enumerator(oop id, oop attributeSpecifier, oop expression) { |
|
|
return object; |
|
|
return object; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//TODO |
|
|
#define YY_INPUT(buf, result, max_size) \ |
|
|
#define YY_INPUT(buf, result, max_size) \ |
|
|
{ \ |
|
|
{ \ |
|
|
int yyc= feof(inputStack->file) ? EOF : getc(inputStack->file); \ |
|
|
int yyc= feof(inputStack->file) ? EOF : getc(inputStack->file); \ |
|
@ -1453,9 +1454,7 @@ start = m:metaCatch { yylval= m } |
|
|
|
|
|
|
|
|
error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 } |
|
|
error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 } |
|
|
|
|
|
|
|
|
### A.1.3 Identifiers |
|
|
|
|
|
|
|
|
|
|
|
# 6.4.2.1 |
|
|
|
|
|
|
|
|
# Identifiers rules |
|
|
|
|
|
|
|
|
idOpt = id | {$$=newNullObject()} |
|
|
idOpt = id | {$$=newNullObject()} |
|
|
|
|
|
|
|
@ -1478,29 +1477,23 @@ IDREST = IDFIRST | [0-9] |
|
|
|
|
|
|
|
|
digit = [0-9] |
|
|
digit = [0-9] |
|
|
|
|
|
|
|
|
### A.1.4 Universal character names |
|
|
|
|
|
|
|
|
|
|
|
# 6.4.3 |
|
|
|
|
|
|
|
|
# universalCharacterName |
|
|
|
|
|
|
|
|
universalCharacterName = "\\u" hexQuad |
|
|
universalCharacterName = "\\u" hexQuad |
|
|
| "\\U" hexQuad hexQuad |
|
|
| "\\U" hexQuad hexQuad |
|
|
|
|
|
|
|
|
hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hexadecimalDigit |
|
|
hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hexadecimalDigit |
|
|
|
|
|
|
|
|
### |
|
|
|
|
|
|
|
|
|
|
|
### A.1.5 Constants |
|
|
|
|
|
|
|
|
|
|
|
# 6.4.4 |
|
|
|
|
|
|
|
|
# constant rule |
|
|
|
|
|
|
|
|
constant = characterConstant |
|
|
constant = characterConstant |
|
|
| floatingConstant |
|
|
| floatingConstant |
|
|
| integerConstant |
|
|
| integerConstant |
|
|
| META_AT m:mvalue |
|
|
|
|
|
|
|
|
| META_AT m:mvalue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 6.4.4.1 |
|
|
|
|
|
|
|
|
# integerConstant rule |
|
|
|
|
|
|
|
|
integerConstant = < ( hexadecimalConstant |
|
|
integerConstant = < ( hexadecimalConstant |
|
|
| octalConstant |
|
|
| octalConstant |
|
@ -1528,7 +1521,7 @@ integerSuffix = ( [uU][lL]?[lL]? | [lL][lL]?[uU]? ) ( imaginarySuffix &{gn |
|
|
|
|
|
|
|
|
imaginarySuffix = [ij] |
|
|
imaginarySuffix = [ij] |
|
|
|
|
|
|
|
|
# 6.4.4.2 |
|
|
|
|
|
|
|
|
# floatingConstant rule |
|
|
|
|
|
|
|
|
floatingConstant = <( decimalFloatingConstant | hexadecimalFloatingConstant )> { $$= new_C_float(yytext); } - |
|
|
floatingConstant = <( decimalFloatingConstant | hexadecimalFloatingConstant )> { $$= new_C_float(yytext); } - |
|
|
|
|
|
|
|
@ -1576,9 +1569,7 @@ octalEscapeSequence = '\\' octalDigit octalDigit? octalDigit? |
|
|
|
|
|
|
|
|
hexadecimalEscapeSequence = '\\x' hexadecimalDigit+ |
|
|
hexadecimalEscapeSequence = '\\x' hexadecimalDigit+ |
|
|
|
|
|
|
|
|
### A.1.6 String literals |
|
|
|
|
|
|
|
|
|
|
|
# 6.4.5 |
|
|
|
|
|
|
|
|
# stringLiteral rule |
|
|
|
|
|
|
|
|
stringLiteral = { listBegin(); } |
|
|
stringLiteral = { listBegin(); } |
|
|
( s:stringLiteralPart { listAppend(s) } |
|
|
( s:stringLiteralPart { listAppend(s) } |
|
@ -1590,18 +1581,16 @@ stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_string(y |
|
|
|
|
|
|
|
|
sCharSequence = ( escapeSequence | !EOL [^\"\\] )* #" |
|
|
sCharSequence = ( escapeSequence | !EOL [^\"\\] )* #" |
|
|
|
|
|
|
|
|
### A.2.1 Expressions |
|
|
|
|
|
|
|
|
|
|
|
# 6.5.1 |
|
|
|
|
|
|
|
|
# primaryExpression rule |
|
|
|
|
|
|
|
|
primaryExpression = stringLiteral | constant | id |
|
|
primaryExpression = stringLiteral | constant | id |
|
|
| META_AT ( META_LCB x:mstmts |
|
|
| META_AT ( META_LCB x:mstmts |
|
|
| x:mvalue |
|
|
|
|
|
|
|
|
| x:mvalue |
|
|
) |
|
|
) |
|
|
| l:LPAREN x:expression r:RPAREN { $$= new_C_subexpr(l, x, r) } |
|
|
| l:LPAREN x:expression r:RPAREN { $$= new_C_subexpr(l, x, r) } |
|
|
| l:LPAREN x:compoundStatement r:RPAREN &{gnu} { $$= new_C_subexpr(l, x, r) } |
|
|
| l:LPAREN x:compoundStatement r:RPAREN &{gnu} { $$= new_C_subexpr(l, x, r) } |
|
|
|
|
|
|
|
|
# 6.5.2 |
|
|
|
|
|
|
|
|
# postfixExpression rule |
|
|
|
|
|
|
|
|
postfixExpression = o:LPAREN l:typeName p:RPAREN |
|
|
postfixExpression = o:LPAREN l:typeName p:RPAREN |
|
|
a:LCURLY r:initializerList ( c:COMMA | {c=newNullObject()} ) b:RCURLY { $$= new_C_aggregate(o, l, p, a, r, c, b) } |
|
|
a:LCURLY r:initializerList ( c:COMMA | {c=newNullObject()} ) b:RCURLY { $$= new_C_aggregate(o, l, p, a, r, c, b) } |
|
@ -1620,7 +1609,7 @@ argumentExpressionList = { listBegin() } |
|
|
)* |
|
|
)* |
|
|
)? { $$= listEnd() } |
|
|
)? { $$= listEnd() } |
|
|
|
|
|
|
|
|
# 6.5.3 |
|
|
|
|
|
|
|
|
# unaryExpression rule |
|
|
|
|
|
|
|
|
unaryExpression = o:INC x:unaryExpression { $$= new_C_prefix(o, x) } |
|
|
unaryExpression = o:INC x:unaryExpression { $$= new_C_prefix(o, x) } |
|
|
| o:DEC x:unaryExpression { $$= new_C_prefix(o, x) } |
|
|
| o:DEC x:unaryExpression { $$= new_C_prefix(o, x) } |
|
@ -1639,12 +1628,12 @@ unaryOperator = BAND | STAR | PLUS | MINUS | BNOT | LNOT |
|
|
| REAL &{gnu} |
|
|
| REAL &{gnu} |
|
|
| IMAG &{gnu} |
|
|
| IMAG &{gnu} |
|
|
|
|
|
|
|
|
# 6.5.4 |
|
|
|
|
|
|
|
|
# castExpression rule |
|
|
|
|
|
|
|
|
castExpression = l:LPAREN t:typeName r:RPAREN x:castExpression { $$= new_C_cast(l, t, r, x) } |
|
|
castExpression = l:LPAREN t:typeName r:RPAREN x:castExpression { $$= new_C_cast(l, t, r, x) } |
|
|
| unaryExpression |
|
|
| unaryExpression |
|
|
|
|
|
|
|
|
# 6.5.5 |
|
|
|
|
|
|
|
|
# multiplicativeExpression rule |
|
|
|
|
|
|
|
|
multiplicativeExpression = l:castExpression |
|
|
multiplicativeExpression = l:castExpression |
|
|
( o:multiplicativeOperator r:castExpression { l= new_C_binary(l, o, r) } |
|
|
( o:multiplicativeOperator r:castExpression { l= new_C_binary(l, o, r) } |
|
@ -1652,7 +1641,7 @@ multiplicativeExpression = l:castExpression |
|
|
|
|
|
|
|
|
multiplicativeOperator = STAR | DIV | MOD |
|
|
multiplicativeOperator = STAR | DIV | MOD |
|
|
|
|
|
|
|
|
# 6.5.6 |
|
|
|
|
|
|
|
|
# additiveExpression rule |
|
|
|
|
|
|
|
|
additiveExpression = l:multiplicativeExpression |
|
|
additiveExpression = l:multiplicativeExpression |
|
|
( o:additiveOperator r:multiplicativeExpression { l= new_C_binary(l, o, r) } |
|
|
( o:additiveOperator r:multiplicativeExpression { l= new_C_binary(l, o, r) } |
|
@ -1660,7 +1649,7 @@ additiveExpression = l:multiplicativeExpression |
|
|
|
|
|
|
|
|
additiveOperator = PLUS | MINUS |
|
|
additiveOperator = PLUS | MINUS |
|
|
|
|
|
|
|
|
# 6.5.7 |
|
|
|
|
|
|
|
|
# shiftExpression rule |
|
|
|
|
|
|
|
|
shiftExpression = l:additiveExpression |
|
|
shiftExpression = l:additiveExpression |
|
|
( o:shiftOperator r:additiveExpression { l= new_C_binary(l, o, r) } |
|
|
( o:shiftOperator r:additiveExpression { l= new_C_binary(l, o, r) } |
|
@ -1668,7 +1657,7 @@ shiftExpression = l:additiveExpression |
|
|
|
|
|
|
|
|
shiftOperator = LSHIFT | RSHIFT |
|
|
shiftOperator = LSHIFT | RSHIFT |
|
|
|
|
|
|
|
|
# 6.5.8 |
|
|
|
|
|
|
|
|
# relationalExpression rule |
|
|
|
|
|
|
|
|
relationalExpression = l:shiftExpression |
|
|
relationalExpression = l:shiftExpression |
|
|
( o:relationalOperator r:shiftExpression { l= new_C_binary(l, o, r) } |
|
|
( o:relationalOperator r:shiftExpression { l= new_C_binary(l, o, r) } |
|
@ -1676,7 +1665,7 @@ relationalExpression = l:shiftExpression |
|
|
|
|
|
|
|
|
relationalOperator = LT | LTE | GT | GTE |
|
|
relationalOperator = LT | LTE | GT | GTE |
|
|
|
|
|
|
|
|
# 6.5.9 |
|
|
|
|
|
|
|
|
# equalityExpression rule |
|
|
|
|
|
|
|
|
equalityExpression = l:relationalExpression |
|
|
equalityExpression = l:relationalExpression |
|
|
( o:equalityOperator r:relationalExpression { l= new_C_binary(l, o, r) } |
|
|
( o:equalityOperator r:relationalExpression { l= new_C_binary(l, o, r) } |
|
@ -1684,37 +1673,37 @@ equalityExpression = l:relationalExpression |
|
|
|
|
|
|
|
|
equalityOperator = EQUAL | NOT_EQUAL |
|
|
equalityOperator = EQUAL | NOT_EQUAL |
|
|
|
|
|
|
|
|
# 6.5.10 |
|
|
|
|
|
|
|
|
# andExpression rule |
|
|
|
|
|
|
|
|
andExpression = l:equalityExpression |
|
|
andExpression = l:equalityExpression |
|
|
( o:BAND r:equalityExpression { l= new_C_binary(l, o, r) } |
|
|
( o:BAND r:equalityExpression { l= new_C_binary(l, o, r) } |
|
|
)* { $$= l } |
|
|
)* { $$= l } |
|
|
|
|
|
|
|
|
# 6.5.11 |
|
|
|
|
|
|
|
|
# exclusiveOrExpression rule |
|
|
|
|
|
|
|
|
exclusiveOrExpression = l:andExpression |
|
|
exclusiveOrExpression = l:andExpression |
|
|
( o:BXOR r:andExpression { l= new_C_binary(l, o, r) } |
|
|
( o:BXOR r:andExpression { l= new_C_binary(l, o, r) } |
|
|
)* { $$= l } |
|
|
)* { $$= l } |
|
|
|
|
|
|
|
|
# 6.5.12 |
|
|
|
|
|
|
|
|
# inclusiveOrExpression rule |
|
|
|
|
|
|
|
|
inclusiveOrExpression = l:exclusiveOrExpression |
|
|
inclusiveOrExpression = l:exclusiveOrExpression |
|
|
( o:BOR r:exclusiveOrExpression { l= new_C_binary(l, o, r) } |
|
|
( o:BOR r:exclusiveOrExpression { l= new_C_binary(l, o, r) } |
|
|
)* { $$= l } |
|
|
)* { $$= l } |
|
|
|
|
|
|
|
|
# 6.5.13 |
|
|
|
|
|
|
|
|
# logicalAndExpression rule |
|
|
|
|
|
|
|
|
logicalAndExpression = l:inclusiveOrExpression |
|
|
logicalAndExpression = l:inclusiveOrExpression |
|
|
( o:LAND r:inclusiveOrExpression { l= new_C_binary(l, o, r) } |
|
|
( o:LAND r:inclusiveOrExpression { l= new_C_binary(l, o, r) } |
|
|
)* { $$= l } |
|
|
)* { $$= l } |
|
|
|
|
|
|
|
|
# 6.5.14 |
|
|
|
|
|
|
|
|
# logicalOrExpression rule |
|
|
|
|
|
|
|
|
logicalOrExpression = l:logicalAndExpression |
|
|
logicalOrExpression = l:logicalAndExpression |
|
|
( o:LOR r:logicalAndExpression { l= new_C_binary(l, o, r) } |
|
|
( o:LOR r:logicalAndExpression { l= new_C_binary(l, o, r) } |
|
|
)* { $$= l } |
|
|
)* { $$= l } |
|
|
|
|
|
|
|
|
# 6.5.15 |
|
|
|
|
|
|
|
|
# conditionalExpression rule |
|
|
|
|
|
|
|
|
conditionalExpression = l:logicalOrExpression |
|
|
conditionalExpression = l:logicalOrExpression |
|
|
( q:QUESTION m:expression c:COLON r:conditionalExpression { $$= new_C_conditional(l, q, m, c, r) } |
|
|
( q:QUESTION m:expression c:COLON r:conditionalExpression { $$= new_C_conditional(l, q, m, c, r) } |
|
@ -1722,7 +1711,7 @@ conditionalExpression = l:logicalOrExpression |
|
|
| { $$= l } |
|
|
| { $$= l } |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
# 6.5.16 |
|
|
|
|
|
|
|
|
# assignmentExpressionOpt rule |
|
|
|
|
|
|
|
|
assignmentExpressionOpt = assignmentExpression | {$$=newNullObject()} |
|
|
assignmentExpressionOpt = assignmentExpression | {$$=newNullObject()} |
|
|
|
|
|
|
|
@ -1733,7 +1722,7 @@ assignmentOperator = ASSIGN |
|
|
| STAR_ASSIGN | DIV_ASSIGN | MOD_ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN |
|
|
| STAR_ASSIGN | DIV_ASSIGN | MOD_ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN |
|
|
| LSHIFT_ASSIGN | RSHIFT_ASSIGN | BAND_ASSIGN | BXOR_ASSIGN | BOR_ASSIGN |
|
|
| LSHIFT_ASSIGN | RSHIFT_ASSIGN | BAND_ASSIGN | BXOR_ASSIGN | BOR_ASSIGN |
|
|
|
|
|
|
|
|
# 6.5.17 |
|
|
|
|
|
|
|
|
# expression rule |
|
|
|
|
|
|
|
|
expression = l:assignmentExpression |
|
|
expression = l:assignmentExpression |
|
|
( o:COMMA r:assignmentExpression { l= new_C_binary(l, o, r) } |
|
|
( o:COMMA r:assignmentExpression { l= new_C_binary(l, o, r) } |
|
@ -1743,9 +1732,7 @@ expressionOpt = expression | { $$= newNullObject() } |
|
|
|
|
|
|
|
|
constantExpression = conditionalExpression |
|
|
constantExpression = conditionalExpression |
|
|
|
|
|
|
|
|
### A.2.2 Declarations |
|
|
|
|
|
|
|
|
|
|
|
# 6.7 |
|
|
|
|
|
|
|
|
# declaration rule |
|
|
|
|
|
|
|
|
declaration = @{ C_declarationBegin() } |
|
|
declaration = @{ C_declarationBegin() } |
|
|
( s:declarationSpecifiers |
|
|
( s:declarationSpecifiers |
|
@ -1777,7 +1764,7 @@ initDeclarator = d:declarator |
|
|
( a:ASSIGN i:initializer &{ !typedeffing } { d= new_C_binary(d, a, i) } |
|
|
( a:ASSIGN i:initializer &{ !typedeffing } { d= new_C_binary(d, a, i) } |
|
|
)? { $$= d } |
|
|
)? { $$= d } |
|
|
|
|
|
|
|
|
# 6.7.1 |
|
|
|
|
|
|
|
|
# storageClassSpecifier rule |
|
|
|
|
|
|
|
|
storageClassSpecifier = TYPEDEF @{ declarationTypedef() } |
|
|
storageClassSpecifier = TYPEDEF @{ declarationTypedef() } |
|
|
| AUTO |
|
|
| AUTO |
|
@ -1788,14 +1775,14 @@ parameterStorageClassSpecifier = REGISTER |
|
|
|
|
|
|
|
|
functionStorageClassSpecifier = EXTERN | STATIC |
|
|
functionStorageClassSpecifier = EXTERN | STATIC |
|
|
|
|
|
|
|
|
# 6.7.2 |
|
|
|
|
|
|
|
|
# typeSpecifier rule |
|
|
|
|
|
|
|
|
typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UNSIGNED | BOOL | COMPLEX |
|
|
typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UNSIGNED | BOOL | COMPLEX |
|
|
| ( BUILTIN_VA_LIST | _FLOAT128 ) |
|
|
| ( BUILTIN_VA_LIST | _FLOAT128 ) |
|
|
| structOrUnionSpecifier |
|
|
| structOrUnionSpecifier |
|
|
| enumSpecifier |
|
|
| enumSpecifier |
|
|
|
|
|
|
|
|
# 6.7.2.1 |
|
|
|
|
|
|
|
|
# structOrUnionSpecifier rule |
|
|
|
|
|
|
|
|
structOrUnionSpecifier = s:structOrUnion |
|
|
structOrUnionSpecifier = s:structOrUnion |
|
|
# An attribute specifier list may appear as part of a struct, union or enum specifier. It may go |
|
|
# An attribute specifier list may appear as part of a struct, union or enum specifier. It may go |
|
@ -1843,7 +1830,7 @@ structDeclarator = ( c:COLON e:constantExpression |
|
|
( a:attributeSpecifiers { d= new_C_attribution(d, a) } |
|
|
( a:attributeSpecifiers { d= new_C_attribution(d, a) } |
|
|
)? { $$= d } |
|
|
)? { $$= d } |
|
|
|
|
|
|
|
|
# 6.7.2.2 |
|
|
|
|
|
|
|
|
# enumSpecifier rule |
|
|
|
|
|
|
|
|
enumSpecifier = e:ENUM |
|
|
enumSpecifier = e:ENUM |
|
|
( i:idOpt l:LCURLY m:enumeratorList r:RCURLY { $$= new_C_enumSpec(e, i, l, m, r) } |
|
|
( i:idOpt l:LCURLY m:enumeratorList r:RCURLY { $$= new_C_enumSpec(e, i, l, m, r) } |
|
@ -1863,17 +1850,17 @@ enumerator = i:id |
|
|
)* |
|
|
)* |
|
|
( a:ASSIGN e:constantExpression | {a=e=newNullObject()} ) { $$= new_C_enumerator(i, a, e) } |
|
|
( a:ASSIGN e:constantExpression | {a=e=newNullObject()} ) { $$= new_C_enumerator(i, a, e) } |
|
|
|
|
|
|
|
|
# 6.7.3 |
|
|
|
|
|
|
|
|
# typeQualifier rule |
|
|
|
|
|
|
|
|
typeQualifier = CONST | RESTRICT | VOLATILE |
|
|
typeQualifier = CONST | RESTRICT | VOLATILE |
|
|
| __RESTRICT |
|
|
| __RESTRICT |
|
|
|
|
|
|
|
|
# 6.7.4 |
|
|
|
|
|
|
|
|
# functionSpecifier rule |
|
|
|
|
|
|
|
|
functionSpecifier = INLINE |
|
|
functionSpecifier = INLINE |
|
|
| __INLINE |
|
|
| __INLINE |
|
|
|
|
|
|
|
|
# 6.7.5 |
|
|
|
|
|
|
|
|
# declarator rule |
|
|
|
|
|
|
|
|
declarator = # An attribute specifier list may appear immediately before a declarator |
|
|
declarator = # An attribute specifier list may appear immediately before a declarator |
|
|
a:attributeSpecifier d:declarator &{gnu} { $$= new_C_attribution(a, d) } |
|
|
a:attributeSpecifier d:declarator &{gnu} { $$= new_C_attribution(a, d) } |
|
@ -1943,7 +1930,7 @@ identifierList = i:id { listWith(i) } |
|
|
( c:COMMA i:id { listAppend2(c, i) } |
|
|
( c:COMMA i:id { listAppend2(c, i) } |
|
|
)* { $$= listEnd() } |
|
|
)* { $$= listEnd() } |
|
|
|
|
|
|
|
|
# 6.7.6 |
|
|
|
|
|
|
|
|
# typeName rule |
|
|
|
|
|
|
|
|
typeName = s:specifierQualifierList d:abstractDeclaratorOpt { $$= new_C_declaration(s, d, newNullObject()) } |
|
|
typeName = s:specifierQualifierList d:abstractDeclaratorOpt { $$= new_C_declaration(s, d, newNullObject()) } |
|
|
|
|
|
|
|
@ -1966,7 +1953,7 @@ directAbstractDeclarator = @{int nonEmpty= 0} |
|
|
) r:RBRACKET @{++nonEmpty} { d= new_C_array(d, l, s, q, t, e, r) } |
|
|
) r:RBRACKET @{++nonEmpty} { d= new_C_array(d, l, s, q, t, e, r) } |
|
|
)* &{nonEmpty} { $$= d } |
|
|
)* &{nonEmpty} { $$= d } |
|
|
|
|
|
|
|
|
# 6.7.7 |
|
|
|
|
|
|
|
|
# typedefName rule |
|
|
|
|
|
|
|
|
typedefName = <ID> &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } - |
|
|
typedefName = <ID> &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } - |
|
|
| t:TYPEOF l:LPAREN |
|
|
| t:TYPEOF l:LPAREN |
|
@ -1974,11 +1961,10 @@ typedefName = &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } - |
|
|
| x:typeName r:RPAREN { $$= new_C_typeOf(t, l, x, newNullObject(), r) } |
|
|
| x:typeName r:RPAREN { $$= new_C_typeOf(t, l, x, newNullObject(), r) } |
|
|
) &{gnu} |
|
|
) &{gnu} |
|
|
|
|
|
|
|
|
# 6.7.8 |
|
|
|
|
|
|
|
|
# initializer rule |
|
|
|
|
|
|
|
|
initializer = l:LCURLY i:initializerList ( c:COMMA | {c=newNullObject()} ) r:RCURLY { $$= new_C_initializer(l, i, c, r) } |
|
|
initializer = l:LCURLY i:initializerList ( c:COMMA | {c=newNullObject()} ) r:RCURLY { $$= new_C_initializer(l, i, c, r) } |
|
|
| assignmentExpression |
|
|
| assignmentExpression |
|
|
| META_AT m:mvalue |
|
|
|
|
|
|
|
|
|
|
|
initializerList = { listBegin() } |
|
|
initializerList = { listBegin() } |
|
|
( d:designation { listAppend(d) } |
|
|
( d:designation { listAppend(d) } |
|
@ -1999,9 +1985,7 @@ designatorList = { listB |
|
|
| l:DOT x:id { listAppend(new_C_binary(newNullObject(), l, x)) } |
|
|
| l:DOT x:id { listAppend(new_C_binary(newNullObject(), l, x)) } |
|
|
)+ { $$= listEnd() } |
|
|
)+ { $$= listEnd() } |
|
|
|
|
|
|
|
|
### A.2.3 Statements |
|
|
|
|
|
|
|
|
|
|
|
# 6.8 |
|
|
|
|
|
|
|
|
# statement rule |
|
|
|
|
|
|
|
|
statement = expressionStatement |
|
|
statement = expressionStatement |
|
|
| labeledStatement |
|
|
| labeledStatement |
|
@ -2010,7 +1994,7 @@ statement = expressionStatement |
|
|
| iterationStatement |
|
|
| iterationStatement |
|
|
| jumpStatement |
|
|
| jumpStatement |
|
|
|
|
|
|
|
|
# 6.8.1 |
|
|
|
|
|
|
|
|
# labeledStatement rule |
|
|
|
|
|
|
|
|
labeledStatement = i:id c:COLON |
|
|
labeledStatement = i:id c:COLON |
|
|
# an attribute specifier list may appear after |
|
|
# an attribute specifier list may appear after |
|
@ -2021,7 +2005,7 @@ labeledStatement = i:id c:COLON |
|
|
| c:CASE x:constantRange d:COLON s:statement &{gnu} { $$= new_C_case(c, x, d, s) } |
|
|
| c:CASE x:constantRange d:COLON s:statement &{gnu} { $$= new_C_case(c, x, d, s) } |
|
|
| d:DEFAULT c:COLON s:statement { $$= new_C_default(d, c, s) } |
|
|
| d:DEFAULT c:COLON s:statement { $$= new_C_default(d, c, s) } |
|
|
|
|
|
|
|
|
# 6.8.2 |
|
|
|
|
|
|
|
|
# compoundStatement rule |
|
|
|
|
|
|
|
|
compoundStatement = @{ C_scopeBegin() } |
|
|
compoundStatement = @{ C_scopeBegin() } |
|
|
l:LCURLY { listBegin() } |
|
|
l:LCURLY { listBegin() } |
|
@ -2036,18 +2020,18 @@ compoundStatement = @{ C_scopeBegin() } |
|
|
@{ C_scopeEnd() } |
|
|
@{ C_scopeEnd() } |
|
|
| &{ C_scopeAbort() } |
|
|
| &{ C_scopeAbort() } |
|
|
|
|
|
|
|
|
# 6.8.3 |
|
|
|
|
|
|
|
|
# expressionStatement rule |
|
|
|
|
|
|
|
|
expressionStatement = SEMI |
|
|
expressionStatement = SEMI |
|
|
| x:expression s:SEMI { $$= new_C_exprStatement(x, s) } |
|
|
| x:expression s:SEMI { $$= new_C_exprStatement(x, s) } |
|
|
|
|
|
|
|
|
# 6.8.4 |
|
|
|
|
|
|
|
|
# selectionStatement rule |
|
|
|
|
|
|
|
|
selectionStatement = i:IF l:LPAREN x:expression r:RPAREN s:statement |
|
|
selectionStatement = i:IF l:LPAREN x:expression r:RPAREN s:statement |
|
|
( e:ELSE t:statement | {e=t=newNullObject()} ) { $$= new_C_if(i, l, x, r, s, e, t) } |
|
|
( e:ELSE t:statement | {e=t=newNullObject()} ) { $$= new_C_if(i, l, x, r, s, e, t) } |
|
|
| s:SWITCH l:LPAREN x:expression r:RPAREN t:statement { $$= new_C_switch(s, l, x, r, t) } |
|
|
| s:SWITCH l:LPAREN x:expression r:RPAREN t:statement { $$= new_C_switch(s, l, x, r, t) } |
|
|
|
|
|
|
|
|
# 6.8.5 |
|
|
|
|
|
|
|
|
# iterationStatement rule |
|
|
|
|
|
|
|
|
iterationStatement = w:WHILE l:LPAREN x:expression r:RPAREN s:statement { $$= new_C_while(w, l, x, r, s) } |
|
|
iterationStatement = w:WHILE l:LPAREN x:expression r:RPAREN s:statement { $$= new_C_while(w, l, x, r, s) } |
|
|
| d:DO s:statement w:WHILE l:LPAREN x:expression r:RPAREN t:SEMI { $$= new_C_do(d, s, w, l, x, r, t) } |
|
|
| d:DO s:statement w:WHILE l:LPAREN x:expression r:RPAREN t:SEMI { $$= new_C_do(d, s, w, l, x, r, t) } |
|
@ -2056,7 +2040,7 @@ iterationStatement = w:WHILE l:LPAREN x:expression r:RPAREN s:statement |
|
|
| f:FOR l:LPAREN a:declaration b:expressionOpt u:SEMI |
|
|
| f:FOR l:LPAREN a:declaration b:expressionOpt u:SEMI |
|
|
c:expressionOpt r:RPAREN s:statement { $$= new_C_for(f, l, a, newNullObject(), b, u, c, r, s) } |
|
|
c:expressionOpt r:RPAREN s:statement { $$= new_C_for(f, l, a, newNullObject(), b, u, c, r, s) } |
|
|
|
|
|
|
|
|
# 6.8.6 |
|
|
|
|
|
|
|
|
# jumpStatement rule |
|
|
|
|
|
|
|
|
jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, newNullObject(), i, t) } |
|
|
jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, newNullObject(), i, t) } |
|
|
| c:CONTINUE t:SEMI { $$= new_C_continue(c, t) } |
|
|
| c:CONTINUE t:SEMI { $$= new_C_continue(c, t) } |
|
@ -2064,9 +2048,7 @@ jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, |
|
|
| r:RETURN x:expressionOpt t:SEMI { $$= new_C_return(r, x, t) } |
|
|
| r:RETURN x:expressionOpt t:SEMI { $$= new_C_return(r, x, t) } |
|
|
| g:GOTO s:STAR x:expression t:SEMI &{gnu} { $$= new_C_goto(g, s, x, t) } |
|
|
| g:GOTO s:STAR x:expression t:SEMI &{gnu} { $$= new_C_goto(g, s, x, t) } |
|
|
|
|
|
|
|
|
### A.2.4 External definitions |
|
|
|
|
|
|
|
|
|
|
|
# 6.9 |
|
|
|
|
|
|
|
|
# externalDeclaration rule |
|
|
|
|
|
|
|
|
## translationUnit = externalDeclaration+ |
|
|
## translationUnit = externalDeclaration+ |
|
|
|
|
|
|
|
@ -2306,15 +2288,15 @@ _FLOAT128 = '_Float128' !IDREST &{gnu} { $$= newToken("_Float128" |
|
|
# input buffer from moving past it before redirecting input from the imported file |
|
|
# input buffer from moving past it before redirecting input from the imported file |
|
|
|
|
|
|
|
|
metaCatch = META_AT ( META_IMPORT s:META_STRING ";" { inputStackPush(get(s, String, value)) ; $$= 0 } |
|
|
metaCatch = META_AT ( META_IMPORT s:META_STRING ";" { inputStackPush(get(s, String, value)) ; $$= 0 } |
|
|
| m:mvalue { map_append(outputProgram, m) ; $$= null } |
|
|
|
|
|
| META_LCB s:mstmts { map_append(outputProgram, s) ; $$= null } |
|
|
|
|
|
|
|
|
| m:mvalue { $$= m } |
|
|
|
|
|
| META_LCB s:mstmts { $$= s } |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
mvalue = ( i:META_IDENT { i= newGetVariable(i) } ( a:meta_argumentList { oop k = map_pop(a); i = newCall(i, a, k) } # call a function with argument |
|
|
mvalue = ( i:META_IDENT { i= newGetVariable(i) } ( a:meta_argumentList { oop k = map_pop(a); i = newCall(i, a, k) } # call a function with argument |
|
|
| { i = is(Function, eval(globals, i)) == 1 ? newCall(i, makeMap(), null) : i } # without |
|
|
|
|
|
|
|
|
| { i = is(Function, eval(globals, i)) ? newCall(i, makeMap(), null) : i } # without |
|
|
) |
|
|
) |
|
|
| META_LPAREN ( i:meta_exp ) META_RPAREN |
|
|
| META_LPAREN ( i:meta_exp ) META_RPAREN |
|
|
) { $$= eval(globals, i) } |
|
|
|
|
|
|
|
|
) { $$= eval(globals, i) } |
|
|
|
|
|
|
|
|
mstmts = ( s:eval_stmt )* META_RCB { $$= s } # return the last stmt |
|
|
mstmts = ( s:eval_stmt )* META_RCB { $$= s } # return the last stmt |
|
|
|
|
|
|
|
@ -2533,26 +2515,22 @@ META_FLOAT = < [-+]* [0-9]+ '.' [0-9]* ('e'[-+]*[0-9]+)? > { $$= make |
|
|
|
|
|
|
|
|
#--------------------------------------------- Meta operator ----------------------------------------------# |
|
|
#--------------------------------------------- Meta operator ----------------------------------------------# |
|
|
|
|
|
|
|
|
MO_OPERATION = META_BACKTICK ( MO_INITIALIZER i:initializer { $$= newUnary(Quasiquote_proto, i) } |
|
|
|
|
|
| MO_CONSTANT c:constant { $$= newUnary(Quasiquote_proto, c) } |
|
|
|
|
|
| MO_STATEMENT s:statement { $$= newUnary(Quasiquote_proto, s) } |
|
|
|
|
|
| MO_INTEGER i:integerConstant { $$= newUnary(Quasiquote_proto, i) } |
|
|
|
|
|
| MO_DECLARATION d:declaration { $$= newUnary(Quasiquote_proto, d) } |
|
|
|
|
|
|
|
|
MO_OPERATION = META_BACKTICK ( MO_CONSTANT c:constant { $$= newUnary(Quasiquote_proto, c) } |
|
|
| MO_STRING s:stringLiteral { $$= newUnary(Quasiquote_proto, s) } |
|
|
| MO_STRING s:stringLiteral { $$= newUnary(Quasiquote_proto, s) } |
|
|
|
|
|
| MO_EXPRESSION e:expression { $$= newUnary(Quasiquote_proto, e) } |
|
|
| MO_FUN f:functionDefinition { $$= newUnary(Quasiquote_proto, f) } |
|
|
| MO_FUN f:functionDefinition { $$= newUnary(Quasiquote_proto, f) } |
|
|
|
|
|
| MO_DECLARATION d:declaration { $$= newUnary(Quasiquote_proto, d) } |
|
|
|
|
|
| MO_STATEMENT s:statement { $$= newUnary(Quasiquote_proto, s) } |
|
|
| MO_ED e:externalDeclaration { $$= newUnary(Quasiquote_proto, e) } |
|
|
| MO_ED e:externalDeclaration { $$= newUnary(Quasiquote_proto, e) } |
|
|
| MO_EXPRESSION e:expression { $$= newUnary(Quasiquote_proto, e) } |
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
MO_INITIALIZER = 'initializer' ![(a-zA-Z0-9_] -- |
|
|
|
|
|
MO_CONSTANT = 'constant' ![(a-zA-Z0-9_] -- |
|
|
MO_CONSTANT = 'constant' ![(a-zA-Z0-9_] -- |
|
|
MO_STATEMENT = 'statement' ![(a-zA-Z0-9_] -- |
|
|
|
|
|
MO_INTEGER = 'integer' ![(a-zA-Z0-9_] -- |
|
|
|
|
|
MO_DECLARATION = 'declaration' ![(a-zA-Z0-9_] -- |
|
|
|
|
|
MO_STRING = 'string' ![(a-zA-Z0-9_] -- |
|
|
MO_STRING = 'string' ![(a-zA-Z0-9_] -- |
|
|
|
|
|
MO_EXPRESSION = 'expression' ![(a-zA-Z0-9_] -- |
|
|
MO_FUN = 'fun' ![(a-zA-Z0-9_] -- |
|
|
MO_FUN = 'fun' ![(a-zA-Z0-9_] -- |
|
|
|
|
|
MO_DECLARATION = 'declaration' ![(a-zA-Z0-9_] -- |
|
|
|
|
|
MO_STATEMENT = 'statement' ![(a-zA-Z0-9_] -- |
|
|
MO_ED = 'ed' ![(a-zA-Z0-9_] -- |
|
|
MO_ED = 'ed' ![(a-zA-Z0-9_] -- |
|
|
MO_EXPRESSION = 'expression' ![(a-zA-Z0-9_] -- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------- Meta rules ----------------------------------------------# |
|
|
#--------------------------------------------- Meta rules ----------------------------------------------# |
|
@ -3238,7 +3216,11 @@ oop eval(oop scope, oop ast) |
|
|
if (keys != null && map_size(keys) > 0) { |
|
|
if (keys != null && map_size(keys) > 0) { |
|
|
oop newArgs = makeMap(); |
|
|
oop newArgs = makeMap(); |
|
|
for (int i = 0; i<map_size(args); i++) { |
|
|
for (int i = 0; i<map_size(args); i++) { |
|
|
if (map_get(keys, makeInteger(i)) == null) map_append(newArgs, map_get(args, makeInteger(i))); |
|
|
|
|
|
|
|
|
if (map_get(keys, makeInteger(i)) == null) { |
|
|
|
|
|
map_append(newArgs, map_get(args, makeInteger(i))); |
|
|
|
|
|
} else { |
|
|
|
|
|
map_append(newArgs, null); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
oop paramFunc = get(func, Function, param); |
|
|
oop paramFunc = get(func, Function, param); |
|
|
oop idKeys = map_keys(keys); |
|
|
oop idKeys = map_keys(keys); |
|
@ -3699,10 +3681,17 @@ void readEvalPrint(oop scope, char *fileName) |
|
|
} |
|
|
} |
|
|
oop proto = map_get(yylval, __proto___symbol); |
|
|
oop proto = map_get(yylval, __proto___symbol); |
|
|
if (proto == null) { |
|
|
if (proto == null) { |
|
|
|
|
|
if (is(Map, yylval)) { |
|
|
|
|
|
for (int i = 0; i < map_size(yylval); i++) { |
|
|
|
|
|
map_append(outputProgram, treeCopyUnquoting(scope, map_get(yylval, makeInteger(i)))); |
|
|
|
|
|
} |
|
|
|
|
|
continue; |
|
|
|
|
|
} // new modification |
|
|
|
|
|
println(map_keys(yylval)); |
|
|
printf("no prototype associated with "); |
|
|
printf("no prototype associated with "); |
|
|
println(yylval); |
|
|
println(yylval); |
|
|
fflush(stdout); |
|
|
fflush(stdout); |
|
|
fprintf(stderr, "aborting\n"); |
|
|
|
|
|
|
|
|
fprintf(stderr, "(readEvalPrint - proto == null) aborting\n"); |
|
|
exit(1); |
|
|
exit(1); |
|
|
} |
|
|
} |
|
|
// proto_number is the enum version of the proto symbol |
|
|
// proto_number is the enum version of the proto symbol |
|
@ -3764,6 +3753,22 @@ oop prim_scope(oop scope, oop params) |
|
|
return fixScope(scope); |
|
|
return fixScope(scope); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
oop prim_parseFrom(oop scope, oop params) |
|
|
|
|
|
{ |
|
|
|
|
|
if (map_size(params) != 1) return null; |
|
|
|
|
|
oop name = get(params, Map, elements)[0].value; |
|
|
|
|
|
if (!is(String, name)) return null; |
|
|
|
|
|
char *s = get(name, String, value); |
|
|
|
|
|
struct _yycontext *yy = yyctx; |
|
|
|
|
|
if (!strcmp(s, "declaration")) { |
|
|
|
|
|
oop res = yyparsefrom(yy_declaration) ? __ : null ; |
|
|
|
|
|
yylval = res; // TODO |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
printf("%s expected\n", s); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#include <sys/resource.h> |
|
|
#include <sys/resource.h> |
|
|
|
|
|
|
|
|
oop prim_microseconds(oop scope, oop params) |
|
|
oop prim_microseconds(oop scope, oop params) |
|
@ -3785,6 +3790,7 @@ void outputText(char *text) |
|
|
|
|
|
|
|
|
void outputNode(oop node) |
|
|
void outputNode(oop node) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
if (!node) return; |
|
|
if (!node) return; |
|
|
switch (getType(node)) { |
|
|
switch (getType(node)) { |
|
|
case Undefined: |
|
|
case Undefined: |
|
@ -4215,6 +4221,9 @@ void outputTree(oop node, int depth) |
|
|
CASE(stringLiteral) |
|
|
CASE(stringLiteral) |
|
|
OUT(text); |
|
|
OUT(text); |
|
|
break; |
|
|
break; |
|
|
|
|
|
CASE(string) |
|
|
|
|
|
OUT(value); |
|
|
|
|
|
break; |
|
|
CASE(char) |
|
|
CASE(char) |
|
|
OUT(value); |
|
|
OUT(value); |
|
|
break; |
|
|
break; |
|
@ -4763,6 +4772,7 @@ void outputTree(oop node, int depth) |
|
|
/** Unknown node */ |
|
|
/** Unknown node */ |
|
|
default: |
|
|
default: |
|
|
printf("I cannot print a node with proto_number %i\n", proto_number); |
|
|
printf("I cannot print a node with proto_number %i\n", proto_number); |
|
|
|
|
|
println(node); |
|
|
exit(0); |
|
|
exit(0); |
|
|
} |
|
|
} |
|
|
#undef PRINT |
|
|
#undef PRINT |
|
@ -4803,10 +4813,9 @@ int main(int argc, char **argv) |
|
|
map_set(globals, intern("treeCopy" ), makeFunction(prim_treeCopy, intern("treeCopy" ), null, null, globals, null)); |
|
|
map_set(globals, intern("treeCopy" ), makeFunction(prim_treeCopy, intern("treeCopy" ), null, null, globals, null)); |
|
|
map_set(globals, intern("import" ), makeFunction(prim_import, intern("import" ), null, null, globals, null)); |
|
|
map_set(globals, intern("import" ), makeFunction(prim_import, intern("import" ), null, null, globals, null)); |
|
|
map_set(globals, intern("microseconds"), makeFunction(prim_microseconds, intern("microseconds"), null, null, globals, null)); |
|
|
map_set(globals, intern("microseconds"), makeFunction(prim_microseconds, intern("microseconds"), null, null, globals, null)); |
|
|
map_set(globals, intern("string" ), makeFunction(prim_String , intern("string" ), null, null, globals, null)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map_set(globals, intern("string" ), makeFunction(prim_String, intern("string" ), null, null, globals, null)); |
|
|
map_set(globals, intern("scope" ), makeFunction(prim_scope, intern("scope" ), null, null, globals, null)); |
|
|
map_set(globals, intern("scope" ), makeFunction(prim_scope, intern("scope" ), null, null, globals, null)); |
|
|
|
|
|
map_set(globals, intern("parseFrom" ), makeFunction(prim_parseFrom, intern("parseFrom" ), null, null, globals, null)); |
|
|
|
|
|
|
|
|
#define _DO(NAME) NAME##_symbol=intern(#NAME); |
|
|
#define _DO(NAME) NAME##_symbol=intern(#NAME); |
|
|
DO_SYMBOLS() |
|
|
DO_SYMBOLS() |