免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2733 | 回复: 4
打印 上一主题 下一主题

activeperl里如何安装Parse::Lex [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-21 19:50 |只看该作者 |倒序浏览
我在ppm里search了一下,没有Parse::Lex。
是不是只能用源代码安装?

哪里可以找到这个包的ppd?

论坛徽章:
0
2 [报告]
发表于 2006-03-22 01:08 |只看该作者
看这个模块的源码是纯 Perl  的,你可以下载了(还有相关的其他模块)直接用就可以。

论坛徽章:
0
3 [报告]
发表于 2006-03-22 07:51 |只看该作者

使用中有错误

谢谢Qiang哥的回复,直接用我试过的。
但是有莫明的错误,好像和strict用关,但是去掉了strict也不行。\
错误信息如下:
---------- perl ----------
Unknown 'strict' tag(s) '1' at C:/Perl/site/lib/Parse/Template.pm line 2
BEGIN failed--compilation aborted at C:/Perl/site/lib/Parse/Template.pm line 2.
Compilation failed in require at C:/Perl/site/lib/Parse/Token.pm line 376.
BEGIN failed--compilation aborted at C:/Perl/site/lib/Parse/Token.pm line 376.
Compilation failed in require at C:/Perl/site/lib/Parse/ALex.pm line 23.
BEGIN failed--compilation aborted at C:/Perl/site/lib/Parse/ALex.pm line 23.
Compilation failed in require at C:/Perl/site/lib/Parse/Lex.pm line 7.
BEGIN failed--compilation aborted at C:/Perl/site/lib/Parse/Lex.pm line 7.
Compilation failed in require at kick_lex.pl line 1.
BEGIN failed--compilation aborted at kick_lex.pl line 1.


代码如下:

  1. use Parse::Lex;

  2. #define the tokens
  3. my @token = qw (
  4.     BegParen [\(]
  5.     Endparen [\)]        
  6.     Operator [-+*/^]
  7.     Number [-?\d+|-?\d+\.\d*]
  8. );

  9. my $lexer = Parse::Lex->new(@token);
  10. $lexer->from(STDIN);

  11. my $token;

  12. TOKEN:
  13. while (1) {
  14.     $token = $lexer->next;
  15.     if ( not $lexer->eoi ) {
  16.         print $token->name. " " . $token->text. " " . "\n";
  17.     } else {
  18.         last TOKEN;
  19.     }
  20. }
复制代码


我用的ParseLex是2.15版本。

我再研究一下

论坛徽章:
0
4 [报告]
发表于 2006-03-22 08:08 |只看该作者

two small errors

In $ParseLexHome/lib/Parse/Template.pm there's two errors. The first is on line 1, 'use strict' is missing a simi colon.

The next is on line 135, the variable $expr needs to be declared as a new variable by adding 'my' in front of it.
broken: $expr = $1;
fixed : my $expr = $1;

论坛徽章:
0
5 [报告]
发表于 2006-03-22 10:40 |只看该作者

把程序修改了一下,好像正常了


  1. use strict;
  2. use warnings;

  3. require 5.000;

  4. use Parse::Lex;

  5. my @token = qw (
  6.     BegParen [\(]
  7.     Endparen [\)]
  8.     Number [-+]*\d+(\.\d+)*
  9.     Operator [-+*/^]
  10. );

  11. my $lexer = Parse::Lex->new(@token);
  12. $lexer->from(\*DATA);

  13. TOKEN:while (1) {
  14.     if (my $token = $lexer->next) {
  15.         print $token->name . " " . $token->text . " " . "\n";
  16.     } else {
  17.         last TOKEN;
  18.     }
  19. }

  20. __END__
  21. (43.4*15^8)
复制代码

[ 本帖最后由 ehu4ever 于 2006-3-22 10:59 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP