diff options
Diffstat (limited to 'src/parser.cpp')
-rw-r--r-- | src/parser.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 1f9a193..0131ba3 100644 --- a/src/parser.cpp +++ b/src/parser.cpp | |||
@@ -23,25 +23,53 @@ void Parser::parse() | |||
23 | for(;;) | 23 | for(;;) |
24 | { | 24 | { |
25 | lex.nextToken(); | 25 | lex.nextToken(); |
26 | if( lex[0].eType == Token::tEndOfInput ) | ||
27 | break; | ||
28 | |||
26 | expr(); | 29 | expr(); |
27 | 30 | ||
31 | Bu::sio << "Final stack:"; | ||
28 | for( TokenStack::iterator i = tsStack.begin(); i; i++ ) | 32 | for( TokenStack::iterator i = tsStack.begin(); i; i++ ) |
29 | { | 33 | { |
30 | Bu::sio << *i << " "; | 34 | Bu::sio << " " << (*i).eType; |
35 | if( (*i).eType == Token::tNumber ) | ||
36 | { | ||
37 | Bu::sio << "(" << (*i).nVal->toString() << ")"; | ||
38 | } | ||
31 | } | 39 | } |
40 | Bu::sio << Bu::sio.nl; | ||
32 | } | 41 | } |
33 | } | 42 | } |
34 | 43 | ||
35 | void Parser::expr() | 44 | void Parser::expr() |
36 | { | 45 | { |
46 | if( lex[0].eType == Token::tEndOfInput ) | ||
47 | return; | ||
37 | if( lex[0].eType == Token::tVariable && | 48 | if( lex[0].eType == Token::tVariable && |
38 | lex[1].eType == Token::tEquals ) | 49 | lex[1].eType == Token::tEquals ) |
39 | { | 50 | { |
40 | // Assignment! | 51 | Token t = lex[0]; |
52 | lex.nextToken(); | ||
53 | lex.nextToken(); | ||
41 | expr(); | 54 | expr(); |
55 | |||
42 | return; | 56 | return; |
43 | } | 57 | } |
44 | exprP(); | 58 | exprP(); |
59 | |||
60 | switch( lex[0].eType ) | ||
61 | { | ||
62 | case Token::tPlus: | ||
63 | case Token::tMinus: | ||
64 | case Token::tMultiply: | ||
65 | case Token::tDivide: | ||
66 | case Token::tModulus: | ||
67 | Token t = lex[0]; | ||
68 | lex.nextToken(); | ||
69 | expr(); | ||
70 | tsStack.push( t ); | ||
71 | break; | ||
72 | } | ||
45 | } | 73 | } |
46 | 74 | ||
47 | void Parser::exprP() | 75 | void Parser::exprP() |
@@ -222,7 +250,7 @@ void Parser::setVariable( const Bu::String &sName, const Number &rValue ) | |||
222 | hVars.insert( sName, rValue ); | 250 | hVars.insert( sName, rValue ); |
223 | } | 251 | } |
224 | 252 | ||
225 | void Parser::unwind() | 253 | void Parser::reduce() |
226 | { | 254 | { |
227 | /* | 255 | /* |
228 | for(;;) | 256 | for(;;) |