Task
Given a grammar and a parse tree obtained by parsing a term over this grammar, construct a subgrammar that still parses the same term.
Description
Given a grammar
G and a term
t over that grammar, a subgrammar that still parses
t can be obtained in the following steps.
- Parse t over G, using Sdf.Sdf2TablePGEN and sglrSGLR, to obtain a parse tree t.asfix.
- Run the parse tree trough asfix2sdfGT, to obtain your subgrammar, in normalized Sdf form.
- Run the normalized subgrammar through sdfdenormalizeGT, to transfer the subgrammar into ordinary Sdf.
- Pretty-print the subgrammar.
Examples
Assume that L.def is an Sdf grammar for language L, and t is a term over L.
# sdf2table -i L.def -o L.tbl
# sglr -p L.tbl -i t -o t.asfix
# asfix2sdf -i t.asfix | sdf-de-normalize -o L.sub.def.af
# sdf2text -a -i L.sub.def.af -o L.sub.def
See Also
Sdf.Sdf2TablePGEN, sglrSGLR, asfix2sdfGT, sdfdenormalizeGT,
HowToPrettyPrintAGrammar.