// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // cfa.y -- // // Author : Peter A. Buhr // Created On : Sat Sep 1 20:22:55 2001 // Last Modified By : Peter A. Buhr // Last Modified On : Mon Sep 28 18:18:32 2015 // Update Count : 1402 // // This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C // grammar by James A. Roskind, specifically parts of DECLARATIONS and EXTERNAL DEFINITIONS. While parts have been // copied, important changes have been made in all sections; these changes are sufficient to constitute a new grammar. // In particular, this grammar attempts to be more syntactically precise, i.e., it parses less incorrect language syntax // that must be subsequently rejected by semantic checks. Nevertheless, there are still several semantic checks // required and many are noted in the grammar. Finally, the grammar is extended with GCC and CFA language extensions. // Acknowledgments to Richard Bilson, Glen Ditchfield, and Rodolfo Gabriel Esteves who all helped when I got stuck with // the grammar. // The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for: // // 1. designation with '=' (use ':' instead) // // Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This grammar also has // two levels of extensions. The first extensions cover most of the GCC C extensions, except for: // // 1. nested functions // 2. generalized lvalues // 3. designation with and without '=' (use ':' instead) // 4. attributes not allowed in parenthesis of declarator // // All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall // (CFA), which fixes several of C's outstanding problems and extends C with many modern language concepts. All of the // syntactic extensions for CFA C are marked with the comment "CFA". As noted above, there is one unreconcileable // parsing problem between C99 and CFA with respect to designators; this is discussed in detail before the "designation" // grammar rule. %{ #define YYDEBUG_LEXER_TEXT (yylval) // lexer loads this up each time #define YYDEBUG 1 // get the pretty debugging code to compile extern char *yytext; #undef __GNUC_MINOR__ #include #include #include "TypedefTable.h" #include "lex.h" #include "ParseNode.h" #include "TypeData.h" #include "LinkageSpec.h" DeclarationNode *theTree = 0; // the resulting parse tree LinkageSpec::Type linkage = LinkageSpec::Cforall; std::stack< LinkageSpec::Type > linkageStack; TypedefTable typedefTable; %} //************************* TERMINAL TOKENS ******************************** // keywords %token TYPEDEF %token AUTO EXTERN REGISTER STATIC %token INLINE // C99 %token FORTRAN // C99, extension ISO/IEC 9899:1999 Section J.5.9(1) %token CONST VOLATILE %token RESTRICT // C99 %token FORALL LVALUE // CFA %token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED %token BOOL COMPLEX IMAGINARY // C99 %token TYPEOF LABEL // GCC %token ENUM STRUCT UNION %token TYPE FTYPE DTYPE CONTEXT // CFA %token SIZEOF %token ATTRIBUTE EXTENSION // GCC %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN %token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT // CFA %token ASM // C99, extension ISO/IEC 9899:1999 Section J.5.10(1) %token ALIGNAS ALIGNOF ATOMIC GENERIC NORETURN STATICASSERT THREADLOCAL // C11 // names and constants: lexer differentiates between identifier and typedef names %token IDENTIFIER QUOTED_IDENTIFIER TYPEDEFname TYPEGENname %token ATTR_IDENTIFIER ATTR_TYPEDEFname ATTR_TYPEGENname %token INTEGERconstant FLOATINGconstant CHARACTERconstant STRINGliteral %token ZERO ONE // CFA // multi-character operators %token ARROW // -> %token ICR DECR // ++ -- %token LS RS // << >> %token LE GE EQ NE // <= >= == != %token ANDAND OROR // && || %token ELLIPSIS // ... %token MULTassign DIVassign MODassign // *= /= %=/ %token PLUSassign MINUSassign // += -= %token LSassign RSassign // <<= >>= %token ANDassign ERassign ORassign // &= ^= |= // Types declaration %union { Token tok; ParseNode *pn; ExpressionNode *en; DeclarationNode *decl; DeclarationNode::Aggregate aggKey; DeclarationNode::TypeClass tclass; StatementNode *sn; ConstantNode *constant; LabelNode *label; InitializerNode *in; bool flag; } %type identifier no_01_identifier no_attr_identifier no_attr_identifier_01 zero_one %type identifier_or_type_name no_attr_identifier_or_type_name no_01_identifier_or_type_name %type string_literal_list // expressions %type constant %type tuple tuple_expression_list %type unary_operator assignment_operator %type primary_expression postfix_expression unary_expression %type cast_expression multiplicative_expression additive_expression shift_expression %type relational_expression equality_expression AND_expression exclusive_OR_expression %type inclusive_OR_expression logical_AND_expression logical_OR_expression conditional_expression %type constant_expression assignment_expression assignment_expression_opt %type comma_expression comma_expression_opt %type argument_expression_list argument_expression for_control_expression assignment_opt %type subrange %type asm_operands_opt asm_operands_list asm_operand %type