Re: target language grammars.

Dobes Vandermeer <dobes@dobesland.com>
7 Nov 2004 12:07:34 -0500

          From comp.compilers

Related articles
target language grammars. ralphpboland@yahoo.com (2004-11-06)
Re: target language grammars. cppljevans@cox-internet.com (Larry Evans) (2004-11-07)
Re: target language grammars. dobes@dobesland.com (Dobes Vandermeer) (2004-11-07)
Re: target language grammars. lujoplujop@gmail.com (Lujop) (2004-11-07)
Re: target language grammars. vbdis@aol.com (2004-11-07)
Re: target language grammars. cgweav@aol.com (2004-11-07)
Re: target language grammars. kenrose@tfb.com (Ken Rose) (2004-11-14)
Re: target language grammars. idbaxter@semdesigns.com (Ira Baxter) (2004-11-14)
target language grammars. a.t.hofkamp@tue.nl (A.T. Hofkamp) (2004-11-14)
[1 later articles]
| List of all articles for this month |
From: Dobes Vandermeer <dobes@dobesland.com>
Newsgroups: comp.compilers
Date: 7 Nov 2004 12:07:34 -0500
Organization: dobesland.com
References: 04-11-013
Keywords: parse, code
Posted-Date: 07 Nov 2004 12:07:34 EST

On 6 Nov 2004 15:15:09 -0500, Ralph Boland <ralphpboland@yahoo.com> wrote:


> When translating/compiling from one language to another we normally
> have a source language grammar but don't (to my knowledge) make much
> use of any grammar for the target language. (Grammar here may mean
> language syntax specification grammar, attribute grammar, or any other
> grammar that might be fed to a "parser" generator.)
>
> Does it make sence to make use of a grammar of the target language in
> any way? Can anyone point to applications where the target language
> grammar is made use of?


In XML applications, the target grammar (e.g. the DTD) is used to check
validity of the output before sending it onward. An XML DTD can also be
used to generate a hetergeneous AST parser, which can then be manipulated
and dumped (pretty-printers and editors).


In many compilers, they have a sort of 'grammar' that describes the target
machine language, although it also includes semantic and scheduling
information.


In Antlr, you can write a 'tree walker' grammar that walks an AST and
produces another AST or text. So, to translate between languages you
could write a tree walker that produced an AST valid for the target
language, and a pretty-printer (also a tree walker) for that AST that
produced text. Antlr tree walking grammars typically look very similar to
the language grammar itself, so this is an example application.


I think for the most part this approach is not employed because you
typically have to hand-code the transformation between the source and
target languages anyway - it is just as easy to emit the actual language
strings as it is the AST so why have an extra step? It would only be
useful if you were going to do further operations/optimization on the
output (like a compiler).


CU
Dobes



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.