user1686620
user1686620

Reputation: 3101

AntLR multiple alternatives

I guess there is something rather fundamental that I'm not understanding. The following grammar seems to me to be quite simple. Starting from the rule 'parse' there doesn't appear to me to be much that could be ambiguous. But I get the errors listed below. If someone could maybe even just interpret the first error that would be helpful.

The intention is to parse simple names like 'Mr. John Smith III & Mrs. Jane Smith' or 'Smith, John'.

parse
    : name+ EOF
    ;

// match Mr. John or Smith,
name
    : NAMESEP? SALUTATION* NAME (firstlast | lastcommafirst)
    ;

// match Smith III
firstlast
    : INITIAL? NAME+ COMMA? title*
    ;

// match John
lastcommafirst
    : COMMA SALUTATION* NAME+ COMMA? title*
    ;

// match III
title
    : TITLE COMMA?
    ;

warning(200): /NameParser.g:23:16: Decision can match input such as "NAME" using multiple alternatives: 1, 2

As a result, alternative(s) 2 were disabled for that input warning(200): /NameParser.g:27:25: Decision can match input such as "NAME COMMA SALUTATION NAME COMMA SALUTATION NAME {EOF, NAME, SALUTATION..TITLE, NAMESEP}" using multiple alternatives: 1, 2

As a result, alternative(s) 2 were disabled for that input warning(200): /NameParser.g:27:25: Decision can match input such as "NAME {EOF, NAME, SALUTATION..TITLE, NAMESEP}" using multiple alternatives: 1, 2

As a result, alternative(s) 2 were disabled for that input warning(200): /NameParser.g:27:25: Decision can match input such as "NAME COMMA SALUTATION NAME {NAME, INITIAL}" using multiple alternatives: 1, 2

Upvotes: 0

Views: 292

Answers (1)

Terence Parr
Terence Parr

Reputation: 5962

firstlast can match just NAME or can match NAME NAME but it could match NAME and let NAME match back in parse, if it falls out of firstlast and then name. That's a hint to get you started :)

Upvotes: 1

Related Questions