From 79c7619dabcbdf0ed371d175ca7e751a21371e06 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Mon, 30 Mar 2009 11:16:40 +0000 Subject: [PATCH] New expression system now handles simple numeric values git-svn-id: http://picoc.googlecode.com/svn/trunk@214 21eae674-98b7-11dd-bd71-f92a316d2d60 --- expression.c | 7 ++++++- picoc.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/expression.c b/expression.c index f9f1ca5..c0d664e 100644 --- a/expression.c +++ b/expression.c @@ -817,6 +817,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) do { + struct ParseState PreState = *Parser; enum LexToken Token = LexGetToken(Parser, &LexValue, TRUE); if ((int)Token <= (int)TokenCloseBracket) { /* it's an operator with precedence */ @@ -904,6 +905,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) } else { /* it isn't a token from an expression */ + *Parser = PreState; Done = TRUE; } @@ -916,7 +918,10 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) if (StackTop != NULL) { /* all that should be left is a single value on the stack */ - HeapPopStack((void *)StackTop - sizeof(struct ExpressionStack), sizeof(struct ExpressionStack)); + if (Parser->Mode == RunModeRun) + *Result = StackTop->Val; + + HeapPopStack(StackTop, sizeof(struct ExpressionStack)); } return TRUE; diff --git a/picoc.h b/picoc.h index 5599357..4784216 100644 --- a/picoc.h +++ b/picoc.h @@ -271,6 +271,7 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp void Parse(const char *FileName, const char *Source, int SourceLen, int RunIt); void ParseInteractive(); void ParseCleanup(); +void ParserCopyPos(struct ParseState *To, struct ParseState *From); /* expression.c */ int ExpressionParse(struct ParseState *Parser, struct Value **Result);