source: src/Parser/parser.yy@ 377e33f

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new stuck-waitfor-destruct with_gc
Last change on this file since 377e33f was 6b224a52, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

  • Property mode set to 100644
File size: 113.2 KB
RevLine 
[b87a5ed]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[9335ecc]7// parser.yy --
[974906e2]8//
[c11e31c]9// Author : Peter A. Buhr
10// Created On : Sat Sep 1 20:22:55 2001
[936e9f4]11// Last Modified By : Peter A. Buhr
[1efa1e1]12// Last Modified On : Wed Aug 23 21:08:08 2017
13// Update Count : 2704
[974906e2]14//
[c11e31c]15
[de62360d]16// This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C
17// grammar by James A. Roskind, specifically parts of DECLARATIONS and EXTERNAL DEFINITIONS. While parts have been
18// copied, important changes have been made in all sections; these changes are sufficient to constitute a new grammar.
19// In particular, this grammar attempts to be more syntactically precise, i.e., it parses less incorrect language syntax
20// that must be subsequently rejected by semantic checks. Nevertheless, there are still several semantic checks
21// required and many are noted in the grammar. Finally, the grammar is extended with GCC and CFA language extensions.
[c11e31c]22
[de62360d]23// Acknowledgments to Richard Bilson, Glen Ditchfield, and Rodolfo Gabriel Esteves who all helped when I got stuck with
24// the grammar.
[c11e31c]25
26// The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for:
27//
28// 1. designation with '=' (use ':' instead)
29//
[de62360d]30// Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This grammar also has
31// two levels of extensions. The first extensions cover most of the GCC C extensions, except for:
[c11e31c]32//
[e7aed49]33// 1. designation with and without '=' (use ':' instead)
[c0aa336]34// 2. attributes not allowed in parenthesis of declarator
[c11e31c]35//
[de62360d]36// All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall
37// (CFA), which fixes several of C's outstanding problems and extends C with many modern language concepts. All of the
38// syntactic extensions for CFA C are marked with the comment "CFA". As noted above, there is one unreconcileable
39// parsing problem between C99 and CFA with respect to designators; this is discussed in detail before the "designation"
40// grammar rule.
[51b73452]41
42%{
[b87a5ed]43#define YYDEBUG_LEXER_TEXT (yylval) // lexer loads this up each time
44#define YYDEBUG 1 // get the pretty debugging code to compile
[51b73452]45
46#undef __GNUC_MINOR__
47
48#include <cstdio>
49#include <stack>
50#include "ParseNode.h"
[984dce6]51#include "TypedefTable.h"
[1db21619]52#include "TypeData.h"
[51b73452]53#include "LinkageSpec.h"
[2298f728]54using namespace std;
[51b73452]55
[cbaee0d]56extern DeclarationNode * parseTree;
[8b7ee09]57extern LinkageSpec::Spec linkage;
[0da3e2c]58extern TypedefTable typedefTable;
59
[2298f728]60stack< LinkageSpec::Spec > linkageStack;
[7bf7fb9]61
[2298f728]62void appendStr( string *to, string *from ) {
[7bf7fb9]63 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.
[ab57786]64 to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
[7bf7fb9]65} // appendStr
[c0aa336]66
67DeclarationNode * distAttr( DeclarationNode * specifier, DeclarationNode * declList ) {
68 // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__.
69 DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier );
70 //cur->addType( specifier );
71 for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
72 cl->cloneBaseType( cur );
73 } // for
74 declList->addType( cl );
75// delete cl;
76 return declList;
77} // distAttr
78
79void distExt( DeclarationNode * declaration ) {
80 // distribute EXTENSION across all declarations
81 for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
82 iter->set_extension( true );
83 } // for
84} // distExt
[fdca7c6]85
86bool forall = false; // aggregate have one or more forall qualifiers ?
[51b73452]87%}
88
[a67b60e]89// Types declaration
90%union
91{
92 Token tok;
93 ParseNode * pn;
94 ExpressionNode * en;
95 DeclarationNode * decl;
96 DeclarationNode::Aggregate aggKey;
97 DeclarationNode::TypeClass tclass;
98 StatementNode * sn;
[135b431]99 WaitForStmt * wfs;
[a67b60e]100 ConstantExpr * constant;
[936e9f4]101 IfCtl * ifctl;
[a67b60e]102 ForCtl * fctl;
103 LabelNode * label;
104 InitializerNode * in;
105 OperKinds op;
106 std::string * str;
107 bool flag;
[307a732]108 CatchStmt::Kind catch_kind;
[a67b60e]109}
110
[c11e31c]111//************************* TERMINAL TOKENS ********************************
[51b73452]112
[c11e31c]113// keywords
[51b73452]114%token TYPEDEF
[a7c90d4]115%token EXTERN STATIC AUTO REGISTER
116%token THREADLOCAL // C11
117%token INLINE FORTRAN // C99, extension ISO/IEC 9899:1999 Section J.5.9(1)
118%token NORETURN // C11
[51b73452]119%token CONST VOLATILE
[b87a5ed]120%token RESTRICT // C99
[a7c90d4]121%token ATOMIC // C11
[9236060]122%token FORALL MUTEX VIRTUAL // CFA
[72457b6]123%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
[b87a5ed]124%token BOOL COMPLEX IMAGINARY // C99
[72457b6]125%token ZERO_T ONE_T // CFA
126%token VALIST // GCC
[b87a5ed]127%token TYPEOF LABEL // GCC
[51b73452]128%token ENUM STRUCT UNION
[d3bc0ad]129%token COROUTINE MONITOR THREAD // CFA
[a7c90d4]130%token OTYPE FTYPE DTYPE TTYPE TRAIT // CFA
[5721a6d]131%token SIZEOF OFFSETOF
[b87a5ed]132%token ATTRIBUTE EXTENSION // GCC
[51b73452]133%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
[5b2edbc]134%token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA
[b87a5ed]135%token ASM // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
[a7c90d4]136%token ALIGNAS ALIGNOF GENERIC STATICASSERT // C11
[51b73452]137
[c11e31c]138// names and constants: lexer differentiates between identifier and typedef names
[b87a5ed]139%token<tok> IDENTIFIER QUOTED_IDENTIFIER TYPEDEFname TYPEGENname
[5b2edbc]140%token<tok> TIMEOUT WOR
[b87a5ed]141%token<tok> ATTR_IDENTIFIER ATTR_TYPEDEFname ATTR_TYPEGENname
[1b29996]142%token<tok> INTEGERconstant CHARACTERconstant STRINGliteral
143// Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and
144// overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically
145// converted into the tuple index (.)(1). e.g., 3.x
146%token<tok> REALDECIMALconstant REALFRACTIONconstant FLOATINGconstant
[51b73452]147
[c11e31c]148// multi-character operators
[b87a5ed]149%token ARROW // ->
150%token ICR DECR // ++ --
151%token LS RS // << >>
152%token LE GE EQ NE // <= >= == !=
153%token ANDAND OROR // && ||
154%token ELLIPSIS // ...
155
[e5f2a67]156%token EXPassign MULTassign DIVassign MODassign // \= *= /= %=
[b87a5ed]157%token PLUSassign MINUSassign // += -=
158%token LSassign RSassign // <<= >>=
159%token ANDassign ERassign ORassign // &= ^= |=
[51b73452]160
[e7aed49]161%token ATassign // @=
[097e2b0]162
[6165ce7]163%type<tok> identifier no_attr_identifier
[84d58c5]164%type<tok> identifier_or_type_name no_attr_identifier_or_type_name attr_name
[5b2edbc]165%type<tok> quasi_keyword
[ab57786]166%type<constant> string_literal
167%type<str> string_literal_list
[51b73452]168
[c11e31c]169// expressions
[d1625f8]170%type<en> constant
[b87a5ed]171%type<en> tuple tuple_expression_list
[9706554]172%type<op> ptrref_operator unary_operator assignment_operator
[b87a5ed]173%type<en> primary_expression postfix_expression unary_expression
[994d080]174%type<en> cast_expression exponential_expression multiplicative_expression additive_expression
175%type<en> shift_expression relational_expression equality_expression
176%type<en> AND_expression exclusive_OR_expression inclusive_OR_expression
177%type<en> logical_AND_expression logical_OR_expression
178%type<en> conditional_expression constant_expression assignment_expression assignment_expression_opt
[b87a5ed]179%type<en> comma_expression comma_expression_opt
[994d080]180%type<en> argument_expression_list argument_expression default_initialize_opt
[936e9f4]181%type<ifctl> if_control_expression
[2f22cc4]182%type<fctl> for_control_expression
[51b73452]183%type<en> subrange
[c0aa336]184%type<decl> asm_name_opt
[7f5566b]185%type<en> asm_operands_opt asm_operands_list asm_operand
186%type<label> label_list
[d1625f8]187%type<en> asm_clobbers_list_opt
[7f5566b]188%type<flag> asm_volatile_opt
[cbce272]189%type<en> handler_predicate_opt
[135b431]190%type<en> when_clause_opt timeout
[51b73452]191
[c11e31c]192// statements
[b87a5ed]193%type<sn> labeled_statement compound_statement expression_statement selection_statement
[8b47e50]194%type<sn> iteration_statement jump_statement
195%type<sn> with_statement exception_statement asm_statement
[135b431]196%type<sn> waitfor_statement
[b87a5ed]197%type<sn> fall_through_opt fall_through
198%type<sn> statement statement_list
199%type<sn> block_item_list block_item
[8b47e50]200%type<sn> with_clause_opt
[8688ce1]201%type<en> case_value
[8b47e50]202%type<sn> case_clause case_value_list case_label case_label_list
[b87a5ed]203%type<sn> switch_clause_list_opt switch_clause_list choose_clause_list_opt choose_clause_list
[5b2edbc]204%type<sn> handler_clause finally_clause
[307a732]205%type<catch_kind> handler_key
[135b431]206%type<wfs> waitfor_clause
207%type<en> waitfor
[51b73452]208
[c11e31c]209// declarations
[c0aa336]210%type<decl> abstract_declarator abstract_ptr abstract_array abstract_function array_dimension multi_array_dimension
211%type<decl> abstract_parameter_declarator abstract_parameter_ptr abstract_parameter_array abstract_parameter_function array_parameter_dimension array_parameter_1st_dimension
212%type<decl> abstract_parameter_declaration
[51b73452]213
214%type<aggKey> aggregate_key
[d0ffed1]215%type<decl> aggregate_type aggregate_type_nobody
[51b73452]216
217%type<decl> assertion assertion_list_opt
218
219%type<en> bit_subrange_size_opt bit_subrange_size
220
[84d58c5]221%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
[51b73452]222
[4040425]223%type<decl> trait_declaration trait_declaration_list trait_declaring_list trait_specifier
[51b73452]224
225%type<decl> declaration declaration_list declaration_list_opt declaration_qualifier_list
[d0ffed1]226%type<decl> declaration_specifier declaration_specifier_nobody declarator declaring_list
[51b73452]227
[d0ffed1]228%type<decl> elaborated_type elaborated_type_nobody
[51b73452]229
[d0ffed1]230%type<decl> enumerator_list enum_type enum_type_nobody
[51b73452]231%type<en> enumerator_value_opt
232
233%type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt
234
235%type<decl> field_declaration field_declaration_list field_declarator field_declaring_list
[8780e30]236%type<en> field field_list field_name fraction_constants
[51b73452]237
[4d51835]238%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
[51b73452]239
[d3bc0ad]240%type<decl> identifier_parameter_declarator identifier_parameter_ptr identifier_parameter_array identifier_parameter_function
241%type<decl> identifier_list
[51b73452]242
[c0aa336]243%type<decl> cfa_abstract_array cfa_abstract_declarator_no_tuple cfa_abstract_declarator_tuple
244%type<decl> cfa_abstract_function cfa_abstract_parameter_declaration cfa_abstract_parameter_list
245%type<decl> cfa_abstract_ptr cfa_abstract_tuple
[51b73452]246
[c0aa336]247%type<decl> cfa_array_parameter_1st_dimension
[51b73452]248
[c0aa336]249%type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list
250%type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier
[51b73452]251
[c0aa336]252%type<decl> cfa_identifier_parameter_array cfa_identifier_parameter_declarator_no_tuple
253%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
[51b73452]254
[c0aa336]255%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_type_list cfa_parameter_type_list_opt
[51b73452]256
[c0aa336]257%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
[51b73452]258
[c0aa336]259%type<decl> c_declaration
260%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
261%type<decl> KR_declaration_list KR_declaration_list_opt
[51b73452]262
263%type<decl> parameter_declaration parameter_list parameter_type_list
264%type<decl> parameter_type_list_opt
265
[2871210]266%type<decl> paren_identifier paren_type
[51b73452]267
[0da3e2c]268%type<decl> storage_class storage_class_list
[51b73452]269
[d0ffed1]270%type<decl> sue_declaration_specifier sue_declaration_specifier_nobody sue_type_specifier sue_type_specifier_nobody
[51b73452]271
272%type<tclass> type_class
273%type<decl> type_declarator type_declarator_name type_declaring_list
274
[84d58c5]275%type<decl> type_declaration_specifier type_type_specifier type_name typegen_name
276%type<decl> typedef typedef_declaration typedef_expression
[c0aa336]277
278%type<decl> variable_type_redeclarator type_ptr type_array type_function
279
280%type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function
[51b73452]281
[84d58c5]282%type<decl> type type_no_function
283%type<decl> type_parameter type_parameter_list type_initializer_opt
[51b73452]284
[84d58c5]285%type<en> type_list
[51b73452]286
[d3bc0ad]287%type<decl> type_qualifier type_qualifier_name type_qualifier_list_opt type_qualifier_list
288%type<decl> type_specifier type_specifier_nobody
[51b73452]289
[c0aa336]290%type<decl> variable_declarator variable_ptr variable_array variable_function
291%type<decl> variable_abstract_declarator variable_abstract_ptr variable_abstract_array variable_abstract_function
[51b73452]292
[44a81853]293%type<decl> attribute_list_opt attribute_list attribute_name_list attribute attribute_name
[1db21619]294
[c11e31c]295// initializers
[51b73452]296%type<in> initializer initializer_list initializer_opt
297
[c11e31c]298// designators
[51b73452]299%type<en> designator designator_list designation
300
301
[b87a5ed]302// Handle single shift/reduce conflict for dangling else by shifting the ELSE token. For example, this string
303// is ambiguous:
[5b2edbc]304// .---------. matches IF '(' comma_expression ')' statement . (reduce)
[c11e31c]305// if ( C ) S1 else S2
[5b2edbc]306// `-----------------' matches IF '(' comma_expression ')' statement . (shift) ELSE statement */
307// Similar issues exit with the waitfor statement.
[51b73452]308
[1efa1e1]309// Order of these lines matters (low-to-high precedence). THEN is left associative over WOR/TIMEOUT/ELSE, WOR is left
310// associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.
[5b2edbc]311%precedence THEN // rule precedence for IF/WAITFOR statement
312%precedence WOR // token precedence for start of WOR in WAITFOR statement
313%precedence TIMEOUT // token precedence for start of TIMEOUT in WAITFOR statement
314%precedence ELSE // token precedence for start of else clause in IF/WAITFOR statement
[51b73452]315
[b87a5ed]316%start translation_unit // parse-tree root
[51b73452]317
318%%
[c11e31c]319//************************* Namespace Management ********************************
320
[de62360d]321// The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols
322// "identifier" and "TYPEDEFname" that are lexically identical. While it is possible to write a purely context-free
323// grammar, such a grammar would obscure the relationship between syntactic and semantic constructs. Hence, this
324// grammar uses the ANSI style.
[c11e31c]325//
[de62360d]326// Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those
[9059213]327// introduced through "forall" qualifiers), and by introducing "type generators" -- parameterized types. This latter
[de62360d]328// type name creates a third class of identifiers that must be distinguished by the scanner.
[c11e31c]329//
[de62360d]330// Since the scanner cannot distinguish among the different classes of identifiers without some context information, it
[9059213]331// accesses a data structure (TypedefTable) to allow classification of an identifier that it has just read. Semantic
332// actions during the parser update this data structure when the class of identifiers change.
[c11e31c]333//
[de62360d]334// Because the Cforall language is block-scoped, there is the possibility that an identifier can change its class in a
335// local scope; it must revert to its original class at the end of the block. Since type names can be local to a
336// particular declaration, each declaration is itself a scope. This requires distinguishing between type names that are
337// local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in
[9059213]338// "typedef" or "otype" declarations).
[c11e31c]339//
[de62360d]340// The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and closing of
341// scopes. Every push must have a matching pop, although it is regrettable the matching pairs do not always occur
342// within the same rule. These non-terminals may appear in more contexts than strictly necessary from a semantic point
343// of view. Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have
344// enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra
345// rules is to open a new scope unconditionally. As the grammar evolves, it may be neccesary to add or move around
346// "push" and "pop" nonterminals to resolve conflicts of this sort.
[51b73452]347
348push:
[ab57786]349 { typedefTable.enterScope(); }
[4d51835]350 ;
[51b73452]351
352pop:
[ab57786]353 { typedefTable.leaveScope(); }
[4d51835]354 ;
[51b73452]355
[c11e31c]356//************************* CONSTANTS ********************************
[51b73452]357
358constant:
[de62360d]359 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
[ab57786]360 INTEGERconstant { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
[1b29996]361 | REALDECIMALconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
362 | REALFRACTIONconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
[ab57786]363 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
364 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
[4d51835]365 ;
[51b73452]366
[5b2edbc]367quasi_keyword: // CFA
368 TIMEOUT
369 | WOR
370 ;
371
[51b73452]372identifier:
[4d51835]373 IDENTIFIER
374 | ATTR_IDENTIFIER // CFA
[5b2edbc]375 | quasi_keyword
[4d51835]376 ;
[51b73452]377
378no_attr_identifier:
[4d51835]379 IDENTIFIER
[5b2edbc]380 | quasi_keyword
[4d51835]381 ;
[51b73452]382
[ab57786]383string_literal:
384 string_literal_list { $$ = build_constantStr( *$1 ); }
385 ;
386
[b87a5ed]387string_literal_list: // juxtaposed strings are concatenated
[ab57786]388 STRINGliteral { $$ = $1; } // conversion from tok to str
[7bf7fb9]389 | string_literal_list STRINGliteral
390 {
[ab57786]391 appendStr( $1, $2 ); // append 2nd juxtaposed string to 1st
[7bf7fb9]392 delete $2; // allocated by lexer
[ab57786]393 $$ = $1; // conversion from tok to str
[7bf7fb9]394 }
[4d51835]395 ;
[51b73452]396
[c11e31c]397//************************* EXPRESSIONS ********************************
[51b73452]398
399primary_expression:
[4d51835]400 IDENTIFIER // typedef name cannot be used as a variable name
[d1625f8]401 { $$ = new ExpressionNode( build_varref( $1 ) ); }
[5b2edbc]402 | quasi_keyword
403 { $$ = new ExpressionNode( build_varref( $1 ) ); }
[1b29996]404 | tuple
[4d51835]405 | '(' comma_expression ')'
406 { $$ = $2; }
407 | '(' compound_statement ')' // GCC, lambda expression
[1b772749]408 { $$ = new ExpressionNode( build_valexpr( $2 ) ); }
[84d58c5]409 | primary_expression '{' argument_expression_list '}' // CFA, constructor call
[ecb27a7]410 {
411 Token fn;
412 fn.str = new std::string( "?{}" ); // location undefined - use location of '{'?
413 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
414 }
[84d58c5]415 | type_name '.' no_attr_identifier // CFA, nested type
416 { $$ = nullptr; } // FIX ME
417 | type_name '.' '[' push field_list pop ']' // CFA, nested type / tuple field selector
418 { $$ = nullptr; } // FIX ME
[4d51835]419 ;
[51b73452]420
421postfix_expression:
[4d51835]422 primary_expression
423 | postfix_expression '[' push assignment_expression pop ']'
[c6b1105]424 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
[de62360d]425 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
426 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
427 // equivalent to the old x[i,j].
[d1625f8]428 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); }
[4d51835]429 | postfix_expression '(' argument_expression_list ')'
[d1625f8]430 { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
[4d51835]431 | postfix_expression '.' no_attr_identifier
[d1625f8]432 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
[4d51835]433 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
[3b58d91]434 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
[1b29996]435 | postfix_expression REALFRACTIONconstant // CFA, tuple index
[8780e30]436 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_REALFRACTIONconstant( *$2 ) ) ); }
[4d51835]437 | postfix_expression ARROW no_attr_identifier
[861799c7]438 {
439 $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) );
440 }
[4d51835]441 | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
[3b58d91]442 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
[861799c7]443 | postfix_expression ARROW INTEGERconstant // CFA, tuple index
444 { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
[4d51835]445 | postfix_expression ICR
[d1625f8]446 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
[4d51835]447 | postfix_expression DECR
[d1625f8]448 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
[84d58c5]449 | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
[d1625f8]450 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
[ecb27a7]451 | '^' primary_expression '{' argument_expression_list '}' // CFA
[097e2b0]452 {
[9706554]453 Token fn;
[ecb27a7]454 fn.str = new string( "^?{}" ); // location undefined
455 $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) );
[097e2b0]456 }
[4d51835]457 ;
[51b73452]458
459argument_expression_list:
[4d51835]460 argument_expression
461 | argument_expression_list ',' argument_expression
[1d4580a]462 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
[4d51835]463 ;
[51b73452]464
465argument_expression:
[4d51835]466 // empty
[738e304]467 { $$ = nullptr; }
468 // | '@' // use default argument
469 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
[4d51835]470 | assignment_expression
471 ;
[b87a5ed]472
473field_list: // CFA, tuple field selector
[4d51835]474 field
[1d4580a]475 | field_list ',' field { $$ = (ExpressionNode *)$1->set_last( $3 ); }
[4d51835]476 ;
[b87a5ed]477
478field: // CFA, tuple field selector
[faddbd8]479 field_name
[1b29996]480 | REALDECIMALconstant field
[8780e30]481 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_REALDECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
[1b29996]482 | REALDECIMALconstant '[' push field_list pop ']'
[8780e30]483 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_REALDECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }
[faddbd8]484 | field_name '.' field
[bf32bb8]485 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
[faddbd8]486 | field_name '.' '[' push field_list pop ']'
[bf32bb8]487 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
[faddbd8]488 | field_name ARROW field
[bf32bb8]489 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
[faddbd8]490 | field_name ARROW '[' push field_list pop ']'
[bf32bb8]491 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
[4d51835]492 ;
[51b73452]493
[faddbd8]494field_name:
[1b29996]495 INTEGERconstant fraction_constants
[8780e30]496 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantInteger( *$1 ), $2 ) ); }
[1b29996]497 | FLOATINGconstant fraction_constants
[8780e30]498 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); }
[1b29996]499 | no_attr_identifier fraction_constants
[4cb935e]500 {
[84d58c5]501 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
502 }
[1b29996]503 ;
504
505fraction_constants:
506 // empty
[8780e30]507 { $$ = nullptr; }
[1b29996]508 | fraction_constants REALFRACTIONconstant
[8780e30]509 {
510 Expression * constant = build_field_name_REALFRACTIONconstant( *$2 );
511 $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( $1, constant ) ) : new ExpressionNode( constant );
512 }
[faddbd8]513 ;
514
[51b73452]515unary_expression:
[4d51835]516 postfix_expression
[c6b1105]517 // first location where constant/string can have operator applied: sizeof 3/sizeof "abc" still requires
518 // semantics checks, e.g., ++3, 3--, *3, &&3
[51b1202]519 | constant
520 { $$ = $1; }
[ab57786]521 | string_literal
[d1625f8]522 { $$ = new ExpressionNode( $1 ); }
[4d51835]523 | EXTENSION cast_expression // GCC
[e04ef3a]524 { $$ = $2->set_extension( true ); }
[c6b1105]525 // '*' ('&') is separated from unary_operator because of shift/reduce conflict in:
526 // { * X; } // dereference X
527 // { * int X; } // CFA declaration of pointer to int
[51e076e]528 | ptrref_operator cast_expression // CFA
[9706554]529 {
530 switch ( $1 ) {
[d9e2280]531 case OperKinds::AddressOf:
[d1625f8]532 $$ = new ExpressionNode( build_addressOf( $2 ) );
[9706554]533 break;
[d9e2280]534 case OperKinds::PointTo:
[d1625f8]535 $$ = new ExpressionNode( build_unary_val( $1, $2 ) );
[9706554]536 break;
537 default:
538 assert( false );
539 }
540 }
[4d51835]541 | unary_operator cast_expression
[d1625f8]542 { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); }
[dd51906]543 | ICR unary_expression
[d1625f8]544 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Incr, $2 ) ); }
[dd51906]545 | DECR unary_expression
[d1625f8]546 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); }
[4d51835]547 | SIZEOF unary_expression
[d1625f8]548 { $$ = new ExpressionNode( build_sizeOfexpr( $2 ) ); }
[84d58c5]549 | SIZEOF '(' type_no_function ')'
[d1625f8]550 { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); }
551 | ALIGNOF unary_expression // GCC, variable alignment
552 { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); }
[a2e0687]553 | ALIGNOF '(' type_no_function ')' // GCC, type alignment
[d1625f8]554 { $$ = new ExpressionNode( build_alignOftype( $3 ) ); }
[84d58c5]555 | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
[d1625f8]556 { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); }
[4d51835]557 | ATTR_IDENTIFIER
[d1625f8]558 { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), nullptr ) ); }
[4d51835]559 | ATTR_IDENTIFIER '(' argument_expression ')'
[d1625f8]560 { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); }
[84d58c5]561 | ATTR_IDENTIFIER '(' type ')'
[d1625f8]562 { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); }
[c6b1105]563// | ANDAND IDENTIFIER // GCC, address of label
[d7dc824]564// { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2 ) ); }
[4d51835]565 ;
[51b73452]566
[dd51906]567ptrref_operator:
[d9e2280]568 '*' { $$ = OperKinds::PointTo; }
569 | '&' { $$ = OperKinds::AddressOf; }
[c6b1105]570 // GCC, address of label must be handled by semantic check for ref,ref,label
[9f07232]571 | ANDAND { $$ = OperKinds::And; }
[dd51906]572 ;
573
[51b73452]574unary_operator:
[d9e2280]575 '+' { $$ = OperKinds::UnPlus; }
576 | '-' { $$ = OperKinds::UnMinus; }
577 | '!' { $$ = OperKinds::Neg; }
578 | '~' { $$ = OperKinds::BitNeg; }
[4d51835]579 ;
[51b73452]580
581cast_expression:
[4d51835]582 unary_expression
[84d58c5]583 | '(' type_no_function ')' cast_expression
[d1625f8]584 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
[72457b6]585 // VIRTUAL cannot be opt because of look ahead issues
586 | '(' VIRTUAL ')' cast_expression
[a5f0529]587 { $$ = new ExpressionNode( build_virtual_cast( nullptr, $4 ) ); }
[72457b6]588 | '(' VIRTUAL type_no_function ')' cast_expression
[a5f0529]589 { $$ = new ExpressionNode( build_virtual_cast( $3, $5 ) ); }
[84d58c5]590// | '(' type_no_function ')' tuple
[1b29996]591// { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
[4d51835]592 ;
[51b73452]593
[994d080]594exponential_expression:
[4d51835]595 cast_expression
[994d080]596 | exponential_expression '\\' cast_expression
[e5f2a67]597 { $$ = new ExpressionNode( build_binary_val( OperKinds::Exp, $1, $3 ) ); }
[994d080]598 ;
599
600multiplicative_expression:
601 exponential_expression
602 | multiplicative_expression '*' exponential_expression
[d1625f8]603 { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 ) ); }
[994d080]604 | multiplicative_expression '/' exponential_expression
[d1625f8]605 { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 ) ); }
[994d080]606 | multiplicative_expression '%' exponential_expression
[d1625f8]607 { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 ) ); }
[4d51835]608 ;
[51b73452]609
610additive_expression:
[4d51835]611 multiplicative_expression
612 | additive_expression '+' multiplicative_expression
[d1625f8]613 { $$ = new ExpressionNode( build_binary_val( OperKinds::Plus, $1, $3 ) ); }
[4d51835]614 | additive_expression '-' multiplicative_expression
[d1625f8]615 { $$ = new ExpressionNode( build_binary_val( OperKinds::Minus, $1, $3 ) ); }
[4d51835]616 ;
[51b73452]617
618shift_expression:
[4d51835]619 additive_expression
620 | shift_expression LS additive_expression
[d1625f8]621 { $$ = new ExpressionNode( build_binary_val( OperKinds::LShift, $1, $3 ) ); }
[4d51835]622 | shift_expression RS additive_expression
[d1625f8]623 { $$ = new ExpressionNode( build_binary_val( OperKinds::RShift, $1, $3 ) ); }
[4d51835]624 ;
[51b73452]625
626relational_expression:
[4d51835]627 shift_expression
628 | relational_expression '<' shift_expression
[d1625f8]629 { $$ = new ExpressionNode( build_binary_val( OperKinds::LThan, $1, $3 ) ); }
[4d51835]630 | relational_expression '>' shift_expression
[d1625f8]631 { $$ = new ExpressionNode( build_binary_val( OperKinds::GThan, $1, $3 ) ); }
[4d51835]632 | relational_expression LE shift_expression
[d1625f8]633 { $$ = new ExpressionNode( build_binary_val( OperKinds::LEThan, $1, $3 ) ); }
[4d51835]634 | relational_expression GE shift_expression
[d1625f8]635 { $$ = new ExpressionNode( build_binary_val( OperKinds::GEThan, $1, $3 ) ); }
[4d51835]636 ;
[51b73452]637
638equality_expression:
[4d51835]639 relational_expression
640 | equality_expression EQ relational_expression
[d1625f8]641 { $$ = new ExpressionNode( build_binary_val( OperKinds::Eq, $1, $3 ) ); }
[4d51835]642 | equality_expression NE relational_expression
[d1625f8]643 { $$ = new ExpressionNode( build_binary_val( OperKinds::Neq, $1, $3 ) ); }
[4d51835]644 ;
[51b73452]645
646AND_expression:
[4d51835]647 equality_expression
648 | AND_expression '&' equality_expression
[d1625f8]649 { $$ = new ExpressionNode( build_binary_val( OperKinds::BitAnd, $1, $3 ) ); }
[4d51835]650 ;
[51b73452]651
652exclusive_OR_expression:
[4d51835]653 AND_expression
654 | exclusive_OR_expression '^' AND_expression
[d1625f8]655 { $$ = new ExpressionNode( build_binary_val( OperKinds::Xor, $1, $3 ) ); }
[4d51835]656 ;
[51b73452]657
658inclusive_OR_expression:
[4d51835]659 exclusive_OR_expression
660 | inclusive_OR_expression '|' exclusive_OR_expression
[d1625f8]661 { $$ = new ExpressionNode( build_binary_val( OperKinds::BitOr, $1, $3 ) ); }
[4d51835]662 ;
[51b73452]663
664logical_AND_expression:
[4d51835]665 inclusive_OR_expression
666 | logical_AND_expression ANDAND inclusive_OR_expression
[d1625f8]667 { $$ = new ExpressionNode( build_and_or( $1, $3, true ) ); }
[4d51835]668 ;
[51b73452]669
670logical_OR_expression:
[4d51835]671 logical_AND_expression
672 | logical_OR_expression OROR logical_AND_expression
[d1625f8]673 { $$ = new ExpressionNode( build_and_or( $1, $3, false ) ); }
[4d51835]674 ;
[51b73452]675
676conditional_expression:
[4d51835]677 logical_OR_expression
678 | logical_OR_expression '?' comma_expression ':' conditional_expression
[d1625f8]679 { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }
[d9e2280]680 // FIX ME: this hack computes $1 twice
[4d51835]681 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
[d1625f8]682 { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); }
[4d51835]683 ;
[51b73452]684
685constant_expression:
[4d51835]686 conditional_expression
687 ;
[51b73452]688
689assignment_expression:
[4d51835]690 // CFA, assignment is separated from assignment_operator to ensure no assignment operations for tuples
691 conditional_expression
692 | unary_expression assignment_operator assignment_expression
[cda7889]693 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
[4d51835]694 ;
[51b73452]695
696assignment_expression_opt:
[4d51835]697 // empty
[d1625f8]698 { $$ = nullptr; }
[4d51835]699 | assignment_expression
700 ;
[b87a5ed]701
[9706554]702assignment_operator:
[d9e2280]703 '=' { $$ = OperKinds::Assign; }
[a839867]704 | ATassign { $$ = OperKinds::AtAssn; }
[e5f2a67]705 | EXPassign { $$ = OperKinds::ExpAssn; }
[d9e2280]706 | MULTassign { $$ = OperKinds::MulAssn; }
707 | DIVassign { $$ = OperKinds::DivAssn; }
708 | MODassign { $$ = OperKinds::ModAssn; }
709 | PLUSassign { $$ = OperKinds::PlusAssn; }
710 | MINUSassign { $$ = OperKinds::MinusAssn; }
711 | LSassign { $$ = OperKinds::LSAssn; }
712 | RSassign { $$ = OperKinds::RSAssn; }
713 | ANDassign { $$ = OperKinds::AndAssn; }
714 | ERassign { $$ = OperKinds::ERAssn; }
715 | ORassign { $$ = OperKinds::OrAssn; }
[413ad05]716 ;
[9706554]717
[b87a5ed]718tuple: // CFA, tuple
[de62360d]719 // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with
[c0aa336]720 // comma_expression in cfa_identifier_parameter_array and cfa_abstract_array
[1b29996]721// '[' ']'
722// { $$ = new ExpressionNode( build_tuple() ); }
723// '[' push assignment_expression pop ']'
724// { $$ = new ExpressionNode( build_tuple( $3 ) ); }
725 '[' push ',' tuple_expression_list pop ']'
[1d4580a]726 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
[4d51835]727 | '[' push assignment_expression ',' tuple_expression_list pop ']'
[1d4580a]728 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
[4d51835]729 ;
[51b73452]730
731tuple_expression_list:
[4d51835]732 assignment_expression_opt
733 | tuple_expression_list ',' assignment_expression_opt
[1d4580a]734 { $$ = (ExpressionNode *)$1->set_last( $3 ); }
[4d51835]735 ;
[51b73452]736
737comma_expression:
[4d51835]738 assignment_expression
[9706554]739 | comma_expression ',' assignment_expression
[d1625f8]740 { $$ = new ExpressionNode( build_comma( $1, $3 ) ); }
[4d51835]741 ;
[51b73452]742
743comma_expression_opt:
[4d51835]744 // empty
[58dd019]745 { $$ = nullptr; }
[4d51835]746 | comma_expression
747 ;
[51b73452]748
[c11e31c]749//*************************** STATEMENTS *******************************
[51b73452]750
751statement:
[4d51835]752 labeled_statement
753 | compound_statement
754 | expression_statement { $$ = $1; }
755 | selection_statement
756 | iteration_statement
757 | jump_statement
[8b47e50]758 | with_statement
[5b2edbc]759 | waitfor_statement
[4d51835]760 | exception_statement
761 | asm_statement
[51b73452]762
763labeled_statement:
[44a81853]764 // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER
765 identifier_or_type_name ':' attribute_list_opt statement
[1db21619]766 {
[44a81853]767 $$ = $4->add_label( $1, $3 );
[1db21619]768 }
[4d51835]769 ;
[51b73452]770
771compound_statement:
[4d51835]772 '{' '}'
[e82aa9df]773 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
[4d51835]774 | '{'
[de62360d]775 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
[3a2128f]776 // requires its own scope.
[4d51835]777 push push
[51b1202]778 local_label_declaration_opt // GCC, local labels
[c0aa336]779 block_item_list // C99, intermix declarations and statements
780 pop '}'
[e82aa9df]781 { $$ = new StatementNode( build_compound( $5 ) ); }
[4d51835]782 ;
[b87a5ed]783
784block_item_list: // C99
[4d51835]785 block_item
786 | block_item_list push block_item
[1d4580a]787 { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
[4d51835]788 ;
[51b73452]789
790block_item:
[4d51835]791 declaration // CFA, new & old style declarations
[e82aa9df]792 { $$ = new StatementNode( $1 ); }
[4d51835]793 | EXTENSION declaration // GCC
[c0aa336]794 {
795 distExt( $2 );
[e82aa9df]796 $$ = new StatementNode( $2 );
[8e9cbb2]797 }
[4d51835]798 | function_definition
[e82aa9df]799 { $$ = new StatementNode( $1 ); }
[c0aa336]800 | EXTENSION function_definition // GCC
801 {
802 distExt( $2 );
803 $$ = new StatementNode( $2 );
804 }
[4d51835]805 | statement pop
806 ;
[51b73452]807
808statement_list:
[4d51835]809 statement
810 | statement_list statement
[1d4580a]811 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
[4d51835]812 ;
[51b73452]813
814expression_statement:
[4d51835]815 comma_expression_opt ';'
[e82aa9df]816 { $$ = new StatementNode( build_expr( $1 ) ); }
[4d51835]817 ;
[51b73452]818
819selection_statement:
[6d49ea3]820 IF '(' push if_control_expression ')' statement %prec THEN
[4d51835]821 // explicitly deal with the shift/reduce conflict on if/else
[6d49ea3]822 { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
823 | IF '(' push if_control_expression ')' statement ELSE statement
824 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
[4cc585b]825 | SWITCH '(' comma_expression ')' case_clause
[e82aa9df]826 { $$ = new StatementNode( build_switch( $3, $5 ) ); }
[4d51835]827 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
[4e06c1e]828 {
[e82aa9df]829 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
[4e06c1e]830 // The semantics of the declaration list is changed to include associated initialization, which is performed
831 // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
832 // statement around the switch. Statements after the initial declaration list can never be executed, and
[8688ce1]833 // therefore, are removed from the grammar even though C allows it. The change also applies to choose
834 // statement.
[a7741435]835 $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
[4e06c1e]836 }
[4d51835]837 | CHOOSE '(' comma_expression ')' case_clause // CFA
[e82aa9df]838 { $$ = new StatementNode( build_switch( $3, $5 ) ); }
[4d51835]839 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA
[4e06c1e]840 {
[e82aa9df]841 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
[a7741435]842 $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
[4e06c1e]843 }
[4d51835]844 ;
[b87a5ed]845
[936e9f4]846if_control_expression:
[6d49ea3]847 comma_expression pop
[936e9f4]848 { $$ = new IfCtl( nullptr, $1 ); }
[4cc585b]849 | c_declaration pop // no semi-colon
[936e9f4]850 { $$ = new IfCtl( $1, nullptr ); }
[4cc585b]851 | cfa_declaration pop // no semi-colon
[936e9f4]852 { $$ = new IfCtl( $1, nullptr ); }
[6d49ea3]853 | declaration comma_expression // semi-colon separated
[936e9f4]854 { $$ = new IfCtl( $1, $2 ); }
855 ;
856
[de62360d]857// CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case
858// clause allows a list of values and subranges.
[b87a5ed]859
860case_value: // CFA
[4d51835]861 constant_expression { $$ = $1; }
862 | constant_expression ELLIPSIS constant_expression // GCC, subrange
[d1625f8]863 { $$ = new ExpressionNode( build_range( $1, $3 ) ); }
[4d51835]864 | subrange // CFA, subrange
865 ;
[b87a5ed]866
867case_value_list: // CFA
[e82aa9df]868 case_value { $$ = new StatementNode( build_case( $1 ) ); }
[064e3ff]869 // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"
[e82aa9df]870 | case_value_list ',' case_value { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); }
[4d51835]871 ;
[b87a5ed]872
873case_label: // CFA
[8688ce1]874 CASE case_value_list ':' { $$ = $2; }
[e82aa9df]875 | DEFAULT ':' { $$ = new StatementNode( build_default() ); }
[4d51835]876 // A semantic check is required to ensure only one default clause per switch/choose statement.
877 ;
[b87a5ed]878
879case_label_list: // CFA
[4d51835]880 case_label
[1d4580a]881 | case_label_list case_label { $$ = (StatementNode *)( $1->set_last( $2 )); }
[4d51835]882 ;
[b87a5ed]883
884case_clause: // CFA
[e82aa9df]885 case_label_list statement { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
[4d51835]886 ;
[b87a5ed]887
888switch_clause_list_opt: // CFA
[4d51835]889 // empty
[58dd019]890 { $$ = nullptr; }
[4d51835]891 | switch_clause_list
892 ;
[b87a5ed]893
894switch_clause_list: // CFA
[4d51835]895 case_label_list statement_list
[e82aa9df]896 { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
[4d51835]897 | switch_clause_list case_label_list statement_list
[e82aa9df]898 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); }
[4d51835]899 ;
[b87a5ed]900
901choose_clause_list_opt: // CFA
[4d51835]902 // empty
[58dd019]903 { $$ = nullptr; }
[4d51835]904 | choose_clause_list
905 ;
[b87a5ed]906
907choose_clause_list: // CFA
[4d51835]908 case_label_list fall_through
[de62360d]909 { $$ = $1->append_last_case( $2 ); }
[4d51835]910 | case_label_list statement_list fall_through_opt
[e82aa9df]911 { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }
[4d51835]912 | choose_clause_list case_label_list fall_through
[1d4580a]913 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }
[4d51835]914 | choose_clause_list case_label_list statement_list fall_through_opt
[e82aa9df]915 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }
[4d51835]916 ;
[b87a5ed]917
918fall_through_opt: // CFA
[4d51835]919 // empty
[ab57786]920 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break
[4d51835]921 | fall_through
922 ;
[b87a5ed]923
924fall_through: // CFA
[4e06c1e]925 FALLTHRU
[58dd019]926 { $$ = nullptr; }
[4e06c1e]927 | FALLTHRU ';'
[58dd019]928 { $$ = nullptr; }
[4d51835]929 ;
[51b73452]930
931iteration_statement:
[4d51835]932 WHILE '(' comma_expression ')' statement
[e82aa9df]933 { $$ = new StatementNode( build_while( $3, $5 ) ); }
[4d51835]934 | DO statement WHILE '(' comma_expression ')' ';'
[5b639ee]935 { $$ = new StatementNode( build_while( $5, $2, true ) ); }
[4d51835]936 | FOR '(' push for_control_expression ')' statement
[e82aa9df]937 { $$ = new StatementNode( build_for( $4, $6 ) ); }
[4d51835]938 ;
[51b73452]939
940for_control_expression:
[4d51835]941 comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
[2f22cc4]942 { $$ = new ForCtl( $1, $4, $6 ); }
[4d51835]943 | declaration comma_expression_opt ';' comma_expression_opt // C99
[2f22cc4]944 { $$ = new ForCtl( $1, $2, $4 ); }
[d1625f8]945 ;
[51b73452]946
947jump_statement:
[44a81853]948 GOTO identifier_or_type_name ';'
[ab57786]949 { $$ = new StatementNode( build_branch( $2, BranchStmt::Goto ) ); }
[4d51835]950 | GOTO '*' comma_expression ';' // GCC, computed goto
[4e06c1e]951 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
[de62360d]952 // whereas normal operator precedence yields goto (*i)+3;
[e82aa9df]953 { $$ = new StatementNode( build_computedgoto( $3 ) ); }
[4d51835]954 | CONTINUE ';'
[de62360d]955 // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
[ab57786]956 { $$ = new StatementNode( build_branch( BranchStmt::Continue ) ); }
[44a81853]957 | CONTINUE identifier_or_type_name ';' // CFA, multi-level continue
[de62360d]958 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
959 // the target of the transfer appears only at the start of an iteration statement.
[ab57786]960 { $$ = new StatementNode( build_branch( $2, BranchStmt::Continue ) ); }
[4d51835]961 | BREAK ';'
[de62360d]962 // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
[ab57786]963 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); }
[44a81853]964 | BREAK identifier_or_type_name ';' // CFA, multi-level exit
[de62360d]965 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
966 // the target of the transfer appears only at the start of an iteration statement.
[ab57786]967 { $$ = new StatementNode( build_branch( $2, BranchStmt::Break ) ); }
[4d51835]968 | RETURN comma_expression_opt ';'
[e82aa9df]969 { $$ = new StatementNode( build_return( $2 ) ); }
[8cc5cb0]970 | THROW assignment_expression_opt ';' // handles rethrow
[e82aa9df]971 { $$ = new StatementNode( build_throw( $2 ) ); }
[8cc5cb0]972 | THROWRESUME assignment_expression_opt ';' // handles reresume
[daf1af8]973 { $$ = new StatementNode( build_resume( $2 ) ); }
[8cc5cb0]974 | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume
[daf1af8]975 { $$ = new StatementNode( build_resume_at( $2, $4 ) ); }
[4d51835]976 ;
[51b73452]977
[8b47e50]978with_statement:
[5b2edbc]979 WITH '(' tuple_expression_list ')' statement
980 { $$ = nullptr; } // FIX ME
981 ;
982
983when_clause_opt:
984 // empty
[135b431]985 { $$ = nullptr; }
[5b2edbc]986 | WHEN '(' comma_expression ')'
[135b431]987 { $$ = $3; }
[5b2edbc]988 ;
989
990waitfor:
991 WAITFOR '(' identifier ')'
[135b431]992 {
993 $$ = new ExpressionNode( new NameExpr( *$3 ) );
994 delete $3;
995 }
[5b2edbc]996 | WAITFOR '(' identifier ',' argument_expression_list ')'
[135b431]997 {
998 $$ = new ExpressionNode( new NameExpr( *$3 ) );
999 $$->set_last( $5 );
1000 delete $3;
1001 }
[5b2edbc]1002 ;
1003
1004timeout:
1005 TIMEOUT '(' comma_expression ')'
[135b431]1006 { $$ = $3; }
[5b2edbc]1007 ;
1008
1009waitfor_clause:
1010 when_clause_opt waitfor statement %prec THEN
[135b431]1011 { $$ = build_waitfor( $2, $3, $1 ); }
[5b2edbc]1012 | when_clause_opt waitfor statement WOR waitfor_clause
[135b431]1013 { $$ = build_waitfor( $2, $3, $1, $5 ); }
[5b2edbc]1014 | when_clause_opt timeout statement %prec THEN
[135b431]1015 { $$ = build_waitfor_timeout( $2, $3, $1 ); }
[5b2edbc]1016 | when_clause_opt ELSE statement
[135b431]1017 { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
[5b2edbc]1018 | when_clause_opt timeout statement WOR when_clause_opt ELSE statement
[135b431]1019 { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
[5b2edbc]1020 ;
1021
1022waitfor_statement:
1023 when_clause_opt waitfor statement %prec THEN
[135b431]1024 { $$ = new StatementNode( build_waitfor( $2, $3, $1 ) ); }
[5b2edbc]1025 | when_clause_opt waitfor statement WOR waitfor_clause
[135b431]1026 { $$ = new StatementNode( build_waitfor( $2, $3, $1, $5 ) ); }
[8b47e50]1027 ;
1028
[51b73452]1029exception_statement:
[cfaabe2c]1030 TRY compound_statement handler_clause
[e82aa9df]1031 { $$ = new StatementNode( build_try( $2, $3, 0 ) ); }
[4d51835]1032 | TRY compound_statement finally_clause
[e82aa9df]1033 { $$ = new StatementNode( build_try( $2, 0, $3 ) ); }
[cfaabe2c]1034 | TRY compound_statement handler_clause finally_clause
[e82aa9df]1035 { $$ = new StatementNode( build_try( $2, $3, $4 ) ); }
[4d51835]1036 ;
[51b73452]1037
1038handler_clause:
[cbce272]1039 handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
1040 { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); }
[dc2b4d6]1041 | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
[cbce272]1042 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); }
[994d080]1043 ;
1044
1045handler_predicate_opt:
1046 //empty
[cbce272]1047 { $$ = nullptr; }
[dc2b4d6]1048 | ';' conditional_expression
[cbce272]1049 { $$ = $2; }
[307a732]1050 ;
1051
1052handler_key:
1053 CATCH
1054 { $$ = CatchStmt::Terminate; }
1055 | CATCHRESUME
1056 { $$ = CatchStmt::Resume; }
[4d51835]1057 ;
[51b73452]1058
1059finally_clause:
[4d51835]1060 FINALLY compound_statement
1061 {
[e82aa9df]1062 $$ = new StatementNode( build_finally( $2 ) );
[4d51835]1063 }
1064 ;
[51b73452]1065
1066exception_declaration:
[d0ffed1]1067 // No SUE declaration in parameter list.
1068 type_specifier_nobody
1069 | type_specifier_nobody declarator
[4d51835]1070 {
1071 typedefTable.addToEnclosingScope( TypedefTable::ID );
1072 $$ = $2->addType( $1 );
1073 }
[d0ffed1]1074 | type_specifier_nobody variable_abstract_declarator
[4d51835]1075 { $$ = $2->addType( $1 ); }
[c0aa336]1076 | cfa_abstract_declarator_tuple no_attr_identifier // CFA
[4d51835]1077 {
1078 typedefTable.addToEnclosingScope( TypedefTable::ID );
1079 $$ = $1->addName( $2 );
1080 }
[c0aa336]1081 | cfa_abstract_declarator_tuple // CFA
[4d51835]1082 ;
[51b73452]1083
1084asm_statement:
[ab57786]1085 ASM asm_volatile_opt '(' string_literal ')' ';'
[e82aa9df]1086 { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
[ab57786]1087 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
[e82aa9df]1088 { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
[ab57786]1089 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'
[e82aa9df]1090 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
[ab57786]1091 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
[e82aa9df]1092 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
[ab57786]1093 | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
[e82aa9df]1094 { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
[7f5566b]1095 ;
1096
1097asm_volatile_opt: // GCC
1098 // empty
1099 { $$ = false; }
1100 | VOLATILE
1101 { $$ = true; }
[4d51835]1102 ;
[b87a5ed]1103
1104asm_operands_opt: // GCC
[4d51835]1105 // empty
[58dd019]1106 { $$ = nullptr; } // use default argument
[4d51835]1107 | asm_operands_list
1108 ;
[b87a5ed]1109
1110asm_operands_list: // GCC
[4d51835]1111 asm_operand
1112 | asm_operands_list ',' asm_operand
[1d4580a]1113 { $$ = (ExpressionNode *)$1->set_last( $3 ); }
[4d51835]1114 ;
[b87a5ed]1115
1116asm_operand: // GCC
[ab57786]1117 string_literal '(' constant_expression ')'
[e82aa9df]1118 { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
[ab57786]1119 | '[' constant_expression ']' string_literal '(' constant_expression ')'
[1b772749]1120 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
[7f5566b]1121 ;
1122
[4e06c1e]1123asm_clobbers_list_opt: // GCC
[7f5566b]1124 // empty
[58dd019]1125 { $$ = nullptr; } // use default argument
[ab57786]1126 | string_literal
[d1625f8]1127 { $$ = new ExpressionNode( $1 ); }
[ab57786]1128 | asm_clobbers_list_opt ',' string_literal
[a7741435]1129 // set_last return ParseNode *
[e82aa9df]1130 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
[4d51835]1131 ;
[b87a5ed]1132
[7f5566b]1133label_list:
1134 no_attr_identifier
[ab57786]1135 {
1136 $$ = new LabelNode(); $$->labels.push_back( *$1 );
1137 delete $1; // allocated by lexer
1138 }
[7f5566b]1139 | label_list ',' no_attr_identifier
[ab57786]1140 {
1141 $$ = $1; $1->labels.push_back( *$3 );
1142 delete $3; // allocated by lexer
1143 }
[4d51835]1144 ;
[51b73452]1145
[c11e31c]1146//******************************* DECLARATIONS *********************************
[51b73452]1147
[b87a5ed]1148declaration_list_opt: // used at beginning of switch statement
[4d51835]1149 pop
[58dd019]1150 { $$ = nullptr; }
[4d51835]1151 | declaration_list
1152 ;
[51b73452]1153
1154declaration_list:
[4d51835]1155 declaration
1156 | declaration_list push declaration
1157 { $$ = $1->appendList( $3 ); }
1158 ;
[51b73452]1159
[c0aa336]1160KR_declaration_list_opt: // used to declare parameter types in K&R style functions
[4cc585b]1161 // empty
[58dd019]1162 { $$ = nullptr; }
[c0aa336]1163 | KR_declaration_list
[4d51835]1164 ;
[51b73452]1165
[c0aa336]1166KR_declaration_list:
[4cc585b]1167 push c_declaration pop ';'
1168 { $$ = $2; }
1169 | KR_declaration_list push c_declaration pop ';'
[4d51835]1170 { $$ = $1->appendList( $3 ); }
1171 ;
[b87a5ed]1172
[51b1202]1173local_label_declaration_opt: // GCC, local label
[4d51835]1174 // empty
[51b1202]1175 | local_label_declaration_list
[4d51835]1176 ;
[b87a5ed]1177
[51b1202]1178local_label_declaration_list: // GCC, local label
1179 LABEL local_label_list ';'
1180 | local_label_declaration_list LABEL local_label_list ';'
[4d51835]1181 ;
[b87a5ed]1182
[51b1202]1183local_label_list: // GCC, local label
[7f5566b]1184 no_attr_identifier_or_type_name {}
[51b1202]1185 | local_label_list ',' no_attr_identifier_or_type_name {}
[4d51835]1186 ;
[b87a5ed]1187
[936e9f4]1188declaration: // old & new style declarations
[4cc585b]1189 c_declaration pop ';'
1190 | cfa_declaration pop ';' // CFA
[4d51835]1191 ;
[b87a5ed]1192
[de62360d]1193// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
1194// declarations. CFA declarations use the same declaration tokens as in C; however, CFA places declaration modifiers to
1195// the left of the base type, while C declarations place modifiers to the right of the base type. CFA declaration
1196// modifiers are interpreted from left to right and the entire type specification is distributed across all variables in
1197// the declaration list (as in Pascal). ANSI C and the new CFA declarations may appear together in the same program
1198// block, but cannot be mixed within a specific declaration.
[c11e31c]1199//
[b87a5ed]1200// CFA C
1201// [10] int x; int x[10]; // array of 10 integers
1202// [10] * char y; char *y[10]; // array of 10 pointers to char
1203
[c0aa336]1204cfa_declaration: // CFA
[4cc585b]1205 cfa_variable_declaration
1206 | cfa_typedef_declaration
1207 | cfa_function_declaration
1208 | type_declaring_list
1209 | trait_specifier
[4d51835]1210 ;
[b87a5ed]1211
[c0aa336]1212cfa_variable_declaration: // CFA
1213 cfa_variable_specifier initializer_opt
[4d51835]1214 {
1215 typedefTable.addToEnclosingScope( TypedefTable::ID );
[3cfe27f]1216 $$ = $1->addInitializer( $2 );
[4d51835]1217 }
[c0aa336]1218 | declaration_qualifier_list cfa_variable_specifier initializer_opt
[de62360d]1219 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude
1220 // them as a type_qualifier cannot appear in that context.
[4d51835]1221 {
1222 typedefTable.addToEnclosingScope( TypedefTable::ID );
[3cfe27f]1223 $$ = $2->addQualifiers( $1 )->addInitializer( $3 );;
[4d51835]1224 }
[c0aa336]1225 | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
[4d51835]1226 {
1227 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
[3cfe27f]1228 $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) );
[4d51835]1229 }
1230 ;
[b87a5ed]1231
[c0aa336]1232cfa_variable_specifier: // CFA
[de62360d]1233 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
1234 // storage-class
[c0aa336]1235 cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
[4d51835]1236 {
1237 typedefTable.setNextIdentifier( *$2 );
[58dd019]1238 $$ = $1->addName( $2 )->addAsmName( $3 );
[4d51835]1239 }
[c0aa336]1240 | cfa_abstract_tuple identifier_or_type_name asm_name_opt
[4d51835]1241 {
1242 typedefTable.setNextIdentifier( *$2 );
[58dd019]1243 $$ = $1->addName( $2 )->addAsmName( $3 );
[4d51835]1244 }
[c0aa336]1245 | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt
[4d51835]1246 {
1247 typedefTable.setNextIdentifier( *$3 );
[58dd019]1248 $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 );
[4d51835]1249 }
1250 ;
[b87a5ed]1251
[c0aa336]1252cfa_function_declaration: // CFA
1253 cfa_function_specifier
[4d51835]1254 {
1255 typedefTable.addToEnclosingScope( TypedefTable::ID );
1256 $$ = $1;
1257 }
[c0aa336]1258 | type_qualifier_list cfa_function_specifier
[4d51835]1259 {
1260 typedefTable.addToEnclosingScope( TypedefTable::ID );
1261 $$ = $2->addQualifiers( $1 );
1262 }
[c0aa336]1263 | declaration_qualifier_list cfa_function_specifier
[4d51835]1264 {
1265 typedefTable.addToEnclosingScope( TypedefTable::ID );
1266 $$ = $2->addQualifiers( $1 );
1267 }
[c0aa336]1268 | declaration_qualifier_list type_qualifier_list cfa_function_specifier
[4d51835]1269 {
1270 typedefTable.addToEnclosingScope( TypedefTable::ID );
1271 $$ = $3->addQualifiers( $1 )->addQualifiers( $2 );
1272 }
[c0aa336]1273 | cfa_function_declaration pop ',' push identifier_or_type_name
[4d51835]1274 {
1275 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
1276 $$ = $1->appendList( $1->cloneType( $5 ) );
1277 }
1278 ;
[b87a5ed]1279
[c0aa336]1280cfa_function_specifier: // CFA
1281// '[' ']' identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' // S/R conflict
[1b29996]1282// {
1283// $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
1284// }
[c0aa336]1285// '[' ']' identifier '(' push cfa_parameter_type_list_opt pop ')'
[2871210]1286// {
1287// typedefTable.setNextIdentifier( *$5 );
1288// $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
1289// }
[c0aa336]1290// | '[' ']' TYPEDEFname '(' push cfa_parameter_type_list_opt pop ')'
[2871210]1291// {
1292// typedefTable.setNextIdentifier( *$5 );
1293// $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
1294// }
1295// | '[' ']' typegen_name
1296 // identifier_or_type_name must be broken apart because of the sequence:
[4d51835]1297 //
[c0aa336]1298 // '[' ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
[4d51835]1299 // '[' ']' type_specifier
1300 //
[2871210]1301 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
1302 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
[c0aa336]1303 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
1304 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
[4d51835]1305 {
1306 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
1307 }
[c0aa336]1308 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
[4d51835]1309 {
1310 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true );
1311 }
1312 ;
[b87a5ed]1313
[c0aa336]1314cfa_function_return: // CFA
1315 '[' push cfa_parameter_list pop ']'
[4d51835]1316 { $$ = DeclarationNode::newTuple( $3 ); }
[c0aa336]1317 | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
1318 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the
[de62360d]1319 // ']'.
[4d51835]1320 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
1321 ;
[b87a5ed]1322
[c0aa336]1323cfa_typedef_declaration: // CFA
1324 TYPEDEF cfa_variable_specifier
[4d51835]1325 {
[de62360d]1326 typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1327 $$ = $2->addTypedef();
1328 }
[c0aa336]1329 | TYPEDEF cfa_function_specifier
[4d51835]1330 {
[de62360d]1331 typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1332 $$ = $2->addTypedef();
1333 }
[c0aa336]1334 | cfa_typedef_declaration pop ',' push no_attr_identifier
[4d51835]1335 {
[de62360d]1336 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
[4d51835]1337 $$ = $1->appendList( $1->cloneType( $5 ) );
1338 }
1339 ;
[b87a5ed]1340
[de62360d]1341// Traditionally typedef is part of storage-class specifier for syntactic convenience only. Here, it is factored out as
1342// a separate form of declaration, which syntactically precludes storage-class specifiers and initialization.
[51b73452]1343
1344typedef_declaration:
[4d51835]1345 TYPEDEF type_specifier declarator
1346 {
[de62360d]1347 typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1348 $$ = $3->addType( $2 )->addTypedef();
1349 }
1350 | typedef_declaration pop ',' push declarator
1351 {
[de62360d]1352 typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1353 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
1354 }
[de62360d]1355 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
[4d51835]1356 {
[de62360d]1357 typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1358 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
1359 }
1360 | type_specifier TYPEDEF declarator
1361 {
[de62360d]1362 typedefTable.addToEnclosingScope( TypedefTable::TD );
[4d51835]1363 $$ = $3->addType( $1 )->addTypedef();
1364 }
1365 | type_specifier TYPEDEF type_qualifier_list declarator
1366 {
[de62360d]1367 typedefTable.addToEnclosingScope( TypedefTable::TD );
1368 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
[4d51835]1369 }
1370 ;
[b87a5ed]1371
[721f17a]1372typedef_expression:
1373 // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
[4d51835]1374 TYPEDEF no_attr_identifier '=' assignment_expression
1375 {
[de62360d]1376 typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );
[c0aa336]1377 $$ = DeclarationNode::newName( 0 ); // unimplemented
[4d51835]1378 }
1379 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
1380 {
[de62360d]1381 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
[c0aa336]1382 $$ = DeclarationNode::newName( 0 ); // unimplemented
[4d51835]1383 }
1384 ;
[51b73452]1385
[c0aa336]1386//c_declaration:
1387// declaring_list pop ';'
1388// | typedef_declaration pop ';'
1389// | typedef_expression pop ';' // GCC, naming expression type
1390// | sue_declaration_specifier pop ';'
1391// ;
1392//
1393//declaring_list:
1394// // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
1395// // storage-class
1396// declarator asm_name_opt initializer_opt
1397// {
1398// typedefTable.addToEnclosingScope( TypedefTable::ID );
1399// $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 );
1400// }
1401// | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
1402// {
1403// typedefTable.addToEnclosingScope( TypedefTable::ID );
1404// $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) );
1405// }
1406// ;
1407
1408c_declaration:
[4cc585b]1409 declaration_specifier declaring_list
[c0aa336]1410 {
1411 $$ = distAttr( $1, $2 );
1412 }
[4cc585b]1413 | typedef_declaration
1414 | typedef_expression // GCC, naming expression type
1415 | sue_declaration_specifier
[4d51835]1416 ;
[51b73452]1417
1418declaring_list:
[de62360d]1419 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
1420 // storage-class
[c0aa336]1421 declarator asm_name_opt initializer_opt
[4d51835]1422 {
1423 typedefTable.addToEnclosingScope( TypedefTable::ID );
[c0aa336]1424 $$ = $1->addAsmName( $2 )->addInitializer( $3 );
[4d51835]1425 }
1426 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
1427 {
1428 typedefTable.addToEnclosingScope( TypedefTable::ID );
[c0aa336]1429 $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) );
[4d51835]1430 }
1431 ;
[b87a5ed]1432
1433declaration_specifier: // type specifier + storage class
[4d51835]1434 basic_declaration_specifier
1435 | sue_declaration_specifier
[84d58c5]1436 | type_declaration_specifier
[4d51835]1437 ;
[b87a5ed]1438
[d0ffed1]1439declaration_specifier_nobody: // type specifier + storage class - {...}
1440 // Preclude SUE declarations in restricted scopes:
1441 //
1442 // int f( struct S { int i; } s1, Struct S s2 ) { struct S s3; ... }
1443 //
1444 // because it is impossible to call f due to name equivalence.
1445 basic_declaration_specifier
1446 | sue_declaration_specifier_nobody
[84d58c5]1447 | type_declaration_specifier
[d0ffed1]1448 ;
1449
1450type_specifier: // type specifier
[4d51835]1451 basic_type_specifier
1452 | sue_type_specifier
[84d58c5]1453 | type_type_specifier
[4d51835]1454 ;
[b87a5ed]1455
[d0ffed1]1456type_specifier_nobody: // type specifier - {...}
1457 // Preclude SUE declarations in restricted scopes:
1458 //
1459 // int f( struct S { int i; } s1, Struct S s2 ) { struct S s3; ... }
1460 //
1461 // because it is impossible to call f due to name equivalence.
1462 basic_type_specifier
1463 | sue_type_specifier_nobody
[84d58c5]1464 | type_type_specifier
[d0ffed1]1465 ;
1466
[b87a5ed]1467type_qualifier_list_opt: // GCC, used in asm_statement
[4d51835]1468 // empty
[58dd019]1469 { $$ = nullptr; }
[4d51835]1470 | type_qualifier_list
1471 ;
[51b73452]1472
1473type_qualifier_list:
[de62360d]1474 // A semantic check is necessary to ensure a type qualifier is appropriate for the kind of declaration.
[4d51835]1475 //
[de62360d]1476 // ISO/IEC 9899:1999 Section 6.7.3(4 ) : If the same qualifier appears more than once in the same
1477 // specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it
1478 // appeared only once.
[4d51835]1479 type_qualifier
1480 | type_qualifier_list type_qualifier
1481 { $$ = $1->addQualifiers( $2 ); }
1482 ;
[51b73452]1483
1484type_qualifier:
[4d51835]1485 type_qualifier_name
1486 | attribute
1487 ;
[51b73452]1488
1489type_qualifier_name:
[4d51835]1490 CONST
[738e304]1491 { $$ = DeclarationNode::newTypeQualifier( Type::Const ); }
[4d51835]1492 | RESTRICT
[738e304]1493 { $$ = DeclarationNode::newTypeQualifier( Type::Restrict ); }
[4d51835]1494 | VOLATILE
[738e304]1495 { $$ = DeclarationNode::newTypeQualifier( Type::Volatile ); }
[a7c90d4]1496 | MUTEX
[738e304]1497 { $$ = DeclarationNode::newTypeQualifier( Type::Mutex ); }
[4d51835]1498 | ATOMIC
[738e304]1499 { $$ = DeclarationNode::newTypeQualifier( Type::Atomic ); }
[4d51835]1500 | FORALL '('
1501 {
1502 typedefTable.enterScope();
1503 }
1504 type_parameter_list ')' // CFA
1505 {
1506 typedefTable.leaveScope();
1507 $$ = DeclarationNode::newForall( $4 );
1508 }
1509 ;
[51b73452]1510
1511declaration_qualifier_list:
[4d51835]1512 storage_class_list
[de62360d]1513 | type_qualifier_list storage_class_list // remaining OBSOLESCENT (see 2 )
[4d51835]1514 { $$ = $1->addQualifiers( $2 ); }
1515 | declaration_qualifier_list type_qualifier_list storage_class_list
1516 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1517 ;
[51b73452]1518
1519storage_class_list:
[de62360d]1520 // A semantic check is necessary to ensure a storage class is appropriate for the kind of declaration and that
1521 // only one of each is specified, except for inline, which can appear with the others.
[4d51835]1522 //
[de62360d]1523 // ISO/IEC 9899:1999 Section 6.7.1(2) : At most, one storage-class specifier may be given in the declaration
1524 // specifiers in a declaration.
[4d51835]1525 storage_class
1526 | storage_class_list storage_class
1527 { $$ = $1->addQualifiers( $2 ); }
1528 ;
[51b73452]1529
1530storage_class:
[4d51835]1531 EXTERN
[68fe077a]1532 { $$ = DeclarationNode::newStorageClass( Type::Extern ); }
[4d51835]1533 | STATIC
[68fe077a]1534 { $$ = DeclarationNode::newStorageClass( Type::Static ); }
[4d51835]1535 | AUTO
[68fe077a]1536 { $$ = DeclarationNode::newStorageClass( Type::Auto ); }
[4d51835]1537 | REGISTER
[68fe077a]1538 { $$ = DeclarationNode::newStorageClass( Type::Register ); }
[dd020c0]1539 | THREADLOCAL // C11
[68fe077a]1540 { $$ = DeclarationNode::newStorageClass( Type::Threadlocal ); }
[dd020c0]1541 // Put function specifiers here to simplify parsing rules, but separate them semantically.
[4d51835]1542 | INLINE // C99
[ddfd945]1543 { $$ = DeclarationNode::newFuncSpecifier( Type::Inline ); }
[4d51835]1544 | FORTRAN // C99
[ddfd945]1545 { $$ = DeclarationNode::newFuncSpecifier( Type::Fortran ); }
[68cd1ce]1546 | NORETURN // C11
[ddfd945]1547 { $$ = DeclarationNode::newFuncSpecifier( Type::Noreturn ); }
[4d51835]1548 ;
[51b73452]1549
1550basic_type_name:
[4d51835]1551 CHAR
1552 { $$ = DeclarationNode::newBasicType( DeclarationNode::Char ); }
1553 | DOUBLE
1554 { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); }
1555 | FLOAT
1556 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
1557 | INT
1558 { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
1559 | LONG
[5b639ee]1560 { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
[4d51835]1561 | SHORT
[5b639ee]1562 { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }
[4d51835]1563 | SIGNED
[5b639ee]1564 { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); }
[4d51835]1565 | UNSIGNED
[5b639ee]1566 { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); }
[4d51835]1567 | VOID
1568 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
1569 | BOOL // C99
1570 { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
1571 | COMPLEX // C99
[5b639ee]1572 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
[4d51835]1573 | IMAGINARY // C99
[5b639ee]1574 { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
[3a2128f]1575 | ZERO_T
[148f7290]1576 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }
[3a2128f]1577 | ONE_T
[148f7290]1578 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }
[72457b6]1579 | VALIST // GCC, __builtin_va_list
1580 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
[4d51835]1581 ;
[51b73452]1582
1583basic_declaration_specifier:
[4d51835]1584 // A semantic check is necessary for conflicting storage classes.
1585 basic_type_specifier
1586 | declaration_qualifier_list basic_type_specifier
1587 { $$ = $2->addQualifiers( $1 ); }
1588 | basic_declaration_specifier storage_class // remaining OBSOLESCENT (see 2)
1589 { $$ = $1->addQualifiers( $2 ); }
1590 | basic_declaration_specifier storage_class type_qualifier_list
1591 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1592 | basic_declaration_specifier storage_class basic_type_specifier
1593 { $$ = $3->addQualifiers( $2 )->addType( $1 ); }
1594 ;
[51b73452]1595
1596basic_type_specifier:
[84d58c5]1597 direct_type
1598 | type_qualifier_list_opt indirect_type type_qualifier_list_opt
[4d51835]1599 { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); }
1600 ;
[51b73452]1601
[84d58c5]1602direct_type:
[4d51835]1603 // A semantic check is necessary for conflicting type qualifiers.
1604 basic_type_name
1605 | type_qualifier_list basic_type_name
1606 { $$ = $2->addQualifiers( $1 ); }
[84d58c5]1607 | direct_type type_qualifier
[4d51835]1608 { $$ = $1->addQualifiers( $2 ); }
[84d58c5]1609 | direct_type basic_type_name
[4d51835]1610 { $$ = $1->addType( $2 ); }
1611 ;
[51b73452]1612
[84d58c5]1613indirect_type:
1614 TYPEOF '(' type ')' // GCC: typeof(x) y;
[4d51835]1615 { $$ = $3; }
1616 | TYPEOF '(' comma_expression ')' // GCC: typeof(a+b) y;
1617 { $$ = DeclarationNode::newTypeof( $3 ); }
[84d58c5]1618 | ATTR_TYPEGENname '(' type ')' // CFA: e.g., @type(x) y;
[4d51835]1619 { $$ = DeclarationNode::newAttr( $1, $3 ); }
1620 | ATTR_TYPEGENname '(' comma_expression ')' // CFA: e.g., @type(a+b) y;
1621 { $$ = DeclarationNode::newAttr( $1, $3 ); }
1622 ;
[51b73452]1623
[d0ffed1]1624sue_declaration_specifier: // struct, union, enum + storage class + type specifier
[4d51835]1625 sue_type_specifier
1626 | declaration_qualifier_list sue_type_specifier
1627 { $$ = $2->addQualifiers( $1 ); }
1628 | sue_declaration_specifier storage_class // remaining OBSOLESCENT (see 2)
1629 { $$ = $1->addQualifiers( $2 ); }
1630 | sue_declaration_specifier storage_class type_qualifier_list
1631 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1632 ;
[51b73452]1633
[d0ffed1]1634sue_type_specifier: // struct, union, enum + type specifier
1635 elaborated_type
[fdca7c6]1636 | type_qualifier_list
1637 { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
1638 elaborated_type
1639 { $$ = $3->addQualifiers( $1 ); }
[4d51835]1640 | sue_type_specifier type_qualifier
1641 { $$ = $1->addQualifiers( $2 ); }
1642 ;
[51b73452]1643
[d0ffed1]1644sue_declaration_specifier_nobody: // struct, union, enum - {...} + storage class + type specifier
1645 sue_type_specifier_nobody
1646 | declaration_qualifier_list sue_type_specifier_nobody
1647 { $$ = $2->addQualifiers( $1 ); }
1648 | sue_declaration_specifier_nobody storage_class // remaining OBSOLESCENT (see 2)
1649 { $$ = $1->addQualifiers( $2 ); }
1650 | sue_declaration_specifier_nobody storage_class type_qualifier_list
1651 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1652 ;
1653
1654sue_type_specifier_nobody: // struct, union, enum - {...} + type specifier
1655 elaborated_type_nobody
1656 | type_qualifier_list elaborated_type_nobody
1657 { $$ = $2->addQualifiers( $1 ); }
1658 | sue_type_specifier_nobody type_qualifier
1659 { $$ = $1->addQualifiers( $2 ); }
1660 ;
1661
[84d58c5]1662type_declaration_specifier:
1663 type_type_specifier
1664 | declaration_qualifier_list type_type_specifier
[4d51835]1665 { $$ = $2->addQualifiers( $1 ); }
[84d58c5]1666 | type_declaration_specifier storage_class // remaining OBSOLESCENT (see 2)
[4d51835]1667 { $$ = $1->addQualifiers( $2 ); }
[84d58c5]1668 | type_declaration_specifier storage_class type_qualifier_list
[4d51835]1669 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }
1670 ;
[b87a5ed]1671
[84d58c5]1672type_type_specifier: // typedef types
1673 type_name
1674 | type_qualifier_list type_name
1675 { $$ = $2->addQualifiers( $1 ); }
1676 | type_type_specifier type_qualifier
1677 { $$ = $1->addQualifiers( $2 ); }
1678 ;
1679
1680type_name:
[4d51835]1681 TYPEDEFname
1682 { $$ = DeclarationNode::newFromTypedef( $1 ); }
[84d58c5]1683 | '.' TYPEDEFname
1684 { $$ = DeclarationNode::newFromTypedef( $2 ); } // FIX ME
1685 | type_name '.' TYPEDEFname
1686 { $$ = DeclarationNode::newFromTypedef( $3 ); } // FIX ME
1687 | typegen_name
1688 | '.' typegen_name
1689 { $$ = $2; } // FIX ME
1690 | type_name '.' typegen_name
1691 { $$ = $3; } // FIX ME
1692 ;
1693
1694typegen_name: // CFA
[67cf18c]1695 TYPEGENname '(' ')'
1696 { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
1697 | TYPEGENname '(' type_list ')'
[84d58c5]1698 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }
[4d51835]1699 ;
[51b73452]1700
[d0ffed1]1701elaborated_type: // struct, union, enum
[c0aa336]1702 aggregate_type
1703 | enum_type
[4d51835]1704 ;
[51b73452]1705
[d0ffed1]1706elaborated_type_nobody: // struct, union, enum - {...}
1707 aggregate_type_nobody
1708 | enum_type_nobody
1709 ;
1710
1711aggregate_type: // struct, union
[c0aa336]1712 aggregate_key attribute_list_opt '{' field_declaration_list '}'
[6f95000]1713 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
[c0aa336]1714 | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
[fdca7c6]1715 {
1716 typedefTable.makeTypedef( *$3 ); // create typedef
1717 if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update
1718 forall = false; // reset
1719 }
[c0aa336]1720 '{' field_declaration_list '}'
1721 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
[84d58c5]1722 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA
[6f95000]1723 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
[d0ffed1]1724 | aggregate_type_nobody
1725 ;
1726
1727aggregate_type_nobody: // struct, union - {...}
[84d58c5]1728 aggregate_key attribute_list_opt no_attr_identifier
1729 {
1730 typedefTable.makeTypedef( *$3 );
1731 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
1732 }
1733 | aggregate_key attribute_list_opt TYPEDEFname
[d0ffed1]1734 {
1735 typedefTable.makeTypedef( *$3 );
1736 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
1737 }
[84d58c5]1738 | aggregate_key attribute_list_opt typegen_name // CFA
[c0aa336]1739 { $$ = $3->addQualifiers( $2 ); }
[4d51835]1740 ;
[51b73452]1741
1742aggregate_key:
[c0aa336]1743 STRUCT
[4d51835]1744 { $$ = DeclarationNode::Struct; }
[c0aa336]1745 | UNION
[4d51835]1746 { $$ = DeclarationNode::Union; }
[d3bc0ad]1747 | COROUTINE
[409433da]1748 { $$ = DeclarationNode::Coroutine; }
[d3bc0ad]1749 | MONITOR
[409433da]1750 { $$ = DeclarationNode::Monitor; }
[d3bc0ad]1751 | THREAD
[409433da]1752 { $$ = DeclarationNode::Thread; }
[4d51835]1753 ;
[51b73452]1754
1755field_declaration_list:
[5d125e4]1756 // empty
[58dd019]1757 { $$ = nullptr; }
[4d51835]1758 | field_declaration_list field_declaration
[a7741435]1759 { $$ = $1 ? $1->appendList( $2 ) : $2; }
[4d51835]1760 ;
[51b73452]1761
1762field_declaration:
[c0aa336]1763 cfa_field_declaring_list ';' // CFA, new style field declaration
1764 | EXTENSION cfa_field_declaring_list ';' // GCC
1765 {
1766 distExt( $2 ); // mark all fields in list
[8e9cbb2]1767 $$ = $2;
1768 }
[c0aa336]1769 | type_specifier field_declaring_list ';'
1770 {
1771 $$ = distAttr( $1, $2 ); }
1772 | EXTENSION type_specifier field_declaring_list ';' // GCC
1773 {
1774 distExt( $3 ); // mark all fields in list
1775 $$ = distAttr( $2, $3 );
1776 }
[4d51835]1777 ;
[b87a5ed]1778
[c0aa336]1779cfa_field_declaring_list: // CFA, new style field declaration
1780 cfa_abstract_declarator_tuple // CFA, no field name
1781 | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name
[4d51835]1782 { $$ = $1->addName( $2 ); }
[c0aa336]1783 | cfa_field_declaring_list ',' no_attr_identifier_or_type_name
[4d51835]1784 { $$ = $1->appendList( $1->cloneType( $3 ) ); }
[c0aa336]1785 | cfa_field_declaring_list ',' // CFA, no field name
[4d51835]1786 { $$ = $1->appendList( $1->cloneType( 0 ) ); }
1787 ;
[51b73452]1788
1789field_declaring_list:
[c0aa336]1790 field_declarator
[4d51835]1791 | field_declaring_list ',' attribute_list_opt field_declarator
[c0aa336]1792 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
[4d51835]1793 ;
[51b73452]1794
1795field_declarator:
[4d51835]1796 // empty
1797 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
[6f95000]1798 // '@'
1799 // { $$ = DeclarationNode::newName( new string( DeclarationNode::anonymous.newName() ) ); } // CFA, no field name
[4d51835]1800 | bit_subrange_size // no field name
1801 { $$ = DeclarationNode::newBitfield( $1 ); }
1802 | variable_declarator bit_subrange_size_opt
1803 // A semantic check is required to ensure bit_subrange only appears on base type int.
1804 { $$ = $1->addBitfield( $2 ); }
[c6b1105]1805 | variable_type_redeclarator bit_subrange_size_opt
[4d51835]1806 // A semantic check is required to ensure bit_subrange only appears on base type int.
1807 { $$ = $1->addBitfield( $2 ); }
1808 | variable_abstract_declarator // CFA, no field name
1809 ;
[51b73452]1810
1811bit_subrange_size_opt:
[4d51835]1812 // empty
[58dd019]1813 { $$ = nullptr; }
[4d51835]1814 | bit_subrange_size
1815 { $$ = $1; }
1816 ;
[51b73452]1817
1818bit_subrange_size:
[4d51835]1819 ':' constant_expression
1820 { $$ = $2; }
1821 ;
[51b73452]1822
[d0ffed1]1823enum_type: // enum
[c0aa336]1824 ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
[6f95000]1825 { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }
[c0aa336]1826 | ENUM attribute_list_opt no_attr_identifier_or_type_name
[d0ffed1]1827 { typedefTable.makeTypedef( *$3 ); }
1828 '{' enumerator_list comma_opt '}'
1829 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
1830 | enum_type_nobody
1831 ;
1832
1833enum_type_nobody: // enum - {...}
1834 ENUM attribute_list_opt no_attr_identifier_or_type_name
[45161b4d]1835 {
[c0aa336]1836 typedefTable.makeTypedef( *$3 );
[ca1a547]1837 $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 );
[45161b4d]1838 }
[4d51835]1839 ;
[51b73452]1840
1841enumerator_list:
[2871210]1842 no_attr_identifier_or_type_name enumerator_value_opt
[4d51835]1843 { $$ = DeclarationNode::newEnumConstant( $1, $2 ); }
[2871210]1844 | enumerator_list ',' no_attr_identifier_or_type_name enumerator_value_opt
[4d51835]1845 { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); }
1846 ;
[51b73452]1847
1848enumerator_value_opt:
[4d51835]1849 // empty
[58dd019]1850 { $$ = nullptr; }
[4d51835]1851 | '=' constant_expression
1852 { $$ = $2; }
1853 ;
[51b73452]1854
[c11e31c]1855// Minimum of one parameter after which ellipsis is allowed only at the end.
[51b73452]1856
[c0aa336]1857cfa_parameter_type_list_opt: // CFA
[4d51835]1858 // empty
[58dd019]1859 { $$ = nullptr; }
[c0aa336]1860 | cfa_parameter_type_list
[4d51835]1861 ;
[b87a5ed]1862
[c0aa336]1863cfa_parameter_type_list: // CFA, abstract + real
1864 cfa_abstract_parameter_list
1865 | cfa_parameter_list
1866 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list
[4d51835]1867 { $$ = $1->appendList( $5 ); }
[c0aa336]1868 | cfa_abstract_parameter_list pop ',' push ELLIPSIS
[4d51835]1869 { $$ = $1->addVarArgs(); }
[c0aa336]1870 | cfa_parameter_list pop ',' push ELLIPSIS
[4d51835]1871 { $$ = $1->addVarArgs(); }
1872 ;
[b87a5ed]1873
[c0aa336]1874cfa_parameter_list: // CFA
1875 // To obtain LR(1) between cfa_parameter_list and cfa_abstract_tuple, the last cfa_abstract_parameter_list is
1876 // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'.
1877 cfa_parameter_declaration
1878 | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
[4d51835]1879 { $$ = $1->appendList( $5 ); }
[c0aa336]1880 | cfa_parameter_list pop ',' push cfa_parameter_declaration
[4d51835]1881 { $$ = $1->appendList( $5 ); }
[c0aa336]1882 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
[4d51835]1883 { $$ = $1->appendList( $5 )->appendList( $9 ); }
1884 ;
[b87a5ed]1885
[c0aa336]1886cfa_abstract_parameter_list: // CFA, new & old style abstract
1887 cfa_abstract_parameter_declaration
1888 | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration
[4d51835]1889 { $$ = $1->appendList( $5 ); }
1890 ;
[51b73452]1891
1892parameter_type_list_opt:
[4d51835]1893 // empty
[58dd019]1894 { $$ = nullptr; }
[4d51835]1895 | parameter_type_list
1896 ;
[51b73452]1897
1898parameter_type_list:
[4d51835]1899 parameter_list
1900 | parameter_list pop ',' push ELLIPSIS
1901 { $$ = $1->addVarArgs(); }
1902 ;
[b87a5ed]1903
1904parameter_list: // abstract + real
[4d51835]1905 abstract_parameter_declaration
1906 | parameter_declaration
1907 | parameter_list pop ',' push abstract_parameter_declaration
1908 { $$ = $1->appendList( $5 ); }
1909 | parameter_list pop ',' push parameter_declaration
1910 { $$ = $1->appendList( $5 ); }
1911 ;
[51b73452]1912
[de62360d]1913// Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics
[2871210]1914// for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes.
[51b73452]1915
[c0aa336]1916cfa_parameter_declaration: // CFA, new & old style parameter declaration
[4d51835]1917 parameter_declaration
[994d080]1918 | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name default_initialize_opt
[4d51835]1919 { $$ = $1->addName( $2 ); }
[994d080]1920 | cfa_abstract_tuple identifier_or_type_name default_initialize_opt
[c0aa336]1921 // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
[4d51835]1922 { $$ = $1->addName( $2 ); }
[994d080]1923 | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initialize_opt
[4d51835]1924 { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
[c0aa336]1925 | cfa_function_specifier
[4d51835]1926 ;
[b87a5ed]1927
[c0aa336]1928cfa_abstract_parameter_declaration: // CFA, new & old style parameter declaration
[4d51835]1929 abstract_parameter_declaration
[c0aa336]1930 | cfa_identifier_parameter_declarator_no_tuple
1931 | cfa_abstract_tuple
1932 // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
1933 | type_qualifier_list cfa_abstract_tuple
[4d51835]1934 { $$ = $2->addQualifiers( $1 ); }
[c0aa336]1935 | cfa_abstract_function
[4d51835]1936 ;
[51b73452]1937
1938parameter_declaration:
[d0ffed1]1939 // No SUE declaration in parameter list.
[994d080]1940 declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
[4d51835]1941 {
1942 typedefTable.addToEnclosingScope( TypedefTable::ID );
[a7741435]1943 $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
[4d51835]1944 }
[994d080]1945 | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
[4d51835]1946 {
1947 typedefTable.addToEnclosingScope( TypedefTable::ID );
[a7741435]1948 $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
[4d51835]1949 }
1950 ;
[51b73452]1951
1952abstract_parameter_declaration:
[994d080]1953 declaration_specifier_nobody default_initialize_opt
[e7cc8cb]1954 { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }
[994d080]1955 | declaration_specifier_nobody abstract_parameter_declarator default_initialize_opt
[e7cc8cb]1956 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
[4d51835]1957 ;
[51b73452]1958
[c11e31c]1959// ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a
[de62360d]1960// parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on
1961// identifiers. The ANSI-style parameter-list can redefine a typedef name.
[51b73452]1962
[b87a5ed]1963identifier_list: // K&R-style parameter list => no types
[4d51835]1964 no_attr_identifier
1965 { $$ = DeclarationNode::newName( $1 ); }
1966 | identifier_list ',' no_attr_identifier
1967 { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); }
1968 ;
[51b73452]1969
[2871210]1970identifier_or_type_name:
[4d51835]1971 identifier
1972 | TYPEDEFname
1973 | TYPEGENname
1974 ;
[51b73452]1975
[2871210]1976no_attr_identifier_or_type_name:
[4d51835]1977 no_attr_identifier
1978 | TYPEDEFname
[721f17a]1979 | TYPEGENname
[4d51835]1980 ;
[b87a5ed]1981
[84d58c5]1982type_no_function: // sizeof, alignof, cast (constructor)
[c0aa336]1983 cfa_abstract_declarator_tuple // CFA
[4d51835]1984 | type_specifier
[c0aa336]1985 | type_specifier abstract_declarator
[4d51835]1986 { $$ = $2->addType( $1 ); }
1987 ;
[b87a5ed]1988
[84d58c5]1989type: // typeof, assertion
1990 type_no_function
[c0aa336]1991 | cfa_abstract_function // CFA
[4d51835]1992 ;
[51b73452]1993
1994initializer_opt:
[4d51835]1995 // empty
[58dd019]1996 { $$ = nullptr; }
[2871210]1997 | '=' initializer
1998 { $$ = $2; }
[641c3d0]1999 | '=' VOID
2000 { $$ = nullptr; }
[097e2b0]2001 | ATassign initializer
[974906e2]2002 { $$ = $2->set_maybeConstructed( false ); }
[4d51835]2003 ;
[51b73452]2004
2005initializer:
[de62360d]2006 assignment_expression { $$ = new InitializerNode( $1 ); }
2007 | '{' initializer_list comma_opt '}' { $$ = new InitializerNode( $2, true ); }
[4d51835]2008 ;
[51b73452]2009
2010initializer_list:
[097e2b0]2011 // empty
[58dd019]2012 { $$ = nullptr; }
[097e2b0]2013 | initializer
[4d51835]2014 | designation initializer { $$ = $2->set_designators( $1 ); }
[1d4580a]2015 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
[4d51835]2016 | initializer_list ',' designation initializer
[1d4580a]2017 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
[4d51835]2018 ;
[b87a5ed]2019
[de62360d]2020// There is an unreconcileable parsing problem between C99 and CFA with respect to designators. The problem is use of
2021// '=' to separator the designator from the initializer value, as in:
[c11e31c]2022//
[b87a5ed]2023// int x[10] = { [1] = 3 };
[c11e31c]2024//
[de62360d]2025// The string "[1] = 3" can be parsed as a designator assignment or a tuple assignment. To disambiguate this case, CFA
2026// changes the syntax from "=" to ":" as the separator between the designator and initializer. GCC does uses ":" for
2027// field selection. The optional use of the "=" in GCC, or in this case ":", cannot be supported either due to
2028// shift/reduce conflicts
[51b73452]2029
2030designation:
[4d51835]2031 designator_list ':' // C99, CFA uses ":" instead of "="
[84d58c5]2032 | no_attr_identifier ':' // GCC, field name
[d1625f8]2033 { $$ = new ExpressionNode( build_varref( $1 ) ); }
[4d51835]2034 ;
[51b73452]2035
[b87a5ed]2036designator_list: // C99
[4d51835]2037 designator
[2871210]2038 | designator_list designator
[1d4580a]2039 { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); }
[d1625f8]2040 //| designator_list designator { $$ = new ExpressionNode( $1, $2 ); }
[4d51835]2041 ;
[51b73452]2042
2043designator:
[84d58c5]2044 '.' no_attr_identifier // C99, field name
[d1625f8]2045 { $$ = new ExpressionNode( build_varref( $2 ) ); }
[4d51835]2046 | '[' push assignment_expression pop ']' // C99, single array element
[de62360d]2047 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple.
[d1625f8]2048 { $$ = $3; }
[4d51835]2049 | '[' push subrange pop ']' // CFA, multiple array elements
[d1625f8]2050 { $$ = $3; }
[4d51835]2051 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
[d1625f8]2052 { $$ = new ExpressionNode( build_range( $3, $5 ) ); }
[4d51835]2053 | '.' '[' push field_list pop ']' // CFA, tuple field selector
[d1625f8]2054 { $$ = $4; }
[4d51835]2055 ;
[51b73452]2056
[de62360d]2057// The CFA type system is based on parametric polymorphism, the ability to declare functions with type parameters,
2058// rather than an object-oriented type system. This required four groups of extensions:
[c11e31c]2059//
2060// Overloading: function, data, and operator identifiers may be overloaded.
2061//
[de62360d]2062// Type declarations: "type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object
2063// and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide
2064// definitions of new types. Type declarations with storage class "extern" provide opaque types.
[c11e31c]2065//
[de62360d]2066// Polymorphic functions: A forall clause declares a type parameter. The corresponding argument is inferred at the call
2067// site. A polymorphic function is not a template; it is a function, with an address and a type.
[c11e31c]2068//
2069// Specifications and Assertions: Specifications are collections of declarations parameterized by one or more
[de62360d]2070// types. They serve many of the purposes of abstract classes, and specification hierarchies resemble subclass
2071// hierarchies. Unlike classes, they can define relationships between types. Assertions declare that a type or
2072// types provide the operations declared by a specification. Assertions are normally used to declare requirements
2073// on type arguments of polymorphic functions.
[c11e31c]2074
[b87a5ed]2075type_parameter_list: // CFA
[67cf18c]2076 type_parameter
2077 { $$ = $1; }
2078 | type_parameter_list ',' type_parameter
[4d51835]2079 { $$ = $1->appendList( $3 ); }
2080 ;
[b87a5ed]2081
[84d58c5]2082type_initializer_opt: // CFA
2083 // empty
2084 { $$ = nullptr; }
2085 | '=' type
2086 { $$ = $2; }
2087 ;
2088
[b87a5ed]2089type_parameter: // CFA
[2871210]2090 type_class no_attr_identifier_or_type_name
2091 { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }
[67cf18c]2092 type_initializer_opt assertion_list_opt
2093 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
[4d51835]2094 | type_specifier identifier_parameter_declarator
2095 ;
[b87a5ed]2096
2097type_class: // CFA
[4040425]2098 OTYPE
[5b639ee]2099 { $$ = DeclarationNode::Otype; }
[4d51835]2100 | DTYPE
2101 { $$ = DeclarationNode::Dtype; }
[8f60f0b]2102 | FTYPE
2103 { $$ = DeclarationNode::Ftype; }
2104 | TTYPE
2105 { $$ = DeclarationNode::Ttype; }
[4d51835]2106 ;
[b87a5ed]2107
2108assertion_list_opt: // CFA
[4d51835]2109 // empty
[58dd019]2110 { $$ = nullptr; }
[4d51835]2111 | assertion_list_opt assertion
[a7741435]2112 { $$ = $1 ? $1->appendList( $2 ) : $2; }
[4d51835]2113 ;
[b87a5ed]2114
2115assertion: // CFA
[84d58c5]2116 '|' no_attr_identifier_or_type_name '(' type_list ')'
[4d51835]2117 {
[4040425]2118 typedefTable.openTrait( *$2 );
2119 $$ = DeclarationNode::newTraitUse( $2, $4 );
[4d51835]2120 }
[4040425]2121 | '|' '{' push trait_declaration_list '}'
[4d51835]2122 { $$ = $4; }
[84d58c5]2123 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
[58dd019]2124 { $$ = nullptr; }
[4d51835]2125 ;
[b87a5ed]2126
[84d58c5]2127type_list: // CFA
2128 type
[d1625f8]2129 { $$ = new ExpressionNode( build_typevalue( $1 ) ); }
[4d51835]2130 | assignment_expression
[84d58c5]2131 | type_list ',' type
[1d4580a]2132 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); }
[84d58c5]2133 | type_list ',' assignment_expression
[1d4580a]2134 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
[4d51835]2135 ;
[b87a5ed]2136
2137type_declaring_list: // CFA
[4040425]2138 OTYPE type_declarator
[4d51835]2139 { $$ = $2; }
[4040425]2140 | storage_class_list OTYPE type_declarator
[4d51835]2141 { $$ = $3->addQualifiers( $1 ); }
2142 | type_declaring_list ',' type_declarator
[a7c90d4]2143 { $$ = $1->appendList( $3->copySpecifiers( $1 ) ); }
[4d51835]2144 ;
[b87a5ed]2145
2146type_declarator: // CFA
[4d51835]2147 type_declarator_name assertion_list_opt
2148 { $$ = $1->addAssertions( $2 ); }
[84d58c5]2149 | type_declarator_name assertion_list_opt '=' type
[4d51835]2150 { $$ = $1->addAssertions( $2 )->addType( $4 ); }
2151 ;
[b87a5ed]2152
2153type_declarator_name: // CFA
[2871210]2154 no_attr_identifier_or_type_name
[4d51835]2155 {
[de62360d]2156 typedefTable.addToEnclosingScope( *$1, TypedefTable::TD );
[4d51835]2157 $$ = DeclarationNode::newTypeDecl( $1, 0 );
2158 }
[84d58c5]2159 | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
[4d51835]2160 {
[de62360d]2161 typedefTable.addToEnclosingScope( *$1, TypedefTable::TG );
[4d51835]2162 $$ = DeclarationNode::newTypeDecl( $1, $4 );
2163 }
2164 ;
[b87a5ed]2165
[4040425]2166trait_specifier: // CFA
2167 TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
[4d51835]2168 {
[de62360d]2169 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
[4040425]2170 $$ = DeclarationNode::newTrait( $2, $5, 0 );
[4d51835]2171 }
[4040425]2172 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{'
[4d51835]2173 {
[4040425]2174 typedefTable.enterTrait( *$2 );
[4d51835]2175 typedefTable.enterScope();
2176 }
[4040425]2177 trait_declaration_list '}'
[4d51835]2178 {
[4040425]2179 typedefTable.leaveTrait();
[de62360d]2180 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
[4040425]2181 $$ = DeclarationNode::newTrait( $2, $5, $10 );
[4d51835]2182 }
2183 ;
[b87a5ed]2184
[84d58c5]2185trait_declaration_list: // CFA
[4040425]2186 trait_declaration
2187 | trait_declaration_list push trait_declaration
[4d51835]2188 { $$ = $1->appendList( $3 ); }
2189 ;
[b87a5ed]2190
[84d58c5]2191trait_declaration: // CFA
[c0aa336]2192 cfa_trait_declaring_list pop ';'
[4040425]2193 | trait_declaring_list pop ';'
[4d51835]2194 ;
[b87a5ed]2195
[c0aa336]2196cfa_trait_declaring_list: // CFA
2197 cfa_variable_specifier
[4d51835]2198 {
2199 typedefTable.addToEnclosingScope2( TypedefTable::ID );
2200 $$ = $1;
2201 }
[c0aa336]2202 | cfa_function_specifier
[4d51835]2203 {
2204 typedefTable.addToEnclosingScope2( TypedefTable::ID );
2205 $$ = $1;
2206 }
[c0aa336]2207 | cfa_trait_declaring_list pop ',' push identifier_or_type_name
[4d51835]2208 {
[de62360d]2209 typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
[4d51835]2210 $$ = $1->appendList( $1->cloneType( $5 ) );
2211 }
2212 ;
[b87a5ed]2213
[4040425]2214trait_declaring_list: // CFA
[4d51835]2215 type_specifier declarator
2216 {
2217 typedefTable.addToEnclosingScope2( TypedefTable::ID );
2218 $$ = $2->addType( $1 );
2219 }
[4040425]2220 | trait_declaring_list pop ',' push declarator
[4d51835]2221 {
2222 typedefTable.addToEnclosingScope2( TypedefTable::ID );
2223 $$ = $1->appendList( $1->cloneBaseType( $5 ) );
2224 }
2225 ;
[51b73452]2226
[c11e31c]2227//***************************** EXTERNAL DEFINITIONS *****************************
[51b73452]2228
2229translation_unit:
[4d51835]2230 // empty
2231 {} // empty input file
2232 | external_definition_list
[a7741435]2233 { parseTree = parseTree ? parseTree->appendList( $1 ) : $1; }
[4d51835]2234 ;
[51b73452]2235
2236external_definition_list:
[4d51835]2237 external_definition
2238 | external_definition_list push external_definition
[a7741435]2239 { $$ = $1 ? $1->appendList( $3 ) : $3; }
[4d51835]2240 ;
[51b73452]2241
2242external_definition_list_opt:
[4d51835]2243 // empty
[58dd019]2244 { $$ = nullptr; }
[4d51835]2245 | external_definition_list
2246 ;
[51b73452]2247
2248external_definition:
[4d51835]2249 declaration
2250 | external_function_definition
[e994912]2251 | ASM '(' string_literal ')' ';' // GCC, global assembler statement
2252 {
2253 $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asmstmt( false, $3, 0 ) ) );
2254 }
[c0aa336]2255 | EXTERN STRINGliteral // C++-style linkage specifier
[4d51835]2256 {
[3b8e52c]2257 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall"
[0fc9756b]2258 linkage = LinkageSpec::linkageUpdate( linkage, $2 );
[4d51835]2259 }
[c0aa336]2260 '{' external_definition_list_opt '}'
[4d51835]2261 {
2262 linkage = linkageStack.top();
2263 linkageStack.pop();
2264 $$ = $5;
2265 }
[c0aa336]2266 | EXTENSION external_definition // GCC, multiple __extension__ allowed, meaning unknown
2267 {
2268 distExt( $2 ); // mark all fields in list
[8e9cbb2]2269 $$ = $2;
2270 }
[4d51835]2271 ;
2272
2273external_function_definition:
2274 function_definition
[de62360d]2275 // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of
[c6b1105]2276 // legacy code with global functions missing the type-specifier for the return type, and assuming "int".
2277 // Parsing is possible because function_definition does not appear in the context of an expression (nested
2278 // functions preclude this concession, i.e., all nested function must have a return type). A function prototype
2279 // declaration must still have a type_specifier. OBSOLESCENT (see 1)
[4d51835]2280 | function_declarator compound_statement
2281 {
2282 typedefTable.addToEnclosingScope( TypedefTable::ID );
2283 typedefTable.leaveScope();
2284 $$ = $1->addFunctionBody( $2 );
2285 }
[4cc585b]2286 | KR_function_declarator KR_declaration_list_opt compound_statement
[4d51835]2287 {
2288 typedefTable.addToEnclosingScope( TypedefTable::ID );
2289 typedefTable.leaveScope();
[4cc585b]2290 $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 );
[4d51835]2291 }
2292 ;
[51b73452]2293
[8b47e50]2294with_clause_opt:
2295 // empty
[5b2edbc]2296 { $$ = nullptr; } // FIX ME
[578e6037]2297 | WITH '(' tuple_expression_list ')'
[5b2edbc]2298 { $$ = nullptr; } // FIX ME
[8b47e50]2299 ;
2300
[51b73452]2301function_definition:
[8b47e50]2302 cfa_function_declaration with_clause_opt compound_statement // CFA
[4d51835]2303 {
2304 typedefTable.addToEnclosingScope( TypedefTable::ID );
2305 typedefTable.leaveScope();
[8b47e50]2306 $$ = $1->addFunctionBody( $3 );
[4d51835]2307 }
[8b47e50]2308 | declaration_specifier function_declarator with_clause_opt compound_statement
[4d51835]2309 {
2310 typedefTable.addToEnclosingScope( TypedefTable::ID );
2311 typedefTable.leaveScope();
[8b47e50]2312 $$ = $2->addFunctionBody( $4 )->addType( $1 );
[4d51835]2313 }
[8b47e50]2314 | type_qualifier_list function_declarator with_clause_opt compound_statement
[4d51835]2315 {
2316 typedefTable.addToEnclosingScope( TypedefTable::ID );
2317 typedefTable.leaveScope();
[8b47e50]2318 $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
[4d51835]2319 }
[8b47e50]2320 | declaration_qualifier_list function_declarator with_clause_opt compound_statement
[4d51835]2321 {
2322 typedefTable.addToEnclosingScope( TypedefTable::ID );
2323 typedefTable.leaveScope();
[8b47e50]2324 $$ = $2->addFunctionBody( $4 )->addQualifiers( $1 );
[4d51835]2325 }
[8b47e50]2326 | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
[4d51835]2327 {
2328 typedefTable.addToEnclosingScope( TypedefTable::ID );
2329 typedefTable.leaveScope();
[8b47e50]2330 $$ = $3->addFunctionBody( $5 )->addQualifiers( $2 )->addQualifiers( $1 );
[4d51835]2331 }
2332
2333 // Old-style K&R function definition, OBSOLESCENT (see 4)
[4cc585b]2334 | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
[4d51835]2335 {
2336 typedefTable.addToEnclosingScope( TypedefTable::ID );
2337 typedefTable.leaveScope();
[4cc585b]2338 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addType( $1 );
[4d51835]2339 }
[4cc585b]2340 | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
[4d51835]2341 {
2342 typedefTable.addToEnclosingScope( TypedefTable::ID );
2343 typedefTable.leaveScope();
[4cc585b]2344 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
[4d51835]2345 }
2346
2347 // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
[4cc585b]2348 | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
[4d51835]2349 {
2350 typedefTable.addToEnclosingScope( TypedefTable::ID );
2351 typedefTable.leaveScope();
[4cc585b]2352 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
[4d51835]2353 }
[4cc585b]2354 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
[4d51835]2355 {
2356 typedefTable.addToEnclosingScope( TypedefTable::ID );
2357 typedefTable.leaveScope();
[4cc585b]2358 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
[4d51835]2359 }
2360 ;
[51b73452]2361
2362declarator:
[4d51835]2363 variable_declarator
[c6b1105]2364 | variable_type_redeclarator
[4d51835]2365 | function_declarator
2366 ;
[51b73452]2367
2368subrange:
[4d51835]2369 constant_expression '~' constant_expression // CFA, integer subrange
[d1625f8]2370 { $$ = new ExpressionNode( build_range( $1, $3 ) ); }
[4d51835]2371 ;
[b87a5ed]2372
2373asm_name_opt: // GCC
[4d51835]2374 // empty
[58dd019]2375 { $$ = nullptr; }
2376 | ASM '(' string_literal ')' attribute_list_opt
[c0aa336]2377 {
2378 DeclarationNode * name = new DeclarationNode();
2379 name->asmName = $3;
2380 $$ = name->addQualifiers( $5 );
2381 }
[4d51835]2382 ;
[b87a5ed]2383
2384attribute_list_opt: // GCC
[4d51835]2385 // empty
[58dd019]2386 { $$ = nullptr; }
[4d51835]2387 | attribute_list
2388 ;
[b87a5ed]2389
2390attribute_list: // GCC
[4d51835]2391 attribute
2392 | attribute_list attribute
[1db21619]2393 { $$ = $2->addQualifiers( $1 ); }
[4d51835]2394 ;
[b87a5ed]2395
2396attribute: // GCC
[44a81853]2397 ATTRIBUTE '(' '(' attribute_name_list ')' ')'
2398 { $$ = $4; }
[4d51835]2399 ;
[b87a5ed]2400
[44a81853]2401attribute_name_list: // GCC
2402 attribute_name
2403 | attribute_name_list ',' attribute_name
[c0aa336]2404 { $$ = $3->addQualifiers( $1 ); }
[4d51835]2405 ;
[b87a5ed]2406
[44a81853]2407attribute_name: // GCC
[4d51835]2408 // empty
[44a81853]2409 { $$ = nullptr; }
2410 | attr_name
2411 { $$ = DeclarationNode::newAttribute( $1 ); }
2412 | attr_name '(' argument_expression_list ')'
2413 { $$ = DeclarationNode::newAttribute( $1, $3 ); }
[4d51835]2414 ;
[b87a5ed]2415
[44a81853]2416attr_name: // GCC
2417 IDENTIFIER
[5b2edbc]2418 | quasi_keyword
[44a81853]2419 | TYPEDEFname
2420 | TYPEGENname
2421 | CONST
[9ff56e7]2422 { $$ = Token{ new string( "__const__" ), { nullptr, -1 } }; }
[4d51835]2423 ;
[51b73452]2424
[c11e31c]2425// ============================================================================
[de62360d]2426// The following sections are a series of grammar patterns used to parse declarators. Multiple patterns are necessary
2427// because the type of an identifier in wrapped around the identifier in the same form as its usage in an expression, as
2428// in:
[c11e31c]2429//
[b87a5ed]2430// int (*f())[10] { ... };
2431// ... (*f())[3] += 1; // definition mimics usage
[c11e31c]2432//
[de62360d]2433// Because these patterns are highly recursive, changes at a lower level in the recursion require copying some or all of
2434// the pattern. Each of these patterns has some subtle variation to ensure correct syntax in a particular context.
[c11e31c]2435// ============================================================================
2436
2437// ----------------------------------------------------------------------------
[de62360d]2438// The set of valid declarators before a compound statement for defining a function is less than the set of declarators
2439// to define a variable or function prototype, e.g.:
[c11e31c]2440//
[b87a5ed]2441// valid declaration invalid definition
2442// ----------------- ------------------
[4d51835]2443// int f; int f {}
2444// int *f; int *f {}
[b87a5ed]2445// int f[10]; int f[10] {}
[4d51835]2446// int (*f)(int); int (*f)(int) {}
[c11e31c]2447//
[de62360d]2448// To preclude this syntactic anomaly requires separating the grammar rules for variable and function declarators, hence
2449// variable_declarator and function_declarator.
[c11e31c]2450// ----------------------------------------------------------------------------
2451
[de62360d]2452// This pattern parses a declaration of a variable that is not redefining a typedef name. The pattern precludes
2453// declaring an array of functions versus a pointer to an array of functions.
[51b73452]2454
2455variable_declarator:
[4d51835]2456 paren_identifier attribute_list_opt
[1db21619]2457 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2458 | variable_ptr
2459 | variable_array attribute_list_opt
[1db21619]2460 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2461 | variable_function attribute_list_opt
[1db21619]2462 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2463 ;
[51b73452]2464
2465paren_identifier:
[4d51835]2466 identifier
2467 {
[de62360d]2468 typedefTable.setNextIdentifier( *$1 );
[4d51835]2469 $$ = DeclarationNode::newName( $1 );
2470 }
2471 | '(' paren_identifier ')' // redundant parenthesis
2472 { $$ = $2; }
2473 ;
[51b73452]2474
2475variable_ptr:
[dd51906]2476 ptrref_operator variable_declarator
[ce8c12f]2477 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[dd51906]2478 | ptrref_operator type_qualifier_list variable_declarator
[ce8c12f]2479 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[c0aa336]2480 | '(' variable_ptr ')' attribute_list_opt
2481 { $$ = $2->addQualifiers( $4 ); } // redundant parenthesis
[4d51835]2482 ;
[51b73452]2483
2484variable_array:
[4d51835]2485 paren_identifier array_dimension
2486 { $$ = $1->addArray( $2 ); }
2487 | '(' variable_ptr ')' array_dimension
2488 { $$ = $2->addArray( $4 ); }
2489 | '(' variable_array ')' multi_array_dimension // redundant parenthesis
2490 { $$ = $2->addArray( $4 ); }
2491 | '(' variable_array ')' // redundant parenthesis
2492 { $$ = $2; }
2493 ;
[51b73452]2494
2495variable_function:
[4d51835]2496 '(' variable_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2497 { $$ = $2->addParamList( $6 ); }
2498 | '(' variable_function ')' // redundant parenthesis
2499 { $$ = $2; }
2500 ;
[51b73452]2501
[c6b1105]2502// This pattern parses a function declarator that is not redefining a typedef name. For non-nested functions, there is
2503// no context where a function definition can redefine a typedef name, i.e., the typedef and function name cannot exist
2504// is the same scope. The pattern precludes returning arrays and functions versus pointers to arrays and functions.
[51b73452]2505
2506function_declarator:
[4d51835]2507 function_no_ptr attribute_list_opt
[1db21619]2508 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2509 | function_ptr
2510 | function_array attribute_list_opt
[1db21619]2511 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2512 ;
[51b73452]2513
2514function_no_ptr:
[4d51835]2515 paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2516 { $$ = $1->addParamList( $4 ); }
2517 | '(' function_ptr ')' '(' push parameter_type_list_opt pop ')'
2518 { $$ = $2->addParamList( $6 ); }
2519 | '(' function_no_ptr ')' // redundant parenthesis
2520 { $$ = $2; }
2521 ;
[51b73452]2522
2523function_ptr:
[dd51906]2524 ptrref_operator function_declarator
[ce8c12f]2525 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[dd51906]2526 | ptrref_operator type_qualifier_list function_declarator
[ce8c12f]2527 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[4d51835]2528 | '(' function_ptr ')'
2529 { $$ = $2; }
2530 ;
[51b73452]2531
2532function_array:
[4d51835]2533 '(' function_ptr ')' array_dimension
2534 { $$ = $2->addArray( $4 ); }
2535 | '(' function_array ')' multi_array_dimension // redundant parenthesis
2536 { $$ = $2->addArray( $4 ); }
2537 | '(' function_array ')' // redundant parenthesis
2538 { $$ = $2; }
2539 ;
[51b73452]2540
[c0aa336]2541// This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4)
2542//
2543// f( a, b, c ) int a, *b, c[]; {}
2544//
2545// that is not redefining a typedef name (see function_declarator for additional comments). The pattern precludes
2546// returning arrays and functions versus pointers to arrays and functions.
[51b73452]2547
[c0aa336]2548KR_function_declarator:
2549 KR_function_no_ptr
2550 | KR_function_ptr
2551 | KR_function_array
[4d51835]2552 ;
[51b73452]2553
[c0aa336]2554KR_function_no_ptr:
[4d51835]2555 paren_identifier '(' identifier_list ')' // function_declarator handles empty parameter
2556 { $$ = $1->addIdList( $3 ); }
[c0aa336]2557 | '(' KR_function_ptr ')' '(' push parameter_type_list_opt pop ')'
2558 { $$ = $2->addParamList( $6 ); }
2559 | '(' KR_function_no_ptr ')' // redundant parenthesis
[4d51835]2560 { $$ = $2; }
2561 ;
[51b73452]2562
[c0aa336]2563KR_function_ptr:
2564 ptrref_operator KR_function_declarator
[ce8c12f]2565 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[c0aa336]2566 | ptrref_operator type_qualifier_list KR_function_declarator
[ce8c12f]2567 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[c0aa336]2568 | '(' KR_function_ptr ')'
[4d51835]2569 { $$ = $2; }
2570 ;
[51b73452]2571
[c0aa336]2572KR_function_array:
2573 '(' KR_function_ptr ')' array_dimension
[4d51835]2574 { $$ = $2->addArray( $4 ); }
[c0aa336]2575 | '(' KR_function_array ')' multi_array_dimension // redundant parenthesis
[4d51835]2576 { $$ = $2->addArray( $4 ); }
[c0aa336]2577 | '(' KR_function_array ')' // redundant parenthesis
[4d51835]2578 { $$ = $2; }
2579 ;
[51b73452]2580
[2871210]2581// This pattern parses a declaration for a variable or function prototype that redefines a type name, e.g.:
[c11e31c]2582//
[b87a5ed]2583// typedef int foo;
2584// {
2585// int foo; // redefine typedef name in new scope
2586// }
[c11e31c]2587//
[de62360d]2588// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
2589// and functions versus pointers to arrays and functions.
[51b73452]2590
[c6b1105]2591variable_type_redeclarator:
[2871210]2592 paren_type attribute_list_opt
[1db21619]2593 { $$ = $1->addQualifiers( $2 ); }
[2871210]2594 | type_ptr
2595 | type_array attribute_list_opt
[1db21619]2596 { $$ = $1->addQualifiers( $2 ); }
[2871210]2597 | type_function attribute_list_opt
[1db21619]2598 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2599 ;
[51b73452]2600
[2871210]2601paren_type:
2602 typedef
2603 | '(' paren_type ')'
[4d51835]2604 { $$ = $2; }
2605 ;
[51b73452]2606
[2871210]2607type_ptr:
[c6b1105]2608 ptrref_operator variable_type_redeclarator
[ce8c12f]2609 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[c6b1105]2610 | ptrref_operator type_qualifier_list variable_type_redeclarator
[ce8c12f]2611 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[c0aa336]2612 | '(' type_ptr ')' attribute_list_opt
2613 { $$ = $2->addQualifiers( $4 ); }
[4d51835]2614 ;
[51b73452]2615
[2871210]2616type_array:
2617 paren_type array_dimension
[4d51835]2618 { $$ = $1->addArray( $2 ); }
[2871210]2619 | '(' type_ptr ')' array_dimension
[4d51835]2620 { $$ = $2->addArray( $4 ); }
[2871210]2621 | '(' type_array ')' multi_array_dimension // redundant parenthesis
[4d51835]2622 { $$ = $2->addArray( $4 ); }
[2871210]2623 | '(' type_array ')' // redundant parenthesis
[4d51835]2624 { $$ = $2; }
2625 ;
[51b73452]2626
[2871210]2627type_function:
2628 paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
[4d51835]2629 { $$ = $1->addParamList( $4 ); }
[2871210]2630 | '(' type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
[4d51835]2631 { $$ = $2->addParamList( $6 ); }
[2871210]2632 | '(' type_function ')' // redundant parenthesis
[4d51835]2633 { $$ = $2; }
2634 ;
[51b73452]2635
[c0aa336]2636// This pattern parses a declaration for a parameter variable of a function prototype or actual that is not redefining a
2637// typedef name and allows the C99 array options, which can only appear in a parameter list. The pattern precludes
2638// declaring an array of functions versus a pointer to an array of functions, and returning arrays and functions versus
2639// pointers to arrays and functions.
[51b73452]2640
2641identifier_parameter_declarator:
[4d51835]2642 paren_identifier attribute_list_opt
[1db21619]2643 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2644 | identifier_parameter_ptr
2645 | identifier_parameter_array attribute_list_opt
[1db21619]2646 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2647 | identifier_parameter_function attribute_list_opt
[1db21619]2648 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2649 ;
[51b73452]2650
2651identifier_parameter_ptr:
[dd51906]2652 ptrref_operator identifier_parameter_declarator
[ce8c12f]2653 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[dd51906]2654 | ptrref_operator type_qualifier_list identifier_parameter_declarator
[ce8c12f]2655 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[c0aa336]2656 | '(' identifier_parameter_ptr ')' attribute_list_opt
2657 { $$ = $2->addQualifiers( $4 ); }
[4d51835]2658 ;
[51b73452]2659
2660identifier_parameter_array:
[4d51835]2661 paren_identifier array_parameter_dimension
2662 { $$ = $1->addArray( $2 ); }
2663 | '(' identifier_parameter_ptr ')' array_dimension
2664 { $$ = $2->addArray( $4 ); }
2665 | '(' identifier_parameter_array ')' multi_array_dimension // redundant parenthesis
2666 { $$ = $2->addArray( $4 ); }
2667 | '(' identifier_parameter_array ')' // redundant parenthesis
2668 { $$ = $2; }
2669 ;
[51b73452]2670
2671identifier_parameter_function:
[4d51835]2672 paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2673 { $$ = $1->addParamList( $4 ); }
2674 | '(' identifier_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2675 { $$ = $2->addParamList( $6 ); }
2676 | '(' identifier_parameter_function ')' // redundant parenthesis
2677 { $$ = $2; }
2678 ;
[b87a5ed]2679
[de62360d]2680// This pattern parses a declaration for a parameter variable or function prototype that is redefining a typedef name,
2681// e.g.:
[c11e31c]2682//
[b87a5ed]2683// typedef int foo;
2684// int f( int foo ); // redefine typedef name in new scope
[c11e31c]2685//
[c0aa336]2686// and allows the C99 array options, which can only appear in a parameter list.
[51b73452]2687
[2871210]2688type_parameter_redeclarator:
[4d51835]2689 typedef attribute_list_opt
[1db21619]2690 { $$ = $1->addQualifiers( $2 ); }
[2871210]2691 | type_parameter_ptr
2692 | type_parameter_array attribute_list_opt
[1db21619]2693 { $$ = $1->addQualifiers( $2 ); }
[2871210]2694 | type_parameter_function attribute_list_opt
[1db21619]2695 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2696 ;
[51b73452]2697
2698typedef:
[4d51835]2699 TYPEDEFname
2700 {
[de62360d]2701 typedefTable.setNextIdentifier( *$1 );
[4d51835]2702 $$ = DeclarationNode::newName( $1 );
2703 }
[2871210]2704 | TYPEGENname
2705 {
2706 typedefTable.setNextIdentifier( *$1 );
2707 $$ = DeclarationNode::newName( $1 );
2708 }
[4d51835]2709 ;
[51b73452]2710
[2871210]2711type_parameter_ptr:
[dd51906]2712 ptrref_operator type_parameter_redeclarator
[ce8c12f]2713 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[dd51906]2714 | ptrref_operator type_qualifier_list type_parameter_redeclarator
[ce8c12f]2715 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[c0aa336]2716 | '(' type_parameter_ptr ')' attribute_list_opt
2717 { $$ = $2->addQualifiers( $4 ); }
[4d51835]2718 ;
[51b73452]2719
[2871210]2720type_parameter_array:
[4d51835]2721 typedef array_parameter_dimension
2722 { $$ = $1->addArray( $2 ); }
[2871210]2723 | '(' type_parameter_ptr ')' array_parameter_dimension
[4d51835]2724 { $$ = $2->addArray( $4 ); }
2725 ;
[51b73452]2726
[2871210]2727type_parameter_function:
[4d51835]2728 typedef '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2729 { $$ = $1->addParamList( $4 ); }
[2871210]2730 | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
[4d51835]2731 { $$ = $2->addParamList( $6 ); }
2732 ;
[b87a5ed]2733
[de62360d]2734// This pattern parses a declaration of an abstract variable or function prototype, i.e., there is no identifier to
2735// which the type applies, e.g.:
[c11e31c]2736//
[b87a5ed]2737// sizeof( int );
[c0aa336]2738// sizeof( int * );
[b87a5ed]2739// sizeof( int [10] );
[c0aa336]2740// sizeof( int (*)() );
2741// sizeof( int () );
[c11e31c]2742//
[de62360d]2743// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
2744// and functions versus pointers to arrays and functions.
[51b73452]2745
2746abstract_declarator:
[4d51835]2747 abstract_ptr
2748 | abstract_array attribute_list_opt
[1db21619]2749 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2750 | abstract_function attribute_list_opt
[1db21619]2751 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2752 ;
[51b73452]2753
2754abstract_ptr:
[dd51906]2755 ptrref_operator
[ce8c12f]2756 { $$ = DeclarationNode::newPointer( 0, $1 ); }
[dd51906]2757 | ptrref_operator type_qualifier_list
[ce8c12f]2758 { $$ = DeclarationNode::newPointer( $2, $1 ); }
[dd51906]2759 | ptrref_operator abstract_declarator
[ce8c12f]2760 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[dd51906]2761 | ptrref_operator type_qualifier_list abstract_declarator
[ce8c12f]2762 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[c0aa336]2763 | '(' abstract_ptr ')' attribute_list_opt
2764 { $$ = $2->addQualifiers( $4 ); }
[4d51835]2765 ;
[51b73452]2766
2767abstract_array:
[4d51835]2768 array_dimension
2769 | '(' abstract_ptr ')' array_dimension
2770 { $$ = $2->addArray( $4 ); }
2771 | '(' abstract_array ')' multi_array_dimension // redundant parenthesis
2772 { $$ = $2->addArray( $4 ); }
2773 | '(' abstract_array ')' // redundant parenthesis
2774 { $$ = $2; }
2775 ;
[51b73452]2776
2777abstract_function:
[4d51835]2778 '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
[2298f728]2779 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
[4d51835]2780 | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2781 { $$ = $2->addParamList( $6 ); }
2782 | '(' abstract_function ')' // redundant parenthesis
2783 { $$ = $2; }
2784 ;
[51b73452]2785
2786array_dimension:
[4d51835]2787 // Only the first dimension can be empty.
[2871210]2788 '[' ']'
[4d51835]2789 { $$ = DeclarationNode::newArray( 0, 0, false ); }
[2871210]2790 | '[' ']' multi_array_dimension
2791 { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); }
[4d51835]2792 | multi_array_dimension
2793 ;
[51b73452]2794
2795multi_array_dimension:
[4d51835]2796 '[' push assignment_expression pop ']'
2797 { $$ = DeclarationNode::newArray( $3, 0, false ); }
2798 | '[' push '*' pop ']' // C99
2799 { $$ = DeclarationNode::newVarArray( 0 ); }
2800 | multi_array_dimension '[' push assignment_expression pop ']'
2801 { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); }
2802 | multi_array_dimension '[' push '*' pop ']' // C99
2803 { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); }
2804 ;
[51b73452]2805
[c11e31c]2806// This pattern parses a declaration of a parameter abstract variable or function prototype, i.e., there is no
2807// identifier to which the type applies, e.g.:
2808//
[c0aa336]2809// int f( int ); // not handled here
2810// int f( int * ); // abstract function-prototype parameter; no parameter name specified
2811// int f( int (*)() ); // abstract function-prototype parameter; no parameter name specified
[b87a5ed]2812// int f( int (int) ); // abstract function-prototype parameter; no parameter name specified
[c11e31c]2813//
[de62360d]2814// The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
[c0aa336]2815// and functions versus pointers to arrays and functions. In addition, the pattern handles the
2816// special meaning of parenthesis around a typedef name:
2817//
2818// ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in
2819// parentheses is taken to be an abstract declarator that specifies a function with a single parameter,
2820// not as redundant parentheses around the identifier."
2821//
2822// For example:
2823//
2824// typedef float T;
2825// int f( int ( T [5] ) ); // see abstract_parameter_declarator
2826// int g( int ( T ( int ) ) ); // see abstract_parameter_declarator
2827// int f( int f1( T a[5] ) ); // see identifier_parameter_declarator
2828// int g( int g1( T g2( int p ) ) ); // see identifier_parameter_declarator
2829//
2830// In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and
2831// not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of
2832// functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to arrays and
2833// functions.
[51b73452]2834
2835abstract_parameter_declarator:
[4d51835]2836 abstract_parameter_ptr
2837 | abstract_parameter_array attribute_list_opt
[1db21619]2838 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2839 | abstract_parameter_function attribute_list_opt
[1db21619]2840 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2841 ;
[51b73452]2842
2843abstract_parameter_ptr:
[dd51906]2844 ptrref_operator
[ce8c12f]2845 { $$ = DeclarationNode::newPointer( nullptr, $1 ); }
[dd51906]2846 | ptrref_operator type_qualifier_list
[ce8c12f]2847 { $$ = DeclarationNode::newPointer( $2, $1 ); }
[dd51906]2848 | ptrref_operator abstract_parameter_declarator
[ce8c12f]2849 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); }
[dd51906]2850 | ptrref_operator type_qualifier_list abstract_parameter_declarator
[ce8c12f]2851 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[c0aa336]2852 | '(' abstract_parameter_ptr ')' attribute_list_opt
2853 { $$ = $2->addQualifiers( $4 ); }
[4d51835]2854 ;
[51b73452]2855
2856abstract_parameter_array:
[4d51835]2857 array_parameter_dimension
2858 | '(' abstract_parameter_ptr ')' array_parameter_dimension
2859 { $$ = $2->addArray( $4 ); }
2860 | '(' abstract_parameter_array ')' multi_array_dimension // redundant parenthesis
2861 { $$ = $2->addArray( $4 ); }
2862 | '(' abstract_parameter_array ')' // redundant parenthesis
2863 { $$ = $2; }
2864 ;
[51b73452]2865
2866abstract_parameter_function:
[4d51835]2867 '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
[2298f728]2868 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
[4d51835]2869 | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2870 { $$ = $2->addParamList( $6 ); }
2871 | '(' abstract_parameter_function ')' // redundant parenthesis
2872 { $$ = $2; }
2873 ;
[51b73452]2874
2875array_parameter_dimension:
[4d51835]2876 // Only the first dimension can be empty or have qualifiers.
2877 array_parameter_1st_dimension
2878 | array_parameter_1st_dimension multi_array_dimension
2879 { $$ = $1->addArray( $2 ); }
2880 | multi_array_dimension
2881 ;
[51b73452]2882
[c11e31c]2883// The declaration of an array parameter has additional syntax over arrays in normal variable declarations:
2884//
[de62360d]2885// ISO/IEC 9899:1999 Section 6.7.5.2(1) : "The optional type qualifiers and the keyword static shall appear only in
2886// a declaration of a function parameter with an array type, and then only in the outermost array type derivation."
[51b73452]2887
2888array_parameter_1st_dimension:
[2871210]2889 '[' ']'
[4d51835]2890 { $$ = DeclarationNode::newArray( 0, 0, false ); }
2891 // multi_array_dimension handles the '[' '*' ']' case
2892 | '[' push type_qualifier_list '*' pop ']' // remaining C99
2893 { $$ = DeclarationNode::newVarArray( $3 ); }
2894 | '[' push type_qualifier_list pop ']'
2895 { $$ = DeclarationNode::newArray( 0, $3, false ); }
2896 // multi_array_dimension handles the '[' assignment_expression ']' case
2897 | '[' push type_qualifier_list assignment_expression pop ']'
2898 { $$ = DeclarationNode::newArray( $4, $3, false ); }
2899 | '[' push STATIC type_qualifier_list_opt assignment_expression pop ']'
2900 { $$ = DeclarationNode::newArray( $5, $4, true ); }
2901 | '[' push type_qualifier_list STATIC assignment_expression pop ']'
2902 { $$ = DeclarationNode::newArray( $5, $3, true ); }
2903 ;
[b87a5ed]2904
[c0aa336]2905// This pattern parses a declaration of an abstract variable, but does not allow "int ()" for a function pointer.
[c11e31c]2906//
[c0aa336]2907// struct S {
2908// int;
2909// int *;
2910// int [10];
2911// int (*)();
2912// };
[51b73452]2913
2914variable_abstract_declarator:
[4d51835]2915 variable_abstract_ptr
2916 | variable_abstract_array attribute_list_opt
[1db21619]2917 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2918 | variable_abstract_function attribute_list_opt
[1db21619]2919 { $$ = $1->addQualifiers( $2 ); }
[4d51835]2920 ;
[51b73452]2921
2922variable_abstract_ptr:
[dd51906]2923 ptrref_operator
[ce8c12f]2924 { $$ = DeclarationNode::newPointer( 0, $1 ); }
[dd51906]2925 | ptrref_operator type_qualifier_list
[ce8c12f]2926 { $$ = DeclarationNode::newPointer( $2, $1 ); }
[dd51906]2927 | ptrref_operator variable_abstract_declarator
[ce8c12f]2928 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[dd51906]2929 | ptrref_operator type_qualifier_list variable_abstract_declarator
[ce8c12f]2930 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); }
[c0aa336]2931 | '(' variable_abstract_ptr ')' attribute_list_opt
2932 { $$ = $2->addQualifiers( $4 ); }
[4d51835]2933 ;
[51b73452]2934
2935variable_abstract_array:
[4d51835]2936 array_dimension
2937 | '(' variable_abstract_ptr ')' array_dimension
2938 { $$ = $2->addArray( $4 ); }
2939 | '(' variable_abstract_array ')' multi_array_dimension // redundant parenthesis
2940 { $$ = $2->addArray( $4 ); }
2941 | '(' variable_abstract_array ')' // redundant parenthesis
2942 { $$ = $2; }
2943 ;
[51b73452]2944
2945variable_abstract_function:
[4d51835]2946 '(' variable_abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
2947 { $$ = $2->addParamList( $6 ); }
2948 | '(' variable_abstract_function ')' // redundant parenthesis
2949 { $$ = $2; }
2950 ;
[b87a5ed]2951
[de62360d]2952// This pattern parses a new-style declaration for a parameter variable or function prototype that is either an
2953// identifier or typedef name and allows the C99 array options, which can only appear in a parameter list.
[b87a5ed]2954
[c0aa336]2955cfa_identifier_parameter_declarator_tuple: // CFA
2956 cfa_identifier_parameter_declarator_no_tuple
2957 | cfa_abstract_tuple
2958 | type_qualifier_list cfa_abstract_tuple
[4d51835]2959 { $$ = $2->addQualifiers( $1 ); }
2960 ;
[b87a5ed]2961
[c0aa336]2962cfa_identifier_parameter_declarator_no_tuple: // CFA
2963 cfa_identifier_parameter_ptr
2964 | cfa_identifier_parameter_array
[4d51835]2965 ;
[b87a5ed]2966
[c0aa336]2967cfa_identifier_parameter_ptr: // CFA
[d0ffed1]2968 // No SUE declaration in parameter list.
2969 ptrref_operator type_specifier_nobody
[ce8c12f]2970 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[d0ffed1]2971 | type_qualifier_list ptrref_operator type_specifier_nobody
[ce8c12f]2972 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[c0aa336]2973 | ptrref_operator cfa_abstract_function
[ce8c12f]2974 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[c0aa336]2975 | type_qualifier_list ptrref_operator cfa_abstract_function
[ce8c12f]2976 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[c0aa336]2977 | ptrref_operator cfa_identifier_parameter_declarator_tuple
[ce8c12f]2978 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[c0aa336]2979 | type_qualifier_list ptrref_operator cfa_identifier_parameter_declarator_tuple
[ce8c12f]2980 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[4d51835]2981 ;
[b87a5ed]2982
[c0aa336]2983cfa_identifier_parameter_array: // CFA
[de62360d]2984 // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to
2985 // shift/reduce conflict with new-style empty (void) function return type.
[d0ffed1]2986 '[' ']' type_specifier_nobody
[2871210]2987 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
[d0ffed1]2988 | cfa_array_parameter_1st_dimension type_specifier_nobody
[4d51835]2989 { $$ = $2->addNewArray( $1 ); }
[d0ffed1]2990 | '[' ']' multi_array_dimension type_specifier_nobody
[2871210]2991 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
[d0ffed1]2992 | cfa_array_parameter_1st_dimension multi_array_dimension type_specifier_nobody
[4d51835]2993 { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
[d0ffed1]2994 | multi_array_dimension type_specifier_nobody
[4d51835]2995 { $$ = $2->addNewArray( $1 ); }
[9059213]2996
[c0aa336]2997 | '[' ']' cfa_identifier_parameter_ptr
[2871210]2998 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
[c0aa336]2999 | cfa_array_parameter_1st_dimension cfa_identifier_parameter_ptr
[4d51835]3000 { $$ = $2->addNewArray( $1 ); }
[c0aa336]3001 | '[' ']' multi_array_dimension cfa_identifier_parameter_ptr
[2871210]3002 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
[c0aa336]3003 | cfa_array_parameter_1st_dimension multi_array_dimension cfa_identifier_parameter_ptr
[4d51835]3004 { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); }
[c0aa336]3005 | multi_array_dimension cfa_identifier_parameter_ptr
[4d51835]3006 { $$ = $2->addNewArray( $1 ); }
3007 ;
[51b73452]3008
[c0aa336]3009cfa_array_parameter_1st_dimension:
[4d51835]3010 '[' push type_qualifier_list '*' pop ']' // remaining C99
3011 { $$ = DeclarationNode::newVarArray( $3 ); }
3012 | '[' push type_qualifier_list assignment_expression pop ']'
3013 { $$ = DeclarationNode::newArray( $4, $3, false ); }
3014 | '[' push declaration_qualifier_list assignment_expression pop ']'
3015 // declaration_qualifier_list must be used because of shift/reduce conflict with
3016 // assignment_expression, so a semantic check is necessary to preclude them as a type_qualifier cannot
3017 // appear in this context.
3018 { $$ = DeclarationNode::newArray( $4, $3, true ); }
3019 | '[' push declaration_qualifier_list type_qualifier_list assignment_expression pop ']'
3020 { $$ = DeclarationNode::newArray( $5, $4->addQualifiers( $3 ), true ); }
3021 ;
[b87a5ed]3022
[de62360d]3023// This pattern parses a new-style declaration of an abstract variable or function prototype, i.e., there is no
3024// identifier to which the type applies, e.g.:
[c11e31c]3025//
[b87a5ed]3026// [int] f( int ); // abstract variable parameter; no parameter name specified
3027// [int] f( [int] (int) ); // abstract function-prototype parameter; no parameter name specified
[c11e31c]3028//
3029// These rules need LR(3):
3030//
[c0aa336]3031// cfa_abstract_tuple identifier_or_type_name
3032// '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
[c11e31c]3033//
3034// since a function return type can be syntactically identical to a tuple type:
3035//
[b87a5ed]3036// [int, int] t;
3037// [int, int] f( int );
[c11e31c]3038//
[2871210]3039// Therefore, it is necessary to look at the token after identifier_or_type_name to know when to reduce
[c0aa336]3040// cfa_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary
3041// lookahead. To accomplish this, cfa_abstract_declarator has an entry point without tuple, and tuple declarations are
3042// duplicated when appearing with cfa_function_specifier.
[b87a5ed]3043
[c0aa336]3044cfa_abstract_declarator_tuple: // CFA
3045 cfa_abstract_tuple
3046 | type_qualifier_list cfa_abstract_tuple
[4d51835]3047 { $$ = $2->addQualifiers( $1 ); }
[c0aa336]3048 | cfa_abstract_declarator_no_tuple
[4d51835]3049 ;
[b87a5ed]3050
[c0aa336]3051cfa_abstract_declarator_no_tuple: // CFA
3052 cfa_abstract_ptr
3053 | cfa_abstract_array
[4d51835]3054 ;
[b87a5ed]3055
[c0aa336]3056cfa_abstract_ptr: // CFA
[dd51906]3057 ptrref_operator type_specifier
[ce8c12f]3058 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[dd51906]3059 | type_qualifier_list ptrref_operator type_specifier
[ce8c12f]3060 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[c0aa336]3061 | ptrref_operator cfa_abstract_function
[ce8c12f]3062 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[c0aa336]3063 | type_qualifier_list ptrref_operator cfa_abstract_function
[ce8c12f]3064 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[c0aa336]3065 | ptrref_operator cfa_abstract_declarator_tuple
[ce8c12f]3066 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }
[c0aa336]3067 | type_qualifier_list ptrref_operator cfa_abstract_declarator_tuple
[ce8c12f]3068 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
[4d51835]3069 ;
[b87a5ed]3070
[c0aa336]3071cfa_abstract_array: // CFA
[de62360d]3072 // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with
3073 // empty (void) function return type.
[2871210]3074 '[' ']' type_specifier
[2298f728]3075 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[2871210]3076 | '[' ']' multi_array_dimension type_specifier
[2298f728]3077 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[4d51835]3078 | multi_array_dimension type_specifier
3079 { $$ = $2->addNewArray( $1 ); }
[c0aa336]3080 | '[' ']' cfa_abstract_ptr
[2298f728]3081 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[c0aa336]3082 | '[' ']' multi_array_dimension cfa_abstract_ptr
[2298f728]3083 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
[c0aa336]3084 | multi_array_dimension cfa_abstract_ptr
[4d51835]3085 { $$ = $2->addNewArray( $1 ); }
3086 ;
[b87a5ed]3087
[c0aa336]3088cfa_abstract_tuple: // CFA
3089 '[' push cfa_abstract_parameter_list pop ']'
[4d51835]3090 { $$ = DeclarationNode::newTuple( $3 ); }
3091 ;
[b87a5ed]3092
[c0aa336]3093cfa_abstract_function: // CFA
3094// '[' ']' '(' cfa_parameter_type_list_opt ')'
[1b29996]3095// { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
[c0aa336]3096 cfa_abstract_tuple '(' push cfa_parameter_type_list_opt pop ')'
[2298f728]3097 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
[c0aa336]3098 | cfa_function_return '(' push cfa_parameter_type_list_opt pop ')'
[2298f728]3099 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
[4d51835]3100 ;
[b87a5ed]3101
[de62360d]3102// 1) ISO/IEC 9899:1999 Section 6.7.2(2) : "At least one type specifier shall be given in the declaration specifiers in
3103// each declaration, and in the specifier-qualifier list in each structure declaration and type name."
[c11e31c]3104//
[de62360d]3105// 2) ISO/IEC 9899:1999 Section 6.11.5(1) : "The placement of a storage-class specifier other than at the beginning of
3106// the declaration specifiers in a declaration is an obsolescent feature."
[c11e31c]3107//
3108// 3) ISO/IEC 9899:1999 Section 6.11.6(1) : "The use of function declarators with empty parentheses (not
3109// prototype-format parameter type declarators) is an obsolescent feature."
3110//
[de62360d]3111// 4) ISO/IEC 9899:1999 Section 6.11.7(1) : "The use of function definitions with separate parameter identifier and
3112// declaration lists (not prototype-format parameter type and identifier declarators) is an obsolescent feature.
[51b73452]3113
[c11e31c]3114//************************* MISCELLANEOUS ********************************
[51b73452]3115
[b87a5ed]3116comma_opt: // redundant comma
[4d51835]3117 // empty
3118 | ','
3119 ;
[51b73452]3120
[994d080]3121default_initialize_opt:
[4d51835]3122 // empty
[58dd019]3123 { $$ = nullptr; }
[4d51835]3124 | '=' assignment_expression
3125 { $$ = $2; }
3126 ;
[51b73452]3127
3128%%
[c11e31c]3129// ----end of grammar----
[51b73452]3130
[0da3e2c]3131extern char *yytext;
3132
[5f2f2d7]3133void yyerror( const char * ) {
[2298f728]3134 cout << "Error ";
[b87a5ed]3135 if ( yyfilename ) {
[2298f728]3136 cout << "in file " << yyfilename << " ";
[5f2f2d7]3137 } // if
[2298f728]3138 cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl;
[51b73452]3139}
3140
[c11e31c]3141// Local Variables: //
[b87a5ed]3142// mode: c++ //
[de62360d]3143// tab-width: 4 //
[c11e31c]3144// compile-command: "make install" //
3145// End: //
Note: See TracBrowser for help on using the repository browser.