Pregunta

Entonces, estoy tratando de analizar algún código C # simple para aprender a usar la ironía.Estoy usando la gramática C # incluida con las muestras de ironía y usando el código de carga del conjunto de muestra desde allí también.Parece que hay muy poco si alguna documentación sobre la ironía.Aquí está la fuente completa que estoy tratando de analizar:

using System;

namespace N
{
    class Test
    {
       public int A(int x)
       {
           return x+1;
       }
    }
    class Test2
    {
        public string hello = "world";
        private int _T = 0;
        private Test _actor = new Test();
        public void B()
        {
            Console.WriteLine(hello+": "+_actor.A(_T++));
        }
    }
}

y el código de análisis:

 string src = File.ReadAllText("testcs.cs");
 LanguageData language = new LanguageData(g);
 Parser parser = new Parser(language);
 ParseTree parseTree = parser.Parse(src);
 ParseTreeNode root = parseTree.Root;
 Console.WriteLine((root==null?"Parse tree unsuccessful!":"Parse tree created!"));

... donde G es la C # gramática de la ironía.¿Alguien ha experimentado estos problemas al analizar la C # con la gramática de la ironía antes?Lo siento, no puedo proporcionar más información.No hay excepciones

¿Fue útil?

Solución

When I tried your code, the parsing indeed was unsuccessful. And the error (in parseTree.ParserMessages) was on the end of the first line with the error message Invalid character: ''., where the character between the quotes is \r.

Hmm, it seems \r is not considered whitespace, so we need to modify the grammar. In the grammar, there is a method SkipWhitespace(), that contains a list of whitespace characters in a switch. If you just add case '\r': there, the parsing should succeed.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top