[antlr-interest] Newby - How to use Parser/Lexer in Code?

Jim Idle jimi at temporal-wave.com
Sat May 26 13:26:59 PDT 2007


Best this is to buy the book, but for pure examples, check out the
examples tar from the download page - that should get you going, but I
can't remember if the C# stuff is there yet.

 

Jim

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Harris, Tobin
Sent: Saturday, May 26, 2007 12:21 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Newby - How to use Parser/Lexer in Code?

 

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/3f850576/attachment-0001.html 


More information about the antlr-interest mailing list