[antlr-interest] Re: Rules for STRING, CHAR, DIGIT

gita roy gitadut at yahoo.co.uk
Thu Apr 3 04:24:16 PST 2003


Hi, 

I am new to Antlr and using C++ to parse some file having Identifiers as digits, Strings (starting with alphabets), char (starting with digits)

Add an IDENTIFIER rule and ANTLR can then check the text against the literals table.

In my case I want the one IDENTIFIER rule, lets say rule for DIGIT: 

. 

 

DIGIT : (‘0’..’9’)+

;

 

And in another IDENTIFIER like STRING I define the rule:

 

STRING : ((‘A’..’Z’) (“%”)? (‘0’..’9’))+ 

;

 

My purpose will be to parse some token “Circuit12” as STRING and at the same time some token may checked as DIGIT.  In third case I need to verify some token as CHAR whose first position may or may not be digits. 

 

So lexer class is as follows: 

 

 class MyLexer extends Lexer;

options {

k=10;

filter=true;

} 

 

DIGIT

            : (('0'..'9')+

            ;

 

STRING : ((‘A’..’Z’) (“%”)? (‘0’..’9’))+ 

;

 

CHAR

            : ((DIGIT)? STRING)+

            ;

 

Add all IDENTIFIER rules and ANTLR can then check the text against the literals table, but for the case of char antlr is giving error. 

 

   The rule methods like mDIGIT are missing in MyLexer.cpp. 

 

 

   How can I check the identifier Circuit12, 12, 12Circuit, using the abovedefined rules. 

 

Please help. 

 

Thanks in advance. 

 

Gita  




---------------------------------
Yahoo! Mail - For a better Internet experience
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030403/1e8ed79c/attachment.html


More information about the antlr-interest mailing list