Re: Concrete to Abstract syntax

Brent Benson <>
23 Jun 1996 23:25:34 -0400

          From comp.compilers

Related articles
Concrete to Abstract syntax (Ron Kanagy) (1996-06-21)
Re: Concrete to Abstract syntax (Brent Benson) (1996-06-23)
Re: Concrete to Abstract syntax (1996-06-24)
Re: Concrete to Abstract syntax kadhim@VNET.IBM.COM ((Basim Kadhim)) (1996-06-27)
| List of all articles for this month |

From: Brent Benson <>
Newsgroups: comp.compilers
Date: 23 Jun 1996 23:25:34 -0400
Organization: Compilers Central
References: 96-06-079
Keywords: syntax, analysis

# From: Ron Kanagy <>
# Does anyone know of any good references, preferable online, that
# describes and/or gives pointers on how to convert a grammar
# representing the concrete syntax of a programming language to a
# grammar representing the abstract syntax of a language. I have a
# couple of books on language design and compiler writing, but they
# only touch upon the subject and don't describe the process in
# detail. Any help on this would be greatly appreciated.

It is very simple to come up with an abstract syntax representation of
a particular concrete syntax. There should be an abstract syntax tree
node type for every distinguishable language construct (e.g., literal
constant, identifier, if statement, assignment statement, etc.).
There should be a field in each of the node types for each distinct
piece of the language construct (e.g., the literal constant node type
would have one field that holds the literal constant itself, the
identifier node type would have one field that holds the name of the
identifier, the if statement node type might have three fields: one
for the "test part"; one for the "then part"; and one for the "else
part", and the assignment statement might have two fields: one for the
identifier whose value is being changed; and the the other for the
expression that computes the new value). For the simplest cases, you
have a field for each non-terminal in your concrete syntax grammar.

I would encourage you to make this stage of your compiler as simple
and as transparent as possible. Later passes of the compiler should
perform simplification and transformation of the tree. In my
experience, combining these two tasks leads to complex and hard to
maintain front ends.

Post a followup to this message

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