下面是一个简单的JAVACC的HELLOWORLD的代码。
options {
LOOKAHEAD = 1;
CHOICE_AMBIGUITY_CHECK = 2;
OTHER_AMBIGUITY_CHECK = 1;
STATIC = true;
DEBUG_PARSER = false;
DEBUG_LOOKAHEAD = false;
DEBUG_TOKEN_MANAGER = false;
ERROR_REPORTING = true;
JAVA_UNICODE_ESCAPE = false;
UNICODE_INPUT = false;
IGNORE_CASE = false;
USER_TOKEN_MANAGER = false;
USER_CHAR_STREAM = false;
BUILD_PARSER = true;
BUILD_TOKEN_MANAGER = true;
SANITY_CHECK = true;
FORCE_LA_CHECK = false;
}
PARSER_BEGIN(Hello)
public class Hello{
public static void main(String args[]) throws ParseException {
Hello parser = new Hello(System.in);
parser.SayHello();
}
}
PARSER_END(Hello)
void SayHello():
{}
{
"Hello"("\n"|"\r")*
}
可以看出,其实最有用的就是SayHello这个函数了,其实是直接匹配字符串"Hello"的。
阅读(577) | 评论(0) | 转发(0) |