Shorter prefix for parser pseudonamespace.

This commit is contained in:
Stefano Sanfilippo 2014-11-27 21:55:40 +01:00
parent ce513643da
commit fda1ae54bc
4 changed files with 23 additions and 23 deletions

View File

@ -1,11 +1,11 @@
compile: compile:
bison --verbose -d Monicelli.y bison --verbose -d Monicelli.y
flex -P monicelli_ Monicelli.ll flex -P mc Monicelli.ll
g++ -std=c++11 -DYYDEBUG=0 Monicelli.tab.c lex.monicelli_.c Nodes.cpp main.cpp -o mcc g++ -std=c++11 -DYYDEBUG=0 Monicelli.tab.c lex.mc.c Nodes.cpp main.cpp -o mcc
rm Monicelli.tab.* lex.monicelli_.c rm Monicelli.tab.* lex.mc.c
graph: graph:
bison --graph Monicelli.y bison --graph Monicelli.y
clean: clean:
rm -f Monicelli.dot Monicelli.tab.* lex.monicelli_.c Monicelli.output rm -f Monicelli.dot Monicelli.tab.* lex.mc.c Monicelli.output

View File

@ -5,8 +5,8 @@
extern int lineNumber; extern int lineNumber;
void monicelli_error(const char *); void mcerror(const char *);
void monicelli_meta(const char *); void mcmeta(const char *);
using namespace monicelli; using namespace monicelli;
%} %}
@ -25,7 +25,7 @@ CHAR [a-zA-Z_]
} }
"#"[^\n]* { "#"[^\n]* {
monicelli_meta(yytext + 1); mcmeta(yytext + 1);
} }
"bituma"[^\n]* {} "bituma"[^\n]* {}
@ -37,23 +37,23 @@ CHAR [a-zA-Z_]
return RETURN; return RETURN;
} }
"Necchi" { "Necchi" {
monicelli_lval.typeval = Type::INT; mclval.typeval = Type::INT;
return TYPENAME; return TYPENAME;
} }
"Mascetti" { "Mascetti" {
monicelli_lval.typeval = Type::CHAR; mclval.typeval = Type::CHAR;
return TYPENAME; return TYPENAME;
} }
"Perozzi" { "Perozzi" {
monicelli_lval.typeval = Type::FLOAT; mclval.typeval = Type::FLOAT;
return TYPENAME; return TYPENAME;
} }
"Melandri" { "Melandri" {
monicelli_lval.typeval = Type::BOOL; mclval.typeval = Type::BOOL;
return TYPENAME; return TYPENAME;
} }
"Sassaroli" { "Sassaroli" {
monicelli_lval.typeval = Type::DOUBLE; mclval.typeval = Type::DOUBLE;
return TYPENAME; return TYPENAME;
} }
"conte" { "conte" {
@ -162,17 +162,17 @@ CHAR [a-zA-Z_]
<INITIAL,shift>[ \t\f\v] {} <INITIAL,shift>[ \t\f\v] {}
{CHAR}({DIGIT}|{CHAR})* { {CHAR}({DIGIT}|{CHAR})* {
monicelli_lval.strval = strdup(yytext); mclval.strval = strdup(yytext);
return ID; return ID;
} }
{DIGIT}+ { {DIGIT}+ {
monicelli_lval.intval = strtol(yytext, NULL, 10); mclval.intval = strtol(yytext, NULL, 10);
return NUMBER; return NUMBER;
} }
<INITIAL,shift>. { <INITIAL,shift>. {
monicelli_error("Unexpected token"); mcerror("Unexpected token");
return -1; return -1;
} }

View File

@ -15,7 +15,7 @@ extern Program *program;
#include "Nodes.hpp" #include "Nodes.hpp"
} }
%define api.prefix {monicelli_} %define api.prefix {mc}
%token MAIN %token MAIN
%token RETURN %token RETURN

View File

@ -11,15 +11,15 @@ using namespace monicelli;
int lineNumber = 1; int lineNumber = 1;
Program *program; Program *program;
extern FILE *monicelli_in; extern FILE *mcin;
void monicelli_error(const char *message) { void mcerror(const char *message) {
std::cerr << "At line " << lineNumber << ": " << message << std::endl; std::cerr << "At line " << lineNumber << ": " << message << std::endl;
std::exit(1); std::exit(1);
} }
void monicelli_meta(const char *text) { void mcmeta(const char *text) {
while (text != '\0' && *text == ' ') { while (text != '\0' && *text == ' ') {
text += 1; text += 1;
} }
@ -28,7 +28,7 @@ void monicelli_meta(const char *text) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
#if YYDEBUG #if YYDEBUG
monicelli_debug = 1; mcdebug = 1;
#endif #endif
bool fromFile = argc > 1; bool fromFile = argc > 1;
@ -37,11 +37,11 @@ int main(int argc, char **argv) {
program = new Program(); program = new Program();
if (fromFile) { if (fromFile) {
monicelli_in = fopen(argv[1], "r"); mcin = fopen(argv[1], "r");
} }
monicelli_parse(); mcparse();
if (fromFile) { if (fromFile) {
fclose(monicelli_in); fclose(mcin);
} }
if (toFile) { if (toFile) {
std::ofstream out(argv[2]); std::ofstream out(argv[2]);