如何在CUP解析器语法中匹配空白字符 [英] How to match the empty case in CUP parser grammar
问题描述
我正在使用CUP生成解析器,并且我希望一个空文件成为可接受的程序.我已根据对类似问题的回答
I am using CUP to generate a parser, and I want an empty file to be an acceptable program. I have tried add the empty case to my start symbol, based off the response to a similar question here.
start with prog;
/* The grammar rules */
prog ::= class_block:cb
| class_block:cb stmts:sb
| stmts:sb
| // desired empty case
;
包含所需的空大小写会给我以下错误:
Including the desired empty case gives me the following error:
parser.java:516: error: incompatible types: Object cannot be converted to Symbol
CUP$parser$result = parser.getSymbolFactory().newSymbol("prog",0, ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
如何修改语法,使解析器接受一个空文件? 我使用Jflex作为词法分析器,使用ComplexSymbolFactory作为符号的类型.
How can I modify my grammar so that the parser accepts an empty file? I am using Jflex as my lexer, and ComplexSymbolFactory as the type of the symbols.
我已经确认上面的语法是包含空的正确方法.但是,ComplexSymbolFactory在将空对象转换为符号时遇到问题. 即使在此示例中运行,我也会收到此错误银联官方网站.
I've confirmed that the grammar above is the correct way to include empty. However, ComplexSymbolFactory is having problems converting the empty object to a symbol. I get this error even when running this example from the official CUP website.
推荐答案
我从一个朋友github项目下载了.jars,并解决了问题.
I downloaded the .jars from a friend github project and problem solved.
您可以在这里看到它的错误: https://github.com/jflex -de/jflex/issues/384
You can see it's a BUG here: https://github.com/jflex-de/jflex/issues/384
尝试降级版本.
这篇关于如何在CUP解析器语法中匹配空白字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!