|source-to-source translators, what language for unparsers cfc@shell01.TheWorld.com (Chris F Clark) (2009-05-05)|
|Re: source-to-source translators, what language for unparsers firstname.lastname@example.org (Stephen Horne) (2009-05-06)|
|Re: source-to-source translators, what language for unparsers email@example.com (2009-05-06)|
|Re: source-to-source translators, what language for unparsers firstname.lastname@example.org (Ira Baxter) (2009-05-06)|
|Re: source-to-source translators, what language for unparsers Ruslan@Shevchenko.Kiev.UA (rssh) (2009-05-08)|
|Re: source-to-source translators, what language for unparsers email@example.com (Ray Dillinger) (2009-05-09)|
|RE: source-to-source translators, what language for unparsers firstname.lastname@example.org (Quinn Tyler Jackson) (2009-06-01)|
|[1 later articles]|
|From:||Chris F Clark <cfc@shell01.TheWorld.com>|
|Date:||Tue, 05 May 2009 12:28:29 -0400|
|Organization:||The World Public Access UNIX, Brookline, MA|
|Posted-Date:||05 May 2009 14:16:53 EDT|
I was recently working on the output side of Yacc++ and realized I
want something better than what I have. In paricular, I want
something where I can quickly take an example output (for some example
input), add some fairly minimal markup and have it turn that into the
appropriate sequence of output commands that recreate that output
given that input. Repeat as needed with different sets until the
program covers all the cases.
I can kind of do this today. I have output routines that can compare
their output to an existing file (do a diff so to speak) and report
where the output doesn't match the file.
For the first pass, I simply take the sample output and wrap each line
with a call to the output routine that will output a line. I can turn
this whole set into the body of a function that I can call at the
appropriate time. When I know certain parts are substitutions from
the input, I can edit the code to make the routine write out the
relevant input rather than a fixed string.
Then, I run the resulting program in "diff-mode" and let it point out
to me where the output doesn't match the example output. I then patch
the code until I'm happy with it.
And while the method works, it isn't that good for allowing someone
else to write the "templates" because the templates end up being
hard-coded into the program. Thus, I really need a templating
language to describe the output.
Not wanting to invent yet-another-incompatible-language, I thought I
would ask what people use already in the situation.
Let me preface this with some of the solutions I'm aware of.
1) At the bottom of the food chain, things like yacc allow one to
write C code, and thus you can code up anything you want, but you
have very little automation supporting you. I've already got this.
Unless you give out source code, it is hard to customize.
2) For the output of bison, one can customize it in m4, which gives
one a powerful macro language, but it's not clear to me whether
that is the right kind of power. I presume all the "sustitutions"
that one wants are setup as pre-definee m4 macros and variables.
3) For its output, LALR had its own built-in template language with
special syntaxes for the substitutions. This is good if one has
one project one wants to customize.
3) Meta-S supports Lua, which as I understand it, is a functional
language defined for scripting. I don't know whether the
substitutions get built-in, or whether one has functions tied to the
parse tree that allow uses to save the relevant text. Attribute
grammar systems generally remind me of this approach.
4) What seemed to me to be the best system I am aware of was SDTB,
later renamed something like Ivy or Harmony. It had a template
syntax that mostly read like text, in which one could put
annotations that extracted information captured by the parser
(i.e. from the AST). One could also walk the AST where one desired
for sections where that was appropriate.
5) I believe there are also systems that unparse the AST, with
annotations for what to generate embedded in the AST. That
probably would work well with a visitor paradigm where one could
define an order to walk the AST.
There are probably other formalizations. For example, I recall that
sorcerer was a tree-walker associated with ANTLR designed for
source-to-source transformations. Perhaps, there is something in Eli,
Cocktail, the Russian Armory tools, or Coco that I would be advised to
What I'm looking for is opinions about what worked and what didn't.
Chris Clark Internet: email@example.com
Compiler Resources, Inc. or: firstname.lastname@example.org
23 Bailey Rd Web Site: http://world.std.com/~compres
Berlin, MA 01503 voice: (508) 435-5016
USA fax: (978) 838-0263 (24 hours)
Return to the
Search the comp.compilers archives again.