summaryrefslogtreecommitdiffstats
path: root/src/parser.y
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2015-11-30 02:22:06 +0800
committerTing-Wei Lan <lantw44@gmail.com>2015-11-30 02:28:14 +0800
commit91f04bf7a454171f1c37d2a42deada3af82fba55 (patch)
treecb0cd267e287a9651fbfb463dfa663fa2f091614 /src/parser.y
parent60a45efca23c7b1339b4fd9f1673f5d1812dc132 (diff)
downloadcompiler2015-91f04bf7a454171f1c37d2a42deada3af82fba55.tar
compiler2015-91f04bf7a454171f1c37d2a42deada3af82fba55.tar.gz
compiler2015-91f04bf7a454171f1c37d2a42deada3af82fba55.tar.bz2
compiler2015-91f04bf7a454171f1c37d2a42deada3af82fba55.tar.lz
compiler2015-91f04bf7a454171f1c37d2a42deada3af82fba55.tar.xz
compiler2015-91f04bf7a454171f1c37d2a42deada3af82fba55.tar.zst
compiler2015-91f04bf7a454171f1c37d2a42deada3af82fba55.zip
Don't include lexer.c and move yyerror to the end of file
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/parser.y b/src/parser.y
index 128788d..c705907 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -8,8 +8,13 @@
#include <string.h>
#include "ast.h"
+extern int yylex(void);
+static void yyerror(const char *mesg);
+
AST_NODE *prog;
+extern char *yytext;
+extern int line_number;
extern int g_anyErrorOccur;
%}
@@ -57,17 +62,6 @@ extern int g_anyErrorOccur;
%right DL_RPAREN ELSE
-%{
-#include "lexer.c"
-
-int yyerror (char *mesg)
-{
- fprintf(stderr, "Error found in Line \t%d\tnext token: \t%s\n",
- line_number, yytext);
- exit(1);
-}
-%}
-
%type <node> program global_decl_list global_decl function_decl block stmt_list
%type <node> decl_list decl var_decl type init_id_list init_id stmt relop_expr
%type <node> relop_term relop_factor expr term factor var_ref param_list param
@@ -693,3 +687,9 @@ dim_list : dim_list DL_LBRACK expr DL_RBRACK
%%
+static void yyerror(const char *mesg)
+{
+ fprintf(stderr, "Error found in Line \t%d\tnext token: \t%s\n",
+ line_number, yytext);
+ exit(1);
+}