I am making a parser for a simple grammar to learn about parsing technique.
For example if I have the following grammar:
exp := if-exp ...
if-exp := if bool-exp then exp else exp
....
In languages which support algebraic data types, I can do:
type exp =
| If-exp of bool-exp * exp * exp
| ....
A Java example I found creates a class for every sub-expression:
Class If_exp
@bool_exp
@then_exp
@else_exp
...
end
"How to manually construct an AST?" uses a hash to construct an AST.
Which way is better? What is the Ruby way?