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:
bison --verbose -d Monicelli.y
flex -P monicelli_ Monicelli.ll
g++ -std=c++11 -DYYDEBUG=0 Monicelli.tab.c lex.monicelli_.c Nodes.cpp main.cpp -o mcc
rm Monicelli.tab.* lex.monicelli_.c
flex -P mc Monicelli.ll
g++ -std=c++11 -DYYDEBUG=0 Monicelli.tab.c lex.mc.c Nodes.cpp main.cpp -o mcc
rm Monicelli.tab.* lex.mc.c
graph:
bison --graph Monicelli.y
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;
void monicelli_error(const char *);
void monicelli_meta(const char *);
void mcerror(const char *);
void mcmeta(const char *);
using namespace monicelli;
%}
@ -25,7 +25,7 @@ CHAR [a-zA-Z_]
}
"#"[^\n]* {
monicelli_meta(yytext + 1);
mcmeta(yytext + 1);
}
"bituma"[^\n]* {}
@ -37,23 +37,23 @@ CHAR [a-zA-Z_]
return RETURN;
}
"Necchi" {
monicelli_lval.typeval = Type::INT;
mclval.typeval = Type::INT;
return TYPENAME;
}
"Mascetti" {
monicelli_lval.typeval = Type::CHAR;
mclval.typeval = Type::CHAR;
return TYPENAME;
}
"Perozzi" {
monicelli_lval.typeval = Type::FLOAT;
mclval.typeval = Type::FLOAT;
return TYPENAME;
}
"Melandri" {
monicelli_lval.typeval = Type::BOOL;
mclval.typeval = Type::BOOL;
return TYPENAME;
}
"Sassaroli" {
monicelli_lval.typeval = Type::DOUBLE;
mclval.typeval = Type::DOUBLE;
return TYPENAME;
}
"conte" {
@ -162,17 +162,17 @@ CHAR [a-zA-Z_]
<INITIAL,shift>[ \t\f\v] {}
{CHAR}({DIGIT}|{CHAR})* {
monicelli_lval.strval = strdup(yytext);
mclval.strval = strdup(yytext);
return ID;
}
{DIGIT}+ {
monicelli_lval.intval = strtol(yytext, NULL, 10);
mclval.intval = strtol(yytext, NULL, 10);
return NUMBER;
}
<INITIAL,shift>. {
monicelli_error("Unexpected token");
mcerror("Unexpected token");
return -1;
}

View File

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

View File

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