Skip to content

How to solve such ambiguity ? #1812

Answered by msujew
4silvertooth asked this question in Q&A
Discussion options

You must be logged in to vote

I believe there's an alternative to this solution that is a bit easier to read, and that doesn't require two CONSUME(MultiplicationOperator) calls. Putting your requirement into other words; the parser has to read a * token if the token afterwards isn't a (, but if it is (, we know that we don't have to parse another *:

const nextParenthesis = tokenMatcher($.LA(1), LParen);
$.OR([
  {
    ALT: () => $.CONSUME(MultiplicationOperator)
  },
  {
    GATE: () => nextParenthesis,
    ALT: EMPTY_ALT()
  }
]);

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by 4silvertooth
Comment options

You must be logged in to vote
1 reply
@msujew
Comment options

Comment options

You must be logged in to vote
3 replies
@4silvertooth
Comment options

@bd82
Comment options

@4silvertooth
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants