The conflict comes mainly from these two rules:
sentence: sentence '[' Text ']' | sentence '[' sentenceList ']'
The reason is that after looking at sentence and [ and looking at the next Text token, the parser does not know whether to shift Text by matching the first rule, or consider that Text as the beginning of a sentenceList is suitable for matching the second rule.
Now, if you have a parser generator that uses a 2-token, this will not be a problem, but the LALR (1) bison (1 is one token).
There are a few things you could try:
make an additional look in the lexer to distinguish the text from the subsequent one] from Text-not-follow-by-], because two different tokens then rewrite the rules for using both of these tokens.
Use the bison% glr-parser function to use the GLR parser. This will analyze the proposal in both directions, and then throw out the one that does not match
reorganize the grammar so that it does not need a two-point image.
One refactoring that works in your case is to rewrite sentence rules to make them correct recursive rather than left recursive:
sentence: | Text sentence | '[' ']' sentence | '[' Text ']' sentence | '[' sentenceList ']' sentence ;
This avoids sentence (or any other rule starting with sentence , such as sentenceList ), with zero reduction of the sentence: /*empty*/ rule sentence: /*empty*/ . Therefore, the analyzer can freely shift a Text in a problematic case, postponing the reduction until it sees the next token. However, this has the consequences of using memory, as it leads to a parser that significantly shifts the entire entry on the parser stack and then reduces it by one sentence at a time.
Another refactor you could do would be to combine the [Text] and [] constructs in [sentenceList] :
sentence: | sentence Text | sentence '[' sentenceList ']' ; sentenceList: sentence | sentenceList ',' sentence
So now the sentenceList is one or more sentences separated by commas (instead of two or more), and in action for the sentence '[' sentenceList ']' rule, you must check the sentenceList to see if it was two or more sentences and act properly.