Mercurial > projects > dang
view ast/Decl.d @ 44:495188f9078e new_gen
Big update - Moving towards a better, more seperated parser
The parser no loner creates the AST directly, but through
callbacks(actions). This means the parser can be run with a different set
of actions that do something else.
The parser is not back to full strength yet, the main thing missing is the
various statements and structs.
Also added a SmallArray that uses the stack only until a given size is
exceeded, after which the array is copied unto the heap.
author | Anders Halager <halager@gmail.com> |
---|---|
date | Wed, 23 Apr 2008 00:57:45 +0200 |
parents | e331e4e816e4 |
children | da551f90e03f |
line wrap: on
line source
module ast.Decl; import ast.Exp, ast.Stmt; import lexer.Token; import sema.SymbolTable; enum DeclType { VarDecl, FuncDecl, StructDecl, } class Decl { this(DeclType declType) { this.declType = declType; } DeclType declType; Scope env; } class VarDecl : Decl { this(Identifier type, Identifier identifier, Exp e = null) { super(DeclType.VarDecl); this.type = type; this.identifier = identifier; this.init = e; } Identifier type, identifier; Exp init; } class FuncDecl : Decl { this(Identifier type, Identifier identifier) { super(DeclType.FuncDecl); this.type = type; this.identifier = identifier; } void addParam(Identifier type, Identifier name) { funcArgs ~= new VarDecl(type, name, null); } void setBody(CompoundStatement stmts) { statements = stmts.statements; } Identifier type, identifier; VarDecl[] funcArgs; Stmt[] statements; } class StructDecl : Decl { this(Identifier identifier, VarDecl[] vars) { super(DeclType.StructDecl); this.identifier = identifier; this.vars = vars; } Identifier identifier; VarDecl[] vars; }