[antlr-interest] Fwd: antlr-interest Digest, Vol 20, Issue 46

Anup Shankar anup_sankaran at yahoo.com
Thu Jul 27 21:25:39 PDT 2006


Hi,
   
  Can someone help me out here, it's bit urgent...
   
  Thanks,
  Anup


Message: 6
Date: Thu, 27 Jul 2006 03:33:56 -0700 (PDT)
From: Anup Shankar 
Subject: [antlr-interest] A Grammar Issue..
To: antlr-interest at antlr.org
Message-ID: <20060727103356.51354.qmail at web53506.mail.yahoo.com>
Content-Type: text/plain; charset="iso-8859-1"

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




 		
---------------------------------
Yahoo! Music Unlimited - Access over 1 million songs.Try it free. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060727/dbf1b76e/attachment-0001.html


More information about the antlr-interest mailing list