/// <summary> /// 遍历Ast树,生成四元式列表 /// </summary> /// <param name="ast">Ast树</param> /// <param name="varTable">变量表</param> /// <returns></returns> public static List<FourExp> Translate(Ast ast, VarTable varTable) { List<FourExp> fourExpList = new List<FourExp>(); LabelStack labelStack = new LabelStack(); foreach (Statement s in ast.Statements) { s.Translate(varTable, labelStack, fourExpList); } return fourExpList; }
public Compiler(string sourcepath, string outputpath) { this.sourcepath = sourcepath; this.outputpath = outputpath; sourceList = new List<string>(); codelist = new List<Instruction>(); addresstable = new Hashtable(); labeltable = new Hashtable(); tokenList = new List<Token>(); ast = new Ast(); }
public static bool DoParse(List<Token> tokenlist, Ast _ast, out CompilerErrorInfo error) { ast = _ast; error = null; i = 0; tokenList = tokenlist; while (i < tokenList.Count) { GenStatement(ast.Statements); } return true; }