summaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2013-05-09 15:24:11 -0600
committerMike Buland <mike@xagasoft.com>2013-05-09 15:24:11 -0600
commitce68e816bd82612c14f3492e8bc969da9bfab06c (patch)
treebe50fa63ce720ecde2748df3df83f38a284c3ff6 /src/parser.cpp
parent722e0ef0ea2624c1cd9bd5ca69833e37dc09f97f (diff)
downloadclic-ce68e816bd82612c14f3492e8bc969da9bfab06c.tar.gz
clic-ce68e816bd82612c14f3492e8bc969da9bfab06c.tar.bz2
clic-ce68e816bd82612c14f3492e8bc969da9bfab06c.tar.xz
clic-ce68e816bd82612c14f3492e8bc969da9bfab06c.zip
Added better filtering in Number::set, and cli options.
The command line options let you set the initial radix/scale, and there's a function te test if any number is prime, that's fun.
Diffstat (limited to '')
-rw-r--r--src/parser.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 57144c2..38988f5 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -152,22 +152,17 @@ void Parser::parse()
152 152
153 default: 153 default:
154 if( tsNonTerminal.getSize() == 0 || 154 if( tsNonTerminal.getSize() == 0 ||
155 getPriority( tsNonTerminal.peek().eType ) < 155 getPriority( tsNonTerminal.peek().eType ) <=
156 getPriority( t.eType ) ) 156 getPriority( t.eType ) )
157 { 157 {
158// Bu::println("Pushing non-terminal: %1").arg( t.eType ); 158// Bu::println("Pushing non-terminal: %1").arg( t.eType );
159 tsNonTerminal.push( t ); 159 tsNonTerminal.push( t );
160
161// for( TokenStack::iterator i = tsTerminal.begin(); i; i++ ) Bu::print(" [%1]").arg( *(*i).nVal ); Bu::println("");
162// for( TokenStack::iterator i = tsNonTerminal.begin(); i; i++ ) Bu::print(" <%1>").arg( (*i).eType ); Bu::println("");
163 } 160 }
164 else 161 else
165 { 162 {
166// Bu::println("Unwinding stack before pushing: %1").arg( t.eType ); 163// Bu::println("Unwinding stack before pushing: %1").arg( t.eType );
167 unwind(); 164 unwind();
168 tsNonTerminal.push( t ); 165 tsNonTerminal.push( t );
169// for( TokenStack::iterator i = tsTerminal.begin(); i; i++ ) Bu::print(" [%1]").arg( *(*i).nVal ); Bu::println("");
170// for( TokenStack::iterator i = tsNonTerminal.begin(); i; i++ ) Bu::print(" <%1>").arg( (*i).eType ); Bu::println("");
171 } 166 }
172 break; 167 break;
173 } 168 }
@@ -178,8 +173,19 @@ void Parser::unwind()
178{ 173{
179 for(;;) 174 for(;;)
180 { 175 {
181// for( TokenStack::iterator i = tsTerminal.begin(); i; i++ ) Bu::print(" [%1]").arg( *(*i).nVal ); Bu::println(""); 176/*
182// for( TokenStack::iterator i = tsNonTerminal.begin(); i; i++ ) Bu::print(" <%1>").arg( (*i).eType ); Bu::println(""); 177 for( TokenStack::iterator i = tsTerminal.begin(); i; i++ )
178 {
179 if( (*i).eType == Token::tNumber )
180 Bu::print(" [%1]").arg( *(*i).nVal );
181 else
182 Bu::print(" [%1]").arg( *(*i).sVal );
183 }
184 Bu::println("");
185 for( TokenStack::iterator i = tsNonTerminal.begin(); i; i++ )
186 Bu::print(" <%1>").arg( (*i).eType );
187 Bu::println("");
188*/
183 if( tsNonTerminal.isEmpty() ) 189 if( tsNonTerminal.isEmpty() )
184 return; 190 return;
185 191
@@ -330,7 +336,6 @@ int Parser::getPriority( Token::Type eType )
330 case Token::tNumber: 336 case Token::tNumber:
331 case Token::tVariable: 337 case Token::tVariable:
332 case Token::tCommand: 338 case Token::tCommand:
333 case Token::tEquals:
334 return 0; 339 return 0;
335 340
336 case Token::tPlus: 341 case Token::tPlus:
@@ -348,6 +353,7 @@ int Parser::getPriority( Token::Type eType )
348 353
349 case Token::tEndOfLine: 354 case Token::tEndOfLine:
350 case Token::tEndOfInput: 355 case Token::tEndOfInput:
356 case Token::tEquals:
351 return -1; 357 return -1;
352 358
353 default: 359 default: