[antlr-interest] how can i fix this

Joan Pujol joanpujol at gmail.com
Mon Jan 10 02:55:32 PST 2005


On Sun, 09 Jan 2005 16:11:19 +0000, clocKwize
<clockwize at blueyonder.co.uk> wrote:
> MyParser.g:11: warning:nondeterminism upon
> MyParser.g:11:     k==1:"public","private",VAR_TYPE
> MyParser.g:11:     between alt 1 and exit branch of block
> 
> script        :    class_dec (globalvar_dec)* (function_dec)*;
> 
> globalvar_dec    :    (TOK_private | TOK_public)? VAR_TYPE IDENT (ASSIGN
> (STR_LIT | INT_LIT))? SEMI;
> 
> function_dec    :    (TOK_private | TOK_public)? VAR_TYPE IDENT LPAREN

With a lookahead of 1 token the parser doesn't know if it have to
match the tokens in globalvar or in function_dec.

You have to factorize your gramar:

script        :    class_dec (TOK_private | TOK_public)? VAR_TYPE
IDENT (globalvar_dec)* (function_dec)*;

globalvar_dec    :   (ASSIGN (STR_LIT | INT_LIT))? SEMI;

function_dec    :   LPAREN (param_dec_list)? RPAREN SEMI;


Cheers,

-- 
Joan Jesús Pujol Espinar


More information about the antlr-interest mailing list