diff --git a/unoptimized_lr/simple_parse_tree.py b/unoptimized_lr/simple_parse_tree.py index 700af89587c67a63c17bf235af5a373edc42cde4..2e03063bc86f642d3759df7ab4402405160497a4 100644 --- a/unoptimized_lr/simple_parse_tree.py +++ b/unoptimized_lr/simple_parse_tree.py @@ -1,20 +1,18 @@ # An example parse tree looks like: -# nonterminal A -# * | * -# * | * -# * terminal K * -# * * -# nonterminal B nonterminal D -# / * * -# / * * -# / nonterminal C * -# / \ * -# / \ terminal L -# terminal I \ -# terminal J - -MAKE VERTICAL SPACING GOOD and PROPER +# nonterminal A +# ** | ** +# ** | ** +# ** | ** +# * | * +# nonterminal B terminal K nonterminal D +# / * * +# / * * +# terminal I nonterminal C terminal L +# \ +# \ +# terminal J + # As it is parsed, we serialize it on the fly. The serialization scheme represents the tree # as a sequence of records, each of which corresponds to a reduction. In other words, each @@ -76,6 +74,31 @@ MAKE VERTICAL SPACING GOOD and PROPER # be stitched in this way. +# The parameters for instantiating the tree serializer are as follows: +# +# parameters dependent only on the language: +# * number of nonterminals +# * number of terminals +# * list of language rules +# +# parameters dependent on the use case: +# * bitwidth of parse tree memory +# * length of parse tree memory +# * maximum possible number of emitted records per parse +# +# If the latter is not provided, a pessimistic estimate will be calculated: +# (number of bits in memory) / (number of bits to represent the smallest possible record) + +# In general, the bitwidth of the record fields do not correspond to the bitwidth of memory available +# to the FPGA. In order to address this, we split up the records across multiple memory addresses as +# is necessary. This means that the records of the serialized parse tree won't necessarily be in any +# sort of alignment. If it is desired, we can add functionality to do alignment. But I do not think it +# is a big deal since this data structure anyway needs to be decoded from the start -- there's no random +# access possible. + + + + class TreeSerializer(Elaboratable):