Mercurial > projects > dang
view ast/Exp.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 | 69464d465284 |
children | b6c1dc30ca4b |
line wrap: on
line source
module ast.Exp; import tango.text.Util : jhash; import lexer.Token; import sema.SymbolTable; enum ExpType { Binary, Negate, IntegerLit, MemberLookup, ArrayLookup, Identifier, AssignExp, CallExp, } class Exp { this(ExpType expType) { this.expType = expType; } ExpType expType; Scope env; } class CallExp : Exp { this(Exp exp, Exp[] args) { super(ExpType.CallExp); this.exp = exp; this.args = args; } Exp exp; Exp[] args; } class AssignExp : Exp { this(Exp identifier, Exp exp) { super(ExpType.AssignExp); this.identifier = identifier; this.exp = exp; } Exp identifier; Exp exp; } class BinaryExp : Exp { public enum Operator { Eq, Ne, Lt, Le, Gt, Ge, Add, Sub, Mul, Div, Mod, } this(Operator op, Exp left, Exp right) { super(ExpType.Binary); this.op = op; this.left = left; this.right = right; } char[] resultType() { if (op >= Operator.Eq && op <= Operator.Ge) return "bool"; return null; } Operator op; Exp left, right; } class NegateExp : Exp { this(Exp exp) { super(ExpType.Negate); this.exp = exp; } public Exp exp; } class IntegerLit : Exp { this(Token t) { super(ExpType.IntegerLit); this.token = t; } Token token; } class MemberLookup : Exp { this(Exp target, Identifier child) { super(ExpType.MemberLookup); this.target = target; this.child = child; } Identifier child; Exp target; } class ArrayLookup : Exp { this(Exp target, IntegerLit pos) { super(ExpType.ArrayLookup); this.target = target; this.pos = pos; } Exp target; IntegerLit pos; } class Identifier : Exp { this(Token t) { super(ExpType.Identifier); this.token = t; name = t.get; } char[] get() { return name; } hash_t toHash() { return jhash(name); } int opCmp(Object o) { if (auto id = cast(Identifier)o) return typeid(char[]).compare(&name, &id.name); return 0; } int opEquals(Object o) { if (auto id = cast(Identifier)o) return typeid(char[]).equals(&name, &id.name); return 0; } Token token; char[] name; }