From 49d67b3ff18195edbcad937d38c9b869e67163dc Mon Sep 17 00:00:00 2001 From: Nathan R Date: Sun, 18 Jul 2021 23:59:01 +0200 Subject: [PATCH] add a lot of object constructors --- ccmeta.leg | 1671 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 1083 insertions(+), 588 deletions(-) diff --git a/ccmeta.leg b/ccmeta.leg index 23b188f..9aba0ff 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -33,7 +33,13 @@ _DO(Comment) _DO(Token) \ _DO(C_declaration) \ _DO(C_if) _DO(C_int) _DO(C_float) _DO(C_char) _DO(C_id) _DO(C_while) _DO(C_do) _DO(C_for) \ - _DO(C_binary) + _DO(C_binary) _DO(C_initializer) _DO(C_range) _DO(C_conditional) _DO(C_index) \ + _DO(C_designation) _DO(C_attribution) _DO(C_deref) _DO(C_block) _DO(C_call) _DO(C_subexpr) \ + _DO(C_array) _DO(C_parameter) _DO(C_typeOf) _DO(C_unary) _DO(C_prefix) _DO(C_alignOf) \ + _DO(C_sizeOf) _DO(C_cast) _DO(C_attributeSpec) _DO(C_asm) _DO(C_asmExpr) _DO(C_asmExprArg) \ + _DO(C_aggregate) _DO(C_attribute) _DO(C_postfix) _DO(C_compound) _DO(C_functionDef) \ + _DO(C_exprStatement) _DO(C_switch) _DO(C_goto) _DO(C_continue) _DO(C_break) _DO(C_return) \ + _DO(C_case) _DO(C_default) _DO(C_label) _DO(C_labelDeclaration) typedef enum { t_UNDEFINED=0, @@ -86,7 +92,14 @@ oop globals= 0; _DO(comment) \ _DO(text) _DO(if) _DO(lparen) _DO(rparen) _DO(else) _DO(identifier) _DO(semicolon) _DO(while) \ _DO(do) _DO(for) _DO(initExpr) _DO(condExpr) _DO(incrExpr) _DO(firstSemi) _DO(secondSemi) \ - _DO(binary) _DO(specifiers) _DO(declarators) + _DO(binary) _DO(specifiers) _DO(declarators) \ + _DO(rightCurly) _DO(leftCurly) _DO(initList) _DO(comma) _DO(constExpr1) _DO(constExpr2) \ + _DO(ellipsis) _DO(logicalOr) _DO(question) _DO(colon) _DO(leftBracket) _DO(rightBracket) \ + _DO(primaryExpr) _DO(typeQualList) _DO(star) _DO(bxor) _DO(paramTypeL) _DO(assignExpr) \ + _DO(static) _DO(dynamic) _DO(typeName) _DO(sizeOfTok) _DO(alignOfTok) _DO(llparen) _DO(lrparen) \ + _DO(rlparen) _DO(rrparen) _DO(attributeL) _DO(attributeTok) _DO(typeOfTok) _DO(asmTok) _DO(element) \ + _DO(volatileTok) _DO(gotoTok) _DO(declarationL) _DO(compoundS) _DO(switchTok) _DO(continueTok) \ + _DO(breakTok) _DO(returnTok) _DO(caseTok) _DO(defaultTok) #define _DO(NAME) oop NAME##_symbol; @@ -239,14 +252,6 @@ oop newMap(oop value) return map; } -oop newDeclaration(oop name, oop exp) -{ - oop declaration = newObject(Declaration_proto); - map_set(declaration, lhs_symbol, name); - map_set(declaration, rhs_symbol, exp); - return declaration; -} - oop new_C_if(oop ifTok, oop lParen, oop condition, oop rParen, oop consequent, oop elseTok, oop alternate) { oop obj = newObject(C_if_proto); @@ -299,13 +304,81 @@ oop new_C_for(oop forTok, oop lParen, oop initExpr, oop semicolon1, oop condExpr return object; } -oop newSwitch(oop expression, oop labels, oop statements) -{ - oop obj= newObject(Switch_proto); - map_set(obj, expression_symbol, expression); - map_set(obj, labels_symbol, labels); - map_set(obj, statements_symbol, statements); - return obj; +oop new_C_goto(oop gotoTok, oop star, oop id, oop semicolon) { + oop object = newObject(C_goto_proto); + map_set(object, gotoTok_symbol, gotoTok); + map_set(object, star_symbol, star); + map_set(object, name_symbol, id); + map_set(object, semicolon_symbol, semicolon); + return object; +} + +oop new_C_initializer(oop leftCurly, oop initList, oop comma, oop rightCurly) { + oop object = newObject(C_initializer_proto); + map_set(object, leftCurly_symbol, leftCurly); + map_set(object, initList_symbol, initList); + map_set(object, comma_symbol, comma); + map_set(object, rightCurly_symbol, rightCurly); + return object; +} + +oop new_C_range(oop constExpr1, oop ellipsis, oop constExpr2) { + oop object = newObject(C_range_proto); + map_set(object, constExpr1_symbol, constExpr1); + map_set(object, ellipsis_symbol, ellipsis); + map_set(object, constExpr2_symbol, constExpr2); + return object; +} + +oop new_C_switch(oop switchTok, oop lParen, oop expression, oop rParen, oop statement) { + oop object = newObject(C_switch_proto); + map_set(object, switchTok_symbol, switchTok); + map_set(object, lparen_symbol, lParen); + map_set(object, expression_symbol, expression); + map_set(object, rParen, rParen); + map_set(object, statements_symbol, statement); + return object; +} + +oop new_C_case (oop caseTok, oop expression, oop colon, oop statement) { + oop object = newObject(C_case_proto); + map_set(object, caseTok_symbol, caseTok); + map_set(object, expression_symbol, expression); + map_set(object, colon_symbol, colon); + map_set(object, statements_symbol, statement); + return object; +} + +oop new_C_default(oop defaultTok, oop colon, oop statement) { + oop object = newObject(C_default_proto); + map_set(object, defaultTok_symbol, defaultTok); + map_set(object, colon_symbol, colon); + map_set(object, statements_symbol, statement); + return object; +} + +oop new_C_attribution(oop specifier, oop declarator) { + oop object = newObject(C_attribution_proto); + map_set(object, specifiers_symbol, specifier); + map_set(object, declarators_symbol, declarator); + return object; +} + +oop new_C_deref(oop star, oop typeQualiferL, oop declarator) { + oop object = newObject(C_deref_proto); + map_set(object, star_symbol, star); + map_set(object, typeQualList_symbol,typeQualiferL); + map_set(object, declarators_symbol, declarator); + return object; +} + +oop new_C_functionDef(oop specifiers, oop declarator, oop declarationList, oop compoundStatement) { + oop object = newObject(C_functionDef_proto); + map_set(object, specifiers_symbol, specifiers); + map_set(object, declarators_symbol, declarator); + map_set(object, declarationL_symbol,declarationList); + map_set(object, compoundS_symbol, compoundStatement); + return object; } // take char *name or oop already interned? @@ -402,6 +475,12 @@ oop new_C_char(char *s) { return object; } +oop new_C_id(char* id) { + oop object = newObject(C_id_proto); + map_set(object, identifier_symbol, intern(id)); + return object; +} + oop newPreIncrement(oop rhs) { assert(is(Map, rhs)); oop proto= map_get(rhs, __proto___symbol); assert(null != proto); @@ -478,27 +557,67 @@ oop newPostDecrement(oop rhs) return rhs; } -oop newUnary(oop proto, oop rhs) -{ - oop obj = newObject(proto); - map_set(obj, rhs_symbol, rhs); - return obj; +oop new_C_sizeOf(oop sizeOfTok, oop lParen, oop typeName, oop rParen) { + oop object = newObject(C_sizeOf_proto); + map_set(object, sizeOfTok_symbol, sizeOfTok); + map_set(object, lparen_symbol, lParen); + map_set(object, typeName_symbol, typeName); + map_set(object, rparen_symbol, rParen); + return object; +} + +oop new_C_alignOf(oop alignOfTok, oop lParen, oop typeName, oop rParen) { + oop object = newObject(C_alignOf_proto); + map_set(object, alignOfTok_symbol, alignOfTok); + map_set(object, lparen_symbol, lParen); + map_set(object, typeName_symbol, typeName); + map_set(object, rparen_symbol, rParen); + return object; +} + +oop new_C_prefix(oop operator, oop expression) { + oop object = newObject(C_prefix_proto); + map_set(object, operator_symbol, operator); + map_set(object, expression_symbol, expression); + return object; +} + +oop new_C_postfix(oop expression, oop operator) { + oop object = newObject(C_postfix_proto); + map_set(object, expression_symbol, expression); + map_set(object, operator_symbol, operator); + return object; +} + +oop new_C_unary(oop operator, oop expression) { + oop object = newObject(C_unary_proto); + map_set(object, operator_symbol, operator); + map_set(object, expression_symbol, expression); + return object; } oop new_C_binary(oop lhs, oop binary, oop rhs) { oop object = newObject(C_binary_proto); - map_set(object, lhs_symbol, lhs); - map_set(object, binary_symbol, binary); - map_set(object, rhs_symbol, rhs); + map_set(object, lhs_symbol, lhs); + map_set(object, binary_symbol, binary); + map_set(object, rhs_symbol, rhs); + return object; +} + +oop new_C_compound(oop leftCurly, oop expression, oop rightCurly) { + oop object = newObject(C_compound_proto); + map_set(object, leftCurly_symbol, leftCurly); + map_set(object, expression_symbol, expression); + map_set(object, rightCurly_symbol, rightCurly); return object; } oop newAssign(oop proto, oop lhs, oop operator, oop rhs) { oop obj = newObject(proto); - map_set(obj, lhs_symbol, lhs); - map_set(obj, operator_symbol, operator); - map_set(obj, rhs_symbol, rhs); + map_set(obj, lhs_symbol, lhs); + map_set(obj, operator_symbol, operator); + map_set(obj, rhs_symbol, rhs); return obj; } @@ -556,12 +675,33 @@ oop getSyntax(int n, oop func) return getSyntaxId(n, key); } -oop newCall(oop func, oop args) -{ - oop call = newObject(Call_proto); - map_set(call, func_symbol, func); - map_set(call, args_symbol, args); - return call; +oop new_C_subexpr (oop lParen, oop declarator, oop rParen) { + oop object = newObject(C_subexpr_proto); + map_set(object, lparen_symbol, lParen); + map_set(object, declarators_symbol, declarator); + map_set(object, rparen_symbol, rParen); + return object; +} + +oop new_C_call(oop declarator, oop lParen, oop paramTypeL, oop rParen) { + oop object = newObject(C_call_proto); + map_set(object, declarators_symbol, declarator); + map_set(object, lparen_symbol, lParen); + map_set(object, paramTypeL_symbol, paramTypeL); + map_set(object, rparen_symbol, rParen); + return object; +} + +oop new_C_array(oop declarator, oop lBracket, oop staticTok, oop typeQualiferL, oop symbol, oop assignExpr, oop rBracket) { + oop object = newObject(C_array_proto); + map_set(object, declarators_symbol, declarator); + map_set(object, leftBracket_symbol, lBracket); + map_set(object, static_symbol, staticTok); + map_set(object, typeQualList_symbol,typeQualiferL); + map_set(object, dynamic_symbol, symbol); + map_set(object, assignExpr_symbol, assignExpr); + map_set(object, rightBracket_symbol,rBracket); + return object; } oop newInvoke(oop this, oop name, oop args) @@ -573,30 +713,34 @@ oop newInvoke(oop this, oop name, oop args) return obj; } -oop newBlock(oop statements) -{ - oop obj = newObject(Block_proto); - map_set(obj, statements_symbol, statements); - return obj; +oop new_C_block(oop bxor, oop typeQualiferL, oop declarator) { + oop object = newObject(C_block_proto); + map_set(object, bxor_symbol, bxor); + map_set(object, typeQualList_symbol,typeQualiferL); + map_set(object, declarators_symbol, declarator); + return object; } -oop newReturn(oop exp) -{ - oop obj = newObject(Return_proto); - map_set(obj, value_symbol, exp); - return obj; +oop new_C_continue(oop continueTok, oop semicolon) { + oop object = newObject(C_continue_proto); + map_set(object, continueTok_symbol, continueTok); + map_set(object, semicolon_symbol, semicolon); + return object; } -oop newBreak(void) -{ - oop obj = newObject(Break_proto); - return obj; +oop new_C_break(oop breakTok, oop semicolon) { + oop object = newObject(C_break_proto); + map_set(object, breakTok_symbol, breakTok); + map_set(object, semicolon_symbol, semicolon); + return object; } -oop newContinue(void) -{ - oop obj = newObject(Continue_proto); - return obj; +oop new_C_return(oop returnTok, oop expression, oop semicolon) { + oop object = newObject(C_return_proto); + map_set(object, returnTok_symbol, returnTok); + map_set(object, expression_symbol, expression); + map_set(object, semicolon_symbol, semicolon); + return object; } oop newTry(oop try, oop exception, oop catch, oop finally) @@ -609,9 +753,40 @@ oop newTry(oop try, oop exception, oop catch, oop finally) return obj; } -oop new_C_id(char* id) { - oop object = newObject(C_id_proto); - map_set(object, identifier_symbol, intern(id)); +oop new_C_exprStatement(oop expression, oop semicolon) { + oop object = newObject(C_exprStatement_proto); + map_set(object, expression_symbol, expression); + map_set(object, semicolon_symbol, semicolon); + return object; +} + +oop new_C_asm(oop asmTok, oop lParen, oop stringLiteral, oop rParen) { + oop object = newObject(C_asm_proto); + map_set(object, asmTok_symbol, asmTok); + map_set(object, lparen_symbol, lParen); + map_set(object, text_symbol, stringLiteral); + map_set(object, rparen_symbol, rParen); + return object; +} + +oop new_C_asmExpr(oop asmTok, oop volatileTok, oop gotoTok, oop lParen, oop stringLiteral, oop list, oop rParen) { + oop object = newObject(C_asmExpr_proto); + map_set(object, asmTok_symbol, asmTok); + map_set(object, volatileTok_symbol, volatileTok); + map_set(object, gotoTok_symbol, gotoTok); + map_set(object, lparen_symbol, lParen); + map_set(object, text_symbol, stringLiteral); + map_set(object, element_symbol, list); + map_set(object, rparen_symbol, rParen); + return object; +} + +oop new_C_asmExprArg(oop stringLiteral, oop lParen, oop expression, oop rParen) { + oop object = newObject(C_asmExprArg_proto); + map_set(object, text_symbol, stringLiteral); + map_set(object, lparen_symbol, lParen); + map_set(object, expression_symbol, expression); + map_set(object, rparen_symbol, rParen); return object; } @@ -623,10 +798,118 @@ oop new_C_declaration(oop specifiers, oop declarators, oop semicolon) { return object; } +oop new_C_parameter(oop paramSpecifiers, oop declarator) { + oop object = newObject(C_parameter_proto); + map_set(object, specifiers_symbol, paramSpecifiers); + map_set(object, declarators_symbol, declarator); + return object; +} + + /* TODO */ void C_declarationBegin(void) {} int C_declarationAbort(void) { return 0; } void C_declarationEnd(void) {} +void C_scopeBegin(){} +int C_scopeAbort(){ return 0; } +void C_scopeEnd(){} + +int declarationId(char *s) { return 1; } +int isTypedefName(char *s) { return 1; } + +oop new_C_conditional(oop logicalOrExpression, oop question, oop expression, oop colon, oop conditionalExpression) { + oop object = newObject(C_conditional_proto); + map_set(object, logicalOr_symbol, logicalOrExpression); + map_set(object, question_symbol, question); + map_set(object, expression_symbol, expression); + map_set(object, colon_symbol, colon); + map_set(object, condExpr_symbol, conditionalExpression); + return object; +} + +oop new_C_designation(oop id, oop colon) { + oop object = newObject(C_designation_proto); + map_set(object, identifier_symbol, id); + map_set(object, colon_symbol, colon); + return object; +} + +oop new_C_index(oop primaryExpression, oop lBracket, oop expression, oop rBracket) { + oop object = newObject(C_index_proto); + map_set(object, primaryExpr_symbol, primaryExpression); + map_set(object, leftBracket_symbol, lBracket); + map_set(object, expression_symbol, expression); + map_set(object, rightBracket_symbol,rBracket); + return object; +} + +oop new_C_typeOf(oop typeOf, oop lParen, oop typeName, oop expression, oop rParen) { + oop object = newObject(C_typeOf_proto); + map_set(object, typeOfTok_symbol, typeOf); + map_set(object, lparen_symbol, lParen); + map_set(object, typeName_symbol, typeName); + map_set(object, expression_symbol, expression); + map_set(object, rparen_symbol, rParen); + return object; +} + +oop new_C_cast(oop lParen, oop typeName, oop rParen, oop expression) { + oop object = newObject(C_cast_proto); + map_set(object, lparen_symbol, lParen); + map_set(object, typeName_symbol, typeName); + map_set(object, rparen_symbol, rParen); + map_set(object, expression_symbol, expression); + return object; +} + +oop new_C_attributeSpec(oop attributeTok, oop llParen, oop lrParen, oop attributeList, oop rlParen, oop rrParen) { + oop object = newObject(C_attributeSpec_proto); + map_set(object, attributeTok_symbol,attributeTok); + map_set(object, llparen_symbol, llParen); + map_set(object, lrparen_symbol, lrParen); + map_set(object, attributeL_symbol, attributeList); + map_set(object, rlparen_symbol, rlParen); + map_set(object, rrparen_symbol, rrParen); + return object; +} + +oop new_C_aggregate(oop lParen, oop typeName, oop rParen, oop leftCurly, oop initList, oop comma, oop rightCurly) { + oop object = newObject(C_aggregate_proto); + map_set(object, lparen_symbol, lParen); + map_set(object, typeName_symbol, typeName); + map_set(object, rparen_symbol, rParen); + map_set(object, leftCurly_symbol, leftCurly_symbol); + map_set(object, initList_symbol, initList); + map_set(object, comma_symbol, comma); + map_set(object, rightCurly_symbol, rightCurly); + return object; +} + +oop new_C_attribute(oop name, oop lParen, oop expression, oop rParen) { + oop object = newObject(C_attribute_proto); + map_set(object, text_symbol, name); + map_set(object, lparen_symbol, lParen); + map_set(object, expression_symbol, expression); + map_set(object, rparen_symbol, rParen); + return object; +} + +oop new_C_label(oop id, oop colon, oop attributeSpecifier, oop statement) { + oop object = newObject(C_label_proto); + map_set(object, name_symbol, id); + map_set(object, colon_symbol, colon); + map_set(object, attributeL_symbol, attributeSpecifier); + map_set(object, statements_symbol, statement); + return object; +} + +oop new_C_labelDeclaration(oop labelTok, oop list, oop semicolon) { + oop object = newObject(C_labelDeclaration_proto); + map_set(object, labels_symbol, labelTok); + map_set(object, element_symbol, list); + map_set(object, semicolon_symbol, semicolon); + return object; +} #define YY_INPUT(buf, result, max_size) \ @@ -655,6 +938,7 @@ int yyparsefrom(int (*yystart)(struct _yycontext *yy)); int irow= 0, icol= 0; int gnu= 1; +int apl = 1; //TODO char *errmsg= "no error"; @@ -702,6 +986,17 @@ void listAppend(oop obj) map_append(currentList, obj); } +void listAppend2(oop obj1, oop obj2) { + assert(currentList); + map_append(currentList, obj1); + map_append(currentList, obj2); +} + +void listWith(oop obj) { + listBegin(); + listAppend(obj); +} + oop listEnd(void) { assert(currentList); @@ -710,6 +1005,11 @@ oop listEnd(void) return list; } +oop List_addLast(oop obj1, oop obj2) { + listAppend2(obj1, obj2); + return listEnd(); +} + oop listEmpty(void) { return makeMap(); @@ -752,9 +1052,9 @@ universalCharacterName = "\\u" hexQuad | "\\U" hexQuad hexQuad hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hexadecimalDigit -#|### -#| -#|### A.1.5 Constants +### + +### A.1.5 Constants # 6.4.4 @@ -838,214 +1138,214 @@ octalEscapeSequence = '\\' octalDigit octalDigit? octalDigit? hexadecimalEscapeSequence = '\\x' hexadecimalDigit+ -#|### A.1.6 String literals -#| -#|# 6.4.5 -#| -#|stringLiteral = { $$= listBegin() } -#| ( s:stringLiteralPart { listAppend(s) } -#| )+ { $$= newString(listEnd()) } -#| -#|stringLiteralPart = < '"' sCharSequence '"' > { $$= newText(yytext) } - -#| | < 'L''"' sCharSequence '"' > { $$= newText(yytext) } - -#| -#|sCharSequence = ( escapeSequence | !EOL [^\"\\] )* -#| -#|### A.2.1 Expressions -#| -#|# 6.5.1 -#| -#|primaryExpression = stringLiteral | constant | id -#| | l:LPAREN x:expression r:RPAREN { $$= newSubexpr(l, x, r) } -#| | l:LPAREN x:compoundStatement r:RPAREN &{gnu} { $$= newSubexpr(l, x, r) } -#| -#|# 6.5.2 -#| -#|postfixExpression = o:LPAREN l:typeName p:RPAREN -#| a:LCURLY r:initializerList ( c:COMMA | {c=0} ) b:RCURLY { $$= newAggregate(o, l, p, a, r, c, b) } -#| | l:primaryExpression -#| ( o:LBRACKET r:expression p:RBRACKET { l= newIndex(l, o, r, p) } -#| | o:LPAREN r:argumentExpressionList p:RPAREN { l= newCall(l, o, r, p) } -#| | o:DOT r:id { l= newBinary(l, o, r) } -#| | o:PTR r:id { l= newBinary(l, o, r) } -#| | o:INC { l= newPostfix(l, o) } -#| | o:DEC { l= newPostfix(l, o) } -#| )* { $$= l } -#| -#|argumentExpressionList = { listBegin() } -#| ( x:assignmentExpression { listAppend(x) } -#| ( c:COMMA x:assignmentExpression { listAppend2(c, x) } -#| )* -#| )? { $$= listEnd() } -#| -#|# 6.5.3 -#| -#|unaryExpression = o:INC x:unaryExpression { $$= newPrefix(o, x) } -#| | o:DEC x:unaryExpression { $$= newPrefix(o, x) } -#| | o:unaryOperator x:castExpression { $$= newUnary(o, x) } -#| | s:SIZEOF ( l:LPAREN t:typeName r:RPAREN { $$= newSizeof(s, l, t, r) } -#| | x:unaryExpression { $$= newSizeof(s, 0, x, 0) } -#| ) -#| | s:ALIGNOF ( l:LPAREN t:typeName r:RPAREN { $$= newAlignof(s, l, t, r) } -#| | x:unaryExpression { $$= newAlignof(s, 0, x, 0) } -#| ) &{gnu} -#| | asmExpr &{gnu} -#| | postfixExpression -#| -#|unaryOperator = BAND | STAR | PLUS | MINUS | BNOT | LNOT -#| | LAND &{gnu} -#| | REAL &{gnu} -#| | IMAG &{gnu} -#| -#|# 6.5.4 -#| -#|castExpression = l:LPAREN t:typeName r:RPAREN x:castExpression { $$= newCast(l, t, r, x) } -#| | unaryExpression -#| -#|# 6.5.5 -#| -#|multiplicativeExpression = l:castExpression -#| ( o:multiplicativeOperator r:castExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|multiplicativeOperator = STAR | DIV | MOD -#| -#|# 6.5.6 -#| -#|additiveExpression = l:multiplicativeExpression -#| ( o:additiveOperator r:multiplicativeExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|additiveOperator = PLUS | MINUS -#| -#|# 6.5.7 -#| -#|shiftExpression = l:additiveExpression -#| ( o:shiftOperator r:additiveExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|shiftOperator = LSHIFT | RSHIFT -#| -#|# 6.5.8 -#| -#|relationalExpression = l:shiftExpression -#| ( o:relationalOperator r:shiftExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|relationalOperator = LT | LTE | GT | GTE -#| -#|# 6.5.9 -#| -#|equalityExpression = l:relationalExpression -#| ( o:equalityOperator r:relationalExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|equalityOperator = EQUAL | NOT_EQUAL -#| -#|# 6.5.10 -#| -#|andExpression = l:equalityExpression -#| ( o:BAND r:equalityExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|# 6.5.11 -#| -#|exclusiveOrExpression = l:andExpression -#| ( o:BXOR r:andExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|# 6.5.12 -#| -#|inclusiveOrExpression = l:exclusiveOrExpression -#| ( o:BOR r:exclusiveOrExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|# 6.5.13 -#| -#|logicalAndExpression = l:inclusiveOrExpression -#| ( o:LAND r:inclusiveOrExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|# 6.5.14 -#| -#|logicalOrExpression = l:logicalAndExpression -#| ( o:LOR r:logicalAndExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|# 6.5.15 -#| -#|conditionalExpression = l:logicalOrExpression -#| ( q:QUESTION m:expression c:COLON r:conditionalExpression { $$= newConditional(l, q, m, c, r) } -#| | q:QUESTION c:COLON r:conditionalExpression &{gnu} { $$= newConditional(l, q, 0, c, r) } -#| | { $$= l } -#| ) -#| -#|# 6.5.16 -#| -#|assignmentExpressionOpt = assignmentExpression | {$$=0} -#| -#|assignmentExpression = l:unaryExpression o:assignmentOperator r:assignmentExpression { $$= newBinary(l, o, r) } -#| | conditionalExpression -#| -#|assignmentOperator = ASSIGN -#| | STAR_ASSIGN | DIV_ASSIGN | MOD_ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN -#| | LSHIFT_ASSIGN | RSHIFT_ASSIGN | BAND_ASSIGN | BXOR_ASSIGN | BOR_ASSIGN -#| -#|# 6.5.17 -#| -#|expression = l:assignmentExpression -#| ( o:COMMA r:assignmentExpression { l= newBinary(l, o, r) } -#| )* { $$= l } -#| -#|expressionOpt = expression | { $$= 0 } -#| -#|constantExpression = conditionalExpression -#| -#|### A.2.2 Declarations -#| -#|# 6.7 -#| -declaration = @{ C_declarationBegin() } - ( s:declarationSpecifiers - d:initDeclaratorListOpt - t:SEMI { $$= new_C_declaration(s, d, t) } - @{ C_declarationEnd() } - | - &{ C_declarationAbort() } +### A.1.6 String literals + +# 6.4.5 + +stringLiteral = { listBegin(); //TODO $$= listBegin() } + ( s:stringLiteralPart { listAppend(s) } + )+ { $$= newString(listEnd()) } + +stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_char(yytext) } - + | < 'L''"' sCharSequence '"' > { $$= new_C_char(yytext) } - + +sCharSequence = ( escapeSequence | !EOL [^\"\\] )* + +### A.2.1 Expressions + +# 6.5.1 + +primaryExpression = stringLiteral | constant | id + | 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) } + +# 6.5.2 + +postfixExpression = o:LPAREN l:typeName p:RPAREN + a:LCURLY r:initializerList ( c:COMMA | {c=0} ) b:RCURLY { $$= new_C_aggregate(o, l, p, a, r, c, b) } + | l:primaryExpression + ( o:LBRACKET r:expression p:RBRACKET { l= new_C_index(l, o, r, p) } + | o:LPAREN r:argumentExpressionList p:RPAREN { l= new_C_call(l, o, r, p) } + | o:DOT r:id { l= new_C_binary(l, o, r) } + | o:PTR r:id { l= new_C_binary(l, o, r) } + | o:INC { l= new_C_postfix(l, o) } + | o:DEC { l= new_C_postfix(l, o) } + )* { $$= l } + +argumentExpressionList = { listBegin() } + ( x:assignmentExpression { listAppend(x) } + ( c:COMMA x:assignmentExpression { listAppend2(c, x) } + )* + )? { $$= listEnd() } + +# 6.5.3 + +unaryExpression = o:INC x:unaryExpression { $$= new_C_prefix(o, x) } + | o:DEC x:unaryExpression { $$= new_C_prefix(o, x) } + | o:unaryOperator x:castExpression { $$= new_C_unary(o, x) } + | s:SIZEOF ( l:LPAREN t:typeName r:RPAREN { $$= new_C_sizeOf(s, l, t, r) } + | x:unaryExpression { $$= new_C_sizeOf(s, 0, x, 0) } + ) + | s:ALIGNOF ( l:LPAREN t:typeName r:RPAREN { $$= new_C_alignOf(s, l, t, r) } + | x:unaryExpression { $$= new_C_alignOf(s, 0, x, 0) } + ) &{gnu} + | asmExpr &{gnu} + | postfixExpression + +unaryOperator = BAND | STAR | PLUS | MINUS | BNOT | LNOT + | LAND &{gnu} + | REAL &{gnu} + | IMAG &{gnu} + +# 6.5.4 + +castExpression = l:LPAREN t:typeName r:RPAREN x:castExpression { $$= new_C_cast(l, t, r, x) } + | unaryExpression + +# 6.5.5 + +multiplicativeExpression = l:castExpression + ( o:multiplicativeOperator r:castExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +multiplicativeOperator = STAR | DIV | MOD + +# 6.5.6 + +additiveExpression = l:multiplicativeExpression + ( o:additiveOperator r:multiplicativeExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +additiveOperator = PLUS | MINUS + +# 6.5.7 + +shiftExpression = l:additiveExpression + ( o:shiftOperator r:additiveExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +shiftOperator = LSHIFT | RSHIFT + +# 6.5.8 + +relationalExpression = l:shiftExpression + ( o:relationalOperator r:shiftExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +relationalOperator = LT | LTE | GT | GTE + +# 6.5.9 + +equalityExpression = l:relationalExpression + ( o:equalityOperator r:relationalExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +equalityOperator = EQUAL | NOT_EQUAL + +# 6.5.10 + +andExpression = l:equalityExpression + ( o:BAND r:equalityExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +# 6.5.11 + +exclusiveOrExpression = l:andExpression + ( o:BXOR r:andExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +# 6.5.12 + +inclusiveOrExpression = l:exclusiveOrExpression + ( o:BOR r:exclusiveOrExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +# 6.5.13 + +logicalAndExpression = l:inclusiveOrExpression + ( o:LAND r:inclusiveOrExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +# 6.5.14 + +logicalOrExpression = l:logicalAndExpression + ( o:LOR r:logicalAndExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +# 6.5.15 + +conditionalExpression = l:logicalOrExpression + ( q:QUESTION m:expression c:COLON r:conditionalExpression { $$= new_C_conditional(l, q, m, c, r) } + | q:QUESTION c:COLON r:conditionalExpression &{gnu} { $$= new_C_conditional(l, q, 0, c, r) } + | { $$= l } ) +# 6.5.16 + +assignmentExpressionOpt = assignmentExpression | {$$=0} + +assignmentExpression = l:unaryExpression o:assignmentOperator r:assignmentExpression { $$= new_C_binary(l, o, r) } + | conditionalExpression + +assignmentOperator = ASSIGN + | STAR_ASSIGN | DIV_ASSIGN | MOD_ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN + | LSHIFT_ASSIGN | RSHIFT_ASSIGN | BAND_ASSIGN | BXOR_ASSIGN | BOR_ASSIGN + +# 6.5.17 + +expression = l:assignmentExpression + ( o:COMMA r:assignmentExpression { l= new_C_binary(l, o, r) } + )* { $$= l } + +expressionOpt = expression | { $$= 0 } + +constantExpression = conditionalExpression + +### A.2.2 Declarations + +# 6.7 + +declaration = @{ C_declarationBegin() } + ( s:declarationSpecifiers + d:initDeclaratorListOpt + t:SEMI { $$= new_C_declaration(s, d, t) } + @{ C_declarationEnd() } + | + &{ C_declarationAbort() } + ) + declarationSpecifiers = @{ int specified= 0 } { listBegin() } - ( s:storageClassSpecifier { listAppend(s) } - | s:typeSpecifier @{ specified++ } { listAppend(s) } -#| | s:typedefName &{ !specified++ } { listAppend(s) } -#| | s:typeQualifier { listAppend(s) } + ( s:storageClassSpecifier { listAppend(s) } + | s:typeSpecifier @{ specified++ } { listAppend(s) } +#| | s:typedefName &{ !specified++ } { listAppend(s) } +#| | s:typeQualifier { listAppend(s) } #| | s:functionSpecifier { listAppend(s) } - )+ { $$= listEnd() } - | &{gnu} { $$= listEmpty() } + )+ { $$= listEnd() } + | &{gnu} { $$= listEmpty() } -#|initDeclaratorListOpt = initDeclaratorList | { $$= 0 } -initDeclaratorListOpt = { $$= listEmpty() } +initDeclaratorListOpt = initDeclaratorList | { $$= listEmpty() } +#|initDeclaratorListOpt = { $$= listEmpty() } -#|initDeclaratorList = d:initDeclarator { listWith(d) } -#| ( c:COMMA d:initDeclarator { listAppend2(c, d) } -#| )* { $$= listEnd() } -#| -#|initDeclarator = d:declarator -#| ( a:ASSIGN i:initializer { d= newBinary(d, a, i) } -#| )? { $$= d } -#| -#|# 6.7.1 +initDeclaratorList = d:initDeclarator { listWith(d) } + ( c:COMMA d:initDeclarator { listAppend2(c, d) } + )* { $$= listEnd() } + +initDeclarator = d:declarator + ( a:ASSIGN i:initializer { d= new_C_binary(d, a, i) } + )? { $$= d } + +# 6.7.1 storageClassSpecifier = TYPEDEF @{ declarationTypedef() } | AUTO -#| | parameterStorageClassSpecifier -#| | functionStorageClassSpecifier -#| -#|parameterStorageClassSpecifier = REGISTER -#| -#|functionStorageClassSpecifier = EXTERN | STATIC -#| -#|# 6.7.2 + | parameterStorageClassSpecifier + | functionStorageClassSpecifier + +parameterStorageClassSpecifier = REGISTER + +functionStorageClassSpecifier = EXTERN | STATIC + +# 6.7.2 typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UNSIGNED | BOOL | COMPLEX #| | structOrUnionSpecifier @@ -1059,18 +1359,18 @@ typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UN #| # An attribute specifier list may appear as part of a struct, union or enum specifier. It may go #| # either immediately after the struct, union or enum keyword... #| ( a:attributeSpecifiers &{gnu} | {a=0} ) -#| ( i:idOpt ( @{ scopeBegin() } +#| ( i:idOpt ( @{ C_scopeBegin() } #| l:LCURLY d:structDeclarationList r:RCURLY -#| @{ scopeEnd() } -#| | &{ scopeAbort() } +#| @{ C_scopeEnd() } +#| | &{ C_scopeAbort() } #| ) #| # ..., or after the closing brace. #| ( b:attributeSpecifiers &{gnu} | {b=0} ) #| | i:id {l=d=r=b=0} #| ) { $$= newStructSpec(s, a, i, l, d, r, b) } -#| -#|structOrUnion = STRUCT | UNION -#| + +structOrUnion = STRUCT | UNION + #|structDeclarationList = d:structDeclaration { listWith(d) } #| ( d:structDeclaration { listAppend(d) } #| )* { $$= listEnd() } @@ -1080,15 +1380,15 @@ typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UN #| ( &SEMI { listWith(t) } #| ( t:SEMI { listAppend(t) } #| )* &{gnu} { t= listEnd() } -#| )? { $$= newDeclaration(s, d, t) } -#| -#|specifierQualifierList = @{ int specified= 0 } { listBegin() } -#| ( ( t:typeSpecifier @{ specified++ } -#| | t:typedefName &{ !specified++ } -#| | t:typeQualifier -#| ) { listAppend(t) } -#| )+ { $$= listEnd() } -#| +#| )? { $$= new_C_declaration(s, d, t) } + +specifierQualifierList = @{ int specified= 0 } { listBegin() } + ( ( t:typeSpecifier @{ specified++ } + | t:typedefName &{ !specified++ } + | t:typeQualifier + ) { listAppend(t) } + )+ { $$= listEnd() } + #|structDeclaratorList = d:structDeclarator { listWith(d) } #| ( c:COMMA d:structDeclarator { listAppend2(c, d) } #| )* { $$= listEnd() } @@ -1121,199 +1421,199 @@ typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UN #| )* #| ( a:ASSIGN e:constantExpression | {a=e=0} ) { $$= newEnumerator(i, a, e) } #| -#|# 6.7.3 -#| -#|typeQualifier = CONST | RESTRICT | VOLATILE -#| -#|# 6.7.4 -#| -#|functionSpecifier = INLINE -#| -#|# 6.7.5 -#| -#|declarator = # An attribute specifier list may appear immediately before a declarator -#| a:attributeSpecifier d:declarator &{gnu} { $$= newAttribution(a, d) } -#| | p:STAR q:typeQualifierList d:declarator { $$= newDeref(p, q, d) } -#| | p:BXOR q:typeQualifierList d:declarator &{apl} { $$= newBlock(p, q, d) } -#| | ( d:directDeclarator -#| # An attribute specifier list may appear immediately before the comma, = or semicolon terminating the declaration of an identifier -#| ( &{gnu} a:attributeSpecifier { d= newAttribution(d, a) } -#| # an asm (or __asm__) keyword may appear after the declarator -#| | &{gnu} a:asm { d= newAttribution(d, a) } -#| )* -#| ) { $$= d } -#| -#|directDeclarator = ( l:LPAREN d:declarator r:RPAREN { d= newSubexpr(l, d, r) } -#| | &( @{ declarationId(yytext) } ) -#| d:id -#| ) ( @{ scopeBegin() } -#| ( l:LPAREN p:parameterTypeList r:RPAREN { d= newCall (d, l, p, r) } -#| @{ scopeEnd() } -#| | l:LPAREN p:identifierListOpt r:RPAREN { d= newCall (d, l, p, r) } -#| @{ scopeEnd() } -#| | l:LBRACKET ( s:STATIC q:typeQualifierListOpt {t=0} e:assignmentExpression -#| | {s=0} q:typeQualifierList t:STATIC e:assignmentExpressionOpt -#| | {s=0} q:typeQualifierListOpt t:STAR {e=0} -#| | {s=0} q:typeQualifierListOpt {t=0} e:assignmentExpressionOpt ) r:RBRACKET { d= newArray(d, l, s, q, t, e, r) } -#| @{ scopeEnd() } -#| | &{ scopeAbort() } -#| ) -#| )* { $$= d } -#| -#|typeQualifierListOpt = typeQualifierList | {$$=0} -#| -#|typeQualifierList = { listBegin() } -#| ( t:typeQualifier { listAppend(t) } -#| )* { $$= listEnd() } -#| -#|parameterTypeListOpt = parameterTypeList | {$$=0} -#| -#|parameterTypeList = p:parameterList -#| ( c:COMMA v:ELLIPSIS { List_addLast(p, c); List_addLast(p, v) } -#| )? { $$= p } -#| -#|parameterList = p:parameterDeclaration { listWith(p) } -#| ( ( c:COMMA | c:SEMI &{gnu} ) { listAppend(c) } -#| p:parameterDeclaration { listAppend(p) } -#| )* { $$= listEnd() } -#| -#|parameterDeclaration = s:parameterDeclarationSpecifiers -#| ( d:declarator | d:abstractDeclaratorOpt ) { $$= newParameter(s, d) } -#| -#|parameterDeclarationSpecifiers -#| = @{ int specified= 0 } { listBegin() } -#| ( s:parameterStorageClassSpecifier { listAppend(s) } -#| | s:typeSpecifier @{ specified++ } { listAppend(s) } -#| | s:typedefName &{ !specified++ } { listAppend(s) } -#| | s:typeQualifier { listAppend(s) } -#| | s:functionSpecifier { listAppend(s) } -#| )+ { $$= listEnd() } -#| -#|identifierListOpt = identifierList | {$$=0} -#| -#|identifierList = i:id { listWith(i) } -#| ( c:COMMA i:id { listAppend2(c, i) } -#| )* { $$= listEnd() } -#| +# 6.7.3 + +typeQualifier = CONST | RESTRICT | VOLATILE + +# 6.7.4 + +functionSpecifier = INLINE + +# 6.7.5 + +declarator = # An attribute specifier list may appear immediately before a declarator + a:attributeSpecifier d:declarator &{gnu} { $$= new_C_attribution(a, d) } + | p:STAR q:typeQualifierList d:declarator { $$= new_C_deref(p, q, d) } + | p:BXOR q:typeQualifierList d:declarator &{apl} { $$= new_C_block(p, q, d) } + | ( d:directDeclarator + # An attribute specifier list may appear immediately before the comma, = or semicolon terminating the declaration of an identifier + ( &{gnu} a:attributeSpecifier { d= new_C_attribution(d, a) } + # an asm (or __asm__) keyword may appear after the declarator + | &{gnu} a:asm { d= new_C_attribution(d, a) } + )* + ) { $$= d } + +directDeclarator = ( l:LPAREN d:declarator r:RPAREN { d= new_C_subexpr(l, d, r) } + | &( @{ declarationId(yytext) } ) + d:id + ) ( @{ C_scopeBegin() } + ( l:LPAREN p:parameterTypeList r:RPAREN { d= new_C_call (d, l, p, r) } + @{ C_scopeEnd() } + | l:LPAREN p:identifierListOpt r:RPAREN { d= new_C_call (d, l, p, r) } + @{ C_scopeEnd() } + | l:LBRACKET ( s:STATIC q:typeQualifierListOpt {t=0} e:assignmentExpression + | {s=0} q:typeQualifierList t:STATIC e:assignmentExpressionOpt + | {s=0} q:typeQualifierListOpt t:STAR {e=0} + | {s=0} q:typeQualifierListOpt {t=0} e:assignmentExpressionOpt ) r:RBRACKET { d= new_C_array(d, l, s, q, t, e, r) } + @{ C_scopeEnd() } + | &{ C_scopeAbort() } + ) + )* { $$= d } + +typeQualifierListOpt = typeQualifierList | {$$=0} + +typeQualifierList = { listBegin() } + ( t:typeQualifier { listAppend(t) } + )* { $$= listEnd() } + +parameterTypeListOpt = parameterTypeList | {$$=0} + +parameterTypeList = p:parameterList + ( c:COMMA v:ELLIPSIS { List_addLast(p, c); List_addLast(p, v) } + )? { $$= p } + +parameterList = p:parameterDeclaration { listWith(p) } + ( ( c:COMMA | c:SEMI &{gnu} ) { listAppend(c) } + p:parameterDeclaration { listAppend(p) } + )* { $$= listEnd() } + +parameterDeclaration = s:parameterDeclarationSpecifiers + ( d:declarator | d:abstractDeclaratorOpt ) { $$= new_C_parameter(s, d) } + +parameterDeclarationSpecifiers + = @{ int specified= 0 } { listBegin() } + ( s:parameterStorageClassSpecifier { listAppend(s) } + | s:typeSpecifier @{ specified++ } { listAppend(s) } + | s:typedefName &{ !specified++ } { listAppend(s) } + | s:typeQualifier { listAppend(s) } + | s:functionSpecifier { listAppend(s) } + )+ { $$= listEnd() } + +identifierListOpt = identifierList | {$$=0} + +identifierList = i:id { listWith(i) } + ( c:COMMA i:id { listAppend2(c, i) } + )* { $$= listEnd() } + #|# 6.7.6 #| -#|typeName = s:specifierQualifierList d:abstractDeclaratorOpt { $$= newDeclaration(s, d, 0) } -#| -#|abstractDeclaratorOpt = abstractDeclarator | {$$=0} -#| -#|abstractDeclarator = p:STAR q:typeQualifierList d:abstractDeclaratorOpt { $$= newDeref(p, q, d) } -#| | p:BXOR q:typeQualifierList d:abstractDeclaratorOpt &{apl} { $$= newBlock(p, q, d) } -#| | directAbstractDeclarator -#| -#|directAbstractDeclarator= @{int nonEmpty= 0} -#| ( l:LPAREN d:abstractDeclarator r:RPAREN @{++nonEmpty} { d= newSubexpr(l, d, r) } -#| | {d=0} -#| ) ( l:LPAREN p:parameterTypeListOpt r:RPAREN @{++nonEmpty} { d= newCall (d, l, p, r) } -#| | l:LBRACKET -#| ( s:STATIC q:typeQualifierListOpt {t=0} e:assignmentExpression -#| | {s=0} q:typeQualifierList t:STATIC e:assignmentExpressionOpt -#| | {s=0} q:typeQualifierListOpt t:STAR {e=0} -#| | {s=0} q:typeQualifierListOpt {t=0} e:assignmentExpressionOpt -#| ) r:RBRACKET @{++nonEmpty} { d= newArray(d, l, s, q, t, e, r) } -#| )* &{nonEmpty} { $$= d } -#| -#|# 6.7.7 -#| -#|typedefName = &{ isTypedefName(yytext) } { $$= newId(yytext) } - -#| | t:TYPEOF l:LPAREN -#| ( x:expression r:RPAREN { $$= newTypeof(t, l, 0, x, r) } -#| | x:typeName r:RPAREN { $$= newTypeof(t, l, x, 0, r) } -#| ) &{gnu} -#| -#|# 6.7.8 -#| -#|initializer = l:LCURLY i:initializerList ( c:COMMA | {c=0} ) r:RCURLY { $$= newInitializer(l, i, c, r) } -#| | assignmentExpression -#| -#|initializerList = { listBegin() } -#| ( d:designation { listAppend(d) } -#| )? i:initializer { listAppend(i) } -#| ( c:COMMA { listAppend(c) } -#| ( d:designation { listAppend(d) } -#| )? i:initializer { listAppend(i) } -#| )* { $$= listEnd() } -#| | &{gnu} { $$= 0 } -#| -#|designation = ( d:designatorList ( a:ASSIGN | {a=0} &{gnu} ) -#| | d:id a:COLON &{gnu} -#| ) { $$= newDesignation(d, a) } -#| -#|designatorList = { listBegin() } -#| ( l:LBRACKET x:constantExpression r:RBRACKET { listAppend(newIndex(0, l, x, r)) } -#| | l:LBRACKET x:constantRange r:RBRACKET &{gnu} { listAppend(newIndex(0, l, x, r)) } -#| | l:DOT x:id { listAppend(newBinary(0, l, x)) } -#| )+ { $$= listEnd() } -#| -#|### A.2.3 Statements -#| -#|# 6.8 -#| -#|statement = expressionStatement -#| | labeledStatement -#| | compoundStatement -#| | selectionStatement -#| | iterationStatement -#| | jumpStatement -#| -#|# 6.8.1 -#| -#|labeledStatement = i:id c:COLON -#| # an attribute specifier list may appear after the colon following a label, other than a case or default label -#| ( a:attributeSpecifiers &{gnu} | {a=0} ) -#| s:statement { $$= newLabel(i, c, a, s) } -#| | c:CASE x:constantExpression d:COLON s:statement { $$= newCase(c, x, d, s) } -#| | c:CASE x:constantRange d:COLON s:statement &{gnu} { $$= newCase(c, x, d, s) } -#| | d:DEFAULT c:COLON s:statement { $$= newDefault(d, c, s) } -#| -#|# 6.8.2 -#| -#|compoundStatement = @{ scopeBegin() } -#| l:LCURLY { listBegin() } -#| ( x:localLabelDeclaration &{gnu} { listAppend(x) } -#| )* -#| ( x:declaration { listAppend(x) } -#| | x:statement { listAppend(x) } -#| | x:functionDefinition &{gnu} { listAppend(x) } -#| | !'}' &{ errmsg= "statement expected" } error -#| )* { x= listEnd() } -#| r:RCURLY { $$= newCompound(l, x, r) } -#| @{ scopeEnd() } -#| | &{ scopeAbort() } -#| -#|# 6.8.3 -#| -#|expressionStatement = SEMI -#| | x:expression s:SEMI { $$= newExprStatement(x, s) } -#| -#|# 6.8.4 -#| -#|selectionStatement = i:IF l:LPAREN x:expression r:RPAREN s:statement -#| ( e:ELSE t:statement | {e=t=0} ) { $$= newIf(i, l, x, r, s, e, t) } -#| | s:SWITCH l:LPAREN x:expression r:RPAREN t:statement { $$= newSwitch(s, l, x, r, t) } -#| -#|# 6.8.5 -#| -#|iterationStatement = w:WHILE l:LPAREN x:expression r:RPAREN s:statement { $$= newWhile(w, l, x, r, s) } -#| | d:DO s:statement w:WHILE l:LPAREN x:expression r:RPAREN t:SEMI { $$= newDo(d, s, w, l, x, r, t) } -#| | f:FOR l:LPAREN a:expressionOpt t:SEMI b:expressionOpt u:SEMI -#| c:expressionOpt r:RPAREN s:statement { $$= newFor(f, l, a, t, b, u, c, r, s) } -#| | f:FOR l:LPAREN a:declaration b:expressionOpt u:SEMI -#| c:expressionOpt r:RPAREN s:statement { $$= newFor(f, l, a, 0, b, u, c, r, s) } -#| -#|# 6.8.6 -#| -#|jumpStatement = g:GOTO i:id t:SEMI { $$= newGoto(g, 0, i, t) } -#| | c:CONTINUE t:SEMI { $$= newContinue(c, t) } -#| | b:BREAK t:SEMI { $$= newBreak(b, t) } -#| | r:RETURN x:expressionOpt t:SEMI { $$= newReturn(r, x, t) } -#| | g:GOTO s:STAR x:expression t:SEMI &{gnu} { $$= newGoto(g, s, x, t) } -#| -#|### A.2.4 External definitions +typeName = s:specifierQualifierList d:abstractDeclaratorOpt { $$= new_C_declaration(s, d, 0) } + +abstractDeclaratorOpt = abstractDeclarator | {$$=0} + +abstractDeclarator = p:STAR q:typeQualifierList d:abstractDeclaratorOpt { $$= new_C_deref(p, q, d) } + | p:BXOR q:typeQualifierList d:abstractDeclaratorOpt &{apl} { $$= new_C_block(p, q, d) } + | directAbstractDeclarator + +directAbstractDeclarator= @{int nonEmpty= 0} + ( l:LPAREN d:abstractDeclarator r:RPAREN @{++nonEmpty} { d= new_C_subexpr(l, d, r) } + | {d=0} + ) ( l:LPAREN p:parameterTypeListOpt r:RPAREN @{++nonEmpty} { d= new_C_call (d, l, p, r) } + | l:LBRACKET + ( s:STATIC q:typeQualifierListOpt {t=0} e:assignmentExpression + | {s=0} q:typeQualifierList t:STATIC e:assignmentExpressionOpt + | {s=0} q:typeQualifierListOpt t:STAR {e=0} + | {s=0} q:typeQualifierListOpt {t=0} e:assignmentExpressionOpt + ) r:RBRACKET @{++nonEmpty} { d= new_C_array(d, l, s, q, t, e, r) } + )* &{nonEmpty} { $$= d } + +# 6.7.7 + +typedefName = &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } - + | t:TYPEOF l:LPAREN + ( x:expression r:RPAREN { $$= new_C_typeOf(t, l, 0, x, r) } + | x:typeName r:RPAREN { $$= new_C_typeOf(t, l, x, 0, r) } + ) &{gnu} + +# 6.7.8 + +initializer = l:LCURLY i:initializerList ( c:COMMA | {c=0} ) r:RCURLY { $$= new_C_initializer(l, i, c, r) } + | assignmentExpression + +initializerList = { listBegin() } + ( d:designation { listAppend(d) } + )? i:initializer { listAppend(i) } + ( c:COMMA { listAppend(c) } + ( d:designation { listAppend(d) } + )? i:initializer { listAppend(i) } + )* { $$= listEnd() } + | &{gnu} { $$= 0 } + +designation = ( d:designatorList ( a:ASSIGN | {a=0} &{gnu} ) + | d:id a:COLON &{gnu} + ) { $$= new_C_designation(d, a) } + +designatorList = { listBegin() } + ( l:LBRACKET x:constantExpression r:RBRACKET { listAppend(new_C_index(0, l, x, r)) } + | l:LBRACKET x:constantRange r:RBRACKET &{gnu} { listAppend(new_C_index(0, l, x, r)) } + | l:DOT x:id { listAppend(new_C_binary(0, l, x)) } + )+ { $$= listEnd() } + +### A.2.3 Statements + +# 6.8 + +statement = expressionStatement + | labeledStatement + | compoundStatement + | selectionStatement + | iterationStatement + | jumpStatement + +# 6.8.1 + +labeledStatement = i:id c:COLON + # an attribute specifier list may appear after the colon following a label, other than a case or default label + ( a:attributeSpecifiers &{gnu} | {a=0} ) + s:statement { $$= new_C_label(i, c, a, s) } + | c:CASE x:constantExpression d:COLON s:statement { $$= 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) } + +# 6.8.2 + +compoundStatement = @{ C_scopeBegin() } + l:LCURLY { listBegin() } + ( x:localLabelDeclaration &{gnu} { listAppend(x) } + )* + ( x:declaration { listAppend(x) } + | x:statement { listAppend(x) } + | x:functionDefinition &{gnu} { listAppend(x) } + | !'}' &{ errmsg= "statement expected" } error + )* { x= listEnd() } + r:RCURLY { $$= new_C_compound(l, x, r) } + @{ C_scopeEnd() } + | &{ C_scopeAbort() } + +# 6.8.3 + +expressionStatement = SEMI + | x:expression s:SEMI { $$= new_C_exprStatement(x, s) } + +# 6.8.4 + +selectionStatement = i:IF l:LPAREN x:expression r:RPAREN s:statement + ( e:ELSE t:statement | {e=t=0} ) { $$= 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) } + +# 6.8.5 + +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) } + | f:FOR l:LPAREN a:expressionOpt t:SEMI b:expressionOpt u:SEMI + c:expressionOpt r:RPAREN s:statement { $$= new_C_for(f, l, a, t, b, u, c, r, s) } + | f:FOR l:LPAREN a:declaration b:expressionOpt u:SEMI + c:expressionOpt r:RPAREN s:statement { $$= new_C_for(f, l, a, 0, b, u, c, r, s) } + +# 6.8.6 + +jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, 0, i, t) } + | c:CONTINUE t:SEMI { $$= new_C_continue(c, t) } + | b:BREAK t:SEMI { $$= new_C_break(b, 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) } + +### A.2.4 External definitions #| #|# 6.9 #| @@ -1328,110 +1628,110 @@ externalDeclaration = { yylval = newComment(yytext); } | &. &{ errmsg= "declaration expected" } error ) { yylval= $$; } -#|functionDefinition = @{ declarationBegin() } -#| ( s:functionDeclarationSpecifiers | &{gnu} {s=0} ) -#| d:declarator -#| l:declarationListOpt -#| c:compoundStatement { $$= newFunctionDefinition(s, d, l, c) } -#| @{ declarationEnd() } -#| | &{ declarationAbort() } -#| -#|functionDeclarationSpecifiers -#| = @{ int specified= 0 } { listBegin() } -#| ( s:functionStorageClassSpecifier { listAppend(s) } -#| | s:typeSpecifier @{ ++specified } { listAppend(s) } -#| | &{ !specified } s:typedefName @{ ++specified } { listAppend(s) } -#| | s:typeQualifier { listAppend(s) } -#| | s:functionSpecifier { listAppend(s) } -#| )+ { $$= listEnd() } -#| -#|declarationListOpt = declarationList | {$$=0} -#| -#|declarationList = d:declaration { $$= listWith(d) } -#| ( d:declaration { listAppend(d) } -#| )* { $$= listEnd() } -#| -#|### GNU C extensions -#| -#|# An attribute specifier is of the form __attribute__ ((attribute-list)). An attribute list is a -#|# possibly empty comma-separated sequence of attributes -#| -#|attributeSpecifier = a:ATTRIBUTE ll:LPAREN lr:LPAREN { listBegin() } -#| ( b:attribute { listAppend(b) } -#| )? ( c:COMMA { listAppend(c) } -#| ( b:attribute { listAppend(b) } -#| )? )* rl:RPAREN rr:RPAREN { $$= newAttributeSpec(a, ll, lr, listEnd(), rl, rr) } -#| -#|attributeSpecifiers = &ATTRIBUTE { listBegin() } -#| a:attributeSpecifier { listAppend(a) } -#| ( a:attributeSpecifier { listAppend(a) } -#| )* { $$= listEnd() } -#| -#|# where each attribute is one of the following: -#|# Empty. Empty attributes are ignored. -#|# An attribute name (which may be an identifier such as unused, or a reserved word such as const). -#|# An attribute name followed by a parenthesized list of parameters for the attribute. These parameters take one of the following forms: -#|# An identifier. For example, mode attributes use this form. -#|# An identifier followed by a comma and a non-empty comma-separated list of expressions. For example, format attributes use this form. -#|# A possibly empty comma-separated list of expressions. For example, format_arg attributes use this -#|# form with the list being a single integer constant expression, and alias attributes use -#|# this form with the list being a single string constant. -#| -#|attribute = n:name ( l:LPAREN { listBegin() } -#| ( p:expression { listAppend(p) } -#| ( p:COMMA { listAppend(p) } -#| p:expression { listAppend(p) } -#| )* -#| )? -#| r:RPAREN { p= listEnd() } -#| | {l=p=r=0} -#| ) { $$= newAttribute(n, l, p, r) } -#| -#|constantRange = a:constantExpression e:ELLIPSIS b:constantExpression { $$= newRange(a, e, b) } -#| -#|localLabelDeclaration = l:LABEL &{gnu} { listBegin() } -#| i:id { listAppend(i) } -#| ( c:COMMA i:id { listAppend2(c, i) } -#| )* -#| ( c:COMMA { listAppend(c) } -#| )? -#| s:SEMI { $$= newLabelDeclaration(l, listEnd(), s) } -#| -#|asm = a:ASM l:LPAREN s:stringLiteral r:RPAREN { $$= newAsm(a, l, s, r) } -#| -#|asmExpr = a:ASM ( v:VOLATILE | {v=0} ) ( g:GOTO | {g=0} ) -#| l:LPAREN s:stringLiteral { listBegin() } -#| ( c:COLON { listAppend(c) } -#| ( p:asmExprArgs { listAppend(p) } -#| )? -#| ( c:COLON { listAppend(c) } -#| ( p:asmExprArgs { listAppend(p) } -#| )? -#| ( c:COLON { listAppend(c) } -#| ( p:stringLiteralList { listAppend(p) } -#| )? -#| ( c:COLON { listAppend(c) } -#| ( p:ids { listAppend(p) } -#| )? -#| )? -#| )? -#| )? -#| )? -#| r:RPAREN { $$= newAsmExpr(a, v, g, l, s, listEnd(), r) } -#| -#|asmExprArgs = a:asmExprArg { listWith(a) } -#| ( c:COMMA a:asmExprArg { listAppend2(c, a) } -#| )* { $$= listEnd() } -#| -#|asmExprArg = s:stringLiteral ( l:LPAREN e:expression r:RPAREN | {l=e=r=0} ){ $$= newAsmExprArg(s, l, e, r) } -#| -#|stringLiteralList = s:stringLiteral { listWith(s) } -#| ( c:COMMA s:stringLiteral { listAppend2(c, s) } -#| )* { $$= listEnd() } -#| -#|ids = i:id { listWith(i) } -#| ( c:COMMA i:id { listAppend2(c, i) } -#| )* { $$= listEnd() } +functionDefinition = @{ C_declarationBegin() } + ( s:functionDeclarationSpecifiers | &{gnu} {s=0} ) + d:declarator + l:declarationListOpt + c:compoundStatement { $$= new_C_functionDef(s, d, l, c) } + @{ C_declarationEnd() } + | &{ C_declarationAbort() } + +functionDeclarationSpecifiers + = @{ int specified= 0 } { listBegin() } + ( s:functionStorageClassSpecifier { listAppend(s) } + | s:typeSpecifier @{ ++specified } { listAppend(s) } + | &{ !specified } s:typedefName @{ ++specified } { listAppend(s) } + | s:typeQualifier { listAppend(s) } + | s:functionSpecifier { listAppend(s) } + )+ { $$= listEnd() } + +declarationListOpt = declarationList | {$$=0} + +declarationList = d:declaration { listWith(d); //TODO $$= listWith(d) } + ( d:declaration { listAppend(d) } + )* { $$= listEnd() } + +### GNU C extensions + +# An attribute specifier is of the form __attribute__ ((attribute-list)). An attribute list is a +# possibly empty comma-separated sequence of attributes + +attributeSpecifier = a:ATTRIBUTE ll:LPAREN lr:LPAREN { listBegin() } + ( b:attribute { listAppend(b) } + )? ( c:COMMA { listAppend(c) } + ( b:attribute { listAppend(b) } + )? )* rl:RPAREN rr:RPAREN { $$= new_C_attributeSpec(a, ll, lr, listEnd(), rl, rr) } + +attributeSpecifiers = &ATTRIBUTE { listBegin() } + a:attributeSpecifier { listAppend(a) } + ( a:attributeSpecifier { listAppend(a) } + )* { $$= listEnd() } + +# where each attribute is one of the following: +# Empty. Empty attributes are ignored. +# An attribute name (which may be an identifier such as unused, or a reserved word such as const). +# An attribute name followed by a parenthesized list of parameters for the attribute. These parameters take one of the following forms: +# An identifier. For example, mode attributes use this form. +# An identifier followed by a comma and a non-empty comma-separated list of expressions. For example, format attributes use this form. +# A possibly empty comma-separated list of expressions. For example, format_arg attributes use this +# form with the list being a single integer constant expression, and alias attributes use +# this form with the list being a single string constant. + +attribute = n:name ( l:LPAREN { listBegin() } + ( p:expression { listAppend(p) } + ( p:COMMA { listAppend(p) } + p:expression { listAppend(p) } + )* + )? + r:RPAREN { p= listEnd() } + | {l=p=r=0} + ) { $$= new_C_attribute(n, l, p, r) } + +constantRange = a:constantExpression e:ELLIPSIS b:constantExpression { $$= new_C_range(a, e, b) } + +localLabelDeclaration = l:LABEL &{gnu} { listBegin() } + i:id { listAppend(i) } + ( c:COMMA i:id { listAppend2(c, i) } + )* + ( c:COMMA { listAppend(c) } + )? + s:SEMI { $$= new_C_labelDeclaration(l, listEnd(), s) } + +asm = a:ASM l:LPAREN s:stringLiteral r:RPAREN { $$= new_C_asm(a, l, s, r) } + +asmExpr = a:ASM ( v:VOLATILE | {v=0} ) ( g:GOTO | {g=0} ) + l:LPAREN s:stringLiteral { listBegin() } + ( c:COLON { listAppend(c) } + ( p:asmExprArgs { listAppend(p) } + )? + ( c:COLON { listAppend(c) } + ( p:asmExprArgs { listAppend(p) } + )? + ( c:COLON { listAppend(c) } + ( p:stringLiteralList { listAppend(p) } + )? + ( c:COLON { listAppend(c) } + ( p:ids { listAppend(p) } + )? + )? + )? + )? + )? + r:RPAREN { $$= new_C_asmExpr(a, v, g, l, s, listEnd(), r) } + +asmExprArgs = a:asmExprArg { listWith(a) } + ( c:COMMA a:asmExprArg { listAppend2(c, a) } + )* { $$= listEnd() } + +asmExprArg = s:stringLiteral ( l:LPAREN e:expression r:RPAREN | {l=e=r=0} ){ $$= new_C_asmExprArg(s, l, e, r) } + +stringLiteralList = s:stringLiteral { listWith(s) } + ( c:COMMA s:stringLiteral { listAppend2(c, s) } + )* { $$= listEnd() } + +ids = i:id { listWith(i) } + ( c:COMMA i:id { listAppend2(c, i) } + )* { $$= listEnd() } - = < Space* > { if (yyleng && $$) setComment($$, newComment(yytext)) } @@ -2630,16 +2930,6 @@ void outputText(char *text) ocol += strlen(text); } -void outputInt(int_t value) -{ - ocol += printf(FMT_I, value); -} - -void outputFloat(flt_t value) -{ - ocol += printf(FMT_F, value); -} - void outputNode(oop node) { if (!node) return; @@ -2651,12 +2941,6 @@ void outputNode(oop node) return; case Map: break; - case Integer: - outputInt(getInteger(node)); - return; - case Float: - outputFloat(getFloat(node)); - return; case Symbol: outputText(get(node, Symbol, name)); return; @@ -2695,11 +2979,6 @@ void outputNode(oop node) case t_C_id: outputNode(map_get(node, identifier_symbol)); break; - case t_C_declaration: - outputNode(map_get(node, specifiers_symbol)); - outputNode(map_get(node, declarators_symbol)); - outputNode(map_get(node, semicolon_symbol)); - break; case t_C_if: outputNode(map_get(node, if_symbol)); outputNode(map_get(node, lparen_symbol)); @@ -2736,11 +3015,227 @@ void outputNode(oop node) outputNode(map_get(node, rparen_symbol)); outputNode(map_get(node, statements_symbol)); break; + case t_C_goto: + outputNode(map_get(node, gotoTok_symbol)); + outputNode(map_get(node, star_symbol)); + outputNode(map_get(node, name_symbol)); + outputNode(map_get(node, semicolon_symbol)); + break; + + case t_C_initializer: + outputNode(map_get(node, leftCurly_symbol)); + outputNode(map_get(node, initList_symbol)); + outputNode(map_get(node, comma_symbol)); + outputNode(map_get(node, rightCurly_symbol)); + break; + case t_C_range: + outputNode(map_get(node, constExpr1_symbol)); + outputNode(map_get(node, ellipsis_symbol)); + outputNode(map_get(node, constExpr2_symbol)); + break; + case t_C_switch: + outputNode(map_get(node, switchTok_symbol)); + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, rparen_symbol)); + outputNode(map_get(node, statements_symbol)); + break; + case t_C_case: + outputNode(map_get(node, caseTok_symbol)); + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, colon_symbol)); + outputNode(map_get(node, statements_symbol)); + break; + case t_C_default: + outputNode(map_get(node, defaultTok_symbol)); + outputNode(map_get(node, colon_symbol)); + outputNode(map_get(node, statements_symbol)); + break; + case t_C_attribution: + outputNode(map_get(node, specifiers_symbol)); + outputNode(map_get(node, declarators_symbol)); + break; + case t_C_deref: + outputNode(map_get(node, star_symbol)); + outputNode(map_get(node, typeQualList_symbol)); + outputNode(map_get(node, declarators_symbol)); + break; + case t_C_functionDef: + outputNode(map_get(node, specifiers_symbol)); + outputNode(map_get(node, declarators_symbol)); + outputNode(map_get(node, declarationL_symbol)); + outputNode(map_get(node, compoundS_symbol)); + break; + case t_C_sizeOf: + outputNode(map_get(node, sizeOfTok_symbol)); + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, typeName_symbol)); + outputNode(map_get(node, rparen_symbol)); + break; + case t_C_alignOf: + outputNode(map_get(node, alignOfTok_symbol)); + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, typeName_symbol)); + outputNode(map_get(node, rparen_symbol)); + break; + case t_C_prefix: + outputNode(map_get(node, operator_symbol)); + outputNode(map_get(node, expression_symbol)); + break; + case t_C_postfix: + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, operator_symbol)); + break; + case t_C_unary: + outputNode(map_get(node, operator_symbol)); + outputNode(map_get(node, expression_symbol)); + break; case t_C_binary: outputNode(map_get(node, lhs_symbol)); outputNode(map_get(node, binary_symbol)); outputNode(map_get(node, rhs_symbol)); break; + case t_C_compound: + outputNode(map_get(node, leftCurly_symbol)); + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, rightCurly_symbol)); + break; + case t_C_subexpr: + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, declarators_symbol)); + outputNode(map_get(node, rparen_symbol)); + break; + case t_C_call: + outputNode(map_get(node, declarators_symbol)); + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, paramTypeL_symbol)); + outputNode(map_get(node, rparen_symbol)); + break; + case t_C_array: + outputNode(map_get(node, declarators_symbol)); + outputNode(map_get(node, leftBracket_symbol)); + outputNode(map_get(node, static_symbol)); + outputNode(map_get(node, typeQualList_symbol)); + outputNode(map_get(node, dynamic_symbol)); + outputNode(map_get(node, assignExpr_symbol)); + outputNode(map_get(node, rightBracket_symbol)); + break; + case t_C_block: + outputNode(map_get(node, bxor_symbol)); + outputNode(map_get(node, typeQualList_symbol)); + outputNode(map_get(node, declarators_symbol)); + break; + case t_C_continue: + outputNode(map_get(node, continueTok_symbol)); + outputNode(map_get(node, semicolon_symbol)); + break; + case t_C_break: + outputNode(map_get(node, breakTok_symbol)); + outputNode(map_get(node, semicolon_symbol)); + break; + case t_C_return: + outputNode(map_get(node, returnTok_symbol)); + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, semicolon_symbol)); + break; + case t_C_exprStatement: + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, semicolon_symbol)); + break; + case t_C_asm: + outputNode(map_get(node, asmTok_symbol)); + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, text_symbol)); + outputNode(map_get(node, rparen_symbol)); + break; + case t_C_asmExpr: + outputNode(map_get(node, asmTok_symbol)); + outputNode(map_get(node, volatileTok_symbol)); + outputNode(map_get(node, gotoTok_symbol)); + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, text_symbol)); + outputNode(map_get(node, element_symbol)); + outputNode(map_get(node, lparen_symbol)); + break; + case t_C_asmExprArg: + outputNode(map_get(node, text_symbol)); + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, lparen_symbol)); + break; + case t_C_declaration: + outputNode(map_get(node, specifiers_symbol)); + outputNode(map_get(node, declarators_symbol)); + outputNode(map_get(node, semicolon_symbol)); + break; + case t_C_parameter: + outputNode(map_get(node, specifiers_symbol)); + outputNode(map_get(node, declarators_symbol)); + break; + case t_C_conditional: + outputNode(map_get(node, logicalOr_symbol)); + outputNode(map_get(node, question_symbol)); + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, colon_symbol)); + outputNode(map_get(node, condExpr_symbol)); + break; + case t_C_designation: + outputNode(map_get(node, identifier_symbol)); + outputNode(map_get(node, colon_symbol)); + break; + case t_C_index: + outputNode(map_get(node, primaryExpr_symbol)); + outputNode(map_get(node, leftBracket_symbol)); + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, rightBracket_symbol)); + break; + case t_C_typeOf: + outputNode(map_get(node, typeOfTok_symbol)); + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, typeName_symbol)); + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, rparen_symbol)); + break; + case t_C_cast: + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, typeName_symbol)); + outputNode(map_get(node, rparen_symbol)); + outputNode(map_get(node, expression_symbol)); + break; + case t_C_attributeSpec: + outputNode(map_get(node, attributeTok_symbol)); + outputNode(map_get(node, llparen_symbol)); + outputNode(map_get(node, lrparen_symbol)); + outputNode(map_get(node, attributeL_symbol)); + outputNode(map_get(node, rlparen_symbol)); + outputNode(map_get(node, rrparen_symbol)); + break; + case t_C_aggregate: + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, typeName_symbol)); + outputNode(map_get(node, rparen_symbol)); + outputNode(map_get(node, leftCurly_symbol)); + outputNode(map_get(node, initList_symbol)); + outputNode(map_get(node, comma_symbol)); + outputNode(map_get(node, rightCurly_symbol)); + break; + case t_C_attribute: + outputNode(map_get(node, text_symbol)); + outputNode(map_get(node, lparen_symbol)); + outputNode(map_get(node, expression_symbol)); + outputNode(map_get(node, rparen_symbol)); + break; + case t_C_label: + outputNode(map_get(node, name_symbol)); + outputNode(map_get(node, colon_symbol)); + outputNode(map_get(node, attributeL_symbol)); + outputNode(map_get(node, statements_symbol)); + break; + case t_C_labelDeclaration: + outputNode(map_get(node, labels_symbol)); + outputNode(map_get(node, element_symbol)); + outputNode(map_get(node, semicolon_symbol)); + break; default: printf("I cannot print a node with proto_number %i\n", proto_number); exit(0);