dsjbest2015 2010-10-23 08:36
浏览 38
已采纳

Lemon Parser-Generator:非终端未评估?

I try to learn parsers. Because my C skills are pretty low, I googled a PHP Lemon to learn sth about Parser Generators. Anyway, the code here should be readable for normal lemon friends, too.

As always when handling parsing questions, I start with trying to produce a simple calculator first.

So my first step is simply this:

start(A)   ::= expr(B). {echo "======RESULT:".A.":".B.":=========".PHP_EOL;}

what parses the first test:

include "mysimple.php"; //include the generated Parser
$P = new ParseParser(); //create a Parser object
$P->Parse(ParseParser::VALUE,"13"); // here is the simple test, just understand the Number 13, pls
$P->Parse(0,0); //input is finished, parse!
echo "finished. yeah!".PHP_EOL;

...to the result of:

======RESULT:13:=========
finished. yeah!

So, everything as expected. Now we try to prepare a step that finally will allow us to handle operations, the expression:

start ::= expr(B).  {echo "======RESULT:".B.":=========".PHP_EOL;}
expr  ::= VALUE(B). {echo "got a value:".B.PHP_EOL;}

When I run the same test now, I expect to see the same output, plus one line saying got a value: 13. But I just get this:

got a value:13
======RESULT::=========
finished. yeah!

Well, what happened? Why is the result line empty? Obviously expr evaluates to a VALUE of `13'. Does Lemon not care about evaluating? Do I have to do that myself somehow? But how, if I get nothing in this point?

  • 写回答

1条回答 默认 最新

  • dongsuo0517 2010-10-23 08:48
    关注

    Do you not want something like:

    expr(A) ::= VALUE(B). {A = B; echo "got a value:".B.PHP_EOL;}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?