From c8c5ef5467283f26998e79507ac1479523e5dd69 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 29 Jun 2010 16:24:54 +0200 Subject: [PATCH] added bracket parsing --- components/compiler/exprparser.cpp | 25 +++++++++++++++++++++++++ components/compiler/exprparser.hpp | 2 ++ 2 files changed, 27 insertions(+) diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index 11347e3e4..12f63d3aa 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -14,6 +14,10 @@ namespace Compiler { switch (op) { + case '(': + + return 0; + case '+': case '-': @@ -143,6 +147,14 @@ namespace Compiler mNextOperand = true; } + void ExprParser::close() + { + while (getOperator()!='(') + pop(); + + popOperator(); + } + ExprParser::ExprParser (ErrorHandler& errorHandler, Context& context, Locals& locals, Literals& literals) : Parser (errorHandler, context), mLocals (locals), mLiterals (literals), @@ -209,6 +221,19 @@ namespace Compiler return true; } + if (code==Scanner::S_open && mNextOperand) + { + mOperators.push_back ('('); + mTokenLoc = loc; + return true; + } + + if (code==Scanner::S_close && !mNextOperand) + { + close(); + return true; + } + mTokenLoc = loc; switch (code) diff --git a/components/compiler/exprparser.hpp b/components/compiler/exprparser.hpp index 73d6b82d7..a87dd995b 100644 --- a/components/compiler/exprparser.hpp +++ b/components/compiler/exprparser.hpp @@ -43,6 +43,8 @@ namespace Compiler void pushBinaryOperator (char c); + void close(); + public: ExprParser (ErrorHandler& errorHandler, Context& context, Locals& locals,