简体   繁体   English

EBNF转JavaCC词法分析器

[英]EBNF to JavaCC lexer

How do you convert ::= [A-Za-z] into JavaCC? 您如何将:: = [A-Za-z]转换为JavaCC?

What I have done: 我做了什么:

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

but I don't know how to do the smaller letter parts 但我不知道怎么做较小的字母部分

Like this: 像这样:

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. 如果字符列表以“〜”符号为前缀,则它表示的字符集是不在指定集中的任何UNICODE字符。

Note that the rule: 注意规则:

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

is equivalent to: 等效于:

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

which both match a single letter. 两者都匹配一个字母。 If you want to repeat the class, you do need the parentheses and append a + quantifier: 如果要重复该类,则需要括号并附加一个+量词:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM