Mercurial > projects > dang
diff ast/Exp.d @ 1:2168f4cb73f1
First push
author | johnsen@johnsen-desktop |
---|---|
date | Fri, 18 Apr 2008 02:01:38 +0200 |
parents | |
children | 2ce5209f1954 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ast/Exp.d Fri Apr 18 02:01:38 2008 +0200 @@ -0,0 +1,135 @@ +module ast.Exp; + +import tango.text.Util : jhash; + +import lexer.Token; + +import sema.SymbolTable; + +enum ExpType +{ + Binary, + Negate, + IntegerLit, + 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(Identifier identifier, Exp exp) + { + super(ExpType.AssignExp); + this.identifier = identifier; + this.exp = exp; + } + + Identifier identifier; + Exp exp; +} + +class BinaryExp : Exp +{ + public enum Operator : char + { + Mul = '*', Div = '/', + Add = '+', Sub = '-' + } + + this(Operator op, Exp left, Exp right) + { + super(ExpType.Binary); + this.op = op; + this.left = left; + this.right = right; + } + + 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 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; +} + +