[antlr-interest] The behavior.....
Meena Vinod
spprtmail09 at yahoo.com
Thu Jan 29 00:21:24 PST 2009
Hi Dave,
I am back with my problem:
heres my Test.g
----------------------------------------------------------------------------------------------------------------
grammar Test;
options
{
output = AST;
ASTLabelType = CommonTree;
}
tokens
{
T_COMMAND;
T_ACTION;
T_OPT;
}
validate_cmd: command EOF -> ^(T_COMMAND command);
command: action1 | action2;
action1: action1_name (action1_opt)* ;
action2: action2_name (action2_opt)* ;
action1_name: ACTION1 -> ^(T_ACTION ACTION1) ;
action2_name: ACTION2 -> ^(T_ACTION ACTION2) ;
action1_opt: tsep action1_tree -> ^(T_OPT action1_tree);
action1_tree: (common_options | wait_option)+;
action2_opt: tsep action2_tree -> ^(T_OPT action2_tree);
action2_tree: (common_options)+;
common_options: version_option | help_option ;
wait_option: WAIT;
version_option: VERSION_OPTION;
help_option: HELP_OPTION;
ACTION1 : 'copy';
ACTION2 : 'cut';
VERSION_OPTION: '-v'('ersion')?;
HELP_OPTION: '-h'('elp')?;
WAIT : '-w'('ait')?;
SEMI: ';' ;
DIGIT : ('0'..'9')*;
tsep : WSP;
WSP : ('\u0009' | ' ')+;
-----------------------------------------------------------------------------------------------------------------------
An input of type "copy -v -h" will work fine.
An input like "junk" comes back with the indeterminate state. There is no exception thrown. Infact, the EOF around for every command.
Am I missing something here?
Thanks in advance,
Ambica
________________________________
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/20090129/5af813b4/attachment.html
More information about the antlr-interest
mailing list