I am looking for a way to implement an S-expression reader (which will be used later with both the Scheme interpreter and the compiler), but I asked myself how (if at all) I should write an AST for it.
I read SICP, and it is quite simple from inside the Scheme, but I am looking for an OO-style interpreter and compiler in C ++.
Please keep in mind that I am only doing this for educational purposes, so I am not looking for the easiest or fastest way to do this, but rather the right and reusable way to do this.
I saw in some implementations of the Scheme that people parse s-expressions and easily output cons-cells, something like this:
struct Sexpr
{
};
struct Cons : public Sexpr
{
Sexpr* left;
Sexpr* right;
};
struct IntAtom : Sexpr
{
int value;
};
And one subclass of Sexpr for each type of Schema Atom, or something on these lines.
, ... , ?
, ( ) S-, , ? , cons-?