From ed09c3727dbdb045d4d518bb6f00c5666f56aeb4 Mon Sep 17 00:00:00 2001 From: Kia <kia@special-circumstanc.es> Date: Thu, 22 Apr 2021 11:46:35 -0600 Subject: [PATCH] explain width of parse tree stream --- unoptimized_lr/simple_lr_automaton.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/unoptimized_lr/simple_lr_automaton.py b/unoptimized_lr/simple_lr_automaton.py index e4dcaf7..7207ece 100644 --- a/unoptimized_lr/simple_lr_automaton.py +++ b/unoptimized_lr/simple_lr_automaton.py @@ -163,9 +163,16 @@ from functools import reduce # (index out, data out, stack pointer) # WLongestParse # -# Serialization memory (or stream): -# -# max(WLongestRule, 1 + WNonterminal, 1 + WTerminal) +# Serialization memory (or stream). +# The record elements in the serialized parse tree have various widths, but the +# width of the overall stream is the maximum of all of those. +# Field 1: Nonterminal in the parse tree. Has length WNonterminal +# Field 2: Number of subnodes. Has length WLongestRule +# Fields for the subnodes: A subnode has a leading indicator bit, if it's 0, it's +# a literal terminal, so the length is (1+WTerminal). +# If the indicator bit is 1, it's a backreference to a nonterminal, so length (1+WLongestParse) +# +# max(WNonterminal, WLongestRule, 1 + WTerminal, 1+ WLongestParse) # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # / \ # /----------------------\ /---------------------\ -- GitLab