ネストされたリストを解析するための LALR 文法を作成したいのですが、常にシフト/リデュースの競合が発生します。
type1 アイテムと list2 のリストである list1 があります。
<list1> ::= <type1> | <type1> <list1> ;
<type1> ::= A | B | <list2> ;
そして、type2 項目のリストである list2 があります。
<list2> ::= <type2> | <type2> <list2> ;
<type2> ::= X | Y ;
この文法はシフト/リデュース エラーを生成します。どうすれば回避できますか?
これは具体的なBiglooソースです。
(lalr-grammar
(comment
new-line
text-chunk
white-space)
(input
(() '())
((node-list) node-list))
(node-list
((node) (cons node '()))
((node node-list) (cons node node-list)))
(node
((comment) (cons 'comment comment))
((new-line) (cons 'new-line new-line))
((text) (cons 'text text))
((white-space) (cons 'white-space white-space)))
(text
((text-chunk) (cons 'text text-chunk))
((text-chunk text) (cons 'text (string-append text-chunk text)))))
ターミナルは、コメント、改行、テキストチャンク、および空白です。非ターミナルは、input、node-list、node、および text です。
Bigloo は、テキストからテキストチャンクへの reduce ルールについて不平を言っています。
*** WARNING:bigloo:lalr-grammar
** Shift/Reduce conflict:
- shift to state 2
- reduce rule (text --> text-chunk)
on token `text-chunk'
しかし、これは Bigloo の問題ではないと思います。文法の問題のようです。