Commit 5bca02f Fiwo735
committed
1 parent 5fbac2d commit 5bca02f Copy full SHA for 5bca02f
File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 8
8
#include " ast.hpp"
9
9
using namespace ast ;
10
10
11
+ extern int yylineno;
12
+ extern char * yytext;
11
13
extern Node* g_root;
12
14
extern FILE* yyin;
13
15
16
18
int yylex_destroy (void );
17
19
}
18
20
21
+ %define parse.error detailed
22
+ %define parse.lac full
23
+
19
24
%union {
20
25
Node* node;
21
26
NodeList* node_list;
33
38
%token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID
34
39
%token STRUCT UNION ENUM ELLIPSIS
35
40
%token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
41
+ %token UNKNOWN
36
42
37
43
%type <node> translation_unit external_declaration function_definition primary_expression postfix_expression
38
44
%type <node> unary_expression cast_expression multiplicative_expression additive_expression shift_expression relational_expression
@@ -185,6 +191,13 @@ expression
185
191
186
192
%%
187
193
194
+ void yyerror (const char *s)
195
+ {
196
+ std::cerr << " Error: " << s << " at line " << yylineno;
197
+ std::cerr << " near '" << yytext << " '" << std::endl;
198
+ std::exit (1 );
199
+ }
200
+
188
201
Node* g_root;
189
202
190
203
NodePtr ParseAST (std::string file_name)
Original file line number Diff line number Diff line change 4
4
#include "ast.hpp"
5
5
using namespace ast;
6
6
7
+ extern int yylineno;
8
+ extern char* yytext;
7
9
extern Node* g_root;
8
10
extern FILE* yyin;
9
11
12
14
int yylex_destroy(void);
13
15
}
14
16
17
+ %define parse.error detailed
18
+ %define parse.lac full
19
+
15
20
// Represents the value associated with any kind of AST node.
16
21
%union {
17
22
Node* node;
30
35
%token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID
31
36
%token STRUCT UNION ENUM ELLIPSIS
32
37
%token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
38
+ %token UNKNOWN
33
39
34
40
%type <node> translation_unit external_declaration function_definition primary_expression postfix_expression argument_expression_list
35
41
%type <node> unary_expression cast_expression multiplicative_expression additive_expression shift_expression relational_expression
@@ -462,6 +468,13 @@ jump_statement
462
468
463
469
%%
464
470
471
+ void yyerror (const char *s)
472
+ {
473
+ std::cerr << "Error: " << s << " at line " << yylineno;
474
+ std::cerr << " near '" << yytext << "'" << std::endl;
475
+ std::exit(1);
476
+ }
477
+
465
478
Node* g_root;
466
479
467
480
NodePtr ParseAST(std::string file_name)
You can’t perform that action at this time.
0 commit comments