// compile: this is a skeleton that is built once from the final grammar,
// and modified by the programmer to do whatever the program needs to do.
//
// The baseline is simply to re-output the initial input, but obviously
// a real implementation would do something more complex, such as indentation
// and formatting (e.g. like SOAP), or conversion into another language
// such as C, or even to create a real compiler.
//
// If all you are doing is re-outputing the original source, this code is
// way overkill. A 20-line version would do the same job.
//
// You would typically *not* re-create this file automatically in your Makefile...
// Remember to edit this comment once you get to the stage where you are
// maintaining this procedure manually...
//
void compile(int astp) {
int i;
// These offsets are a poor man's struct:
// Offsets in the A record are different from offsets in the AST.
// A record offsets:
#define A_literal_offset 3
// AST offsets:
#define AST_op_offset 1
#define AST_alt_offset 2
#define AST_count_offset 3
// Any new fixed fields (such as a pointer to the text) would be inserted here.
// Please do not ever write code with absolute offsets!
#define AST_child0_offset 4
if (astp < 0) {
return; // -phrase denotes an optional item we don't want to print when reconstituting the source
// Not an ideal mechanism. May change it later to add optional bits to 'op' field.
}
int astop = AST[astp+AST_op_offset];
int alt = AST[astp+AST_alt_offset];
int count = AST[astp+AST_count_offset];
int *A_child = &AST[astp+AST_child0_offset]; // An index into a child of the AREC, *not* a child of the AST.
// Must use these macros for children of the AST, in case new fields are added.
#define leftchild(p) AST[(p)+AST_child0_offset+(1-1)]
#define rightchild(p) AST[(p)+AST_child0_offset+(2-1)]
#define nthchild(p,i) AST[(p)+AST_child0_offset+((i)-1)]
//\\ C<immediate> = {
//\\ // WARNING: currently parse-time phrases are not being handled properly
//\\ // by compile(). Are they set to -1 or skipped completely?
//\\ extern int *A; // remove as much of this as possible as soon as things start working again...
//\\ extern int cp; // code pointer. Has to be global state.
//\\ extern int ap; // Analysis record pointer.
//\\ int kw(int AST_op, int kw_idx, int ap) // kw(AST__KW, KW_void, A[ap+0]);
//\\
//\\ {
//\\ int data[3];
//\\
//\\ data[1] = kw_idx;
//\\
//\\ data[2] = ap;
//\\
//\\ return mktuple(B_keyword, 1, 2, data);
//\\
//\\ }
//\\ int check(int Aval, int *table);
//\\
//\\ int is_in_array(char *word, char **array, int max) {
//\\ int i;
//\\
//\\ for (i = 0; i < max; i++) {
//\\ if (strcmp(word, array[i]) == 0) return TRUE;
//\\
//\\ }
//\\ return FALSE;
//\\
//\\ }
//\\ // variables used in line_reconstruction() moved here so they are available to semantic code in grammar.
//\\ int saved = TRUE;
//\\
//\\ int at_startofline = TRUE;
//\\
//\\ };
switch (astop) {
case AST_char: //\\ B<char> = 0;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_internal_identifier: //\\ B<internal-identifier> = 1;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_integer_constant: //\\ B<integer-constant> = 2;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
//\\ # <character-constant> temporarily replaced by <sqstring>
//\\ # and <string> temporarily replaced by <dqstring>
//\\ # because parser.c TEMPORARILY assumes these exist in all parsers :-(
case AST_sqstring: //\\ B<sqstring> = 3;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_floating_constant: //\\ B<floating-constant> = 4;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_dqstring: //\\ B<dqstring> = 5;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_keyword: //\\ B<keyword> = 6;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_pp: //\\ B<pp> = 7;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_mm: //\\ B<mm> = 8;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_andand: //\\ B<andand> = 9;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_oror: //\\ B<oror> = 10;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_eqeq: //\\ B<eqeq> = 11;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
//\\ # char, NL, and EOF are required by all parsers
case AST_NL: //\\ B<NL> = 12;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST_EOF: //\\ B<EOF> = 13;
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
//\\ # top-level statement
case AST_identifier: //\\ P<identifier> =
if (alt == 0) { //\\ <!keyword-not-allowed-in-context-of-an-identifier> <internal-identifier>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # want to use keyword[] array from parser.h, but this will have to do for now
//\\ # until I can work out a clean mechanism using <immediate:...>
case AST_keyword_not_allowed_in_context_of_an_identifier://\\ P<keyword-not-allowed-in-context-of-an-identifier> =
if (alt == 0) { //\\ <immediate: return is_in_array(\"\", keyword, MAX_KEYWORD) ;>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_XXkeyword_not_allowed_in_context_of_an_identifier://\\ P<XXkeyword-not-allowed-in-context-of-an-identifier> =
if (alt == 0) { //\\ "if",
} else if (alt == 1) { //\\ "const",
} else if (alt == 2) { //\\ "struct",
} else if (alt == 3) { //\\ "union",
} else if (alt == 4) { //\\ "sizeof",
} else if (alt == 5) { //\\ "typeof",
} else if (alt == 6) { //\\ "double",
} else if (alt == 7) { //\\ "long",
} else if (alt == 8) { //\\ "char",
} else if (alt == 9) { //\\ "float",
} else if (alt == 10) { //\\ "void",
} else if (alt == 11) { //\\ "enum",
} else if (alt == 12) { //\\ "short",
} else if (alt == 13) { //\\ "int",
} else if (alt == 14) { //\\ "signed",
} else if (alt == 15) { //\\ "unsigned",
} else if (alt == 16) { //\\ "volatile",
} else if (alt == 17) { //\\ "auto",
} else if (alt == 18) { //\\ "register",
} else if (alt == 19) { //\\ "static",
} else if (alt == 20) { //\\ "extern",
} else if (alt == 21) { //\\ "goto",
} else if (alt == 22) { //\\ "continue",
} else if (alt == 23) { //\\ "break",
} else if (alt == 24) { //\\ "return",
} else if (alt == 25) { //\\ "while",
} else if (alt == 26) { //\\ "do",
} else if (alt == 27) { //\\ "for",
} else if (alt == 28) { //\\ "switch",
} else if (alt == 29) { //\\ "else",
} else if (alt == 30) { //\\ "case",
} else if (alt == 31) { //\\ "default",
} else if (alt == 32) { //\\ "typedef";
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_ignored: //\\ P<ignored> =
if (alt == 0) { //\\ <immediate:return FALSE;> ';';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_SS: //\\ P<SS> =
if (alt == 0) { //\\ <opt-external-declaration-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_external_declaration_list://\\ P<opt-external-declaration-list> =
if (alt == 0) { //\\ <external-declaration> <opt-external-declaration-list>,
} else if (alt == 1) { //\\ <EOF>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_external_declaration://\\ P<external-declaration> =
if (alt == 0) { //\\ <typedef-declaration> ';',
} else if (alt == 1) { //\\ <proc-fn-decl>,
} else if (alt == 2) { //\\ <possibly-initialised-scalar-or-array-decl>,
} else if (alt == 3) { //\\ <enum-specifier>,
} else if (alt == 4) { //\\ <struct-or-union-specifier>,
} else if (alt == 5) { //\\ ';';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # Oops - these can be initialised. Not yet done so.
//\\ #
case AST_struct_or_union_specifier://\\ P<struct-or-union-specifier> =
if (alt == 0) { //\\ <struct-or-union> <identifier> '{' <struct-field-declarations> '}',
} else if (alt == 1) { //\\ <struct-or-union> '{' <struct-field-declarations> '}',
} else if (alt == 2) { //\\ <struct-or-union> <identifier>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_struct_or_union: //\\ P<struct-or-union> =
if (alt == 0) { //\\ "struct",
} else if (alt == 1) { //\\ "union";
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_struct_field_declarations://\\ P<struct-field-declarations> =
if (alt == 0) { //\\ <struct-field-declaration> <rest-of-struct-field-declarations>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_struct_field_declarations://\\ P<rest-of-struct-field-declarations> =
if (alt == 0) { //\\ <struct-field-declaration> <rest-of-struct-field-declarations>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_struct_field_declaration://\\ P<struct-field-declaration> =
if (alt == 0) { //\\ <possibly-initialised-scalar-or-array-decl>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # I originally thought you could only initialise an array after a declaration
//\\ # that had '[]' in it. But not the case - a typedef'd declaration may have
//\\ # the array part in the typedef rather than the instance. Ugly language.
//\\ #
//\\ # Also we can have initialised structs :-/
//\\ #
case AST_possibly_initialised_scalar_or_array_decl://\\ P<possibly-initialised-scalar-or-array-decl> =
if (alt == 0) { //\\ <opt-auto-reg-static-ext> <opt-const-or-volatile-type-qualifier> <type> <rest-of-scalar-or-array-decl> ';';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # The <opt-scalar-init> part of function pointers is usually going to be "= &procname"... any other type of scalar is dubious...
case AST_rest_of_scalar_or_array_decl://\\ P<rest-of-scalar-or-array-decl> =
if (alt == 0) { //\\ <opt-indirection-decl> <identifier> <array-bounds> <opt-array-init> <opt-rest-of-scalar-or-array-decl>,
} else if (alt == 1) { //\\ <opt-indirection-decl> '(' <opt-indirection-decl> <identifier> ')' '(' <opt-param-list> ')' <opt-scalar-init> <opt-rest-of-scalar-or-array-decl>,
} else if (alt == 2) { //\\ <opt-indirection-decl> <identifier> <opt-scalar-init> <opt-rest-of-scalar-or-array-decl>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_rest_of_scalar_or_array_decl://\\ P<opt-rest-of-scalar-or-array-decl> =
if (alt == 0) { //\\ ',' <rest-of-scalar-or-array-decl>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_scalar_init: //\\ P<opt-scalar-init> =
if (alt == 0) { //\\ '=' <assignment-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_assignment_expression://\\ P<assignment-expression> =
if (alt == 0) { //\\ <opt-lvalue-assign> <conditional-expression> <opt-rest-of-assignment-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_rest_of_assignment_expression://\\ P<opt-rest-of-assignment-expression> =
if (alt == 0) { //\\ <assignment-operator> <conditional-expression> <opt-rest-of-assignment-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_conditional_expression://\\ P<conditional-expression> =
if (alt == 0) { //\\ <logical-or-expression> <rest-of-conditional-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_conditional_expression://\\ P<rest-of-conditional-expression> =
if (alt == 0) { //\\ '?' <expression> ':' <conditional-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_expression: //\\ P<expression> =
if (alt == 0) { //\\ <comma-statement>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_comma_statement: //\\ P<comma-statement> =
if (alt == 0) { //\\ <assignment-expression> <rest-of-comma-statement>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_comma_statement://\\ P<rest-of-comma-statement> =
if (alt == 0) { //\\ ',' <assignment-expression> <rest-of-comma-statement>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_logical_or_expression://\\ P<logical-or-expression> =
if (alt == 0) { //\\ <logical-and-expression> <rest-of-logical-or-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_logical_or_expression://\\ P<rest-of-logical-or-expression> =
if (alt == 0) { //\\ <oror> <logical-and-expression> <rest-of-logical-or-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_logical_and_expression://\\ P<logical-and-expression> =
if (alt == 0) { //\\ <inclusive-or-expression> <rest-of-logical-and-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_logical_and_expression://\\ P<rest-of-logical-and-expression> =
if (alt == 0) { //\\ <andand> <inclusive-or-expression> <rest-of-logical-and-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_inclusive_or_expression://\\ P<inclusive-or-expression> =
if (alt == 0) { //\\ <exclusive-or-expression> <rest-of-inclusive-or-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_inclusive_or_expression://\\ P<rest-of-inclusive-or-expression> =
if (alt == 0) { //\\ '|' <exclusive-or-expression> <rest-of-inclusive-or-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_exclusive_or_expression://\\ P<exclusive-or-expression> =
if (alt == 0) { //\\ <bitwise-and-expression> <rest-of-exclusive-or-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_exclusive_or_expression://\\ P<rest-of-exclusive-or-expression> =
if (alt == 0) { //\\ '^' <bitwise-and-expression> <rest-of-exclusive-or-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_bitwise_and_expression://\\ P<bitwise-and-expression> =
if (alt == 0) { //\\ <equality-expression> <rest-of-bitwise-and-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_bitwise_and_expression://\\ P<rest-of-bitwise-and-expression> =
if (alt == 0) { //\\ '&' <equality-expression> <rest-of-bitwise-and-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_equality_expression://\\ P<equality-expression> =
if (alt == 0) { //\\ <relational-expression> <rest-of-equality-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_equality_expression://\\ P<rest-of-equality-expression> =
if (alt == 0) { //\\ <eqop> <relational-expression> <rest-of-equality-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_relational_expression://\\ P<relational-expression> =
if (alt == 0) { //\\ <shift-expression> <rest-of-relational-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_relational_expression://\\ P<rest-of-relational-expression> =
if (alt == 0) { //\\ <relop> <shift-expression> <rest-of-relational-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_shift_expression: //\\ P<shift-expression> =
if (alt == 0) { //\\ <additive-expression> <rest-of-shift-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_shift_expression://\\ P<rest-of-shift-expression> =
if (alt == 0) { //\\ <shiftop> <additive-expression> <rest-of-shift-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_additive_expression://\\ P<additive-expression> =
if (alt == 0) { //\\ <multiplicative-expression> <rest-of-additive-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_additive_expression://\\ P<rest-of-additive-expression> =
if (alt == 0) { //\\ <plusminus> <multiplicative-expression> <rest-of-additive-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_multiplicative_expression://\\ P<multiplicative-expression> =
if (alt == 0) { //\\ <unary-rvalue-expression> <rest-of-multiplicative-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_multiplicative_expression://\\ P<rest-of-multiplicative-expression> =
if (alt == 0) { //\\ <mulop> <unary-rvalue-expression> <rest-of-multiplicative-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # my reading of the spec is that "sizeof" <type-specifier> is valid but "sizeof" '(' <type-specifier> ')' is not,
//\\ # however the latter appears to be accepted by gcc.
//\\ # Should we merge <type-specifier> with <opt-indirection-unary-ops>? Is <type-specifier> ever used without an optional '*' following?
case AST_unary_rvalue_expression://\\ P<unary-rvalue-expression> =
if (alt == 0) { //\\ <arithmetic-unary-op> <optionally-cast-unary-rvalue-expression>,
} else if (alt == 1) { //\\ <boolean-unary-ops> <optionally-cast-unary-rvalue-expression>,
} else if (alt == 2) { //\\ <bitwise-unary-ops> <optionally-cast-unary-rvalue-expression>,
} else if (alt == 3) { //\\ <indirection-unary-ops> <unary-address-expression>,
} else if (alt == 4) { //\\ "sizeof" <unary-rvalue-expression>,
} else if (alt == 5) { //\\ "sizeof" <unary-lvalue-expression>,
} else if (alt == 6) { //\\ "sizeof" <type-specifier> <opt-indirection-unary-ops>,
} else if (alt == 7) { //\\ "sizeof" '(' <type-specifier> <opt-indirection-unary-ops> ')',
} else if (alt == 8) { //\\ <optionally-cast-postfix-rvalue-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_optionally_cast_postfix_rvalue_expression://\\ P<optionally-cast-postfix-rvalue-expression> =
if (alt == 0) { //\\ <cast> <optionally-cast-postfix-rvalue-expression>,
} else if (alt == 1) { //\\ <postfix-rvalue-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_postfix_rvalue_expression://\\ P<postfix-rvalue-expression> =
if (alt == 0) { //\\ <primary-expression> <rest-of-postfix-rvalue-expression>,
} else if (alt == 1) { //\\ <unary-lvalue-expression> <rest-of-postfix-rvalue-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_postfix_rvalue_expression://\\ P<rest-of-postfix-rvalue-expression> =
if (alt == 0) { //\\ '[' <expression> ']' <rest-of-postfix-rvalue-expression>,
} else if (alt == 1) { //\\ '(' <actual-param-list> ')' <rest-of-postfix-rvalue-expression>,
} else if (alt == 2) { //\\ '.' <identifier> <rest-of-postfix-rvalue-expression>,
} else if (alt == 3) { //\\ '-' '>' <identifier> <rest-of-postfix-rvalue-expression>,
} else if (alt == 4) { //\\ <post-increment-op> <rest-of-postfix-rvalue-expression>,
} else if (alt == 5) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_post_increment_op: //\\ P<post-increment-op> =
if (alt == 0) { //\\ <pp>,
} else if (alt == 1) { //\\ <mm>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_actual_param_list: //\\ P<actual-param-list> =
if (alt == 0) { //\\ <assignment-expression> <rest-of-param-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_param_list: //\\ P<rest-of-param-list> =
if (alt == 0) { //\\ ',' <assignment-expression> <rest-of-param-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_unary_lvalue_expression://\\ P<unary-lvalue-expression> =
if (alt == 0) { //\\ <pre-increment-op> <unary-lvalue-expression>,
} else if (alt == 1) { //\\ <indirection-unary-ops> <optionally-cast-unary-lvalue-expression>,
} else if (alt == 2) { //\\ <unary-address-expression>,
} else if (alt == 3) { //\\ <postfix-lvalue-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_postfix_lvalue_expression://\\ P<postfix-lvalue-expression> =
if (alt == 0) { //\\ <primary-expression> <rest-of-postfix-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_postfix_expression://\\ P<rest-of-postfix-expression> =
if (alt == 0) { //\\ '[' <expression> ']' <rest-of-postfix-expression>,
} else if (alt == 1) { //\\ '(' <actual-param-list> ')' <non-empty-rest-of-postfix-expression>,
} else if (alt == 2) { //\\ '.' <identifier> <rest-of-postfix-expression>,
} else if (alt == 3) { //\\ '-' '>' <identifier> <rest-of-postfix-expression>,
} else if (alt == 4) { //\\ <post-increment-op> <rest-of-postfix-expression>,
} else if (alt == 5) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_non_empty_rest_of_postfix_expression://\\ P<non-empty-rest-of-postfix-expression> =
if (alt == 0) { //\\ '[' <expression> ']' <rest-of-postfix-expression>,
} else if (alt == 1) { //\\ '(' <actual-param-list> ')' <non-empty-rest-of-postfix-expression>,
} else if (alt == 2) { //\\ '.' <identifier> <rest-of-postfix-expression>,
} else if (alt == 3) { //\\ '-' '>' <identifier> <rest-of-postfix-expression>,
} else if (alt == 4) { //\\ <post-increment-op> <rest-of-postfix-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_primary_expression: //\\ P<primary-expression> =
if (alt == 0) { //\\ <identifier>,
} else if (alt == 1) { //\\ <constant>,
} else if (alt == 2) { //\\ <dqstring>,
} else if (alt == 3) { //\\ '(' <expression> ')';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_constant: //\\ P<constant> =
if (alt == 0) { //\\ <integer-constant>,
} else if (alt == 1) { //\\ <sqstring>,
} else if (alt == 2) { //\\ <floating-constant>,
} else if (alt == 3) { //\\ <enumeration-constant>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_enumeration_constant://\\ P<enumeration-constant> =
if (alt == 0) { //\\ <identifier>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_unary_address_expression://\\ P<unary-address-expression> =
if (alt == 0) { //\\ <address-operator> <optionally-cast-unary-lvalue-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_optionally_cast_unary_lvalue_expression://\\ P<optionally-cast-unary-lvalue-expression> =
if (alt == 0) { //\\ <cast> <optionally-cast-unary-lvalue-expression>,
} else if (alt == 1) { //\\ <unary-lvalue-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_cast: //\\ P<cast> =
if (alt == 0) { //\\ '(' <type-specifier> <opt-indirection-unary-ops> ')',
} else if (alt == 1) { //\\ '(' "typeof" '(' <unary-lvalue-expression> ')' ')',
} else if (alt == 2) { //\\ '(' "typeof" '(' <type-specifier> <opt-indirection-unary-ops> ')' ')';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # <opt-indirection-decl> looks just like <opt-indirection-unary-ops> except that it only
//\\ # happens in a declaration, not a data access. The significant difference is that the '*'
//\\ # can be preceded by a "const" (and maybe "volatile") keyword, eg "int const *fred" which
//\\ # is a constant pointer to an int.
//\\ #
case AST_opt_indirection_decl://\\ P<opt-indirection-decl> =
if (alt == 0) { //\\ <opt-const-or-volatile-type-qualifier> '*' <opt-indirection-decl>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_indirection_unary_ops://\\ P<indirection-unary-ops> =
if (alt == 0) { //\\ '*' <opt-indirection-unary-ops>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_indirection_unary_ops://\\ P<opt-indirection-unary-ops> =
if (alt == 0) { //\\ '*' <opt-indirection-unary-ops>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_type_specifier: //\\ P<type-specifier> =
if (alt == 0) { //\\ <basic-type-specifier>,
} else if (alt == 1) { //\\ <typedef-name>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_typedef_name: //\\ P<typedef-name> =
if (alt == 0) { //\\ <identifier>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # I think struct or union or enum specifier below can be an actual declaration using '{}'s
//\\ # rather than just a struct or enum name.
//\\ #
case AST_basic_type_specifier://\\ P<basic-type-specifier> =
if (alt == 0) { //\\ "double",
} else if (alt == 1) { //\\ "long" "double",
} else if (alt == 2) { //\\ <opt-signed> "char",
} else if (alt == 3) { //\\ <opt-signed-inttype>,
} else if (alt == 4) { //\\ "float",
} else if (alt == 5) { //\\ <struct-or-union-specifier>,
} else if (alt == 6) { //\\ <enum-specifier>,
} else if (alt == 7) { //\\ "void";
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_enum_specifier: //\\ P<enum-specifier> =
if (alt == 0) { //\\ "enum" '{' <enumerator-list> '}',
} else if (alt == 1) { //\\ "enum" <identifier> '{' <enumerator-list> '}',
} else if (alt == 2) { //\\ "enum" <identifier>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_enumerator_list: //\\ P<enumerator-list> =
if (alt == 0) { //\\ <enumerator> <rest-of-enumerator-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_enumerator_list://\\ P<rest-of-enumerator-list> =
if (alt == 0) { //\\ ',' <enumerator> <rest-of-enumerator-list>,
} else if (alt == 1) { //\\ ',',
} else if (alt == 2) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_enumerator: //\\ P<enumerator> =
if (alt == 0) { //\\ <identifier> '=' <constant-expression>,
} else if (alt == 1) { //\\ <identifier>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_constant_expression://\\ P<constant-expression> =
if (alt == 0) { //\\ <conditional-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # does this omit "signed int"? - check, and add <opt-signed> "int" if needed...
case AST_opt_signed_inttype: //\\ P<opt-signed-inttype> =
if (alt == 0) { //\\ <opt-signed> "short" <opt-int>,
} else if (alt == 1) { //\\ <opt-signed> "long" "long" <opt-int>,
} else if (alt == 2) { //\\ <opt-signed> "long" <opt-int>,
} else if (alt == 3) { //\\ <opt-signed> "int",
} else if (alt == 4) { //\\ "signed",
} else if (alt == 5) { //\\ "unsigned";
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_int: //\\ P<opt-int> =
if (alt == 0) { //\\ "int",
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_signed: //\\ P<opt-signed> =
if (alt == 0) { //\\ "signed",
} else if (alt == 1) { //\\ "unsigned",
} else if (alt == 2) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_address_operator: //\\ P<address-operator> =
if (alt == 0) { //\\ '&';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_pre_increment_op: //\\ P<pre-increment-op> =
if (alt == 0) { //\\ <pp>,
} else if (alt == 1) { //\\ <mm>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_optionally_cast_unary_rvalue_expression://\\ P<optionally-cast-unary-rvalue-expression> =
if (alt == 0) { //\\ <cast> <optionally-cast-unary-rvalue-expression>,
} else if (alt == 1) { //\\ <unary-rvalue-expression>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_bitwise_unary_ops: //\\ P<bitwise-unary-ops> =
if (alt == 0) { //\\ '~' <rest-of-bitwise-unary-ops>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_bitwise_unary_ops://\\ P<rest-of-bitwise-unary-ops> =
if (alt == 0) { //\\ '~' <rest-of-bitwise-unary-ops>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_boolean_unary_ops: //\\ P<boolean-unary-ops> =
if (alt == 0) { //\\ '!' <rest-of-boolean-unary-ops>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_boolean_unary_ops://\\ P<rest-of-boolean-unary-ops> =
if (alt == 0) { //\\ '!' <rest-of-boolean-unary-ops>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_arithmetic_unary_op://\\ P<arithmetic-unary-op> =
if (alt == 0) { //\\ '+',
} else if (alt == 1) { //\\ '-';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_mulop: //\\ P<mulop> =
if (alt == 0) { //\\ '*',
} else if (alt == 1) { //\\ '/',
} else if (alt == 2) { //\\ '%';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_plusminus: //\\ P<plusminus> =
if (alt == 0) { //\\ '+',
} else if (alt == 1) { //\\ '-';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_shiftop: //\\ P<shiftop> =
if (alt == 0) { //\\ '<' '<',
} else if (alt == 1) { //\\ '>' '>';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_relop: //\\ P<relop> =
if (alt == 0) { //\\ '<' '=',
} else if (alt == 1) { //\\ '<',
} else if (alt == 2) { //\\ '>' '=',
} else if (alt == 3) { //\\ '>';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_eqop: //\\ P<eqop> =
if (alt == 0) { //\\ <eqeq>,
} else if (alt == 1) { //\\ '!' '=';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_assignment_operator://\\ P<assignment-operator> =
if (alt == 0) { //\\ '=',
} else if (alt == 1) { //\\ '*' '=',
} else if (alt == 2) { //\\ '/' '=',
} else if (alt == 3) { //\\ '%' '=',
} else if (alt == 4) { //\\ '+' '=',
} else if (alt == 5) { //\\ '-' '=',
} else if (alt == 6) { //\\ '<' '<' '=',
} else if (alt == 7) { //\\ '>' '>' '=',
} else if (alt == 8) { //\\ '&' '=',
} else if (alt == 9) { //\\ '^' '=',
} else if (alt == 10) { //\\ '|' '=';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_lvalue_assign: //\\ P<opt-lvalue-assign> =
if (alt == 0) { //\\ <unary-lvalue-expression> <assignment-operator>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_array_init: //\\ P<opt-array-init> =
if (alt == 0) { //\\ '=' '{' <constant-initializer-list> '}',
} else if (alt == 1) { //\\ '=' <dqstring>,
} else if (alt == 2) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_constant_initializer_list://\\ P<constant-initializer-list> =
if (alt == 0) { //\\ <constant-initializer> <rest-of-constant-initializer-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_constant_initializer_list://\\ P<rest-of-constant-initializer-list> =
if (alt == 0) { //\\ ',' <constant-initializer> <rest-of-constant-initializer-list>,
} else if (alt == 1) { //\\ ',',
} else if (alt == 2) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_constant_initializer://\\ P<constant-initializer> =
if (alt == 0) { //\\ <constant-expression>,
} else if (alt == 1) { //\\ '{' <constant-initializer-list> '}';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_array_bounds: //\\ P<array-bounds> =
if (alt == 0) { //\\ '[' <opt-constant-expression> ']' <opt-array-bounds>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_array_bounds: //\\ P<opt-array-bounds> =
if (alt == 0) { //\\ '[' <opt-constant-expression> ']' <opt-array-bounds>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_constant_expression://\\ P<opt-constant-expression> =
if (alt == 0) { //\\ <constant-expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_type: //\\ P<type> =
if (alt == 0) { //\\ <enum-specifier>,
} else if (alt == 1) { //\\ <struct-or-union-specifier>,
} else if (alt == 2) { //\\ "typeof" '(' <unary-lvalue-expression> ')',
} else if (alt == 3) { //\\ "typeof" '(' <type-specifier> <opt-indirection-unary-ops> ')',
} else if (alt == 4) { //\\ <basic-type-specifier>,
} else if (alt == 5) { //\\ <typedef-name>,
} else if (alt == 6) { //\\ "void";
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_const_or_volatile_type_qualifier://\\ P<opt-const-or-volatile-type-qualifier> =
if (alt == 0) { //\\ <const-or-volatile-type-qualifier>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_const_or_volatile_type_qualifier://\\ P<const-or-volatile-type-qualifier> =
if (alt == 0) { //\\ "const",
} else if (alt == 1) { //\\ "volatile";
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_auto_reg_static_ext://\\ P<opt-auto-reg-static-ext> =
if (alt == 0) { //\\ "auto",
} else if (alt == 1) { //\\ "register",
} else if (alt == 2) { //\\ "static",
} else if (alt == 3) { //\\ "extern",
} else if (alt == 4) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_identifier_list: //\\ P<identifier-list> =
if (alt == 0) { //\\ <identifier> <rest-of-identifier-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_identifier_list://\\ P<rest-of-identifier-list> =
if (alt == 0) { //\\ ',' <identifier-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_more_forward_decls_or_actual_body://\\ P<more-forward-decls-or-actual-body> =
if (alt == 0) { //\\ <opt-extern-proc-name-and-params-list> ';',
} else if (alt == 1) { //\\ <compound-statement>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_extern_proc_spec: //\\ P<extern-proc-spec> =
if (alt == 0) { //\\ <opt-auto-reg-static-ext> <opt-const-or-volatile-type-qualifier> <opt-basic-type-specifier-or-typedef-name>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_basic_type_specifier_or_typedef_name://\\ P<opt-basic-type-specifier-or-typedef-name> =
if (alt == 0) { //\\ <opt-basic-type-specifier>,
} else if (alt == 1) { //\\ <typedef-name>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_identifier_or_function_pointer://\\ P<identifier-or-function-pointer> =
if (alt == 0) { //\\ '(' '*' <identifier> ')',
} else if (alt == 1) { //\\ <identifier>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_extern_proc_name_and_params://\\ P<extern-proc-name-and-params> =
if (alt == 0) { //\\ <opt-indirection-decl> <identifier-or-function-pointer> '(' <opt-param-list> ')';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_extern_proc_name_and_params_list://\\ P<opt-extern-proc-name-and-params-list> =
if (alt == 0) { //\\ ',' <extern-proc-name-and-params> <opt-extern-proc-name-and-params-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_proc_fn_decl: //\\ P<proc-fn-decl> =
if (alt == 0) { //\\ <extern-proc-spec> <extern-proc-name-and-params> <more-forward-decls-or-actual-body>,
} else if (alt == 1) { //\\ <extern-proc-spec> <opt-indirection-decl> <identifier> '(' <identifier-list> ')' <opt-oldstyle-param-list> ';' <compound-statement>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_compound_statement: //\\ P<compound-statement> =
if (alt == 0) { //\\ '{' '}',
} else if (alt == 1) { //\\ '{' <statement-list> '}';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # Actually I don't think declarations inside a block are allowed
//\\ # to be preceded by labels.
//\\ # So the three lines below (which are in P<statement>) probably should
//\\ # be separated out and put in <statement-list> below separately from the
//\\ # options which can have <opt-labels> in front of them.
//\\ #
//\\ # <extern-proc-spec> <extern-proc-name-and-params> <more-forward-decls-or-actual-body>,
//\\ # <in-proc-data-declaration>,
//\\ # <opt-external-declaration-list>;
//\\ # Also still to add are label declarations (inside blocks):
//\\ # P<label-declaration> =
//\\ # "__label__" <identifier-list> ';';
//\\ # (I'm not sure if "label" as a keyword is valid too, or does it have to be #define'd as __label__ ?
case AST_statement_list: //\\ P<statement-list> =
if (alt == 0) { //\\ <opt-labels> <statement> <rest-of-statement-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_statement_list://\\ P<rest-of-statement-list> =
if (alt == 0) { //\\ <opt-labels> <statement> <rest-of-statement-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # added as a test: <extern-proc-spec> <extern-proc-name-and-params> <more-forward-decls-or-actual-body>,
case AST_statement: //\\ P<statement> =
if (alt == 0) { //\\ ';',
} else if (alt == 1) { //\\ <compound-statement>,
} else if (alt == 2) { //\\ <selection-statement>,
} else if (alt == 3) { //\\ <iteration-statement>,
} else if (alt == 4) { //\\ <jump-statement>,
} else if (alt == 5) { //\\ <expression> ';',
} else if (alt == 6) { //\\ <extern-proc-spec> <extern-proc-name-and-params> <more-forward-decls-or-actual-body>,
} else if (alt == 7) { //\\ <in-proc-data-declaration>,
} else if (alt == 8) { //\\ <opt-external-declaration-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_in_proc_data_declaration://\\ P<in-proc-data-declaration> =
if (alt == 0) { //\\ <opt-auto-reg-static-ext> <opt-const-or-volatile-type-qualifier> <type> <decl-list>,
} else if (alt == 1) { //\\ <struct-decl>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_struct_decl: //\\ P<struct-decl> =
if (alt == 0) { //\\ "struct" <new-structname> '{' <struct-member-list> '}';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_struct_member_list: //\\ P<struct-member-list> =
if (alt == 0) { //\\ <struct-member-declaration> <struct-member-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_struct_member_declaration://\\ P<struct-member-declaration> =
if (alt == 0) { //\\ <struct-decl>,
} else if (alt == 1) { //\\ <possibly-initialised-scalar-decl>,
} else if (alt == 2) { //\\ <possibly-initialised-array-decl>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_possibly_initialised_array_decl://\\ P<possibly-initialised-array-decl> =
if (alt == 0) { //\\ <opt-auto-reg-static-ext> <opt-const-or-volatile-type-qualifier> <type> <opt-indirection-decl> <identifier> <array-bounds> <opt-array-init> ';';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_possibly_initialised_scalar_decl://\\ P<possibly-initialised-scalar-decl> =
if (alt == 0) { //\\ <opt-auto-reg-static-ext> <opt-const-or-volatile-type-qualifier> <type> <rest-of-scalar-decl>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_scalar_decl://\\ P<rest-of-scalar-decl> =
if (alt == 0) { //\\ <opt-indirection-decl> <identifier> <opt-scalar-init> <opt-rest-of-scalar-decl> ';';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_rest_of_scalar_decl://\\ P<opt-rest-of-scalar-decl> =
if (alt == 0) { //\\ ',' <opt-indirection-decl> <identifier> <opt-scalar-init> <opt-rest-of-scalar-decl>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_new_structname: //\\ P<new-structname> =
if (alt == 0) { //\\ <identifier>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_decl_list: //\\ P<decl-list> =
if (alt == 0) { //\\ <decl> <rest-of-decl-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_decl_list: //\\ P<rest-of-decl-list> =
if (alt == 0) { //\\ ',' <decl-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_decl: //\\ P<decl> =
if (alt == 0) { //\\ <opt-indirection-decl> <identifier> <possibly-empty-array-bounds-list> <opt-array-init>,
} else if (alt == 1) { //\\ <opt-indirection-decl> <identifier> <opt-scalar-init>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_possibly_empty_array_bounds_list://\\ P<possibly-empty-array-bounds-list> =
if (alt == 0) { //\\ '[' <opt-constant-expression> ']' <optional-possibly-empty-array-bounds-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_optional_possibly_empty_array_bounds_list://\\ P<optional-possibly-empty-array-bounds-list> =
if (alt == 0) { //\\ '[' <opt-constant-expression> ']' <optional-possibly-empty-array-bounds-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_jump_statement: //\\ P<jump-statement> =
if (alt == 0) { //\\ "goto" <label> ';',
} else if (alt == 1) { //\\ "continue" ';',
} else if (alt == 2) { //\\ "break" ';',
} else if (alt == 3) { //\\ "return" <opt-expression> ';';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_expression: //\\ P<opt-expression> =
if (alt == 0) { //\\ <expression>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_label: //\\ P<label> =
if (alt == 0) { //\\ <identifier>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_iteration_statement://\\ P<iteration-statement> =
if (alt == 0) { //\\ "while" '(' <expression> ')' <statement>,
} else if (alt == 1) { //\\ "do" <statement> "while" '(' <expression> ')' ';',
} else if (alt == 2) { //\\ "for" '(' <opt-expression> ';' <opt-expression> ';' <opt-expression> ')' <statement>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_selection_statement://\\ P<selection-statement> =
if (alt == 0) { //\\ "if" '(' <expression> ')' <statement> <opt-else>,
} else if (alt == 1) { //\\ "switch" '(' <expression> ')' <statement>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_else: //\\ P<opt-else> =
if (alt == 0) { //\\ "else" <statement>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # guard to give better error on "label: }" which should be "label: ; }"
case AST_missing_semicolon_after_label_at_end_of_block://\\ P<missing-semicolon-after-label-at-end-of-block> =
if (alt == 0) { //\\ '}';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_labels: //\\ P<opt-labels> =
if (alt == 0) { //\\ <label> ':' <opt-labels> <!missing-semicolon-after-label-at-end-of-block>,
} else if (alt == 1) { //\\ "case" <constant-expression> ':' <opt-labels> <!missing-semicolon-after-label-at-end-of-block>,
} else if (alt == 2) { //\\ "default" ':' <opt-labels> <!missing-semicolon-after-label-at-end-of-block>,
} else if (alt == 3) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # formal parameter list can also be just a list of types (but can still end in "...")
//\\ # normal current style however is to have named parameters.
//\\ #
case AST_opt_param_list: //\\ P<opt-param-list> =
if (alt == 0) { //\\ <formal-param> <opt-rest-of-param-list>,
} else if (alt == 1) { //\\ "void",
} else if (alt == 2) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_oldstyle_param_list://\\ P<opt-oldstyle-param-list> =
if (alt == 0) { //\\ <oldstyle-param-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_oldstyle_param_list://\\ P<oldstyle-param-list> =
if (alt == 0) { //\\ <oldstyle-formal-param> <opt-rest-of-oldstyle-param-list>,
} else if (alt == 1) { //\\ "void";
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_rest_of_oldstyle_param_list://\\ P<opt-rest-of-oldstyle-param-list> =
if (alt == 0) { //\\ ';' <oldstyle-param-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_oldstyle_formal_param://\\ P<oldstyle-formal-param> =
if (alt == 0) { //\\ <opt-const-or-volatile-type-qualifier> <type> <oldstyle-parameter-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_oldstyle_parameter_list://\\ P<oldstyle-parameter-list> =
if (alt == 0) { //\\ <whatever> <rest-of-oldstyle-parameter-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_oldstyle_parameter_list://\\ P<rest-of-oldstyle-parameter-list> =
if (alt == 0) { //\\ ',' <oldstyle-parameter-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_whatever: //\\ P<whatever> =
if (alt == 0) { //\\ <opt-indirection-decl> <opt-identifier> <optional-possibly-empty-array-bounds-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_rest_of_param_list://\\ P<opt-rest-of-param-list> =
if (alt == 0) { //\\ ',' '.' '.' '.',
} else if (alt == 1) { //\\ ',' <formal-param> <opt-rest-of-param-list>,
} else if (alt == 2) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_formal_param: //\\ P<formal-param> =
if (alt == 0) { //\\ <procedure-as-parameter>,
} else if (alt == 1) { //\\ <opt-const-or-volatile-type-qualifier> <type> <opt-indirection-decl> <opt-identifier> <optional-possibly-empty-array-bounds-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_identifier: //\\ P<opt-identifier> =
if (alt == 0) { //\\ <identifier>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_procedure_as_parameter://\\ P<procedure-as-parameter> =
if (alt == 0) { //\\ <opt-auto-reg-static-ext> <opt-const-or-volatile-type-qualifier> <opt-basic-type-specifier> '(' <opt-indirection-decl> <identifier> ')' '(' <opt-param-list> ')',
} else if (alt == 1) { //\\ <opt-auto-reg-static-ext> <opt-const-or-volatile-type-qualifier> <typedef-name> '(' <opt-indirection-decl> <identifier> ')' '(' <opt-param-list> ')';
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_opt_basic_type_specifier://\\ P<opt-basic-type-specifier> =
if (alt == 0) { //\\ <basic-type-specifier>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
//\\ # Wonder if this would do it? <opt-indirection-decl> '(' <opt-indirection-decl> <identifier> ')' '(' <opt-param-list> ')' <opt-scalar-init> <opt-rest-of-scalar-or-array-decl>,
case AST_typedef_declaration://\\ P<typedef-declaration> =
if (alt == 0) { //\\ "typedef" <type-specifier> <opt-indirection-decl> '(' <opt-indirection-decl> <identifier> ')' '(' <opt-param-list> ')',
} else if (alt == 1) { //\\ "typedef" <struct-decl> <maybe-indirect-typedef-name-list>,
} else if (alt == 2) { //\\ "typedef" <type-specifier> <maybe-indirect-typedef-name-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_maybe_indirect_typedef_name_list://\\ P<maybe-indirect-typedef-name-list> =
if (alt == 0) { //\\ <opt-indirection-decl> <typedef-name> <rest-of-maybe-indirect-typedef-name-list>;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST_rest_of_maybe_indirect_typedef_name_list://\\ P<rest-of-maybe-indirect-typedef-name-list> =
if (alt == 0) { //\\ ',' <maybe-indirect-typedef-name-list>,
} else if (alt == 1) { //\\ ;
}
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
case AST__LIT:
RECONSTITUTE(A[A_child[1]+A_literal_offset], stdout);
break;
case AST__KW:
for (i = A_child[1]; i < A_child[1]+A_child[2]; i++) {
// fprintf(stdout, "%s", String(i));
RECONSTITUTE(i, stdout);
}
break;
default:
for (i = 1; i <= count; i++) compile(nthchild(astp,i));
break;
}
}