dongren1977 2012-10-17 10:08
浏览 79
已采纳

解析器和词法分析器生成器php

I am doing a academic work that I need to use parser and lexer generator for php. I searched on the internet and I found this

The problem is create the grammar and plex file. For example:

<?php
class blah {
/*!lex2php
%input $this->data
%counter $this->N
%token $this->token
%value $this->value
%line $this->line
variable = @/?:([a-zA-Z0-9_]+)/?@
*/
/*!lex2php
variable {$a = 1;}
*/
}
?>

Someone can explain me that code please?

  • 写回答

1条回答 默认 最新

  • duanliusong6395 2012-10-17 10:15
    关注

    The first comment block is used for declarations. All the % declaration are mostly for internal use, and not very relevant at this stage.
    The variable = @/?:([a-zA-Z0-9_]+)/?@ is interesting though. It defines a nonterminal symbol variable, defined by the regex @/?:([a-zA-Z0-9_]+)/?@.

    If you generate your lexer using this plex file and feed it something like this:

    234lksdf lskdjf324 kl234jd
    

    The tokenstream would be as follows:

    token: variable
    value: 234lksdf 
    
    token: variable
    value: lskdjf324 
    
    token: variable
    value: kl234jd
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料