From 0321e6e39b8cf24718cf853c28f0f35443753264 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 30 Nov 2016 13:57:04 -0700 Subject: Working on the parser, some issues. --- src/parser.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index 153b6fe..1f9a193 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -20,6 +20,58 @@ Parser::~Parser() void Parser::parse() { + for(;;) + { + lex.nextToken(); + expr(); + + for( TokenStack::iterator i = tsStack.begin(); i; i++ ) + { + Bu::sio << *i << " "; + } + } +} + +void Parser::expr() +{ + if( lex[0].eType == Token::tVariable && + lex[1].eType == Token::tEquals ) + { + // Assignment! + expr(); + return; + } + exprP(); +} + +void Parser::exprP() +{ + switch( lex[0].eType ) + { + case Token::tNumber: + case Token::tVariable: + tsStack.push( lex[0] ); + lex.nextToken(); + break; + + case Token::tOpenParen: + lex.nextToken(); + expr(); + if( lex[0].eType != Token::tCloseParen ) + { + throw Bu::ExceptionBase("Expected close paren"); + } + lex.nextToken(); + break; + + case Token::tMinus: + lex.nextToken(); + exprP(); + tsStack.push( Token( Token::tNegate ) ); + break; + } +} +/* for(;;) { Token t = lex.nextToken(); @@ -158,6 +210,7 @@ void Parser::parse() } } } +*/ Number Parser::getVariable( const Bu::String &sName ) { @@ -171,6 +224,7 @@ void Parser::setVariable( const Bu::String &sName, const Number &rValue ) void Parser::unwind() { + /* for(;;) { DBS_START( PARSE ); @@ -312,6 +366,7 @@ void Parser::unwind() getPriority( t.eType ) ) return; } + */ } int Parser::reqTokens( Token::Type eType ) -- cgit v1.2.3