Dinushan
Dinushan

Reputation: 2077

javacc grammar conflicting tokens

I'm parsing command line arguments for a program
ex: --param1 value1 --param2 value2

When the value is a String that is preceded by a dash (-) ex: --param1 -value1 it's a lexical error.
How should I modify the grammar to accept inputs like above?

<STRING : (["A"-"Z" , "a"-"z" , "0"-"9"])+ >
<PARAMNAME : "--"(<STRING>) >

Upvotes: 0

Views: 109

Answers (1)

Theodore Norvell
Theodore Norvell

Reputation: 16221

You could to this

<VALUE: ("-")? <NAME> >
<PARAMNAME : "--" <NAME> >
<#NAME : (["A"-"Z" , "a"-"z" , "0"-"9"])+ >

Upvotes: 1

Related Questions