diff options
author | Mike Buland <eichlan@xagasoft.com> | 2016-12-13 12:46:09 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2016-12-13 12:46:09 -0700 |
commit | 7e0edb6c2db17c87415fbd041ef7add9dfb467e5 (patch) | |
tree | 2feddf5d1dde80d97b2eefdd299cbebc0d2e30d4 /src/parser.cpp | |
parent | 5d59aa3e9dffe2912215335ce0b76c67ebbe5a4e (diff) | |
download | clic-7e0edb6c2db17c87415fbd041ef7add9dfb467e5.tar.gz clic-7e0edb6c2db17c87415fbd041ef7add9dfb467e5.tar.bz2 clic-7e0edb6c2db17c87415fbd041ef7add9dfb467e5.tar.xz clic-7e0edb6c2db17c87415fbd041ef7add9dfb467e5.zip |
Corrected negation and single value parse bugs.
Discovered arithmetic bug in the Number class, -4 + 5 is coming back as -1, not 1. It's getting the sign wrong somehow. I'll have to hunt that down.
Diffstat (limited to 'src/parser.cpp')
-rw-r--r-- | src/parser.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 982c342..8e30d24 100644 --- a/src/parser.cpp +++ b/src/parser.cpp | |||
@@ -8,7 +8,7 @@ | |||
8 | #include <bu/sio.h> | 8 | #include <bu/sio.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
10 | 10 | ||
11 | // #define DEBUG_MODE 1 | 11 | //#define DEBUG_MODE 1 |
12 | #ifdef DEBUG_MODE | 12 | #ifdef DEBUG_MODE |
13 | #define DBG( x ) { x; } (void)0 | 13 | #define DBG( x ) { x; } (void)0 |
14 | #else | 14 | #else |
@@ -161,6 +161,7 @@ void Parser::exprP() | |||
161 | return; | 161 | return; |
162 | } | 162 | } |
163 | 163 | ||
164 | DBG( Bu::sio << "exprP on " << lex[0] << Bu::sio.nl ); | ||
164 | switch( lex[0].eType ) | 165 | switch( lex[0].eType ) |
165 | { | 166 | { |
166 | case Token::tNumber: | 167 | case Token::tNumber: |
@@ -188,7 +189,7 @@ void Parser::exprP() | |||
188 | case Token::tMinus: | 189 | case Token::tMinus: |
189 | lex.nextToken(); | 190 | lex.nextToken(); |
190 | exprP(); | 191 | exprP(); |
191 | shift( Token( Token::tNegate ) ); | 192 | shift( Token( Token::tNegate ) ); |
192 | reduce(); | 193 | reduce(); |
193 | break; | 194 | break; |
194 | } | 195 | } |
@@ -196,7 +197,7 @@ void Parser::exprP() | |||
196 | 197 | ||
197 | void Parser::statement() | 198 | void Parser::statement() |
198 | { | 199 | { |
199 | if( lex[0].eType == Token::tCommand ) | 200 | if( (lex[0].eType&Token::mMetaCmd) ) |
200 | { | 201 | { |
201 | lex.setMode( Lexer::modeCommand ); | 202 | lex.setMode( Lexer::modeCommand ); |
202 | output( lex[0] ); | 203 | output( lex[0] ); |
@@ -309,7 +310,8 @@ case Token::tCommand: | |||
309 | 310 | ||
310 | void Parser::shift( const Token &t ) | 311 | void Parser::shift( const Token &t ) |
311 | { | 312 | { |
312 | if( (t.eType&(Token::mMetaOperator)) || t.eType==Token::tCloseParen ) | 313 | if( (t.eType&(Token::mMetaOperator|Token::mMetaAltOp)) || |
314 | t.eType==Token::tCloseParen ) | ||
313 | tsTerminal.push( t ); | 315 | tsTerminal.push( t ); |
314 | else | 316 | else |
315 | tsNonTerminal.push( t ); | 317 | tsNonTerminal.push( t ); |
@@ -317,9 +319,20 @@ void Parser::shift( const Token &t ) | |||
317 | 319 | ||
318 | void Parser::reduce() | 320 | void Parser::reduce() |
319 | { | 321 | { |
320 | if( tsTerminal.isEmpty() || tsNonTerminal.peek().eType == Token::tOpenParen ) | 322 | if( tsTerminal.isEmpty() ) |
323 | { | ||
324 | DBG( Bu::sio << "reduce: terminal stack empty." << Bu::sio.nl ); | ||
325 | if( !tsNonTerminal.isEmpty() ) | ||
326 | { | ||
327 | DBG( Bu::sio << " : non-terminal stack non-empty, pushing item." << Bu::sio.nl ); | ||
328 | output( tsNonTerminal.peekPop() ); | ||
329 | } | ||
330 | return; | ||
331 | } | ||
332 | if( tsNonTerminal.peek().eType == Token::tOpenParen ) | ||
321 | return; | 333 | return; |
322 | Token tOp = tsTerminal.peekPop(); | 334 | Token tOp = tsTerminal.peekPop(); |
335 | DBG( Bu::sio << "recuding on " << tOp << Bu::sio.nl ); | ||
323 | switch( tOp.eType ) | 336 | switch( tOp.eType ) |
324 | { | 337 | { |
325 | /* | 338 | /* |
@@ -416,7 +429,6 @@ int Parser::getPriority( Token::Type eType ) | |||
416 | { | 429 | { |
417 | case Token::tNumber: | 430 | case Token::tNumber: |
418 | case Token::tVariable: | 431 | case Token::tVariable: |
419 | case Token::tCommand: | ||
420 | return 0; | 432 | return 0; |
421 | 433 | ||
422 | case Token::tPlus: | 434 | case Token::tPlus: |