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 | |
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')
-rw-r--r-- | src/parser.cpp | 32 | ||||
-rw-r--r-- | src/token.h | 48 |
2 files changed, 51 insertions, 29 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 | { |
diff --git a/src/token.h b/src/token.h index 072a96b..4ad1136 100644 --- a/src/token.h +++ b/src/token.h | |||
@@ -13,26 +13,34 @@ class Token | |||
13 | public: | 13 | public: |
14 | enum Type | 14 | enum Type |
15 | { | 15 | { |
16 | tNumber, | 16 | tNumber = 0x1001, |
17 | tVariable, | 17 | tVariable = 0x2002, |
18 | tCommand, | 18 | tCommand = 0x2003, |
19 | tPlus, | 19 | tPlus = 0x4004, |
20 | tMinus, | 20 | tMinus = 0x4005, |
21 | tDivide, | 21 | tDivide = 0x4006, |
22 | tMultiply, | 22 | tMultiply = 0x4007, |
23 | tModulus, | 23 | tModulus = 0x4008, |
24 | tOpenParen, | 24 | tOpenParen = 0x8009, |
25 | tCloseParen, | 25 | tCloseParen = 0x800a, |
26 | tEquals, | 26 | tEquals = 0x400b, |
27 | tString, | 27 | tString = 0x200c, |
28 | 28 | ||
29 | tNegate, | 29 | tNegate = 0x800d, |
30 | tEndOfLine, | 30 | tEndOfLine = 0x010e, |
31 | 31 | ||
32 | tEndOfInput, | 32 | tEndOfInput = 0x010f, |
33 | 33 | ||
34 | tUninitialized, | 34 | tUninitialized = 0x0110, |
35 | tComputedValue | 35 | tComputedValue = 0x0111, |
36 | |||
37 | |||
38 | mMetaNumber = 0x1000, | ||
39 | mMetaString = 0x2000, | ||
40 | mMetaOperator = 0x4000, | ||
41 | mMetaAltOp = 0x8000, | ||
42 | mMetaMeta = 0x0100, | ||
43 | |||
36 | }; | 44 | }; |
37 | 45 | ||
38 | Token(); | 46 | Token(); |