I'm attempting to write a grammar to parse numbers in English sentences, and I can successfully parse up to 999. Once I add in the logic to support the thousands place, I get a reduce
parsing conflict, and I'm having a hard time understanding what's causing it.
I've attached a portion of the parser.out file generated by lemon, and I'm hoping someone can shed some light on the issue. I've also included a large portion of the grammar, where everything below the line works on it's own, but once I add in the logic for thousands above the line I begin running into issues.
My thought is that I'm running into an issue similar to the "dangling else" but with my separator. However, that normally manifests as a shift-reduce
error, whereas it looks like I have just a reduce
error. Lemon documentation is a bit sparse, and I'm not exactly sure how to read the parser.out file's contents. For example, in the line HYPHEN reduce 15 ** Parsing conflict **
, what does the 15
even refer to?
Any help would be greatly appreciated!
Portion of my grammar file:
final_number(A) ::= one_to_999999(B).
final_number(A) ::= ZERO.
one_to_999999(A) ::= thousands(B) separator one_to_999(C).
one_to_999999(A) ::= thousands(B).
one_to_999999(A) ::= one_to_999(B).
thousands(A) ::= one_to_999(B) separator THOUSAND.
thousands(A) ::= THOUSAND.
/* -------------------------------------- */
one_to_999(A) ::= hundreds(B) separator one_to_99(C).
one_to_999(A) ::= hundreds(B).
one_to_999(A) ::= one_to_99(B).
one_to_99(A) ::= tens(B) separator one_to_9(C).
one_to_99(A) ::= tens(B).
one_to_99(A) ::= ten_to_19(B).
one_to_99(A) ::= one_to_9(B).
hundreds(A) ::= one_to_9(B) separator HUNDRED.
hundreds(A) ::= HUNDRED.
separator ::= WHITESPACE.
separator ::= HYPHEN.
separator ::= .
Portion of parser.out with an error:
State 5:
one_to_99 ::= tens * separator one_to_9
(15) one_to_99 ::= tens *
separator ::= * WHITESPACE
separator ::= * HYPHEN
(65) separator ::= *
$ reduce 15 one_to_99 ::= tens
THOUSAND reduce 15 one_to_99 ::= tens
WHITESPACE shift-reduce 63 separator ::= WHITESPACE
WHITESPACE reduce 15 ** Parsing conflict **
HYPHEN shift-reduce 64 separator ::= HYPHEN
HYPHEN reduce 15 ** Parsing conflict **
separator shift 4
{default} reduce 65 separator ::=