作者kornelius (c9s)
看板Perl
标题Re: [问题] Parse::RecDescent 如何取出grammer 里 …
时间Sun Aug 2 15:47:55 2009
※ 引述《kornelius (c9s)》之铭言:
: ※ 引述《n0tme (I made this)》之铭言:
: : $grammar = q {
: : # GRAMMAR SPECIFICATION HERE {;return={something => $var} }
: ^^^^^^ 被注解掉了?
: 请参考 perldoc Parse::RecDescent 的 Rules 章节,
: 我想 $grammer 里面的 rule 应该是要照那样写:
: rule1: production1
: | production2 |
: production3 | production4
: typedef: "typedef" typename identifier ';'
: 之类的。
: : };
应该会像是这样用:
parser = new Parse::RecDescent (q{
expression: and_expr '||' expression
{ [@item] }
| and_expr
{ [@item] }
and_expr: not_expr '&&' and_expr
{ [@item] }
| not_expr
{ [@item] }
not_expr: '!' brack_expr
{ [@item] }
| brack_expr
{ [@item] }
brack_expr: '(' expression ')'
{ [@item] }
| identifier
{ [@item] }
identifier: /[a-z]+/i
{ [@item] }
});
--
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.117.168.163