[antlr-interest] Beginner question: How do I access stuff from my parser?

Bunul si Iubitul Mos Craciun mos-craciun at adicomsoft.ro
Wed Dec 19 04:50:20 PST 2001


Hello Antlr folks and HAPPY NEW YEAR!!! (first of all...)

My name is Cosmin Prund, I'm from Romania and I'm trying hard to learn
Antlr.
It seemns to me that Antlr is a GRATE tool, much better then yacc and lex
(from an superficial point-of-view: antlr generates "classes" and it's
lexers scan from an stream, while lex/yacc generate a bunch of C-code, and
lex-lexers read from stdin or a file). My attempt to use lex+yacc resulted
in a bunch of scanners and an C-like preprocessor writen BY HAND!

So this is my question: "How do I access stuff that was matched in my Lexer
from my Parser?".

Also this question seems quite simple (I hope it is!) it is just a small
part of my problems. In fact, it could be easily be re-writen as: "What is
the interface betwen Lexers (token-streams?) and Parsers?".

I think this is the time to say I'm using Antlr with Visual C++.

This is what I've done so far:
1) I read most of the "antlr manual". That is, I read everithing up to
tree-parsers.
2) I searched the Web for documentations on ANTLR.
3) I read the examples.
4) I made a off-line copy of "www.antlr.org".
5) I made a off-line copy of
"http://wwwhome.cs.utwente.nl/~klaren/antlr/support-docs".
6) I wrote small-simple-lexers and followd the generated code to see if I
could guest what antlr is doing.
But I ran into the following dead-end:
I found out that MyLexer::NextToken() returns a reference to a token
generated by something called "tokenFactory". Also I noticed a call to some
function "setText" on that reference that was suposed to set the text into
that token. So far-so god you might say... but the default tokenFactory
generated TokenRef has a setText function that looks like this: "{}". That
is, it doesn't set a thing! When I reached this end-point I sad to myself:
Hey! I can change tokenFactory to return something that does remember text!
So I moved on to code generated for my parser, and this is where I got stock
again.

Maby I tryed to hard to learn Antlr and I overlooked something obvious
(again, I hope so!).

Thank-you for your answer!


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list