From fda1ae54bc0160e2ac0ffd05f55d79cd1fdd9c2f Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Thu, 27 Nov 2014 21:55:40 +0100 Subject: [PATCH] Shorter prefix for parser pseudonamespace. --- Makefile | 8 ++++---- Monicelli.ll | 22 +++++++++++----------- Monicelli.y | 2 +- main.cpp | 14 +++++++------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 3b0afc0..9069950 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/Monicelli.ll b/Monicelli.ll index 54902cb..7384bfc 100644 --- a/Monicelli.ll +++ b/Monicelli.ll @@ -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_] [ \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; } . { - monicelli_error("Unexpected token"); + mcerror("Unexpected token"); return -1; } diff --git a/Monicelli.y b/Monicelli.y index 79a2a72..77d7cd3 100644 --- a/Monicelli.y +++ b/Monicelli.y @@ -15,7 +15,7 @@ extern Program *program; #include "Nodes.hpp" } -%define api.prefix {monicelli_} +%define api.prefix {mc} %token MAIN %token RETURN diff --git a/main.cpp b/main.cpp index 5f1f555..afe32a8 100644 --- a/main.cpp +++ b/main.cpp @@ -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]);