我在語法中遇到了一些註釋塊問題。語法很好,但第3步DFA掃描器正在抱怨我正在進行的操作。GOLD解析器註釋語法
我試圖解析看起來像這樣的語言:
{聲明} {}聲明等
在每個語句可以是幾個不同類型的評論:
{% This is a comment.
It can contain multiple lines
and continues until the statement end}
{statement REM This is a comment.
It can contain multiple lines
and continues until the statement end}
這是一個顯示問題簡化的語法我運行到:
"Start Symbol" = <Program>
{String Chars} = {Printable} + {HT} - ["\]
StringLiteral = '"' ({String Chars} | '\' {Printable})* '"'
Comment Start = '{%'
Comment End = '}'
Comment Block @= { Ending = Closed } ! Eat the } and produce an empty statement
!Comment @= { Type = Noise } !Implied by GOLD
Remark Start = 'REM'
Remark End = '}'
Remark Block @= { Ending = Open } ! Don't eat the }, the statements expects it
Remark @= { Type = Noise }
<Program> ::= <Statements>
<Statements> ::= '{' <Statement> '}' <Statements> | <>
<Statement> ::= StringLiteral
步驟3正在抱怨<聲明>中的}和詞彙組結尾處的}。
任何人都知道如何完成我所需要的?
[編輯]
我得到了REM部分具有以下工作:
{Remark Chars} = {Printable} + {WhiteSpace} - [}]
Remark = 'REM' {Remark Chars}* '}'
<Statements> ::= <Statements> '{' <Statement> '}'
| <Statements> '{' <Statement> <Remark Stmt>
| <>
<Remark Stmt> ::= Remark
這實際上是理想的,因爲備註不一定噪音給我。
仍然有評論詞彙組的問題。我會用相同的方式來解決問題。
我很願意幫助,但我不知道金解析器,我使用野牛。我認爲這將是一個像轉移/減少或減少/減少的衝突。我沒有看到任何錯誤。它究竟是什麼意思? (也許你不應該寫,因爲我不知道如何解決它)反正 - 是的,我不能理解這一點。我沒有看到評論或評論如何與語法聯繫在一起。它看起來像ATM只有串litereals可以使用,只是在一份聲明中塊 – 2012-07-17 03:56:25
確切的錯誤是: DFA狀態12: 當兩個或多個終端定義可以接受相同的衝突的情況下}}:不能區分文本。 – Jay 2012-07-17 03:58:51
嗯,我正在考慮轉移/減少野牛的問題。當它說'{stringliterForStatement}'< - 可能'''結尾語句(除了後面的語句)或結束一個註釋/評論?在野牛你得到這個錯誤BC它不知道它是否應該減少和轉移會做更多的工作。然而,它是一個警告,由程序員決定是否要改變規則或允許它。當2條路徑可以完全結束並且它不知道選擇哪個時,它可能會導致問題 – 2012-07-17 04:02:26