Abstract Syntax

home1 home2
 Bib
 Algorithms
 Bioinfo
 FP
 Logic
 MML
 Prog.Lang
and the
 Book

Prog-Langs
 glossary
 Grammar
  Arith-Exp
  Abstract-syn
  Top-Down
  Bottom-Up
The (optional) abstract syntax of a language may be specified by a simpler grammar than that for the concrete syntax. For example,
 
<Exp> ::= <Exp> + <Exp>  |  <Exp> - <Exp>  |  <Exp> * <Exp>  |  <Exp> / <Exp>  |  <id>  |  - <Exp>

A grammar for the abstract syntax of simple arithmetic expressions

Compared to the concrete syntax, the abstract syntax is ambiguous and is unsuitable for direct use in building a parser. However it is simpler than the concrete syntax and is very suitable to build the data-structure for the parse-tree returned by a parser, e.g.,
 
datatype Exp = binexp of Exp * Bopr * Exp | unexp of Uopr * Exp | varid of Ide | ...   in [exp.sml].
 
For example, given the input x+y*z either of the following trees is possible according to the abstract syntax above
 
Parse trees for x + y * z
+

*

x y z

correct bindings

 
*

+

x y z

incorrect bindings

 
but only the left tree is correct according to the conventional concrete syntax.
However the right tree would be the correct one given the input (x+y)*z. Note that there are no parentheses in the abstract syntax above nor in the parse trees. Parentheses are only needed to direct the parser to a certain parse and are not required in a parse tree which shows the binding of operators to operands by its very structure.
Coding Ockham's Razor, L. Allison, Springer

A Practical Introduction to Denotational Semantics, L. Allison, CUP

Linux
 Ubuntu
free op. sys.
OpenOffice
free office suite
The GIMP
~ free photoshop
Firefox
web browser

key
::= "can be replaced by"
->
| "or by"
=> derivation
lm left most
rm right most

© L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated),
Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University,
was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.)
Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Friday, 29-Mar-2024 16:44:59 AEDT.