Abstract Syntax


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.
window on the wide world:

Computer Science Education Week

free op. sys.
free office suite,
ver 3.4+

~ free photoshop
web browser
like it says!

::= "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 Monday, 25-Sep-2017 06:59:22 AEST.