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.

  1. Parse t over G, using Sdf2TablePGEN and sglrSGLR, to obtain a parse tree t.asfix.
  2. Run the parse tree trough asfix2sdfGT, to obtain your subgrammar, in normalized Sdf form.
  3. Run the normalized subgrammar through sdfdenormalizeGT, to transfer the subgrammar into ordinary Sdf.
  4. 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

Sdf2TablePGEN, sglrSGLR, asfix2sdfGT, sdfdenormalizeGT, HowToPrettyPrintAGrammar.

Revision: r1.2 - 11 Nov 2001 - 23:24 - EelcoVisser
Tools > HowToGenerateMinimalGrammarsFromParseTrees
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback