[antlr-interest] The behavior.....

Meena Vinod spprtmail09 at yahoo.com
Tue Jan 27 04:08:29 PST 2009


Thanks a ton Dave. That surely helped solve the problem.
I have a new problem now. My application's .g is as follows:

    CMD_CD : 'cd';
    CMD_SHOW: 'show';
    CMD_RESET: 'reset';
    CMD_SET: 'set';
    CMD_OPTION: (' -all' | ' -help' | ' -version' | ' -display')*;
    TSEP: ' ' { SKIP(); };

The parser is defined as:
cmd_validate: (cmd)(CMD_OPTION) EOF;

cmd: CMD_CD | CMD_SHOW | CMD_RESET | CMD_SET;

A valid input to my application is "cd -help -version -display". I can achieve this with the " " (space) prefixed for each of the CMD_OPTION value.
However, if I enter "cd-help", then my application hangs on ANTLRWorks and even my C code hangs.

I would want to ensure that there is a space between the "cmd" and the "cmd_option" (if there is a cmd_option value).

So, my application takes values as follows:
1. cd -help -version -display
2. cd -version
3. cd
4. show -help -version -display....... et al

What should I do so that it throws an exception when I enter "cd-help" or "show-version"?

Could you please help me on this too?

Regards,
Swift



________________________________
From: David Peckham <dave.peckham at me.com>
To: Meena Vinod <spprtmail09 at yahoo.com>
Cc: antlr-interest at antlr.org
Sent: Tuesday, January 27, 2009 11:04:44 AM
Subject: Re: [antlr-interest] The behavior.....


Try:


cmd_validate
:cmd CMD_OPTION EOF
;

ANTLR will report errors if you have extra input.

Dave


On Jan 26, 2009, at 8:03 PM, Meena Vinod wrote:

Hello,
This pet project of mine requires that I can validate a command. The command is of the form <command_name><command options>

My lexer consists of all the command names and options:

Ex: 
    
    CMD_CD : 'cd';
    CMD_SHOW: 'show';
    CMD_RESET: 'reset';
    CMD_SET: 'set';
    CMD_OPTION: '-all' | '-help';
    TSEP: ' ' { SKIP(); };

The parser is defined as:
cmd_validate: (cmd)(CMD_OPTION);

cmd: CMD_CD | CMD_SHOW | CMD_RESET | CMD_SET;

For all valid inputs, the cmd_validate behaves properly.

On the ANTLRWorks, when I give a junk input say 'zee zee', the ANTLRWorks does not generate any proper output and does not evn throw an exception.
Also, the C code generated hangs when given this input.

Can someone help me out on this?

Many thanks,
Swift. 



List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090127/12c306b2/attachment.html 


More information about the antlr-interest mailing list