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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器