Ejemplo n.º 1
0
        public static Value Parse(OsmiumEngine engine, string input)
        {
            var lines = input.Split('\n');
            var lex   = new WolframLanguageLexer(new AntlrInputStream(input));
            var parse = new WolframLanguageParser(new CommonTokenStream(lex, Lexer.DefaultTokenChannel));

            lex.Parser = parse;
            var listen = new ExprBuildListener(engine, parse);

            var errors = new List <string>();

            parse.AddErrorListener(new ErrorListener <IToken>((recognizer, token, line, pos, msg, e) => { errors.Add($"Unexpected {token} at {line}:{pos}: {msg}"); }));
            var expr = parse.expr();

            ParseTreeWalker.Default.Walk(listen, expr);

            if (errors.Any())
            {
                foreach (var i in errors)
                {
                    Console.WriteLine("err: {0}", i);
                }
                return(null);
            }

            return(listen.GetValue());
        }
Ejemplo n.º 2
0
 public ExprBuildListener(OsmiumEngine engine, WolframLanguageParser parse)
 {
     _engine = engine;
     _parse  = parse;
 }