diff options
author | Mike Buland <eichlan@xagasoft.com> | 2016-12-01 09:51:06 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2016-12-01 09:51:06 -0700 |
commit | 4efeaef41e57b25d6004e7f91828f7d5b5cd0b20 (patch) | |
tree | 19986986ab7e4638547588094fcc19275cfe9ef3 /src/parser.cpp | |
parent | 3015ea4677201060777435cf76815e898d221f8c (diff) | |
download | clic-4efeaef41e57b25d6004e7f91828f7d5b5cd0b20.tar.gz clic-4efeaef41e57b25d6004e7f91828f7d5b5cd0b20.tar.bz2 clic-4efeaef41e57b25d6004e7f91828f7d5b5cd0b20.tar.xz clic-4efeaef41e57b25d6004e7f91828f7d5b5cd0b20.zip |
Forgot assignment and negation. They both work now.
That was actually really cool. Now to clean up the debugging code and write
the execution engine.
Diffstat (limited to 'src/parser.cpp')
-rw-r--r-- | src/parser.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index f88ffe7..04a81ce 100644 --- a/src/parser.cpp +++ b/src/parser.cpp | |||
@@ -79,12 +79,7 @@ void Parser::expr() | |||
79 | " " << lex[1] << | 79 | " " << lex[1] << |
80 | Bu::sio.nl; | 80 | Bu::sio.nl; |
81 | shift( lex[0] ); | 81 | shift( lex[0] ); |
82 | if( lex[1].eType == Token::tPlus || | 82 | if( lex[1].eType&Token::mMetaOperator ) |
83 | lex[1].eType == Token::tMinus || | ||
84 | lex[1].eType == Token::tDivide || | ||
85 | lex[1].eType == Token::tMultiply || | ||
86 | lex[1].eType == Token::tModulus || | ||
87 | lex[1].eType == Token::tEquals ) | ||
88 | { | 83 | { |
89 | if( getPriority(lex[1].eType) <= | 84 | if( getPriority(lex[1].eType) <= |
90 | getPriority(t.eType) ) | 85 | getPriority(t.eType) ) |
@@ -117,9 +112,17 @@ void Parser::expr() | |||
117 | printState("no next op"); | 112 | printState("no next op"); |
118 | } | 113 | } |
119 | } | 114 | } |
120 | else | 115 | else if( lex[0].eType == Token::tMinus ) |
121 | { | 116 | { |
122 | Bu::println("???"); | 117 | // This is negation |
118 | Bu::sio << "next token: " << lex[0] << Bu::sio.nl; | ||
119 | printState("inline-negate"); | ||
120 | exprP(); | ||
121 | printState("inline-negate-post"); | ||
122 | shift( t ); | ||
123 | printState("inline-negate-post2"); | ||
124 | |||
125 | Bu::sio << "??? " << lex[0] << Bu::sio.nl; | ||
123 | } | 126 | } |
124 | } | 127 | } |
125 | break; | 128 | break; |
@@ -171,7 +174,8 @@ void Parser::exprP() | |||
171 | case Token::tMinus: | 174 | case Token::tMinus: |
172 | lex.nextToken(); | 175 | lex.nextToken(); |
173 | exprP(); | 176 | exprP(); |
174 | shift( Token( Token::tNegate ) ); | 177 | shift( Token( Token::tNegate ) ); |
178 | reduce(); | ||
175 | break; | 179 | break; |
176 | } | 180 | } |
177 | } | 181 | } |
@@ -310,6 +314,16 @@ void Parser::reduce() | |||
310 | shift( Token( Token::tComputedValue ) ); | 314 | shift( Token( Token::tComputedValue ) ); |
311 | break; | 315 | break; |
312 | 316 | ||
317 | case Token::tNegate: | ||
318 | { | ||
319 | Token t = tsParse.peekPop(); | ||
320 | if( t.eType != Token::tComputedValue ) | ||
321 | tsScript.append( t ); | ||
322 | tsScript.append( tOp ); | ||
323 | shift( Token( Token::tComputedValue ) ); | ||
324 | } | ||
325 | break; | ||
326 | |||
313 | case Token::tCloseParen: | 327 | case Token::tCloseParen: |
314 | if( tsParse.peek().eType != Token::tComputedValue ) | 328 | if( tsParse.peek().eType != Token::tComputedValue ) |
315 | { | 329 | { |