I'm using bison to parse a lang from a spec I don't have control over it. In its definition there is a recursive rule and since the language uses indentation this resulted in reduce/reduce errors. So to get rid of the reduce/reduce I added a semi colon. I have a layout tracker which auto inserts semi colons and braces already. I was thinking of extending the rules for inserting semi colons to support the one I added that's not in the spec but I can't think of a way of knowing when we're at the end of the recursive rule.
Is there a reliable way of knowing when I'm at the end of the recursive rule or any suggestions on a different approach? Or as messy as it'd be is there some way to get two way comms between the parser and lexer?
Currently using a pull parser. I thought using a push parser would enable me to keep better track of where I am in the lexer but when I try the define directive to generate a push parser the option isn't recognised. I'm using bison 3.0.4 with a custom lexer, generating a pure parser with the C++ api.
EDIT:
exp : infixexp TYPE_SEP type {}
| infixexp TYPE_SEP context RIGHT_ARROW type {}
| infixexp {}
infixexp : lexp qop infixexp {}
| MINUS infixexp {}
| lexp {}
lexp : BACKSLASH apat_list FUNC_TYPE_CONS exp {}
| KW_LET decls KW_IN exp {}
| KW_IF exp SEMI_COLON KW_THEN exp SEMI_COLON KW_ELSE exp {} //conditional
| KW_CASE exp KW_OF L_BRACE alts R_BRACE {}
| KW_DO L_BRACE stmts R_BRACE {}
| fexp SEMI_COLON {}
fexp : aexp {}
| fexp aexp {}
literal : INTEGER {}
| FLOAT {}
| CHAR {}
| STRING {}
aexp : qvar {}
| gcon {}
| literal
| L_PAREN exp R_PAREN {}
| L_PAREN exp_list R_PAREN {}
| L_BRACKET exp R_BRACKET {}
| L_BRACKET exp_list R_BRACKET {}
| L_BRACKET exp DOTDOT R_BRACKET {}
| L_BRACKET exp DOTDOT exp R_BRACKET {}
| L_BRACKET exp COMMA exp DOTDOT exp R_BRACKET {}
| L_BRACKET exp PIPE qual_list R_BRACKET {}
| L_PAREN infixexp qop R_PAREN {}
| L_PAREN qop infixexp R_PAREN {}
| qcon L_BRACE fbind_list R_BRACE {}
| aexp L_BRACE fbind_list R_BRACE {}
apat : qvar {}
| qvar AT_SYM apat {}
| gcon {}
| qcon L_BRACE fpat_list R_BRACE {}
| literal {}
| WILDCARD {}
| L_PAREN pat R_PAREN {}
| L_PAREN pat COMMA pat_list R_PAREN {}
| L_BRACKET pat_list R_BRACKET {}
| TILDE apat {}
Added a section from the grammar. It's basically a modified version of the Haskell 2010 spec. The reduce/reduce conflicts were resolved by adding the semi colon after fexp
in the definition of lexp
.
I am simulating indent/dedents and inserting open and curly braces. And I was basically thinking of the lexer hack but couldn't figure out how to do it with Bison. And there are multiple recursive rules but only the one was causing reduce/reduce errors.
EDIT 2: