From abe845ab98c027bc0895f597c6e4b663b423a065 Mon Sep 17 00:00:00 2001 From: jimtahu Date: Thu, 25 Apr 2013 15:51:55 -0500 Subject: [PATCH] Split vars into Scalar and Vector --- LangS.cpp | 6 +++++- LangS.l | 6 ++++-- LangS.ypp | 23 +++++++++++++---------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/LangS.cpp b/LangS.cpp index 862c3fd..73eac5f 100644 --- a/LangS.cpp +++ b/LangS.cpp @@ -5,7 +5,7 @@ using namespace std; void yyerror(std::string s); -int yylex (void); +int yyparse (void); map varTable; @@ -87,3 +87,7 @@ string binOP(string op, string a, string b){ }else return a+b; }//end binOP +int main(int argc, char *argv[]) { + yyparse(); + return 0; +}//end main diff --git a/LangS.l b/LangS.l index 9ee8246..142602b 100644 --- a/LangS.l +++ b/LangS.l @@ -14,6 +14,7 @@ void yyerror(std::string s); %% +exit {return Exit; } print {return Print; } '.*' { yylval = yytext; @@ -21,8 +22,9 @@ print {return Print; } yylval.erase(yylval.end()-1); return STRING; } -$[[:alpha:]]+ {yylval = yytext; return VAR; } -[[:digit:]]+ {yylval = yytext; return NUM; } +[[:digit:]]+ {yylval = yytext; return STRING; } +$[[:alpha:]]+ {yylval = yytext; return Scalar; } +%[[:alpha:]]+ {yylval = yytext; return Vector; } [-] {yylval = '-'; return BinOP; } [+] {yylval = '+'; return BinOP; } [\*] {yylval = '*'; return BinOP; } diff --git a/LangS.ypp b/LangS.ypp index c24e1a9..2deb8e7 100644 --- a/LangS.ypp +++ b/LangS.ypp @@ -15,11 +15,12 @@ int yylex (void); %} -%token VAR -%token NUM +%token Scalar +%token Vector %token STRING %token BinOP %token Print +%token Exit %left BinOP @@ -28,15 +29,21 @@ int yylex (void); Prog: Stm ';' Prog | Stm ';' -Stm: VAR '=' Value { setValue($1, $3); } - | Value { } +Stm: Exit { } + | Scalar '=' Value { setValue($1, $3); } + | Vector '=' List { } + | Value { } | Print Value { cout<< $2 <