[antlr-interest] nondeterminism

Roshan Achar broshan at gmail.com
Sun Nov 20 22:06:09 PST 2005


Hi,

I am trying to write grammer for a bookmarks file. Iam getting the
following error -

 warning:nondeterminism upon
Bookmarks.g:44:     k==1:A_START,H3_START
Bookmarks.g:44:     between alt 1 and exit branch of block

I am not sure of the cause since with k=2 there should be no
nondeterminism between A_START and H3_START.

The grammer is as follows -

options
{
    language = "CSharp";
}

class BookmarksParser extends Parser;

file
    : (item)+
    ;

item
    : (shortcut | subfolder)
    ;

subfolder
    : (item_title) (item)*
    ;

shortcut
    : (A_START) (TEXT)+  (TAG_END)
    ;

item_title
    : (H3_START) (TEXT)+ (TAG_END)
    ;

class BookmarksLexer extends Lexer;
options
{
    k=2;
    //caseSensitive=false;
}

TAG_START
    : '<' ~( 'A' | 'H' | 'a' | 'h' | '/' | '<' | '>' ) (TEXT)* 
(ATTRIBUTES)* '>'
    {
        $setType(Token.SKIP);
    }
    ;

TAG_END
    : "</" (~( '>' ))+ '>'
    {
        $setType(Token.SKIP);
    }
    ;

H3_START
    : "<H3"  (attr:ATTRIBUTES {Console.WriteLine("Got attribute -
"+attr.getText());})* '>'
    ;


// Atleast one attribute href="" is needed
A_START
    : "<A"  (attr:ATTRIBUTES {Console.WriteLine("Got attribute -
"+attr.getText());})+  '>'
    ;

ATTRIBUTES
    : (TEXT)+ '=' '"' (~('"' | '<' | '>' ))* '"'
    ;

TEXT
    : ~('"' | '<' | '>' | '\r' | '\t' | '\n' | ' ')
    ;

SKIP_WS
    : ( '\r' '\n'
      | '\n'
      | '  '
      | '\t' )
    {
        $setType(Token.SKIP);
    }
    ;

The file format is specified at -
http://msdn.microsoft.com/workshop/browser/external/overview/bookmark_file_format.asp

Any help is appreciated.

Thanks ,
Roshan
broshan at gmail.com


More information about the antlr-interest mailing list