parsing - C to Forth parser using Bison -
i'm trying make c-to-forth bison parser.
i've developed of typical functions, have troubles expressions.
i thinking using ast during parse, more difficult code temporary buffer.
could recommend 1 strategy on other?
thanks
if use strategy of producing translation each production, becomes impossible reorder clauses. that's severe limitation.
there number of hacks in common use around problem. 1 provide mechanism whereby output production can saved in temporary buffer, can output later on.
however, cleaner solution create ast (abstract syntax tree) during parse, , walk ast when parse complete. since entire parse tree available @ point, can walk child nodes of production in arbitrary order.
the ast strategy more cleanly separates parse code generation, making easier implement other processing steps (pretty printing, linting, etc., etc.). avoids problem of producing partial output in case error detected , parse prematurely terminated.
Comments
Post a Comment