I'm trying to build a parser for a DSL I'm building using Irony in .NET and found a problem I can't find a way around. Since it handles BNF I think that any BNF solution will be of help.
I have the following input:
$10 yesterday at drug store
With the following grammar:
<expr> :== unit | expr + unit
<unit> :== money | date | location
<date> : == yesterday|today|tomorrow
<location> :== .* | <preposition> .*
<preposition> :== at
<money> :== ((\$)?\d*((\.*)\d*)*\,?\d{1,2})
It works like a charm with this input. I get exactly the result I wanted which is:
Money Amount: 10
Date: Yesterday
Location: Drug Store
However, if I change the order of the input as following
$10 at drug store yesterday
because of reduce steps it fails to give me the same output. The output becomes:
Money amount: 10
Location: Drug Store Yesterday
I was wondering if there is way to make sure that Location (which is a really broad regex match) is only evaluated when all the other tokens are captured and nothing else is left.
Any help is appreciated.
Thanks!
Edit: Updated title according to suggestion