From 4efeaef41e57b25d6004e7f91828f7d5b5cd0b20 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 1 Dec 2016 09:51:06 -0700 Subject: 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. --- src/parser.cpp | 32 +++++++++++++++++++++++--------- src/token.h | 48 ++++++++++++++++++++++++++++-------------------- 2 files changed, 51 insertions(+), 29 deletions(-) (limited to 'src') 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() " " << lex[1] << Bu::sio.nl; shift( lex[0] ); - if( lex[1].eType == Token::tPlus || - lex[1].eType == Token::tMinus || - lex[1].eType == Token::tDivide || - lex[1].eType == Token::tMultiply || - lex[1].eType == Token::tModulus || - lex[1].eType == Token::tEquals ) + if( lex[1].eType&Token::mMetaOperator ) { if( getPriority(lex[1].eType) <= getPriority(t.eType) ) @@ -117,9 +112,17 @@ void Parser::expr() printState("no next op"); } } - else + else if( lex[0].eType == Token::tMinus ) { - Bu::println("???"); + // This is negation + Bu::sio << "next token: " << lex[0] << Bu::sio.nl; + printState("inline-negate"); + exprP(); + printState("inline-negate-post"); + shift( t ); + printState("inline-negate-post2"); + + Bu::sio << "??? " << lex[0] << Bu::sio.nl; } } break; @@ -171,7 +174,8 @@ void Parser::exprP() case Token::tMinus: lex.nextToken(); exprP(); - shift( Token( Token::tNegate ) ); + shift( Token( Token::tNegate ) ); + reduce(); break; } } @@ -310,6 +314,16 @@ void Parser::reduce() shift( Token( Token::tComputedValue ) ); break; + case Token::tNegate: + { + Token t = tsParse.peekPop(); + if( t.eType != Token::tComputedValue ) + tsScript.append( t ); + tsScript.append( tOp ); + shift( Token( Token::tComputedValue ) ); + } + break; + case Token::tCloseParen: if( tsParse.peek().eType != Token::tComputedValue ) { 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 public: enum Type { - tNumber, - tVariable, - tCommand, - tPlus, - tMinus, - tDivide, - tMultiply, - tModulus, - tOpenParen, - tCloseParen, - tEquals, - tString, - - tNegate, - tEndOfLine, - - tEndOfInput, - - tUninitialized, - tComputedValue + tNumber = 0x1001, + tVariable = 0x2002, + tCommand = 0x2003, + tPlus = 0x4004, + tMinus = 0x4005, + tDivide = 0x4006, + tMultiply = 0x4007, + tModulus = 0x4008, + tOpenParen = 0x8009, + tCloseParen = 0x800a, + tEquals = 0x400b, + tString = 0x200c, + + tNegate = 0x800d, + tEndOfLine = 0x010e, + + tEndOfInput = 0x010f, + + tUninitialized = 0x0110, + tComputedValue = 0x0111, + + + mMetaNumber = 0x1000, + mMetaString = 0x2000, + mMetaOperator = 0x4000, + mMetaAltOp = 0x8000, + mMetaMeta = 0x0100, + }; Token(); -- cgit v1.2.3