diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-01 17:18:54 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-01 17:18:54 +0000 |
commit | 9e761324895d098a87f0ba66b7eb1794cd3ed6b4 (patch) | |
tree | b46b0eb0eb91f6784d586acb8611495de81b92e4 /c_parser | |
parent | 2e5cacc6633a6973f8e96adc6bafa633487fc2a1 (diff) | |
download | Compiler-9e761324895d098a87f0ba66b7eb1794cd3ed6b4.tar.gz Compiler-9e761324895d098a87f0ba66b7eb1794cd3ed6b4.zip |
Finished parser
Diffstat (limited to 'c_parser')
-rw-r--r-- | c_parser/include/ast_base.hpp | 6 | ||||
-rw-r--r-- | c_parser/include/ast_declaration.hpp | 16 | ||||
-rw-r--r-- | c_parser/include/ast_expression.hpp | 6 | ||||
-rw-r--r-- | c_parser/include/ast_function.hpp | 20 | ||||
-rw-r--r-- | c_parser/include/ast_primitives.hpp | 12 | ||||
-rw-r--r-- | c_parser/include/ast_statement.hpp | 123 | ||||
-rw-r--r-- | c_parser/include/ast_top.hpp | 10 | ||||
-rw-r--r-- | c_parser/src/c_parser.y | 315 |
8 files changed, 237 insertions, 271 deletions
diff --git a/c_parser/include/ast_base.hpp b/c_parser/include/ast_base.hpp index b793a9b..9451609 100644 --- a/c_parser/include/ast_base.hpp +++ b/c_parser/include/ast_base.hpp @@ -5,12 +5,12 @@ #include <iostream> #include <vector> -class ast_Base { +class Base { public: - virtual ~ast_Base() {} + virtual ~Base() {} virtual void print() const = 0; - virtual void push(const ast_Base* _var) const = 0; + virtual void push(const Base* _var) const = 0; }; #endif diff --git a/c_parser/include/ast_declaration.hpp b/c_parser/include/ast_declaration.hpp index 3778939..bfd3070 100644 --- a/c_parser/include/ast_declaration.hpp +++ b/c_parser/include/ast_declaration.hpp @@ -7,12 +7,12 @@ // Declaration that holds a list of declarations -class ast_DeclarationList : public ast_Base { +class DeclarationList : public Base { private: - mutable std::vector<const ast_Base*> dec_list; + mutable std::vector<const Base*> dec_list; public: - ast_DeclarationList(const ast_Base* _dec) { + DeclarationList(const Base* _dec) { dec_list.push_back(_dec); } @@ -22,17 +22,17 @@ public: } } - virtual void push(const ast_Base* _dec) const { + virtual void push(const Base* _dec) const { dec_list.push_back(_dec); } }; -class ast_VariableDeclaration : public ast_Base { +class VariableDeclaration : public Base { private: - mutable std::vector<const ast_Base*> var_list; + mutable std::vector<const Base*> var_list; public: - ast_VariableDeclaration(const ast_Base* _var) { + VariableDeclaration(const Base* _var) { var_list.push_back(_var); } @@ -42,7 +42,7 @@ public: } } - virtual void push(const ast_Base* _var) const { + virtual void push(const Base* _var) const { var_list.push_back(_var); } }; diff --git a/c_parser/include/ast_expression.hpp b/c_parser/include/ast_expression.hpp index 87db997..f67d2d7 100644 --- a/c_parser/include/ast_expression.hpp +++ b/c_parser/include/ast_expression.hpp @@ -6,16 +6,16 @@ #include <string> #include <iostream> -class ast_Expression : public ast_Base { +class Expression : public Base { private: public: - ast_Expression() {} + Expression() {} virtual void print() const { } - virtual void push(const ast_Base* _base) const { + virtual void push(const Base* _base) const { std::cerr << "Can't call this function for this type" << std::endl; (void)_base; } diff --git a/c_parser/include/ast_function.hpp b/c_parser/include/ast_function.hpp index 085957c..6fbcdee 100644 --- a/c_parser/include/ast_function.hpp +++ b/c_parser/include/ast_function.hpp @@ -6,13 +6,13 @@ #include <string> #include <iostream> -class ast_Function : public ast_Base { +class Function : public Base { private: std::string id; - const ast_Base* param; - const ast_Base* comp_statement; + const Base* param; + const Base* comp_statement; public: - ast_Function(const std::string& _id, const ast_Base* _param, const ast_Base* _comp_statement) : + Function(const std::string& _id, const Base* _param, const Base* _comp_statement) : id(_id), param(_param), comp_statement(_comp_statement) {} virtual void print() const { @@ -22,20 +22,20 @@ public: std::cout << "</Function>" << std::endl; } - virtual void push(const ast_Base* var) const { + virtual void push(const Base* var) const { std::cerr << "Error: Can't call this function on this class" << std::endl; (void)var; } }; -class ast_ParamList : public ast_Base { +class ParamList : public Base { private: - mutable std::vector<const ast_Base*> param_list; + mutable std::vector<const Base*> param_list; public: - ast_ParamList() {} + ParamList() {} - ast_ParamList(const ast_Base* param) { + ParamList(const Base* param) { param_list.push_back(param); } @@ -45,7 +45,7 @@ public: } } - virtual void push(const ast_Base* _var) const { + virtual void push(const Base* _var) const { param_list.push_back(_var); } }; diff --git a/c_parser/include/ast_primitives.hpp b/c_parser/include/ast_primitives.hpp index 5ae6d12..2eeaa19 100644 --- a/c_parser/include/ast_primitives.hpp +++ b/c_parser/include/ast_primitives.hpp @@ -5,33 +5,33 @@ #include <string> -class ast_Variable : public ast_Base { +class Variable : public Base { private: std::string id; public: - ast_Variable(const std::string& _id) : id(_id) {} + Variable(const std::string& _id) : id(_id) {} virtual void print() const { std::cout << "<Variable id=\"" << id << "\" />" << std::endl; } - virtual void push(const ast_Base* var) const { + virtual void push(const Base* var) const { std::cerr << "Error: Can't call this function on this class" << std::endl; (void)var; } }; -class ast_Parameter : public ast_Base { +class Parameter : public Base { private: std::string id; public: - ast_Parameter(const std::string& _id) : id(_id) {} + Parameter(const std::string& _id) : id(_id) {} virtual void print() const { std::cout << "<Parameter id=\"" << id << "\" />" << std::endl; } - virtual void push(const ast_Base* var) const { + virtual void push(const Base* var) const { std::cerr << "Error: Can't call this function on this class" << std::endl; (void)var; } diff --git a/c_parser/include/ast_statement.hpp b/c_parser/include/ast_statement.hpp index 224a809..4761efb 100644 --- a/c_parser/include/ast_statement.hpp +++ b/c_parser/include/ast_statement.hpp @@ -1,122 +1,81 @@ #ifndef AST_STATEMENT_HPP #define AST_STATEMENT_HPP -class ast_StatementList : public ast_Base { -protected: - mutable std::vector<const ast_Base*> statement_list; - -public: - ast_StatementList(const ast_Base* _statement) { - statement_list.push_back(_statement); - } - - virtual void print() const { - for(size_t i = 0; i < statement_list.size(); ++i) { - statement_list[i]->print(); - } - } +#include "ast.hpp" - virtual void push(const ast_Base* _statement) const { - statement_list.push_back(_statement); - } -}; - -class ast_Statement : public ast_Base { +class Statement : public Base { protected: - mutable std::vector<const ast_Base*> ast_list; + mutable std::vector<const Base*> list; public: - ast_Statement() {} + Statement() {} - ast_Statement(const ast_Base* _el) { - ast_list.push_back(_el); + Statement(const Base* _el) { + list.push_back(_el); } - ast_Statement(const ast_Base* _dec, const ast_Base* _statement) { - ast_list.push_back(_dec); - ast_list.push_back(_statement); + Statement(const Base* _dec, const Base* _statement) { + list.push_back(_dec); + list.push_back(_statement); } virtual void print() const { - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); + for(size_t i = 0; i < list.size(); ++i) { + list[i]->print(); } } - virtual void push(const ast_Base* _var) const { - ast_list.push_back(_var); + virtual void push(const Base* _var) const { + list.push_back(_var); } }; -class ast_CompoundStatement : public ast_Statement { +class StatementList : public Statement { public: - ast_CompoundStatement() : ast_Statement() {} - ast_CompoundStatement(const ast_Base* _el) : ast_Statement(_el) {} - ast_CompoundStatement(const ast_Base* _dec, const ast_Base* _statement) : - ast_Statement(_dec, _statement) {} + StatementList(const Base* _statement) : Statement(_statement) {} +}; + +class CompoundStatement : public Statement { +public: + CompoundStatement() : Statement() {} + CompoundStatement(const Base* _el) : Statement(_el) {} + CompoundStatement(const Base* _dec, const Base* _statement) : + Statement(_dec, _statement) {} virtual void print() const override { std::cout << "<Scope>" << std::endl; - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); + for(size_t i = 0; i < list.size(); ++i) { + list[i]->print(); } std::cout << "</Scope>" << std::endl; } }; -class ast_SelectionStatement : public ast_Statement { +class SelectionStatement : public Statement { public: - ast_SelectionStatement() : ast_Statement() {} - ast_SelectionStatement(const ast_Base* _el) : ast_Statement(_el) {} - ast_SelectionStatement(const ast_Base* _if, const ast_Base* _else) : - ast_Statement(_if, _else) {} - - virtual void print() const override { - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); - } - } + SelectionStatement() : Statement() {} + SelectionStatement(const Base* _el) : Statement(_el) {} + SelectionStatement(const Base* _if, const Base* _else) : + Statement(_if, _else) {} }; -class ast_ExpressionStatement : public ast_Statement { +class ExpressionStatement : public Statement { public: - ast_ExpressionStatement() : ast_Statement() {} - ast_ExpressionStatement(const ast_Base* _el) : ast_Statement(_el) {} - ast_ExpressionStatement(const ast_Base* _if, const ast_Base* _else) : - ast_Statement(_if, _else) {} - - virtual void print() const override { - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); - } - } + ExpressionStatement() : Statement() {} + ExpressionStatement(const Base* _el) : Statement(_el) {} }; -class ast_JumpStatement : public ast_Statement { +class JumpStatement : public Statement { public: - ast_JumpStatement() : ast_Statement() {} - ast_JumpStatement(const ast_Base* _el) : ast_Statement(_el) {} - ast_JumpStatement(const ast_Base* _if, const ast_Base* _else) : - ast_Statement(_if, _else) {} - - virtual void print() const override { - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); - } - } + JumpStatement() : Statement() {} + JumpStatement(const Base* _el) : Statement(_el) {} }; -class ast_IterationStatement : public ast_Statement { +class IterationStatement : public Statement { public: - ast_IterationStatement() : ast_Statement() {} - ast_IterationStatement(const ast_Base* _el) : ast_Statement(_el) {} - ast_IterationStatement(const ast_Base* _if, const ast_Base* _else) : - ast_Statement(_if, _else) {} - - virtual void print() const override { - for(size_t i = 0; i < ast_list.size(); ++i) { - ast_list[i]->print(); - } - } + IterationStatement() : Statement() {} + IterationStatement(const Base* _el) : Statement(_el) {} + IterationStatement(const Base* _if, const Base* _else) : + Statement(_if, _else) {} }; #endif diff --git a/c_parser/include/ast_top.hpp b/c_parser/include/ast_top.hpp index 142dfb8..737ff58 100644 --- a/c_parser/include/ast_top.hpp +++ b/c_parser/include/ast_top.hpp @@ -8,17 +8,17 @@ class ast_Top { public: void print() { - for(size_t i = 0; i < ast_vec.size(); ++i) { - ast_vec[i]->print(); + for(size_t i = 0; i < vec.size(); ++i) { + vec[i]->print(); } } - void push(const ast_Base *stmnt) { - ast_vec.push_back(stmnt); + void push(const Base *stmnt) { + vec.push_back(stmnt); } private: - std::vector<const ast_Base *> ast_vec; + std::vector<const Base *> vec; }; #endif diff --git a/c_parser/src/c_parser.y b/c_parser/src/c_parser.y index 53108ad..1fc4d4a 100644 --- a/c_parser/src/c_parser.y +++ b/c_parser/src/c_parser.y @@ -14,159 +14,166 @@ void yyerror(const char *); // Represents the value associated with any kind of // AST node. %union{ - const ast_Base *stmnt; + const Base *stmnt; double number; std::string *string; } %token T_TYPE_SPEC T_TYPE_QUAL T_STRG_SPEC T_IDENTIFIER -%token T_SC T_CMA T_LRB T_RRB T_LCB T_RCB T_LSB T_RSB T_QU T_COL T_LOG_OR T_LOG_AND T_OR T_XOR T_AND T_EQUALITY_OP T_REL_OP T_SHIFT_OP T_MULT T_DIV T_REM T_TILDE T_NOT T_DOT T_ARROW T_INCDEC T_ADDSUB_OP T_ASSIGN_OPER T_EQ T_SIZEOF +%token T_SC T_CMA T_LRB T_LCB T_RCB T_LSB T_RSB T_QU T_COL T_LOG_OR T_LOG_AND T_OR T_XOR T_AND T_EQUALITY_OP T_REL_OP T_SHIFT_OP T_MULT T_DIV T_REM T_TILDE T_NOT T_DOT T_ARROW T_INCDEC T_ADDSUB_OP T_ASSIGN_OPER T_EQ T_SIZEOF %token T_INT_CONST -%token T_IF T_ELSE T_WHILE T_DO T_FOR T_RETURN +%token T_IF T_WHILE T_DO T_FOR T_RETURN +%nonassoc T_RRB +%nonassoc T_ELSE + -%type <stmnt> EXT_DEF EXT_DECLARATION -%type <stmnt> FUNC_DEF PARAMETER_LIST PARAMETER PARAM_DECLARATOR -%type <stmnt> DECLARATION_LIST DECLARATION DECLARATION_SPEC DECLARATION_SPEC_T INIT_DECLARATOR INIT_DECLARATOR_LIST DECLARATOR -%type <stmnt> STATEMENT_LIST STATEMENT COMPOUND_STATEMENT COMPOUND_STATEMENT_2 SELECTION_STATEMENT SELECTION_STATEMENT_2 EXPRESSION_STATEMENT JUMP_STATEMENT ITERATION_STATEMENT -%type <stmnt> EXPRESSION ASSIGNMENT_EXPRESSION CONDITIONAL_EXPRESSION LOGICAL_OR_EXPRESSION LOGICAL_AND_EXPRESSION INCLUSIVE_OR_EXPRESSION EXCLUSIVE_OR_EXPRESSION AND_EXPRESSION EQUALITY_EXPRESSION RELATIONAL_EXPRESSION SHIFT_EXPRESSION ADDITIVE_EXPRESSION MULTIPLICATIVE_EXPRESSION CAST_EXPRESSION UNARY_EXPRESSION POSTFIX_EXPRESSION POSTFIX_EXPRESSION_2 ARGUMENT_EXPRESSION_LIST PRIMARY_EXPRESSION -%type <number> CONSTANT T_INT_CONST -%type <string> T_IDENTIFIER MULTDIVREM_OP UNARY_OPERATOR ASSIGN_OPER T_ASSIGN_OPER T_EQ T_AND T_ADDSUB_OP T_TILDE T_NOT T_MULT T_DIV T_REM //T_OPERATOR +%type <stmnt> ExtDef ExtDeclaration + +%type <stmnt> FuncDef ParameterList Parameter ParamDeclarator + +%type <stmnt> DeclarationList Declaration DeclarationSpec DeclarationSpec_T InitDeclarator InitDeclaratorList Declarator + +%type <stmnt> StatementList Statement CompoundStatement CompoundStatement_2 SelectionStatement ExpressionStatement JumpStatement IterationStatement + +%type <stmnt> Expression AssignmentExpression ConditionalExpression LogicalOrExpression LogicalAndExpression InclusiveOrExpression ExclusiveOrExpression AndExpression EqualityExpression RelationalExpression ShiftExpression AdditiveExpression MultiplicativeExpression CastExpression UnaryExpression PostfixExpression PostfixExpression2 ArgumentExpressionList PrimaryExpression + + +%type <number> Constant T_INT_CONST + + +%type <string> T_IDENTIFIER MultDivRemOP UnaryOperator ASSIGN_OPER T_ASSIGN_OPER T_EQ T_AND T_ADDSUB_OP T_TILDE T_NOT T_MULT T_DIV T_REM //T_Operator %start ROOT %% ROOT: - EXT_DEF { ; } + ExtDef { ; } ; // EXTERNAL DEFINITION -EXT_DEF: - EXT_DECLARATION { g_root->push($1); } - | EXT_DEF EXT_DECLARATION { g_root->push($2); } +ExtDef: + ExtDeclaration { g_root->push($1); } + | ExtDef ExtDeclaration { g_root->push($2); } ; -EXT_DECLARATION: - DECLARATION { $$ = $1; } - | FUNC_DEF { $$ = $1; } +ExtDeclaration: + Declaration { $$ = $1; } + | FuncDef { $$ = $1; } ; // FUNCTION DEFINITION -FUNC_DEF: - DECLARATION_SPEC T_IDENTIFIER T_LRB PARAMETER_LIST T_RRB COMPOUND_STATEMENT { $$ = new ast_Function(*$2, $4, $6); } +FuncDef: + DeclarationSpec T_IDENTIFIER T_LRB ParameterList T_RRB CompoundStatement { $$ = new Function(*$2, $4, $6); } ; -PARAMETER_LIST: - %empty { $$ = new ast_ParamList(); } - | PARAMETER { $$ = new ast_ParamList($1); } - | PARAMETER_LIST T_CMA PARAMETER { $$->push($3); } +ParameterList: + %empty { $$ = new ParamList(); } + | Parameter { $$ = new ParamList($1); } + | ParameterList T_CMA Parameter { $$->push($3); } ; -PARAMETER: - DECLARATION_SPEC PARAM_DECLARATOR { $$ = $2; } +Parameter: + DeclarationSpec ParamDeclarator { $$ = $2; } ; -PARAM_DECLARATOR: - T_IDENTIFIER { $$ = new ast_Parameter(*$1);} +ParamDeclarator: + T_IDENTIFIER { $$ = new Parameter(*$1);} ; -// DECLARATION +// Declaration -DECLARATION_LIST: - DECLARATION { $$ = new ast_DeclarationList($1); } - | DECLARATION_LIST DECLARATION { $$->push($2); } +DeclarationList: + Declaration { $$ = new DeclarationList($1); } + | DeclarationList Declaration { $$->push($2); } ; -DECLARATION: - DECLARATION_SPEC INIT_DECLARATOR_LIST T_SC { $$ = $2; } +Declaration: + DeclarationSpec InitDeclaratorList T_SC { $$ = $2; } ; -DECLARATION_SPEC: - DECLARATION_SPEC_T { ; } - | DECLARATION_SPEC_T DECLARATION_SPEC { ; } +DeclarationSpec: + DeclarationSpec_T { ; } + | DeclarationSpec_T DeclarationSpec { ; } ; -DECLARATION_SPEC_T: +DeclarationSpec_T: T_TYPE_SPEC { ; } | T_TYPE_QUAL { ; } | T_STRG_SPEC { ; } ; -INIT_DECLARATOR_LIST: - INIT_DECLARATOR { $$ = new ast_VariableDeclaration($1); } - | INIT_DECLARATOR_LIST T_CMA INIT_DECLARATOR { $$->push($3); } +InitDeclaratorList: + InitDeclarator { $$ = new VariableDeclaration($1); } + | InitDeclaratorList T_CMA InitDeclarator { $$->push($3); } ; -INIT_DECLARATOR: - DECLARATOR { ; } - | DECLARATOR T_EQ ASSIGNMENT_EXPRESSION { ; } +InitDeclarator: + Declarator { ; } + | Declarator T_EQ AssignmentExpression { ; } ; -DECLARATOR: - T_IDENTIFIER {$$ = new ast_Variable(*$1); } +Declarator: + T_IDENTIFIER {$$ = new Variable(*$1); } ; -// STATEMENT +// Statement -STATEMENT_LIST: - STATEMENT { $$ = new ast_StatementList($1); } - | STATEMENT_LIST STATEMENT { $$->push($2); } +StatementList: + Statement { $$ = new StatementList($1); } + | StatementList Statement { $$->push($2); } ; -STATEMENT: - COMPOUND_STATEMENT { $$ = $1; } - | SELECTION_STATEMENT { $$ = $1; } - | EXPRESSION_STATEMENT { $$ = $1; } - | JUMP_STATEMENT { $$ = $1; } - | ITERATION_STATEMENT { $$ = $1; } +Statement: + CompoundStatement { $$ = $1; } + | SelectionStatement { $$ = $1; } + | ExpressionStatement { $$ = $1; } + | JumpStatement { $$ = $1; } + | IterationStatement { $$ = $1; } ; -COMPOUND_STATEMENT: - T_LCB COMPOUND_STATEMENT_2 { $$ = $2; } +CompoundStatement: + T_LCB CompoundStatement_2 { $$ = $2; } ; -COMPOUND_STATEMENT_2: - T_RCB { $$ = new ast_CompoundStatement; } - | DECLARATION_LIST T_RCB { $$ = new ast_CompoundStatement($1); } - | DECLARATION_LIST STATEMENT_LIST T_RCB { $$ = new ast_CompoundStatement($1, $2); } - | STATEMENT_LIST T_RCB { $$ = new ast_CompoundStatement($1); } +CompoundStatement_2: + T_RCB { $$ = new CompoundStatement; } + | DeclarationList T_RCB { $$ = new CompoundStatement($1); } + | DeclarationList StatementList T_RCB { $$ = new CompoundStatement($1, $2); } + | StatementList T_RCB { $$ = new CompoundStatement($1); } ; -SELECTION_STATEMENT: - T_IF T_LRB EXPRESSION T_RRB STATEMENT SELECTION_STATEMENT_2 { $$ = new ast_SelectionStatement($5, $6); } +SelectionStatement: + T_IF T_LRB Expression T_RRB Statement { $$ = new SelectionStatement($5); } +| T_IF T_LRB Expression T_RRB Statement T_ELSE Statement { $$ = new SelectionStatement($5, $7); } ; -SELECTION_STATEMENT_2: - %empty { $$ = new ast_SelectionStatement(); } - | T_ELSE STATEMENT { $$ = $2; } +ExpressionStatement: + T_SC { $$ = new ExpressionStatement(); } + | Expression T_SC { $$ = $1; } ; -EXPRESSION_STATEMENT: - T_SC { $$ = new ast_ExpressionStatement(); } - | EXPRESSION T_SC { $$ = $1; } +JumpStatement: + T_RETURN ExpressionStatement { $$ = $2; } ; -JUMP_STATEMENT: - T_RETURN EXPRESSION_STATEMENT { $$ = $2; } - ; - -ITERATION_STATEMENT: - T_WHILE T_LRB EXPRESSION T_RRB STATEMENT { $$ = $5; } - | T_DO STATEMENT T_WHILE T_LRB EXPRESSION T_RRB T_SC { $$ = $2; } - | T_FOR T_LRB EXPRESSION T_SC EXPRESSION T_SC EXPRESSION T_RRB STATEMENT { $$ = $9; } +IterationStatement: + T_WHILE T_LRB Expression T_RRB Statement { $$ = $5; } + | T_DO Statement T_WHILE T_LRB Expression T_RRB T_SC { $$ = $2; } + | T_FOR T_LRB Expression T_SC Expression T_SC Expression T_RRB Statement { $$ = $9; } ; // Expressions -EXPRESSION: - ASSIGNMENT_EXPRESSION { $$ = $1; } +Expression: + AssignmentExpression { $$ = $1; } ; -ASSIGNMENT_EXPRESSION: - CONDITIONAL_EXPRESSION { $$ = $1; } - | UNARY_EXPRESSION ASSIGN_OPER ASSIGNMENT_EXPRESSION { $$ = $1; } +AssignmentExpression: + ConditionalExpression { $$ = $1; } + | UnaryExpression ASSIGN_OPER AssignmentExpression { $$ = $1; } ; ASSIGN_OPER: @@ -174,116 +181,116 @@ ASSIGN_OPER: | T_EQ { ; } ; -CONDITIONAL_EXPRESSION: - LOGICAL_OR_EXPRESSION { $$ = $1; } - | LOGICAL_OR_EXPRESSION T_QU EXPRESSION T_COL CONDITIONAL_EXPRESSION { $$ = $1; } +ConditionalExpression: + LogicalOrExpression { $$ = $1; } + | LogicalOrExpression T_QU Expression T_COL ConditionalExpression { $$ = $1; } ; -LOGICAL_OR_EXPRESSION: - LOGICAL_AND_EXPRESSION { $$ = $1; } - | LOGICAL_OR_EXPRESSION T_LOG_OR LOGICAL_AND_EXPRESSION { $$ = $3; } +LogicalOrExpression: + LogicalAndExpression { $$ = $1; } + | LogicalOrExpression T_LOG_OR LogicalAndExpression { $$ = $3; } ; -LOGICAL_AND_EXPRESSION: - INCLUSIVE_OR_EXPRESSION { $$ = $1; } - | LOGICAL_AND_EXPRESSION T_LOG_AND INCLUSIVE_OR_EXPRESSION { $$ = $3; } +LogicalAndExpression: + InclusiveOrExpression { $$ = $1; } + | LogicalAndExpression T_LOG_AND InclusiveOrExpression { $$ = $3; } ; -INCLUSIVE_OR_EXPRESSION: - EXCLUSIVE_OR_EXPRESSION { $$ = $1; } - | INCLUSIVE_OR_EXPRESSION T_OR EXCLUSIVE_OR_EXPRESSION { $$ = $3; } +InclusiveOrExpression: + ExclusiveOrExpression { $$ = $1; } + | InclusiveOrExpression T_OR ExclusiveOrExpression { $$ = $3; } ; -EXCLUSIVE_OR_EXPRESSION: - AND_EXPRESSION { $$ = $1; } - | EXCLUSIVE_OR_EXPRESSION T_XOR AND_EXPRESSION { $$ = $3; } +ExclusiveOrExpression: + AndExpression { $$ = $1; } + | ExclusiveOrExpression T_XOR AndExpression { $$ = $3; } ; -AND_EXPRESSION: - EQUALITY_EXPRESSION { $$ = $1; } - | AND_EXPRESSION T_AND EQUALITY_EXPRESSION { $$ = $3; } +AndExpression: + EqualityExpression { $$ = $1; } + | AndExpression T_AND EqualityExpression { $$ = $3; } ; -EQUALITY_EXPRESSION: - RELATIONAL_EXPRESSION { $$ = $1; } - | EQUALITY_EXPRESSION T_EQUALITY_OP RELATIONAL_EXPRESSION { $$ = $3; } +EqualityExpression: + RelationalExpression { $$ = $1; } + | EqualityExpression T_EQUALITY_OP RelationalExpression { $$ = $3; } ; -RELATIONAL_EXPRESSION: - SHIFT_EXPRESSION { $$ = $1; } - | RELATIONAL_EXPRESSION T_REL_OP SHIFT_EXPRESSION { $$ = $3; } +RelationalExpression: + ShiftExpression { $$ = $1; } + | RelationalExpression T_REL_OP ShiftExpression { $$ = $3; } ; -SHIFT_EXPRESSION: - ADDITIVE_EXPRESSION { $$ = $1; } - | SHIFT_EXPRESSION T_SHIFT_OP ADDITIVE_EXPRESSION { $$ = $3; } +ShiftExpression: + AdditiveExpression { $$ = $1; } + | ShiftExpression T_SHIFT_OP AdditiveExpression { $$ = $3; } ; -ADDITIVE_EXPRESSION: - MULTIPLICATIVE_EXPRESSION { $$ = $1; } - | ADDITIVE_EXPRESSION T_ADDSUB_OP MULTIPLICATIVE_EXPRESSION { $$ = $3; } +AdditiveExpression: + MultiplicativeExpression { $$ = $1; } + | AdditiveExpression T_ADDSUB_OP MultiplicativeExpression { $$ = $3; } ; -MULTIPLICATIVE_EXPRESSION: - CAST_EXPRESSION { $$ = $1; } - | MULTIPLICATIVE_EXPRESSION MULTDIVREM_OP CAST_EXPRESSION { $$ = $3; } +MultiplicativeExpression: + CastExpression { $$ = $1; } + | MultiplicativeExpression MultDivRemOP CastExpression { $$ = $3; } ; -MULTDIVREM_OP: +MultDivRemOP: T_MULT { $$ = $1; } | T_DIV { $$ = $1; } | T_REM { $$ = $1; } - ; + ; -CAST_EXPRESSION: - UNARY_EXPRESSION { $$ = $1; } - | T_LRB T_TYPE_SPEC T_RRB CAST_EXPRESSION { $$ = $4; } - ; +CastExpression: + UnaryExpression { $$ = $1; } + | T_LRB T_TYPE_SPEC T_RRB CastExpression { $$ = $4; } + ; -UNARY_EXPRESSION: - POSTFIX_EXPRESSION { $$ = $1; } - | T_INCDEC UNARY_EXPRESSION { $$ = $2; } - | UNARY_OPERATOR CAST_EXPRESSION { $$ = $2; } - | T_SIZEOF UNARY_EXPRESSION { $$ = $2; } - | T_SIZEOF T_LRB T_TYPE_SPEC T_RRB { $$ = new ast_Expression(); } - ; +UnaryExpression: + PostfixExpression { $$ = $1; } + | T_INCDEC UnaryExpression { $$ = $2; } + | UnaryOperator CastExpression { $$ = $2; } + | T_SIZEOF UnaryExpression { $$ = $2; } + | T_SIZEOF T_LRB T_TYPE_SPEC T_RRB { $$ = new Expression(); } + ; -UNARY_OPERATOR: +UnaryOperator: T_AND { $$ = $1; } | T_ADDSUB_OP { $$ = $1; } | T_MULT { $$ = $1; } | T_TILDE { $$ = $1; } | T_NOT { $$ = $1; } - ; + ; -POSTFIX_EXPRESSION: - PRIMARY_EXPRESSION { $$ = $1; } - | POSTFIX_EXPRESSION T_LSB EXPRESSION T_RSB { $$ = $3; } - | POSTFIX_EXPRESSION T_LRB POSTFIX_EXPRESSION_2 { $$ = $3; } - | POSTFIX_EXPRESSION T_DOT T_IDENTIFIER { $$ = new ast_Expression(); } - | POSTFIX_EXPRESSION T_ARROW T_IDENTIFIER { $$ = new ast_Expression(); } - | POSTFIX_EXPRESSION T_INCDEC { $$ = new ast_Expression(); } - ; +PostfixExpression: + PrimaryExpression { $$ = $1; } + | PostfixExpression T_LSB Expression T_RSB { $$ = $3; } + | PostfixExpression T_LRB PostfixExpression2 { $$ = $3; } + | PostfixExpression T_DOT T_IDENTIFIER { $$ = new Expression(); } + | PostfixExpression T_ARROW T_IDENTIFIER { $$ = new Expression(); } + | PostfixExpression T_INCDEC { $$ = new Expression(); } + ; -POSTFIX_EXPRESSION_2: - T_RRB { $$ = new ast_Expression(); } - | ARGUMENT_EXPRESSION_LIST T_RRB { $$ = $1; } - ; +PostfixExpression2: + T_RRB { $$ = new Expression(); } + | ArgumentExpressionList T_RRB { $$ = $1; } + ; -ARGUMENT_EXPRESSION_LIST: - ASSIGNMENT_EXPRESSION { $$ = $1; } - | ARGUMENT_EXPRESSION_LIST T_CMA ASSIGNMENT_EXPRESSION { $$ = $3; } - ; +ArgumentExpressionList: + AssignmentExpression { $$ = $1; } + | ArgumentExpressionList T_CMA AssignmentExpression { $$ = $3; } + ; -PRIMARY_EXPRESSION: - T_IDENTIFIER { $$ = new ast_Expression(); } - | CONSTANT { $$ = new ast_Expression(); } - | T_LRB EXPRESSION T_RRB { $$ = $2; } - ; +PrimaryExpression: + T_IDENTIFIER { $$ = new Expression(); } + | Constant { $$ = new Expression(); } + | T_LRB Expression T_RRB { $$ = $2; } + ; -CONSTANT: +Constant: T_INT_CONST { $$ = $1; } - ; + ; %% |