Overview
Project Synx has the aim of writing
an integrated compiler construction kit. Currently, the toolbox
contains a scanner & parser generator, and tools for abstract
syntax tree representation. From an integrated grammar, the tool
generates a regular scanner and a context-free parser: either SLL(k),
LR(1), or LALR(1), or a nondeterministic parser. Next, I plan to
provide generators for PAG attribute grammar evaluators on the
abstract syntax tree. Synx has been implemented in the functional logic
programming language Mercury.
An α-version of Synx is available for download.
For a brief motivating description of what scanners and parser do, take a
look at the HTML Parser-Example.
Example
For a very simple example of an expression grammar, take a look at the
following Synx grammar description file.
E --> E "+" T.
E --> T.
T --> T "*" F.
T --> F.
F --> identifier.
F --> "{" E "}".
identifier --> "[a-z]([a-z])*".
<SKIP> :--> " ".
This grammar declares three nonterminals E (short for expression), T (short for
term) and F (short for factor). Automatically it declares some terminals, first
for each explicit string like "+", and second Synx will detect that the
nonterminal identifier can be reduced to a synonym for a terminal token type.
The regular expression of the string defining the terminal identifier matches
any non-empty sequence of small letters a to z.
The special <SKIP> production is additional syntax for declaring what
characters the generated scanner should simply skip and ignore.
After Synx generates a scanner
and a parser from the above integrated grammar description file, expressions
like the following can be parsed.
- a + b * c
- a + {b + c} * d
- a + b * {c + dag}
- a*{b +c}*d+ff*eff
- {a*{b+c}*{{d+xyz}+z}}
For example, Synx can produce a (simplified) abstract syntax tree
for the example 2 that looks like this (excuse the preliminary ascii arts version)
a + { b + c } * d
| | | | | | | | |
| | \ \|/ / | F
| | \ E / | |
| | \|/ | |
| | F | |
| | \ | |
| | \ | |
| | \ | |
| | \ | |
| | \|/
| | T
| | _/
| | _/
| | _/
| | _/
| | _/
\|/
E
Download
If you want to give the Synx compiler construction kit a try,
|