# HG changeset patch # User Teemu Piippo # Date 1344735633 -10800 # Node ID a29eeecf3ecb66da5350371fe35ed4ba1e06cf4c # Parent e1d3b7ea975ce37628c035c181c6c4aa9b98e623 Expressions now allow multiple operators diff -r e1d3b7ea975c -r a29eeecf3ecb parser.cxx --- a/parser.cxx Sun Aug 12 04:13:27 2012 +0300 +++ b/parser.cxx Sun Aug 12 04:40:33 2012 +0300 @@ -533,40 +533,34 @@ DataBuffer* ScriptReader::ParseExpression (int reqtype) { DataBuffer* retbuf = new DataBuffer (64); - DataBuffer* lb = NULL; - - lb = ParseExprValue (reqtype); + // Parse first operand + retbuf->Merge (ParseExprValue (reqtype)); - // Get an operator - int oper = ParseOperator (true); - - // No operator found - stop here. - if (oper == -1) { - retbuf->Merge (lb); - return retbuf; + // Parse any and all operators we get + int oper; + while ((oper = ParseOperator (true)) != -1) { + // We peeked the operator, move forward now + MustNext(); + + // Can't be an assignement operator, those belong in assignments. + if (IsAssignmentOperator (oper)) + ParserError ("assignment operator inside expressions"); + + // Parse the right operand, + MustNext (); + DataBuffer* rb = ParseExprValue (reqtype); + + // Write to buffer + retbuf->Merge (rb); + long dh = DataHeaderByOperator (NULL, oper); + retbuf->Write (dh); } - // We peeked the operator, move forward now - MustNext(); - - // Can't be an assignement operator, those belong in assignments. - if (IsAssignmentOperator (oper)) - ParserError ("assignment operator inside expressions"); - - // Parse the right operand, - MustNext (); - DataBuffer* rb = ParseExprValue (reqtype); - - retbuf->Merge (lb); - retbuf->Merge (rb); - - long dh = DataHeaderByOperator (NULL, oper); - retbuf->Write (dh); return retbuf; } // ============================================================================ -// `arses an operator string. Returns the operator number code. +// Parses an operator string. Returns the operator number code. int ScriptReader::ParseOperator (bool peek) { str oper; if (peek) @@ -685,7 +679,7 @@ // Parse the right operand, MustNext (); - DataBuffer* retbuf = ParseExprValue (TYPE_INT); + DataBuffer* retbuf = ParseExpression (TYPE_INT); long dh = DataHeaderByOperator (var, oper); retbuf->Write (dh);