2011-12-08 24 views
5

Tôi đang xây dựng một phân tích cú pháp với Happy và nhận thấy đây là online documentation:%% cho trong Happy là gì?

Giống như yacc, chúng tôi bao gồm %% đây, không có lý do thực sự.

%%

Phải có một lý do mặc dù, ngay cả khi nó là tầm thường. Có ai biết nó là gì?

Trả lời

5

Nó phân tách các phần trong tệp nguồn Yacc. ví dụ. Xem 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 
Các vấn đề liên quan