summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2016-12-19 15:52:04 -0700
committerMike Buland <eichlan@xagasoft.com>2016-12-19 15:52:04 -0700
commit0580d6a85fda454b05620aa4415a53f3dbcd3475 (patch)
treeef257f03b3c395f7eb2177177bbafef9e5de8265
parentf7035d970fc629e3e95f03dd5f4e9618cb3230d7 (diff)
downloadclic-newparser.tar.gz
clic-newparser.tar.bz2
clic-newparser.tar.xz
clic-newparser.zip
It actually sorta' works again!newparser
-rw-r--r--src/main.cpp29
-rw-r--r--src/parser.cpp6
-rw-r--r--src/scriptengine.cpp31
3 files changed, 62 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 667d19a..1365f1f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,6 +5,8 @@
5#include "token.h" 5#include "token.h"
6#include "parser.h" 6#include "parser.h"
7#include "options.h" 7#include "options.h"
8#include "scriptengine.h"
9
8#include <math.h> 10#include <math.h>
9#include <sys/time.h> 11#include <sys/time.h>
10 12
@@ -14,6 +16,21 @@
14#include <bu/streamstack.h> 16#include <bu/streamstack.h>
15using namespace Bu; 17using namespace Bu;
16 18
19void numResult( const class Number &num )
20{
21 println("==> %1").arg( num );
22}
23
24void dispError( const Bu::String &sMsg )
25{
26 println(sMsg);
27}
28
29void dispMessage( const Bu::String &sMsg )
30{
31 println(sMsg);
32}
33
17int main( int argc, char *argv[] ) 34int main( int argc, char *argv[] )
18{ 35{
19 try 36 try
@@ -28,7 +45,17 @@ int main( int argc, char *argv[] )
28 lex.setScale( opt.getScale() ); 45 lex.setScale( opt.getScale() );
29 lex.setRadix( opt.getRadix() ); 46 lex.setRadix( opt.getRadix() );
30 Parser parser( lex ); 47 Parser parser( lex );
31 parser.parse(); 48
49 ScriptEngine se;
50 se.sigNumResult = Bu::slot(numResult);
51 se.sigError = Bu::slot(dispError);
52 se.sigMessage = Bu::slot(dispMessage);
53 for(;;)
54 {
55 Expression *pExpr = parser.parse();
56 se.exec( pExpr );
57 delete pExpr;
58 }
32 } 59 }
33 catch( std::exception &e ) 60 catch( std::exception &e )
34 { 61 {
diff --git a/src/parser.cpp b/src/parser.cpp
index c83c156..cdb1064 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -26,6 +26,8 @@ Parser::~Parser()
26 26
27Expression *Parser::parse() 27Expression *Parser::parse()
28{ 28{
29 while( lex[0].eType == Token::tEndOfLine )
30 lex.nextToken();
29 pCurExp = new Expression(); 31 pCurExp = new Expression();
30 statement(); 32 statement();
31 while( !tsTerminal.isEmpty() ) 33 while( !tsTerminal.isEmpty() )
@@ -33,6 +35,9 @@ Expression *Parser::parse()
33 reduce(); 35 reduce();
34 } 36 }
35 37
38 if( lex[0].eType == Token::tEndOfLine )
39 lex.nextToken();
40
36 printState("Final"); 41 printState("Final");
37 42
38 tsTerminal.clear(); 43 tsTerminal.clear();
@@ -247,6 +252,7 @@ void Parser::statement()
247 break; 252 break;
248 } 253 }
249 lex.setMode( Lexer::modeNormal ); 254 lex.setMode( Lexer::modeNormal );
255 lex.nextToken();
250 } 256 }
251 else 257 else
252 { 258 {
diff --git a/src/scriptengine.cpp b/src/scriptengine.cpp
index e4c5c2e..6a00af8 100644
--- a/src/scriptengine.cpp
+++ b/src/scriptengine.cpp
@@ -105,7 +105,7 @@ void ScriptEngine::exec( Expression *pExpr )
105 } 105 }
106 } 106 }
107 107
108 if( sigNumResult.isSet() ) 108 if( sigNumResult.isSet() && !sNums.isEmpty() )
109 sigNumResult( sNums.peekPop() ); 109 sigNumResult( sNums.peekPop() );
110} 110}
111 111
@@ -134,12 +134,34 @@ void ScriptEngine::command( Expression::iterator &i )
134 } 134 }
135 if( sigMessage.isSet() ) 135 if( sigMessage.isSet() )
136 sigMessage(Bu::String("Changed scale to: %1").arg( iScale )); 136 sigMessage(Bu::String("Changed scale to: %1").arg( iScale ));
137 for( VarHash::iterator i = hVarState.begin(); i; i++ ) 137 for( VarHash::iterator j = hVarState.begin(); j; j++ )
138 (*i).setScale( iScale ); 138 (*j).setScale( iScale );
139 i++;
139 } 140 }
140 break; 141 break;
141 142
142 case Token::tCmdRadix: 143 case Token::tCmdRadix:
144 {
145 if( !(++i) )
146 {
147 if( sigError.isSet() )
148 sigError("You must provide a positive integer.");
149 return;
150 }
151 int32_t iRadix = strtol( (*i).sVal->getStr(), 0, 10 );
152 if( iRadix < 0 )
153 {
154 if( sigError.isSet() )
155 sigError("You must provide a positive integer.");
156 return;
157 }
158 if( sigMessage.isSet() )
159 sigMessage(Bu::String("Changed radix to: %1").arg( iRadix ));
160 hVarState.clear();
161// for( VarHash::iterator i = hVarState.begin(); i; i++ )
162// (*i).setRadix( iRadix );
163 i++;
164 }
143 break; 165 break;
144 166
145 case Token::tCmdExtended: 167 case Token::tCmdExtended:
@@ -155,5 +177,8 @@ void ScriptEngine::command( Expression::iterator &i )
155 }*/ 177 }*/
156 break; 178 break;
157 } 179 }
180
181 if( (*i).eType != Token::tCmdEndParams )
182 sigError("Too many parameters.");
158} 183}
159 184