我的语法中的注释块有一些问题。语法很好,但第 3 步 DFA 扫描程序抱怨我的处理方式。
我试图解析的语言如下所示:
{statement}{statement} 等
每个语句中可以包含几种不同类型的注释:
{% 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 步是抱怨 <Statements> 中的 } 和词组末尾的 }。
有人知道如何完成我需要的吗?
[编辑]
我让 REM 部分使用以下内容:
{Remark Chars} = {Printable} + {WhiteSpace} - [}]
Remark = 'REM' {Remark Chars}* '}'
<Statements> ::= <Statements> '{' <Statement> '}'
| <Statements> '{' <Statement> <Remark Stmt>
| <>
<Remark Stmt> ::= Remark
这实际上是理想的,因为备注对我来说不一定是噪音。
仍然有评论词汇组的问题。我会以同样的方式解决问题。