Antlr JavaScript ECMA脚本派生语法错误

Antlr JavaScript ECMA脚本派生语法错误,antlr,antlr4,Antlr,Antlr4,我正在创建一个源自ECMA脚本语法的简化语法: 到目前为止,原始语法还不错,我只添加了一些规则。但是,以下表达式在我的语法中是有效的表达式,但在原始ECMA语法中抛出错误: round(frames++/((getTime()-start)/1000)) 由 框架++/ 表情 鉴于以下类似表达适用: round(frames++*((getTime()-start)/1000)) round(frames++%((getTime()-start)/1000)) 我的问题是如何使第一个表达式

我正在创建一个源自ECMA脚本语法的简化语法:

到目前为止,原始语法还不错,我只添加了一些规则。但是,以下表达式在我的语法中是有效的表达式,但在原始ECMA语法中抛出错误:

round(frames++/((getTime()-start)/1000))

框架++/

表情

鉴于以下类似表达适用:

round(frames++*((getTime()-start)/1000))
round(frames++%((getTime()-start)/1000))

我的问题是如何使第一个表达式工作以及有什么区别?

这可能是因为
/
被解释为正则表达式分隔符的开始

如果查看lexer方法,该方法确定
/
何时为正则表达式文字,何时为除法运算符:

/**
 * Returns {@code true} iff the lexer can match a regex literal.
 *
 * @return {@code true} iff the lexer can match a regex literal.
 */
private boolean isRegexPossible() {

    if (this.lastToken == null) {
        // No token has been produced yet: at the start of the input,
        // no division is possible, so a regex literal _is_ possible.
        return true;
    }

    switch (this.lastToken.getType()) {
        case Identifier:
        case NullLiteral:
        case BooleanLiteral:
        case This:
        case CloseBracket:
        case CloseParen:
        case OctalIntegerLiteral:
        case DecimalLiteral:
        case HexIntegerLiteral:
        case StringLiteral:
            // After any of the tokens above, no regex literal can follow.
            return false;
        default:
            // In all other cases, a regex literal _is_ possible.
            return true;
    }
}
然后,对于标记
--
++
,这也应该返回false

调整
isRegexPossible()
,如下所示:

private boolean isRegexPossible() {

    if (this.lastToken == null) {
        // No token has been produced yet: at the start of the input,
        // no division is possible, so a regex literal _is_ possible.
        return true;
    }

    switch (this.lastToken.getType()) {
        case Identifier:
        case NullLiteral:
        case BooleanLiteral:
        case This:
        case CloseBracket:
        case CloseParen:
        case OctalIntegerLiteral:
        case DecimalLiteral:
        case HexIntegerLiteral:
        case StringLiteral:
        case PlusPlus:               // <-- NEW
        case MinusMinus:             // <-- NEW
            // After any of the tokens above, no regex literal can follow.
            return false;
        default:
            // In all other cases, a regex literal _is_ possible.
            return true;
    }
}
private boolean isregexpossable(){
if(this.lastToken==null){
//尚未生成令牌:在输入开始时,
//没有除法是可能的,所以正则表达式文字是可能的。
返回true;
}
开关(this.lastToken.getType()){
案例标识符:
大小写NullLiteral:
大小写布尔文本:
本案:
箱盖支架:
结案:
案例八面平行:
病例分位数:
病例报告:
大小写字符串:

case PlusPlus://你写的第一个表达式已经与你的语法一起工作了,然后你问如何使它工作。这没有多大意义。要说一些关于差异的东西,我们需要在原始语法和你的语法之间进行区分。亲爱的Mike,谢谢你的回答。语法尚未完成,但将继续要比ECMA语法简单得多。让我换一种方式问一下。为什么表达式“round(frames++/((getTime()-start)/1000))”在ECMA语法中,虽然其他引用的表达式有效,但不起作用?我必须在ECMA语法中做些什么才能使这个表达式有效?很好的解释。非常感谢您的时间帮助。现在它有效了。如果这个更改也能在Github上成为ECMA语法,那就太好了。@Marcel我刚刚看到了原始的语法已经有了
PlusPlus
minusplus
标记。@Bart是的,我注意到了。再次感谢