5

Happyを使用してパーサーを構築していますが、これがオンラインドキュメントであることに気付きました。

yaccのように、本当の理由もなく、ここに%%を含めます。

%%

たとえそれが些細なことであっても、理由があるに違いありません。誰かがそれが何であるか知っていますか?

4

1 に答える 1

5

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
于 2011-12-08T13:24:55.787 に答える