コード例 #1
0
        static void OnlyTokenizer(string file)
        {
            Console.WriteLine("Iniciando Tokens");
            JackTokenizer jk  = new JackTokenizer(file);
            string        xml = "<tokens>\n";

            while (jk.Advance())
            {
                JackTokenizer.JackTokenType tokenClass = jk.TokenType();
                xml += "<" + tokenClass.ToString() + ">";
                switch (tokenClass)
                {
                case JackTokenizer.JackTokenType.identifier:
                    xml += jk.Identifier();
                    break;

                case JackTokenizer.JackTokenType.intConst:
                    xml += jk.IntVal().ToString();
                    break;

                case JackTokenizer.JackTokenType.keyword:
                    xml += jk.KeyWord().ToString().ToLower();
                    break;

                case JackTokenizer.JackTokenType.stringConst:
                    xml += jk.StringVal();
                    break;

                case JackTokenizer.JackTokenType.symbol:
                    char sym = jk.Symbol();
                    if (sym == '<')
                    {
                        xml += "&lt;";
                    }
                    else if (sym == '>')
                    {
                        xml += "&gt;";
                    }
                    else if (sym == '&')
                    {
                        xml += "&amp;";
                    }
                    else
                    {
                        xml += jk.Symbol();
                    }
                    break;
                }
                xml += "</" + tokenClass.ToString() + ">\n";
            }
            xml += "</tokens>";
            File.WriteAllText(file.Substring(0, file.Length - 4) + "tokens.xml", xml);
            Console.WriteLine("Tokens FIM");
        }
コード例 #2
0
 public CompilationEngine(string filepath)
 {
     this.filepath           = filepath;
     xml                     = "";
     this.currentTokenIndex  = 0;
     this.kind2segmentMapper = new Dictionary <SymbolTable.Kind, VMWriter.Segment>();
     this.kind2segmentMapper.Add(SymbolTable.Kind.STATIC, VMWriter.Segment.STATIC);
     this.kind2segmentMapper.Add(SymbolTable.Kind.FIELD, VMWriter.Segment.THIS);
     this.kind2segmentMapper.Add(SymbolTable.Kind.VAR, VMWriter.Segment.LOCAL);
     this.kind2segmentMapper.Add(SymbolTable.Kind.ARG, VMWriter.Segment.ARG);
     this.ifLabelsCount    = 0;
     this.whileLabelsCount = 0;
     this.tokenizer        = new JackTokenizer(filepath);
     this.ExtractTokens();
 }