Re: target language grammars.

Dobes Vandermeer <>
7 Nov 2004 12:07:34 -0500

          From comp.compilers

Related articles
target language grammars. (2004-11-06)
Re: target language grammars. (Larry Evans) (2004-11-07)
Re: target language grammars. (Dobes Vandermeer) (2004-11-07)
Re: target language grammars. (Lujop) (2004-11-07)
Re: target language grammars. (2004-11-07)
Re: target language grammars. (2004-11-07)
Re: target language grammars. (Ken Rose) (2004-11-14)
Re: target language grammars. (Ira Baxter) (2004-11-14)
target language grammars. (A.T. Hofkamp) (2004-11-14)
[1 later articles]
| List of all articles for this month |

From: Dobes Vandermeer <>
Newsgroups: comp.compilers
Date: 7 Nov 2004 12:07:34 -0500
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 <> 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

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).


Post a followup to this message

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