gpt4 book ai didi

java - javacc 中多余的 LOOKAHEAD 会导致错误吗?

转载 作者:行者123 更新时间:2023-12-01 11:35:06 27 4
gpt4 key购买 nike

我有以下TT.jj,如果我取消注释下面的SomethingElse部分,它会成功解析create create blahblah形式的语言> 或创建废话。但是,如果我注释掉下面的 SomethingElse 部分,但保留 LOOKAHEAD,javacc 会提示前瞻是不必要的并且“被忽略”,但生成的解析器只接受一个空的字符串。

我以为 javacc 说它被“忽略”,所以它不应该产生任何效果?基本上,多余的 LOOKAHEAD 会导致错误。具体是如何运作的?也许 javacc 的 LOOKAHEAD 实现不完全符合规范?

     options{
IGNORE_CASE=true ;
STATIC=false;
DEBUG_PARSER=true;
DEBUG_LOOKAHEAD=false;
DEBUG_TOKEN_MANAGER=false;
// FORCE_LA_CHECK=true;
UNICODE_INPUT=true;
}

PARSER_BEGIN(TT)

import java.util.*;

/**
* The parser generated by JavaCC
*/
public class TT {

}

PARSER_END(TT)


///////////////////////////////////////////// main stuff concerned
void Statement() :
{ }
{
LOOKAHEAD(2)
CreateTable()
//|
//SomethingElse()
}

void CreateTable():
{
}
{
<K_CREATE> <K_CREATE> <S_IDENTIFIER>
}

//void SomethingElse():
//{}{
// <K_CREATE> <S_IDENTIFIER>
//}
//
//////////////////////////////////////////////////////////


SKIP:
{
" "
| "\t"
| "\r"
| "\n"
}

TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
{
<K_CREATE: "CREATE">
}


TOKEN : /* Numeric Constants */
{
< S_DOUBLE: ((<S_LONG>)? "." <S_LONG> ( ["e","E"] (["+", "-"])? <S_LONG>)?
|
<S_LONG> "." (["e","E"] (["+", "-"])? <S_LONG>)?
|
<S_LONG> ["e","E"] (["+", "-"])? <S_LONG>
)>
| < S_LONG: ( <DIGIT> )+ >
| < #DIGIT: ["0" - "9"] >
}


TOKEN:
{
< S_IDENTIFIER: ( <LETTER> | <ADDITIONAL_LETTERS> )+ ( <DIGIT> | <LETTER> | <ADDITIONAL_LETTERS> | <SPECIAL_CHARS>)* >
| < #LETTER: ["a"-"z", "A"-"Z", "_", "$"] >
| < #SPECIAL_CHARS: "$" | "_" | "#" | "@">
| < S_CHAR_LITERAL: "'" (~["'"])* "'" ("'" (~["'"])* "'")*>
| < S_QUOTED_IDENTIFIER: "\"" (~["\n","\r","\""])+ "\"" | ("`" (~["\n","\r","`"])+ "`") | ( "[" ~["0"-"9","]"] (~["\n","\r","]"])* "]" ) >

/*
To deal with database names (columns, tables) using not only latin base characters, one
can expand the following rule to accept additional letters. Here is the addition of german umlauts.

There seems to be no way to recognize letters by an external function to allow
a configurable addition. One must rebuild JSqlParser with this new "Letterset".
*/
| < #ADDITIONAL_LETTERS: ["ä","ö","ü","Ä","Ö","Ü","ß"] >
}

最佳答案

JavaCC 表示忽略的前瞻规范并未被忽略。寓意:不要将前瞻规范放在非选择点。

更详细。当前瞻(除了纯语义前瞻)出现在非选择点时,它似乎会生成一个始终返回 false 的前瞻方法,因此前瞻失败,并且没有其他选择,会引发异常。

关于java - javacc 中多余的 LOOKAHEAD 会导致错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30087025/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com