Re: syntax directed translation



aegis wrote:
> Are syntax directed translation and syntax directed definition
> synonymous?
>
> [I've never heard of syntax directed definition. -John]


I'm a little surprised this term does not seem to be better known in
this circle. In the classic compilers text (Aho, Sethi, & Ullman's
"Dragon" Book"), both terms are given definitions right in the
introductory chapters. On page 33 they write: "A syntax-directed
definition uses a context-free grammar to specify the syntactic
structure of the input. With each grammar symbol, it associates a set
of attributes, and with each production, a set of semantic rules for
computing values of the attributes associated with the symbols
appearing in that production. The grammar and the set of semantic
rules constitute the syntax-directed definition."

(I would note that this notational form treats the production rules
and the semantic rules as separate items that are paired with each
other. )

Then, at the bottom of page 37, they state: "A translation scheme is a
context-free grammar in which program fragments called semantic
actions are embedded within the right sides of productions. A
translation scheme is like a syntax-directed definition, except that
the order of the evaluation of the semantic rules is explicitly shown.
The position at which an action is to be executed is shown by
enclosing it between braces and writing it within the right side of a
production, as in

rest --> + term { print('+') } rest

A translation scheme generates an output for each sentence x generated
by the underlying grammar be executing the actions in the order they
appear during a depth-first traversal of a parse tree for x."

(In this form, the "actions" are "built-in" to the grammar productions
where each action is like a pseudo-symbol that is now a part of the
RHS of a production. It also corresponds pretty much exactly to the
way "actions" are embedded in a bison or yacc grammar.)

There is some context missing here (they are talking about a specific
example), but the essence of the difference as they define it is that
a "syntax-directed definition" is more of a mathematical concept, in
which the "rules" are mathematical statements of the relationships
between the attributes (without regard to how they might actually be
computed), while the "actions" called for in a "translation scheme"
are procedural in nature, and they carry out a translation by being
"executed" in some defined order related to the traversal of a parse
tree (which happens to correspond to the order in which the conceptual
parse tree would be traversed during a top-down or bottom-up parse).

I don't know if this helps the original inquirer or not, but I'll let
it stand on its own as a direct quotation from the book.
--
Allan G. Jost, Ph.D.
Professor and Program Director
Faculty of Computer Science
Dalhousie University
Halifax, NS, Canada
[Hmmn, just goes to show how long it's been since I actually read through
the dragon book. -John]

.



Relevant Pages

  • Re: Aspects of programming languages in common
    ... A lot of language suites consist of front ends for C, ... They undergo a syntax evaluation before being ... > My understanding of the proposal is to perform the translation to ... There would then be a consistent base upon which to build the parse tree, ...
    (comp.programming)
  • Re: [ Attn: Randy ] Ad-hoc Parsing?
    ... > Anyway, the matter to be resolved is that suggesting this style of syntax, ... which production you want to use (the empty production or ... Well, when doing a predictive parser, you need to eliminate ... Processing macro parameter lists was a big hack. ...
    (alt.lang.asm)
  • Re: Work around ambiguities in LL(1) assembler parser
    ... I'm stuck with ambiguities with my syntax. ... # syntactic analysis is a simple LLrecursive descent parser. ... If you cannot distinguish which production goes with '(' ... thingie in the parse tree, and then relabel the parse tree ...
    (comp.compilers)
  • Re: C# very optimisation
    ... is to consider what you can't do with a particular syntax: ... The most basic form is ... Since the compiler was very stupid with no optimizations, ... But a different translation required a different syntax, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Emacs in ANSI CL
    ... A lot of translation is just syntax. ... The bigger problem, I believe, is translating the large body of ... > conversion effort of this kind already as to whether any of the ...
    (comp.lang.lisp)