Commit ffdc15f3 authored by matthew-eads's avatar matthew-eads
Browse files


parent 4b00dde6
File deleted
Readme for Grammar Generator Prototype
To use the grammar generator, you must first specify the AST for your language
in an ast file (the example `Imp.ast` is provided). The syntax for these is
fairly simple and is explained below. You can then simply run the Grammar Generator
binary with the ast file as input (`./IMP < Imp.ast`). This will print out text
representing a valid input for the Happy parser generator.
To compile, simply run happy, then ghc over the parser generator generator:
`happy AST.y; ghc AST.hs` (stack coming soon).
`AST.y` is the grammar for the mini-language for parsing the user's AST declaration.
It reads all the grammar directives, and assembles them into a grammar that represents
a simpler, more universal AST. It should accept everything that is in the user's language,
but could potentially accept things that are not.
`Lexer.x` is the lexer for all generated grammars (the lexer for the AST language is built into `AST.y`).
It has the simple job of parsing some predefined tokens, and feeding them to the parser. It will almost
certainly need adjustments to handle things such as comments, and will likely need to be produced at some
point by the grammar generator, but for now it is sufficient.
`Imp.ast` is the example AST declaration. It is mostly a Haskell data declaration of a
modified impcore language. Lines corresponding to hard syntax are followed by the token `-->`
which is then followed by grammar directives. The possible directives are as follows:
| Operation Type | AST Syntax | Expexted impcore syntax |
| Set | `--> set` | `(set x e)` |
| If | `--> if` | `(if c e1 e2)` |
| While | `--> while` | `(while c b)` |
| Begin | `--> begin` | `(begin (e1 e2 e3))`|
| Var | `--> var` | `x`
| User Defined Function | `--> userdef` | `(foo e)` |
| Integer Literal | `--> int` | `1` |
| Binary Operation | `--> binop '+'` | `(+ 1 2)` |
| Built-in Function | `--> builtin PLUS '+'` | `(+ 1 2)` |
| Custom Syntax | Not yet supported | `(arr[i])` |
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment