move C code out of parser.y to parser.c
This commit is contained in:
parent
8db0a47fb4
commit
fc5dfb7744
30
src/parser/parser.c
Normal file
30
src/parser/parser.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include "parser.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern FILE * yyin;
|
||||
|
||||
static const char * input_fname;
|
||||
|
||||
void parse(const char * filename)
|
||||
{
|
||||
input_fname = filename;
|
||||
yyin = fopen(filename, "r");
|
||||
if (yyin == NULL)
|
||||
{
|
||||
fprintf(stderr, "Error opening \"%s\"\n", filename);
|
||||
return;
|
||||
}
|
||||
if (yyparse() != 0)
|
||||
{
|
||||
fprintf(stderr, "Parsing error\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_parse_error(const char * str, const YYLTYPE * yylloc)
|
||||
{
|
||||
fprintf(stderr, "error: %s (line %d, column %d)\n",
|
||||
str,
|
||||
yylloc->first_line,
|
||||
yylloc->first_column);
|
||||
}
|
@ -2,9 +2,11 @@
|
||||
#define PARSER_H
|
||||
|
||||
#include "Node.h"
|
||||
#include "parser.tab.h"
|
||||
|
||||
#define YYSTYPE Node *
|
||||
|
||||
void parse(const char * filename);
|
||||
void handle_parse_error(const char * str, const YYLTYPE * yylloc);
|
||||
|
||||
#endif
|
||||
|
@ -4,7 +4,6 @@
|
||||
%{
|
||||
|
||||
#include "parser.h"
|
||||
#include "parser.tab.h"
|
||||
#include "String.h"
|
||||
#include <stdlib.h>
|
||||
#include "Node.h"
|
||||
|
@ -2,13 +2,10 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "parser.h"
|
||||
#include "parser.tab.h"
|
||||
|
||||
#define yyerror(msg) handle_error(msg, &yyloc)
|
||||
#define yyerror(msg) handle_parse_error(msg, &yyloc)
|
||||
|
||||
extern FILE * yyin;
|
||||
int yylex(YYSTYPE *, YYLTYPE *);
|
||||
static void handle_error(const char * str, const YYLTYPE * yylloc);
|
||||
|
||||
%}
|
||||
|
||||
@ -452,26 +449,3 @@ function_definition: declarator declaration_list compound_statement
|
||||
| declaration_specifiers declarator compound_statement
|
||||
;
|
||||
%%
|
||||
|
||||
static void handle_error(const char * str, const YYLTYPE * yylloc)
|
||||
{
|
||||
fprintf(stderr, "error: %s (line %d, column %d)\n",
|
||||
str,
|
||||
yylloc->first_line,
|
||||
yylloc->first_column);
|
||||
}
|
||||
|
||||
void parse(const char * filename)
|
||||
{
|
||||
yyin = fopen(filename, "r");
|
||||
if (yyin == NULL)
|
||||
{
|
||||
fprintf(stderr, "Error opening \"%s\"\n", filename);
|
||||
return;
|
||||
}
|
||||
if (yyparse() != 0)
|
||||
{
|
||||
fprintf(stderr, "Parsing error\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user