views:

60

answers:

1

I'm using ANTRL and this is my some grammar which give error to me.

statement
:     (name)(
    | BECOMES expression
    | LPAREN (expression (COMMA expression)*)? RPAREN
    | SHIFTLEFT name LPAREN (expression ( COMMA expression )*)? RPAREN
    )
    | OUTPUT LPAREN expression ( COMMA expression)* RPAREN
    | IF expression  THEN statement (ELSE statement)?
    | FOR name BECOMES expression TO expression DO statement
    | REPEAT statement UNTIL expression
    | WHILE expression DO statement
    | body
    | 
;

This is error " Decision can match input such as "ELSE" using multiple alternatives ".

How can I fix it ?

A: 

Try using the backtrack option.

options {
    backtrack = true;
}

Description

The new feature (a big one) is the backtrack=true option for grammar, rule, and block that lets you type in any old crap and ANTLR will backtrack if it can't figure out what you meant. No errors are reported by antlr during analysis. It implicitly adds a syn pred in front of every production, using them only if static grammar LL* analysis fails. Syn pred code is not generated if the pred is not used in a decision. This is essentially a rapid prototyping mode. It is what I have used on the java.g. Oh, it doesn't memoize partial parses (i.e. rule parsing results) during backtracking automatically now. You must also say memoize=true. Can make a HUGE difference to turn on.

ChaosPandion
How about backtrack do ?
Atom Skaa ska Hic
@Atom - Can I assume you mean *"What does backtrack do?"* ?
ChaosPandion
@Chaos - Yeah, sry for my bad English.
Atom Skaa ska Hic
@Atom - No need to apologize, I only speak one language. :)
ChaosPandion