public SymbolTable Analyze(AstNode ast) { code = ast; result = new SymbolTable(); result.PushScope(); code.VisitChildren(this); return result; }
public HassiumModule Compile(AstNode ast, SymbolTable table) { this.table = table; module = new HassiumModule(); method = new HassiumMethod(); var globalParent = new HassiumClass(); foreach (AstNode child in ast.Children) { if (child is FuncNode) { compileFunc(child as FuncNode); method.Parent = new HassiumClass(); if (module.Attributes.ContainsKey(method.Name)) { if (module.Attributes[method.Name] is HassiumMultiFunc) ((HassiumMultiFunc)module.Attributes[method.Name]).Methods.Add(method); else if (module.Attributes[method.Name] is HassiumMethod) module.Attributes[method.Name] = new HassiumMultiFunc(new List<HassiumMethod>() { method, (HassiumMethod)module.Attributes[method.Name] }); } else module.Attributes.Add(method.Name, method); } else if (child is ClassNode) { var clazz = compileClass(child as ClassNode); clazz.Parent = globalParent; module.Attributes.Add(clazz.Name, clazz); } else if (child is ExpressionStatementNode) { if (child.Children[0] is BinaryOperationNode) { var binop = child.Children[0] as BinaryOperationNode; if (binop.BinaryOperation == BinaryOperation.Assignment) { string variable = ((IdentifierNode)binop.Left).Identifier; table.AddGlobalSymbol(variable); var temp = method; method = new HassiumMethod(); method.Name = variable; method.SourceRepresentation = string.Format("set_{0}", variable); binop.Right.Visit(this); method.Emit(child.SourceLocation, InstructionType.Return); module.InitialVariables.Add(table.GetGlobalSymbol(variable), method); method = temp; } } } else if (child is TraitNode || child is PropertyNode || child is UseNode || child is EnumNode) child.Visit(this); } preformInherits(module); return module; }