diff options
Diffstat (limited to '')
-rw-r--r-- | src/parser.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index c7cf994..701c4bd 100644 --- a/src/parser.cpp +++ b/src/parser.cpp | |||
@@ -20,8 +20,7 @@ Parser::~Parser() | |||
20 | Expression *Parser::parse() | 20 | Expression *Parser::parse() |
21 | { | 21 | { |
22 | pCurExp = new Expression(); | 22 | pCurExp = new Expression(); |
23 | exprR(); | 23 | statement(); |
24 | reduce(); | ||
25 | 24 | ||
26 | printState("Final"); | 25 | printState("Final"); |
27 | 26 | ||
@@ -40,7 +39,7 @@ void Parser::exprR() | |||
40 | 39 | ||
41 | void Parser::expr() | 40 | void Parser::expr() |
42 | { | 41 | { |
43 | //Bu::sio << "::expr " << lex[0] << Bu::sio.nl; | 42 | Bu::sio << "::expr " << lex[0] << Bu::sio.nl; |
44 | if( lex[0].eType == Token::tEndOfInput ) | 43 | if( lex[0].eType == Token::tEndOfInput ) |
45 | return; | 44 | return; |
46 | 45 | ||
@@ -57,7 +56,7 @@ void Parser::expr() | |||
57 | case Token::tModulus: | 56 | case Token::tModulus: |
58 | Token t = lex[0]; | 57 | Token t = lex[0]; |
59 | lex.nextToken(); | 58 | lex.nextToken(); |
60 | //Bu::sio << "->expr " << t << " " << lex[0] << Bu::sio.nl; | 59 | Bu::sio << "->expr " << t << " " << lex[0] << Bu::sio.nl; |
61 | if( lex[0].eType == Token::tOpenParen ) | 60 | if( lex[0].eType == Token::tOpenParen ) |
62 | { | 61 | { |
63 | exprP(); | 62 | exprP(); |
@@ -70,10 +69,10 @@ void Parser::expr() | |||
70 | if( lex[0].eType == Token::tNumber || | 69 | if( lex[0].eType == Token::tNumber || |
71 | lex[0].eType == Token::tVariable ) | 70 | lex[0].eType == Token::tVariable ) |
72 | { | 71 | { |
73 | //Bu::sio << "->expr " << t << | 72 | Bu::sio << "->expr " << t << |
74 | // " " << lex[0] << | 73 | " " << lex[0] << |
75 | // " " << lex[1] << | 74 | " " << lex[1] << |
76 | // Bu::sio.nl; | 75 | Bu::sio.nl; |
77 | shift( lex[0] ); | 76 | shift( lex[0] ); |
78 | if( lex[1].eType&Token::mMetaOperator ) | 77 | if( lex[1].eType&Token::mMetaOperator ) |
79 | { | 78 | { |
@@ -111,14 +110,14 @@ void Parser::expr() | |||
111 | else if( lex[0].eType == Token::tMinus ) | 110 | else if( lex[0].eType == Token::tMinus ) |
112 | { | 111 | { |
113 | // This is negation | 112 | // This is negation |
114 | //Bu::sio << "next token: " << lex[0] << Bu::sio.nl; | 113 | Bu::sio << "next token: " << lex[0] << Bu::sio.nl; |
115 | printState("inline-negate"); | 114 | printState("inline-negate"); |
116 | exprP(); | 115 | exprP(); |
117 | printState("inline-negate-post"); | 116 | printState("inline-negate-post"); |
118 | shift( t ); | 117 | shift( t ); |
119 | printState("inline-negate-post2"); | 118 | printState("inline-negate-post2"); |
120 | 119 | ||
121 | //Bu::sio << "??? " << lex[0] << Bu::sio.nl; | 120 | Bu::sio << "??? " << lex[0] << Bu::sio.nl; |
122 | } | 121 | } |
123 | } | 122 | } |
124 | break; | 123 | break; |
@@ -157,7 +156,7 @@ void Parser::exprP() | |||
157 | exprR(); | 156 | exprR(); |
158 | if( lex[0].eType != Token::tCloseParen ) | 157 | if( lex[0].eType != Token::tCloseParen ) |
159 | { | 158 | { |
160 | //Bu::sio << "::exprP " << lex[0] << Bu::sio.nl; | 159 | Bu::sio << "::exprP " << lex[0] << Bu::sio.nl; |
161 | throw Bu::ExceptionBase("Expected close paren"); | 160 | throw Bu::ExceptionBase("Expected close paren"); |
162 | } | 161 | } |
163 | shift( lex[0] ); | 162 | shift( lex[0] ); |
@@ -175,6 +174,21 @@ void Parser::exprP() | |||
175 | break; | 174 | break; |
176 | } | 175 | } |
177 | } | 176 | } |
177 | |||
178 | void Parser::statement() | ||
179 | { | ||
180 | if( lex[0].eType == Token::tCommand ) | ||
181 | { | ||
182 | lex.setMode( Lexer::modeCommand ); | ||
183 | lex.setMode( Lexer::modeNormal ); | ||
184 | } | ||
185 | else | ||
186 | { | ||
187 | exprR(); | ||
188 | reduce(); | ||
189 | } | ||
190 | } | ||
191 | |||
178 | /* | 192 | /* |
179 | case Token::tCommand: | 193 | case Token::tCommand: |
180 | lex.setMode( Lexer::modeCommand ); | 194 | lex.setMode( Lexer::modeCommand ); |
@@ -403,7 +417,6 @@ int Parser::getPriority( Token::Type eType ) | |||
403 | 417 | ||
404 | void Parser::printState( const Bu::String &sTag ) | 418 | void Parser::printState( const Bu::String &sTag ) |
405 | { | 419 | { |
406 | /* | ||
407 | Bu::sio << "----------------" << Bu::sio.nl; | 420 | Bu::sio << "----------------" << Bu::sio.nl; |
408 | Bu::sio << sTag << " stack:"; | 421 | Bu::sio << sTag << " stack:"; |
409 | for( TokenStack::iterator i = tsParse.begin(); i; i++ ) | 422 | for( TokenStack::iterator i = tsParse.begin(); i; i++ ) |
@@ -418,6 +431,5 @@ void Parser::printState( const Bu::String &sTag ) | |||
418 | } | 431 | } |
419 | Bu::sio << Bu::sio.nl; | 432 | Bu::sio << Bu::sio.nl; |
420 | Bu::sio << "----------------" << Bu::sio.nl; | 433 | Bu::sio << "----------------" << Bu::sio.nl; |
421 | */ | ||
422 | } | 434 | } |
423 | 435 | ||