I have defined my language's BNF and have no idea how to design an AST from it.
For example, from the first several lines of my BNF:
<program> ::= <import declarations>? <class declaration>?
<import declarations> ::= <import declaration> | <import declarations> <import declaration>
<class declaration> ::= class <identifier> <class body>
<import declaration> ::= import <type name> ';'
How can I express this from my AST? Should I design it like this way?
typedef vector<ImportDeclaration*> ImportDeclarationList;
class Program {
ImportDeclarationList importDeclarations;
ClassDeclaration classDeclaration;
};
class ImportDeclaration {
TypeName typeName;
};
class ClassDeclaration {
Identifier identifer;
ClassBody classbody;
};
Do I need to add some inheritance among thess classes?
Are there some books about how to design AST from BNF?