haskell - Happy 中的 %% 是什么意思?

标签 haskell parser-generator happy

我正在用 Happy 构建一个解析器,并注意到这是 online documentation :

Like yacc, we include %% here, for no real reason.

%%


一定有原因,即使它是微不足道的。有谁知道它是什么?

最佳答案

它将 Yacc 源文件中的部分分开。例如见 http://dinosaur.compilertools.net/yacc/

Names refer to either tokens or nonterminal symbols. Yacc requires token names 
to be declared as such. In addition, for reasons discussed in Section 3, it is 
often desirable to include the lexical analyzer as part of the specification 
file; it may be useful to include other programs as well. Thus, every 
specification file consists of three sections: the declarations, (grammar) 
rules, and programs. The sections are separated by double percent ``%%'' marks. 
(The percent ``%'' is generally used in Yacc specifications as an escape 
character.)

In other words, a full specification file looks like

        declarations
        %%
        rules
        %%
        programs
The declaration section may be empty. Moreover, if the programs section is 
omitted, the second %% mark may be omitted also; thus, the smallest legal Yacc 
specification is

        %%
        rules

关于haskell - Happy 中的 %% 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8431621/

相关文章:

解析函数与Happy的应用

javascript - 如何在 Happy 解析器中匹配正则表达式?

function - 有没有办法定义一个单词是否只有 "a"元音?

string - 在 Haskell 中,如何在两个索引之间获取 Text 的子字符串?

haskell - 禁止某些 Haskell Alex/Happy 编译消息

silverlight - Silverilight 中的语言解析器

haskell - Haskell 中 "!!"的含义

haskell - 如何从 package.yml 生成 .cabal 文件

.net - .NET 的 JavaCC?

haskell - 在 Happy 和 Alex 中推回 token