From 2f4f4035353bb497d35470072d8dbf284a57e580 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Thu, 15 Dec 2016 02:42:12 +0100 Subject: [PATCH] Add lslcalc support. lslcalc is currently derived from a snapshot of PyOptimizer at some point in past, making it difficult to maintain when bug fixes are applied to the optimizer. Solve this by incorporating expression evaluation capabilities. --- lslopt/lslparse.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lslopt/lslparse.py b/lslopt/lslparse.py index b143b0d..af44cdc 100644 --- a/lslopt/lslparse.py +++ b/lslopt/lslparse.py @@ -2359,6 +2359,17 @@ list lazy_list_set(list L, integer i, list v) del self.jump_lookups # Finished with it. + def Parse_single_expression(self): + """Parse the script as an expression, Used by lslcalc. + + Grammar parsed here: + + script: expression EOF + """ + value = self.Parse_expression() + self.tree.append({'nt':'EXPR', 't':value['t'], 'ch':[value]}) + return + def BuildTempGlobalsTable(self): """Build an approximate globals table. @@ -2609,7 +2620,8 @@ list lazy_list_set(list L, integer i, list v) self.linestart = True self.tok = self.GetToken() - self.globals = self.BuildTempGlobalsTable() + self.globals = self.BuildTempGlobalsTable() if \ + 'lslcalc' not in options else self.funclibrary.copy() # Restart @@ -2623,7 +2635,10 @@ list lazy_list_set(list L, integer i, list v) self.usedspots = 0 # Start the parsing proper - self.Parse_script() + if 'lslcalc' in options: + self.Parse_single_expression() + else: + self.Parse_script() # No longer needed. The data is already in self.symtab[0]. del self.globals