博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javacc学习总结
阅读量:7117 次
发布时间:2019-06-28

本文共 1484 字,大约阅读时间需要 4 分钟。

       在学javacc的时候。发现一个问题,见下:

Example.jj文件

PARSER_BEGIN(Example)public class Example {  public static void main(String args[]) throws ParseException {    Example parser = new Example(System.in);    parser.basic_expr();  }}PARSER_END(Example)SKIP :{  " "| "\t"| "\n"| "\r"}void basic_expr() :{}{  
{System.out.println("got 333");} "(" expr() ")"| "(" expr() ")"| "weichaofan"{System.out.println("got 111");}
{System.out.println("got 222");} | "weichao"{System.out.println("got 44");}
{System.out.println("got 55");} }void expr() :{}{ "TBD"}TOKEN [IGNORE_CASE] :{
}

 

看官网文档,有一下重要说明:

1、若jj文件里含有冲突。则会提示。例如以下图所看到的。

In situations where it does not work well, Java Compiler Compiler provides you with warning messages like the ones shown above.
If you have a grammar that goes through Java Compiler Compiler without producing any warnings, then the grammar is a LL(1) grammar. Essentially, LL(1) grammars are those that can be handled by top-down parsers (such as those generated by Java Compiler Compiler) using at most one token of LOOKAHEAD.
解释:
    假设jj文件里出现警告信息,则说明不能正常执行,假设jj文件没有警告信息,则说明此是LL(1)文法。LL(1)文法可以从上而下解析最多仅仅用lookahead 1 个token。

 

 

疑问

    看上面样例,ID是否包括符号“weichaofan”和“weichao”?

 

 

看样例:

    经过拿样例验证。得出下面结论:

   1、“weichaofan”和“weichao”不是ID,即ID已经不包括这两个符号。
   2、语法分析程序在选择时,首先依据已经确定的,然后再匹配,在这个样例中匹配顺序例如以下(“(”,“weichaofan”。“weichao”。ID)。

   假设把这两个结论合成一个,那就是“weichaofan”和“weichao”在程序里面已经是“keyword”了。是和ID并行的,就像java程序里面的newkeyword和变量名字

 

 

你可能感兴趣的文章
bash配置文件读取顺序
查看>>
北京教育软件创业公司招 .net工程师
查看>>
AIX扩展文件系统
查看>>
RedHat 6 创建和扩容LVM卷
查看>>
access_log每周回滚方法分割一次成access_log.1....
查看>>
centos 6.5 ntp 服务器搭建
查看>>
server2008r2网卡绑定
查看>>
HTML5基础标签一
查看>>
linux下配置socks 5代理
查看>>
CentOS 7 不能连接Kvm虚拟机console.....
查看>>
利用组策略部署软件——将软件发布给用户
查看>>
开心城市能否再创“偷菜”辉煌
查看>>
域名服务DNS--(1)
查看>>
算法学习之路|逆元取模(二)
查看>>
科技,让奥运更智能:阿里云ET大脑推动奥运时代变革
查看>>
修改SSH端口,对Oracle集群的影响
查看>>
vSphere部署系列之05——虚拟机的创建和设置
查看>>
进程间通信的方式及比较
查看>>
Pnp安装过程
查看>>
Linux 下 Oracle 10g 安装“三部曲”
查看>>