[antlr-interest] A Grammar Issue..

Micheal J open.zone at virgin.net
Thu Jul 27 23:24:00 PDT 2006


Hi,
 
Basic comments: You need to use the "tokens" option to specify "open" and,
you also need to set the option "testLiterals" on your STRING lexer rule.
 
See the ANTLR docs.
 
 
Micheal

-----------------------
The best way to contact me is via the list/forum. My time is very limited. 

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Anup Shankar
Sent: 27 July 2006 11:34
To: antlr-interest at antlr.org
Subject: [antlr-interest] A Grammar Issue..


Hi,
 
Iam trying to come up with a simple grammar, which can parse commands the
given to it.
 
The below is the abstract grammar file::
----------------------------------------------------------------------------
------------------------------------------------

options {
language="Cpp";
}
class ftpParser extends Parser;
options {
genHashLines = true; // include line number information
k =5;
}
cmd: openCmd 
 

openCmd: open SPACE (hostname)+ EOL;

hostname: ( SPLCHAR | STRING);

open: "open";

 
 
class ftpLexer extends Lexer;
options {
k=2;
charVocabulary = '\3'..'\377';
caseSensitive=false;
}
EOL :
( "\r\n"
| '\n'
| '\r'
) 
;

STRING :( 'a'..'z' |'0'..'9' | ','..'/'
)
;
 
SPLCHAR: ('$'..'+' | '['..'_' );
 
----------------------------------------------------------------------------
------------------------------------------
 
The invocation code is 
--------------------------------

istringstream input_string;
istream *input=NULL;

 
input_string.str( "open server1.net");
input = &input_string;
ftpLexer lexer(*input);
ftpParser parser(lexer);
parser.cmd();
 
SwithStmt
--------------
void ftpParser::cmd() {
try { // for error handling

switch ( LA(1)) {
case LITERAL_open:
{
openCmd();
break;
}
 
}
Here iam facing problems, where the comparision of the literal in this case
"open" is not succeeding, in the Switch case stmt..
 
 
Could any of you help me out in this issue.
 
 
 
Thanks,
Anup



  _____  

Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great
<http://us.rd.yahoo.com/mail_us/taglines/postman7/*http://us.rd.yahoo.com/ev
t=39666/*http://messenger.yahoo.com> rates starting at 1¢/min.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060728/36fc6b79/attachment.html


More information about the antlr-interest mailing list