📄 javacc.jj
字号:
/* * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has * intellectual property rights relating to technology embodied in the product * that is described in this document. In particular, and without limitation, * these intellectual property rights may include one or more of the U.S. * patents listed at http://www.sun.com/patents and one or more additional * patents or pending patent applications in the U.S. and in other countries. * U.S. Government Rights - Commercial software. Government users are subject * to the Sun Microsystems, Inc. standard license agreement and applicable * provisions of the FAR and its supplements. Use is subject to license terms. * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This * product is covered and controlled by U.S. Export Control laws and may be * subject to the export or import laws in other countries. Nuclear, missile, * chemical biological weapons or nuclear maritime end uses or end users, * whether direct or indirect, are strictly prohibited. Export or reexport * to countries subject to U.S. embargo or to entities identified on U.S. * export exclusion lists, including, but not limited to, the denied persons * and specially designated nationals lists is strictly prohibited. *//* * This file contains the grammar and actions that describe * JavaCCParser. When passed as input to JavaCCParser it generates * another copy of itself. Hence JavaCCParser may be modified by * modifying this file, and therefore this file is to be considered * the master version of JavaCCParser. */options { JAVA_UNICODE_ESCAPE = true; STATIC=false;}PARSER_BEGIN(JavaCCParser)/** * This file contains the code for JavaCCParser generated * by JavaCCParser itself. */package org.javacc.parser;public class JavaCCParser extends JavaCCParserInternals { /** * The name of the parser class. */ String parser_class_name; /** * This flag is set to true when the part between PARSER_BEGIN and * PARSER_END is being parsed. */ boolean processing_cu = false; /** * The level of class nesting. */ int class_nesting = 0; /** * This int variable is incremented while parsing local lookaheads. * Hence it keeps track of *syntactic* lookahead nesting. * This is used to provide warnings when actions and nested lookaheads * are used in syntactic lookahead productions. This is to prevent * typos such as leaving out the comma in LOOKAHEAD( foo(), {check()} ). */ int inLocalLA = 0; /** * Set to true when the parser is within an action. */ boolean inAction = false; /** * This flag keeps track of whether or not return and throw * statements have been patched during the parsing of a production. * The value of this flag is assigned the field with the same * name in BNFProduction.java. */ boolean jumpPatched = false; /* * Returns true if the next token is not in the FOLLOW list of "expansion". * It is used to decide when the end of an "expansion" has been reached. */ private boolean notTailOfExpansionUnit() { Token t; t = getToken(1); if (t.kind == BIT_OR || t.kind == COMMA || t.kind == RPAREN || t.kind == RBRACE || t.kind == RBRACKET) return false; return true; }}PARSER_END(JavaCCParser)TOKEN_MGR_DECLS :{ int beginLine[] = new int[10]; int beginCol[] = new int[10]; int depth = 0; int size = 10; void saveBeginLineCol(int l, int c) { if (depth == size) { size += 5; int tmpbeginLine[] = new int[size]; int tmpbeginCol[] = new int[size]; System.arraycopy(beginLine, 0, beginLine = tmpbeginLine, 0, depth); System.arraycopy(beginCol, 0, beginCol = tmpbeginCol, 0, depth); } beginLine[depth] = l; beginCol[depth] = c; depth++; } void restoreBeginLineCol() { depth--; input_stream.adjustBeginLineColumn(beginLine[depth], beginCol[depth]); }}/********************************************** * THE JAVACC TOKEN SPECIFICATION STARTS HERE * **********************************************//* JAVACC RESERVED WORDS: These are the only tokens in JavaCC but not in Java */TOKEN :{ < _OPTIONS: "options" >| < _LOOKAHEAD: "LOOKAHEAD" >| < _IGNORE_CASE: "IGNORE_CASE" >| < _PARSER_BEGIN: "PARSER_BEGIN" >| < _PARSER_END: "PARSER_END" >| < _JAVACODE: "JAVACODE" >| < _TOKEN: "TOKEN" >| < _SPECIAL_TOKEN: "SPECIAL_TOKEN" >| < _MORE: "MORE" >| < _SKIP: "SKIP" >| < _TOKEN_MGR_DECLS: "TOKEN_MGR_DECLS" >| < _EOF: "EOF" >}/* * The remainder of the tokens are exactly (except for the removal of tokens * containing ">>" and "<<") as in the Java grammar and must be diff equivalent * (again with the exceptions above) to it. *//* WHITE SPACE */SKIP :{ " "| "\t"| "\n"| "\r"| "\f"| "/*@egen*/" : AFTER_EGEN }<AFTER_EGEN> SKIP :{ <~[]> { restoreBeginLineCol(); input_stream.backup(1); } : DEFAULT}/* COMMENTS */MORE :{ "//" : IN_SINGLE_LINE_COMMENT| <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT| "/*" : IN_MULTI_LINE_COMMENT| "/*@bgen(jjtree" { saveBeginLineCol(input_stream.getBeginLine(), input_stream.getBeginColumn()); } : IN_MULTI_LINE_COMMENT}<IN_SINGLE_LINE_COMMENT>SPECIAL_TOKEN :{ <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : DEFAULT}<IN_FORMAL_COMMENT>SPECIAL_TOKEN :{ <FORMAL_COMMENT: "*/" > : DEFAULT}<IN_MULTI_LINE_COMMENT>SPECIAL_TOKEN :{ <MULTI_LINE_COMMENT: "*/" > : DEFAULT}<IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>MORE :{ < ~[] >}/* JAVA RESERVED WORDS AND LITERALS */TOKEN :{ < ABSTRACT: "abstract" >| < BOOLEAN: "boolean" >| < BREAK: "break" >| < BYTE: "byte" >| < CASE: "case" >| < CATCH: "catch" >| < CHAR: "char" >| < CLASS: "class" >| < CONST: "const" >| < CONTINUE: "continue" >| < _DEFAULT: "default" >| < DO: "do" >| < DOUBLE: "double" >| < ELSE: "else" >| < EXTENDS: "extends" >| < FALSE: "false" >| < FINAL: "final" >| < FINALLY: "finally" >| < FLOAT: "float" >| < FOR: "for" >| < GOTO: "goto" >| < IF: "if" >| < IMPLEMENTS: "implements" >| < IMPORT: "import" >| < INSTANCEOF: "instanceof" >| < INT: "int" >| < INTERFACE: "interface" >| < LONG: "long" >| < NATIVE: "native" >| < NEW: "new" >| < NULL: "null" >| < PACKAGE: "package">| < PRIVATE: "private" >| < PROTECTED: "protected" >| < PUBLIC: "public" >| < RETURN: "return" >| < SHORT: "short" >| < STATIC: "static" >| < SUPER: "super" >| < SWITCH: "switch" >| < SYNCHRONIZED: "synchronized" >| < THIS: "this" >| < THROW: "throw" >| < THROWS: "throws" >| < TRANSIENT: "transient" >| < TRUE: "true" >| < TRY: "try" >| < VOID: "void" >| < VOLATILE: "volatile" >| < WHILE: "while" >}/* JAVA LITERALS */TOKEN :{ < INTEGER_LITERAL: <DECIMAL_LITERAL> (["l","L"])? | <HEX_LITERAL> (["l","L"])? | <OCTAL_LITERAL> (["l","L"])? >| < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >| < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >| < #OCTAL_LITERAL: "0" (["0"-"7"])* >| < FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])? | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])? | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])? | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"] >| < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >| < CHARACTER_LITERAL: "'" ( (~["'","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) ) "'" >| < STRING_LITERAL: "\"" ( (~["\"","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* "\"" >}/* IDENTIFIERS */TOKEN :{ < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* > { matchedToken.image = JavaCCGlobals.addUnicodeEscapes(matchedToken.image); }| < #LETTER: [ "\u0024", "\u0041"-"\u005a", "\u005f", "\u0061"-"\u007a", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u00ff", "\u0100"-"\u1fff", "\u3040"-"\u318f", "\u3300"-"\u337f", "\u3400"-"\u3d2d", "\u4e00"-"\u9fff", "\uf900"-"\ufaff" ] >| < #DIGIT: [ "\u0030"-"\u0039", "\u0660"-"\u0669", "\u06f0"-"\u06f9", "\u0966"-"\u096f", "\u09e6"-"\u09ef", "\u0a66"-"\u0a6f", "\u0ae6"-"\u0aef", "\u0b66"-"\u0b6f", "\u0be7"-"\u0bef", "\u0c66"-"\u0c6f", "\u0ce6"-"\u0cef", "\u0d66"-"\u0d6f", "\u0e50"-"\u0e59", "\u0ed0"-"\u0ed9", "\u1040"-"\u1049" ] >}/* SEPARATORS */TOKEN :{ < LPAREN: "(" >| < RPAREN: ")" >| < LBRACE: "{" >| < RBRACE: "}" >| < LBRACKET: "[" >| < RBRACKET: "]" >| < SEMICOLON: ";" >| < COMMA: "," >| < DOT: "." >}/* OPERATORS */TOKEN :{ < ASSIGN: "=" >| < GT: ">" >| < LT: "<" >| < BANG: "!" >| < TILDE: "~" >| < HOOK: "?" >| < COLON: ":" >| < EQ: "==" >| < LE: "<=" >| < GE: ">=" >| < NE: "!=" >| < SC_OR: "||" >| < SC_AND: "&&" >| < INCR: "++" >| < DECR: "--" >| < PLUS: "+" >| < MINUS: "-" >| < STAR: "*" >| < SLASH: "/" >| < BIT_AND: "&" >| < BIT_OR: "|" >| < XOR: "^" >| < REM: "%" >// | < LSHIFT: "<<" >// | < RSIGNEDSHIFT: ">>" >// | < RUNSIGNEDSHIFT: ">>>" >| < PLUSASSIGN: "+=" >| < MINUSASSIGN: "-=" >| < STARASSIGN: "*=" >| < SLASHASSIGN: "/=" >| < ANDASSIGN: "&=" >| < ORASSIGN: "|=" >| < XORASSIGN: "^=" >| < REMASSIGN: "%=" >// | < LSHIFTASSIGN: "<<=" >// | < RSIGNEDSHIFTASSIGN: ">>=" >// | < RUNSIGNEDSHIFTASSIGN: ">>>=" >}/************************************************ * THE JAVACC GRAMMAR SPECIFICATION STARTS HERE * ************************************************/void javacc_input() : { String id1, id2; initialize(); }{ javacc_options() "PARSER_BEGIN" "(" id1=identifier() { addcuname(id1); } ")" { processing_cu = true; parser_class_name = id1; } CompilationUnit() { processing_cu = false; } "PARSER_END" "(" id2=identifier() { compare(getToken(0), id1, id2); } ")" ( production() )+ <EOF>}void javacc_options() :{}{ [ "options" "{" ( option_binding() )+ "}" ] { Options.normalize(); }}void option_binding() : { String option_name; int int_val; boolean bool_val; String string_val; Token t = getToken(1); }{ ( <IDENTIFIER> | "LOOKAHEAD" | "IGNORE_CASE" | "static" ) { option_name = t.image; } "=" ( int_val = IntegerLiteral() { Options.setInputFileOption(t, getToken(0), option_name, int_val); } | bool_val = BooleanLiteral() { Options.setInputFileOption(t, getToken(0), option_name, bool_val); } | string_val = StringLiteral() { Options.setInputFileOption(t, getToken(0), option_name, string_val); } ) ";"}void production() :{}{ LOOKAHEAD(1) /* * Since JAVACODE is both a JavaCC reserved word and a Java identifier, * we need to give preference to "javacode_production" over * "bnf_production". */ javacode_production()| LOOKAHEAD(1) /* * Since SKIP, TOKEN, etc. are both JavaCC reserved words and Java * identifiers, we need to give preference to "regular_expression_production" * over "bnf_production". */ regular_expr_production()| LOOKAHEAD(1) /* * Since TOKEN_MGR_DECLS is both a JavaCC reserved word and a Java identifier, * we need to give preference to "token_manager_decls" over * "bnf_production". */ token_manager_decls()| bnf_production()}void javacode_production() : { String lhs; JavaCodeProduction p = new JavaCodeProduction(); Token t = p.firstToken = getToken(1); java.util.Vector excName; p.throws_list = new java.util.Vector(); p.line = t.beginLine; p.column = t.beginColumn; }{ "JAVACODE" ResultType(p.return_type_tokens) p.lhs=identifier() FormalParameters(p.parameter_list_tokens) [ "throws" { excName = new java.util.Vector(); } Name(excName) { p.throws_list.addElement(excName); } ( { excName = new java.util.Vector(); } "," Name(excName) { p.throws_list.addElement(excName); } )* ] Block(p.code_tokens) { p.lastToken = getToken(0); addproduction(p); }}void bnf_production() : { String lhs; BNFProduction p = new BNFProduction(); Container c = new Container(); Token t = p.firstToken = getToken(1); java.util.Vector excName; p.throws_list = new java.util.Vector(); p.line = t.beginLine; p.column = t.beginColumn; jumpPatched = false; }{ ResultType(p.return_type_tokens) p.lhs=identifier() FormalParameters(p.parameter_list_tokens) [ "throws" { excName = new java.util.Vector(); } Name(excName) { p.throws_list.addElement(excName); } ( { excName = new java.util.Vector(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -