gpt4 book ai didi

java - EBNF 到 JavaCC 词法分析器

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

如何将::= [A-Za-z] 转换为 JavaCC?

我做了什么:

TOKEN :
{
< LETTER : (["A"-"Z"])>
}

但我不知道如何做较小的字母部分

最佳答案

像这样:

TOKEN :
{
< LETTER : (["A"-"Z", "a"-"z"])>
}

Reference :

A character list describes a set of characters. A legal match for a character list is any character in this set. A character list is a list of character descriptors separated by commas within square brackets. Each character descriptor describes a single character or a range of characters (see character descriptor below), and this is added to the set of characters of the character list. If the character list is prefixed by the "~" symbol, the set of characters it represents is any UNICODE character not in the specified set.

请注意规则:

TOKEN :
{
< LETTER : (["A"-"Z", "a"-"z"])>
}

相当于:

TOKEN :
{
< LETTER : ["A"-"Z", "a"-"z"]>
}

两者都匹配单个字母。如果您想重复该类,则需要括号并附加一个 + 量词:

TOKEN :
{
< LETTERS : (["A"-"Z", "a"-"z"])+ >
}

关于java - EBNF 到 JavaCC 词法分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23218292/

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