Commit 5ae576db authored by thiarichey's avatar thiarichey
Browse files

More grammar doc.

parent 36ee3a00
......@@ -231,28 +231,21 @@ we now have many more runtime errors and unbound variable and function binding e
### The generating procedure
Let's begin with expressions. Expressions can be a lot of things, and we won't review them
all here--although you can see LANGUAGE in HW3 for that--but consider integer literals,
boolean literals, variable reference expressions, the `nil` literal, and if expressions.
One of these is not like the others -- whereas the first four expression types are composed of
literals or symbols, an if expression takes other expressions as arguments! So, we need our generator
to generate more expressions, some of which will themselves be recursive expressions and some of
which will be literals or symbols. You can probably envision a problem here -- stack
overflow! We choose a reasonably small maximum depth for expressions to address this, after which
point we guarantee that a nonrecursive expression will be generated. We can think of the first four
expression types as our "base cases".
all here (although you can see LANGUAGE in HW3 for that!). Instead, let's consider the subset of
expressions consisting of integer literals, boolean literals, variable reference expressions, the `nil` literal, and if expressions. One of these is not like the others -- whereas the first four expression types are composed of literals or symbols, an if expression takes other expressions as arguments! In other words, it is a recursive expression.
So, we need our generator to generate more expressions, some of which will be recursive expressions and some of which will be literals or symbols. You may be able to envision a problem here -- stack overflow! We choose a reasonably small maximum depth for expressions to address this, after which point we guarantee that a nonrecursive expression will be generated. We can think of the first four expression types as our base cases.
Bindings are similar to expressions, but simpler in that their arguments are nodes, symbols, or
expressions, as opposed to other (non-expression) bindings.
So, we generate bindings, which generate expressions, which eventually terminate! This results in
only valid Trefoil V2 ASTs. Last time, in Trefoil V1, this was sufficient to generate exclusively
valid programs, but that is not the case here. Consider what happens in the following simple Trefoil
V2 program:
valid programs, but that is not the case in our smarter Trefoil V2 programs. Consider what happens in the following example:
```
(define x (+ 1 y))
```
When we try to look up `a` in our dynamic environment, it's not there because we have not defined it in
our program! This represents an unbound variable error. What are some other types of errors you can think
of coming up in Trefoil V2 programs generated using grammarFuzz?
\ No newline at end of file
When we try to look up `a` in our dynamic environment, it's not there, because we have not defined it! This represents an unbound variable error. What are some other types of errors you can think
of coming up in Trefoil V2 programs generated using the Grammar fuzzer?
\ No newline at end of file
Supports Markdown
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