[antlr-interest] Newby - How to use Parser/Lexer in Code?
Harris, Tobin
tobin at tobinharris.com
Sat May 26 12:20:40 PDT 2007
Hi Folks,
Firstly, I'd like to say I'm enjoying exploring ANTLR - the workbench is
*very* cool and it's great to be able to get some results so quickly!
I've developed a grammar for a custom type of URL that I need in my
program, and I've picked ANTLR because RegEx was string to feel like a
hammer! The problem is I'm now stuck on what to do next J
So far I've done this...
1) Downloaded the workbench, authored a simple grammar and got test
cases passing in the Interpreter.
2) Generated the C# Lexer/Parser files for my grammar and included
them in my Visual Studio project.
3) Got some basic test code working that can show the contents of
the Tree.
Here's the test c# code
DbUriGrammarParser parser =
GetParser("custom://user:pass@someserver:1000/folder?query=blah");
DbUriGrammarParser.dburigrammar_return ret = parser.dburigrammar();
ITreeAdaptor ad = parser.TreeAdaptor;
ITree tree = ((ITree)ret.Tree);
Console.WriteLine(tree.ToStringTree());
This shows
custom :// user : pass @ someserver : 1000 / folder ? query = blah
At this point I'm guessing I need to start working with the tree to make
my program extract the tokens, work out what they are, and implement the
desired functionality? However, I don't really know what I'm doing! Does
anyone know of any up-to-date simple examples of this that show a
grammar actually being consumed and used in a program? Can anyone
recommend the best next steps to take?
Many thanks
Tobin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070526/8f397339/attachment.html
More information about the antlr-interest
mailing list