Example #1
0
        private void button_Parse_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(textBox_Expr.Text))
            {
                return;
            }

            AntlrInputStream       input  = new AntlrInputStream(textBox_Expr.Text);
            ParamExprGrammarLexer  lexer  = new ParamExprGrammarLexer(input);
            CommonTokenStream      tokens = new CommonTokenStream(lexer);
            ParamExprGrammarParser parser = new ParamExprGrammarParser(tokens);

            parser.RemoveErrorListeners();
            Logger.resetStream();

            parser.AddErrorListener(new ParamExprErrorListener());

            //IParseTree tree = parser.start_rule();
            IParseTree      tree   = parser.param_expr();
            ParseTreeWalker walker = new ParseTreeWalker();
            EvalListener    eval   = new EvalListener(parser);

            walker.Walk(eval, tree);

            // BIMRL_output.Text = tree.ToStringTree(parser);
            string toOutput = new string(Logger.getmStreamContent());

            textBox_Output.Text = tree.ToStringTree(parser) + '\n' + toOutput;
        }
Example #2
0
        object Process(ExpectedValueEnum expectedValueType)
        {
            object                 val    = null;
            AntlrInputStream       input  = new AntlrInputStream(paramExprContent);
            ParamExprGrammarLexer  lexer  = new ParamExprGrammarLexer(input);
            CommonTokenStream      tokens = new CommonTokenStream(lexer);
            ParamExprGrammarParser parser = new ParamExprGrammarParser(tokens);

            parser.RemoveErrorListeners();
            ParamExprLogger.resetStream();
            parser.AddErrorListener(new ParamExprErrorListener());
            IParseTree        tree   = parser.param_expr();
            ParseTreeWalker   walker = new ParseTreeWalker();
            ParamExprListener eval   = new ParamExprListener(tokens);

            eval.RevitElement       = _element;
            eval.RevitParameterName = _paramName;

            try
            {
                walker.Walk(eval, tree);
                if (eval.HasValue)
                {
                    val      = eval.Value;
                    UnitType = eval.UnitType;
                }
            }
            catch
            {
            }
            return(val);
        }