Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        public CCompiler(TokenList <Token> tokenList)
        {
            _tokenList       = tokenList;
            _compileCommands = new TokenList <object[]>();
            _symbolTable     = new SymbolTable();

            // Label stacks
            _endIfLabels      = new LabelStack("ENDIF_");
            _elseLabels       = new LabelStack("ELSE_");
            _beginWhileLabels = new LabelStack("BEGINWHILE_");
            _endWhileLabels   = new LabelStack("ENDWHILE_");
        }