From de0a76818e96caaf57b28287848db65d5413cb61 Mon Sep 17 00:00:00 2001 From: John Doty Date: Wed, 17 Apr 2024 17:13:18 -0700 Subject: [PATCH] faster: Correct precedence but don't use it Precedence now works for, like, resolving expressions in a single big table but uh... it takes the time from 700ms to like 7s so I've reverted it for now. --- grammar.py | 1 + parser_faster.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/grammar.py b/grammar.py index abb1b04..6d775b5 100644 --- a/grammar.py +++ b/grammar.py @@ -143,6 +143,7 @@ precedence = [ (Assoc.LEFT, [LESS, GREATER, GREATEREQUAL, LESSEQUAL]), (Assoc.LEFT, [PLUS, MINUS]), (Assoc.LEFT, [STAR, SLASH]), + (Assoc.LEFT, ["PrimaryExpression"]), (Assoc.LEFT, [LPAREN]), (Assoc.LEFT, [DOT]), diff --git a/parser_faster.py b/parser_faster.py index fad7d70..fd81306 100644 --- a/parser_faster.py +++ b/parser_faster.py @@ -321,6 +321,12 @@ class TableBuilder(object): action = ('goto', index) self._set_table_action(symbol, action, None) + def _action_precedence(self, symbol, action, config): + if action[0] == 'shift': + return self.precedence[symbol] + else: + return self.precedence[config.name] + def _set_table_action(self, symbol_id: int, action, config: Configuration|None): """Set the action for 'symbol' in the table row to 'action'. @@ -335,9 +341,10 @@ class TableBuilder(object): assert existing_config is not None assert config is not None - # Maybe we can resolve the conflict with precedence? - existing_assoc, existing_prec = self.precedence[existing_config.name] - new_assoc, new_prec = self.precedence[config.name] + existing_assoc, existing_prec = self._action_precedence( + symbol_id, existing, existing_config) + new_assoc, new_prec = self._action_precedence( + symbol_id, action, config) if existing_prec > new_prec: # Precedence of the action in the table already wins, do nothing.