tags:

views:

156

answers:

1

I have a (badly specified) requirement that I recognize certain keywords, but there is also provision for 'any string' ...

For instance, in the input "let's have a " I have to handle == "beer", == "curry" and == anything else at all (in theory, the keywords beer & curry have priority over all other strings).

When I try to define this, of course, I get

Decision can match input such as "'curry" using multiple alternatives: 2, 3
As a result, alternative(s) 3 were disabled for that input

I imagine this is a st00pid n00b FAQ, but don't see an obvious answer. Any help gratefully received ...

+1  A: 

You need to apply some of the grammar disambiguation techniques that you are either learning (if this is homework). Generally speaking you add an additional rule that disambiguates the grammar.

Another antlr specific thing you can do is add an action to the rule that will handle the differences.

I might be able to help more if you post the antlr code in question.

BioBuckyBall
no, not homework, I gave that up a few decades ago ;-) just some hobby programming.I have tried to reduce this to a very simple example, so it is not the full spec of the ATD command. ATD is the modem command to dial.It can be ATD<number to dial>or "ATD>" plus some parameters to dial from 'phone book (e.g, SIM card of handset phone book. The official definition *is* ambiguous, but common sense shows what is wanted.
Mawg
Params can be1) an offset. E.g, dial entry 5 in my 'phonebook (the choice of SIM or Handset phonebook has previously been made)2) indicate which phonebook and the offset. Eg. dial offset 5 in my SIM Card phonebook3) give the text associated with an entry, search for that and dial it. E.g, dial "Bill Gates".1 3 can be ambiguous if you allow phone book entries to start with numbers, e.g "1st national bank".I am unsure how to handle that.2 and 3 can be ambiguous, but common sense says name of phone book takes priority over name in phone book.here's the simplest I can reduce it to...
Mawg
<pre>grammar at_command_set;options { language=C; } fragment PB_mem_SM : ('sm' | 'Sm' | 'sM' | 'SM');fragment PB_mem_HP : ('hp' | 'Hp' | 'hP' | 'HP');fragment PB_mem_type : (PB_mem_SM | PB_mem_HP);fragment Decimal_digit : '0'..'9' ;fragment Decimal_number : Decimal_digit+; fragment Alpha_numeric_char : (Decimal_digit | 'a'..'z'|'A'..'Z') ;fragment Alpha_numeric_string : 'a'..'z'|'A'..'Z' Alpha_numeric_char+; fragment V250_dialing_digits : (Decimal_digit | '*' | 'a'..'c' | 'A' .. 'C')+;AT_cmd_dial_from_phone_book: ('AT' | 'at' | 'aT' | 'At') ( 'd'|'D')'>';
Mawg
AT_cmd_dial : ('AT' | 'at' | 'aT' | 'At') ( 'd'|'D') ; NEWLINE : '\r'?'\n'; AT_cmd : ATD_dial_from_phone_book | ATD_dial ; ATD_dial : AT_cmd_dial V250_dialing_digits ; ATD_dial_from_phone_book : AT_cmd_dial_from_phone_book Decimal_number | AT_cmd_dial_from_phone_book PB_mem_type Decimal_number | AT_cmd_dial_from_phone_book Alpha_numeric_string ;
Mawg
sorry that the formating is lousy ... the rrors given are:[13:09:18] warning(200): at_command_set.g:34:27: Decision can match input such as "'A''T'{'D', 'd'}'>''S''m''0'..'9'" using multiple alternatives: 2, 3As a result, alternative(s) 3 were disabled for that input[13:09:18] error(208): at_command_set.g:34:1: The following token definitions can never be matched because prior tokens match the same input: ATD_dial,ATD_dial_from_phone_book
Mawg
Hard to read it all like this...can you edit the question and post the rules the error is referring to (2 and 3) wrapped with the code format
BioBuckyBall
Ok, I sorted it out - it was all my own dumb fault for not following the "grammar rules begin lower case, lexer rules upper" rule.Sorry to have troubled you.
Mawg