Concrete Syntax
The current Spoofax/Eclipse IDE is oriented around individual language projects. Therefore in order to work with ASTs of the SPL abstract syntax that we just saw, it’s easiest to define a concrete syntax for SPL, via the following SDF3 definition:
context-free syntax
Prop.True = <1>
Prop.False = <0>
Prop.Atom = String
Prop.Not = <!<Prop>>
Prop.And = <<Prop> & <Prop>> {left}
Prop.Or = <<Prop> | <Prop>> {left}
Prop.Impl = [[Prop] -> [Prop]] {right}
Prop.Eq = <<Prop> = <Prop>> {non-assoc}
Prop = <(<Prop>)> {bracket}
String = ID
context-free priorities
Prop.Not
> Prop.And
> Prop.Or
> Prop.Impl
> Prop.Eq
Thus, the first two example AST expressions
A: And(Impl(True(), False()), False())
and
B: And(Atom("p"), False())
from Section 4.1 can be generated by the following much more compact SPL expressions:
A: (1 -> 0) & 0
and
B: p & 0
. (If you are following along in the repository,
you can visit the file syntax/examples/sec4.1_A.spl
(or …_B.spl
) and from the
Spoofax menu select “Syntax > Show parsed AST” to see the AST generation
in action.)