diff --git a/LangS.l b/LangS.l index 142602b..170d365 100644 --- a/LangS.l +++ b/LangS.l @@ -4,8 +4,9 @@ #include #include -#define YYSTYPE std::string +#define YYSTYPE ParseTree::Node* +#include "ParseTree.h" #include "LangS.tab.hpp" void yyerror(std::string s); @@ -17,18 +18,19 @@ void yyerror(std::string s); exit {return Exit; } print {return Print; } '.*' { - yylval = yytext; - yylval.erase(yylval.begin()); - yylval.erase(yylval.end()-1); + std::string text=yytext; + text.erase(text.begin()); + text.erase(text.end()-1); + yylval = new ParseTree::StringValue(text); return STRING; } -[[:digit:]]+ {yylval = yytext; return STRING; } -$[[:alpha:]]+ {yylval = yytext; return Scalar; } -%[[:alpha:]]+ {yylval = yytext; return Vector; } -[-] {yylval = '-'; return BinOP; } -[+] {yylval = '+'; return BinOP; } -[\*] {yylval = '*'; return BinOP; } -[\\/] {yylval = '/'; return BinOP; } +[[:digit:]]+ {yylval = new ParseTree::StringValue(yytext); return STRING; } +$[[:alpha:]]+ {yylval = new ParseTree::Identifier(yytext); return Scalar; } +%[[:alpha:]]+ {yylval = new ParseTree::Identifier(yytext); return Vector; } +[-] {yylval = new ParseTree::Identifier("-"); return BinOP; } +[+] {yylval = new ParseTree::Identifier("+"); return BinOP; } +[\*] {yylval = new ParseTree::Identifier("*"); return BinOP; } +[\\/] {yylval = new ParseTree::Identifier("/"); return BinOP; } [[:punct:]] {return *yytext; } [[:space:]]+ ; /* ignore whitespace */ . { yyerror("Unhandeled character "+std::string(yytext)); }; diff --git a/LangS.ypp b/LangS.ypp index 2deb8e7..730fd1b 100644 --- a/LangS.ypp +++ b/LangS.ypp @@ -5,9 +5,11 @@ #include #include "LangS.h" +#include "ParseTree.h" -#define YYSTYPE string +#define YYSTYPE Node* using namespace std; +using namespace ParseTree; std::ofstream out; void yyerror(std::string s); @@ -29,15 +31,15 @@ int yylex (void); Prog: Stm ';' Prog | Stm ';' -Stm: Exit { } - | Scalar '=' Value { setValue($1, $3); } +Stm: Exit { $$ = new ExitStatement();} + | Scalar '=' Value { $$ = new AssingmentStatement((Identifier*)$1,(Value*)$3); } | Vector '=' List { } | Value { } - | Print Value { cout<< $2 <getName(),(Value*)$1,(Value*)$3); } List: '[' Items ']' diff --git a/ParseTree.h b/ParseTree.h new file mode 100644 index 0000000..7918b6f --- /dev/null +++ b/ParseTree.h @@ -0,0 +1,21 @@ +/* + * ParseTree.h + * + * Created on: Apr 26, 2013 + * Author: jimtahu + */ + +#ifndef PARSETREE_H_ +#define PARSETREE_H_ + +#include "Node.h" +#include "Value.h" +#include "Identifier.h" +#include "StringValue.h" +#include "BinOpValue.h" +#include "Statement.h" +#include "AssingmentStatement.h" +#include "ExitStatement.h" +#include "PrintStatement.h" + +#endif /* PARSETREE_H_ */ diff --git a/Statement.cpp b/Statement.cpp index 232f042..a3c6d69 100644 --- a/Statement.cpp +++ b/Statement.cpp @@ -14,7 +14,6 @@ namespace ParseTree { using namespace std; Statement::Statement() { - cerr << "Creation of abstract statement" << endl; } void Statement::Execute(){