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");
        }
Exemple #2
0
        public static string toXml(this JackTokenizer.ClassifiedJackToken token, SymbolTable symbolTable = null)
        {
            string xml = "";

            JackTokenizer.JackTokenType tokenClass = token.TokenType();
            xml += $"<{tokenClass.ToString()}{token.getIdentifierCategory(symbolTable)}>";
            switch (tokenClass)
            {
            case JackTokenizer.JackTokenType.identifier:
            case JackTokenizer.JackTokenType.intConst:
            case JackTokenizer.JackTokenType.keyword:
                xml += token.value;
                break;

            case JackTokenizer.JackTokenType.stringConst:
                xml += token.ParseStringVal();
                break;

            case JackTokenizer.JackTokenType.symbol:
                char sym = token.ParseChar();
                if (sym == '<')
                {
                    xml += "&lt;";
                }
                else if (sym == '>')
                {
                    xml += "&gt;";
                }
                else if (sym == '&')
                {
                    xml += "&amp;";
                }
                else
                {
                    xml += token.value;
                }
                break;
            }
            xml += "</" + tokenClass.ToString() + ">\n";
            return(xml);
        }