From 31dd02aaa60d7ffee48a87befe47f0d252feb2da Mon Sep 17 00:00:00 2001 From: Kia <kia@special-circumstanc.es> Date: Sat, 25 Jan 2020 16:35:30 -0700 Subject: [PATCH] add definitions of terms in hex --- combinatorial_LR_parser.py | 82 +++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/combinatorial_LR_parser.py b/combinatorial_LR_parser.py index 0ec554e..924291c 100644 --- a/combinatorial_LR_parser.py +++ b/combinatorial_LR_parser.py @@ -598,59 +598,53 @@ class DummyPlug(Elaboratable): mem = Memory(width=16, depth=256, init=[0x5a00, 0xe142, 0xAB00, 0xe102]) m.submodules.parse_data = rdport = mem.read_port() - match_rules = [ - # Rule 1: E{x} + T{y} => E{x + y} - [(0, 0xff00, 0xE700), (1, 0xff00, 0xAA00), (2, 0xff00, 0xEE00)], - - # Rule 2: T{x} => E{x} - [(0, 0xff00, 0xE700)], - - # Rule 3: T{x} * F{y} => T{x * y} - [(0, 0xff00, 0xEF00), (1, 0xff00, 0xAB00), (2, 0xff00, 0xE700)], - - # Rule 4: F{x} => T{x} - [(0, 0xff00, 0xEF00)], - - # Rule 5: ( E{x} ) => F{x} - [(0, 0xff00, 0xcb00), (1, 0xff00, 0xee00), (2, 0xff00, 0xca00)], - - # Rule 6: Int{x} => F{x} - [(0, 0xff00, 0xE100)] - ] - def extractor(x): return (x & 0x00ff) + # EXPRESSION = 0xEE00 + # TERM = 0xE700 + # FACTOR = 0xEF00 + # INTEGER = 0xE100 + # OPEN PAREN = 0xCA00 + # CLOSE PAREN = 0xCB00 + # ADDOP = 0xAA00 + # MULTOP = 0xAB00 common_stack_states = [ # State 0 in the paper - [(0, 0xffff, 0x5a00)], # Bottom of parse stack + # Bottom of parse stack + [(0, 0xffff, 0x5a00)], # State 1 in the paper - [(1, 0xffff, 0x5a00), (0, 0xff00, 0xEE00)], # Bottom of parse stack, Expression + # Bottom of parse stack Expression + [(1, 0xffff, 0x5a00), (0, 0xff00, 0xEE00)], # state 2 in paper - [(0, 0xff00, 0xE700)], # Term + # TERM + [(0, 0xff00, 0xE700)], # state 3 in paper - [(0, 0xff00, 0xEF00)], # Factor + # FACTOR + [(0, 0xff00, 0xEF00)], # State 4 in paper - [(0, 0xff00, 0xca00)], # Open paren + # OPEN PAREN + [(0, 0xff00, 0xca00)], # State 5 in paper - [(0, 0xff00, 0xE100)], # Integer + # INTEGER + [(0, 0xff00, 0xE100)], # State 6 in paper - - [(1, 0xff00, 0xEE00), (0, 0xff00, 0xAA00)] # Expression, Plus + # EXPRESSION PLUS + [(1, 0xff00, 0xEE00), (0, 0xff00, 0xAA00)] # State 7 in paper - - [(1, 0xff00, 0xE700), (0, 0xff00, 0xAB00)] # Term, Multiply + # TERM MULTIPLY + [(1, 0xff00, 0xE700), (0, 0xff00, 0xAB00)] # State 8 in paper - - [(1, 0xff00, 0xCA00), (0, 0xff00, 0xEE00)] # Open paren, Expression + # OPEN PAREN EXPRESSION + [(1, 0xff00, 0xCA00), (0, 0xff00, 0xEE00)] # State 9 in paper # EXPRESSION PLUS TERM @@ -663,9 +657,33 @@ class DummyPlug(Elaboratable): # State 11 in paper # OPEN PAREN EXPRESSION CLOSE PAREN [(2, 0xff00, 0xCA00), (1, 0xff00, 0xEE00), (0, 0xFF00, 0xCB00)] + ] + + + match_rules = [ + # Rule 1: E{x} + T{y} => E{x + y} + [(0, 0xff00, 0xE700), (1, 0xff00, 0xAA00), (2, 0xff00, 0xEE00)], + + # Rule 2: T{x} => E{x} + [(0, 0xff00, 0xE700)], + + # Rule 3: T{x} * F{y} => T{x * y} + [(0, 0xff00, 0xEF00), (1, 0xff00, 0xAB00), (2, 0xff00, 0xE700)], + # Rule 4: F{x} => T{x} + [(0, 0xff00, 0xEF00)], + + # Rule 5: ( E{x} ) => F{x} + [(0, 0xff00, 0xcb00), (1, 0xff00, 0xee00), (2, 0xff00, 0xca00)], + # Rule 6: Int{x} => F{x} + [(0, 0xff00, 0xE100)] ] + def extractor(x): return (x & 0x00ff) + + + + validitem_ruleset = [] pairwise_priority_ruleset = [] forceshift_ruleset = [] -- GitLab