`
tianyalinfeng
  • 浏览: 442462 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

JavaCC options

    博客分类:
  • Java
 
阅读更多

quote from: http://javacc.java.net/doc/javaccgrm.html

 

  • LOOKAHEAD: The number of tokens to look ahead before making a decision at a choice point during parsing. The default value is 1. The smaller this number, the faster the parser. This number may be overridden for specific productions within the grammar as described later. See the description of the lookahead algorithm for complete details on how lookahead works.
  • CHOICE_AMBIGUITY_CHECK: This is an integer option whose default value is 2. This is the number of tokens considered in checking choices of the form "A | B | ..." for ambiguity. For example, if there is a common two token prefix for both A and B, but no common three token prefix, (assume this option is set to 3) then JavaCC can tell you to use a lookahead of 3 for disambiguation purposes. And if A and B have a common three token prefix, then JavaCC only tell you that you need to have a lookahead of 3 or more. Increasing this can give you more comprehensive ambiguity information at the cost of more processing time. For large grammars such as the Java grammar, increasing this number any further causes the checking to take too much time.
  • OTHER_AMBIGUITY_CHECK: This is an integer option whose default value is 1. This is the number of tokens considered in checking all other kinds of choices (i.e., of the forms "(A)*", "(A)+", and "(A)?") for ambiguity. This takes more time to do than the choice checking, and hence the default value is set to 1 rather than 2.
  • STATIC: This is a boolean option whose default value is true. If true, all methods and class variables are specified as static in the generated parser and token manager. This allows only one parser object to be present, but it improves the performance of the parser. To perform multiple parses during one run of your Java program, you will have to call the ReInit() method to reinitialize your parser if it is static. If the parser is non-static, you may use the "new" operator to construct as many parsers as you wish. These can all be used simultaneously from different threads.
  • DEBUG_PARSER: This is a boolean option whose default value is false. This option is used to obtain debugging information from the generated parser. Setting this option to true causes the parser to generate a trace of its actions. Tracing may be disabled by calling the method disable_tracing() in the generated parser class. Tracing may be subsequently enabled by calling the method enable_tracing() in the generated parser class.
  • DEBUG_LOOKAHEAD: This is a boolean option whose default value is false. Setting this option to true causes the parser to generate all the tracing information it does when the option DEBUG_PARSER is true, and in addition, also causes it to generated a trace of actions performed during lookahead operation.
  • DEBUG_TOKEN_MANAGER: This is a boolean option whose default value is false. This option is used to obtain debugging information from the generated token manager. Setting this option to true causes the token manager to generate a trace of its actions. This trace is rather large and should only be used when you have a lexical error that has been reported to you and you cannot understand why. Typically, in this situation, you can determine the problem by looking at the last few lines of this trace.
  • ERROR_REPORTING: This is a boolean option whose default value is true. Setting it to false causes errors due to parse errors to be reported in somewhat less detail. The only reason to set this option to false is to improve performance.
  • JAVA_UNICODE_ESCAPE: This is a boolean option whose default value is false. When set to true, the generated parser uses an input stream object that processes Java Unicode escapes (\u...) before sending characters to the token manager. By default, Java Unicode escapes are not processed.
    This option is ignored if either of options USER_TOKEN_MANAGER, USER_CHAR_STREAM is set to true.
  • UNICODE_INPUT: This is a boolean option whose default value is false. When set to true, the generated parser uses uses an input stream object that reads Unicode files. By default, ASCII files are assumed.
    This option is ignored if either of options USER_TOKEN_MANAGER, USER_CHAR_STREAM is set to true.
  • IGNORE_CASE: This is a boolean option whose default value is false. Setting this option to true causes the generated token manager to ignore case in the token specifications and the input files. This is useful for writing grammars for languages such as HTML. It is also possible to localize the effect of IGNORE_CASE by using an alternate mechanism described later.
  • USER_TOKEN_MANAGER: This is a boolean option whose default value is false. The default action is to generate a token manager that works on the specified grammar tokens. If this option is set to true, then the parser is generated to accept tokens from any token manager of type "TokenManager" - this interface is generated into the generated parser directory.
  • SUPPORT_CLASS_VISIBILITY_PUBLIC: This is a boolean option whose default value is true. The default action is to generate support classes (such as Token.java, ParseException.java etc) with Public visibility. If set to false, the classes will be generated with package-private visibility.
  • USER_CHAR_STREAM: This is a boolean option whose default value is false. The default action is to generate a character stream reader as specified by the options JAVA_UNICODE_ESCAPE and UNICODE_INPUT. The generated token manager receives characters from this stream reader. If this option is set to true, then the token manager is generated to read characters from any character stream reader of type "CharStream.java". This file is generated into the generated parser directory.
    This option is ignored if USER_TOKEN_MANAGER is set to true.
  • BUILD_PARSER: This is a boolean option whose default value is true. The default action is to generate the parser file ("MyParser.java" in the above example). When set to false, the parser file is not generated. Typically, this option is set to false when you wish to generate only the token manager and use it without the associated parser.
  • BUILD_TOKEN_MANAGER: This is a boolean option whose default value is true. The default action is to generate the token manager file ("MyParserTokenManager.java" in the above example). When set to false the token manager file is not generated. The only reason to set this option to false is to save some time during parser generation when you fix problems in the parser part of the grammar file and leave the lexical specifications untouched.
  • TOKEN_MANAGER_USES_PARSER: This is a boolean option whose default value is false. When set to true, the generated token manager will include a field called parser that references the instantiating parser instance (of type MyParser in the above example). The main reason for having a parser in a token manager is using some of its logic in lexical actions. This option has no effect if the STATIC option is set to true.
  • TOKEN_EXTENDS: This is a string option whose default value is "", meaning that the generated Token class will extend java.lang.Object. This option may be set to the name of a class that will be used as the base class for the generated Token class.
  • TOKEN_FACTORY: This is a string option whose default value is "", meaning that Tokens will be created by calling Token.newToken(). If set the option names a Token factory class containing a public static Token newToken(int ofKind, String image) method.
  • SANITY_CHECK: This is a boolean option whose default value is true. JavaCC performs many syntactic and semantic checks on the grammar file during parser generation. Some checks such as detection of left recursion, detection of ambiguity, and bad usage of empty expansions may be suppressed for faster parser generation by setting this option to false. Note that the presence of these errors (even if they are not detected and reported by setting this option to false) can cause unexpected behavior from the generated parser.
  • FORCE_LA_CHECK: This is a boolean option whose default value is false. This option setting controls lookahead ambiguity checking performed by JavaCC. By default (when this option is false), lookahead ambiguity checking is performed for all choice points where the default lookahead of 1 is used. Lookahead ambiguity checking is not performed at choice points where there is an explicit lookahead specification, or if the option LOOKAHEAD is set to something other than 1. Setting this option to true performs lookahead ambiguity checking at all choice points regardless of the lookahead specifications in the grammar file.
  • COMMON_TOKEN_ACTION: This is a boolean option whose default value is false. When set to true, every call to the token manager's method "getNextToken" (see the description of the Java Compiler Compiler API) will cause a call to a used defined method "CommonTokenAction" after the token has been scanned in by the token manager. The user must define this method within the TOKEN_MGR_DECLS section. The signature of this method is:
        void CommonTokenAction(Token t)
    
  • CACHE_TOKENS: This is a boolean option whose default value is false. Setting this option to true causes the generated parser to lookahead for extra tokens ahead of time. This facilitates some performance improvements. However, in this case (when the option is true), interactive applications may not work since the parser needs to work synchronously with the availability of tokens from the input stream. In such cases, it's best to leave this option at its default value.
  • OUTPUT_DIRECTORY: This is a string valued option whose default value is the current directory. This controls where output files are generated.
  • 分享到:
    评论

    相关推荐

      JavaCC学习心得

      JavaCC 文件可以分为三个部分:参数列表(Options)、解释器 JAVA 代码和一系列产物(Production)。参数列表是可选项,解释器 JAVA 代码由 PARSER_BEGIN(解释器名称)、JAVA 编辑单元和 PARSER_END(解释器名称)...

      javacc+jjtree使用教程

      - 通过在`options`部分设置`MULTI = true;`和`VISITOR = true;`,启用多态解析器模式和访问者模式,这允许我们更灵活地处理生成的AST。 2. **JJTree**: - JJTree 是JavaCC的一个扩展,用于生成抽象语法树。它...

      JAVACC简易教程学习

      - **选项设置**:在`options`块中,`STATIC=false`指定了生成的解析器代码不会是静态的。 - **类定义**:定义了一个名为`Adder`的类,其中包含`main`方法,用于实例化`Adder`对象并调用`Start`方法开始解析过程。 ...

      JavaCC语法文件中文版 V2.0_静水71

      此外,文档中提到的javacc_options定义了JavaCC解析器生成的选项,比如是否忽略大小写、是否包含更多的调试信息等。这些选项可以根据不同的需求和目标来配置。 总的来说,JavaCC语法文件是构建编译器前端的一个重要...

      JavaCC教程(附源码)

      options { STATIC = false; } PARSER_BEGIN(Adder) // 定义词法分析器 TOKEN: { <PLUS: "+"> // 定义加号 ([0-9])+> // 定义数字 SKIP: {" "} // 忽略空格 SKIP: {"\n" | "\r" | "\r\n"} // 忽略换行符 } ...

      javacc 学习心得

      ### JAVACC学习心得知识点详解 #### 一、引言 JAVACC是一款强大的解析工具,主要用于构建解析器。本文档旨在分享通过两周多的学习后对JAVACC的理解与心得,主要内容涵盖其工作原理、使用方法及深入认识等方面。 #...

      JavaCC:Java原始码解析-源码解析

      5. **Options**:配置JavaCC的行为,如错误处理、输入输出设置等。 在使用JavaCC时,你需要编写一个`.jj`文件,包含上述定义。然后运行JavaCC工具,它会生成对应的Java源代码,这些代码实现了你定义的解析逻辑。...

      学习javaCC语法分析whileifelsefor互相嵌套.pdf

      `options`块设置了一些配置,如JDK版本和是否开启调试模式。 文件中的`SKIP`部分定义了忽略的字符,如空格、制表符、换行符和回车符。`TOKEN`部分则定义了词法规则,包括运算符、常量、关键字(如`main`、`void`、`...

      javaCC语法分析(while、if...else...、for互相嵌套).pdf

      1. **选项(Options)**:`JDK_VERSION`设置为"1.5"表示该解析器兼容Java 1.5及以上版本,而`DEBUG_PARSER`设置为`true`意味着在运行时将启用调试模式。 2. **PARSER_BEGIN/END**:定义解析器的开始和结束。`...

      javaccjjtree使用教程借鉴.pdf

      - 在`minijava.jj`文件中,`options`部分是配置解析器的关键。添加`MULTI = true;`和`VISITOR = true;`这两行代码,分别开启多重词法分析器和访问者模式。 - 重命名`minijava.jj`为`minijava.jjt`,这告诉JJTree这...

      Java_高级文本编辑器的android.zip

      5. **UI设计**:使用XML布局文件创建用户界面,包括EditText(文本输入框)、Toolbar(自定义顶部栏)、OptionsMenu(选项菜单)等元素。对于高级编辑器,可能还会涉及代码高亮、缩进、行号显示等功能。 6. **文件I...

    Global site tag (gtag.js) - Google Analytics