Beispiel #1
0
        private void parseBtn_Click(object sender, EventArgs e)
        {
#if DEBUG && HELLO
            String       input  = editor.Text;
            ICharStream  stream = CharStreams.fromstring(input);
            ITokenSource lexer  = new HelloLexer(stream);
            ITokenStream tokens = new CommonTokenStream(lexer);
            HelloParser  parser = new HelloParser(tokens);

            HelloCustomListener helloListener = new HelloCustomListener();
            parser.r().EnterRule(helloListener);
#elif DEBUG && ADVANCED
            String             input  = editor.Text;
            ICharStream        stream = CharStreams.fromstring(input);
            ITokenSource       lexer  = new VisualBasic6Lexer(stream);
            ITokenStream       tokens = new CommonTokenStream(lexer);
            VisualBasic6Parser parser = new VisualBasic6Parser(tokens);
            IParseTree         tree   = parser.startRule();

            ParseTreeWalker            walker   = new ParseTreeWalker();
            VisualBasic6CustomListener listener = new VisualBasic6CustomListener();
            walker.Walk(listener, tree);

            //parser.startRule().EnterRule(listener);
#endif
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            String       input  = @"package P
context A
inv:
let fact(n: var) = if n = 1 then n else n * fact(n - 1) endif;
let n = 5;
fact(n+1) = 720
inv:
let a = 6;
let b = 6;
a = b
endpackage";
            ICharStream  stream = CharStreams.fromstring(input);
            ITokenSource lexer  = new HelloLexer(stream);
            ITokenStream tokens = new CommonTokenStream(lexer);
            HelloParser  parser = new HelloParser(tokens);

            parser.BuildParseTree = true;
            IParseTree   tree    = parser.oclFile();
            HelloPrinter printer = new HelloPrinter();

            //ParseTreeWalker.Default.Walk(printer, tree);
            tree.Accept(printer);
            Console.ReadLine();
        }
Beispiel #3
0
    void Start()
    {
        AntlrInputStream  antlerStream = new AntlrInputStream("hello " + Name);
        HelloLexer        lexer        = new HelloLexer(antlerStream);
        CommonTokenStream tokenStream  = new CommonTokenStream(lexer);
        HelloParser       parser       = new HelloParser(tokenStream);

        parser.r();
    }
Beispiel #4
0
        static void Main(string[] args)
        {
            var inputStream       = new AntlrInputStream(Console.In);
            var lexer             = new HelloLexer(inputStream);
            var commonTokenStream = new CommonTokenStream(lexer);
            var parser            = new HelloParser(commonTokenStream);
            var graphContext      = parser.r();

            Console.WriteLine(graphContext.ToStringTree());
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var input    = new AntlrInputStream("hello world");
            var lexer    = new HelloLexer(input);
            var tokens   = new CommonTokenStream(lexer);
            var parser   = new HelloParser(tokens);
            var listener = new ErrorListener <IToken>();

            parser.AddErrorListener(listener);
            var tree = parser.r();

            System.Console.WriteLine(listener.had_error ? "Didn't work" : "Worked");
        }