Esempio n. 1
0
        IExpression parse_expression(String code)
        {
            ECleverParser   parser = new ECleverParser(code);
            ITokenStream    stream = (ITokenStream)parser.InputStream;
            EIndentingLexer lexer  = (EIndentingLexer)stream.TokenSource;

            lexer.AddLF = false;
            IParseTree      tree    = parser.expression();
            EPromptoBuilder builder = new EPromptoBuilder(parser);
            ParseTreeWalker walker  = new ParseTreeWalker();

            walker.Walk(builder, tree);
            return(builder.GetNodeValue <IExpression>(tree));
        }
Esempio n. 2
0
        public void testSystemOutPrint()
        {
            ECleverParser   parser = new ECleverParser("System.Console.Write(value);");
            ITokenStream    stream = (ITokenStream)parser.InputStream;
            EIndentingLexer lexer  = (EIndentingLexer)stream.TokenSource;

            lexer.AddLF = false;
            IParseTree      tree    = parser.csharp_statement();
            EPromptoBuilder builder = new EPromptoBuilder(parser);
            ParseTreeWalker walker  = new ParseTreeWalker();

            walker.Walk(builder, tree);
            CSharpStatement statement = builder.GetNodeValue <CSharpStatement>(tree);
            Context         context   = Context.newGlobalsContext();
            IParameter      arg       = new CategoryParameter(TextType.Instance, "value");

            arg.register(context);
            context.setValue("value", new prompto.value.TextValue("test")); // StringLiteral trims enclosing quotes
            Object result = statement.interpret(context, null);

            Assert.IsNull(result);
            Assert.AreEqual("test", Out.read());
        }