diff --git a/Monicelli.ll b/Monicelli.ll index 12a8c82..9d69e7d 100644 --- a/Monicelli.ll +++ b/Monicelli.ll @@ -1,7 +1,8 @@ %{ #include "Monicelli.tab.h" -#include -#include + +#include +#include extern int lineNumber; @@ -163,7 +164,7 @@ CHAR [a-zA-Z_] [ \t\f\v] {} {CHAR}({DIGIT}|{CHAR})* { - mclval.strval = strdup(yytext); + mclval.strval = new std::string(yytext); return ID; } diff --git a/Monicelli.y b/Monicelli.y index 5471f84..7e014db 100644 --- a/Monicelli.y +++ b/Monicelli.y @@ -6,9 +6,6 @@ extern int yylex(); #include "Nodes.hpp" -// For free() -#include - using namespace monicelli; extern Program *program; @@ -53,7 +50,7 @@ static std::stack branchCaseStack; %union { int intval; double floatval; - char *strval; + std::string* strval; bool boolval; monicelli::Type typeval; monicelli::Statement* statementval; @@ -131,7 +128,6 @@ fun_decl: $$ = new Function(new Id($2), paramsStack.top(), stmtStack.top()); paramsStack.pop(); stmtStack.pop(); - free($2); } ; args: @@ -195,11 +191,9 @@ numeric: variable: ID { $$ = new Id($1); - free($1); } | ARTICLE ID { $$ = new Id($2); - free($2); } ; assign_stmt: @@ -273,7 +267,6 @@ fun_call: ID call_args FUN_END { $$ = new FunctionCall(new Id($3), argsStack.top()); argsStack.pop(); - free($3); } ; call_args: diff --git a/Nodes.cpp b/Nodes.cpp index d1db6b0..6b85e04 100644 --- a/Nodes.cpp +++ b/Nodes.cpp @@ -11,7 +11,7 @@ void emitIndent(std::ostream &stream, int indent) { } void Id::emit(std::ostream &stream, int indent) { - stream << value; + stream << *value; } void Integer::emit(std::ostream &stream, int indent) { diff --git a/Nodes.hpp b/Nodes.hpp index 2bcab38..e51db20 100644 --- a/Nodes.hpp +++ b/Nodes.hpp @@ -90,13 +90,13 @@ class SimpleExpression: public Expression { class Id: public SimpleExpression { public: - explicit Id(const char *c): value(c) {} + explicit Id(std::string *c): value(c) {} virtual ~Id() {} virtual void emit(std::ostream &stream, int indent = 0); private: - std::string value; + std::unique_ptr value; };