From c078b94243cf70e89a12c37af1c085afb5df1788 Mon Sep 17 00:00:00 2001 From: Katja Date: Sun, 14 May 2023 16:56:30 +0200 Subject: [PATCH] Initial commit --- csjavacc.java | 49 + csjavacc/Version.java | 5 + csjavacc/parser/CSJavaCC.jj | 2996 +++++++ csjavacc/parser/CSJavaCCErrors.java | 116 + csjavacc/parser/CSJavaCCGlobals.java | 548 ++ csjavacc/parser/CSJavaCCParser.java | 7661 +++++++++++++++++ csjavacc/parser/CSJavaCCParserConstants.java | 299 + csjavacc/parser/CSJavaCCParserInternals.java | 307 + .../parser/CSJavaCCParserTokenManager.java | 2765 ++++++ csjavacc/parser/CSJavaCharStream.java | 567 ++ csjavacc/parser/CSJavaFiles.java | 2048 +++++ csjavacc/parser/ExpansionTreeWalker.java | 142 + csjavacc/parser/JavaCharStream.java | 589 ++ csjavacc/parser/LexGen.java | 1464 ++++ csjavacc/parser/LookaheadCalc.java | 261 + csjavacc/parser/LookaheadWalk.java | 217 + csjavacc/parser/Main.java | 207 + csjavacc/parser/MetaParseException.java | 26 + csjavacc/parser/NfaState.java | 2967 +++++++ csjavacc/parser/NormalProduction.java | 105 + csjavacc/parser/OneOrMore.java | 38 + csjavacc/parser/Options.java | 518 ++ csjavacc/parser/OtherFilesGen.java | 147 + csjavacc/parser/ParseEngine.java | 1224 +++ csjavacc/parser/ParseException.java | 197 + csjavacc/parser/ParseGen.java | 716 ++ csjavacc/parser/RCharacterList.java | 617 ++ csjavacc/parser/RChoice.java | 153 + csjavacc/parser/RStringLiteral.java | 1306 +++ csjavacc/parser/RegExprSpec.java | 60 + csjavacc/parser/Semanticize.java | 841 ++ csjavacc/parser/Sequence.java | 40 + csjavacc/parser/SingleCharacter.java | 51 + csjavacc/parser/Token.java | 89 + csjavacc/parser/TokenMgrError.java | 138 + csjavacc/struct/Action.java | 40 + csjavacc/struct/BNFProduction.java | 45 + csjavacc/struct/CSCodeProduction.java | 38 + csjavacc/struct/CharacterRange.java | 55 + csjavacc/struct/Choice.java | 39 + csjavacc/struct/Container.java | 33 + csjavacc/struct/Expansion.java | 98 + csjavacc/struct/Lookahead.java | 66 + csjavacc/struct/MatchInfo.java | 34 + csjavacc/struct/Nfa.java | 43 + csjavacc/struct/NonTerminal.java | 55 + csjavacc/struct/REndOfFile.java | 36 + csjavacc/struct/RJustName.java | 44 + csjavacc/struct/ROneOrMore.java | 52 + csjavacc/struct/RRepetitionRange.java | 69 + csjavacc/struct/RSequence.java | 82 + csjavacc/struct/RZeroOrMore.java | 54 + csjavacc/struct/RZeroOrOne.java | 53 + csjavacc/struct/RegularExpression.java | 89 + csjavacc/struct/TokenProduction.java | 94 + csjavacc/struct/TreeWalkerOp.java | 44 + csjavacc/struct/TryBlock.java | 61 + csjavacc/struct/ZeroOrMore.java | 37 + csjavacc/struct/ZeroOrOne.java | 37 + 59 files changed, 30772 insertions(+) create mode 100644 csjavacc.java create mode 100644 csjavacc/Version.java create mode 100644 csjavacc/parser/CSJavaCC.jj create mode 100644 csjavacc/parser/CSJavaCCErrors.java create mode 100644 csjavacc/parser/CSJavaCCGlobals.java create mode 100644 csjavacc/parser/CSJavaCCParser.java create mode 100644 csjavacc/parser/CSJavaCCParserConstants.java create mode 100644 csjavacc/parser/CSJavaCCParserInternals.java create mode 100644 csjavacc/parser/CSJavaCCParserTokenManager.java create mode 100644 csjavacc/parser/CSJavaCharStream.java create mode 100644 csjavacc/parser/CSJavaFiles.java create mode 100644 csjavacc/parser/ExpansionTreeWalker.java create mode 100644 csjavacc/parser/JavaCharStream.java create mode 100644 csjavacc/parser/LexGen.java create mode 100644 csjavacc/parser/LookaheadCalc.java create mode 100644 csjavacc/parser/LookaheadWalk.java create mode 100644 csjavacc/parser/Main.java create mode 100644 csjavacc/parser/MetaParseException.java create mode 100644 csjavacc/parser/NfaState.java create mode 100644 csjavacc/parser/NormalProduction.java create mode 100644 csjavacc/parser/OneOrMore.java create mode 100644 csjavacc/parser/Options.java create mode 100644 csjavacc/parser/OtherFilesGen.java create mode 100644 csjavacc/parser/ParseEngine.java create mode 100644 csjavacc/parser/ParseException.java create mode 100644 csjavacc/parser/ParseGen.java create mode 100644 csjavacc/parser/RCharacterList.java create mode 100644 csjavacc/parser/RChoice.java create mode 100644 csjavacc/parser/RStringLiteral.java create mode 100644 csjavacc/parser/RegExprSpec.java create mode 100644 csjavacc/parser/Semanticize.java create mode 100644 csjavacc/parser/Sequence.java create mode 100644 csjavacc/parser/SingleCharacter.java create mode 100644 csjavacc/parser/Token.java create mode 100644 csjavacc/parser/TokenMgrError.java create mode 100644 csjavacc/struct/Action.java create mode 100644 csjavacc/struct/BNFProduction.java create mode 100644 csjavacc/struct/CSCodeProduction.java create mode 100644 csjavacc/struct/CharacterRange.java create mode 100644 csjavacc/struct/Choice.java create mode 100644 csjavacc/struct/Container.java create mode 100644 csjavacc/struct/Expansion.java create mode 100644 csjavacc/struct/Lookahead.java create mode 100644 csjavacc/struct/MatchInfo.java create mode 100644 csjavacc/struct/Nfa.java create mode 100644 csjavacc/struct/NonTerminal.java create mode 100644 csjavacc/struct/REndOfFile.java create mode 100644 csjavacc/struct/RJustName.java create mode 100644 csjavacc/struct/ROneOrMore.java create mode 100644 csjavacc/struct/RRepetitionRange.java create mode 100644 csjavacc/struct/RSequence.java create mode 100644 csjavacc/struct/RZeroOrMore.java create mode 100644 csjavacc/struct/RZeroOrOne.java create mode 100644 csjavacc/struct/RegularExpression.java create mode 100644 csjavacc/struct/TokenProduction.java create mode 100644 csjavacc/struct/TreeWalkerOp.java create mode 100644 csjavacc/struct/TryBlock.java create mode 100644 csjavacc/struct/ZeroOrMore.java create mode 100644 csjavacc/struct/ZeroOrOne.java diff --git a/csjavacc.java b/csjavacc.java new file mode 100644 index 0000000..0345870 --- /dev/null +++ b/csjavacc.java @@ -0,0 +1,49 @@ +/* + * 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. + */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * List of Major Changes/Problems + * - Obvious grammar changes... to support C# in the parser main + * - Change over output stream related stuff + * - Don't declare exceptions... + * - End of file was handled strangely in JavaCC, relying on an + * exception being thrown. I had to keep track of when the EOF + * was hit, and generate, token manually and close the stream. + * - C# doesn't allow octal numbers: + * @ There were bit masks of 030 for token things that had to + * be changed + * @ String literal images had to use Hex ("\x20") instead of + * octal numbers ("\040") + * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + +/** + * Intermediary between OS script and main program of application. + * Having this intermediary allows the OS scripts to be package name + * independent. + */ +import csjavacc.parser.Main; + +public class csjavacc { + public static void main(String[] args) throws Exception { Main.main(args); } +} diff --git a/csjavacc/Version.java b/csjavacc/Version.java new file mode 100644 index 0000000..af06223 --- /dev/null +++ b/csjavacc/Version.java @@ -0,0 +1,5 @@ +package csjavacc; +public interface Version { + String version = "4.0 (12/04/2018)"; +} + diff --git a/csjavacc/parser/CSJavaCC.jj b/csjavacc/parser/CSJavaCC.jj new file mode 100644 index 0000000..d5327b6 --- /dev/null +++ b/csjavacc/parser/CSJavaCC.jj @@ -0,0 +1,2996 @@ +/* + * This file contains the grammar and actions that describe + * CSJavaCCParser. + */ + +/* TODO: + - Support namespace "::" operator + - Support Annotations +*/ + +options { + JAVA_UNICODE_ESCAPE = true; + STATIC=false; +} + +PARSER_BEGIN(CSJavaCCParser) + +/** + * This file contains the code for CSJavaCCParser generated + * by CSJavaCCParser itself. + */ + +package csjavacc.parser; + +import java.util.Vector; +import csjavacc.struct.*; + +public class CSJavaCCParser extends CSJavaCCParserInternals { + + /** + * 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; + } + + /** + * Class to hold modifiers. + */ + static public final class ModifierSet + { + /* Definitions of the bits in the modifiers field. */ + public static final int PUBLIC = 0x0001; + public static final int PROTECTED = 0x0002; + public static final int PRIVATE = 0x0004; + public static final int ABSTRACT = 0x0008; + public static final int STATIC = 0x0010; + public static final int OVERRIDE = 0x0020; + public static final int PARTIAL = 0x0040; + public static final int NEW = 0x0100; + public static final int INTERNAL = 0x0080; + public static final int READONLY = 0x0200; + public static final int FIXED = 0x0400; + public static final int UNSAFE = 0x0800; + public static final int OUT = 0x1000; + public static final int REF = 0x2000; + + public boolean isPublic(int modifiers){ return (modifiers & PUBLIC) != 0; } + public boolean isProtected(int modifiers){ return (modifiers & PROTECTED) != 0; } + public boolean isPrivate(int modifiers){ return (modifiers & PRIVATE) != 0; } + public boolean isStatic(int modifiers){ return (modifiers & STATIC) != 0; } + public boolean isAbstract(int modifiers){ return (modifiers & ABSTRACT) != 0; } + public boolean isOverride(int modifiers){ return (modifiers & OVERRIDE) != 0; } + + /** Removes the given modifier. */ + static int removeModifier(int modifiers, int mod){ return modifiers & ~mod; } + } +} + +PARSER_END(CSJavaCCParser) + +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 CSJAVACC TOKEN SPECIFICATION STARTS HERE * + **********************************************/ + +/* CSJAVACC RESERVED WORDS: These are the only tokens in CSJavaCC but not in Java */ + +TOKEN : +{ < _OPTIONS: "options" > +| < _LOOKAHEAD: "LOOKAHEAD" > +| < _IGNORE_CASE: "IGNORE_CASE" > +| < _PARSER_BEGIN: "PARSER_BEGIN" > +| < _PARSER_END: "PARSER_END" > +| < _CSCODE: "CSCODE" > +| < _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 C# grammar and must be diff equivalent + * (again with the exceptions above) to it. + */ + +/* WHITE SPACE */ + +SKIP : { " " | "\t" | "\n" | "\r" | "\f" : 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 +| <"#" ( [" ","\t","\f"] )* + ("pragma" | "if" | "else" | "elif" | "endif" | "define" | "undef" | "warning" + | "error" | "line" | "region" | "endregion") > : IN_PRAGMA +} + + +SPECIAL_TOKEN : { : DEFAULT } + + +SPECIAL_TOKEN : { : DEFAULT } + + +SPECIAL_TOKEN : { : DEFAULT } + + +SPECIAL_TOKEN : { : DEFAULT } + + +MORE : { < ~[] > } + +/* C# RESERVED WORDS AND LITERALS */ + +TOKEN : +{ + < ABSTRACT: "abstract" > +//| < ASSERT: "assert" > +| < BOOLEAN: "bool" > +| < BREAK: "break" > +| < BYTE: "byte" > +| < CASE: "case" > +| < CATCH: "catch" > +| < CHAR: "char" > +| < CLASS: "class" > +| < CONST: "const" > +| < CONTINUE: "continue" > +| < _DEFAULT: "default" > +| < DO: "do" > +| < DOUBLE: "double" > +| < ELSE: "else" > +| < ENUM: "enum" > +| < FALSE: "false" > +//| < FINAL: "final" > +| < OVERRIDE: "override" > +//| < FINALLY: "finally" > +| < FLOAT: "single" > +| < FOR: "for" > +| < GOTO: "goto" > +| < IF: "if" > +| < IMPORT: "using" > +| < INT: "int" > +| < INTERFACE: "interface" > +| < LONG: "long" > +| < NEW: "new" > +| < NULL: "null" > +//| < PACKAGE: "package"> +| < NAMESPACE: "namespace"> +| < OUT: "out" > +| < PRIVATE: "private" > +| < PROTECTED: "protected" > +| < PUBLIC: "public" > +| < REF: "ref" > +| < RETURN: "return" > +| < SHORT: "short" > +| < STATIC: "static" > +//| < SUPER: "super" > +| < BASE: "base" > +| < SWITCH: "switch" > +| < THIS: "this" > +| < THROW: "throw" > +| < TRUE: "true" > +| < TRY: "try" > +| < VOID: "void" > +| < WHILE: "while" > +// New Stuff for C# +| < FOREACH: "foreach" > +| < PARTIAL: "partial" > +| < YIELD: "yield" > +| < INTERNAL: "internal" > +| < DELEGATE: "delegate" > +| < READONLY: "readonly" > +| < FIXED: "fixed" > +| < UNSAFE: "unsafe" > +| < VAR: "var" > +} + +/* C# LITERALS */ + +TOKEN : +{ < INTEGER_LITERAL: + (["l","L"])? + | (["l","L"])? + | (["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: + + | > +| < #DECIMAL_FLOATING_POINT_LITERAL: + (["0"-"9"])+ "." (["0"-"9"])* ()? (["f","F","d","D"])? + | "." (["0"-"9"])+ ()? (["f","F","d","D"])? + | (["0"-"9"])+ (["f","F","d","D"])? + | (["0"-"9"])+ ()? ["f","F","d","D"] > +| < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > +| < #HEXADECIMAL_FLOATING_POINT_LITERAL: + "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])+ (".")? (["f","F","d","D"])? + | "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])* "." (["0"-"9","a"-"f","A"-"F"])+ + (["f","F","d","D"])? > +| < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["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"] + ) + ) + )* + "\"" > +} + +/* 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: ">>>=" > +} + +/* >'s need special attention due to generics syntax. */ +TOKEN : +{ < RUNSIGNEDSHIFT: ">>>" > + { + matchedToken.kind = GT; + ((Token.GTToken)matchedToken).realKind = RUNSIGNEDSHIFT; + input_stream.backup(2); + matchedToken.image = ">"; + } +| < RSIGNEDSHIFT: ">>" > + { + matchedToken.kind = GT; + ((Token.GTToken)matchedToken).realKind = RSIGNEDSHIFT; + input_stream.backup(1); + matchedToken.image = ">"; + } +| < GT: ">" > +} + + +/************************************************ + * THE CSJAVACC GRAMMAR SPECIFICATION STARTS HERE * + ************************************************/ + +void csjavacc_input() : + { + String id1, id2; + initialize(); + } +{ + csjavacc_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() )+ + +} + +void csjavacc_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); + } +{ + ( | "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 CSCODE is both a CSJavaCC reserved word and a C# identifier, + * we need to give preference to "cscode_production" over + * "bnf_production". + */ + cscode_production() +| + LOOKAHEAD(1) + /* + * Since SKIP, TOKEN, etc. are both CSJavaCC reserved words and C# + * 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 CSJavaCC reserved word and a C# identifier, + * we need to give preference to "token_manager_decls" over + * "bnf_production". + */ + token_manager_decls() +| + bnf_production() +} + +void cscode_production() : + { + String lhs; + CSCodeProduction p = new CSCodeProduction(); + 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; + } +{ + "CSCODE" + AccessModifier(p) + ResultType(p.return_type_tokens) + p.lhs=identifier() + FormalParameters(p.parameter_list_tokens) + + 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; + } +{ + AccessModifier(p) + ResultType(p.return_type_tokens) + p.lhs=identifier() + FormalParameters(p.parameter_list_tokens) + ":" + Block(p.declaration_tokens) + "{" expansion_choices(c) t="}" + { + p.lastToken = t; + p.jumpPatched = jumpPatched; + production_addexpansion(p, (Expansion)(c.member)); + addproduction(p); + } +} + +void AccessModifier(NormalProduction p) : + { + Token t = null; + } +{ + ( t = "public" | t = "protected" | t = "private" )? + { + if(t != null){ + p.accessMod = t.image; + } + } +} + +void regular_expr_production() : + { + TokenProduction p = new TokenProduction(); + java.util.Vector states; + Token t = p.firstToken = getToken(1); + p.line = t.beginLine; + p.column = t.beginColumn; + } +{ + { + // set p.lexStates assuming there is no state spec. + // and then override if necessary. + p.lexStates = new String[1]; + p.lexStates[0] = "DEFAULT"; + } + [ + LOOKAHEAD(2) "<" "*" ">" + { + p.lexStates = null; + } + | + "<" + { + states = new java.util.Vector(); + } + t= + { + states.addElement(t.image); + } + ( "," t= + { + states.addElement(t.image); + } + )* + ">" + { + p.lexStates = new String[states.size()]; + for (int i = 0; i < states.size(); i++) { + p.lexStates[i] = (String)states.elementAt(i); + } + } + ] + regexpr_kind(p) + { + if (p.kind != TokenProduction.TOKEN && Options.getUserTokenManager()) { + CSJavaCCErrors.warning(getToken(0), "Regular expression is being treated as if it were a TOKEN since option USER_TOKEN_MANAGER has been set to true."); + } + } + [ + "[" t="IGNORE_CASE" "]" + { + p.ignoreCase = true; + if (Options.getUserTokenManager()) { + CSJavaCCErrors.warning(t, "Ignoring \"IGNORE_CASE\" specification since option USER_TOKEN_MANAGER has been set to true."); + } + } + ] + ":" + "{" regexpr_spec(p) ( "|" regexpr_spec(p) )* t="}" + { + p.lastToken = t; + addregexpr(p); + } +} + +void token_manager_decls() : + { + java.util.Vector decls = new java.util.Vector(); + Token t; + } +{ + t="TOKEN_MGR_DECLS" ":" + ClassOrInterfaceBody(false, decls) + { + add_token_manager_decls(t, decls); + } +} + +void regexpr_kind(TokenProduction p) : +{} +{ + "TOKEN" + { + p.kind = TokenProduction.TOKEN; + } +| + "SPECIAL_TOKEN" + { + p.kind = TokenProduction.SPECIAL; + } +| + "SKIP" + { + p.kind = TokenProduction.SKIP; + } +| + "MORE" + { + p.kind = TokenProduction.MORE; + } +} + +void regexpr_spec(TokenProduction p) : + { + Container c = new Container(); + Action act = new Action(); + Token t = null; + RegExprSpec res = new RegExprSpec(); + } +{ + regular_expression(c) + { + res.rexp = (RegularExpression)c.member; + res.rexp.tpContext = p; + } + [ + { + t = getToken(1); + } + Block(act.action_tokens) + { + if (Options.getUserTokenManager()) { + CSJavaCCErrors.warning(t, "Ignoring action in regular expression specification since option USER_TOKEN_MANAGER has been set to true."); + } + if (res.rexp.private_rexp) { + CSJavaCCErrors.parse_error(t, "Actions are not permitted on private (#) regular expressions."); + } + } + ] + [ ":" t= + { + res.nextState = t.image; + if (res.rexp.private_rexp) { + CSJavaCCErrors.parse_error(t, "Lexical state changes are not permitted after private (#) regular expressions."); + } + } + ] + { + res.act = act; + res.nsTok = t; + p.respecs.addElement(res); + } +} + +void expansion_choices(Container c1) : + { + boolean morethanone = false; + Choice ch = null; + Container c2 = new Container(); + } +{ + expansion(c1) + ( "|" expansion(c2) + { + if (morethanone) { + ch.choices.addElement(c2.member); + ((Expansion)c2.member).parent = ch; + } else { + morethanone = true; + ch = new Choice(); + ch.line = ((Expansion)c1.member).line; + ch.column = ((Expansion)c1.member).column; + ch.choices.addElement(c1.member); + ((Expansion)c1.member).parent = ch; + ch.choices.addElement(c2.member); + ((Expansion)c2.member).parent = ch; + } + } + )* + { + if (morethanone) { + c1.member = ch; + } + } +} + +void expansion(Container c1) : + { + Sequence seq = new Sequence(); + Container c2 = new Container(); + Lookahead la = new Lookahead(); + Token t = getToken(1); + seq.line = t.beginLine; + seq.column = t.beginColumn; + la.line = t.beginLine; + la.column = t.beginColumn; + } +{ + { + la.amount = Options.getLookahead(); + la.la_expansion = null; + la.isExplicit = false; + } + ( LOOKAHEAD(1) + t="LOOKAHEAD" "(" la=local_lookahead() ")" + { + if (inLocalLA != 0 && la.amount != 0) { + CSJavaCCErrors.warning(t, "Only semantic lookahead specifications within other lookahead specifications is considered. Syntactic lookahead is ignored."); + } + } + )? + { + seq.units.addElement(la); + } + ( LOOKAHEAD(0, { notTailOfExpansionUnit() } ) + expansion_unit(c2) + { + seq.units.addElement(c2.member); + ((Expansion)c2.member).parent = seq; + ((Expansion)c2.member).ordinal = seq.units.size()-1; + } + )+ + { + if (la.la_expansion == null) { + la.la_expansion = seq; + } + c1.member = seq; + } +} + +Lookahead local_lookahead() : + { + Lookahead la = new Lookahead(); + la.isExplicit = true; + Token t = getToken(1); + la.line = t.beginLine; + la.column = t.beginColumn; + la.la_expansion = null; + Container c = new Container(); + boolean commaAtEnd = false, emptyLA = true; + inLocalLA++; + } +{ + [ + /* + * The lookahead of 1 is to turn off the warning message that lets + * us know that an expansion choice can also start with an integer + * literal because a primary expression can do the same. But we + * know that this is what we want. + */ + LOOKAHEAD(1) + la.amount = IntegerLiteral() + { + emptyLA = false; + } + ] + [ LOOKAHEAD(0, { !emptyLA && (getToken(1).kind != RPAREN) } ) + "," + { + commaAtEnd = true; + } + ] + [ LOOKAHEAD(0, { getToken(1).kind != RPAREN && getToken(1).kind != LBRACE } ) + expansion_choices(c) + { + emptyLA = false; commaAtEnd = false; + la.la_expansion = (Expansion)c.member; + } + ] + [ LOOKAHEAD(0, { !emptyLA && !commaAtEnd && (getToken(1).kind != RPAREN) } ) + "," + { + commaAtEnd = true; + } + ] + [ LOOKAHEAD(0, { emptyLA || commaAtEnd } ) + "{" Expression(la.action_tokens) "}" + { + if (emptyLA) { + la.amount = 0; + } + } + ] + { + inLocalLA--; + return la; + } +} + +void expansion_unit(Container c) : + { + String name; + java.util.Vector lhsTokens = new java.util.Vector(); + NonTerminal nt; + Action act; + Token t; + Lookahead la; + } +{ + LOOKAHEAD(1) + /* + * We give this priority over primary expressions which use LOOKAHEAD as the + * name of its identifier. + */ + t="LOOKAHEAD" "(" la=local_lookahead() ")" + { + // Now set the la_expansion field of la with a dummy + // expansion (we use EOF). + la.la_expansion = new REndOfFile(); + // Create a singleton choice with an empty action. + Choice ch = new Choice(); + ch.line = t.beginLine; ch.column = t.beginColumn; + Sequence seq = new Sequence(); + seq.line = t.beginLine; seq.column = t.beginColumn; + seq.units.addElement(la); + la.parent = seq; la.ordinal = 0; + act = new Action(); + act.line = t.beginLine; act.column = t.beginColumn; + seq.units.addElement(act); + act.parent = seq; act.ordinal = 1; + ch.choices.addElement(seq); + seq.parent = ch; seq.ordinal = 0; + if (la.amount != 0) { + if (la.action_tokens.size() != 0) { + CSJavaCCErrors.warning(t, "Encountered LOOKAHEAD(...) at a non-choice location. Only semantic lookahead will be considered here."); + } else { + CSJavaCCErrors.warning(t, "Encountered LOOKAHEAD(...) at a non-choice location. This will be ignored."); + } + } + c.member = ch; + } +| + { + act = new Action(); + t = getToken(1); + act.line = t.beginLine; + act.column = t.beginColumn; + inAction = true; + } + Block(act.action_tokens) + { + inAction = false; + if (inLocalLA != 0) { + CSJavaCCErrors.warning(t, "Action within lookahead specification will be ignored."); + } + c.member = act; + } +| + t="[" expansion_choices(c) "]" + { + ZeroOrOne exp = new ZeroOrOne(); + exp.line = t.beginLine; + exp.column = t.beginColumn; + exp.expansion = (Expansion)c.member; + ((Expansion)c.member).parent = exp; + c.member = exp; + } +| + { + Container expch = new Container(); + java.util.Vector types = new java.util.Vector(); + java.util.Vector ids = new java.util.Vector(); + java.util.Vector catchblks = new java.util.Vector(); + java.util.Vector finallyblk = null; + java.util.Vector vec = new java.util.Vector(); + Token t0; + } + t0="try" "{" expansion_choices(expch) "}" + ( "catch" "(" Name(vec) t= ")" + { + types.addElement(vec); + ids.addElement(t); + vec = new java.util.Vector(); + inAction = true; + } + Block(vec) + { + inAction = false; + catchblks.addElement(vec); + vec = new java.util.Vector(); + } + )* + { + makeTryBlock(t0, c, expch, types, ids, catchblks, finallyblk); + } +| + LOOKAHEAD( + identifier() + | StringLiteral() + | "<" + | PrimaryExpression() "=" + ) + [ LOOKAHEAD(PrimaryExpression() "=") + { + Token first = getToken(1); + } + PrimaryExpression() + { + Token last = getToken(0); + } + "=" + { + t = first; + while (true) { + lhsTokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + ] + ( + LOOKAHEAD( identifier() "(") + { + nt = new NonTerminal(); + t = getToken(1); + nt.line = t.beginLine; + nt.column = t.beginColumn; + nt.lhsTokens = lhsTokens; + } + name=identifier() Arguments(nt.argument_tokens) + { + nt.name = name; + c.member = nt; + } + | + regular_expression(c) + { + ((RegularExpression)(c.member)).lhsTokens = lhsTokens; + add_inline_regexpr((RegularExpression)(c.member)); + } + [ "." t= { ((RegularExpression)(c.member)).rhsToken = t; } ] + ) +| + t="(" expansion_choices(c) ")" + ( "+" + { + OneOrMore omexp = new OneOrMore(); + omexp.line = t.beginLine; + omexp.column = t.beginColumn; + omexp.expansion = (Expansion)c.member; + ((Expansion)c.member).parent = omexp; + c.member = omexp; + } + | "*" + { + ZeroOrMore zmexp = new ZeroOrMore(); + zmexp.line = t.beginLine; + zmexp.column = t.beginColumn; + zmexp.expansion = (Expansion)c.member; + ((Expansion)c.member).parent = zmexp; + c.member = zmexp; + } + | "?" + { + ZeroOrOne zoexp = new ZeroOrOne(); + zoexp.line = t.beginLine; + zoexp.column = t.beginColumn; + zoexp.expansion = (Expansion)c.member; + ((Expansion)c.member).parent = zoexp; + c.member = zoexp; + } + )? +} + +void regular_expression(Container c) : + { + RStringLiteral strlit; + REndOfFile ef; + RJustName jn; + String image; + boolean private_rexp = false; + Token t = getToken(1); + } +{ + image=StringLiteral() + { + strlit = new RStringLiteral(); + strlit.line = t.beginLine; + strlit.column = t.beginColumn; + strlit.image = image; + c.member = strlit; + } +| + LOOKAHEAD(3) + { + image = ""; + } + < LANGLE: "<" > + [ + [ "#" + { + private_rexp = true; + } + ] + image=identifier() ":" + ] + complex_regular_expression_choices(c) < RANGLE: ">" > + { + RegularExpression re; + if (c.member instanceof RJustName) { + RSequence seq = new RSequence(); + seq.units.addElement(c.member); + re = seq; + } else { + re = (RegularExpression)c.member; + } + re.label = image; + re.private_rexp = private_rexp; + re.line = t.beginLine; + re.column = t.beginColumn; + c.member = re; + } +| + LOOKAHEAD(2) + "<" image=identifier() ">" + { + jn = new RJustName(); + jn.line = t.beginLine; + jn.column = t.beginColumn; + jn.label = image; + c.member = jn; + } +| + "<" "EOF" ">" + { + ef = new REndOfFile(); + ef.line = t.beginLine; + ef.column = t.beginColumn; + ef.ordinal = 0; + c.member = ef; + } +} + +void complex_regular_expression_choices(Container c1) : + { + boolean morethanone = false; + RChoice ch = null; + Container c2 = new Container(); + } +{ + complex_regular_expression(c1) + ( "|" complex_regular_expression(c2) + { + if (morethanone) { + ch.choices.addElement(c2.member); + } else { + morethanone = true; + ch = new RChoice(); + ch.line = ((RegularExpression)c1.member).line; + ch.column = ((RegularExpression)c1.member).column; + ch.choices.addElement(c1.member); + ch.choices.addElement(c2.member); + } + } + )* + { + if (morethanone) { + c1.member = ch; + } + } +} + +void complex_regular_expression(Container c1) : + { + int count = 0; + RSequence seq = null; + Container c2 = new Container(); + } +{ + ( complex_regular_expression_unit(c2) + { + count++; + if (count == 1) { + c1.member = c2.member; // if count does not go beyond 1, we are done. + } else if (count == 2) { // more than 1, so create a sequence. + seq = new RSequence(); + seq.line = ((RegularExpression)c1.member).line; + seq.column = ((RegularExpression)c1.member).column; + seq.units.addElement(c1.member); + seq.units.addElement(c2.member); + } else { + seq.units.addElement(c2.member); + } + } + )+ + { + if (count > 1) { + c1.member = seq; + } + } +} + +void complex_regular_expression_unit(Container c) : + { + String image; + RStringLiteral strlit; + RJustName jn; + Token t = getToken(1); + int r1 = 0, r2 = -1; + boolean hasMax = false; + } +{ + image=StringLiteral() + { + strlit = new RStringLiteral(); + strlit.line = t.beginLine; + strlit.column = t.beginColumn; + strlit.image = image; + c.member = strlit; + } +| + "<" image=identifier() ">" + { + jn = new RJustName(); + jn.line = t.beginLine; + jn.column = t.beginColumn; + jn.label = image; + c.member = jn; + } +| + character_list(c) +| + "(" complex_regular_expression_choices(c) ")" + ( "+" + { + ROneOrMore omrexp = new ROneOrMore(); + omrexp.line = t.beginLine; + omrexp.column = t.beginColumn; + omrexp.regexpr = (RegularExpression)c.member; + c.member = omrexp; + } + | "*" + { + RZeroOrMore zmrexp = new RZeroOrMore(); + zmrexp.line = t.beginLine; + zmrexp.column = t.beginColumn; + zmrexp.regexpr = (RegularExpression)c.member; + c.member = zmrexp; + } + | "?" + { + RZeroOrOne zorexp = new RZeroOrOne(); + zorexp.line = t.beginLine; + zorexp.column = t.beginColumn; + zorexp.regexpr = (RegularExpression)c.member; + c.member = zorexp; + } + | "{" r1 = IntegerLiteral() + [ "," { hasMax = true; } [ r2 = IntegerLiteral() ] ] + "}" + { + RRepetitionRange rrrexp = new RRepetitionRange(); + rrrexp.line = t.beginLine; + rrrexp.column = t.beginColumn; + rrrexp.min = r1; + rrrexp.max = r2; + rrrexp.hasMax = hasMax; + rrrexp.regexpr = (RegularExpression)c.member; + c.member = rrrexp; + } + )? +} + +void character_list(Container c1) : + { + RCharacterList chlist = new RCharacterList(); + Token t = getToken(1); + chlist.line = t.beginLine; + chlist.column = t.beginColumn; + Container c2 = new Container(); + } +{ + ["~" + { + chlist.negated_list = true; + } + ] + "[" [ character_descriptor(c2) + { + chlist.descriptors.addElement(c2.member); + } + ( "," character_descriptor(c2) + { + chlist.descriptors.addElement(c2.member); + } + )* + ] + "]" + { + c1.member = chlist; + } +} + +void character_descriptor(Container c) : + { + char c1, c2 = ' '; + boolean isrange = false; + String imageL, imageR; + Token t = getToken(1); + } +{ + imageL=StringLiteral() + { + c1 = character_descriptor_assign(getToken(0), imageL); + } + [ "-" imageR=StringLiteral() + { + isrange = true; + c2 = character_descriptor_assign(getToken(0), imageR, imageL); + } + ] + { + if (isrange) { + CharacterRange cr = new CharacterRange(); + cr.line = t.beginLine; + cr.column = t.beginColumn; + cr.left = c1; + cr.right = c2; + c.member = cr; + } else { + SingleCharacter sc = new SingleCharacter(); + sc.line = t.beginLine; + sc.column = t.beginColumn; + sc.ch = c1; + c.member = sc; + } + } +} + +String identifier() : + { + Token t; + } +{ + t= + { + return t.image; + } +} + +/********************************************** + * THE C# GRAMMAR SPECIFICATION STARTS HERE * + **********************************************/ + +/* + * The C# grammar is modified to use sequences of tokens + * for the missing tokens - those that include "<<" and ">>". + */ + +/* + * The following production defines C# identifiers - it + * includes the reserved words of CSJavaCC also. + */ + +Token CSIdentifier() : +{} +{ +( + +| "options" +| "LOOKAHEAD" +| "IGNORE_CASE" +| "PARSER_BEGIN" +| "PARSER_END" +| "CSCODE" +| "TOKEN" +| "SPECIAL_TOKEN" +| "MORE" +| "SKIP" +| "TOKEN_MGR_DECLS" +| "EOF" +) + { + Token retval = getToken(0); + retval.kind = IDENTIFIER; + return retval; + } +} + +/* + * The productions for the missing code follows. Obviously + * these productions accept more than what is legal in Java, + * but that is OK for our purposes. + */ + +void ShiftOps() : +{} +{ + "<" "<" +| + ">" ">" [ ">" ] +} + +void OtherAssignmentOps() : +{} +{ + "<" "<=" +| + ">" [ ">" ] ">=" +} + +/* + * Program structuring syntax follows. + */ + +void CompilationUnit() : +/* + * The is deleted since the compilation unit is embedded + * within grammar code. + */ + { + set_initial_cu_token(getToken(1)); + System.out.println(getToken(1).image); + } +{ + [ LOOKAHEAD( "namespace" ) NamespaceDeclaration() ] + ( ImportDeclaration() )* + ( TypeDeclaration() )* + { + insertionpointerrors(getToken(1)); + } +} + +void NamespaceDeclaration() : +{} +{ + Modifiers() "namespace" Name(new Vector()) ";" +} + +void ImportDeclaration() : +{} +{ + "using" (LOOKAHEAD(CSIdentifier() "=") + NameType(new java.util.Vector()) | + Name(new java.util.Vector()) + ) ";" +} + +/* + * Modifiers. We match all modifiers in a single rule to reduce the chances of + * syntax errors for simple modifier mistakes. It will also enable us to give + * better error messages. + */ + +int Modifiers(): +{ + int modifiers = 0; +} +{ + ( + LOOKAHEAD(2) + ( "public" { modifiers |= ModifierSet.PUBLIC; } + | "static" { modifiers |= ModifierSet.STATIC; } + | "protected" { modifiers |= ModifierSet.PROTECTED; } + | "private" { modifiers |= ModifierSet.PRIVATE; } + | "override" { modifiers |= ModifierSet.OVERRIDE; } + | "partial" { modifiers |= ModifierSet.PARTIAL; } + | "abstract" { modifiers |= ModifierSet.ABSTRACT; } + | "new" { modifiers |= ModifierSet.NEW; } + | "out" { modifiers |= ModifierSet.OUT; } + | "ref" { modifiers |= ModifierSet.REF; } + | "internal" { modifiers |= ModifierSet.INTERNAL; } + | "readonly" { modifiers |= ModifierSet.READONLY; } + | "fixed" { modifiers |= ModifierSet.FIXED; } + | "unsafe" { modifiers |= ModifierSet.UNSAFE; } + // | "synchronized" { modifiers |= ModifierSet.SYNCHRONIZED; } + // | Annotation() + ) + )* + + { + return modifiers; + } +} + +/* + * Declaration syntax follows. + */ +void TypeDeclaration(): +{ + int modifiers; +} +{ + ";" +| + modifiers = Modifiers() + ( ClassOrInterfaceDeclaration(modifiers, new Vector()) + // | EnumDeclaration(modifiers) + // | AnnotationTypeDeclaration(modifiers) + ) +} + + +void ClassOrInterfaceDeclaration(int modifiers, Vector tokens): +{ + boolean isInterface = false; + class_nesting++; + Token t; + boolean is_parser_class = false; +} +{ + ( "class" | "interface" { isInterface = true; } ) + t= + [ TypeParameters() ] + [ ExtendsList(isInterface) ] + { + if (t.image.equals(parser_class_name) && class_nesting == 1 && processing_cu) { + is_parser_class = true; + setinsertionpoint(getToken(1), 1); + } + } + ClassOrInterfaceBody(isInterface, new Vector()) + { + if (is_parser_class) { + setinsertionpoint(getToken(0), 2); + } + class_nesting--; + } +} + +void DelegateDeclaration(int modifiers): {} +{ + "delegate" ResultType(new Vector()) [ TypeParameters() ] FormalParameters(new Vector()) ";" +} + + +void ExtendsList(boolean isInterface): +{ + boolean extendsMoreThanOne = false; +} +{ + ":" ClassOrInterfaceType() + ( "," ClassOrInterfaceType())* +} + +void TypeParameters(): +{} +{ "<" TypeParameter() ( "," TypeParameter() )* ">" } + +void TypeParameter(): +{} +{ } + +void ClassOrInterfaceBody(boolean isInterface, Vector tokens): + { + Token first, last; + } +{ + "{" + { + first = getToken(1); + } + ( ClassOrInterfaceBodyDeclaration(isInterface) )* + { + last = getToken(0); + } + "}" + { + if (last.next != first) { // i.e., this is not an empty sequence + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + } +} + +void ClassOrInterfaceBodyDeclaration(boolean isInterface): +{ + boolean isNestedInterface = false; + int modifiers; +} +{ + modifiers = Modifiers() // Just get all the modifiers out of the way. If you want to do + // more checks, pass the modifiers down to the member + ( + ClassOrInterfaceDeclaration(modifiers, new Vector()) + | DelegateDeclaration(modifiers) + | LOOKAHEAD( [ TypeParameters() ] "(" ) + ConstructorDeclaration() + | LOOKAHEAD( Type() VariableDeclaratorId() ( "[" "]" )* ( "," | "=" | ";" | "{" ) ) + FieldDeclaration(modifiers) + | MethodDeclaration(modifiers) + ) +| + ";" +} + +void FieldDeclaration(int modifiers): +{} +{ + // Modifiers are already matched in the caller + Type() VariableDeclaratorId() ( ( [ "=" VariableInitializer() ] ( "," VariableDeclarator() )* ";" ) + | ( "{" PropertyBody() "}" ) ) +} + +void VariableDeclarator(): +{} +{ + VariableDeclaratorId() [ "=" VariableInitializer() ] +} + +void PropertyBody(): +{} +{ + ( ("get" Statement()) [ ("set" Statement()) ] ) + | ( ("set" Statement()) [ ("get" Statement()) ] ) +} + +void VariableDeclaratorId(): +{} +{ + ( "." )* +} + +void VariableInitializer(): +{} +{ + ArrayInitializer() +| + Expression(new Vector()) +} + +void ArrayInitializer(): +{} +{ "{" [ VariableInitializer() ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}" } + +void MethodDeclaration(int modifiers): +{} +{ + // Modifiers already matched in the caller! + ResultType(new Vector()) + MethodDeclarator() + ( Block(new Vector()) | ";" ) +} + +void MethodDeclarator(): +{} +// Useless ("[" "]")* removed +{ ( "." )* [ TypeParameters() ] FormalParameters(new Vector()) } + +void FormalParameters(Vector tokens) : +/* + * Parsing this fills "tokens" with all tokens of the formal + * parameters excluding the parentheses at each end. + */ + { + Token first, last; + } +{ + "(" + { + first = getToken(1); + } + [ FormalParameter() ( "," FormalParameter() )* ] + { + last = getToken(0); + } + ")" + { + if (last.next != first) { // i.e., this is not an empty sequence + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + } +} + +void FormalParameter(): +{} +{ Modifiers() Type() [ "..." ] VariableDeclaratorId() } + +void ConstructorDeclaration(): +{} +{ + [ TypeParameters() ] + // Modifiers matched in the caller + FormalParameters(new Vector()) //[ ExplicitConstructorInvocation() ] + "{" ( BlockStatement() )* "}" +} + +/* + * Type, name and expression syntax follows. + */ + +void Type(): +{} +{ ( LOOKAHEAD(2) ReferenceType() + | PrimitiveType() ) + // Nullable Types + [ "?" ] +} + +void ReferenceType(): +{} +{ + PrimitiveType() ( LOOKAHEAD(2) "[" "]" )+ + | ( ClassOrInterfaceType() ) ( LOOKAHEAD(2) "[" "]" )* +} + +void ClassOrInterfaceType(): +{} +{ + [ LOOKAHEAD(2) TypeArguments() ] + ( LOOKAHEAD(2) "." [ LOOKAHEAD(2) TypeArguments() ] )* +} + +void TypeArguments(): +{} +{ "<" TypeArgument() ( "," TypeArgument() )* ">" } + +void TypeArgument(): +{} +{ LOOKAHEAD(2) PrimitiveType() + | ReferenceType() +} + +void PrimitiveType(): +{} +{ "bool" +| "char" +| "byte" +| "short" +| "int" +| "long" +| "single" +| "double" +| "var" +} + + +void ResultType(java.util.Vector tokens) : + { + Token first = getToken(1); + } +{ +( "void" +| Type() +) + { + Token last = getToken(0); + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } +} + +void NameType(java.util.Vector tokens) : + { + Token first = getToken(1); + } +{ + CSIdentifier() "=" { + Token last = getToken(0); + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + Name(tokens) +} + +void Name(java.util.Vector tokens) : +/* + * A lookahead of 2 is required below since "Name" can be followed + * by a ".*" when used in the context of an "ImportDeclaration". + */ + { + Token first = getToken(1); + } +{ + CSIdentifier() + ( LOOKAHEAD(2) "." CSIdentifier() + )* + { + Token last = getToken(0); + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } +} + + +void NameList(): +{} +{ Name(new Vector()) ( "," Name(new Vector()) )* } + + +/* + * Expression syntax follows. + */ + +void Expression(java.util.Vector tokens) : +/* + * This expansion has been written this way instead of: + * Assignment() | ConditionalExpression() + * for performance reasons. + * However, it is a weakening of the grammar for it allows the LHS of + * assignments to be any conditional expression whereas it can only be + * a primary expression. Consider adding a semantic predicate to work + * around this. + */ + { + Token first = getToken(1); + } +{ + + AnonymousDelegate() + | ConditionalExpression() + [ + LOOKAHEAD(2) + AssignmentOperator() Expression(new java.util.Vector()) + ] { + Token last = getToken(0); + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } +} + +void AnonymousDelegate():{} +{ + "delegate" FormalParameters(new Vector()) Block(new Vector()) +} + +void AssignmentOperator(): +{} +{ + "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | ">>>=" | "&=" | "^=" | "|=" +} + +void ConditionalExpression(): +{} +{ + ConditionalOrExpression() [ "?" Expression(new Vector()) ":" Expression(new Vector()) ] +} + +void ConditionalOrExpression(): +{} +{ + ConditionalAndExpression() ( "||" ConditionalAndExpression() )* +} + +void ConditionalAndExpression(): +{} +{ + InclusiveOrExpression() ( "&&" InclusiveOrExpression() )* +} + +void InclusiveOrExpression(): +{} +{ + ExclusiveOrExpression() ( "|" ExclusiveOrExpression() )* +} + +void ExclusiveOrExpression(): +{} +{ + AndExpression() ( "^" AndExpression() )* +} + +void AndExpression(): +{} +{ + EqualityExpression() ( "&" EqualityExpression() )* +} + +void EqualityExpression(): +{} +{ + InstanceOfExpression() ( ( "==" | "!=" ) InstanceOfExpression() )* +} + +void InstanceOfExpression(): +{} +{ + RelationalExpression() [ "is" Type() ] +} + +void RelationalExpression(): +{} +{ + ShiftExpression() ( ( "<" | ">" | "<=" | ">=" ) ShiftExpression() )* +} + +void ShiftExpression(): +{} +{ + AdditiveExpression() ( ( "<<" | RSIGNEDSHIFT() | RUNSIGNEDSHIFT() ) AdditiveExpression() )* +} + +void AdditiveExpression(): +{} +{ + MultiplicativeExpression() ( ( "+" | "-" ) MultiplicativeExpression() )* +} + +void MultiplicativeExpression(): +{} +{ + UnaryExpression() ( ( "*" | "/" | "%" ) UnaryExpression() )* +} + +void UnaryExpression(): +{} +{ + ( "+" | "-" ) UnaryExpression() +| + PreIncrementExpression() +| + PreDecrementExpression() +| + UnaryExpressionNotPlusMinus() +} + +void PreIncrementExpression(): +{} +{ + "++" PrimaryExpression() +} + +void PreDecrementExpression(): +{} +{ + "--" PrimaryExpression() +} + +void UnaryExpressionNotPlusMinus(): +{} +{ + ( "~" | "!" ) UnaryExpression() +| + LOOKAHEAD( CastLookahead() ) + CastExpression() +| + PostfixExpression() +} + +// This production is to determine lookahead only. The LOOKAHEAD specifications +// below are not used, but they are there just to indicate that we know about +// this. +void CastLookahead(): +{} +{ + LOOKAHEAD(2) + "(" PrimitiveType() +| LOOKAHEAD("(" Type() "[") + "(" Type() "[" "]" +| "(" Type() ")" ( "~" | "!" | "(" | | "this" | "base" | "new" | Literal() ) +} + +void PostfixExpression(): +{} +{ + PrimaryExpression() [ "++" | "--" ] +} + +void CastExpression(): +{} +{ + LOOKAHEAD("(" PrimitiveType()) + "(" Type() ")" UnaryExpression() +| "(" Type() ")" UnaryExpressionNotPlusMinus() +} + +void PrimaryExpression(): +{} +{ PrimaryPrefix() ( LOOKAHEAD(2) PrimarySuffix() )* } + +void MemberSelector(): +{} +{ "." TypeArguments() } + +void PrimaryPrefix(): +{} +{ Literal() +| "this" +| "base" "." +| "(" Expression(new Vector()) ")" +| AllocationExpression() +| LOOKAHEAD( ResultType(new Vector()) "." "class" ) + ResultType(new Vector()) "." "class" +| Name(new Vector()) +} + +void PrimarySuffix(): +{} +{ LOOKAHEAD(2) "." "this" +| LOOKAHEAD(2) "." AllocationExpression() +| LOOKAHEAD(3) MemberSelector() +| "[" Expression(new Vector()) "]" +| "." +| Arguments(new Vector()) +} + +void Literal(): +{} +{ +| +| +| +| BooleanLiteral() +| NullLiteral() +} + +int IntegerLiteral() : +{} +{ + { + try { + return Integer.parseInt(token.image); + } catch (NumberFormatException e) { + throw new Error(); + } + } +} + +boolean BooleanLiteral() : +{} +{ "true" { return true; } +| "false" { return false; } +} + +String StringLiteral() : + { + Token t; + } +{ + t= + { + return remove_escapes_and_quotes(t, t.image); + } +} + +void NullLiteral() : +{} +{ + "null" +} + +void Arguments(java.util.Vector tokens) : +/* + * Parsing this fills "tokens" with all tokens of the arguments + * excluding the parentheses at each end. + */ + { + Token first, last; + } +{ + "(" + { + first = getToken(1); + } + [ ArgumentList() ] + { + last = getToken(0); + } + ")" + { + if (last.next != first) { // i.e., this is not an empty sequence + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + } +} + +void ArgumentList(): +{} +{ + Expression(new Vector()) ( "," Expression(new Vector()) )* +} + +void AllocationExpression(): +{} +{ + LOOKAHEAD(2) + "new" PrimitiveType() ArrayDimsAndInits() +| + "new" ClassOrInterfaceType() [ TypeArguments() ] + ( + ArrayDimsAndInits() + | + Arguments(new Vector()) [ ClassOrInterfaceBody(false, new Vector()) ] + ) +} + +/* + * The third LOOKAHEAD specification below is to parse to PrimarySuffix + * if there is an expression between the "[...]". + */ +void ArrayDimsAndInits(): +{} +{ + LOOKAHEAD(2) + ( LOOKAHEAD(2) "[" Expression(new Vector()) "]" )+ ( LOOKAHEAD(2) "[" "]" )* +| + ( "[" "]" )+ ArrayInitializer() +} + + +/* + * Statement syntax follows. + */ + +void Statement(): +{} +{ + LOOKAHEAD(2) + LabeledStatement() +//| AssertStatement() +| Block(new Vector()) +| UnsafeStatment() +| EmptyStatement() +| StatementExpression() ";" +| SwitchStatement() +| IfStatement() +| WhileStatement() +| UsingStatement() +| LockStatement() +| DoStatement() +| ForStatement() +| ForEachStatement() +| BreakStatement() +| ContinueStatement() +| [ ] ReturnStatement() +| ThrowStatement() +| TryStatement() +} + +/*void AssertStatement(): +{} +{ "assert" Expression(new Vector()) [ ":" Expression(new Vector()) ] ";" } +*/ + +void LabeledStatement(): +{} +{ + ":" Statement() +} + +// Unsafe Block +void UnsafeStatment():{} +{ + "unsafe" Block(new Vector()) +} + +void Block(java.util.Vector tokens) : +/* + * Parsing this fills "tokens" with all tokens of the block + * excluding the braces at each end. + */ + { + Token first, last; + } +{ + "{" + { + first = getToken(1); + } + ( BlockStatement() )* + { + last = getToken(0); + } + "}" + { + if (last.next != first) { // i.e., this is not an empty sequence + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + } +} + +void BlockStatement(): +{} +{ + LOOKAHEAD( Modifiers() Type() ) + LocalVariableDeclaration() ";" +| Statement() +| ClassOrInterfaceDeclaration(0, new Vector()) +} + +void LocalVariableDeclaration(): +{} +{ Modifiers() Type() VariableDeclarator() ( "," VariableDeclarator() )* } + +void EmptyStatement(): +{} +{ ";" } + +void StatementExpression(): +/* + * The last expansion of this production accepts more than the legal + * Java expansions for StatementExpression. This expansion does not + * use PostfixExpression for performance reasons. + */ +{} +{ PreIncrementExpression() +| PreDecrementExpression() +| PrimaryExpression() + [ "++" + | "--" + | AssignmentOperator() Expression(new Vector()) + ] +} + +void SwitchStatement(): +{} +{ "switch" "(" Expression(new Vector()) ")" "{" + ( SwitchLabel() ( BlockStatement() )* )* + "}" +} + +void SwitchLabel(): +{} +{ "case" Expression(new Vector()) ":" +| "default" ":" +} + +void IfStatement(): +/* + * The disambiguating algorithm of JavaCC automatically binds dangling + * else's to the innermost if statement. The LOOKAHEAD specification + * is to tell CSJavaCC that we know what we are doing. + */ +{} +{ "if" "(" Expression(new Vector()) ")" Statement() [ LOOKAHEAD(1) "else" Statement() ] } + +void WhileStatement(): +{} +{ "while" "(" Expression(new Vector()) ")" Statement() } + +void UsingStatement(): +{} +{ "using" "(" Expression(new Vector()) ")" Statement() } + +void LockStatement(): +{} +{ "lock" "(" Expression(new Vector()) ")" Statement() } + + +void DoStatement(): +{} +{ "do" Statement() "while" "(" Expression(new Vector()) ")" ";" } + +void ForStatement(): +{} +{ "for" "(" + ( + LOOKAHEAD(Modifiers() Type() ":") + Modifiers() Type() ":" Expression(new Vector()) + | [ ForInit() ] ";" [ Expression(new Vector()) ] ";" [ ForUpdate() ] + ) + ")" Statement() +} + +void ForInit(): +{} +{ LOOKAHEAD( Modifiers() Type() ) + LocalVariableDeclaration() +| StatementExpressionList() +} + +void ForEachStatement(): +{} +{ "foreach" "(" + ( + Modifiers() Type() "in" Expression(new Vector()) + ) + ")" Statement() +} + + +void StatementExpressionList():{} +{ StatementExpression() ( "," StatementExpression() )* } + +void ForUpdate():{} +{ StatementExpressionList() } + +void BreakStatement():{} +{ "break" [ ] ";" } + +void ContinueStatement():{} +{ "continue" [ ] ";" } + +void ReturnStatement() : + { + Token t; + } +{ + // Iterator Yield + //[ "yield" ] + t="return" + { + // Add if statement to prevent subsequent code generated + // from being dead code. + if (inAction) { + t.image = "{if (true) return"; + jumpPatched = true; + } + } + [ + Expression(new java.util.Vector()) + ] + t=";" + { + // Add closing brace for above if statement. + if (inAction) { + t.image = ";}"; + } + } +} + +void ThrowStatement() : + { + Token t; + } +{ + t="throw" + { + // Add if statement to prevent subsequent code generated + // from being dead code. + if (inAction) { + t.image = "{if (true) throw"; + jumpPatched = true; + } + } + Expression(new java.util.Vector()) + t=";" + { + // Add closing brace for above if statement. + if (inAction) { + t.image = ";}"; + } + } +} + +void TryStatement(): +/* + * Semantic check required here to make sure that at least one + * finally/catch is present. + */ +{} +{ + "try" Block(new Vector()) + ( "catch" "(" FormalParameter() ")" Block(new Vector()) )* + [ "finally" Block(new Vector()) ] +} + +/* We use productions to match >>>, >> and > so that we can keep the + * type declaration syntax with generics clean + */ + +void RUNSIGNEDSHIFT(): +{} +{ + ( LOOKAHEAD({ getToken(1).kind == GT && + ((Token.GTToken)getToken(1)).realKind == RUNSIGNEDSHIFT} ) + ">" ">" ">" + ) +} + +void RSIGNEDSHIFT(): +{} +{ + ( LOOKAHEAD({ getToken(1).kind == GT && + ((Token.GTToken)getToken(1)).realKind == RSIGNEDSHIFT} ) + ">" ">" + ) +} + +/* IDENTIFIERS */ + +TOKEN : +{ < IDENTIFIER: ()* > +| < #LETTER: + [ // all chars for which Character.isIdentifierStart is true + //"$", + "@", + "A"-"Z", + "_", + "a"-"z", + "\u00a2"-"\u00a5", + "\u00aa", + "\u00b5", + "\u00ba", + "\u00c0"-"\u00d6", + "\u00d8"-"\u00f6", + "\u00f8"-"\u021f", + "\u0222"-"\u0233", + "\u0250"-"\u02ad", + "\u02b0"-"\u02b8", + "\u02bb"-"\u02c1", + "\u02d0"-"\u02d1", + "\u02e0"-"\u02e4", + "\u02ee", + "\u037a", + "\u0386", + "\u0388"-"\u038a", + "\u038c", + "\u038e"-"\u03a1", + "\u03a3"-"\u03ce", + "\u03d0"-"\u03d7", + "\u03da"-"\u03f3", + "\u0400"-"\u0481", + "\u048c"-"\u04c4", + "\u04c7"-"\u04c8", + "\u04cb"-"\u04cc", + "\u04d0"-"\u04f5", + "\u04f8"-"\u04f9", + "\u0531"-"\u0556", + "\u0559", + "\u0561"-"\u0587", + "\u05d0"-"\u05ea", + "\u05f0"-"\u05f2", + "\u0621"-"\u063a", + "\u0640"-"\u064a", + "\u0671"-"\u06d3", + "\u06d5", + "\u06e5"-"\u06e6", + "\u06fa"-"\u06fc", + "\u0710", + "\u0712"-"\u072c", + "\u0780"-"\u07a5", + "\u0905"-"\u0939", + "\u093d", + "\u0950", + "\u0958"-"\u0961", + "\u0985"-"\u098c", + "\u098f"-"\u0990", + "\u0993"-"\u09a8", + "\u09aa"-"\u09b0", + "\u09b2", + "\u09b6"-"\u09b9", + "\u09dc"-"\u09dd", + "\u09df"-"\u09e1", + "\u09f0"-"\u09f3", + "\u0a05"-"\u0a0a", + "\u0a0f"-"\u0a10", + "\u0a13"-"\u0a28", + "\u0a2a"-"\u0a30", + "\u0a32"-"\u0a33", + "\u0a35"-"\u0a36", + "\u0a38"-"\u0a39", + "\u0a59"-"\u0a5c", + "\u0a5e", + "\u0a72"-"\u0a74", + "\u0a85"-"\u0a8b", + "\u0a8d", + "\u0a8f"-"\u0a91", + "\u0a93"-"\u0aa8", + "\u0aaa"-"\u0ab0", + "\u0ab2"-"\u0ab3", + "\u0ab5"-"\u0ab9", + "\u0abd", + "\u0ad0", + "\u0ae0", + "\u0b05"-"\u0b0c", + "\u0b0f"-"\u0b10", + "\u0b13"-"\u0b28", + "\u0b2a"-"\u0b30", + "\u0b32"-"\u0b33", + "\u0b36"-"\u0b39", + "\u0b3d", + "\u0b5c"-"\u0b5d", + "\u0b5f"-"\u0b61", + "\u0b85"-"\u0b8a", + "\u0b8e"-"\u0b90", + "\u0b92"-"\u0b95", + "\u0b99"-"\u0b9a", + "\u0b9c", + "\u0b9e"-"\u0b9f", + "\u0ba3"-"\u0ba4", + "\u0ba8"-"\u0baa", + "\u0bae"-"\u0bb5", + "\u0bb7"-"\u0bb9", + "\u0c05"-"\u0c0c", + "\u0c0e"-"\u0c10", + "\u0c12"-"\u0c28", + "\u0c2a"-"\u0c33", + "\u0c35"-"\u0c39", + "\u0c60"-"\u0c61", + "\u0c85"-"\u0c8c", + "\u0c8e"-"\u0c90", + "\u0c92"-"\u0ca8", + "\u0caa"-"\u0cb3", + "\u0cb5"-"\u0cb9", + "\u0cde", + "\u0ce0"-"\u0ce1", + "\u0d05"-"\u0d0c", + "\u0d0e"-"\u0d10", + "\u0d12"-"\u0d28", + "\u0d2a"-"\u0d39", + "\u0d60"-"\u0d61", + "\u0d85"-"\u0d96", + "\u0d9a"-"\u0db1", + "\u0db3"-"\u0dbb", + "\u0dbd", + "\u0dc0"-"\u0dc6", + "\u0e01"-"\u0e30", + "\u0e32"-"\u0e33", + "\u0e3f"-"\u0e46", + "\u0e81"-"\u0e82", + "\u0e84", + "\u0e87"-"\u0e88", + "\u0e8a", + "\u0e8d", + "\u0e94"-"\u0e97", + "\u0e99"-"\u0e9f", + "\u0ea1"-"\u0ea3", + "\u0ea5", + "\u0ea7", + "\u0eaa"-"\u0eab", + "\u0ead"-"\u0eb0", + "\u0eb2"-"\u0eb3", + "\u0ebd", + "\u0ec0"-"\u0ec4", + "\u0ec6", + "\u0edc"-"\u0edd", + "\u0f00", + "\u0f40"-"\u0f47", + "\u0f49"-"\u0f6a", + "\u0f88"-"\u0f8b", + "\u1000"-"\u1021", + "\u1023"-"\u1027", + "\u1029"-"\u102a", + "\u1050"-"\u1055", + "\u10a0"-"\u10c5", + "\u10d0"-"\u10f6", + "\u1100"-"\u1159", + "\u115f"-"\u11a2", + "\u11a8"-"\u11f9", + "\u1200"-"\u1206", + "\u1208"-"\u1246", + "\u1248", + "\u124a"-"\u124d", + "\u1250"-"\u1256", + "\u1258", + "\u125a"-"\u125d", + "\u1260"-"\u1286", + "\u1288", + "\u128a"-"\u128d", + "\u1290"-"\u12ae", + "\u12b0", + "\u12b2"-"\u12b5", + "\u12b8"-"\u12be", + "\u12c0", + "\u12c2"-"\u12c5", + "\u12c8"-"\u12ce", + "\u12d0"-"\u12d6", + "\u12d8"-"\u12ee", + "\u12f0"-"\u130e", + "\u1310", + "\u1312"-"\u1315", + "\u1318"-"\u131e", + "\u1320"-"\u1346", + "\u1348"-"\u135a", + "\u13a0"-"\u13f4", + "\u1401"-"\u166c", + "\u166f"-"\u1676", + "\u1681"-"\u169a", + "\u16a0"-"\u16ea", + "\u1780"-"\u17b3", + "\u17db", + "\u1820"-"\u1877", + "\u1880"-"\u18a8", + "\u1e00"-"\u1e9b", + "\u1ea0"-"\u1ef9", + "\u1f00"-"\u1f15", + "\u1f18"-"\u1f1d", + "\u1f20"-"\u1f45", + "\u1f48"-"\u1f4d", + "\u1f50"-"\u1f57", + "\u1f59", + "\u1f5b", + "\u1f5d", + "\u1f5f"-"\u1f7d", + "\u1f80"-"\u1fb4", + "\u1fb6"-"\u1fbc", + "\u1fbe", + "\u1fc2"-"\u1fc4", + "\u1fc6"-"\u1fcc", + "\u1fd0"-"\u1fd3", + "\u1fd6"-"\u1fdb", + "\u1fe0"-"\u1fec", + "\u1ff2"-"\u1ff4", + "\u1ff6"-"\u1ffc", + "\u203f"-"\u2040", + "\u207f", + "\u20a0"-"\u20af", + "\u2102", + "\u2107", + "\u210a"-"\u2113", + "\u2115", + "\u2119"-"\u211d", + "\u2124", + "\u2126", + "\u2128", + "\u212a"-"\u212d", + "\u212f"-"\u2131", + "\u2133"-"\u2139", + "\u2160"-"\u2183", + "\u3005"-"\u3007", + "\u3021"-"\u3029", + "\u3031"-"\u3035", + "\u3038"-"\u303a", + "\u3041"-"\u3094", + "\u309d"-"\u309e", + "\u30a1"-"\u30fe", + "\u3105"-"\u312c", + "\u3131"-"\u318e", + "\u31a0"-"\u31b7", + "\u3400"-"\u4db5", + "\u4e00"-"\u9fa5", + "\ua000"-"\ua48c", + "\uac00"-"\ud7a3", + "\uf900"-"\ufa2d", + "\ufb00"-"\ufb06", + "\ufb13"-"\ufb17", + "\ufb1d", + "\ufb1f"-"\ufb28", + "\ufb2a"-"\ufb36", + "\ufb38"-"\ufb3c", + "\ufb3e", + "\ufb40"-"\ufb41", + "\ufb43"-"\ufb44", + "\ufb46"-"\ufbb1", + "\ufbd3"-"\ufd3d", + "\ufd50"-"\ufd8f", + "\ufd92"-"\ufdc7", + "\ufdf0"-"\ufdfb", + "\ufe33"-"\ufe34", + "\ufe4d"-"\ufe4f", + "\ufe69", + "\ufe70"-"\ufe72", + "\ufe74", + "\ufe76"-"\ufefc", + "\uff04", + "\uff21"-"\uff3a", + "\uff3f", + "\uff41"-"\uff5a", + "\uff65"-"\uffbe", + "\uffc2"-"\uffc7", + "\uffca"-"\uffcf", + "\uffd2"-"\uffd7", + "\uffda"-"\uffdc", + "\uffe0"-"\uffe1", + "\uffe5"-"\uffe6" + ] + > +| < #PART_LETTER: + [ // all chars for which Character.isIdentifierPart is true + "\u0000"-"\u0008", + "\u000e"-"\u001b", + //"$", + "0"-"9", + "A"-"Z", + "_", + "a"-"z", + "\u007f"-"\u009f", + "\u00a2"-"\u00a5", + "\u00aa", + "\u00b5", + "\u00ba", + "\u00c0"-"\u00d6", + "\u00d8"-"\u00f6", + "\u00f8"-"\u021f", + "\u0222"-"\u0233", + "\u0250"-"\u02ad", + "\u02b0"-"\u02b8", + "\u02bb"-"\u02c1", + "\u02d0"-"\u02d1", + "\u02e0"-"\u02e4", + "\u02ee", + "\u0300"-"\u034e", + "\u0360"-"\u0362", + "\u037a", + "\u0386", + "\u0388"-"\u038a", + "\u038c", + "\u038e"-"\u03a1", + "\u03a3"-"\u03ce", + "\u03d0"-"\u03d7", + "\u03da"-"\u03f3", + "\u0400"-"\u0481", + "\u0483"-"\u0486", + "\u048c"-"\u04c4", + "\u04c7"-"\u04c8", + "\u04cb"-"\u04cc", + "\u04d0"-"\u04f5", + "\u04f8"-"\u04f9", + "\u0531"-"\u0556", + "\u0559", + "\u0561"-"\u0587", + "\u0591"-"\u05a1", + "\u05a3"-"\u05b9", + "\u05bb"-"\u05bd", + "\u05bf", + "\u05c1"-"\u05c2", + "\u05c4", + "\u05d0"-"\u05ea", + "\u05f0"-"\u05f2", + "\u0621"-"\u063a", + "\u0640"-"\u0655", + "\u0660"-"\u0669", + "\u0670"-"\u06d3", + "\u06d5"-"\u06dc", + "\u06df"-"\u06e8", + "\u06ea"-"\u06ed", + "\u06f0"-"\u06fc", + "\u070f"-"\u072c", + "\u0730"-"\u074a", + "\u0780"-"\u07b0", + "\u0901"-"\u0903", + "\u0905"-"\u0939", + "\u093c"-"\u094d", + "\u0950"-"\u0954", + "\u0958"-"\u0963", + "\u0966"-"\u096f", + "\u0981"-"\u0983", + "\u0985"-"\u098c", + "\u098f"-"\u0990", + "\u0993"-"\u09a8", + "\u09aa"-"\u09b0", + "\u09b2", + "\u09b6"-"\u09b9", + "\u09bc", + "\u09be"-"\u09c4", + "\u09c7"-"\u09c8", + "\u09cb"-"\u09cd", + "\u09d7", + "\u09dc"-"\u09dd", + "\u09df"-"\u09e3", + "\u09e6"-"\u09f3", + "\u0a02", + "\u0a05"-"\u0a0a", + "\u0a0f"-"\u0a10", + "\u0a13"-"\u0a28", + "\u0a2a"-"\u0a30", + "\u0a32"-"\u0a33", + "\u0a35"-"\u0a36", + "\u0a38"-"\u0a39", + "\u0a3c", + "\u0a3e"-"\u0a42", + "\u0a47"-"\u0a48", + "\u0a4b"-"\u0a4d", + "\u0a59"-"\u0a5c", + "\u0a5e", + "\u0a66"-"\u0a74", + "\u0a81"-"\u0a83", + "\u0a85"-"\u0a8b", + "\u0a8d", + "\u0a8f"-"\u0a91", + "\u0a93"-"\u0aa8", + "\u0aaa"-"\u0ab0", + "\u0ab2"-"\u0ab3", + "\u0ab5"-"\u0ab9", + "\u0abc"-"\u0ac5", + "\u0ac7"-"\u0ac9", + "\u0acb"-"\u0acd", + "\u0ad0", + "\u0ae0", + "\u0ae6"-"\u0aef", + "\u0b01"-"\u0b03", + "\u0b05"-"\u0b0c", + "\u0b0f"-"\u0b10", + "\u0b13"-"\u0b28", + "\u0b2a"-"\u0b30", + "\u0b32"-"\u0b33", + "\u0b36"-"\u0b39", + "\u0b3c"-"\u0b43", + "\u0b47"-"\u0b48", + "\u0b4b"-"\u0b4d", + "\u0b56"-"\u0b57", + "\u0b5c"-"\u0b5d", + "\u0b5f"-"\u0b61", + "\u0b66"-"\u0b6f", + "\u0b82"-"\u0b83", + "\u0b85"-"\u0b8a", + "\u0b8e"-"\u0b90", + "\u0b92"-"\u0b95", + "\u0b99"-"\u0b9a", + "\u0b9c", + "\u0b9e"-"\u0b9f", + "\u0ba3"-"\u0ba4", + "\u0ba8"-"\u0baa", + "\u0bae"-"\u0bb5", + "\u0bb7"-"\u0bb9", + "\u0bbe"-"\u0bc2", + "\u0bc6"-"\u0bc8", + "\u0bca"-"\u0bcd", + "\u0bd7", + "\u0be7"-"\u0bef", + "\u0c01"-"\u0c03", + "\u0c05"-"\u0c0c", + "\u0c0e"-"\u0c10", + "\u0c12"-"\u0c28", + "\u0c2a"-"\u0c33", + "\u0c35"-"\u0c39", + "\u0c3e"-"\u0c44", + "\u0c46"-"\u0c48", + "\u0c4a"-"\u0c4d", + "\u0c55"-"\u0c56", + "\u0c60"-"\u0c61", + "\u0c66"-"\u0c6f", + "\u0c82"-"\u0c83", + "\u0c85"-"\u0c8c", + "\u0c8e"-"\u0c90", + "\u0c92"-"\u0ca8", + "\u0caa"-"\u0cb3", + "\u0cb5"-"\u0cb9", + "\u0cbe"-"\u0cc4", + "\u0cc6"-"\u0cc8", + "\u0cca"-"\u0ccd", + "\u0cd5"-"\u0cd6", + "\u0cde", + "\u0ce0"-"\u0ce1", + "\u0ce6"-"\u0cef", + "\u0d02"-"\u0d03", + "\u0d05"-"\u0d0c", + "\u0d0e"-"\u0d10", + "\u0d12"-"\u0d28", + "\u0d2a"-"\u0d39", + "\u0d3e"-"\u0d43", + "\u0d46"-"\u0d48", + "\u0d4a"-"\u0d4d", + "\u0d57", + "\u0d60"-"\u0d61", + "\u0d66"-"\u0d6f", + "\u0d82"-"\u0d83", + "\u0d85"-"\u0d96", + "\u0d9a"-"\u0db1", + "\u0db3"-"\u0dbb", + "\u0dbd", + "\u0dc0"-"\u0dc6", + "\u0dca", + "\u0dcf"-"\u0dd4", + "\u0dd6", + "\u0dd8"-"\u0ddf", + "\u0df2"-"\u0df3", + "\u0e01"-"\u0e3a", + "\u0e3f"-"\u0e4e", + "\u0e50"-"\u0e59", + "\u0e81"-"\u0e82", + "\u0e84", + "\u0e87"-"\u0e88", + "\u0e8a", + "\u0e8d", + "\u0e94"-"\u0e97", + "\u0e99"-"\u0e9f", + "\u0ea1"-"\u0ea3", + "\u0ea5", + "\u0ea7", + "\u0eaa"-"\u0eab", + "\u0ead"-"\u0eb9", + "\u0ebb"-"\u0ebd", + "\u0ec0"-"\u0ec4", + "\u0ec6", + "\u0ec8"-"\u0ecd", + "\u0ed0"-"\u0ed9", + "\u0edc"-"\u0edd", + "\u0f00", + "\u0f18"-"\u0f19", + "\u0f20"-"\u0f29", + "\u0f35", + "\u0f37", + "\u0f39", + "\u0f3e"-"\u0f47", + "\u0f49"-"\u0f6a", + "\u0f71"-"\u0f84", + "\u0f86"-"\u0f8b", + "\u0f90"-"\u0f97", + "\u0f99"-"\u0fbc", + "\u0fc6", + "\u1000"-"\u1021", + "\u1023"-"\u1027", + "\u1029"-"\u102a", + "\u102c"-"\u1032", + "\u1036"-"\u1039", + "\u1040"-"\u1049", + "\u1050"-"\u1059", + "\u10a0"-"\u10c5", + "\u10d0"-"\u10f6", + "\u1100"-"\u1159", + "\u115f"-"\u11a2", + "\u11a8"-"\u11f9", + "\u1200"-"\u1206", + "\u1208"-"\u1246", + "\u1248", + "\u124a"-"\u124d", + "\u1250"-"\u1256", + "\u1258", + "\u125a"-"\u125d", + "\u1260"-"\u1286", + "\u1288", + "\u128a"-"\u128d", + "\u1290"-"\u12ae", + "\u12b0", + "\u12b2"-"\u12b5", + "\u12b8"-"\u12be", + "\u12c0", + "\u12c2"-"\u12c5", + "\u12c8"-"\u12ce", + "\u12d0"-"\u12d6", + "\u12d8"-"\u12ee", + "\u12f0"-"\u130e", + "\u1310", + "\u1312"-"\u1315", + "\u1318"-"\u131e", + "\u1320"-"\u1346", + "\u1348"-"\u135a", + "\u1369"-"\u1371", + "\u13a0"-"\u13f4", + "\u1401"-"\u166c", + "\u166f"-"\u1676", + "\u1681"-"\u169a", + "\u16a0"-"\u16ea", + "\u1780"-"\u17d3", + "\u17db", + "\u17e0"-"\u17e9", + "\u180b"-"\u180e", + "\u1810"-"\u1819", + "\u1820"-"\u1877", + "\u1880"-"\u18a9", + "\u1e00"-"\u1e9b", + "\u1ea0"-"\u1ef9", + "\u1f00"-"\u1f15", + "\u1f18"-"\u1f1d", + "\u1f20"-"\u1f45", + "\u1f48"-"\u1f4d", + "\u1f50"-"\u1f57", + "\u1f59", + "\u1f5b", + "\u1f5d", + "\u1f5f"-"\u1f7d", + "\u1f80"-"\u1fb4", + "\u1fb6"-"\u1fbc", + "\u1fbe", + "\u1fc2"-"\u1fc4", + "\u1fc6"-"\u1fcc", + "\u1fd0"-"\u1fd3", + "\u1fd6"-"\u1fdb", + "\u1fe0"-"\u1fec", + "\u1ff2"-"\u1ff4", + "\u1ff6"-"\u1ffc", + "\u200c"-"\u200f", + "\u202a"-"\u202e", + "\u203f"-"\u2040", + "\u206a"-"\u206f", + "\u207f", + "\u20a0"-"\u20af", + "\u20d0"-"\u20dc", + "\u20e1", + "\u2102", + "\u2107", + "\u210a"-"\u2113", + "\u2115", + "\u2119"-"\u211d", + "\u2124", + "\u2126", + "\u2128", + "\u212a"-"\u212d", + "\u212f"-"\u2131", + "\u2133"-"\u2139", + "\u2160"-"\u2183", + "\u3005"-"\u3007", + "\u3021"-"\u302f", + "\u3031"-"\u3035", + "\u3038"-"\u303a", + "\u3041"-"\u3094", + "\u3099"-"\u309a", + "\u309d"-"\u309e", + "\u30a1"-"\u30fe", + "\u3105"-"\u312c", + "\u3131"-"\u318e", + "\u31a0"-"\u31b7", + "\u3400"-"\u4db5", + "\u4e00"-"\u9fa5", + "\ua000"-"\ua48c", + "\uac00"-"\ud7a3", + "\uf900"-"\ufa2d", + "\ufb00"-"\ufb06", + "\ufb13"-"\ufb17", + "\ufb1d"-"\ufb28", + "\ufb2a"-"\ufb36", + "\ufb38"-"\ufb3c", + "\ufb3e", + "\ufb40"-"\ufb41", + "\ufb43"-"\ufb44", + "\ufb46"-"\ufbb1", + "\ufbd3"-"\ufd3d", + "\ufd50"-"\ufd8f", + "\ufd92"-"\ufdc7", + "\ufdf0"-"\ufdfb", + "\ufe20"-"\ufe23", + "\ufe33"-"\ufe34", + "\ufe4d"-"\ufe4f", + "\ufe69", + "\ufe70"-"\ufe72", + "\ufe74", + "\ufe76"-"\ufefc", + "\ufeff", + "\uff04", + "\uff10"-"\uff19", + "\uff21"-"\uff3a", + "\uff3f", + "\uff41"-"\uff5a", + "\uff65"-"\uffbe", + "\uffc2"-"\uffc7", + "\uffca"-"\uffcf", + "\uffd2"-"\uffd7", + "\uffda"-"\uffdc", + "\uffe0"-"\uffe1", + "\uffe5"-"\uffe6", + "\ufff9"-"\ufffb" + ] + > +} diff --git a/csjavacc/parser/CSJavaCCErrors.java b/csjavacc/parser/CSJavaCCErrors.java new file mode 100644 index 0000000..9b1662b --- /dev/null +++ b/csjavacc/parser/CSJavaCCErrors.java @@ -0,0 +1,116 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import csjavacc.struct.CharacterRange; +import csjavacc.struct.Expansion; +import csjavacc.struct.TokenProduction; + +public class CSJavaCCErrors { + + private static int parse_error_count = 0, semantic_error_count = 0, warning_count = 0; + + private static void printLocationInfo(Object node) { + if (node instanceof NormalProduction) { + NormalProduction n = (NormalProduction)node; + System.err.print("Line " + n.line + ", Column " + n.column + ": "); + } else if (node instanceof TokenProduction) { + TokenProduction n = (TokenProduction)node; + System.err.print("Line " + n.line + ", Column " + n.column + ": "); + } else if (node instanceof Expansion) { + Expansion n = (Expansion)node; + System.err.print("Line " + n.line + ", Column " + n.column + ": "); + } else if (node instanceof CharacterRange) { + CharacterRange n = (CharacterRange)node; + System.err.print("Line " + n.line + ", Column " + n.column + ": "); + } else if (node instanceof SingleCharacter) { + SingleCharacter n = (SingleCharacter)node; + System.err.print("Line " + n.line + ", Column " + n.column + ": "); + } else if (node instanceof Token) { + Token t = (Token)node; + System.err.print("Line " + t.beginLine + ", Column " + t.beginColumn + ": "); + } + } + + public static void parse_error(Object node, String mess) { + System.err.print("Error: "); + printLocationInfo(node); + System.err.println(mess); + parse_error_count++; + } + + public static void parse_error(String mess) { + System.err.print("Error: "); + System.err.println(mess); + parse_error_count++; + } + + public static int get_parse_error_count() { + return parse_error_count; + } + + public static void semantic_error(Object node, String mess) { + System.err.print("Error: "); + printLocationInfo(node); + System.err.println(mess); + semantic_error_count++; + } + + public static void semantic_error(String mess) { + System.err.print("Error: "); + System.err.println(mess); + semantic_error_count++; + } + + public static int get_semantic_error_count() { + return semantic_error_count; + } + + public static void warning(Object node, String mess) { + System.err.print("Warning: "); + printLocationInfo(node); + System.err.println(mess); + warning_count++; + } + + public static void warning(String mess) { + System.err.print("Warning: "); + System.err.println(mess); + warning_count++; + } + + public static int get_warning_count() { + return warning_count; + } + + public static int get_error_count() { + return parse_error_count + semantic_error_count; + } + + public static void reInit(){ + parse_error_count = 0; + semantic_error_count = 0; + warning_count = 0; + } + +} diff --git a/csjavacc/parser/CSJavaCCGlobals.java b/csjavacc/parser/CSJavaCCGlobals.java new file mode 100644 index 0000000..36cb0fe --- /dev/null +++ b/csjavacc/parser/CSJavaCCGlobals.java @@ -0,0 +1,548 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.util.Vector; +import java.io.*; + +import csjavacc.Version; +import csjavacc.struct.Action; + + +/** + * This package contains data created as a result of parsing and semanticizing + * a JavaCC input file. This data is what is used by the back-ends of JavaCC as + * well as any other back-end of JavaCC related tools such as JJTree. + */ +public class CSJavaCCGlobals { + final static String language = "CS"; + final static String extension = ".cs"; + /** + * String that identifies the JavaCC generated files. + */ + protected static final String toolName = language+"CC"; + + /** + * The name of the grammar file being processed. + */ + static public String fileName; + + /** + * The name of the original file (before processing by JJTree and JJCov). + * Currently this is the same as fileName. + */ + static public String origFileName; + + /** + * Set to true if this file has been processed by JJTree. + */ + static public boolean jjtreeGenerated; + + /** + * Set to true if this file has been processed by JJCov. + */ + static public boolean jjcovGenerated; + + /** + * The list of tools that have participated in generating the + * input grammar file. + */ + static public Vector toolNames; + + /** + * This prints the banner line when the various tools are invoked. This + * takes as argument the tool's full name and its version. + */ + static public void bannerLine(String fullName, String ver) { + System.err.print(language+" Compiler Compiler Version " + Version.version + " (" + fullName); + if (!ver.equals("")) { + System.err.print(" Version " + ver); + } + System.err.println(")"); + } + + /** + * The name of the parser class (what appears in PARSER_BEGIN and PARSER_END). + */ + static public String cu_name; + + /** + * This is a list of tokens that appear after "PARSER_BEGIN(name)" all the + * way until (but not including) the opening brace "{" of the class "name". + */ + static public java.util.Vector cu_to_insertion_point_1 = new java.util.Vector(); + + /** + * This is the list of all tokens that appear after the tokens in + * "cu_to_insertion_point_1" and until (but not including) the closing brace "}" + * of the class "name". + */ + static public java.util.Vector cu_to_insertion_point_2 = new java.util.Vector(); + + /** + * This is the list of all tokens that appear after the tokens in + * "cu_to_insertion_point_2" and until "PARSER_END(name)". + */ + static public java.util.Vector cu_from_insertion_point_2 = new java.util.Vector(); + + /** + * A list of all grammar productions - normal and JAVACODE - in the order + * they appear in the input file. Each entry here will be a subclass of + * "NormalProduction". + */ + static public java.util.Vector bnfproductions = new java.util.Vector(); + + /** + * A symbol table of all grammar productions - normal and JAVACODE. The + * symbol table is indexed by the name of the left hand side non-terminal. + * Its contents are of type "NormalProduction". + */ + static public java.util.Hashtable production_table = new java.util.Hashtable(); + + /** + * A mapping of lexical state strings to their integer internal representation. + * Integers are stored as java.lang.Integer's. + */ + static public java.util.Hashtable lexstate_S2I = new java.util.Hashtable(); + + /** + * A mapping of the internal integer representations of lexical states to + * their strings. Integers are stored as java.lang.Integer's. + */ + static public java.util.Hashtable lexstate_I2S = new java.util.Hashtable(); + + /** + * The declarations to be inserted into the TokenManager class. + */ + static public java.util.Vector token_mgr_decls; + + /** + * The list of all TokenProductions from the input file. This list includes + * implicit TokenProductions that are created for uses of regular expressions + * within BNF productions. + */ + static public java.util.Vector rexprlist = new java.util.Vector(); + + /** + * The total number of distinct tokens. This is therefore one more than the + * largest assigned token ordinal. + */ + static public int tokenCount; + + /** + * This is a symbol table that contains all named tokens (those that are + * defined with a label). The index to the table is the image of the label + * and the contents of the table are of type "RegularExpression". + */ + static public java.util.Hashtable named_tokens_table = new java.util.Hashtable(); + + /** + * Contains the same entries as "named_tokens_table", but this is an ordered + * list which is ordered by the order of appearance in the input file. + */ + static public java.util.Vector ordered_named_tokens = new java.util.Vector(); + + /** + * A mapping of ordinal values (represented as objects of type "Integer") to + * the corresponding labels (of type "String"). An entry exists for an ordinal + * value only if there is a labeled token corresponding to this entry. + * If there are multiple labels representing the same ordinal value, then + * only one label is stored. + */ + static public java.util.Hashtable names_of_tokens = new java.util.Hashtable(); + + /** + * A mapping of ordinal values (represented as objects of type "Integer") to + * the corresponding RegularExpression's. + */ + static public java.util.Hashtable rexps_of_tokens = new java.util.Hashtable(); + + /** + * This is a three-level symbol table that contains all simple tokens (those + * that are defined using a single string (with or without a label). The index + * to the first level table is a lexical state which maps to a second level + * hashtable. The index to the second level hashtable is the string of the + * simple token converted to upper case, and this maps to a third level hashtable. + * This third level hashtable contains the actual string of the simple token + * and maps it to its RegularExpression. + */ + static public java.util.Hashtable simple_tokens_table = new java.util.Hashtable(); + + /** + * maskindex, jj2index, maskVals are variables that are shared between + * ParseEngine and ParseGen. + */ + static protected int maskindex = 0; + static protected int jj2index = 0; + static protected Vector maskVals = new Vector(); + + static Action actForEof; + static String nextStateForEof; + + + // Some general purpose utilities follow. + + /** + * Returns the identifying string for the file name, given a toolname + * used to generate it. + */ + public static String getIdString(String toolName, String fileName) { + Vector toolNames = new Vector(); + toolNames.addElement(toolName); + return getIdString(toolNames, fileName); + } + + /** + * Returns the identifying string for the file name, given a set of tool + * names that are used to generate it. + */ + public static String getIdString(Vector toolNames, String fileName) { + int i; + String toolNamePrefix = "Generated By: "; + + for (i = 0; i < toolNames.size() - 1; i++) + toolNamePrefix += (String)toolNames.elementAt(i) + "&"; + toolNamePrefix += (String)toolNames.elementAt(i) + ":"; + + if (toolNamePrefix.length() > 200) + { + System.err.println("Tool name is too long."); + throw new Error(); + } + return toolNamePrefix + " " + Version.version + " " +" Do not edit this line. " + addUnicodeEscapes(fileName); + } + + /** + * Returns true if tool name passed is one of the tool names returned + * by getToolNames(fileName). + */ + public static boolean isGeneratedBy(String toolName, String fileName) { + Vector v = getToolNames(fileName); + + for (int i = 0; i < v.size(); i++) + if (toolName.equals(v.elementAt(i))) + return true; + + return false; + } + + private static Vector makeToolNameVector(String str) { + Vector retVal = new Vector(); + + int limit1 = str.indexOf('\n'); + if (limit1 == -1) limit1 = 1000; + int limit2 = str.indexOf('\r'); + if (limit2 == -1) limit2 = 1000; + int limit = (limit1 < limit2) ? limit1 : limit2; + + String tmp; + if (limit == 1000) { + tmp = str; + } else { + tmp = str.substring(0, limit); + } + + if (tmp.indexOf(':') == -1) + return retVal; + + tmp = tmp.substring(tmp.indexOf(':') + 1); + + if (tmp.indexOf(':') == -1) + return retVal; + + tmp = tmp.substring(0, tmp.indexOf(':')); + + int i = 0, j = 0; + + while (j < tmp.length() && (i = tmp.indexOf('&', j)) != -1) + { + retVal.addElement(tmp.substring(j, i)); + j = i + 1; + } + + if (j < tmp.length()) + retVal.addElement(tmp.substring(j)); + + return retVal; + } + + /** + * Returns a Vector of names of the tools that have been used to generate + * the given file. + */ + public static Vector getToolNames(String fileName) { + char[] buf = new char[256]; + java.io.FileReader stream = null; + int read, total = 0; + + try { + stream = new java.io.FileReader(fileName); + + for (;;) + if ((read = stream.read(buf, total, buf.length - total)) != -1) + { + if ((total += read) == buf.length) + break; + } + else + break; + + return makeToolNameVector(new String(buf, 0, total)); + } catch(java.io.FileNotFoundException e1) { + } catch(java.io.IOException e2) { + if (total > 0) + return makeToolNameVector(new String(buf, 0, total)); + } + finally { + try { stream.close(); } + catch (Exception e3) { } + } + + return new Vector(); + } + + public static void createOutputDir(File outputDir) { + if (!outputDir.exists()) { + CSJavaCCErrors.warning("Output directory \"" + outputDir + "\" does not exist. Creating the directory."); + + if (!outputDir.mkdirs()) { + CSJavaCCErrors.semantic_error("Cannot create the output directory : " + outputDir); + return; + } + } + + if (!outputDir.isDirectory()) { + CSJavaCCErrors.semantic_error("\"" + outputDir + " is not a valid output directory."); + return; + } + + if (!outputDir.canWrite()) { + CSJavaCCErrors.semantic_error("Cannot write to the output output directory : \"" + outputDir + "\""); + return; + } + } + + static public String staticOpt() { + if (Options.getStatic()) { + return "static "; + } else { + return ""; + } + } + + static public String add_escapes(String str) { + String retval = ""; + char ch; + for (int i = 0; i < str.length(); i++) { + ch = str.charAt(i); + if (ch == '\b') { + retval += "\\b"; + } else if (ch == '\t') { + retval += "\\t"; + } else if (ch == '\n') { + retval += "\\n"; + } else if (ch == '\f') { + retval += "\\f"; + } else if (ch == '\r') { + retval += "\\r"; + } else if (ch == '\"') { + retval += "\\\""; + } else if (ch == '\'') { + retval += "\\\'"; + } else if (ch == '\\') { + retval += "\\\\"; + } else if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval += "\\u" + s.substring(s.length() - 4, s.length()); + } else { + retval += ch; + } + } + return retval; + } + + static public String addUnicodeEscapes(String str) { + String retval = ""; + char ch; + for (int i = 0; i < str.length(); i++) { + ch = str.charAt(i); + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval += "\\u" + s.substring(s.length() - 4, s.length()); + } else { + retval += ch; + } + } + return retval; + } + + static protected int cline, ccol; + + static protected void printTokenSetup(Token t) { + Token tt = t; + while (tt.specialToken != null) tt = tt.specialToken; + cline = tt.beginLine; + ccol = tt.beginColumn; + } + + static protected void printTokenOnly(Token t, java.io.PrintWriter ostr) { + for (; cline < t.beginLine; cline++) { + ostr.println(""); ccol = 1; + } + for (; ccol < t.beginColumn; ccol++) { + ostr.print(" "); + } + if (t.kind == CSJavaCCParserConstants.STRING_LITERAL || + t.kind == CSJavaCCParserConstants.CHARACTER_LITERAL) + ostr.print(addUnicodeEscapes(t.image)); + else + ostr.print(t.image); + cline = t.endLine; + ccol = t.endColumn+1; + char last = t.image.charAt(t.image.length()-1); + if (last == '\n' || last == '\r') { + cline++; ccol = 1; + } + } + + static protected void printToken(Token t, java.io.PrintWriter ostr) { + Token tt = t.specialToken; + if (tt != null) { + while (tt.specialToken != null) tt = tt.specialToken; + while (tt != null) { + printTokenOnly(tt, ostr); + tt = tt.next; + } + } + printTokenOnly(t, ostr); + } + + static protected void printLeadingComments(Token t, java.io.PrintWriter ostr) { + if (t.specialToken == null) return; + Token tt = t.specialToken; + while (tt.specialToken != null) tt = tt.specialToken; + while (tt != null) { + printTokenOnly(tt, ostr); + tt = tt.next; + } + if (ccol != 1 && cline != t.beginLine) { + ostr.println(""); + cline++; ccol = 1; + } + } + + static protected void printTrailingComments(Token t, java.io.PrintWriter ostr) { + if (t.next == null) return; + printLeadingComments(t.next); + } + + static protected String printTokenOnly(Token t) { + String retval = ""; + for (; cline < t.beginLine; cline++) { + retval += "\n"; ccol = 1; + } + for (; ccol < t.beginColumn; ccol++) { + retval += " "; + } + if (t.kind == CSJavaCCParserConstants.STRING_LITERAL || + t.kind == CSJavaCCParserConstants.CHARACTER_LITERAL) + retval += addUnicodeEscapes(t.image); + else + retval += t.image; + cline = t.endLine; + ccol = t.endColumn+1; + char last = t.image.charAt(t.image.length()-1); + if (last == '\n' || last == '\r') { + cline++; ccol = 1; + } + return retval; + } + + static protected String printToken(Token t) { + String retval = ""; + Token tt = t.specialToken; + if (tt != null) { + while (tt.specialToken != null) tt = tt.specialToken; + while (tt != null) { + retval += printTokenOnly(tt); + tt = tt.next; + } + } + retval += printTokenOnly(t); + return retval; + } + + static protected String printLeadingComments(Token t) { + String retval = ""; + if (t.specialToken == null) return retval; + Token tt = t.specialToken; + while (tt.specialToken != null) tt = tt.specialToken; + while (tt != null) { + retval += printTokenOnly(tt); + tt = tt.next; + } + if (ccol != 1 && cline != t.beginLine) { + retval += "\n"; + cline++; ccol = 1; + } + return retval; + } + + static protected String printTrailingComments(Token t) { + if (t.next == null) return ""; + return printLeadingComments(t.next); + } + + public static void reInit() + { + fileName = null; + origFileName = null; + jjtreeGenerated = false; + jjcovGenerated = false; + toolNames = null; + cu_name = null; + cu_to_insertion_point_1 = new java.util.Vector(); + cu_to_insertion_point_2 = new java.util.Vector(); + cu_from_insertion_point_2 = new java.util.Vector(); + bnfproductions = new java.util.Vector(); + production_table = new java.util.Hashtable(); + lexstate_S2I = new java.util.Hashtable(); + lexstate_I2S = new java.util.Hashtable(); + token_mgr_decls = null; + rexprlist = new java.util.Vector(); + tokenCount = 0; + named_tokens_table = new java.util.Hashtable(); + ordered_named_tokens = new java.util.Vector(); + names_of_tokens = new java.util.Hashtable(); + rexps_of_tokens = new java.util.Hashtable(); + simple_tokens_table = new java.util.Hashtable(); + maskindex = 0; + jj2index = 0; + maskVals = new Vector(); + cline = 0; + ccol = 0; + actForEof = null; + nextStateForEof = null; + } + +} diff --git a/csjavacc/parser/CSJavaCCParser.java b/csjavacc/parser/CSJavaCCParser.java new file mode 100644 index 0000000..e4ac09b --- /dev/null +++ b/csjavacc/parser/CSJavaCCParser.java @@ -0,0 +1,7661 @@ +/* Generated By:JavaCC: Do not edit this line. CSJavaCCParser.java */ +/** + * This file contains the code for CSJavaCCParser generated + * by CSJavaCCParser itself. + */ + +package csjavacc.parser; + +import java.util.Vector; +import csjavacc.struct.*; + +public class CSJavaCCParser extends CSJavaCCParserInternals implements CSJavaCCParserConstants { + + /** + * 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; + } + + /** + * Class to hold modifiers. + */ + static public final class ModifierSet + { + /* Definitions of the bits in the modifiers field. */ + public static final int PUBLIC = 0x0001; + public static final int PROTECTED = 0x0002; + public static final int PRIVATE = 0x0004; + public static final int ABSTRACT = 0x0008; + public static final int STATIC = 0x0010; + public static final int OVERRIDE = 0x0020; + public static final int PARTIAL = 0x0040; + public static final int NEW = 0x0100; + public static final int INTERNAL = 0x0080; + public static final int READONLY = 0x0200; + public static final int FIXED = 0x0400; + public static final int UNSAFE = 0x0800; + public static final int OUT = 0x1000; + public static final int REF = 0x2000; + + public boolean isPublic(int modifiers){ return (modifiers & PUBLIC) != 0; } + public boolean isProtected(int modifiers){ return (modifiers & PROTECTED) != 0; } + public boolean isPrivate(int modifiers){ return (modifiers & PRIVATE) != 0; } + public boolean isStatic(int modifiers){ return (modifiers & STATIC) != 0; } + public boolean isAbstract(int modifiers){ return (modifiers & ABSTRACT) != 0; } + public boolean isOverride(int modifiers){ return (modifiers & OVERRIDE) != 0; } + + /** Removes the given modifier. */ + static int removeModifier(int modifiers, int mod){ return modifiers & ~mod; } + } + +/************************************************ + * THE CSJAVACC GRAMMAR SPECIFICATION STARTS HERE * + ************************************************/ + final public void csjavacc_input() throws ParseException { + String id1, id2; + initialize(); + csjavacc_options(); + jj_consume_token(_PARSER_BEGIN); + jj_consume_token(LPAREN); + id1 = identifier(); + addcuname(id1); + jj_consume_token(RPAREN); + processing_cu = true; + parser_class_name = id1; + CompilationUnit(); + processing_cu = false; + jj_consume_token(_PARSER_END); + jj_consume_token(LPAREN); + id2 = identifier(); + compare(getToken(0), id1, id2); + jj_consume_token(RPAREN); + label_1: + while (true) { + production(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case VOID: + case VAR: + case LANGLE: + case IDENTIFIER: + ; + break; + default: + jj_la1[0] = jj_gen; + break label_1; + } + } + jj_consume_token(0); + } + + final public void csjavacc_options() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + jj_consume_token(_OPTIONS); + jj_consume_token(LBRACE); + label_2: + while (true) { + option_binding(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _LOOKAHEAD: + case _IGNORE_CASE: + case STATIC: + case IDENTIFIER: + ; + break; + default: + jj_la1[1] = jj_gen; + break label_2; + } + } + jj_consume_token(RBRACE); + break; + default: + jj_la1[2] = jj_gen; + ; + } + Options.normalize(); + } + + final public void option_binding() throws ParseException { + String option_name; + int int_val; + boolean bool_val; + String string_val; + Token t = getToken(1); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENTIFIER: + jj_consume_token(IDENTIFIER); + break; + case _LOOKAHEAD: + jj_consume_token(_LOOKAHEAD); + break; + case _IGNORE_CASE: + jj_consume_token(_IGNORE_CASE); + break; + case STATIC: + jj_consume_token(STATIC); + break; + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + option_name = t.image; + jj_consume_token(ASSIGN); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INTEGER_LITERAL: + int_val = IntegerLiteral(); + Options.setInputFileOption(t, getToken(0), option_name, int_val); + break; + case FALSE: + case TRUE: + bool_val = BooleanLiteral(); + Options.setInputFileOption(t, getToken(0), option_name, bool_val); + break; + case STRING_LITERAL: + string_val = StringLiteral(); + Options.setInputFileOption(t, getToken(0), option_name, string_val); + break; + default: + jj_la1[4] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(SEMICOLON); + } + + final public void production() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _CSCODE: + cscode_production(); + break; + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case LANGLE: + regular_expr_production(); + break; + case _TOKEN_MGR_DECLS: + token_manager_decls(); + break; + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case VOID: + case VAR: + case IDENTIFIER: + bnf_production(); + break; + default: + jj_la1[5] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void cscode_production() throws ParseException { + String lhs; + CSCodeProduction p = new CSCodeProduction(); + 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; + jj_consume_token(_CSCODE); + AccessModifier(p); + ResultType(p.return_type_tokens); + p.lhs = identifier(); + FormalParameters(p.parameter_list_tokens); + Block(p.code_tokens); + p.lastToken = getToken(0); + addproduction(p); + } + + final public void bnf_production() throws ParseException { + 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; + AccessModifier(p); + ResultType(p.return_type_tokens); + p.lhs = identifier(); + FormalParameters(p.parameter_list_tokens); + jj_consume_token(COLON); + Block(p.declaration_tokens); + jj_consume_token(LBRACE); + expansion_choices(c); + t = jj_consume_token(RBRACE); + p.lastToken = t; + p.jumpPatched = jumpPatched; + production_addexpansion(p, (Expansion)(c.member)); + addproduction(p); + } + + final public void AccessModifier(NormalProduction p) throws ParseException { + Token t = null; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PRIVATE: + case PROTECTED: + case PUBLIC: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PUBLIC: + t = jj_consume_token(PUBLIC); + break; + case PROTECTED: + t = jj_consume_token(PROTECTED); + break; + case PRIVATE: + t = jj_consume_token(PRIVATE); + break; + default: + jj_la1[6] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[7] = jj_gen; + ; + } + if(t != null){ + p.accessMod = t.image; + } + } + + final public void regular_expr_production() throws ParseException { + TokenProduction p = new TokenProduction(); + java.util.Vector states; + Token t = p.firstToken = getToken(1); + p.line = t.beginLine; + p.column = t.beginColumn; + // set p.lexStates assuming there is no state spec. + // and then override if necessary. + p.lexStates = new String[1]; + p.lexStates[0] = "DEFAULT"; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + if (jj_2_1(2)) { + jj_consume_token(LANGLE); + jj_consume_token(STAR); + jj_consume_token(RANGLE); + p.lexStates = null; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + jj_consume_token(LANGLE); + states = new java.util.Vector(); + t = jj_consume_token(IDENTIFIER); + states.addElement(t.image); + label_3: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[8] = jj_gen; + break label_3; + } + jj_consume_token(COMMA); + t = jj_consume_token(IDENTIFIER); + states.addElement(t.image); + } + jj_consume_token(RANGLE); + p.lexStates = new String[states.size()]; + for (int i = 0; i < states.size(); i++) { + p.lexStates[i] = (String)states.elementAt(i); + } + break; + default: + jj_la1[9] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + break; + default: + jj_la1[10] = jj_gen; + ; + } + regexpr_kind(p); + if (p.kind != TokenProduction.TOKEN && Options.getUserTokenManager()) { + CSJavaCCErrors.warning(getToken(0), "Regular expression is being treated as if it were a TOKEN since option USER_TOKEN_MANAGER has been set to true."); + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACKET: + jj_consume_token(LBRACKET); + t = jj_consume_token(_IGNORE_CASE); + jj_consume_token(RBRACKET); + p.ignoreCase = true; + if (Options.getUserTokenManager()) { + CSJavaCCErrors.warning(t, "Ignoring \"IGNORE_CASE\" specification since option USER_TOKEN_MANAGER has been set to true."); + } + break; + default: + jj_la1[11] = jj_gen; + ; + } + jj_consume_token(COLON); + jj_consume_token(LBRACE); + regexpr_spec(p); + label_4: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BIT_OR: + ; + break; + default: + jj_la1[12] = jj_gen; + break label_4; + } + jj_consume_token(BIT_OR); + regexpr_spec(p); + } + t = jj_consume_token(RBRACE); + p.lastToken = t; + addregexpr(p); + } + + final public void token_manager_decls() throws ParseException { + java.util.Vector decls = new java.util.Vector(); + Token t; + t = jj_consume_token(_TOKEN_MGR_DECLS); + jj_consume_token(COLON); + ClassOrInterfaceBody(false, decls); + add_token_manager_decls(t, decls); + } + + final public void regexpr_kind(TokenProduction p) throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _TOKEN: + jj_consume_token(_TOKEN); + p.kind = TokenProduction.TOKEN; + break; + case _SPECIAL_TOKEN: + jj_consume_token(_SPECIAL_TOKEN); + p.kind = TokenProduction.SPECIAL; + break; + case _SKIP: + jj_consume_token(_SKIP); + p.kind = TokenProduction.SKIP; + break; + case _MORE: + jj_consume_token(_MORE); + p.kind = TokenProduction.MORE; + break; + default: + jj_la1[13] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void regexpr_spec(TokenProduction p) throws ParseException { + Container c = new Container(); + Action act = new Action(); + Token t = null; + RegExprSpec res = new RegExprSpec(); + regular_expression(c); + res.rexp = (RegularExpression)c.member; + res.rexp.tpContext = p; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACE: + t = getToken(1); + Block(act.action_tokens); + if (Options.getUserTokenManager()) { + CSJavaCCErrors.warning(t, "Ignoring action in regular expression specification since option USER_TOKEN_MANAGER has been set to true."); + } + if (res.rexp.private_rexp) { + CSJavaCCErrors.parse_error(t, "Actions are not permitted on private (#) regular expressions."); + } + break; + default: + jj_la1[14] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COLON: + jj_consume_token(COLON); + t = jj_consume_token(IDENTIFIER); + res.nextState = t.image; + if (res.rexp.private_rexp) { + CSJavaCCErrors.parse_error(t, "Lexical state changes are not permitted after private (#) regular expressions."); + } + break; + default: + jj_la1[15] = jj_gen; + ; + } + res.act = act; + res.nsTok = t; + p.respecs.addElement(res); + } + + final public void expansion_choices(Container c1) throws ParseException { + boolean morethanone = false; + Choice ch = null; + Container c2 = new Container(); + expansion(c1); + label_5: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BIT_OR: + ; + break; + default: + jj_la1[16] = jj_gen; + break label_5; + } + jj_consume_token(BIT_OR); + expansion(c2); + if (morethanone) { + ch.choices.addElement(c2.member); + ((Expansion)c2.member).parent = ch; + } else { + morethanone = true; + ch = new Choice(); + ch.line = ((Expansion)c1.member).line; + ch.column = ((Expansion)c1.member).column; + ch.choices.addElement(c1.member); + ((Expansion)c1.member).parent = ch; + ch.choices.addElement(c2.member); + ((Expansion)c2.member).parent = ch; + } + } + if (morethanone) { + c1.member = ch; + } + } + + final public void expansion(Container c1) throws ParseException { + Sequence seq = new Sequence(); + Container c2 = new Container(); + Lookahead la = new Lookahead(); + Token t = getToken(1); + seq.line = t.beginLine; + seq.column = t.beginColumn; + la.line = t.beginLine; + la.column = t.beginColumn; + la.amount = Options.getLookahead(); + la.la_expansion = null; + la.isExplicit = false; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _LOOKAHEAD: + t = jj_consume_token(_LOOKAHEAD); + jj_consume_token(LPAREN); + la = local_lookahead(); + jj_consume_token(RPAREN); + if (inLocalLA != 0 && la.amount != 0) { + CSJavaCCErrors.warning(t, "Only semantic lookahead specifications within other lookahead specifications is considered. Syntactic lookahead is ignored."); + } + break; + default: + jj_la1[17] = jj_gen; + ; + } + seq.units.addElement(la); + label_6: + while (true) { + expansion_unit(c2); + seq.units.addElement(c2.member); + ((Expansion)c2.member).parent = seq; + ((Expansion)c2.member).ordinal = seq.units.size()-1; + if (notTailOfExpansionUnit()) { + ; + } else { + break label_6; + } + } + if (la.la_expansion == null) { + la.la_expansion = seq; + } + c1.member = seq; + } + + final public Lookahead local_lookahead() throws ParseException { + Lookahead la = new Lookahead(); + la.isExplicit = true; + Token t = getToken(1); + la.line = t.beginLine; + la.column = t.beginColumn; + la.la_expansion = null; + Container c = new Container(); + boolean commaAtEnd = false, emptyLA = true; + inLocalLA++; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INTEGER_LITERAL: + la.amount = IntegerLiteral(); + emptyLA = false; + break; + default: + jj_la1[18] = jj_gen; + ; + } + if (!emptyLA && (getToken(1).kind != RPAREN)) { + jj_consume_token(COMMA); + commaAtEnd = true; + } else { + ; + } + if (getToken(1).kind != RPAREN && getToken(1).kind != LBRACE) { + expansion_choices(c); + emptyLA = false; commaAtEnd = false; + la.la_expansion = (Expansion)c.member; + } else { + ; + } + if (!emptyLA && !commaAtEnd && (getToken(1).kind != RPAREN)) { + jj_consume_token(COMMA); + commaAtEnd = true; + } else { + ; + } + if (emptyLA || commaAtEnd) { + jj_consume_token(LBRACE); + Expression(la.action_tokens); + jj_consume_token(RBRACE); + if (emptyLA) { + la.amount = 0; + } + } else { + ; + } + inLocalLA--; + {if (true) return la;} + throw new Error("Missing return statement in function"); + } + + final public void expansion_unit(Container c) throws ParseException { + String name; + java.util.Vector lhsTokens = new java.util.Vector(); + NonTerminal nt; + Action act; + Token t; + Lookahead la; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _LOOKAHEAD: + /* + * We give this priority over primary expressions which use LOOKAHEAD as the + * name of its identifier. + */ + t = jj_consume_token(_LOOKAHEAD); + jj_consume_token(LPAREN); + la = local_lookahead(); + jj_consume_token(RPAREN); + // Now set the la_expansion field of la with a dummy + // expansion (we use EOF). + la.la_expansion = new REndOfFile(); + // Create a singleton choice with an empty action. + Choice ch = new Choice(); + ch.line = t.beginLine; ch.column = t.beginColumn; + Sequence seq = new Sequence(); + seq.line = t.beginLine; seq.column = t.beginColumn; + seq.units.addElement(la); + la.parent = seq; la.ordinal = 0; + act = new Action(); + act.line = t.beginLine; act.column = t.beginColumn; + seq.units.addElement(act); + act.parent = seq; act.ordinal = 1; + ch.choices.addElement(seq); + seq.parent = ch; seq.ordinal = 0; + if (la.amount != 0) { + if (la.action_tokens.size() != 0) { + CSJavaCCErrors.warning(t, "Encountered LOOKAHEAD(...) at a non-choice location. Only semantic lookahead will be considered here."); + } else { + CSJavaCCErrors.warning(t, "Encountered LOOKAHEAD(...) at a non-choice location. This will be ignored."); + } + } + c.member = ch; + break; + case LBRACE: + act = new Action(); + t = getToken(1); + act.line = t.beginLine; + act.column = t.beginColumn; + inAction = true; + Block(act.action_tokens); + inAction = false; + if (inLocalLA != 0) { + CSJavaCCErrors.warning(t, "Action within lookahead specification will be ignored."); + } + c.member = act; + break; + case LBRACKET: + t = jj_consume_token(LBRACKET); + expansion_choices(c); + jj_consume_token(RBRACKET); + ZeroOrOne exp = new ZeroOrOne(); + exp.line = t.beginLine; + exp.column = t.beginColumn; + exp.expansion = (Expansion)c.member; + ((Expansion)c.member).parent = exp; + c.member = exp; + break; + case TRY: + Container expch = new Container(); + java.util.Vector types = new java.util.Vector(); + java.util.Vector ids = new java.util.Vector(); + java.util.Vector catchblks = new java.util.Vector(); + java.util.Vector finallyblk = null; + java.util.Vector vec = new java.util.Vector(); + Token t0; + t0 = jj_consume_token(TRY); + jj_consume_token(LBRACE); + expansion_choices(expch); + jj_consume_token(RBRACE); + label_7: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case CATCH: + ; + break; + default: + jj_la1[19] = jj_gen; + break label_7; + } + jj_consume_token(CATCH); + jj_consume_token(LPAREN); + Name(vec); + t = jj_consume_token(IDENTIFIER); + jj_consume_token(RPAREN); + types.addElement(vec); + ids.addElement(t); + vec = new java.util.Vector(); + inAction = true; + Block(vec); + inAction = false; + catchblks.addElement(vec); + vec = new java.util.Vector(); + } + makeTryBlock(t0, c, expch, types, ids, catchblks, finallyblk); + break; + default: + jj_la1[24] = jj_gen; + if (jj_2_4(2147483647)) { + if (jj_2_2(2147483647)) { + Token first = getToken(1); + PrimaryExpression(); + Token last = getToken(0); + jj_consume_token(ASSIGN); + t = first; + while (true) { + lhsTokens.addElement(t); + if (t == last) break; + t = t.next; + } + } else { + ; + } + if (jj_2_3(2147483647)) { + nt = new NonTerminal(); + t = getToken(1); + nt.line = t.beginLine; + nt.column = t.beginColumn; + nt.lhsTokens = lhsTokens; + name = identifier(); + Arguments(nt.argument_tokens); + nt.name = name; + c.member = nt; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING_LITERAL: + case LANGLE: + regular_expression(c); + ((RegularExpression)(c.member)).lhsTokens = lhsTokens; + add_inline_regexpr((RegularExpression)(c.member)); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case DOT: + jj_consume_token(DOT); + t = jj_consume_token(IDENTIFIER); + ((RegularExpression)(c.member)).rhsToken = t; + break; + default: + jj_la1[20] = jj_gen; + ; + } + break; + default: + jj_la1[21] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LPAREN: + t = jj_consume_token(LPAREN); + expansion_choices(c); + jj_consume_token(RPAREN); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case HOOK: + case PLUS: + case STAR: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PLUS: + jj_consume_token(PLUS); + OneOrMore omexp = new OneOrMore(); + omexp.line = t.beginLine; + omexp.column = t.beginColumn; + omexp.expansion = (Expansion)c.member; + ((Expansion)c.member).parent = omexp; + c.member = omexp; + break; + case STAR: + jj_consume_token(STAR); + ZeroOrMore zmexp = new ZeroOrMore(); + zmexp.line = t.beginLine; + zmexp.column = t.beginColumn; + zmexp.expansion = (Expansion)c.member; + ((Expansion)c.member).parent = zmexp; + c.member = zmexp; + break; + case HOOK: + jj_consume_token(HOOK); + ZeroOrOne zoexp = new ZeroOrOne(); + zoexp.line = t.beginLine; + zoexp.column = t.beginColumn; + zoexp.expansion = (Expansion)c.member; + ((Expansion)c.member).parent = zoexp; + c.member = zoexp; + break; + default: + jj_la1[22] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[23] = jj_gen; + ; + } + break; + default: + jj_la1[25] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + } + + final public void regular_expression(Container c) throws ParseException { + RStringLiteral strlit; + REndOfFile ef; + RJustName jn; + String image; + boolean private_rexp = false; + Token t = getToken(1); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING_LITERAL: + image = StringLiteral(); + strlit = new RStringLiteral(); + strlit.line = t.beginLine; + strlit.column = t.beginColumn; + strlit.image = image; + c.member = strlit; + break; + default: + jj_la1[28] = jj_gen; + if (jj_2_5(3)) { + image = ""; + jj_consume_token(LANGLE); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 134: + case IDENTIFIER: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 134: + jj_consume_token(134); + private_rexp = true; + break; + default: + jj_la1[26] = jj_gen; + ; + } + image = identifier(); + jj_consume_token(COLON); + break; + default: + jj_la1[27] = jj_gen; + ; + } + complex_regular_expression_choices(c); + jj_consume_token(RANGLE); + RegularExpression re; + if (c.member instanceof RJustName) { + RSequence seq = new RSequence(); + seq.units.addElement(c.member); + re = seq; + } else { + re = (RegularExpression)c.member; + } + re.label = image; + re.private_rexp = private_rexp; + re.line = t.beginLine; + re.column = t.beginColumn; + c.member = re; + } else if (jj_2_6(2)) { + jj_consume_token(LANGLE); + image = identifier(); + jj_consume_token(RANGLE); + jn = new RJustName(); + jn.line = t.beginLine; + jn.column = t.beginColumn; + jn.label = image; + c.member = jn; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + jj_consume_token(LANGLE); + jj_consume_token(_EOF); + jj_consume_token(RANGLE); + ef = new REndOfFile(); + ef.line = t.beginLine; + ef.column = t.beginColumn; + ef.ordinal = 0; + c.member = ef; + break; + default: + jj_la1[29] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + } + + final public void complex_regular_expression_choices(Container c1) throws ParseException { + boolean morethanone = false; + RChoice ch = null; + Container c2 = new Container(); + complex_regular_expression(c1); + label_8: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BIT_OR: + ; + break; + default: + jj_la1[30] = jj_gen; + break label_8; + } + jj_consume_token(BIT_OR); + complex_regular_expression(c2); + if (morethanone) { + ch.choices.addElement(c2.member); + } else { + morethanone = true; + ch = new RChoice(); + ch.line = ((RegularExpression)c1.member).line; + ch.column = ((RegularExpression)c1.member).column; + ch.choices.addElement(c1.member); + ch.choices.addElement(c2.member); + } + } + if (morethanone) { + c1.member = ch; + } + } + + final public void complex_regular_expression(Container c1) throws ParseException { + int count = 0; + RSequence seq = null; + Container c2 = new Container(); + label_9: + while (true) { + complex_regular_expression_unit(c2); + count++; + if (count == 1) { + c1.member = c2.member; // if count does not go beyond 1, we are done. + } else if (count == 2) { // more than 1, so create a sequence. + seq = new RSequence(); + seq.line = ((RegularExpression)c1.member).line; + seq.column = ((RegularExpression)c1.member).column; + seq.units.addElement(c1.member); + seq.units.addElement(c2.member); + } else { + seq.units.addElement(c2.member); + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING_LITERAL: + case LPAREN: + case LBRACKET: + case LANGLE: + case TILDE: + ; + break; + default: + jj_la1[31] = jj_gen; + break label_9; + } + } + if (count > 1) { + c1.member = seq; + } + } + + final public void complex_regular_expression_unit(Container c) throws ParseException { + String image; + RStringLiteral strlit; + RJustName jn; + Token t = getToken(1); + int r1 = 0, r2 = -1; + boolean hasMax = false; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING_LITERAL: + image = StringLiteral(); + strlit = new RStringLiteral(); + strlit.line = t.beginLine; + strlit.column = t.beginColumn; + strlit.image = image; + c.member = strlit; + break; + case LANGLE: + jj_consume_token(LANGLE); + image = identifier(); + jj_consume_token(RANGLE); + jn = new RJustName(); + jn.line = t.beginLine; + jn.column = t.beginColumn; + jn.label = image; + c.member = jn; + break; + case LBRACKET: + case TILDE: + character_list(c); + break; + case LPAREN: + jj_consume_token(LPAREN); + complex_regular_expression_choices(c); + jj_consume_token(RPAREN); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACE: + case HOOK: + case PLUS: + case STAR: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PLUS: + jj_consume_token(PLUS); + ROneOrMore omrexp = new ROneOrMore(); + omrexp.line = t.beginLine; + omrexp.column = t.beginColumn; + omrexp.regexpr = (RegularExpression)c.member; + c.member = omrexp; + break; + case STAR: + jj_consume_token(STAR); + RZeroOrMore zmrexp = new RZeroOrMore(); + zmrexp.line = t.beginLine; + zmrexp.column = t.beginColumn; + zmrexp.regexpr = (RegularExpression)c.member; + c.member = zmrexp; + break; + case HOOK: + jj_consume_token(HOOK); + RZeroOrOne zorexp = new RZeroOrOne(); + zorexp.line = t.beginLine; + zorexp.column = t.beginColumn; + zorexp.regexpr = (RegularExpression)c.member; + c.member = zorexp; + break; + case LBRACE: + jj_consume_token(LBRACE); + r1 = IntegerLiteral(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + jj_consume_token(COMMA); + hasMax = true; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INTEGER_LITERAL: + r2 = IntegerLiteral(); + break; + default: + jj_la1[32] = jj_gen; + ; + } + break; + default: + jj_la1[33] = jj_gen; + ; + } + jj_consume_token(RBRACE); + RRepetitionRange rrrexp = new RRepetitionRange(); + rrrexp.line = t.beginLine; + rrrexp.column = t.beginColumn; + rrrexp.min = r1; + rrrexp.max = r2; + rrrexp.hasMax = hasMax; + rrrexp.regexpr = (RegularExpression)c.member; + c.member = rrrexp; + break; + default: + jj_la1[34] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[35] = jj_gen; + ; + } + break; + default: + jj_la1[36] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void character_list(Container c1) throws ParseException { + RCharacterList chlist = new RCharacterList(); + Token t = getToken(1); + chlist.line = t.beginLine; + chlist.column = t.beginColumn; + Container c2 = new Container(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case TILDE: + jj_consume_token(TILDE); + chlist.negated_list = true; + break; + default: + jj_la1[37] = jj_gen; + ; + } + jj_consume_token(LBRACKET); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING_LITERAL: + character_descriptor(c2); + chlist.descriptors.addElement(c2.member); + label_10: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[38] = jj_gen; + break label_10; + } + jj_consume_token(COMMA); + character_descriptor(c2); + chlist.descriptors.addElement(c2.member); + } + break; + default: + jj_la1[39] = jj_gen; + ; + } + jj_consume_token(RBRACKET); + c1.member = chlist; + } + + final public void character_descriptor(Container c) throws ParseException { + char c1, c2 = ' '; + boolean isrange = false; + String imageL, imageR; + Token t = getToken(1); + imageL = StringLiteral(); + c1 = character_descriptor_assign(getToken(0), imageL); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case MINUS: + jj_consume_token(MINUS); + imageR = StringLiteral(); + isrange = true; + c2 = character_descriptor_assign(getToken(0), imageR, imageL); + break; + default: + jj_la1[40] = jj_gen; + ; + } + if (isrange) { + CharacterRange cr = new CharacterRange(); + cr.line = t.beginLine; + cr.column = t.beginColumn; + cr.left = c1; + cr.right = c2; + c.member = cr; + } else { + SingleCharacter sc = new SingleCharacter(); + sc.line = t.beginLine; + sc.column = t.beginColumn; + sc.ch = c1; + c.member = sc; + } + } + + final public String identifier() throws ParseException { + Token t; + t = jj_consume_token(IDENTIFIER); + {if (true) return t.image;} + throw new Error("Missing return statement in function"); + } + +/********************************************** + * THE C# GRAMMAR SPECIFICATION STARTS HERE * + **********************************************/ + +/* + * The C# grammar is modified to use sequences of tokens + * for the missing tokens - those that include "<<" and ">>". + */ + +/* + * The following production defines C# identifiers - it + * includes the reserved words of CSJavaCC also. + */ + final public Token CSIdentifier() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENTIFIER: + jj_consume_token(IDENTIFIER); + break; + case _OPTIONS: + jj_consume_token(_OPTIONS); + break; + case _LOOKAHEAD: + jj_consume_token(_LOOKAHEAD); + break; + case _IGNORE_CASE: + jj_consume_token(_IGNORE_CASE); + break; + case _PARSER_BEGIN: + jj_consume_token(_PARSER_BEGIN); + break; + case _PARSER_END: + jj_consume_token(_PARSER_END); + break; + case _CSCODE: + jj_consume_token(_CSCODE); + break; + case _TOKEN: + jj_consume_token(_TOKEN); + break; + case _SPECIAL_TOKEN: + jj_consume_token(_SPECIAL_TOKEN); + break; + case _MORE: + jj_consume_token(_MORE); + break; + case _SKIP: + jj_consume_token(_SKIP); + break; + case _TOKEN_MGR_DECLS: + jj_consume_token(_TOKEN_MGR_DECLS); + break; + case _EOF: + jj_consume_token(_EOF); + break; + default: + jj_la1[41] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + Token retval = getToken(0); + retval.kind = IDENTIFIER; + {if (true) return retval;} + throw new Error("Missing return statement in function"); + } + +/* + * The productions for the missing code follows. Obviously + * these productions accept more than what is legal in Java, + * but that is OK for our purposes. + */ + final public void ShiftOps() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + jj_consume_token(LANGLE); + jj_consume_token(LANGLE); + break; + case RANGLE: + jj_consume_token(RANGLE); + jj_consume_token(RANGLE); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case RANGLE: + jj_consume_token(RANGLE); + break; + default: + jj_la1[42] = jj_gen; + ; + } + break; + default: + jj_la1[43] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void OtherAssignmentOps() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + jj_consume_token(LANGLE); + jj_consume_token(LE); + break; + case RANGLE: + jj_consume_token(RANGLE); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case RANGLE: + jj_consume_token(RANGLE); + break; + default: + jj_la1[44] = jj_gen; + ; + } + jj_consume_token(GE); + break; + default: + jj_la1[45] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + +/* + * Program structuring syntax follows. + */ + final public void CompilationUnit() throws ParseException { + set_initial_cu_token(getToken(1)); + System.out.println(getToken(1).image); + if (jj_2_7(2147483647)) { + NamespaceDeclaration(); + } else { + ; + } + label_11: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IMPORT: + ; + break; + default: + jj_la1[46] = jj_gen; + break label_11; + } + ImportDeclaration(); + } + label_12: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ABSTRACT: + case CLASS: + case OVERRIDE: + case INTERFACE: + case NEW: + case OUT: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case REF: + case STATIC: + case PARTIAL: + case INTERNAL: + case READONLY: + case FIXED: + case UNSAFE: + case SEMICOLON: + ; + break; + default: + jj_la1[47] = jj_gen; + break label_12; + } + TypeDeclaration(); + } + insertionpointerrors(getToken(1)); + } + + final public void NamespaceDeclaration() throws ParseException { + Modifiers(); + jj_consume_token(NAMESPACE); + Name(new Vector()); + jj_consume_token(SEMICOLON); + } + + final public void ImportDeclaration() throws ParseException { + jj_consume_token(IMPORT); + if (jj_2_8(2147483647)) { + NameType(new java.util.Vector()); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case IDENTIFIER: + Name(new java.util.Vector()); + break; + default: + jj_la1[48] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + jj_consume_token(SEMICOLON); + } + +/* + * Modifiers. We match all modifiers in a single rule to reduce the chances of + * syntax errors for simple modifier mistakes. It will also enable us to give + * better error messages. + */ + final public int Modifiers() throws ParseException { + int modifiers = 0; + label_13: + while (true) { + if (jj_2_9(2)) { + ; + } else { + break label_13; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PUBLIC: + jj_consume_token(PUBLIC); + modifiers |= ModifierSet.PUBLIC; + break; + case STATIC: + jj_consume_token(STATIC); + modifiers |= ModifierSet.STATIC; + break; + case PROTECTED: + jj_consume_token(PROTECTED); + modifiers |= ModifierSet.PROTECTED; + break; + case PRIVATE: + jj_consume_token(PRIVATE); + modifiers |= ModifierSet.PRIVATE; + break; + case OVERRIDE: + jj_consume_token(OVERRIDE); + modifiers |= ModifierSet.OVERRIDE; + break; + case PARTIAL: + jj_consume_token(PARTIAL); + modifiers |= ModifierSet.PARTIAL; + break; + case ABSTRACT: + jj_consume_token(ABSTRACT); + modifiers |= ModifierSet.ABSTRACT; + break; + case NEW: + jj_consume_token(NEW); + modifiers |= ModifierSet.NEW; + break; + case OUT: + jj_consume_token(OUT); + modifiers |= ModifierSet.OUT; + break; + case REF: + jj_consume_token(REF); + modifiers |= ModifierSet.REF; + break; + case INTERNAL: + jj_consume_token(INTERNAL); + modifiers |= ModifierSet.INTERNAL; + break; + case READONLY: + jj_consume_token(READONLY); + modifiers |= ModifierSet.READONLY; + break; + case FIXED: + jj_consume_token(FIXED); + modifiers |= ModifierSet.FIXED; + break; + case UNSAFE: + jj_consume_token(UNSAFE); + modifiers |= ModifierSet.UNSAFE; + break; + default: + jj_la1[49] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + {if (true) return modifiers;} + throw new Error("Missing return statement in function"); + } + +/* + * Declaration syntax follows. + */ + final public void TypeDeclaration() throws ParseException { + int modifiers; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case SEMICOLON: + jj_consume_token(SEMICOLON); + break; + case ABSTRACT: + case CLASS: + case OVERRIDE: + case INTERFACE: + case NEW: + case OUT: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case REF: + case STATIC: + case PARTIAL: + case INTERNAL: + case READONLY: + case FIXED: + case UNSAFE: + modifiers = Modifiers(); + ClassOrInterfaceDeclaration(modifiers, new Vector()); + break; + default: + jj_la1[50] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void ClassOrInterfaceDeclaration(int modifiers, Vector tokens) throws ParseException { + boolean isInterface = false; + class_nesting++; + Token t; + boolean is_parser_class = false; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case CLASS: + jj_consume_token(CLASS); + break; + case INTERFACE: + jj_consume_token(INTERFACE); + isInterface = true; + break; + default: + jj_la1[51] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + t = jj_consume_token(IDENTIFIER); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + TypeParameters(); + break; + default: + jj_la1[52] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COLON: + ExtendsList(isInterface); + break; + default: + jj_la1[53] = jj_gen; + ; + } + if (t.image.equals(parser_class_name) && class_nesting == 1 && processing_cu) { + is_parser_class = true; + setinsertionpoint(getToken(1), 1); + } + ClassOrInterfaceBody(isInterface, new Vector()); + if (is_parser_class) { + setinsertionpoint(getToken(0), 2); + } + class_nesting--; + } + + final public void DelegateDeclaration(int modifiers) throws ParseException { + jj_consume_token(DELEGATE); + ResultType(new Vector()); + jj_consume_token(IDENTIFIER); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + TypeParameters(); + break; + default: + jj_la1[54] = jj_gen; + ; + } + FormalParameters(new Vector()); + jj_consume_token(SEMICOLON); + } + + final public void ExtendsList(boolean isInterface) throws ParseException { + boolean extendsMoreThanOne = false; + jj_consume_token(COLON); + ClassOrInterfaceType(); + label_14: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[55] = jj_gen; + break label_14; + } + jj_consume_token(COMMA); + ClassOrInterfaceType(); + } + } + + final public void TypeParameters() throws ParseException { + jj_consume_token(LANGLE); + TypeParameter(); + label_15: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[56] = jj_gen; + break label_15; + } + jj_consume_token(COMMA); + TypeParameter(); + } + jj_consume_token(RANGLE); + } + + final public void TypeParameter() throws ParseException { + jj_consume_token(IDENTIFIER); + } + + final public void ClassOrInterfaceBody(boolean isInterface, Vector tokens) throws ParseException { + Token first, last; + jj_consume_token(LBRACE); + first = getToken(1); + label_16: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case DOUBLE: + case OVERRIDE: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NEW: + case OUT: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case REF: + case SHORT: + case STATIC: + case VOID: + case PARTIAL: + case INTERNAL: + case DELEGATE: + case READONLY: + case FIXED: + case UNSAFE: + case VAR: + case SEMICOLON: + case LANGLE: + case IDENTIFIER: + ; + break; + default: + jj_la1[57] = jj_gen; + break label_16; + } + ClassOrInterfaceBodyDeclaration(isInterface); + } + last = getToken(0); + jj_consume_token(RBRACE); + if (last.next != first) { // i.e., this is not an empty sequence + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + } + + final public void ClassOrInterfaceBodyDeclaration(boolean isInterface) throws ParseException { + boolean isNestedInterface = false; + int modifiers; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case DOUBLE: + case OVERRIDE: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NEW: + case OUT: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case REF: + case SHORT: + case STATIC: + case VOID: + case PARTIAL: + case INTERNAL: + case DELEGATE: + case READONLY: + case FIXED: + case UNSAFE: + case VAR: + case LANGLE: + case IDENTIFIER: + modifiers = Modifiers(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case CLASS: + case INTERFACE: + ClassOrInterfaceDeclaration(modifiers, new Vector()); + break; + case DELEGATE: + DelegateDeclaration(modifiers); + break; + default: + jj_la1[58] = jj_gen; + if (jj_2_10(2147483647)) { + ConstructorDeclaration(); + } else if (jj_2_11(2147483647)) { + FieldDeclaration(modifiers); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT: + case VOID: + case VAR: + case IDENTIFIER: + MethodDeclaration(modifiers); + break; + default: + jj_la1[59] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + break; + case SEMICOLON: + jj_consume_token(SEMICOLON); + break; + default: + jj_la1[60] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void FieldDeclaration(int modifiers) throws ParseException { + Type(); + VariableDeclaratorId(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case SEMICOLON: + case COMMA: + case ASSIGN: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ASSIGN: + jj_consume_token(ASSIGN); + VariableInitializer(); + break; + default: + jj_la1[61] = jj_gen; + ; + } + label_17: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[62] = jj_gen; + break label_17; + } + jj_consume_token(COMMA); + VariableDeclarator(); + } + jj_consume_token(SEMICOLON); + break; + case LBRACE: + jj_consume_token(LBRACE); + PropertyBody(); + jj_consume_token(RBRACE); + break; + default: + jj_la1[63] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void VariableDeclarator() throws ParseException { + VariableDeclaratorId(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ASSIGN: + jj_consume_token(ASSIGN); + VariableInitializer(); + break; + default: + jj_la1[64] = jj_gen; + ; + } + } + + final public void PropertyBody() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 135: + jj_consume_token(135); + Statement(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 136: + jj_consume_token(136); + Statement(); + break; + default: + jj_la1[65] = jj_gen; + ; + } + break; + case 136: + jj_consume_token(136); + Statement(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 135: + jj_consume_token(135); + Statement(); + break; + default: + jj_la1[66] = jj_gen; + ; + } + break; + default: + jj_la1[67] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void VariableDeclaratorId() throws ParseException { + jj_consume_token(IDENTIFIER); + label_18: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case DOT: + ; + break; + default: + jj_la1[68] = jj_gen; + break label_18; + } + jj_consume_token(DOT); + jj_consume_token(IDENTIFIER); + } + } + + final public void VariableInitializer() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACE: + ArrayInitializer(); + break; + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case DELEGATE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS: + case IDENTIFIER: + Expression(new Vector()); + break; + default: + jj_la1[69] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void ArrayInitializer() throws ParseException { + jj_consume_token(LBRACE); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case DELEGATE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case LBRACE: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS: + case IDENTIFIER: + VariableInitializer(); + label_19: + while (true) { + if (jj_2_12(2)) { + ; + } else { + break label_19; + } + jj_consume_token(COMMA); + VariableInitializer(); + } + break; + default: + jj_la1[70] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + jj_consume_token(COMMA); + break; + default: + jj_la1[71] = jj_gen; + ; + } + jj_consume_token(RBRACE); + } + + final public void MethodDeclaration(int modifiers) throws ParseException { + ResultType(new Vector()); + MethodDeclarator(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACE: + Block(new Vector()); + break; + case SEMICOLON: + jj_consume_token(SEMICOLON); + break; + default: + jj_la1[72] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void MethodDeclarator() throws ParseException { + jj_consume_token(IDENTIFIER); + label_20: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case DOT: + ; + break; + default: + jj_la1[73] = jj_gen; + break label_20; + } + jj_consume_token(DOT); + jj_consume_token(IDENTIFIER); + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + TypeParameters(); + break; + default: + jj_la1[74] = jj_gen; + ; + } + FormalParameters(new Vector()); + } + + final public void FormalParameters(Vector tokens) throws ParseException { + Token first, last; + jj_consume_token(LPAREN); + first = getToken(1); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case OVERRIDE: + case FLOAT: + case INT: + case LONG: + case NEW: + case OUT: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case REF: + case SHORT: + case STATIC: + case PARTIAL: + case INTERNAL: + case READONLY: + case FIXED: + case UNSAFE: + case VAR: + case IDENTIFIER: + FormalParameter(); + label_21: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[75] = jj_gen; + break label_21; + } + jj_consume_token(COMMA); + FormalParameter(); + } + break; + default: + jj_la1[76] = jj_gen; + ; + } + last = getToken(0); + jj_consume_token(RPAREN); + if (last.next != first) { // i.e., this is not an empty sequence + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + } + + final public void FormalParameter() throws ParseException { + Modifiers(); + Type(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 137: + jj_consume_token(137); + break; + default: + jj_la1[77] = jj_gen; + ; + } + VariableDeclaratorId(); + } + + final public void ConstructorDeclaration() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + TypeParameters(); + break; + default: + jj_la1[78] = jj_gen; + ; + } + jj_consume_token(IDENTIFIER); + FormalParameters(new Vector()); + jj_consume_token(LBRACE); + label_22: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case ABSTRACT: + case BOOLEAN: + case BREAK: + case BYTE: + case CHAR: + case CLASS: + case CONTINUE: + case DO: + case DOUBLE: + case FALSE: + case OVERRIDE: + case FLOAT: + case FOR: + case IF: + case IMPORT: + case INT: + case INTERFACE: + case LONG: + case NEW: + case NULL: + case OUT: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case REF: + case RETURN: + case SHORT: + case STATIC: + case BASE: + case SWITCH: + case THIS: + case THROW: + case TRUE: + case TRY: + case VOID: + case WHILE: + case FOREACH: + case PARTIAL: + case YIELD: + case INTERNAL: + case READONLY: + case FIXED: + case UNSAFE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case LBRACE: + case SEMICOLON: + case INCR: + case DECR: + case 143: + case IDENTIFIER: + ; + break; + default: + jj_la1[79] = jj_gen; + break label_22; + } + BlockStatement(); + } + jj_consume_token(RBRACE); + } + +/* + * Type, name and expression syntax follows. + */ + final public void Type() throws ParseException { + if (jj_2_13(2)) { + ReferenceType(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT: + case VAR: + PrimitiveType(); + break; + default: + jj_la1[80] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case HOOK: + jj_consume_token(HOOK); + break; + default: + jj_la1[81] = jj_gen; + ; + } + } + + final public void ReferenceType() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT: + case VAR: + PrimitiveType(); + label_23: + while (true) { + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + if (jj_2_14(2)) { + ; + } else { + break label_23; + } + } + break; + case IDENTIFIER: + ClassOrInterfaceType(); + label_24: + while (true) { + if (jj_2_15(2)) { + ; + } else { + break label_24; + } + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + } + break; + default: + jj_la1[82] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void ClassOrInterfaceType() throws ParseException { + jj_consume_token(IDENTIFIER); + if (jj_2_16(2)) { + TypeArguments(); + } else { + ; + } + label_25: + while (true) { + if (jj_2_17(2)) { + ; + } else { + break label_25; + } + jj_consume_token(DOT); + jj_consume_token(IDENTIFIER); + if (jj_2_18(2)) { + TypeArguments(); + } else { + ; + } + } + } + + final public void TypeArguments() throws ParseException { + jj_consume_token(LANGLE); + TypeArgument(); + label_26: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[83] = jj_gen; + break label_26; + } + jj_consume_token(COMMA); + TypeArgument(); + } + jj_consume_token(RANGLE); + } + + final public void TypeArgument() throws ParseException { + if (jj_2_19(2)) { + PrimitiveType(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT: + case VAR: + case IDENTIFIER: + ReferenceType(); + break; + default: + jj_la1[84] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + + final public void PrimitiveType() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BOOLEAN: + jj_consume_token(BOOLEAN); + break; + case CHAR: + jj_consume_token(CHAR); + break; + case BYTE: + jj_consume_token(BYTE); + break; + case SHORT: + jj_consume_token(SHORT); + break; + case INT: + jj_consume_token(INT); + break; + case LONG: + jj_consume_token(LONG); + break; + case FLOAT: + jj_consume_token(FLOAT); + break; + case DOUBLE: + jj_consume_token(DOUBLE); + break; + case VAR: + jj_consume_token(VAR); + break; + default: + jj_la1[85] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void ResultType(java.util.Vector tokens) throws ParseException { + Token first = getToken(1); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case VOID: + jj_consume_token(VOID); + break; + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT: + case VAR: + case IDENTIFIER: + Type(); + break; + default: + jj_la1[86] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + Token last = getToken(0); + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + + final public void NameType(java.util.Vector tokens) throws ParseException { + Token first = getToken(1); + CSIdentifier(); + jj_consume_token(ASSIGN); + Token last = getToken(0); + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + Name(tokens); + } + + final public void Name(java.util.Vector tokens) throws ParseException { + Token first = getToken(1); + CSIdentifier(); + label_27: + while (true) { + if (jj_2_20(2)) { + ; + } else { + break label_27; + } + jj_consume_token(DOT); + CSIdentifier(); + } + Token last = getToken(0); + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + + final public void NameList() throws ParseException { + Name(new Vector()); + label_28: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[87] = jj_gen; + break label_28; + } + jj_consume_token(COMMA); + Name(new Vector()); + } + } + +/* + * Expression syntax follows. + */ + final public void Expression(java.util.Vector tokens) throws ParseException { + Token first = getToken(1); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case DELEGATE: + AnonymousDelegate(); + break; + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS: + case IDENTIFIER: + ConditionalExpression(); + if (jj_2_21(2)) { + AssignmentOperator(); + Expression(new java.util.Vector()); + } else { + ; + } + Token last = getToken(0); + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + break; + default: + jj_la1[88] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void AnonymousDelegate() throws ParseException { + jj_consume_token(DELEGATE); + FormalParameters(new Vector()); + Block(new Vector()); + } + + final public void AssignmentOperator() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ASSIGN: + jj_consume_token(ASSIGN); + break; + case STARASSIGN: + jj_consume_token(STARASSIGN); + break; + case SLASHASSIGN: + jj_consume_token(SLASHASSIGN); + break; + case REMASSIGN: + jj_consume_token(REMASSIGN); + break; + case PLUSASSIGN: + jj_consume_token(PLUSASSIGN); + break; + case MINUSASSIGN: + jj_consume_token(MINUSASSIGN); + break; + case 138: + jj_consume_token(138); + break; + case 139: + jj_consume_token(139); + break; + case 140: + jj_consume_token(140); + break; + case ANDASSIGN: + jj_consume_token(ANDASSIGN); + break; + case XORASSIGN: + jj_consume_token(XORASSIGN); + break; + case ORASSIGN: + jj_consume_token(ORASSIGN); + break; + default: + jj_la1[89] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void ConditionalExpression() throws ParseException { + ConditionalOrExpression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case HOOK: + jj_consume_token(HOOK); + Expression(new Vector()); + jj_consume_token(COLON); + Expression(new Vector()); + break; + default: + jj_la1[90] = jj_gen; + ; + } + } + + final public void ConditionalOrExpression() throws ParseException { + ConditionalAndExpression(); + label_29: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case SC_OR: + ; + break; + default: + jj_la1[91] = jj_gen; + break label_29; + } + jj_consume_token(SC_OR); + ConditionalAndExpression(); + } + } + + final public void ConditionalAndExpression() throws ParseException { + InclusiveOrExpression(); + label_30: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case SC_AND: + ; + break; + default: + jj_la1[92] = jj_gen; + break label_30; + } + jj_consume_token(SC_AND); + InclusiveOrExpression(); + } + } + + final public void InclusiveOrExpression() throws ParseException { + ExclusiveOrExpression(); + label_31: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BIT_OR: + ; + break; + default: + jj_la1[93] = jj_gen; + break label_31; + } + jj_consume_token(BIT_OR); + ExclusiveOrExpression(); + } + } + + final public void ExclusiveOrExpression() throws ParseException { + AndExpression(); + label_32: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case XOR: + ; + break; + default: + jj_la1[94] = jj_gen; + break label_32; + } + jj_consume_token(XOR); + AndExpression(); + } + } + + final public void AndExpression() throws ParseException { + EqualityExpression(); + label_33: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BIT_AND: + ; + break; + default: + jj_la1[95] = jj_gen; + break label_33; + } + jj_consume_token(BIT_AND); + EqualityExpression(); + } + } + + final public void EqualityExpression() throws ParseException { + InstanceOfExpression(); + label_34: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case EQ: + case NE: + ; + break; + default: + jj_la1[96] = jj_gen; + break label_34; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case EQ: + jj_consume_token(EQ); + break; + case NE: + jj_consume_token(NE); + break; + default: + jj_la1[97] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + InstanceOfExpression(); + } + } + + final public void InstanceOfExpression() throws ParseException { + RelationalExpression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 141: + jj_consume_token(141); + Type(); + break; + default: + jj_la1[98] = jj_gen; + ; + } + } + + final public void RelationalExpression() throws ParseException { + ShiftExpression(); + label_35: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + case LE: + case GE: + case RANGLE: + ; + break; + default: + jj_la1[99] = jj_gen; + break label_35; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + jj_consume_token(LANGLE); + break; + case RANGLE: + jj_consume_token(RANGLE); + break; + case LE: + jj_consume_token(LE); + break; + case GE: + jj_consume_token(GE); + break; + default: + jj_la1[100] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + ShiftExpression(); + } + } + + final public void ShiftExpression() throws ParseException { + AdditiveExpression(); + label_36: + while (true) { + if (jj_2_22(1)) { + ; + } else { + break label_36; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 142: + jj_consume_token(142); + break; + default: + jj_la1[101] = jj_gen; + if (jj_2_23(1)) { + RSIGNEDSHIFT(); + } else if (jj_2_24(1)) { + RUNSIGNEDSHIFT(); + } else { + jj_consume_token(-1); + throw new ParseException(); + } + } + AdditiveExpression(); + } + } + + final public void AdditiveExpression() throws ParseException { + MultiplicativeExpression(); + label_37: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PLUS: + case MINUS: + ; + break; + default: + jj_la1[102] = jj_gen; + break label_37; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PLUS: + jj_consume_token(PLUS); + break; + case MINUS: + jj_consume_token(MINUS); + break; + default: + jj_la1[103] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + MultiplicativeExpression(); + } + } + + final public void MultiplicativeExpression() throws ParseException { + UnaryExpression(); + label_38: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STAR: + case SLASH: + case REM: + ; + break; + default: + jj_la1[104] = jj_gen; + break label_38; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STAR: + jj_consume_token(STAR); + break; + case SLASH: + jj_consume_token(SLASH); + break; + case REM: + jj_consume_token(REM); + break; + default: + jj_la1[105] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + UnaryExpression(); + } + } + + final public void UnaryExpression() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PLUS: + case MINUS: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case PLUS: + jj_consume_token(PLUS); + break; + case MINUS: + jj_consume_token(MINUS); + break; + default: + jj_la1[106] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + UnaryExpression(); + break; + case INCR: + PreIncrementExpression(); + break; + case DECR: + PreDecrementExpression(); + break; + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case BANG: + case TILDE: + case IDENTIFIER: + UnaryExpressionNotPlusMinus(); + break; + default: + jj_la1[107] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void PreIncrementExpression() throws ParseException { + jj_consume_token(INCR); + PrimaryExpression(); + } + + final public void PreDecrementExpression() throws ParseException { + jj_consume_token(DECR); + PrimaryExpression(); + } + + final public void UnaryExpressionNotPlusMinus() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case BANG: + case TILDE: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case TILDE: + jj_consume_token(TILDE); + break; + case BANG: + jj_consume_token(BANG); + break; + default: + jj_la1[108] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + UnaryExpression(); + break; + default: + jj_la1[109] = jj_gen; + if (jj_2_25(2147483647)) { + CastExpression(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case IDENTIFIER: + PostfixExpression(); + break; + default: + jj_la1[110] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + } + +// This production is to determine lookahead only. The LOOKAHEAD specifications +// below are not used, but they are there just to indicate that we know about +// this. + final public void CastLookahead() throws ParseException { + if (jj_2_26(2)) { + jj_consume_token(LPAREN); + PrimitiveType(); + } else if (jj_2_27(2147483647)) { + jj_consume_token(LPAREN); + Type(); + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LPAREN: + jj_consume_token(LPAREN); + Type(); + jj_consume_token(RPAREN); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case TILDE: + jj_consume_token(TILDE); + break; + case BANG: + jj_consume_token(BANG); + break; + case LPAREN: + jj_consume_token(LPAREN); + break; + case IDENTIFIER: + jj_consume_token(IDENTIFIER); + break; + case THIS: + jj_consume_token(THIS); + break; + case BASE: + jj_consume_token(BASE); + break; + case NEW: + jj_consume_token(NEW); + break; + case FALSE: + case NULL: + case TRUE: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + Literal(); + break; + default: + jj_la1[111] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[112] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + + final public void PostfixExpression() throws ParseException { + PrimaryExpression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INCR: + case DECR: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INCR: + jj_consume_token(INCR); + break; + case DECR: + jj_consume_token(DECR); + break; + default: + jj_la1[113] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[114] = jj_gen; + ; + } + } + + final public void CastExpression() throws ParseException { + if (jj_2_28(2147483647)) { + jj_consume_token(LPAREN); + Type(); + jj_consume_token(RPAREN); + UnaryExpression(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LPAREN: + jj_consume_token(LPAREN); + Type(); + jj_consume_token(RPAREN); + UnaryExpressionNotPlusMinus(); + break; + default: + jj_la1[115] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + + final public void PrimaryExpression() throws ParseException { + PrimaryPrefix(); + label_39: + while (true) { + if (jj_2_29(2)) { + ; + } else { + break label_39; + } + PrimarySuffix(); + } + } + + final public void MemberSelector() throws ParseException { + jj_consume_token(DOT); + TypeArguments(); + jj_consume_token(IDENTIFIER); + } + + final public void PrimaryPrefix() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case FALSE: + case NULL: + case TRUE: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + Literal(); + break; + case THIS: + jj_consume_token(THIS); + break; + case BASE: + jj_consume_token(BASE); + jj_consume_token(DOT); + jj_consume_token(IDENTIFIER); + break; + case LPAREN: + jj_consume_token(LPAREN); + Expression(new Vector()); + jj_consume_token(RPAREN); + break; + case NEW: + AllocationExpression(); + break; + default: + jj_la1[116] = jj_gen; + if (jj_2_30(2147483647)) { + ResultType(new Vector()); + jj_consume_token(DOT); + jj_consume_token(CLASS); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case IDENTIFIER: + Name(new Vector()); + break; + default: + jj_la1[117] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + } + + final public void PrimarySuffix() throws ParseException { + if (jj_2_31(2)) { + jj_consume_token(DOT); + jj_consume_token(THIS); + } else if (jj_2_32(2)) { + jj_consume_token(DOT); + AllocationExpression(); + } else if (jj_2_33(3)) { + MemberSelector(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACKET: + jj_consume_token(LBRACKET); + Expression(new Vector()); + jj_consume_token(RBRACKET); + break; + case DOT: + jj_consume_token(DOT); + jj_consume_token(IDENTIFIER); + break; + case LPAREN: + Arguments(new Vector()); + break; + default: + jj_la1[118] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + + final public void Literal() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INTEGER_LITERAL: + jj_consume_token(INTEGER_LITERAL); + break; + case FLOATING_POINT_LITERAL: + jj_consume_token(FLOATING_POINT_LITERAL); + break; + case CHARACTER_LITERAL: + jj_consume_token(CHARACTER_LITERAL); + break; + case STRING_LITERAL: + jj_consume_token(STRING_LITERAL); + break; + case FALSE: + case TRUE: + BooleanLiteral(); + break; + case NULL: + NullLiteral(); + break; + default: + jj_la1[119] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public int IntegerLiteral() throws ParseException { + jj_consume_token(INTEGER_LITERAL); + try { + {if (true) return Integer.parseInt(token.image);} + } catch (NumberFormatException e) { + {if (true) throw new Error();} + } + throw new Error("Missing return statement in function"); + } + + final public boolean BooleanLiteral() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case TRUE: + jj_consume_token(TRUE); + {if (true) return true;} + break; + case FALSE: + jj_consume_token(FALSE); + {if (true) return false;} + break; + default: + jj_la1[120] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + throw new Error("Missing return statement in function"); + } + + final public String StringLiteral() throws ParseException { + Token t; + t = jj_consume_token(STRING_LITERAL); + {if (true) return remove_escapes_and_quotes(t, t.image);} + throw new Error("Missing return statement in function"); + } + + final public void NullLiteral() throws ParseException { + jj_consume_token(NULL); + } + + final public void Arguments(java.util.Vector tokens) throws ParseException { + Token first, last; + jj_consume_token(LPAREN); + first = getToken(1); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case DELEGATE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS: + case IDENTIFIER: + ArgumentList(); + break; + default: + jj_la1[121] = jj_gen; + ; + } + last = getToken(0); + jj_consume_token(RPAREN); + if (last.next != first) { // i.e., this is not an empty sequence + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + } + + final public void ArgumentList() throws ParseException { + Expression(new Vector()); + label_40: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[122] = jj_gen; + break label_40; + } + jj_consume_token(COMMA); + Expression(new Vector()); + } + } + + final public void AllocationExpression() throws ParseException { + if (jj_2_34(2)) { + jj_consume_token(NEW); + PrimitiveType(); + ArrayDimsAndInits(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case NEW: + jj_consume_token(NEW); + ClassOrInterfaceType(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LANGLE: + TypeArguments(); + break; + default: + jj_la1[123] = jj_gen; + ; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACKET: + ArrayDimsAndInits(); + break; + case LPAREN: + Arguments(new Vector()); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACE: + ClassOrInterfaceBody(false, new Vector()); + break; + default: + jj_la1[124] = jj_gen; + ; + } + break; + default: + jj_la1[125] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[126] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + +/* + * The third LOOKAHEAD specification below is to parse to PrimarySuffix + * if there is an expression between the "[...]". + */ + final public void ArrayDimsAndInits() throws ParseException { + if (jj_2_37(2)) { + label_41: + while (true) { + jj_consume_token(LBRACKET); + Expression(new Vector()); + jj_consume_token(RBRACKET); + if (jj_2_35(2)) { + ; + } else { + break label_41; + } + } + label_42: + while (true) { + if (jj_2_36(2)) { + ; + } else { + break label_42; + } + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + } + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACKET: + label_43: + while (true) { + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACKET: + ; + break; + default: + jj_la1[127] = jj_gen; + break label_43; + } + } + ArrayInitializer(); + break; + default: + jj_la1[128] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + +/* + * Statement syntax follows. + */ + final public void Statement() throws ParseException { + if (jj_2_38(2)) { + LabeledStatement(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case LBRACE: + Block(new Vector()); + break; + case UNSAFE: + UnsafeStatment(); + break; + case SEMICOLON: + EmptyStatement(); + break; + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case INCR: + case DECR: + case IDENTIFIER: + StatementExpression(); + jj_consume_token(SEMICOLON); + break; + case SWITCH: + SwitchStatement(); + break; + case IF: + IfStatement(); + break; + case WHILE: + WhileStatement(); + break; + case IMPORT: + UsingStatement(); + break; + case 143: + LockStatement(); + break; + case DO: + DoStatement(); + break; + case FOR: + ForStatement(); + break; + case FOREACH: + ForEachStatement(); + break; + case BREAK: + BreakStatement(); + break; + case CONTINUE: + ContinueStatement(); + break; + case RETURN: + case YIELD: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case YIELD: + jj_consume_token(YIELD); + break; + default: + jj_la1[129] = jj_gen; + ; + } + ReturnStatement(); + break; + case THROW: + ThrowStatement(); + break; + case TRY: + TryStatement(); + break; + default: + jj_la1[130] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + +/*void AssertStatement(): +{} +{ "assert" Expression(new Vector()) [ ":" Expression(new Vector()) ] ";" } +*/ + final public void LabeledStatement() throws ParseException { + jj_consume_token(IDENTIFIER); + jj_consume_token(COLON); + Statement(); + } + +// Unsafe Block + final public void UnsafeStatment() throws ParseException { + jj_consume_token(UNSAFE); + Block(new Vector()); + } + + final public void Block(java.util.Vector tokens) throws ParseException { + Token first, last; + jj_consume_token(LBRACE); + first = getToken(1); + label_44: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case ABSTRACT: + case BOOLEAN: + case BREAK: + case BYTE: + case CHAR: + case CLASS: + case CONTINUE: + case DO: + case DOUBLE: + case FALSE: + case OVERRIDE: + case FLOAT: + case FOR: + case IF: + case IMPORT: + case INT: + case INTERFACE: + case LONG: + case NEW: + case NULL: + case OUT: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case REF: + case RETURN: + case SHORT: + case STATIC: + case BASE: + case SWITCH: + case THIS: + case THROW: + case TRUE: + case TRY: + case VOID: + case WHILE: + case FOREACH: + case PARTIAL: + case YIELD: + case INTERNAL: + case READONLY: + case FIXED: + case UNSAFE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case LBRACE: + case SEMICOLON: + case INCR: + case DECR: + case 143: + case IDENTIFIER: + ; + break; + default: + jj_la1[131] = jj_gen; + break label_44; + } + BlockStatement(); + } + last = getToken(0); + jj_consume_token(RBRACE); + if (last.next != first) { // i.e., this is not an empty sequence + Token t = first; + while (true) { + tokens.addElement(t); + if (t == last) break; + t = t.next; + } + } + } + + final public void BlockStatement() throws ParseException { + if (jj_2_39(2147483647)) { + LocalVariableDeclaration(); + jj_consume_token(SEMICOLON); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BREAK: + case BYTE: + case CHAR: + case CONTINUE: + case DO: + case DOUBLE: + case FALSE: + case FLOAT: + case FOR: + case IF: + case IMPORT: + case INT: + case LONG: + case NEW: + case NULL: + case RETURN: + case SHORT: + case BASE: + case SWITCH: + case THIS: + case THROW: + case TRUE: + case TRY: + case VOID: + case WHILE: + case FOREACH: + case YIELD: + case UNSAFE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case LBRACE: + case SEMICOLON: + case INCR: + case DECR: + case 143: + case IDENTIFIER: + Statement(); + break; + case CLASS: + case INTERFACE: + ClassOrInterfaceDeclaration(0, new Vector()); + break; + default: + jj_la1[132] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + + final public void LocalVariableDeclaration() throws ParseException { + Modifiers(); + Type(); + VariableDeclarator(); + label_45: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[133] = jj_gen; + break label_45; + } + jj_consume_token(COMMA); + VariableDeclarator(); + } + } + + final public void EmptyStatement() throws ParseException { + jj_consume_token(SEMICOLON); + } + + final public void StatementExpression() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INCR: + PreIncrementExpression(); + break; + case DECR: + PreDecrementExpression(); + break; + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case IDENTIFIER: + PrimaryExpression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ASSIGN: + case INCR: + case DECR: + case PLUSASSIGN: + case MINUSASSIGN: + case STARASSIGN: + case SLASHASSIGN: + case ANDASSIGN: + case ORASSIGN: + case XORASSIGN: + case REMASSIGN: + case 138: + case 139: + case 140: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case INCR: + jj_consume_token(INCR); + break; + case DECR: + jj_consume_token(DECR); + break; + case ASSIGN: + case PLUSASSIGN: + case MINUSASSIGN: + case STARASSIGN: + case SLASHASSIGN: + case ANDASSIGN: + case ORASSIGN: + case XORASSIGN: + case REMASSIGN: + case 138: + case 139: + case 140: + AssignmentOperator(); + Expression(new Vector()); + break; + default: + jj_la1[134] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[135] = jj_gen; + ; + } + break; + default: + jj_la1[136] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void SwitchStatement() throws ParseException { + jj_consume_token(SWITCH); + jj_consume_token(LPAREN); + Expression(new Vector()); + jj_consume_token(RPAREN); + jj_consume_token(LBRACE); + label_46: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case CASE: + case _DEFAULT: + ; + break; + default: + jj_la1[137] = jj_gen; + break label_46; + } + SwitchLabel(); + label_47: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case ABSTRACT: + case BOOLEAN: + case BREAK: + case BYTE: + case CHAR: + case CLASS: + case CONTINUE: + case DO: + case DOUBLE: + case FALSE: + case OVERRIDE: + case FLOAT: + case FOR: + case IF: + case IMPORT: + case INT: + case INTERFACE: + case LONG: + case NEW: + case NULL: + case OUT: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case REF: + case RETURN: + case SHORT: + case STATIC: + case BASE: + case SWITCH: + case THIS: + case THROW: + case TRUE: + case TRY: + case VOID: + case WHILE: + case FOREACH: + case PARTIAL: + case YIELD: + case INTERNAL: + case READONLY: + case FIXED: + case UNSAFE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case LBRACE: + case SEMICOLON: + case INCR: + case DECR: + case 143: + case IDENTIFIER: + ; + break; + default: + jj_la1[138] = jj_gen; + break label_47; + } + BlockStatement(); + } + } + jj_consume_token(RBRACE); + } + + final public void SwitchLabel() throws ParseException { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case CASE: + jj_consume_token(CASE); + Expression(new Vector()); + jj_consume_token(COLON); + break; + case _DEFAULT: + jj_consume_token(_DEFAULT); + jj_consume_token(COLON); + break; + default: + jj_la1[139] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + + final public void IfStatement() throws ParseException { + jj_consume_token(IF); + jj_consume_token(LPAREN); + Expression(new Vector()); + jj_consume_token(RPAREN); + Statement(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ELSE: + jj_consume_token(ELSE); + Statement(); + break; + default: + jj_la1[140] = jj_gen; + ; + } + } + + final public void WhileStatement() throws ParseException { + jj_consume_token(WHILE); + jj_consume_token(LPAREN); + Expression(new Vector()); + jj_consume_token(RPAREN); + Statement(); + } + + final public void UsingStatement() throws ParseException { + jj_consume_token(IMPORT); + jj_consume_token(LPAREN); + Expression(new Vector()); + jj_consume_token(RPAREN); + Statement(); + } + + final public void LockStatement() throws ParseException { + jj_consume_token(143); + jj_consume_token(LPAREN); + Expression(new Vector()); + jj_consume_token(RPAREN); + Statement(); + } + + final public void DoStatement() throws ParseException { + jj_consume_token(DO); + Statement(); + jj_consume_token(WHILE); + jj_consume_token(LPAREN); + Expression(new Vector()); + jj_consume_token(RPAREN); + jj_consume_token(SEMICOLON); + } + + final public void ForStatement() throws ParseException { + jj_consume_token(FOR); + jj_consume_token(LPAREN); + if (jj_2_40(2147483647)) { + Modifiers(); + Type(); + jj_consume_token(IDENTIFIER); + jj_consume_token(COLON); + Expression(new Vector()); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case OVERRIDE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case OUT: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case REF: + case SHORT: + case STATIC: + case BASE: + case THIS: + case TRUE: + case VOID: + case PARTIAL: + case INTERNAL: + case READONLY: + case FIXED: + case UNSAFE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case SEMICOLON: + case INCR: + case DECR: + case IDENTIFIER: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case OVERRIDE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case OUT: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case REF: + case SHORT: + case STATIC: + case BASE: + case THIS: + case TRUE: + case VOID: + case PARTIAL: + case INTERNAL: + case READONLY: + case FIXED: + case UNSAFE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case INCR: + case DECR: + case IDENTIFIER: + ForInit(); + break; + default: + jj_la1[141] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case DELEGATE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS: + case IDENTIFIER: + Expression(new Vector()); + break; + default: + jj_la1[142] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case INCR: + case DECR: + case IDENTIFIER: + ForUpdate(); + break; + default: + jj_la1[143] = jj_gen; + ; + } + break; + default: + jj_la1[144] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + jj_consume_token(RPAREN); + Statement(); + } + + final public void ForInit() throws ParseException { + if (jj_2_41(2147483647)) { + LocalVariableDeclaration(); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case INCR: + case DECR: + case IDENTIFIER: + StatementExpressionList(); + break; + default: + jj_la1[145] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + + final public void ForEachStatement() throws ParseException { + jj_consume_token(FOREACH); + jj_consume_token(LPAREN); + Modifiers(); + Type(); + jj_consume_token(IDENTIFIER); + jj_consume_token(144); + Expression(new Vector()); + jj_consume_token(RPAREN); + Statement(); + } + + final public void StatementExpressionList() throws ParseException { + StatementExpression(); + label_48: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMA: + ; + break; + default: + jj_la1[146] = jj_gen; + break label_48; + } + jj_consume_token(COMMA); + StatementExpression(); + } + } + + final public void ForUpdate() throws ParseException { + StatementExpressionList(); + } + + final public void BreakStatement() throws ParseException { + jj_consume_token(BREAK); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENTIFIER: + jj_consume_token(IDENTIFIER); + break; + default: + jj_la1[147] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); + } + + final public void ContinueStatement() throws ParseException { + jj_consume_token(CONTINUE); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENTIFIER: + jj_consume_token(IDENTIFIER); + break; + default: + jj_la1[148] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); + } + + final public void ReturnStatement() throws ParseException { + Token t; + // Iterator Yield + //[ "yield" ] + t = jj_consume_token(RETURN); + // Add if statement to prevent subsequent code generated + // from being dead code. + if (inAction) { + t.image = "{if (true) return"; + jumpPatched = true; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _CSCODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case BASE: + case THIS: + case TRUE: + case VOID: + case DELEGATE: + case VAR: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case LPAREN: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS: + case IDENTIFIER: + Expression(new java.util.Vector()); + break; + default: + jj_la1[149] = jj_gen; + ; + } + t = jj_consume_token(SEMICOLON); + // Add closing brace for above if statement. + if (inAction) { + t.image = ";}"; + } + } + + final public void ThrowStatement() throws ParseException { + Token t; + t = jj_consume_token(THROW); + // Add if statement to prevent subsequent code generated + // from being dead code. + if (inAction) { + t.image = "{if (true) throw"; + jumpPatched = true; + } + Expression(new java.util.Vector()); + t = jj_consume_token(SEMICOLON); + // Add closing brace for above if statement. + if (inAction) { + t.image = ";}"; + } + } + + final public void TryStatement() throws ParseException { + jj_consume_token(TRY); + Block(new Vector()); + label_49: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case CATCH: + ; + break; + default: + jj_la1[150] = jj_gen; + break label_49; + } + jj_consume_token(CATCH); + jj_consume_token(LPAREN); + FormalParameter(); + jj_consume_token(RPAREN); + Block(new Vector()); + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 145: + jj_consume_token(145); + Block(new Vector()); + break; + default: + jj_la1[151] = jj_gen; + ; + } + } + +/* We use productions to match >>>, >> and > so that we can keep the + * type declaration syntax with generics clean + */ + final public void RUNSIGNEDSHIFT() throws ParseException { + if (getToken(1).kind == GT && + ((Token.GTToken)getToken(1)).realKind == RUNSIGNEDSHIFT) { + + } else { + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(RANGLE); + jj_consume_token(RANGLE); + jj_consume_token(RANGLE); + } + + final public void RSIGNEDSHIFT() throws ParseException { + if (getToken(1).kind == GT && + ((Token.GTToken)getToken(1)).realKind == RSIGNEDSHIFT) { + + } else { + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(RANGLE); + jj_consume_token(RANGLE); + } + + final private boolean jj_2_1(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_1(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + final private boolean jj_2_2(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_2(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(1, xla); } + } + + final private boolean jj_2_3(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_3(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(2, xla); } + } + + final private boolean jj_2_4(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_4(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(3, xla); } + } + + final private boolean jj_2_5(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_5(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(4, xla); } + } + + final private boolean jj_2_6(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_6(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(5, xla); } + } + + final private boolean jj_2_7(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_7(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(6, xla); } + } + + final private boolean jj_2_8(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_8(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(7, xla); } + } + + final private boolean jj_2_9(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_9(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(8, xla); } + } + + final private boolean jj_2_10(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_10(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(9, xla); } + } + + final private boolean jj_2_11(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_11(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(10, xla); } + } + + final private boolean jj_2_12(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_12(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(11, xla); } + } + + final private boolean jj_2_13(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_13(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(12, xla); } + } + + final private boolean jj_2_14(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_14(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(13, xla); } + } + + final private boolean jj_2_15(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_15(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(14, xla); } + } + + final private boolean jj_2_16(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_16(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(15, xla); } + } + + final private boolean jj_2_17(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_17(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(16, xla); } + } + + final private boolean jj_2_18(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_18(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(17, xla); } + } + + final private boolean jj_2_19(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_19(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(18, xla); } + } + + final private boolean jj_2_20(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_20(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(19, xla); } + } + + final private boolean jj_2_21(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_21(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(20, xla); } + } + + final private boolean jj_2_22(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_22(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(21, xla); } + } + + final private boolean jj_2_23(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_23(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(22, xla); } + } + + final private boolean jj_2_24(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_24(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(23, xla); } + } + + final private boolean jj_2_25(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_25(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(24, xla); } + } + + final private boolean jj_2_26(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_26(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(25, xla); } + } + + final private boolean jj_2_27(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_27(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(26, xla); } + } + + final private boolean jj_2_28(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_28(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(27, xla); } + } + + final private boolean jj_2_29(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_29(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(28, xla); } + } + + final private boolean jj_2_30(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_30(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(29, xla); } + } + + final private boolean jj_2_31(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_31(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(30, xla); } + } + + final private boolean jj_2_32(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_32(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(31, xla); } + } + + final private boolean jj_2_33(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_33(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(32, xla); } + } + + final private boolean jj_2_34(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_34(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(33, xla); } + } + + final private boolean jj_2_35(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_35(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(34, xla); } + } + + final private boolean jj_2_36(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_36(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(35, xla); } + } + + final private boolean jj_2_37(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_37(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(36, xla); } + } + + final private boolean jj_2_38(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_38(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(37, xla); } + } + + final private boolean jj_2_39(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_39(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(38, xla); } + } + + final private boolean jj_2_40(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_40(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(39, xla); } + } + + final private boolean jj_2_41(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_41(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(40, xla); } + } + + final private boolean jj_3R_229() { + if (jj_scan_token(THROW)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + final private boolean jj_3R_250() { + if (jj_3R_96()) return true; + return false; + } + + final private boolean jj_3R_265() { + if (jj_3R_277()) return true; + return false; + } + + final private boolean jj_3R_245() { + if (jj_3R_81()) return true; + return false; + } + + final private boolean jj_3R_122() { + if (jj_scan_token(COMMA)) return true; + if (jj_scan_token(146)) return true; + return false; + } + + final private boolean jj_3R_291() { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_217()) return true; + return false; + } + + final private boolean jj_3R_173() { + if (jj_3R_179()) return true; + return false; + } + + final private boolean jj_3R_164() { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_173()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + final private boolean jj_3R_228() { + if (jj_scan_token(RETURN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_245()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + final private boolean jj_3R_227() { + if (jj_scan_token(CONTINUE)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(146)) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + final private boolean jj_3R_96() { + if (jj_scan_token(LANGLE)) return true; + if (jj_scan_token(146)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_122()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RANGLE)) return true; + return false; + } + + final private boolean jj_3R_226() { + if (jj_scan_token(BREAK)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(146)) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + final private boolean jj_3R_248() { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_124()) return true; + return false; + } + + final private boolean jj_3R_242() { + if (jj_scan_token(ELSE)) return true; + if (jj_3R_182()) return true; + return false; + } + + final private boolean jj_3R_277() { + if (jj_3R_286()) return true; + return false; + } + + final private boolean jj_3R_231() { + if (jj_scan_token(COLON)) return true; + if (jj_3R_124()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_248()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_264() { + if (jj_3R_81()) return true; + return false; + } + + final private boolean jj_3R_286() { + if (jj_3R_217()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_291()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3_41() { + if (jj_3R_90()) return true; + if (jj_3R_73()) return true; + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + final private boolean jj_3R_233() { + if (jj_scan_token(DELEGATE)) return true; + if (jj_3R_86()) return true; + if (jj_scan_token(IDENTIFIER)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_250()) jj_scanpos = xsp; + if (jj_3R_151()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + final private boolean jj_3R_225() { + if (jj_scan_token(FOREACH)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_90()) return true; + if (jj_3R_73()) return true; + if (jj_scan_token(IDENTIFIER)) return true; + if (jj_scan_token(144)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_182()) return true; + return false; + } + + final private boolean jj_3_40() { + if (jj_3R_90()) return true; + if (jj_3R_73()) return true; + if (jj_scan_token(IDENTIFIER)) return true; + if (jj_scan_token(COLON)) return true; + return false; + } + + final private boolean jj_3R_285() { + if (jj_3R_286()) return true; + return false; + } + + final private boolean jj_3R_284() { + if (jj_3R_181()) return true; + return false; + } + + final private boolean jj_3R_276() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_284()) { + jj_scanpos = xsp; + if (jj_3R_285()) return true; + } + return false; + } + + final private boolean jj_3R_205() { + if (jj_scan_token(INTERFACE)) return true; + return false; + } + + final private boolean jj_3R_263() { + if (jj_3R_276()) return true; + return false; + } + + final private boolean jj_3R_244() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_263()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + xsp = jj_scanpos; + if (jj_3R_264()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + xsp = jj_scanpos; + if (jj_3R_265()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_243() { + if (jj_3R_90()) return true; + if (jj_3R_73()) return true; + if (jj_scan_token(IDENTIFIER)) return true; + if (jj_scan_token(COLON)) return true; + if (jj_3R_81()) return true; + return false; + } + + final private boolean jj_3R_207() { + if (jj_3R_231()) return true; + return false; + } + + final private boolean jj_3R_206() { + if (jj_3R_96()) return true; + return false; + } + + final private boolean jj_3R_224() { + if (jj_scan_token(FOR)) return true; + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_243()) { + jj_scanpos = xsp; + if (jj_3R_244()) return true; + } + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_182()) return true; + return false; + } + + final private boolean jj_3R_183() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(35)) { + jj_scanpos = xsp; + if (jj_3R_205()) return true; + } + if (jj_scan_token(IDENTIFIER)) return true; + xsp = jj_scanpos; + if (jj_3R_206()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_207()) jj_scanpos = xsp; + if (jj_3R_164()) return true; + return false; + } + + final private boolean jj_3R_223() { + if (jj_scan_token(DO)) return true; + if (jj_3R_182()) return true; + if (jj_scan_token(WHILE)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + final private boolean jj_3R_222() { + if (jj_scan_token(143)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_182()) return true; + return false; + } + + final private boolean jj_3R_221() { + if (jj_scan_token(IMPORT)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_182()) return true; + return false; + } + + final private boolean jj_3R_220() { + if (jj_scan_token(WHILE)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_182()) return true; + return false; + } + + final private boolean jj_3R_262() { + if (jj_3R_170()) return true; + return false; + } + + final private boolean jj_3R_188() { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_187()) return true; + return false; + } + + final private boolean jj_3R_219() { + if (jj_scan_token(IF)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_182()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_242()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_275() { + if (jj_scan_token(_DEFAULT)) return true; + if (jj_scan_token(COLON)) return true; + return false; + } + + final private boolean jj_3R_274() { + if (jj_scan_token(CASE)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(COLON)) return true; + return false; + } + + final private boolean jj_3R_261() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_274()) { + jj_scanpos = xsp; + if (jj_3R_275()) return true; + } + return false; + } + + final private boolean jj_3R_241() { + if (jj_3R_261()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_262()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_71() { + if (jj_scan_token(UNSAFE)) return true; + return false; + } + + final private boolean jj_3R_70() { + if (jj_scan_token(FIXED)) return true; + return false; + } + + final private boolean jj_3R_69() { + if (jj_scan_token(READONLY)) return true; + return false; + } + + final private boolean jj_3R_218() { + if (jj_scan_token(SWITCH)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_scan_token(LBRACE)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_241()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + final private boolean jj_3R_68() { + if (jj_scan_token(INTERNAL)) return true; + return false; + } + + final private boolean jj_3R_67() { + if (jj_scan_token(REF)) return true; + return false; + } + + final private boolean jj_3R_66() { + if (jj_scan_token(OUT)) return true; + return false; + } + + final private boolean jj_3R_65() { + if (jj_scan_token(NEW)) return true; + return false; + } + + final private boolean jj_3R_273() { + if (jj_3R_80()) return true; + if (jj_3R_81()) return true; + return false; + } + + final private boolean jj_3R_64() { + if (jj_scan_token(ABSTRACT)) return true; + return false; + } + + final private boolean jj_3R_63() { + if (jj_scan_token(PARTIAL)) return true; + return false; + } + + final private boolean jj_3R_260() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(113)) { + jj_scanpos = xsp; + if (jj_scan_token(114)) { + jj_scanpos = xsp; + if (jj_3R_273()) return true; + } + } + return false; + } + + final private boolean jj_3R_62() { + if (jj_scan_token(OVERRIDE)) return true; + return false; + } + + final private boolean jj_3R_61() { + if (jj_scan_token(PRIVATE)) return true; + return false; + } + + final private boolean jj_3R_60() { + if (jj_scan_token(PROTECTED)) return true; + return false; + } + + final private boolean jj_3R_240() { + if (jj_3R_50()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_260()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_59() { + if (jj_scan_token(STATIC)) return true; + return false; + } + + final private boolean jj_3R_239() { + if (jj_3R_259()) return true; + return false; + } + + final private boolean jj_3R_58() { + if (jj_scan_token(PUBLIC)) return true; + return false; + } + + final private boolean jj_3R_217() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_238()) { + jj_scanpos = xsp; + if (jj_3R_239()) { + jj_scanpos = xsp; + if (jj_3R_240()) return true; + } + } + return false; + } + + final private boolean jj_3R_238() { + if (jj_3R_258()) return true; + return false; + } + + final private boolean jj_3_8() { + if (jj_3R_57()) return true; + if (jj_scan_token(ASSIGN)) return true; + return false; + } + + final private boolean jj_3_9() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_58()) { + jj_scanpos = xsp; + if (jj_3R_59()) { + jj_scanpos = xsp; + if (jj_3R_60()) { + jj_scanpos = xsp; + if (jj_3R_61()) { + jj_scanpos = xsp; + if (jj_3R_62()) { + jj_scanpos = xsp; + if (jj_3R_63()) { + jj_scanpos = xsp; + if (jj_3R_64()) { + jj_scanpos = xsp; + if (jj_3R_65()) { + jj_scanpos = xsp; + if (jj_3R_66()) { + jj_scanpos = xsp; + if (jj_3R_67()) { + jj_scanpos = xsp; + if (jj_3R_68()) { + jj_scanpos = xsp; + if (jj_3R_69()) { + jj_scanpos = xsp; + if (jj_3R_70()) { + jj_scanpos = xsp; + if (jj_3R_71()) return true; + } + } + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + final private boolean jj_3R_90() { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_9()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3_39() { + if (jj_3R_90()) return true; + if (jj_3R_73()) return true; + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + final private boolean jj_3R_181() { + if (jj_3R_90()) return true; + if (jj_3R_73()) return true; + if (jj_3R_187()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_188()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_177() { + if (jj_3R_183()) return true; + return false; + } + + final private boolean jj_3R_176() { + if (jj_3R_182()) return true; + return false; + } + + final private boolean jj_3R_170() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_175()) { + jj_scanpos = xsp; + if (jj_3R_176()) { + jj_scanpos = xsp; + if (jj_3R_177()) return true; + } + } + return false; + } + + final private boolean jj_3R_175() { + if (jj_3R_181()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + final private boolean jj_3_7() { + if (jj_scan_token(NAMESPACE)) return true; + return false; + } + + final private boolean jj_3R_161() { + if (jj_3R_170()) return true; + return false; + } + + final private boolean jj_3R_152() { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_161()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + final private boolean jj_3_36() { + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + final private boolean jj_3R_216() { + if (jj_scan_token(UNSAFE)) return true; + if (jj_3R_152()) return true; + return false; + } + + final private boolean jj_3_1() { + if (jj_scan_token(LANGLE)) return true; + if (jj_scan_token(STAR)) return true; + return false; + } + + final private boolean jj_3R_89() { + if (jj_scan_token(IDENTIFIER)) return true; + if (jj_scan_token(COLON)) return true; + if (jj_3R_182()) return true; + return false; + } + + final private boolean jj_3R_204() { + if (jj_3R_230()) return true; + return false; + } + + final private boolean jj_3R_203() { + if (jj_3R_229()) return true; + return false; + } + + final private boolean jj_3R_202() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(74)) jj_scanpos = xsp; + if (jj_3R_228()) return true; + return false; + } + + final private boolean jj_3R_201() { + if (jj_3R_227()) return true; + return false; + } + + final private boolean jj_3R_200() { + if (jj_3R_226()) return true; + return false; + } + + final private boolean jj_3R_199() { + if (jj_3R_225()) return true; + return false; + } + + final private boolean jj_3R_198() { + if (jj_3R_224()) return true; + return false; + } + + final private boolean jj_3R_197() { + if (jj_3R_223()) return true; + return false; + } + + final private boolean jj_3R_196() { + if (jj_3R_222()) return true; + return false; + } + + final private boolean jj_3R_195() { + if (jj_3R_221()) return true; + return false; + } + + final private boolean jj_3R_194() { + if (jj_3R_220()) return true; + return false; + } + + final private boolean jj_3R_193() { + if (jj_3R_219()) return true; + return false; + } + + final private boolean jj_3R_192() { + if (jj_3R_218()) return true; + return false; + } + + final private boolean jj_3R_191() { + if (jj_3R_217()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + final private boolean jj_3R_155() { + if (jj_3R_164()) return true; + return false; + } + + final private boolean jj_3R_190() { + if (jj_3R_216()) return true; + return false; + } + + final private boolean jj_3R_189() { + if (jj_3R_152()) return true; + return false; + } + + final private boolean jj_3R_144() { + if (jj_3R_78()) return true; + return false; + } + + final private boolean jj_3_38() { + if (jj_3R_89()) return true; + return false; + } + + final private boolean jj_3R_182() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_38()) { + jj_scanpos = xsp; + if (jj_3R_189()) { + jj_scanpos = xsp; + if (jj_3R_190()) { + jj_scanpos = xsp; + if (jj_scan_token(98)) { + jj_scanpos = xsp; + if (jj_3R_191()) { + jj_scanpos = xsp; + if (jj_3R_192()) { + jj_scanpos = xsp; + if (jj_3R_193()) { + jj_scanpos = xsp; + if (jj_3R_194()) { + jj_scanpos = xsp; + if (jj_3R_195()) { + jj_scanpos = xsp; + if (jj_3R_196()) { + jj_scanpos = xsp; + if (jj_3R_197()) { + jj_scanpos = xsp; + if (jj_3R_198()) { + jj_scanpos = xsp; + if (jj_3R_199()) { + jj_scanpos = xsp; + if (jj_3R_200()) { + jj_scanpos = xsp; + if (jj_3R_201()) { + jj_scanpos = xsp; + if (jj_3R_202()) { + jj_scanpos = xsp; + if (jj_3R_203()) { + jj_scanpos = xsp; + if (jj_3R_204()) return true; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + final private boolean jj_3R_57() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(146)) { + jj_scanpos = xsp; + if (jj_scan_token(1)) { + jj_scanpos = xsp; + if (jj_scan_token(2)) { + jj_scanpos = xsp; + if (jj_scan_token(3)) { + jj_scanpos = xsp; + if (jj_scan_token(4)) { + jj_scanpos = xsp; + if (jj_scan_token(5)) { + jj_scanpos = xsp; + if (jj_scan_token(6)) { + jj_scanpos = xsp; + if (jj_scan_token(7)) { + jj_scanpos = xsp; + if (jj_scan_token(8)) { + jj_scanpos = xsp; + if (jj_scan_token(9)) { + jj_scanpos = xsp; + if (jj_scan_token(10)) { + jj_scanpos = xsp; + if (jj_scan_token(11)) { + jj_scanpos = xsp; + if (jj_scan_token(12)) return true; + } + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + final private boolean jj_3R_163() { + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + final private boolean jj_3_35() { + if (jj_scan_token(LBRACKET)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + final private boolean jj_3R_154() { + Token xsp; + if (jj_3R_163()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_163()) { jj_scanpos = xsp; break; } + } + if (jj_3R_123()) return true; + return false; + } + + final private boolean jj_3R_165() { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_81()) return true; + return false; + } + + final private boolean jj_3_37() { + Token xsp; + if (jj_3_35()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3_35()) { jj_scanpos = xsp; break; } + } + while (true) { + xsp = jj_scanpos; + if (jj_3_36()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_143() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_37()) { + jj_scanpos = xsp; + if (jj_3R_154()) return true; + } + return false; + } + + final private boolean jj_3R_146() { + if (jj_3R_129()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_155()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_145() { + if (jj_3R_143()) return true; + return false; + } + + final private boolean jj_3R_51() { + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + final private boolean jj_3R_114() { + if (jj_scan_token(NEW)) return true; + if (jj_3R_124()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_144()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_145()) { + jj_scanpos = xsp; + if (jj_3R_146()) return true; + } + return false; + } + + final private boolean jj_3R_87() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_34()) { + jj_scanpos = xsp; + if (jj_3R_114()) return true; + } + return false; + } + + final private boolean jj_3_34() { + if (jj_scan_token(NEW)) return true; + if (jj_3R_79()) return true; + if (jj_3R_143()) return true; + return false; + } + + final private boolean jj_3R_141() { + if (jj_3R_81()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_165()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_134() { + if (jj_3R_141()) return true; + return false; + } + + final private boolean jj_3R_166() { + if (jj_3R_92()) return true; + return false; + } + + final private boolean jj_3R_129() { + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_134()) jj_scanpos = xsp; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + final private boolean jj_3R_158() { + if (jj_3R_166()) return true; + return false; + } + + final private boolean jj_3R_92() { + if (jj_scan_token(STRING_LITERAL)) return true; + return false; + } + + final private boolean jj_3R_157() { + if (jj_scan_token(TILDE)) return true; + return false; + } + + final private boolean jj_3R_128() { + if (jj_3R_130()) return true; + return false; + } + + final private boolean jj_3R_147() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_157()) jj_scanpos = xsp; + if (jj_scan_token(LBRACKET)) return true; + xsp = jj_scanpos; + if (jj_3R_158()) jj_scanpos = xsp; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + final private boolean jj_3R_150() { + if (jj_scan_token(FALSE)) return true; + return false; + } + + final private boolean jj_3R_142() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_149()) { + jj_scanpos = xsp; + if (jj_3R_150()) return true; + } + return false; + } + + final private boolean jj_3R_149() { + if (jj_scan_token(TRUE)) return true; + return false; + } + + final private boolean jj_3R_135() { + if (jj_3R_142()) return true; + return false; + } + + final private boolean jj_3R_130() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(81)) { + jj_scanpos = xsp; + if (jj_scan_token(85)) { + jj_scanpos = xsp; + if (jj_scan_token(90)) { + jj_scanpos = xsp; + if (jj_scan_token(91)) { + jj_scanpos = xsp; + if (jj_3R_135()) { + jj_scanpos = xsp; + if (jj_scan_token(54)) return true; + } + } + } + } + } + return false; + } + + final private boolean jj_3R_112() { + if (jj_3R_129()) return true; + return false; + } + + final private boolean jj_3R_111() { + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + final private boolean jj_3_30() { + if (jj_3R_86()) return true; + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(CLASS)) return true; + return false; + } + + final private boolean jj_3R_110() { + if (jj_scan_token(LBRACKET)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + final private boolean jj_3_33() { + if (jj_3R_88()) return true; + return false; + } + + final private boolean jj_3_32() { + if (jj_scan_token(DOT)) return true; + if (jj_3R_87()) return true; + return false; + } + + final private boolean jj_3R_85() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_31()) { + jj_scanpos = xsp; + if (jj_3_32()) { + jj_scanpos = xsp; + if (jj_3_33()) { + jj_scanpos = xsp; + if (jj_3R_110()) { + jj_scanpos = xsp; + if (jj_3R_111()) { + jj_scanpos = xsp; + if (jj_3R_112()) return true; + } + } + } + } + } + return false; + } + + final private boolean jj_3_31() { + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(THIS)) return true; + return false; + } + + final private boolean jj_3_29() { + if (jj_3R_85()) return true; + return false; + } + + final private boolean jj_3R_120() { + if (jj_3R_131()) return true; + return false; + } + + final private boolean jj_3R_119() { + if (jj_3R_86()) return true; + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(CLASS)) return true; + return false; + } + + final private boolean jj_3R_118() { + if (jj_3R_87()) return true; + return false; + } + + final private boolean jj_3R_117() { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + final private boolean jj_3R_116() { + if (jj_scan_token(BASE)) return true; + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + final private boolean jj_3R_300() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(113)) { + jj_scanpos = xsp; + if (jj_scan_token(114)) return true; + } + return false; + } + + final private boolean jj_3R_115() { + if (jj_3R_130()) return true; + return false; + } + + final private boolean jj_3R_91() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_115()) { + jj_scanpos = xsp; + if (jj_scan_token(66)) { + jj_scanpos = xsp; + if (jj_3R_116()) { + jj_scanpos = xsp; + if (jj_3R_117()) { + jj_scanpos = xsp; + if (jj_3R_118()) { + jj_scanpos = xsp; + if (jj_3R_119()) { + jj_scanpos = xsp; + if (jj_3R_120()) return true; + } + } + } + } + } + } + return false; + } + + final private boolean jj_3R_139() { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_56()) return true; + return false; + } + + final private boolean jj_3R_138() { + if (jj_3R_147()) return true; + return false; + } + + final private boolean jj_3R_88() { + if (jj_scan_token(DOT)) return true; + if (jj_3R_78()) return true; + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + final private boolean jj_3_28() { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_79()) return true; + return false; + } + + final private boolean jj_3R_50() { + if (jj_3R_91()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_29()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_299() { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_73()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_290()) return true; + return false; + } + + final private boolean jj_3R_137() { + if (jj_scan_token(LANGLE)) return true; + if (jj_3R_51()) return true; + return false; + } + + final private boolean jj_3R_298() { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_73()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_272()) return true; + return false; + } + + final private boolean jj_3R_296() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_298()) { + jj_scanpos = xsp; + if (jj_3R_299()) return true; + } + return false; + } + + final private boolean jj_3_27() { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_73()) return true; + if (jj_scan_token(LBRACKET)) return true; + return false; + } + + final private boolean jj_3R_297() { + if (jj_3R_50()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_300()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_136() { + if (jj_3R_92()) return true; + return false; + } + + final private boolean jj_3R_132() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_136()) { + jj_scanpos = xsp; + if (jj_3R_137()) { + jj_scanpos = xsp; + if (jj_3R_138()) { + jj_scanpos = xsp; + if (jj_3R_139()) return true; + } + } + } + return false; + } + + final private boolean jj_3R_109() { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_73()) return true; + if (jj_scan_token(RPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(104)) { + jj_scanpos = xsp; + if (jj_scan_token(103)) { + jj_scanpos = xsp; + if (jj_scan_token(92)) { + jj_scanpos = xsp; + if (jj_scan_token(146)) { + jj_scanpos = xsp; + if (jj_scan_token(66)) { + jj_scanpos = xsp; + if (jj_scan_token(64)) { + jj_scanpos = xsp; + if (jj_scan_token(53)) { + jj_scanpos = xsp; + if (jj_3R_128()) return true; + } + } + } + } + } + } + } + return false; + } + + final private boolean jj_3R_108() { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_73()) return true; + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + final private boolean jj_3R_84() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_26()) { + jj_scanpos = xsp; + if (jj_3R_108()) { + jj_scanpos = xsp; + if (jj_3R_109()) return true; + } + } + return false; + } + + final private boolean jj_3_26() { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_79()) return true; + return false; + } + + final private boolean jj_3_25() { + if (jj_3R_84()) return true; + return false; + } + + final private boolean jj_3_24() { + if (jj_3R_83()) return true; + return false; + } + + final private boolean jj_3R_295() { + if (jj_3R_297()) return true; + return false; + } + + final private boolean jj_3R_294() { + if (jj_3R_296()) return true; + return false; + } + + final private boolean jj_3R_293() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(104)) { + jj_scanpos = xsp; + if (jj_scan_token(103)) return true; + } + if (jj_3R_272()) return true; + return false; + } + + final private boolean jj_3R_290() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_293()) { + jj_scanpos = xsp; + if (jj_3R_294()) { + jj_scanpos = xsp; + if (jj_3R_295()) return true; + } + } + return false; + } + + final private boolean jj_3R_259() { + if (jj_scan_token(DECR)) return true; + if (jj_3R_50()) return true; + return false; + } + + final private boolean jj_3R_287() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(115)) { + jj_scanpos = xsp; + if (jj_scan_token(116)) return true; + } + if (jj_3R_257()) return true; + return false; + } + + final private boolean jj_3R_121() { + if (jj_3R_132()) return true; + return false; + } + + final private boolean jj_3R_292() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(117)) { + jj_scanpos = xsp; + if (jj_scan_token(118)) { + jj_scanpos = xsp; + if (jj_scan_token(122)) return true; + } + } + if (jj_3R_272()) return true; + return false; + } + + final private boolean jj_3R_94() { + Token xsp; + if (jj_3R_121()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_121()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3_23() { + if (jj_3R_82()) return true; + return false; + } + + final private boolean jj_3R_258() { + if (jj_scan_token(INCR)) return true; + if (jj_3R_50()) return true; + return false; + } + + final private boolean jj_3R_283() { + if (jj_3R_290()) return true; + return false; + } + + final private boolean jj_3_22() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(142)) { + jj_scanpos = xsp; + if (jj_3_23()) { + jj_scanpos = xsp; + if (jj_3_24()) return true; + } + } + if (jj_3R_237()) return true; + return false; + } + + final private boolean jj_3R_282() { + if (jj_3R_259()) return true; + return false; + } + + final private boolean jj_3R_281() { + if (jj_3R_258()) return true; + return false; + } + + final private boolean jj_3R_280() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(115)) { + jj_scanpos = xsp; + if (jj_scan_token(116)) return true; + } + if (jj_3R_272()) return true; + return false; + } + + final private boolean jj_3R_272() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_280()) { + jj_scanpos = xsp; + if (jj_3R_281()) { + jj_scanpos = xsp; + if (jj_3R_282()) { + jj_scanpos = xsp; + if (jj_3R_283()) return true; + } + } + } + return false; + } + + final private boolean jj_3R_266() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(102)) { + jj_scanpos = xsp; + if (jj_scan_token(133)) { + jj_scanpos = xsp; + if (jj_scan_token(108)) { + jj_scanpos = xsp; + if (jj_scan_token(109)) return true; + } + } + } + if (jj_3R_214()) return true; + return false; + } + + final private boolean jj_3R_249() { + if (jj_scan_token(141)) return true; + if (jj_3R_73()) return true; + return false; + } + + final private boolean jj_3R_257() { + if (jj_3R_272()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_292()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_232() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(107)) { + jj_scanpos = xsp; + if (jj_scan_token(110)) return true; + } + if (jj_3R_180()) return true; + return false; + } + + final private boolean jj_3R_95() { + if (jj_scan_token(BIT_OR)) return true; + return false; + } + + final private boolean jj_3R_237() { + if (jj_3R_257()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_287()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_56() { + if (jj_3R_94()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_95()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_214() { + if (jj_3R_237()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_22()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_208() { + if (jj_scan_token(BIT_AND)) return true; + if (jj_3R_174()) return true; + return false; + } + + final private boolean jj_3R_186() { + if (jj_3R_214()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_266()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_178() { + if (jj_scan_token(BIT_OR)) return true; + if (jj_3R_159()) return true; + return false; + } + + final private boolean jj_3R_180() { + if (jj_3R_186()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_249()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_184() { + if (jj_scan_token(XOR)) return true; + if (jj_3R_167()) return true; + return false; + } + + final private boolean jj_3R_171() { + if (jj_scan_token(SC_AND)) return true; + if (jj_3R_148()) return true; + return false; + } + + final private boolean jj_3R_174() { + if (jj_3R_180()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_232()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_162() { + if (jj_scan_token(SC_OR)) return true; + if (jj_3R_140()) return true; + return false; + } + + final private boolean jj_3_6() { + if (jj_scan_token(LANGLE)) return true; + if (jj_3R_51()) return true; + return false; + } + + final private boolean jj_3R_167() { + if (jj_3R_174()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_208()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_153() { + if (jj_scan_token(HOOK)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(COLON)) return true; + if (jj_3R_81()) return true; + return false; + } + + final private boolean jj_3R_159() { + if (jj_3R_167()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_184()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_148() { + if (jj_3R_159()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_178()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_140() { + if (jj_3R_148()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_171()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_93() { + if (jj_scan_token(134)) return true; + return false; + } + + final private boolean jj_3R_55() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_93()) jj_scanpos = xsp; + if (jj_3R_51()) return true; + if (jj_scan_token(COLON)) return true; + return false; + } + + final private boolean jj_3R_133() { + if (jj_3R_140()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_162()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3_5() { + if (jj_scan_token(LANGLE)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_55()) jj_scanpos = xsp; + if (jj_3R_56()) return true; + if (jj_scan_token(RANGLE)) return true; + return false; + } + + final private boolean jj_3R_127() { + if (jj_3R_133()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_153()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_80() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(101)) { + jj_scanpos = xsp; + if (jj_scan_token(125)) { + jj_scanpos = xsp; + if (jj_scan_token(126)) { + jj_scanpos = xsp; + if (jj_scan_token(130)) { + jj_scanpos = xsp; + if (jj_scan_token(123)) { + jj_scanpos = xsp; + if (jj_scan_token(124)) { + jj_scanpos = xsp; + if (jj_scan_token(138)) { + jj_scanpos = xsp; + if (jj_scan_token(139)) { + jj_scanpos = xsp; + if (jj_scan_token(140)) { + jj_scanpos = xsp; + if (jj_scan_token(127)) { + jj_scanpos = xsp; + if (jj_scan_token(129)) { + jj_scanpos = xsp; + if (jj_scan_token(128)) return true; + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + final private boolean jj_3R_126() { + if (jj_scan_token(DELEGATE)) return true; + if (jj_3R_151()) return true; + if (jj_3R_152()) return true; + return false; + } + + final private boolean jj_3_21() { + if (jj_3R_80()) return true; + if (jj_3R_81()) return true; + return false; + } + + final private boolean jj_3R_105() { + if (jj_3R_127()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_21()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_104() { + if (jj_3R_126()) return true; + return false; + } + + final private boolean jj_3R_81() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_104()) { + jj_scanpos = xsp; + if (jj_3R_105()) return true; + } + return false; + } + + final private boolean jj_3_3() { + if (jj_3R_51()) return true; + if (jj_scan_token(LPAREN)) return true; + return false; + } + + final private boolean jj_3_20() { + if (jj_scan_token(DOT)) return true; + if (jj_3R_57()) return true; + return false; + } + + final private boolean jj_3R_131() { + if (jj_3R_57()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_20()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3_2() { + if (jj_3R_50()) return true; + if (jj_scan_token(ASSIGN)) return true; + return false; + } + + final private boolean jj_3R_54() { + if (jj_3R_50()) return true; + if (jj_scan_token(ASSIGN)) return true; + return false; + } + + final private boolean jj_3R_53() { + if (jj_3R_92()) return true; + return false; + } + + final private boolean jj_3_4() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_52()) { + jj_scanpos = xsp; + if (jj_3R_53()) { + jj_scanpos = xsp; + if (jj_scan_token(102)) { + jj_scanpos = xsp; + if (jj_3R_54()) return true; + } + } + } + return false; + } + + final private boolean jj_3R_52() { + if (jj_3R_51()) return true; + return false; + } + + final private boolean jj_3_18() { + if (jj_3R_78()) return true; + return false; + } + + final private boolean jj_3R_113() { + if (jj_3R_73()) return true; + return false; + } + + final private boolean jj_3R_86() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(70)) { + jj_scanpos = xsp; + if (jj_3R_113()) return true; + } + return false; + } + + final private boolean jj_3R_156() { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_103()) return true; + return false; + } + + final private boolean jj_3_15() { + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + final private boolean jj_3R_79() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(29)) { + jj_scanpos = xsp; + if (jj_scan_token(34)) { + jj_scanpos = xsp; + if (jj_scan_token(31)) { + jj_scanpos = xsp; + if (jj_scan_token(62)) { + jj_scanpos = xsp; + if (jj_scan_token(50)) { + jj_scanpos = xsp; + if (jj_scan_token(52)) { + jj_scanpos = xsp; + if (jj_scan_token(45)) { + jj_scanpos = xsp; + if (jj_scan_token(40)) { + jj_scanpos = xsp; + if (jj_scan_token(80)) return true; + } + } + } + } + } + } + } + } + return false; + } + + final private boolean jj_3_16() { + if (jj_3R_78()) return true; + return false; + } + + final private boolean jj_3R_125() { + if (jj_3R_77()) return true; + return false; + } + + final private boolean jj_3_14() { + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + final private boolean jj_3R_103() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_19()) { + jj_scanpos = xsp; + if (jj_3R_125()) return true; + } + return false; + } + + final private boolean jj_3_19() { + if (jj_3R_79()) return true; + return false; + } + + final private boolean jj_3R_78() { + if (jj_scan_token(LANGLE)) return true; + if (jj_3R_103()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_156()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RANGLE)) return true; + return false; + } + + final private boolean jj_3_17() { + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(IDENTIFIER)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_18()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_124() { + if (jj_scan_token(IDENTIFIER)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_16()) jj_scanpos = xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_17()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_102() { + if (jj_3R_124()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_15()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_101() { + if (jj_3R_79()) return true; + Token xsp; + if (jj_3_14()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3_14()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_77() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_101()) { + jj_scanpos = xsp; + if (jj_3R_102()) return true; + } + return false; + } + + final private boolean jj_3R_97() { + if (jj_3R_79()) return true; + return false; + } + + final private boolean jj_3_13() { + if (jj_3R_77()) return true; + return false; + } + + final private boolean jj_3R_73() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_13()) { + jj_scanpos = xsp; + if (jj_3R_97()) return true; + } + xsp = jj_scanpos; + if (jj_scan_token(105)) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_252() { + if (jj_3R_170()) return true; + return false; + } + + final private boolean jj_3R_251() { + if (jj_3R_96()) return true; + return false; + } + + final private boolean jj_3R_234() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_251()) jj_scanpos = xsp; + if (jj_scan_token(IDENTIFIER)) return true; + if (jj_3R_151()) return true; + if (jj_scan_token(LBRACE)) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_252()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + final private boolean jj_3R_271() { + if (jj_3R_96()) return true; + return false; + } + + final private boolean jj_3R_169() { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_168()) return true; + return false; + } + + final private boolean jj_3R_168() { + if (jj_3R_90()) return true; + if (jj_3R_73()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(137)) jj_scanpos = xsp; + if (jj_3R_74()) return true; + return false; + } + + final private boolean jj_3R_268() { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_187()) return true; + return false; + } + + final private boolean jj_3R_160() { + if (jj_3R_168()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_169()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3_12() { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_76()) return true; + return false; + } + + final private boolean jj_3R_270() { + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + final private boolean jj_3R_151() { + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_160()) jj_scanpos = xsp; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + final private boolean jj_3R_255() { + if (jj_scan_token(IDENTIFIER)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_270()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_3R_271()) jj_scanpos = xsp; + if (jj_3R_151()) return true; + return false; + } + + final private boolean jj_3R_256() { + if (jj_3R_152()) return true; + return false; + } + + final private boolean jj_3R_289() { + if (jj_scan_token(135)) return true; + if (jj_3R_182()) return true; + return false; + } + + final private boolean jj_3R_172() { + if (jj_3R_76()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_12()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_236() { + if (jj_3R_86()) return true; + if (jj_3R_255()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_256()) { + jj_scanpos = xsp; + if (jj_scan_token(98)) return true; + } + return false; + } + + final private boolean jj_3R_106() { + return false; + } + + final private boolean jj_3R_288() { + if (jj_scan_token(136)) return true; + if (jj_3R_182()) return true; + return false; + } + + final private boolean jj_3R_267() { + if (jj_scan_token(ASSIGN)) return true; + if (jj_3R_76()) return true; + return false; + } + + final private boolean jj_3R_98() { + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(IDENTIFIER)) return true; + return false; + } + + final private boolean jj_3R_75() { + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + final private boolean jj_3R_254() { + if (jj_scan_token(LBRACE)) return true; + if (jj_3R_269()) return true; + if (jj_scan_token(RBRACE)) return true; + return false; + } + + final private boolean jj_3R_123() { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_172()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_scan_token(99)) jj_scanpos = xsp; + if (jj_scan_token(RBRACE)) return true; + return false; + } + + final private boolean jj_3R_215() { + if (jj_scan_token(ASSIGN)) return true; + if (jj_3R_76()) return true; + return false; + } + + final private boolean jj_3R_253() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_267()) jj_scanpos = xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_268()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + final private boolean jj_3R_107() { + return false; + } + + final private boolean jj_3R_100() { + if (jj_3R_81()) return true; + return false; + } + + final private boolean jj_3R_82() { + Token xsp; + xsp = jj_scanpos; + lookingAhead = true; + jj_semLA = getToken(1).kind == GT && + ((Token.GTToken)getToken(1)).realKind == RSIGNEDSHIFT; + lookingAhead = false; + if (!jj_semLA || jj_3R_106()) return true; + if (jj_scan_token(RANGLE)) return true; + if (jj_scan_token(RANGLE)) return true; + return false; + } + + final private boolean jj_3R_99() { + if (jj_3R_123()) return true; + return false; + } + + final private boolean jj_3R_76() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_99()) { + jj_scanpos = xsp; + if (jj_3R_100()) return true; + } + return false; + } + + final private boolean jj_3R_74() { + if (jj_scan_token(IDENTIFIER)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_98()) { jj_scanpos = xsp; break; } + } + return false; + } + + final private boolean jj_3R_83() { + Token xsp; + xsp = jj_scanpos; + lookingAhead = true; + jj_semLA = getToken(1).kind == GT && + ((Token.GTToken)getToken(1)).realKind == RUNSIGNEDSHIFT; + lookingAhead = false; + if (!jj_semLA || jj_3R_107()) return true; + if (jj_scan_token(RANGLE)) return true; + if (jj_scan_token(RANGLE)) return true; + if (jj_scan_token(RANGLE)) return true; + return false; + } + + final private boolean jj_3R_279() { + if (jj_scan_token(136)) return true; + if (jj_3R_182()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_289()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_278() { + if (jj_scan_token(135)) return true; + if (jj_3R_182()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_288()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_269() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_278()) { + jj_scanpos = xsp; + if (jj_3R_279()) return true; + } + return false; + } + + final private boolean jj_3R_247() { + if (jj_scan_token(145)) return true; + if (jj_3R_152()) return true; + return false; + } + + final private boolean jj_3R_246() { + if (jj_scan_token(CATCH)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_168()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_152()) return true; + return false; + } + + final private boolean jj_3R_187() { + if (jj_3R_74()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_215()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_230() { + if (jj_scan_token(TRY)) return true; + if (jj_3R_152()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_246()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_3R_247()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3_11() { + if (jj_3R_73()) return true; + if (jj_3R_74()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_75()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_scan_token(99)) { + jj_scanpos = xsp; + if (jj_scan_token(101)) { + jj_scanpos = xsp; + if (jj_scan_token(98)) { + jj_scanpos = xsp; + if (jj_scan_token(94)) return true; + } + } + } + return false; + } + + final private boolean jj_3R_72() { + if (jj_3R_96()) return true; + return false; + } + + final private boolean jj_3_10() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_72()) jj_scanpos = xsp; + if (jj_scan_token(IDENTIFIER)) return true; + if (jj_scan_token(LPAREN)) return true; + return false; + } + + final private boolean jj_3R_235() { + if (jj_3R_73()) return true; + if (jj_3R_74()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_253()) { + jj_scanpos = xsp; + if (jj_3R_254()) return true; + } + return false; + } + + final private boolean jj_3R_213() { + if (jj_3R_236()) return true; + return false; + } + + final private boolean jj_3R_212() { + if (jj_3R_235()) return true; + return false; + } + + final private boolean jj_3R_211() { + if (jj_3R_234()) return true; + return false; + } + + final private boolean jj_3R_210() { + if (jj_3R_233()) return true; + return false; + } + + final private boolean jj_3R_209() { + if (jj_3R_183()) return true; + return false; + } + + final private boolean jj_3R_179() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_185()) { + jj_scanpos = xsp; + if (jj_scan_token(98)) return true; + } + return false; + } + + final private boolean jj_3R_185() { + if (jj_3R_90()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_209()) { + jj_scanpos = xsp; + if (jj_3R_210()) { + jj_scanpos = xsp; + if (jj_3R_211()) { + jj_scanpos = xsp; + if (jj_3R_212()) { + jj_scanpos = xsp; + if (jj_3R_213()) return true; + } + } + } + } + return false; + } + + public CSJavaCCParserTokenManager token_source; + JavaCharStream jj_input_stream; + public Token token, jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + public boolean lookingAhead = false; + private boolean jj_semLA; + private int jj_gen; + final private int[] jj_la1 = new int[152]; + static private int[] jj_la1_0; + static private int[] jj_la1_1; + static private int[] jj_la1_2; + static private int[] jj_la1_3; + static private int[] jj_la1_4; + static { + jj_la1_0(); + jj_la1_1(); + jj_la1_2(); + jj_la1_3(); + jj_la1_4(); + } + private static void jj_la1_0() { + jj_la1_0 = new int[] {0xa0000fc0,0xc,0x2,0xc,0x0,0xa0000fc0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x780,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1ffe,0x0,0x0,0x0,0x0,0x0,0x10000000,0x1ffe,0x10000000,0x10000000,0x0,0x0,0x0,0x0,0x0,0x0,0xb0000000,0x0,0xa0000000,0xb0000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa0001ffe,0xa0001ffe,0x0,0x0,0x0,0x0,0x0,0xb0000000,0x0,0x0,0xf0001ffe,0xa0000000,0x0,0xa0000000,0x0,0xa0000000,0xa0000000,0xa0000000,0x0,0xa0001ffe,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa0001ffe,0x0,0x0,0xa0001ffe,0x0,0x0,0x0,0x0,0x0,0x0,0x1ffe,0x0,0x0,0x0,0xa0001ffe,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xe0001ffe,0xf0001ffe,0xe0001ffe,0x0,0x0,0x0,0xa0001ffe,0x0,0xf0001ffe,0x0,0x0,0xb0001ffe,0xa0001ffe,0xa0001ffe,0xb0001ffe,0xa0001ffe,0x0,0x0,0x0,0xa0001ffe,0x0,0x0,}; + } + private static void jj_la1_1() { + jj_la1_1 = new int[] {0x4e142104,0x80000000,0x0,0x80000000,0x800,0x4e142104,0xe000000,0xe000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20000,0x9f281008,0x0,0x9f201000,0x9f281008,0x80008,0x0,0x0,0x0,0x0,0x0,0xdf3c310c,0x80008,0x40142104,0xdf3c310c,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40742904,0x40742904,0x0,0x0,0x0,0x0,0x0,0xdf343104,0x0,0x0,0xff7f79ac,0x40142104,0x0,0x40142104,0x0,0x40142104,0x40142104,0x40142104,0x0,0x40742904,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40742904,0x0,0x0,0x40742904,0x600800,0x0,0x0,0x0,0x0,0x600800,0x0,0x0,0x400800,0x800,0x40742904,0x0,0x0,0x0,0x0,0x200000,0x0,0x0,0x0,0x607769a4,0xff7f79ac,0x607f69ac,0x0,0x0,0x0,0x40742904,0x41,0xff7f79ac,0x41,0x200,0xdf743904,0x40742904,0x40742904,0xdf743904,0x40742904,0x0,0x0,0x0,0x40742904,0x2,0x0,}; + } + private static void jj_la1_2() { + jj_la1_2 = new int[] {0x10040,0x0,0x0,0x0,0x8020010,0x10040,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40000000,0x0,0x0,0x0,0x20000,0x0,0x0,0x8000000,0x0,0x0,0x40000020,0x10000000,0x0,0x0,0x8000000,0x0,0x0,0x18000000,0x20000,0x0,0x40000000,0x40000000,0x18000000,0x0,0x0,0x8000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xea00,0x0,0xea00,0xea00,0x0,0x0,0x0,0x0,0x0,0x0,0x1fa40,0x1000,0x10040,0x1fa40,0x0,0x0,0x40000000,0x0,0x0,0x0,0x0,0x0,0x5c231055,0x5c231055,0x0,0x40000000,0x0,0x0,0x0,0x1ea00,0x0,0x0,0x5c23efff,0x10000,0x0,0x10000,0x0,0x10000,0x10000,0x10040,0x0,0x1c231055,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1c230055,0x0,0x0,0x1c230055,0x1c220015,0x10000000,0x0,0x0,0x10000000,0x1c220015,0x0,0x10000000,0xc220010,0x10,0x1c231055,0x0,0x0,0x40000000,0x10000000,0x0,0x0,0x0,0x400,0x5c2385ff,0x5c23efff,0x5c2385ff,0x0,0x0,0x0,0x1c230055,0x0,0x5c23efff,0x0,0x0,0x1c23ea55,0x1c231055,0x1c230055,0x1c23ea55,0x1c230055,0x0,0x0,0x0,0x1c231055,0x0,0x0,}; + } + private static void jj_la1_3() { + jj_la1_3 = new int[] {0x40,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x8,0x40,0x40,0x1,0x1000000,0x0,0x0,0x400,0x1000000,0x0,0x0,0x0,0x10,0x40,0x280200,0x280200,0x1,0x0,0x0,0x0,0x0,0x40,0x1000000,0x141,0x0,0x8,0x280200,0x280200,0x141,0x100,0x8,0x0,0x100000,0x0,0x0,0x40,0x0,0x40,0x0,0x4,0x0,0x0,0x4,0x0,0x40,0x400,0x40,0x8,0x8,0x44,0x0,0x0,0x44,0x20,0x8,0x2c,0x20,0x0,0x0,0x0,0x10,0x1e0180,0x1e0180,0x8,0x4,0x10,0x40,0x8,0x0,0x0,0x40,0x60004,0x0,0x200,0x0,0x8,0x0,0x0,0x0,0x8,0x1e0180,0xf8000020,0x200,0x8000,0x10000,0x1000000,0x2000000,0x800000,0x4800,0x4800,0x0,0x3040,0x3040,0x0,0x180000,0x180000,0x4600000,0x4600000,0x180000,0x1e0180,0x180,0x180,0x0,0x180,0x0,0x60000,0x60000,0x0,0x0,0x0,0x11,0x0,0x0,0x1e0180,0x8,0x40,0x0,0x1,0x0,0x1,0x1,0x0,0x60004,0x60004,0x60004,0x8,0xf8060020,0xf8060020,0x60000,0x0,0x60004,0x0,0x0,0x60000,0x1e0180,0x60000,0x60004,0x60000,0x8,0x0,0x0,0x1e0180,0x0,0x0,}; + } + private static void jj_la1_4() { + jj_la1_4 = new int[] {0x40000,0x40000,0x0,0x40000,0x0,0x40000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x40040,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40000,0x20,0x20,0x20,0x20,0x0,0x0,0x40000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40000,0x0,0x40000,0x40000,0x0,0x0,0x0,0x0,0x100,0x80,0x180,0x0,0x40000,0x40000,0x0,0x0,0x0,0x0,0x0,0x40000,0x200,0x0,0x48000,0x0,0x0,0x40000,0x0,0x40000,0x0,0x40000,0x0,0x40000,0x1c07,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2000,0x20,0x20,0x4000,0x0,0x0,0x0,0x0,0x0,0x40000,0x0,0x0,0x40000,0x40000,0x0,0x0,0x0,0x0,0x0,0x40000,0x0,0x0,0x0,0x40000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x48000,0x48000,0x48000,0x0,0x1c07,0x1c07,0x40000,0x0,0x48000,0x0,0x0,0x40000,0x40000,0x40000,0x40000,0x40000,0x0,0x40000,0x40000,0x40000,0x0,0x20000,}; + } + final private JJCalls[] jj_2_rtns = new JJCalls[41]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + public CSJavaCCParser(java.io.InputStream stream) { + this(stream, null); + } + public CSJavaCCParser(java.io.InputStream stream, String encoding) { + try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new CSJavaCCParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 152; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + public void ReInit(java.io.InputStream stream, String encoding) { + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 152; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + public CSJavaCCParser(java.io.Reader stream) { + jj_input_stream = new JavaCharStream(stream, 1, 1); + token_source = new CSJavaCCParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 152; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + public void ReInit(java.io.Reader stream) { + jj_input_stream.ReInit(stream, 1, 1); + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 152; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + public CSJavaCCParser(CSJavaCCParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 152; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + public void ReInit(CSJavaCCParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 152; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + final private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + static private final class LookaheadSuccess extends java.lang.Error { } + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + final private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + final public Token getToken(int index) { + Token t = lookingAhead ? jj_scanpos : token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + final private int jj_ntk() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.Vector jj_expentries = new java.util.Vector(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) return; + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + boolean exists = false; + for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) { + int[] oldentry = (int[])(e.nextElement()); + if (oldentry.length == jj_expentry.length) { + exists = true; + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + exists = false; + break; + } + } + if (exists) break; + } + } + if (!exists) jj_expentries.addElement(jj_expentry); + if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + + public ParseException generateParseException() { + jj_expentries.removeAllElements(); + boolean[] la1tokens = new boolean[149]; + for (int i = 0; i < 149; i++) { + la1tokens[i] = false; + } + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 152; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1< jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + case 1: jj_3_2(); break; + case 2: jj_3_3(); break; + case 3: jj_3_4(); break; + case 4: jj_3_5(); break; + case 5: jj_3_6(); break; + case 6: jj_3_7(); break; + case 7: jj_3_8(); break; + case 8: jj_3_9(); break; + case 9: jj_3_10(); break; + case 10: jj_3_11(); break; + case 11: jj_3_12(); break; + case 12: jj_3_13(); break; + case 13: jj_3_14(); break; + case 14: jj_3_15(); break; + case 15: jj_3_16(); break; + case 16: jj_3_17(); break; + case 17: jj_3_18(); break; + case 18: jj_3_19(); break; + case 19: jj_3_20(); break; + case 20: jj_3_21(); break; + case 21: jj_3_22(); break; + case 22: jj_3_23(); break; + case 23: jj_3_24(); break; + case 24: jj_3_25(); break; + case 25: jj_3_26(); break; + case 26: jj_3_27(); break; + case 27: jj_3_28(); break; + case 28: jj_3_29(); break; + case 29: jj_3_30(); break; + case 30: jj_3_31(); break; + case 31: jj_3_32(); break; + case 32: jj_3_33(); break; + case 33: jj_3_34(); break; + case 34: jj_3_35(); break; + case 35: jj_3_36(); break; + case 36: jj_3_37(); break; + case 37: jj_3_38(); break; + case 38: jj_3_39(); break; + case 39: jj_3_40(); break; + case 40: jj_3_41(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + final private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} diff --git a/csjavacc/parser/CSJavaCCParserConstants.java b/csjavacc/parser/CSJavaCCParserConstants.java new file mode 100644 index 0000000..2559f39 --- /dev/null +++ b/csjavacc/parser/CSJavaCCParserConstants.java @@ -0,0 +1,299 @@ +/* Generated By:JavaCC: Do not edit this line. CSJavaCCParserConstants.java */ +/** + * This file contains the code for CSJavaCCParser generated + * by CSJavaCCParser itself. + */ + +package csjavacc.parser; + +public interface CSJavaCCParserConstants { + + int EOF = 0; + int _OPTIONS = 1; + int _LOOKAHEAD = 2; + int _IGNORE_CASE = 3; + int _PARSER_BEGIN = 4; + int _PARSER_END = 5; + int _CSCODE = 6; + int _TOKEN = 7; + int _SPECIAL_TOKEN = 8; + int _MORE = 9; + int _SKIP = 10; + int _TOKEN_MGR_DECLS = 11; + int _EOF = 12; + int SINGLE_LINE_COMMENT = 23; + int PRAGMA = 24; + int FORMAL_COMMENT = 25; + int MULTI_LINE_COMMENT = 26; + int ABSTRACT = 28; + int BOOLEAN = 29; + int BREAK = 30; + int BYTE = 31; + int CASE = 32; + int CATCH = 33; + int CHAR = 34; + int CLASS = 35; + int CONST = 36; + int CONTINUE = 37; + int _DEFAULT = 38; + int DO = 39; + int DOUBLE = 40; + int ELSE = 41; + int ENUM = 42; + int FALSE = 43; + int OVERRIDE = 44; + int FLOAT = 45; + int FOR = 46; + int GOTO = 47; + int IF = 48; + int IMPORT = 49; + int INT = 50; + int INTERFACE = 51; + int LONG = 52; + int NEW = 53; + int NULL = 54; + int NAMESPACE = 55; + int OUT = 56; + int PRIVATE = 57; + int PROTECTED = 58; + int PUBLIC = 59; + int REF = 60; + int RETURN = 61; + int SHORT = 62; + int STATIC = 63; + int BASE = 64; + int SWITCH = 65; + int THIS = 66; + int THROW = 67; + int TRUE = 68; + int TRY = 69; + int VOID = 70; + int WHILE = 71; + int FOREACH = 72; + int PARTIAL = 73; + int YIELD = 74; + int INTERNAL = 75; + int DELEGATE = 76; + int READONLY = 77; + int FIXED = 78; + int UNSAFE = 79; + int VAR = 80; + int INTEGER_LITERAL = 81; + int DECIMAL_LITERAL = 82; + int HEX_LITERAL = 83; + int OCTAL_LITERAL = 84; + int FLOATING_POINT_LITERAL = 85; + int DECIMAL_FLOATING_POINT_LITERAL = 86; + int DECIMAL_EXPONENT = 87; + int HEXADECIMAL_FLOATING_POINT_LITERAL = 88; + int HEXADECIMAL_EXPONENT = 89; + int CHARACTER_LITERAL = 90; + int STRING_LITERAL = 91; + int LPAREN = 92; + int RPAREN = 93; + int LBRACE = 94; + int RBRACE = 95; + int LBRACKET = 96; + int RBRACKET = 97; + int SEMICOLON = 98; + int COMMA = 99; + int DOT = 100; + int ASSIGN = 101; + int LT = 102; + int BANG = 103; + int TILDE = 104; + int HOOK = 105; + int COLON = 106; + int EQ = 107; + int LE = 108; + int GE = 109; + int NE = 110; + int SC_OR = 111; + int SC_AND = 112; + int INCR = 113; + int DECR = 114; + int PLUS = 115; + int MINUS = 116; + int STAR = 117; + int SLASH = 118; + int BIT_AND = 119; + int BIT_OR = 120; + int XOR = 121; + int REM = 122; + int PLUSASSIGN = 123; + int MINUSASSIGN = 124; + int STARASSIGN = 125; + int SLASHASSIGN = 126; + int ANDASSIGN = 127; + int ORASSIGN = 128; + int XORASSIGN = 129; + int REMASSIGN = 130; + int RUNSIGNEDSHIFT = 131; + int RSIGNEDSHIFT = 132; + int GT = 133; + int LANGLE = 102; + int RANGLE = 133; + int IDENTIFIER = 146; + int LETTER = 147; + int PART_LETTER = 148; + + int DEFAULT = 0; + int AFTER_EGEN = 1; + int IN_SINGLE_LINE_COMMENT = 2; + int IN_PRAGMA = 3; + int IN_FORMAL_COMMENT = 4; + int IN_MULTI_LINE_COMMENT = 5; + + String[] tokenImage = { + "", + "\"options\"", + "\"LOOKAHEAD\"", + "\"IGNORE_CASE\"", + "\"PARSER_BEGIN\"", + "\"PARSER_END\"", + "\"CSCODE\"", + "\"TOKEN\"", + "\"SPECIAL_TOKEN\"", + "\"MORE\"", + "\"SKIP\"", + "\"TOKEN_MGR_DECLS\"", + "\"EOF\"", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "\"\\f\"", + "", + "\"//\"", + "", + "\"/*\"", + "", + "", + "", + "\"*/\"", + "\"*/\"", + "", + "\"abstract\"", + "\"bool\"", + "\"break\"", + "\"byte\"", + "\"case\"", + "\"catch\"", + "\"char\"", + "\"class\"", + "\"const\"", + "\"continue\"", + "\"default\"", + "\"do\"", + "\"double\"", + "\"else\"", + "\"enum\"", + "\"false\"", + "\"override\"", + "\"single\"", + "\"for\"", + "\"goto\"", + "\"if\"", + "\"using\"", + "\"int\"", + "\"interface\"", + "\"long\"", + "\"new\"", + "\"null\"", + "\"namespace\"", + "\"out\"", + "\"private\"", + "\"protected\"", + "\"public\"", + "\"ref\"", + "\"return\"", + "\"short\"", + "\"static\"", + "\"base\"", + "\"switch\"", + "\"this\"", + "\"throw\"", + "\"true\"", + "\"try\"", + "\"void\"", + "\"while\"", + "\"foreach\"", + "\"partial\"", + "\"yield\"", + "\"internal\"", + "\"delegate\"", + "\"readonly\"", + "\"fixed\"", + "\"unsafe\"", + "\"var\"", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "\"(\"", + "\")\"", + "\"{\"", + "\"}\"", + "\"[\"", + "\"]\"", + "\";\"", + "\",\"", + "\".\"", + "\"=\"", + "\"<\"", + "\"!\"", + "\"~\"", + "\"?\"", + "\":\"", + "\"==\"", + "\"<=\"", + "\">=\"", + "\"!=\"", + "\"||\"", + "\"&&\"", + "\"++\"", + "\"--\"", + "\"+\"", + "\"-\"", + "\"*\"", + "\"/\"", + "\"&\"", + "\"|\"", + "\"^\"", + "\"%\"", + "\"+=\"", + "\"-=\"", + "\"*=\"", + "\"/=\"", + "\"&=\"", + "\"|=\"", + "\"^=\"", + "\"%=\"", + "\">>>\"", + "\">>\"", + "\">\"", + "\"#\"", + "\"get\"", + "\"set\"", + "\"...\"", + "\"<<=\"", + "\">>=\"", + "\">>>=\"", + "\"is\"", + "\"<<\"", + "\"lock\"", + "\"in\"", + "\"finally\"", + "", + "", + "", + }; + +} diff --git a/csjavacc/parser/CSJavaCCParserInternals.java b/csjavacc/parser/CSJavaCCParserInternals.java new file mode 100644 index 0000000..3894fcb --- /dev/null +++ b/csjavacc/parser/CSJavaCCParserInternals.java @@ -0,0 +1,307 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import csjavacc.struct.*; + + +public abstract class CSJavaCCParserInternals extends CSJavaCCGlobals { + + static protected void initialize() { + Integer i = new Integer(0); + lexstate_S2I.put("DEFAULT", i); + lexstate_I2S.put(i, "DEFAULT"); + simple_tokens_table.put("DEFAULT", new java.util.Hashtable()); + } + + static protected void addcuname(String id) { + cu_name = id; + } + + static protected void compare(Token t, String id1, String id2) { + if (!id2.equals(id1)) { + CSJavaCCErrors.parse_error(t, "Name " + id2 + " must be the same as that used at PARSER_BEGIN (" + id1 + ")"); + } + } + + static private java.util.Vector add_cu_token_here = cu_to_insertion_point_1; + static private Token first_cu_token; + static private boolean insertionpoint1set = false; + static private boolean insertionpoint2set = false; + + static protected void setinsertionpoint(Token t, int no) { + do { + add_cu_token_here.addElement(first_cu_token); + first_cu_token = first_cu_token.next; + } while (first_cu_token != t); + if (no == 1) { + if (insertionpoint1set) { + CSJavaCCErrors.parse_error(t, "Multiple declaration of parser class."); + } else { + insertionpoint1set = true; + add_cu_token_here = cu_to_insertion_point_2; + } + } else { + add_cu_token_here = cu_from_insertion_point_2; + insertionpoint2set = true; + } + first_cu_token = t; + } + + static protected void insertionpointerrors(Token t) { + while (first_cu_token != t) { + add_cu_token_here.addElement(first_cu_token); + first_cu_token = first_cu_token.next; + } + if (!insertionpoint1set || !insertionpoint2set) { + CSJavaCCErrors.parse_error(t, "Parser class has not been defined between PARSER_BEGIN and PARSER_END."); + } + } + + static protected void set_initial_cu_token(Token t) { + first_cu_token = t; + } + + static protected void addproduction(NormalProduction p) { + bnfproductions.addElement(p); + } + + static protected void production_addexpansion(BNFProduction p, Expansion e) { + e.parent = p; + p.expansion = e; + } + + static private int nextFreeLexState = 1; + + static protected void addregexpr(TokenProduction p) { + Integer ii; + rexprlist.addElement(p); + if (Options.getUserTokenManager()) { + if (p.lexStates == null || p.lexStates.length != 1 || !p.lexStates[0].equals("DEFAULT")) { + CSJavaCCErrors.warning(p, "Ignoring lexical state specifications since option USER_TOKEN_MANAGER has been set to true."); + } + } + if (p.lexStates == null) { + return; + } + for (int i = 0; i < p.lexStates.length; i++) { + for (int j = 0; j < i; j++) { + if (p.lexStates[i].equals(p.lexStates[j])) { + CSJavaCCErrors.parse_error(p, "Multiple occurrence of \"" + p.lexStates[i] + "\" in lexical state list."); + } + } + if (lexstate_S2I.get(p.lexStates[i]) == null) { + ii = new Integer(nextFreeLexState++); + lexstate_S2I.put(p.lexStates[i], ii); + lexstate_I2S.put(ii, p.lexStates[i]); + simple_tokens_table.put(p.lexStates[i], new java.util.Hashtable()); + } + } + } + + static protected void add_token_manager_decls(Token t, java.util.Vector decls) { + if (token_mgr_decls != null) { + CSJavaCCErrors.parse_error(t, "Multiple occurrence of \"TOKEN_MGR_DECLS\"."); + } else { + token_mgr_decls = decls; + if (Options.getUserTokenManager()) { + CSJavaCCErrors.warning(t, "Ignoring declarations in \"TOKEN_MGR_DECLS\" since option USER_TOKEN_MANAGER has been set to true."); + } + } + } + + static protected void add_inline_regexpr(RegularExpression r) { + if (!(r instanceof REndOfFile)) { + TokenProduction p = new TokenProduction(); + p.isExplicit = false; + p.lexStates = new String[1]; + p.lexStates[0] = "DEFAULT"; + p.kind = TokenProduction.TOKEN; + RegExprSpec res = new RegExprSpec(); + res.rexp = r; + res.rexp.tpContext = p; + res.act = new Action(); + res.nextState = null; + res.nsTok = null; + p.respecs.addElement(res); + rexprlist.addElement(p); + } + } + + static protected boolean hexchar(char ch) { + if (ch >= '0' && ch <= '9') return true; + if (ch >= 'A' && ch <= 'F') return true; + if (ch >= 'a' && ch <= 'f') return true; + return false; + } + + static protected int hexval(char ch) { + if (ch >= '0' && ch <= '9') return ((int)ch) - ((int)'0'); + if (ch >= 'A' && ch <= 'F') return ((int)ch) - ((int)'A') + 10; + return ((int)ch) - ((int)'a') + 10; + } + + static protected String remove_escapes_and_quotes(Token t, String str) { + String retval = ""; + int index = 1; + char ch, ch1; + int ordinal; + while (index < str.length()-1) { + if (str.charAt(index) != '\\') { + retval += str.charAt(index); index++; + continue; + } + index++; + ch = str.charAt(index); + if (ch == 'b') { + retval += '\b'; index++; + continue; + } + if (ch == 't') { + retval += '\t'; index++; + continue; + } + if (ch == 'n') { + retval += '\n'; index++; + continue; + } + if (ch == 'f') { + retval += '\f'; index++; + continue; + } + if (ch == 'r') { + retval += '\r'; index++; + continue; + } + if (ch == '"') { + retval += '\"'; index++; + continue; + } + if (ch == '\'') { + retval += '\''; index++; + continue; + } + if (ch == '\\') { + retval += '\\'; index++; + continue; + } + if (ch >= '0' && ch <= '7') { + ordinal = ((int)ch) - ((int)'0'); index++; + ch1 = str.charAt(index); + if (ch1 >= '0' && ch1 <= '7') { + ordinal = ordinal*8 + ((int)ch1) - ((int)'0'); index++; + ch1 = str.charAt(index); + if (ch <= '3' && ch1 >= '0' && ch1 <= '7') { + ordinal = ordinal*8 + ((int)ch1) - ((int)'0'); index++; + } + } + retval += (char)ordinal; + continue; + } + if (ch == 'u') { + index++; ch = str.charAt(index); + if (hexchar(ch)) { + ordinal = hexval(ch); + index++; ch = str.charAt(index); + if (hexchar(ch)) { + ordinal = ordinal*16 + hexval(ch); + index++; ch = str.charAt(index); + if (hexchar(ch)) { + ordinal = ordinal*16 + hexval(ch); + index++; ch = str.charAt(index); + if (hexchar(ch)) { + ordinal = ordinal*16 + hexval(ch); + index++; + continue; + } + } + } + } + CSJavaCCErrors.parse_error(t, "Encountered non-hex character '" + ch + "' at position " + index + " of string - Unicode escape must have 4 hex digits after it."); + return retval; + } + CSJavaCCErrors.parse_error(t, "Illegal escape sequence '\\" + ch + "' at position " + index + " of string."); + return retval; + } + return retval; + } + + static protected char character_descriptor_assign(Token t, String s) { + if (s.length() != 1) { + CSJavaCCErrors.parse_error(t, "String in character list may contain only one character."); + return ' '; + } else { + return s.charAt(0); + } + } + + static protected char character_descriptor_assign(Token t, String s, String left) { + if (s.length() != 1) { + CSJavaCCErrors.parse_error(t, "String in character list may contain only one character."); + return ' '; + } else if ((int)(left.charAt(0)) > (int)(s.charAt(0))) { + CSJavaCCErrors.parse_error(t, "Right end of character range \'" + s + "\' has a lower ordinal value than the left end of character range \'" + left + "\'."); + return left.charAt(0); + } else { + return s.charAt(0); + } + } + + static protected void makeTryBlock( + Token tryLoc, + Container result, + Container nestedExp, + java.util.Vector types, + java.util.Vector ids, + java.util.Vector catchblks, + java.util.Vector finallyblk + ) + { + if (catchblks.size() == 0 && finallyblk == null) { + CSJavaCCErrors.parse_error(tryLoc, "Try block must contain at least one catch or finally block."); + result = nestedExp; + return; + } + TryBlock tblk = new TryBlock(); + tblk.line = tryLoc.beginLine; + tblk.column = tryLoc.beginColumn; + tblk.exp = (Expansion)(nestedExp.member); + tblk.exp.parent = tblk; + tblk.exp.ordinal = 0; + tblk.types = types; + tblk.ids = ids; + tblk.catchblks = catchblks; + tblk.finallyblk = finallyblk; + result.member = tblk; + } + + public static void reInit() + { + add_cu_token_here = cu_to_insertion_point_1; + first_cu_token = null; + insertionpoint1set = false; + insertionpoint2set = false; + nextFreeLexState = 1; + } + +} diff --git a/csjavacc/parser/CSJavaCCParserTokenManager.java b/csjavacc/parser/CSJavaCCParserTokenManager.java new file mode 100644 index 0000000..bc3873f --- /dev/null +++ b/csjavacc/parser/CSJavaCCParserTokenManager.java @@ -0,0 +1,2765 @@ +/* Generated By:JavaCC: Do not edit this line. CSJavaCCParserTokenManager.java */ +/** + * This file contains the code for CSJavaCCParser generated + * by CSJavaCCParser itself. + */ + +package csjavacc.parser; +import java.util.Vector; +import csjavacc.struct.*; + +public class CSJavaCCParserTokenManager implements CSJavaCCParserConstants +{ + 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]); + } + public java.io.PrintStream debugStream = System.out; + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1, long active2) +{ + switch (pos) + { + case 0: + if ((active0 & 0x280000L) != 0L || (active1 & 0x4040000000000000L) != 0L) + return 2; + if ((active1 & 0x1000000000L) != 0L || (active2 & 0x200L) != 0L) + return 63; + if ((active0 & 0xfffffffff0001ffeL) != 0L || (active1 & 0x1ffffL) != 0L || (active2 & 0x3a180L) != 0L) + { + jjmatchedKind = 146; + return 87; + } + if ((active2 & 0x40L) != 0L) + return 120; + return -1; + case 1: + if ((active0 & 0x200000L) != 0L) + return 0; + if ((active0 & 0xd018000000000L) != 0L || (active1 & 0x800L) != 0L || (active2 & 0x12000L) != 0L) + return 87; + if ((active0 & 0xfff2fe7ff0001ffeL) != 0L || (active1 & 0x1f7ffL) != 0L || (active2 & 0x28180L) != 0L) + { + if (jjmatchedPos != 1) + { + jjmatchedKind = 146; + jjmatchedPos = 1; + } + return 87; + } + return -1; + case 2: + if ((active0 & 0xeed2bf7ff0000ffeL) != 0L || (active1 & 0xf6dfL) != 0L || (active2 & 0x28000L) != 0L) + { + if (jjmatchedPos != 2) + { + jjmatchedKind = 146; + jjmatchedPos = 2; + } + return 87; + } + if ((active0 & 0x112c400000001000L) != 0L || (active1 & 0x10920L) != 0L || (active2 & 0x180L) != 0L) + return 87; + return -1; + case 3: + if ((active0 & 0x508605a0000600L) != 0L || (active1 & 0x55L) != 0L || (active2 & 0x8000L) != 0L) + return 87; + if ((active0 & 0xee8a397a500009feL) != 0L || (active1 & 0xff8aL) != 0L || (active2 & 0x20000L) != 0L) + { + jjmatchedKind = 146; + jjmatchedPos = 3; + return 87; + } + return -1; + case 4: + if ((active0 & 0x4002081a40000880L) != 0L || (active1 & 0x4488L) != 0L) + return 87; + if ((active0 & 0xae8831601000017eL) != 0L || (active1 & 0xbb02L) != 0L || (active2 & 0x20000L) != 0L) + { + if (jjmatchedPos != 4) + { + jjmatchedKind = 146; + jjmatchedPos = 4; + } + return 87; + } + return -1; + case 5: + if ((active0 & 0xa800210000000040L) != 0L || (active1 & 0x8002L) != 0L) + return 87; + if ((active0 & 0x68810601000093eL) != 0L || (active1 & 0x3b00L) != 0L || (active2 & 0x20000L) != 0L) + { + jjmatchedKind = 146; + jjmatchedPos = 5; + return 87; + } + return -1; + case 6: + if ((active0 & 0x48810201000093cL) != 0L || (active1 & 0x3800L) != 0L) + { + jjmatchedKind = 146; + jjmatchedPos = 6; + return 87; + } + if ((active0 & 0x200004000000002L) != 0L || (active1 & 0x300L) != 0L || (active2 & 0x20000L) != 0L) + return 87; + return -1; + case 7: + if ((active0 & 0x102010000000L) != 0L || (active1 & 0x3800L) != 0L) + return 87; + if ((active0 & 0x48800000000093cL) != 0L) + { + jjmatchedKind = 146; + jjmatchedPos = 7; + return 87; + } + return -1; + case 8: + if ((active0 & 0x488000000000004L) != 0L) + return 87; + if ((active0 & 0x938L) != 0L) + { + jjmatchedKind = 146; + jjmatchedPos = 8; + return 87; + } + return -1; + case 9: + if ((active0 & 0x20L) != 0L) + return 87; + if ((active0 & 0x918L) != 0L) + { + jjmatchedKind = 146; + jjmatchedPos = 9; + return 87; + } + return -1; + case 10: + if ((active0 & 0x910L) != 0L) + { + jjmatchedKind = 146; + jjmatchedPos = 10; + return 87; + } + if ((active0 & 0x8L) != 0L) + return 87; + return -1; + case 11: + if ((active0 & 0x10L) != 0L) + return 87; + if ((active0 & 0x900L) != 0L) + { + jjmatchedKind = 146; + jjmatchedPos = 11; + return 87; + } + return -1; + case 12: + if ((active0 & 0x100L) != 0L) + return 87; + if ((active0 & 0x800L) != 0L) + { + jjmatchedKind = 146; + jjmatchedPos = 12; + return 87; + } + return -1; + case 13: + if ((active0 & 0x800L) != 0L) + { + jjmatchedKind = 146; + jjmatchedPos = 13; + return 87; + } + return -1; + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0, long active1, long active2) +{ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0, active1, active2), pos + 1); +} +private final int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private final int jjStartNfaWithStates_0(int pos, int kind, int state) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return pos + 1; } + return jjMoveNfa_0(state, pos + 1); +} +private final int jjMoveStringLiteralDfa0_0() +{ + switch(curChar) + { + case 12: + return jjStopAtPos(0, 17); + case 33: + jjmatchedKind = 103; + return jjMoveStringLiteralDfa1_0(0x0L, 0x400000000000L, 0x0L); + case 35: + return jjStartNfaWithStates_0(0, 134, 120); + case 37: + jjmatchedKind = 122; + return jjMoveStringLiteralDfa1_0(0x0L, 0x0L, 0x4L); + case 38: + jjmatchedKind = 119; + return jjMoveStringLiteralDfa1_0(0x0L, 0x8001000000000000L, 0x0L); + case 40: + return jjStopAtPos(0, 92); + case 41: + return jjStopAtPos(0, 93); + case 42: + jjmatchedKind = 117; + return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000000000000L, 0x0L); + case 43: + jjmatchedKind = 115; + return jjMoveStringLiteralDfa1_0(0x0L, 0x802000000000000L, 0x0L); + case 44: + return jjStopAtPos(0, 99); + case 45: + jjmatchedKind = 116; + return jjMoveStringLiteralDfa1_0(0x0L, 0x1004000000000000L, 0x0L); + case 46: + jjmatchedKind = 100; + return jjMoveStringLiteralDfa1_0(0x0L, 0x0L, 0x200L); + case 47: + jjmatchedKind = 118; + return jjMoveStringLiteralDfa1_0(0x280000L, 0x4000000000000000L, 0x0L); + case 58: + return jjStopAtPos(0, 106); + case 59: + return jjStopAtPos(0, 98); + case 60: + jjmatchedKind = 102; + return jjMoveStringLiteralDfa1_0(0x0L, 0x100000000000L, 0x4400L); + case 61: + jjmatchedKind = 101; + return jjMoveStringLiteralDfa1_0(0x0L, 0x80000000000L, 0x0L); + case 62: + jjmatchedKind = 133; + return jjMoveStringLiteralDfa1_0(0x0L, 0x200000000000L, 0x1818L); + case 63: + return jjStopAtPos(0, 105); + case 67: + return jjMoveStringLiteralDfa1_0(0x40L, 0x0L, 0x0L); + case 69: + return jjMoveStringLiteralDfa1_0(0x1000L, 0x0L, 0x0L); + case 73: + return jjMoveStringLiteralDfa1_0(0x8L, 0x0L, 0x0L); + case 76: + return jjMoveStringLiteralDfa1_0(0x4L, 0x0L, 0x0L); + case 77: + return jjMoveStringLiteralDfa1_0(0x200L, 0x0L, 0x0L); + case 80: + return jjMoveStringLiteralDfa1_0(0x30L, 0x0L, 0x0L); + case 83: + return jjMoveStringLiteralDfa1_0(0x500L, 0x0L, 0x0L); + case 84: + return jjMoveStringLiteralDfa1_0(0x880L, 0x0L, 0x0L); + case 91: + return jjStopAtPos(0, 96); + case 93: + return jjStopAtPos(0, 97); + case 94: + jjmatchedKind = 121; + return jjMoveStringLiteralDfa1_0(0x0L, 0x0L, 0x2L); + case 97: + return jjMoveStringLiteralDfa1_0(0x10000000L, 0x0L, 0x0L); + case 98: + return jjMoveStringLiteralDfa1_0(0xe0000000L, 0x1L, 0x0L); + case 99: + return jjMoveStringLiteralDfa1_0(0x3f00000000L, 0x0L, 0x0L); + case 100: + return jjMoveStringLiteralDfa1_0(0x1c000000000L, 0x1000L, 0x0L); + case 101: + return jjMoveStringLiteralDfa1_0(0x60000000000L, 0x0L, 0x0L); + case 102: + return jjMoveStringLiteralDfa1_0(0x480000000000L, 0x4100L, 0x20000L); + case 103: + return jjMoveStringLiteralDfa1_0(0x800000000000L, 0x0L, 0x80L); + case 105: + return jjMoveStringLiteralDfa1_0(0xd000000000000L, 0x800L, 0x12000L); + case 108: + return jjMoveStringLiteralDfa1_0(0x10000000000000L, 0x0L, 0x8000L); + case 110: + return jjMoveStringLiteralDfa1_0(0xe0000000000000L, 0x0L, 0x0L); + case 111: + return jjMoveStringLiteralDfa1_0(0x100100000000002L, 0x0L, 0x0L); + case 112: + return jjMoveStringLiteralDfa1_0(0xe00000000000000L, 0x200L, 0x0L); + case 114: + return jjMoveStringLiteralDfa1_0(0x3000000000000000L, 0x2000L, 0x0L); + case 115: + return jjMoveStringLiteralDfa1_0(0xc000200000000000L, 0x2L, 0x100L); + case 116: + return jjMoveStringLiteralDfa1_0(0x0L, 0x3cL, 0x0L); + case 117: + return jjMoveStringLiteralDfa1_0(0x2000000000000L, 0x8000L, 0x0L); + case 118: + return jjMoveStringLiteralDfa1_0(0x0L, 0x10040L, 0x0L); + case 119: + return jjMoveStringLiteralDfa1_0(0x0L, 0x80L, 0x0L); + case 121: + return jjMoveStringLiteralDfa1_0(0x0L, 0x400L, 0x0L); + case 123: + return jjStopAtPos(0, 94); + case 124: + jjmatchedKind = 120; + return jjMoveStringLiteralDfa1_0(0x0L, 0x800000000000L, 0x1L); + case 125: + return jjStopAtPos(0, 95); + case 126: + return jjStopAtPos(0, 104); + default : + return jjMoveNfa_0(3, 0); + } +} +private final int jjMoveStringLiteralDfa1_0(long active0, long active1, long active2) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0, active1, active2); + return 1; + } + switch(curChar) + { + case 38: + if ((active1 & 0x1000000000000L) != 0L) + return jjStopAtPos(1, 112); + break; + case 42: + if ((active0 & 0x200000L) != 0L) + return jjStartNfaWithStates_0(1, 21, 0); + break; + case 43: + if ((active1 & 0x2000000000000L) != 0L) + return jjStopAtPos(1, 113); + break; + case 45: + if ((active1 & 0x4000000000000L) != 0L) + return jjStopAtPos(1, 114); + break; + case 46: + return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0L, active2, 0x200L); + case 47: + if ((active0 & 0x80000L) != 0L) + return jjStopAtPos(1, 19); + break; + case 60: + if ((active2 & 0x4000L) != 0L) + { + jjmatchedKind = 142; + jjmatchedPos = 1; + } + return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0L, active2, 0x400L); + case 61: + if ((active1 & 0x80000000000L) != 0L) + return jjStopAtPos(1, 107); + else if ((active1 & 0x100000000000L) != 0L) + return jjStopAtPos(1, 108); + else if ((active1 & 0x200000000000L) != 0L) + return jjStopAtPos(1, 109); + else if ((active1 & 0x400000000000L) != 0L) + return jjStopAtPos(1, 110); + else if ((active1 & 0x800000000000000L) != 0L) + return jjStopAtPos(1, 123); + else if ((active1 & 0x1000000000000000L) != 0L) + return jjStopAtPos(1, 124); + else if ((active1 & 0x2000000000000000L) != 0L) + return jjStopAtPos(1, 125); + else if ((active1 & 0x4000000000000000L) != 0L) + return jjStopAtPos(1, 126); + else if ((active1 & 0x8000000000000000L) != 0L) + return jjStopAtPos(1, 127); + else if ((active2 & 0x1L) != 0L) + return jjStopAtPos(1, 128); + else if ((active2 & 0x2L) != 0L) + return jjStopAtPos(1, 129); + else if ((active2 & 0x4L) != 0L) + return jjStopAtPos(1, 130); + break; + case 62: + if ((active2 & 0x10L) != 0L) + { + jjmatchedKind = 132; + jjmatchedPos = 1; + } + return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0L, active2, 0x1808L); + case 65: + return jjMoveStringLiteralDfa2_0(active0, 0x30L, active1, 0L, active2, 0L); + case 71: + return jjMoveStringLiteralDfa2_0(active0, 0x8L, active1, 0L, active2, 0L); + case 75: + return jjMoveStringLiteralDfa2_0(active0, 0x400L, active1, 0L, active2, 0L); + case 79: + return jjMoveStringLiteralDfa2_0(active0, 0x1a84L, active1, 0L, active2, 0L); + case 80: + return jjMoveStringLiteralDfa2_0(active0, 0x100L, active1, 0L, active2, 0L); + case 83: + return jjMoveStringLiteralDfa2_0(active0, 0x40L, active1, 0L, active2, 0L); + case 97: + return jjMoveStringLiteralDfa2_0(active0, 0x80080300000000L, active1, 0x10201L, active2, 0L); + case 98: + return jjMoveStringLiteralDfa2_0(active0, 0x10000000L, active1, 0L, active2, 0L); + case 101: + return jjMoveStringLiteralDfa2_0(active0, 0x3020004000000000L, active1, 0x3000L, active2, 0x180L); + case 102: + if ((active0 & 0x1000000000000L) != 0L) + return jjStartNfaWithStates_0(1, 48, 87); + break; + case 104: + return jjMoveStringLiteralDfa2_0(active0, 0x4000000400000000L, active1, 0x8cL, active2, 0L); + case 105: + return jjMoveStringLiteralDfa2_0(active0, 0x200000000000L, active1, 0x4400L, active2, 0x20000L); + case 108: + return jjMoveStringLiteralDfa2_0(active0, 0x20800000000L, active1, 0L, active2, 0L); + case 110: + if ((active2 & 0x10000L) != 0L) + { + jjmatchedKind = 144; + jjmatchedPos = 1; + } + return jjMoveStringLiteralDfa2_0(active0, 0xc040000000000L, active1, 0x8800L, active2, 0L); + case 111: + if ((active0 & 0x8000000000L) != 0L) + { + jjmatchedKind = 39; + jjmatchedPos = 1; + } + return jjMoveStringLiteralDfa2_0(active0, 0x10c13020000000L, active1, 0x140L, active2, 0x8000L); + case 112: + return jjMoveStringLiteralDfa2_0(active0, 0x2L, active1, 0L, active2, 0L); + case 114: + return jjMoveStringLiteralDfa2_0(active0, 0x600000040000000L, active1, 0x30L, active2, 0L); + case 115: + if ((active2 & 0x2000L) != 0L) + return jjStartNfaWithStates_0(1, 141, 87); + return jjMoveStringLiteralDfa2_0(active0, 0x2000000000000L, active1, 0L, active2, 0L); + case 116: + return jjMoveStringLiteralDfa2_0(active0, 0x8000000000000000L, active1, 0L, active2, 0L); + case 117: + return jjMoveStringLiteralDfa2_0(active0, 0x940000000000000L, active1, 0L, active2, 0L); + case 118: + return jjMoveStringLiteralDfa2_0(active0, 0x100000000000L, active1, 0L, active2, 0L); + case 119: + return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x2L, active2, 0L); + case 121: + return jjMoveStringLiteralDfa2_0(active0, 0x80000000L, active1, 0L, active2, 0L); + case 124: + if ((active1 & 0x800000000000L) != 0L) + return jjStopAtPos(1, 111); + break; + default : + break; + } + return jjStartNfa_0(0, active0, active1, active2); +} +private final int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long active1, long old2, long active2) +{ + if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) + return jjStartNfa_0(0, old0, old1, old2); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0, active1, active2); + return 2; + } + switch(curChar) + { + case 46: + if ((active2 & 0x200L) != 0L) + return jjStopAtPos(2, 137); + break; + case 61: + if ((active2 & 0x400L) != 0L) + return jjStopAtPos(2, 138); + else if ((active2 & 0x800L) != 0L) + return jjStopAtPos(2, 139); + break; + case 62: + if ((active2 & 0x8L) != 0L) + { + jjmatchedKind = 131; + jjmatchedPos = 2; + } + return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0L, active2, 0x1000L); + case 67: + return jjMoveStringLiteralDfa3_0(active0, 0x40L, active1, 0L, active2, 0L); + case 69: + return jjMoveStringLiteralDfa3_0(active0, 0x100L, active1, 0L, active2, 0L); + case 70: + if ((active0 & 0x1000L) != 0L) + return jjStartNfaWithStates_0(2, 12, 87); + break; + case 73: + return jjMoveStringLiteralDfa3_0(active0, 0x400L, active1, 0L, active2, 0L); + case 75: + return jjMoveStringLiteralDfa3_0(active0, 0x880L, active1, 0L, active2, 0L); + case 78: + return jjMoveStringLiteralDfa3_0(active0, 0x8L, active1, 0L, active2, 0L); + case 79: + return jjMoveStringLiteralDfa3_0(active0, 0x4L, active1, 0L, active2, 0L); + case 82: + return jjMoveStringLiteralDfa3_0(active0, 0x230L, active1, 0L, active2, 0L); + case 97: + return jjMoveStringLiteralDfa3_0(active0, 0x8000000c00000000L, active1, 0x2000L, active2, 0L); + case 98: + return jjMoveStringLiteralDfa3_0(active0, 0x800000000000000L, active1, 0L, active2, 0L); + case 99: + return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0L, active2, 0x8000L); + case 101: + return jjMoveStringLiteralDfa3_0(active0, 0x100040000000L, active1, 0x400L, active2, 0L); + case 102: + if ((active0 & 0x1000000000000000L) != 0L) + return jjStartNfaWithStates_0(2, 60, 87); + return jjMoveStringLiteralDfa3_0(active0, 0x4000000000L, active1, 0L, active2, 0L); + case 105: + return jjMoveStringLiteralDfa3_0(active0, 0x202000000000000L, active1, 0xc6L, active2, 0L); + case 108: + return jjMoveStringLiteralDfa3_0(active0, 0x40080000000000L, active1, 0x1000L, active2, 0L); + case 109: + return jjMoveStringLiteralDfa3_0(active0, 0x80000000000000L, active1, 0L, active2, 0L); + case 110: + return jjMoveStringLiteralDfa3_0(active0, 0x10203000000000L, active1, 0L, active2, 0x20000L); + case 111: + return jjMoveStringLiteralDfa3_0(active0, 0x4400000020000000L, active1, 0L, active2, 0L); + case 114: + if ((active0 & 0x400000000000L) != 0L) + { + jjmatchedKind = 46; + jjmatchedPos = 2; + } + else if ((active1 & 0x10000L) != 0L) + return jjStartNfaWithStates_0(2, 80, 87); + return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0x308L, active2, 0L); + case 115: + return jjMoveStringLiteralDfa3_0(active0, 0x20110000000L, active1, 0x8001L, active2, 0L); + case 116: + if ((active0 & 0x4000000000000L) != 0L) + { + jjmatchedKind = 50; + jjmatchedPos = 2; + } + else if ((active0 & 0x100000000000000L) != 0L) + return jjStartNfaWithStates_0(2, 56, 87); + else if ((active2 & 0x80L) != 0L) + return jjStartNfaWithStates_0(2, 135, 87); + else if ((active2 & 0x100L) != 0L) + return jjStartNfaWithStates_0(2, 136, 87); + return jjMoveStringLiteralDfa3_0(active0, 0x2008800280000002L, active1, 0x800L, active2, 0L); + case 117: + return jjMoveStringLiteralDfa3_0(active0, 0x50000000000L, active1, 0x10L, active2, 0L); + case 119: + if ((active0 & 0x20000000000000L) != 0L) + return jjStartNfaWithStates_0(2, 53, 87); + break; + case 120: + return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0x4000L, active2, 0L); + case 121: + if ((active1 & 0x20L) != 0L) + return jjStartNfaWithStates_0(2, 69, 87); + break; + default : + break; + } + return jjStartNfa_0(1, active0, active1, active2); +} +private final int jjMoveStringLiteralDfa3_0(long old0, long active0, long old1, long active1, long old2, long active2) +{ + if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) + return jjStartNfa_0(1, old0, old1, old2); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0, active1, active2); + return 3; + } + switch(curChar) + { + case 61: + if ((active2 & 0x1000L) != 0L) + return jjStopAtPos(3, 140); + break; + case 67: + return jjMoveStringLiteralDfa4_0(active0, 0x100L, active1, 0L, active2, 0L); + case 69: + if ((active0 & 0x200L) != 0L) + return jjStartNfaWithStates_0(3, 9, 87); + return jjMoveStringLiteralDfa4_0(active0, 0x880L, active1, 0L, active2, 0L); + case 75: + return jjMoveStringLiteralDfa4_0(active0, 0x4L, active1, 0L, active2, 0L); + case 79: + return jjMoveStringLiteralDfa4_0(active0, 0x48L, active1, 0L, active2, 0L); + case 80: + if ((active0 & 0x400L) != 0L) + return jjStartNfaWithStates_0(3, 10, 87); + break; + case 83: + return jjMoveStringLiteralDfa4_0(active0, 0x30L, active1, 0L, active2, 0L); + case 97: + return jjMoveStringLiteralDfa4_0(active0, 0x4040000000L, active1, 0x8000L, active2, 0x20000L); + case 98: + return jjMoveStringLiteralDfa4_0(active0, 0x10000000000L, active1, 0L, active2, 0L); + case 99: + return jjMoveStringLiteralDfa4_0(active0, 0x200000000L, active1, 0L, active2, 0L); + case 100: + if ((active1 & 0x40L) != 0L) + return jjStartNfaWithStates_0(3, 70, 87); + return jjMoveStringLiteralDfa4_0(active0, 0L, active1, 0x2000L, active2, 0L); + case 101: + if ((active0 & 0x80000000L) != 0L) + return jjStartNfaWithStates_0(3, 31, 87); + else if ((active0 & 0x100000000L) != 0L) + return jjStartNfaWithStates_0(3, 32, 87); + else if ((active0 & 0x20000000000L) != 0L) + return jjStartNfaWithStates_0(3, 41, 87); + else if ((active1 & 0x1L) != 0L) + return jjStartNfaWithStates_0(3, 64, 87); + else if ((active1 & 0x10L) != 0L) + return jjStartNfaWithStates_0(3, 68, 87); + return jjMoveStringLiteralDfa4_0(active0, 0x88000000000000L, active1, 0x5900L, active2, 0L); + case 103: + if ((active0 & 0x10000000000000L) != 0L) + return jjStartNfaWithStates_0(3, 52, 87); + return jjMoveStringLiteralDfa4_0(active0, 0x200000000000L, active1, 0L, active2, 0L); + case 105: + return jjMoveStringLiteralDfa4_0(active0, 0x2L, active1, 0L, active2, 0L); + case 107: + if ((active2 & 0x8000L) != 0L) + return jjStartNfaWithStates_0(3, 143, 87); + break; + case 108: + if ((active0 & 0x20000000L) != 0L) + return jjStartNfaWithStates_0(3, 29, 87); + else if ((active0 & 0x40000000000000L) != 0L) + return jjStartNfaWithStates_0(3, 54, 87); + return jjMoveStringLiteralDfa4_0(active0, 0x800000000000000L, active1, 0x480L, active2, 0L); + case 109: + if ((active0 & 0x40000000000L) != 0L) + return jjStartNfaWithStates_0(3, 42, 87); + break; + case 110: + return jjMoveStringLiteralDfa4_0(active0, 0x2000000000000L, active1, 0L, active2, 0L); + case 111: + if ((active0 & 0x800000000000L) != 0L) + return jjStartNfaWithStates_0(3, 47, 87); + return jjMoveStringLiteralDfa4_0(active0, 0L, active1, 0x8L, active2, 0L); + case 114: + if ((active0 & 0x400000000L) != 0L) + return jjStartNfaWithStates_0(3, 34, 87); + return jjMoveStringLiteralDfa4_0(active0, 0x4000100000000000L, active1, 0L, active2, 0L); + case 115: + if ((active1 & 0x4L) != 0L) + return jjStartNfaWithStates_0(3, 66, 87); + return jjMoveStringLiteralDfa4_0(active0, 0x81800000000L, active1, 0L, active2, 0L); + case 116: + return jjMoveStringLiteralDfa4_0(active0, 0x8400002010000000L, active1, 0x202L, active2, 0L); + case 117: + return jjMoveStringLiteralDfa4_0(active0, 0x2000000000000000L, active1, 0L, active2, 0L); + case 118: + return jjMoveStringLiteralDfa4_0(active0, 0x200000000000000L, active1, 0L, active2, 0L); + default : + break; + } + return jjStartNfa_0(2, active0, active1, active2); +} +private final int jjMoveStringLiteralDfa4_0(long old0, long active0, long old1, long active1, long old2, long active2) +{ + if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) + return jjStartNfa_0(2, old0, old1, old2); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(3, active0, active1, active2); + return 4; + } + switch(curChar) + { + case 65: + return jjMoveStringLiteralDfa5_0(active0, 0x4L, active1, 0L, active2, 0L); + case 68: + return jjMoveStringLiteralDfa5_0(active0, 0x40L, active1, 0L, active2, 0L); + case 69: + return jjMoveStringLiteralDfa5_0(active0, 0x30L, active1, 0L, active2, 0L); + case 73: + return jjMoveStringLiteralDfa5_0(active0, 0x100L, active1, 0L, active2, 0L); + case 78: + if ((active0 & 0x80L) != 0L) + { + jjmatchedKind = 7; + jjmatchedPos = 4; + } + return jjMoveStringLiteralDfa5_0(active0, 0x800L, active1, 0L, active2, 0L); + case 82: + return jjMoveStringLiteralDfa5_0(active0, 0x8L, active1, 0L, active2, 0L); + case 97: + return jjMoveStringLiteralDfa5_0(active0, 0x200000000000000L, active1, 0x100L, active2, 0L); + case 99: + return jjMoveStringLiteralDfa5_0(active0, 0L, active1, 0x2L, active2, 0L); + case 100: + if ((active1 & 0x400L) != 0L) + return jjStartNfaWithStates_0(4, 74, 87); + else if ((active1 & 0x4000L) != 0L) + return jjStartNfaWithStates_0(4, 78, 87); + break; + case 101: + if ((active0 & 0x80000000000L) != 0L) + return jjStartNfaWithStates_0(4, 43, 87); + else if ((active1 & 0x80L) != 0L) + return jjStartNfaWithStates_0(4, 71, 87); + return jjMoveStringLiteralDfa5_0(active0, 0x400000000000000L, active1, 0L, active2, 0L); + case 102: + return jjMoveStringLiteralDfa5_0(active0, 0L, active1, 0x8000L, active2, 0L); + case 103: + if ((active0 & 0x2000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 49, 87); + return jjMoveStringLiteralDfa5_0(active0, 0L, active1, 0x1000L, active2, 0L); + case 104: + if ((active0 & 0x200000000L) != 0L) + return jjStartNfaWithStates_0(4, 33, 87); + break; + case 105: + return jjMoveStringLiteralDfa5_0(active0, 0x8800002000000000L, active1, 0x200L, active2, 0L); + case 107: + if ((active0 & 0x40000000L) != 0L) + return jjStartNfaWithStates_0(4, 30, 87); + break; + case 108: + return jjMoveStringLiteralDfa5_0(active0, 0x210000000000L, active1, 0L, active2, 0x20000L); + case 111: + return jjMoveStringLiteralDfa5_0(active0, 0x2L, active1, 0x2000L, active2, 0L); + case 114: + return jjMoveStringLiteralDfa5_0(active0, 0x2008100010000000L, active1, 0x800L, active2, 0L); + case 115: + if ((active0 & 0x800000000L) != 0L) + return jjStartNfaWithStates_0(4, 35, 87); + return jjMoveStringLiteralDfa5_0(active0, 0x80000000000000L, active1, 0L, active2, 0L); + case 116: + if ((active0 & 0x1000000000L) != 0L) + return jjStartNfaWithStates_0(4, 36, 87); + else if ((active0 & 0x4000000000000000L) != 0L) + return jjStartNfaWithStates_0(4, 62, 87); + break; + case 117: + return jjMoveStringLiteralDfa5_0(active0, 0x4000000000L, active1, 0L, active2, 0L); + case 119: + if ((active1 & 0x8L) != 0L) + return jjStartNfaWithStates_0(4, 67, 87); + break; + default : + break; + } + return jjStartNfa_0(3, active0, active1, active2); +} +private final int jjMoveStringLiteralDfa5_0(long old0, long active0, long old1, long active1, long old2, long active2) +{ + if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) + return jjStartNfa_0(3, old0, old1, old2); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(4, active0, active1, active2); + return 5; + } + switch(curChar) + { + case 65: + return jjMoveStringLiteralDfa6_0(active0, 0x100L, active1, 0L, active2, 0L); + case 69: + if ((active0 & 0x40L) != 0L) + return jjStartNfaWithStates_0(5, 6, 87); + return jjMoveStringLiteralDfa6_0(active0, 0x8L, active1, 0L, active2, 0L); + case 72: + return jjMoveStringLiteralDfa6_0(active0, 0x4L, active1, 0L, active2, 0L); + case 82: + return jjMoveStringLiteralDfa6_0(active0, 0x30L, active1, 0L, active2, 0L); + case 95: + return jjMoveStringLiteralDfa6_0(active0, 0x800L, active1, 0L, active2, 0L); + case 97: + return jjMoveStringLiteralDfa6_0(active0, 0x10000000L, active1, 0x1200L, active2, 0L); + case 99: + if ((active0 & 0x800000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 59, 87); + else if ((active0 & 0x8000000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 63, 87); + return jjMoveStringLiteralDfa6_0(active0, 0x400000000000000L, active1, 0x100L, active2, 0L); + case 101: + if ((active0 & 0x10000000000L) != 0L) + return jjStartNfaWithStates_0(5, 40, 87); + else if ((active0 & 0x200000000000L) != 0L) + return jjStartNfaWithStates_0(5, 45, 87); + else if ((active1 & 0x8000L) != 0L) + return jjStartNfaWithStates_0(5, 79, 87); + break; + case 102: + return jjMoveStringLiteralDfa6_0(active0, 0x8000000000000L, active1, 0L, active2, 0L); + case 104: + if ((active1 & 0x2L) != 0L) + return jjStartNfaWithStates_0(5, 65, 87); + break; + case 105: + return jjMoveStringLiteralDfa6_0(active0, 0x100000000000L, active1, 0L, active2, 0L); + case 108: + return jjMoveStringLiteralDfa6_0(active0, 0x4000000000L, active1, 0L, active2, 0x20000L); + case 110: + if ((active0 & 0x2000000000000000L) != 0L) + return jjStartNfaWithStates_0(5, 61, 87); + return jjMoveStringLiteralDfa6_0(active0, 0x2000000002L, active1, 0x2800L, active2, 0L); + case 112: + return jjMoveStringLiteralDfa6_0(active0, 0x80000000000000L, active1, 0L, active2, 0L); + case 116: + return jjMoveStringLiteralDfa6_0(active0, 0x200000000000000L, active1, 0L, active2, 0L); + default : + break; + } + return jjStartNfa_0(4, active0, active1, active2); +} +private final int jjMoveStringLiteralDfa6_0(long old0, long active0, long old1, long active1, long old2, long active2) +{ + if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) + return jjStartNfa_0(4, old0, old1, old2); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(5, active0, active1, active2); + return 6; + } + switch(curChar) + { + case 69: + return jjMoveStringLiteralDfa7_0(active0, 0x4L, active1, 0L, active2, 0L); + case 76: + return jjMoveStringLiteralDfa7_0(active0, 0x100L, active1, 0L, active2, 0L); + case 77: + return jjMoveStringLiteralDfa7_0(active0, 0x800L, active1, 0L, active2, 0L); + case 95: + return jjMoveStringLiteralDfa7_0(active0, 0x38L, active1, 0L, active2, 0L); + case 97: + return jjMoveStringLiteralDfa7_0(active0, 0x88000000000000L, active1, 0x800L, active2, 0L); + case 99: + return jjMoveStringLiteralDfa7_0(active0, 0x10000000L, active1, 0L, active2, 0L); + case 100: + return jjMoveStringLiteralDfa7_0(active0, 0x100000000000L, active1, 0L, active2, 0L); + case 101: + if ((active0 & 0x200000000000000L) != 0L) + return jjStartNfaWithStates_0(6, 57, 87); + break; + case 104: + if ((active1 & 0x100L) != 0L) + return jjStartNfaWithStates_0(6, 72, 87); + break; + case 108: + if ((active1 & 0x200L) != 0L) + return jjStartNfaWithStates_0(6, 73, 87); + return jjMoveStringLiteralDfa7_0(active0, 0L, active1, 0x2000L, active2, 0L); + case 115: + if ((active0 & 0x2L) != 0L) + return jjStartNfaWithStates_0(6, 1, 87); + break; + case 116: + if ((active0 & 0x4000000000L) != 0L) + return jjStartNfaWithStates_0(6, 38, 87); + return jjMoveStringLiteralDfa7_0(active0, 0x400000000000000L, active1, 0x1000L, active2, 0L); + case 117: + return jjMoveStringLiteralDfa7_0(active0, 0x2000000000L, active1, 0L, active2, 0L); + case 121: + if ((active2 & 0x20000L) != 0L) + return jjStartNfaWithStates_0(6, 145, 87); + break; + default : + break; + } + return jjStartNfa_0(5, active0, active1, active2); +} +private final int jjMoveStringLiteralDfa7_0(long old0, long active0, long old1, long active1, long old2, long active2) +{ + if (((active0 &= old0) | (active1 &= old1) | (active2 &= old2)) == 0L) + return jjStartNfa_0(5, old0, old1, old2); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(6, active0, active1, 0L); + return 7; + } + switch(curChar) + { + case 65: + return jjMoveStringLiteralDfa8_0(active0, 0x4L, active1, 0L); + case 66: + return jjMoveStringLiteralDfa8_0(active0, 0x10L, active1, 0L); + case 67: + return jjMoveStringLiteralDfa8_0(active0, 0x8L, active1, 0L); + case 69: + return jjMoveStringLiteralDfa8_0(active0, 0x20L, active1, 0L); + case 71: + return jjMoveStringLiteralDfa8_0(active0, 0x800L, active1, 0L); + case 95: + return jjMoveStringLiteralDfa8_0(active0, 0x100L, active1, 0L); + case 99: + return jjMoveStringLiteralDfa8_0(active0, 0x88000000000000L, active1, 0L); + case 101: + if ((active0 & 0x2000000000L) != 0L) + return jjStartNfaWithStates_0(7, 37, 87); + else if ((active0 & 0x100000000000L) != 0L) + return jjStartNfaWithStates_0(7, 44, 87); + else if ((active1 & 0x1000L) != 0L) + return jjStartNfaWithStates_0(7, 76, 87); + return jjMoveStringLiteralDfa8_0(active0, 0x400000000000000L, active1, 0L); + case 108: + if ((active1 & 0x800L) != 0L) + return jjStartNfaWithStates_0(7, 75, 87); + break; + case 116: + if ((active0 & 0x10000000L) != 0L) + return jjStartNfaWithStates_0(7, 28, 87); + break; + case 121: + if ((active1 & 0x2000L) != 0L) + return jjStartNfaWithStates_0(7, 77, 87); + break; + default : + break; + } + return jjStartNfa_0(6, active0, active1, 0L); +} +private final int jjMoveStringLiteralDfa8_0(long old0, long active0, long old1, long active1) +{ + if (((active0 &= old0) | (active1 &= old1)) == 0L) + return jjStartNfa_0(6, old0, old1, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(7, active0, 0L, 0L); + return 8; + } + switch(curChar) + { + case 65: + return jjMoveStringLiteralDfa9_0(active0, 0x8L); + case 68: + if ((active0 & 0x4L) != 0L) + return jjStartNfaWithStates_0(8, 2, 87); + break; + case 69: + return jjMoveStringLiteralDfa9_0(active0, 0x10L); + case 78: + return jjMoveStringLiteralDfa9_0(active0, 0x20L); + case 82: + return jjMoveStringLiteralDfa9_0(active0, 0x800L); + case 84: + return jjMoveStringLiteralDfa9_0(active0, 0x100L); + case 100: + if ((active0 & 0x400000000000000L) != 0L) + return jjStartNfaWithStates_0(8, 58, 87); + break; + case 101: + if ((active0 & 0x8000000000000L) != 0L) + return jjStartNfaWithStates_0(8, 51, 87); + else if ((active0 & 0x80000000000000L) != 0L) + return jjStartNfaWithStates_0(8, 55, 87); + break; + default : + break; + } + return jjStartNfa_0(7, active0, 0L, 0L); +} +private final int jjMoveStringLiteralDfa9_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(7, old0, 0L, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(8, active0, 0L, 0L); + return 9; + } + switch(curChar) + { + case 68: + if ((active0 & 0x20L) != 0L) + return jjStartNfaWithStates_0(9, 5, 87); + break; + case 71: + return jjMoveStringLiteralDfa10_0(active0, 0x10L); + case 79: + return jjMoveStringLiteralDfa10_0(active0, 0x100L); + case 83: + return jjMoveStringLiteralDfa10_0(active0, 0x8L); + case 95: + return jjMoveStringLiteralDfa10_0(active0, 0x800L); + default : + break; + } + return jjStartNfa_0(8, active0, 0L, 0L); +} +private final int jjMoveStringLiteralDfa10_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(8, old0, 0L, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(9, active0, 0L, 0L); + return 10; + } + switch(curChar) + { + case 68: + return jjMoveStringLiteralDfa11_0(active0, 0x800L); + case 69: + if ((active0 & 0x8L) != 0L) + return jjStartNfaWithStates_0(10, 3, 87); + break; + case 73: + return jjMoveStringLiteralDfa11_0(active0, 0x10L); + case 75: + return jjMoveStringLiteralDfa11_0(active0, 0x100L); + default : + break; + } + return jjStartNfa_0(9, active0, 0L, 0L); +} +private final int jjMoveStringLiteralDfa11_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(9, old0, 0L, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(10, active0, 0L, 0L); + return 11; + } + switch(curChar) + { + case 69: + return jjMoveStringLiteralDfa12_0(active0, 0x900L); + case 78: + if ((active0 & 0x10L) != 0L) + return jjStartNfaWithStates_0(11, 4, 87); + break; + default : + break; + } + return jjStartNfa_0(10, active0, 0L, 0L); +} +private final int jjMoveStringLiteralDfa12_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(10, old0, 0L, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(11, active0, 0L, 0L); + return 12; + } + switch(curChar) + { + case 67: + return jjMoveStringLiteralDfa13_0(active0, 0x800L); + case 78: + if ((active0 & 0x100L) != 0L) + return jjStartNfaWithStates_0(12, 8, 87); + break; + default : + break; + } + return jjStartNfa_0(11, active0, 0L, 0L); +} +private final int jjMoveStringLiteralDfa13_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(11, old0, 0L, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(12, active0, 0L, 0L); + return 13; + } + switch(curChar) + { + case 76: + return jjMoveStringLiteralDfa14_0(active0, 0x800L); + default : + break; + } + return jjStartNfa_0(12, active0, 0L, 0L); +} +private final int jjMoveStringLiteralDfa14_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(12, old0, 0L, 0L); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(13, active0, 0L, 0L); + return 14; + } + switch(curChar) + { + case 83: + if ((active0 & 0x800L) != 0L) + return jjStartNfaWithStates_0(14, 11, 87); + break; + default : + break; + } + return jjStartNfa_0(13, active0, 0L, 0L); +} +private final void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private final void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private final void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} +private final void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} +private final void jjCheckNAddStates(int start) +{ + jjCheckNAdd(jjnextStates[start]); + jjCheckNAdd(jjnextStates[start + 1]); +} +static final long[] jjbitVec0 = { + 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec2 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec3 = { + 0xfff0000000200002L, 0xffffffffffffdfffL, 0xfffff00f7fffffffL, 0x12000000007fffffL +}; +static final long[] jjbitVec4 = { + 0x0L, 0x0L, 0x420043c00000000L, 0xff7fffffff7fffffL +}; +static final long[] jjbitVec5 = { + 0xffffcffffffffL, 0xffffffffffff0000L, 0xf9ff3fffffffffffL, 0x401f00030003L +}; +static final long[] jjbitVec6 = { + 0x0L, 0x400000000000000L, 0xfffffffbffffd740L, 0xffffffcff7fffL +}; +static final long[] jjbitVec7 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffffff003L, 0x33fffffffff199fL +}; +static final long[] jjbitVec8 = { + 0xfffe000000000000L, 0xfffffffe027fffffL, 0xffL, 0x707ffffff0000L +}; +static final long[] jjbitVec9 = { + 0x7fffffe00000000L, 0xfffe0000000007ffL, 0xffffffffffffffffL, 0x1c000060002fffffL +}; +static final long[] jjbitVec10 = { + 0x1ffffffd0000L, 0x0L, 0x3fffffffffL, 0x0L +}; +static final long[] jjbitVec11 = { + 0x23ffffffffffffe0L, 0x3ff010000L, 0x3c5fdfffff99fe0L, 0xf0003b0000000L +}; +static final long[] jjbitVec12 = { + 0x36dfdfffff987e0L, 0x1c00005e000000L, 0x23edfdfffffbafe0L, 0x100010000L +}; +static final long[] jjbitVec13 = { + 0x23cdfdfffff99fe0L, 0x3b0000000L, 0x3bfc718d63dc7e0L, 0x0L +}; +static final long[] jjbitVec14 = { + 0x3effdfffffddfe0L, 0x300000000L, 0x3effdfffffddfe0L, 0x340000000L +}; +static final long[] jjbitVec15 = { + 0x3fffdfffffddfe0L, 0x300000000L, 0x2ffbfffffc7fffe0L, 0x7fL +}; +static final long[] jjbitVec16 = { + 0x800dfffffffffffeL, 0x7fL, 0x200decaefef02596L, 0x3000005fL +}; +static final long[] jjbitVec17 = { + 0x1L, 0x7fffffffeffL, 0xf00L, 0x0L +}; +static final long[] jjbitVec18 = { + 0x6fbffffffffL, 0x3f0000L, 0xffffffff00000000L, 0x7fffffffff003fL +}; +static final long[] jjbitVec19 = { + 0xffffffffffffffffL, 0xffffffff83ffffffL, 0xffffff07ffffffffL, 0x3ffffffffffffffL +}; +static final long[] jjbitVec20 = { + 0xffffffffffffff7fL, 0xffffffff3d7f3d7fL, 0x7f3d7fffffff3d7fL, 0xffff7fffff7f7f3dL +}; +static final long[] jjbitVec21 = { + 0xffffffff7f3d7fffL, 0x7ffff7fL, 0xffffffff00000000L, 0x1fffffffffffffL +}; +static final long[] jjbitVec22 = { + 0xffffffffffffffffL, 0x7f9fffffffffffL, 0xffffffff07fffffeL, 0x7ffffffffffL +}; +static final long[] jjbitVec23 = { + 0x0L, 0x0L, 0xfffffffffffffL, 0x8000000L +}; +static final long[] jjbitVec24 = { + 0xffffffff00000000L, 0xffffffffffffffL, 0x1ffffffffffL, 0x0L +}; +static final long[] jjbitVec25 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffff0fffffffL, 0x3ffffffffffffffL +}; +static final long[] jjbitVec26 = { + 0xffffffff3f3fffffL, 0x3fffffffaaff3f3fL, 0x5fdfffffffffffffL, 0x1fdc1fff0fcf1fdcL +}; +static final long[] jjbitVec27 = { + 0x8000000000000000L, 0x8000000000000001L, 0xffff00000000L, 0x0L +}; +static final long[] jjbitVec28 = { + 0x3fbbd503e2ffc84L, 0xffffffff00000000L, 0xfL, 0x0L +}; +static final long[] jjbitVec29 = { + 0x73e03fe000000e0L, 0xfffffffffffffffeL, 0xfffffffe601fffffL, 0x7fffffffffffffffL +}; +static final long[] jjbitVec30 = { + 0xfffe1fffffffffe0L, 0xffffffffffffffffL, 0xffffff00007fffL, 0x0L +}; +static final long[] jjbitVec31 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0x3fffffffffffffL, 0x0L +}; +static final long[] jjbitVec32 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0x3fffffffffL, 0x0L +}; +static final long[] jjbitVec33 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0x1fffL, 0x0L +}; +static final long[] jjbitVec34 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffL, 0x0L +}; +static final long[] jjbitVec35 = { + 0x3fffffffffffL, 0x0L, 0x0L, 0x0L +}; +static final long[] jjbitVec36 = { + 0x5f7ffdffa0f8007fL, 0xffffffffffffffdbL, 0x3ffffffffffffL, 0xfffffffffff80000L +}; +static final long[] jjbitVec37 = { + 0x3fffffffffffffffL, 0xffffffffffff0000L, 0xfffffffffffcffffL, 0xfff0000000000ffL +}; +static final long[] jjbitVec38 = { + 0x18000000000000L, 0xffd702000000e000L, 0xffffffffffffffffL, 0x1fffffffffffffffL +}; +static final long[] jjbitVec39 = { + 0x87fffffe00000010L, 0xffffffe007fffffeL, 0x7fffffffffffffffL, 0x631cfcfcfcL +}; +static final long[] jjbitVec40 = { + 0x0L, 0x0L, 0x420043cffffffffL, 0xff7fffffff7fffffL +}; +static final long[] jjbitVec41 = { + 0xffffffffffffffffL, 0x400000700007fffL, 0xfffffffbffffd740L, 0xffffffcff7fffL +}; +static final long[] jjbitVec42 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xfffffffffffff07bL, 0x33fffffffff199fL +}; +static final long[] jjbitVec43 = { + 0xfffe000000000000L, 0xfffffffe027fffffL, 0xbbfffffbfffe00ffL, 0x707ffffff0016L +}; +static final long[] jjbitVec44 = { + 0x7fffffe00000000L, 0xffff03ff003fffffL, 0xffffffffffffffffL, 0x1fff3dff9fefffffL +}; +static final long[] jjbitVec45 = { + 0xffff1fffffff8000L, 0x7ffL, 0x1ffffffffffffL, 0x0L +}; +static final long[] jjbitVec46 = { + 0xf3ffffffffffffeeL, 0xffcfff1f3fffL, 0xd3c5fdfffff99feeL, 0xfffcfb080399fL +}; +static final long[] jjbitVec47 = { + 0xd36dfdfffff987e4L, 0x1fffc05e003987L, 0xf3edfdfffffbafeeL, 0xffc100013bbfL +}; +static final long[] jjbitVec48 = { + 0xf3cdfdfffff99feeL, 0xffc3b0c0398fL, 0xc3bfc718d63dc7ecL, 0xff8000803dc7L +}; +static final long[] jjbitVec49 = { + 0xc3effdfffffddfeeL, 0xffc300603ddfL, 0xc3effdfffffddfecL, 0xffc340603ddfL +}; +static final long[] jjbitVec50 = { + 0xc3fffdfffffddfecL, 0xffc300803dcfL, 0x2ffbfffffc7fffecL, 0xc0000ff5f847fL +}; +static final long[] jjbitVec51 = { + 0x87fffffffffffffeL, 0x3ff7fffL, 0x3bffecaefef02596L, 0x33ff3f5fL +}; +static final long[] jjbitVec52 = { + 0xc2a003ff03000001L, 0xfffe07fffffffeffL, 0x1ffffffffeff0fdfL, 0x40L +}; +static final long[] jjbitVec53 = { + 0x3c7f6fbffffffffL, 0x3ff03ffL, 0xffffffff00000000L, 0x7fffffffff003fL +}; +static final long[] jjbitVec54 = { + 0xffffffff7f3d7fffL, 0x3fe0007ffff7fL, 0xffffffff00000000L, 0x1fffffffffffffL +}; +static final long[] jjbitVec55 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0x3ff080fffffL +}; +static final long[] jjbitVec56 = { + 0xffffffff03ff7800L, 0xffffffffffffffL, 0x3ffffffffffL, 0x0L +}; +static final long[] jjbitVec57 = { + 0x80007c000000f000L, 0x8000fc0000000001L, 0xffff00000000L, 0x21fff0000L +}; +static final long[] jjbitVec58 = { + 0x73efffe000000e0L, 0xfffffffffffffffeL, 0xfffffffe661fffffL, 0x7fffffffffffffffL +}; +static final long[] jjbitVec59 = { + 0x5f7ffdffe0f8007fL, 0xffffffffffffffdbL, 0x3ffffffffffffL, 0xfffffffffff80000L +}; +static final long[] jjbitVec60 = { + 0x18000f00000000L, 0xffd702000000e000L, 0xffffffffffffffffL, 0x9fffffffffffffffL +}; +static final long[] jjbitVec61 = { + 0x87fffffe03ff0010L, 0xffffffe007fffffeL, 0x7fffffffffffffffL, 0xe0000631cfcfcfcL +}; +private final int jjMoveNfa_0(int startState, int curPos) +{ + int[] nextStates; + int startsAt = 0; + jjnewStateCnt = 120; + int i = 1; + jjstateSet[0] = startState; + int j, kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + MatchLoop: do + { + switch(jjstateSet[--i]) + { + case 3: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddStates(0, 6); + else if (curChar == 34) + jjCheckNAddStates(7, 9); + else if (curChar == 39) + jjAddStates(10, 11); + else if (curChar == 46) + jjCheckNAdd(63); + else if (curChar == 35) + jjCheckNAddStates(12, 20); + else if (curChar == 47) + jjstateSet[jjnewStateCnt++] = 2; + if ((0x3fe000000000000L & l) != 0L) + { + if (kind > 81) + kind = 81; + jjCheckNAddTwoStates(60, 61); + } + else if (curChar == 48) + { + if (kind > 81) + kind = 81; + jjCheckNAddStates(21, 25); + } + break; + case 120: + case 5: + if ((0x100001200L & l) != 0L) + jjCheckNAddStates(12, 20); + break; + case 0: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 1; + break; + case 1: + if ((0xffff7fffffffffffL & l) != 0L && kind > 20) + kind = 20; + break; + case 2: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 0; + break; + case 4: + if (curChar == 35) + jjCheckNAddStates(12, 20); + break; + case 59: + if ((0x3fe000000000000L & l) == 0L) + break; + if (kind > 81) + kind = 81; + jjCheckNAddTwoStates(60, 61); + break; + case 60: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 81) + kind = 81; + jjCheckNAddTwoStates(60, 61); + break; + case 62: + if (curChar == 46) + jjCheckNAdd(63); + break; + case 63: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 85) + kind = 85; + jjCheckNAddStates(26, 28); + break; + case 65: + if ((0x280000000000L & l) != 0L) + jjCheckNAdd(66); + break; + case 66: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 85) + kind = 85; + jjCheckNAddTwoStates(66, 67); + break; + case 68: + if (curChar == 39) + jjAddStates(10, 11); + break; + case 69: + if ((0xffffff7fffffdbffL & l) != 0L) + jjCheckNAdd(70); + break; + case 70: + if (curChar == 39 && kind > 90) + kind = 90; + break; + case 72: + if ((0x8400000000L & l) != 0L) + jjCheckNAdd(70); + break; + case 73: + if ((0xff000000000000L & l) != 0L) + jjCheckNAddTwoStates(74, 70); + break; + case 74: + if ((0xff000000000000L & l) != 0L) + jjCheckNAdd(70); + break; + case 75: + if ((0xf000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 76; + break; + case 76: + if ((0xff000000000000L & l) != 0L) + jjCheckNAdd(74); + break; + case 77: + if (curChar == 34) + jjCheckNAddStates(7, 9); + break; + case 78: + if ((0xfffffffbffffdbffL & l) != 0L) + jjCheckNAddStates(7, 9); + break; + case 80: + if ((0x8400000000L & l) != 0L) + jjCheckNAddStates(7, 9); + break; + case 81: + if (curChar == 34 && kind > 91) + kind = 91; + break; + case 82: + if ((0xff000000000000L & l) != 0L) + jjCheckNAddStates(29, 32); + break; + case 83: + if ((0xff000000000000L & l) != 0L) + jjCheckNAddStates(7, 9); + break; + case 84: + if ((0xf000000000000L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 85; + break; + case 85: + if ((0xff000000000000L & l) != 0L) + jjCheckNAdd(83); + break; + case 87: + if ((0x3ff00000fffc1ffL & l) == 0L) + break; + if (kind > 146) + kind = 146; + jjstateSet[jjnewStateCnt++] = 87; + break; + case 88: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddStates(0, 6); + break; + case 89: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddStates(33, 35); + break; + case 91: + if ((0x280000000000L & l) != 0L) + jjCheckNAdd(92); + break; + case 92: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(92, 67); + break; + case 93: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(93, 94); + break; + case 95: + if ((0x280000000000L & l) != 0L) + jjCheckNAdd(96); + break; + case 96: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 85) + kind = 85; + jjCheckNAddTwoStates(96, 67); + break; + case 97: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(97, 98); + break; + case 98: + if (curChar != 46) + break; + if (kind > 85) + kind = 85; + jjCheckNAddStates(36, 38); + break; + case 99: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 85) + kind = 85; + jjCheckNAddStates(36, 38); + break; + case 101: + if ((0x280000000000L & l) != 0L) + jjCheckNAdd(102); + break; + case 102: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 85) + kind = 85; + jjCheckNAddTwoStates(102, 67); + break; + case 103: + if (curChar != 48) + break; + if (kind > 81) + kind = 81; + jjCheckNAddStates(21, 25); + break; + case 105: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 81) + kind = 81; + jjCheckNAddTwoStates(105, 61); + break; + case 106: + if ((0xff000000000000L & l) == 0L) + break; + if (kind > 81) + kind = 81; + jjCheckNAddTwoStates(106, 61); + break; + case 108: + if ((0x3ff000000000000L & l) != 0L) + jjAddStates(39, 40); + break; + case 109: + if (curChar == 46) + jjCheckNAdd(110); + break; + case 110: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(110, 111); + break; + case 112: + if ((0x280000000000L & l) != 0L) + jjCheckNAdd(113); + break; + case 113: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 85) + kind = 85; + jjCheckNAddTwoStates(113, 67); + break; + case 115: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddStates(41, 43); + break; + case 116: + if (curChar == 46) + jjCheckNAdd(117); + break; + case 118: + if ((0x280000000000L & l) != 0L) + jjCheckNAdd(119); + break; + case 119: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 85) + kind = 85; + jjCheckNAddTwoStates(119, 67); + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + MatchLoop: do + { + switch(jjstateSet[--i]) + { + case 3: + if ((0x7fffffe87ffffffL & l) == 0L) + break; + if (kind > 146) + kind = 146; + jjCheckNAdd(87); + break; + case 120: + if (curChar == 101) + jjAddStates(44, 48); + else if (curChar == 114) + jjstateSet[jjnewStateCnt++] = 38; + else if (curChar == 108) + jjstateSet[jjnewStateCnt++] = 32; + else if (curChar == 119) + jjstateSet[jjnewStateCnt++] = 29; + else if (curChar == 117) + jjstateSet[jjnewStateCnt++] = 22; + else if (curChar == 100) + jjstateSet[jjnewStateCnt++] = 18; + else if (curChar == 105) + jjCheckNAdd(12); + else if (curChar == 112) + jjstateSet[jjnewStateCnt++] = 10; + break; + case 1: + if (kind > 20) + kind = 20; + break; + case 6: + if (curChar == 97 && kind > 22) + kind = 22; + break; + case 7: + if (curChar == 109) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 8: + if (curChar == 103) + jjstateSet[jjnewStateCnt++] = 7; + break; + case 9: + if (curChar == 97) + jjstateSet[jjnewStateCnt++] = 8; + break; + case 10: + if (curChar == 114) + jjstateSet[jjnewStateCnt++] = 9; + break; + case 11: + if (curChar == 112) + jjstateSet[jjnewStateCnt++] = 10; + break; + case 12: + if (curChar == 102 && kind > 22) + kind = 22; + break; + case 13: + case 43: + case 45: + if (curChar == 105) + jjCheckNAdd(12); + break; + case 14: + if (curChar == 101 && kind > 22) + kind = 22; + break; + case 15: + case 31: + if (curChar == 110) + jjCheckNAdd(14); + break; + case 16: + if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 15; + break; + case 17: + if (curChar == 102) + jjstateSet[jjnewStateCnt++] = 16; + break; + case 18: + if (curChar == 101) + jjstateSet[jjnewStateCnt++] = 17; + break; + case 19: + if (curChar == 100) + jjstateSet[jjnewStateCnt++] = 18; + break; + case 20: + if (curChar == 101) + jjCheckNAdd(12); + break; + case 21: + if (curChar == 100) + jjstateSet[jjnewStateCnt++] = 20; + break; + case 22: + if (curChar == 110) + jjstateSet[jjnewStateCnt++] = 21; + break; + case 23: + if (curChar == 117) + jjstateSet[jjnewStateCnt++] = 22; + break; + case 24: + if (curChar == 103 && kind > 22) + kind = 22; + break; + case 25: + if (curChar == 110) + jjstateSet[jjnewStateCnt++] = 24; + break; + case 26: + if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 25; + break; + case 27: + if (curChar == 110) + jjstateSet[jjnewStateCnt++] = 26; + break; + case 28: + if (curChar == 114) + jjstateSet[jjnewStateCnt++] = 27; + break; + case 29: + if (curChar == 97) + jjstateSet[jjnewStateCnt++] = 28; + break; + case 30: + if (curChar == 119) + jjstateSet[jjnewStateCnt++] = 29; + break; + case 32: + if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 31; + break; + case 33: + if (curChar == 108) + jjstateSet[jjnewStateCnt++] = 32; + break; + case 34: + if (curChar == 110 && kind > 22) + kind = 22; + break; + case 35: + case 52: + if (curChar == 111) + jjCheckNAdd(34); + break; + case 36: + if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 35; + break; + case 37: + if (curChar == 103) + jjstateSet[jjnewStateCnt++] = 36; + break; + case 38: + if (curChar == 101) + jjstateSet[jjnewStateCnt++] = 37; + break; + case 39: + if (curChar == 114) + jjstateSet[jjnewStateCnt++] = 38; + break; + case 40: + if (curChar == 101) + jjAddStates(44, 48); + break; + case 41: + if (curChar == 115) + jjCheckNAdd(14); + break; + case 42: + if (curChar == 108) + jjstateSet[jjnewStateCnt++] = 41; + break; + case 44: + if (curChar == 108) + jjstateSet[jjnewStateCnt++] = 43; + break; + case 46: + if (curChar == 100) + jjstateSet[jjnewStateCnt++] = 45; + break; + case 47: + if (curChar == 110) + jjstateSet[jjnewStateCnt++] = 46; + break; + case 48: + if (curChar == 114 && kind > 22) + kind = 22; + break; + case 49: + if (curChar == 111) + jjstateSet[jjnewStateCnt++] = 48; + break; + case 50: + if (curChar == 114) + jjstateSet[jjnewStateCnt++] = 49; + break; + case 51: + if (curChar == 114) + jjstateSet[jjnewStateCnt++] = 50; + break; + case 53: + if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 52; + break; + case 54: + if (curChar == 103) + jjstateSet[jjnewStateCnt++] = 53; + break; + case 55: + if (curChar == 101) + jjstateSet[jjnewStateCnt++] = 54; + break; + case 56: + if (curChar == 114) + jjstateSet[jjnewStateCnt++] = 55; + break; + case 57: + if (curChar == 100) + jjstateSet[jjnewStateCnt++] = 56; + break; + case 58: + if (curChar == 110) + jjstateSet[jjnewStateCnt++] = 57; + break; + case 61: + if ((0x100000001000L & l) != 0L && kind > 81) + kind = 81; + break; + case 64: + if ((0x2000000020L & l) != 0L) + jjAddStates(49, 50); + break; + case 67: + if ((0x5000000050L & l) != 0L && kind > 85) + kind = 85; + break; + case 69: + if ((0xffffffffefffffffL & l) != 0L) + jjCheckNAdd(70); + break; + case 71: + if (curChar == 92) + jjAddStates(51, 53); + break; + case 72: + if ((0x14404410000000L & l) != 0L) + jjCheckNAdd(70); + break; + case 78: + if ((0xffffffffefffffffL & l) != 0L) + jjCheckNAddStates(7, 9); + break; + case 79: + if (curChar == 92) + jjAddStates(54, 56); + break; + case 80: + if ((0x14404410000000L & l) != 0L) + jjCheckNAddStates(7, 9); + break; + case 87: + if ((0x87fffffe87fffffeL & l) == 0L) + break; + if (kind > 146) + kind = 146; + jjCheckNAdd(87); + break; + case 90: + if ((0x2000000020L & l) != 0L) + jjAddStates(57, 58); + break; + case 94: + if ((0x2000000020L & l) != 0L) + jjAddStates(59, 60); + break; + case 100: + if ((0x2000000020L & l) != 0L) + jjAddStates(61, 62); + break; + case 104: + if ((0x100000001000000L & l) != 0L) + jjCheckNAdd(105); + break; + case 105: + if ((0x7e0000007eL & l) == 0L) + break; + if (kind > 81) + kind = 81; + jjCheckNAddTwoStates(105, 61); + break; + case 107: + if ((0x100000001000000L & l) != 0L) + jjCheckNAddTwoStates(108, 109); + break; + case 108: + if ((0x7e0000007eL & l) != 0L) + jjCheckNAddTwoStates(108, 109); + break; + case 110: + if ((0x7e0000007eL & l) != 0L) + jjAddStates(63, 64); + break; + case 111: + if ((0x1000000010000L & l) != 0L) + jjAddStates(65, 66); + break; + case 114: + if ((0x100000001000000L & l) != 0L) + jjCheckNAdd(115); + break; + case 115: + if ((0x7e0000007eL & l) != 0L) + jjCheckNAddStates(41, 43); + break; + case 117: + if ((0x1000000010000L & l) != 0L) + jjAddStates(67, 68); + break; + default : break; + } + } while(i != startsAt); + } + else + { + int hiByte = (int)(curChar >> 8); + int i1 = hiByte >> 6; + long l1 = 1L << (hiByte & 077); + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + MatchLoop: do + { + switch(jjstateSet[--i]) + { + case 3: + if (!jjCanMove_1(hiByte, i1, i2, l1, l2)) + break; + if (kind > 146) + kind = 146; + jjCheckNAdd(87); + break; + case 1: + if (jjCanMove_0(hiByte, i1, i2, l1, l2) && kind > 20) + kind = 20; + break; + case 69: + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) + jjstateSet[jjnewStateCnt++] = 70; + break; + case 78: + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) + jjAddStates(7, 9); + break; + case 87: + if (!jjCanMove_2(hiByte, i1, i2, l1, l2)) + break; + if (kind > 146) + kind = 146; + jjCheckNAdd(87); + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 120 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +private final int jjMoveStringLiteralDfa0_5() +{ + switch(curChar) + { + case 42: + return jjMoveStringLiteralDfa1_5(0x4000000L); + default : + return 1; + } +} +private final int jjMoveStringLiteralDfa1_5(long active0) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + return 1; + } + switch(curChar) + { + case 47: + if ((active0 & 0x4000000L) != 0L) + return jjStopAtPos(1, 26); + break; + default : + return 2; + } + return 2; +} +private final int jjMoveStringLiteralDfa0_3() +{ + return jjMoveNfa_3(0, 0); +} +private final int jjMoveNfa_3(int startState, int curPos) +{ + int[] nextStates; + int startsAt = 0; + jjnewStateCnt = 3; + int i = 1; + jjstateSet[0] = startState; + int j, kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + MatchLoop: do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x2400L & l) != 0L) + { + if (kind > 24) + kind = 24; + } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 1; + break; + case 1: + if (curChar == 10 && kind > 24) + kind = 24; + break; + case 2: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 1; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + MatchLoop: do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + else + { + int hiByte = (int)(curChar >> 8); + int i1 = hiByte >> 6; + long l1 = 1L << (hiByte & 077); + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + MatchLoop: do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +private final int jjMoveStringLiteralDfa0_2() +{ + return jjMoveNfa_2(0, 0); +} +private final int jjMoveNfa_2(int startState, int curPos) +{ + int[] nextStates; + int startsAt = 0; + jjnewStateCnt = 3; + int i = 1; + jjstateSet[0] = startState; + int j, kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + MatchLoop: do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x2400L & l) != 0L) + { + if (kind > 23) + kind = 23; + } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 1; + break; + case 1: + if (curChar == 10 && kind > 23) + kind = 23; + break; + case 2: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 1; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + MatchLoop: do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + else + { + int hiByte = (int)(curChar >> 8); + int i1 = hiByte >> 6; + long l1 = 1L << (hiByte & 077); + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + MatchLoop: do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +private final int jjMoveStringLiteralDfa0_1() +{ + return 1; +} +private final int jjMoveStringLiteralDfa0_4() +{ + switch(curChar) + { + case 42: + return jjMoveStringLiteralDfa1_4(0x2000000L); + default : + return 1; + } +} +private final int jjMoveStringLiteralDfa1_4(long active0) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + return 1; + } + switch(curChar) + { + case 47: + if ((active0 & 0x2000000L) != 0L) + return jjStopAtPos(1, 25); + break; + default : + return 2; + } + return 2; +} +static final int[] jjnextStates = { + 89, 90, 67, 93, 94, 97, 98, 78, 79, 81, 69, 71, 5, 11, 13, 19, + 23, 30, 33, 39, 40, 104, 106, 61, 107, 114, 63, 64, 67, 78, 79, 83, + 81, 89, 90, 67, 99, 100, 67, 108, 109, 115, 116, 117, 42, 44, 47, 51, + 58, 65, 66, 72, 73, 75, 80, 82, 84, 91, 92, 95, 96, 101, 102, 110, + 111, 112, 113, 118, 119, +}; +private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec2[i2] & l2) != 0L); + default : + if ((jjbitVec0[i1] & l1) != 0L) + return true; + return false; + } +} +private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec4[i2] & l2) != 0L); + case 2: + return ((jjbitVec5[i2] & l2) != 0L); + case 3: + return ((jjbitVec6[i2] & l2) != 0L); + case 4: + return ((jjbitVec7[i2] & l2) != 0L); + case 5: + return ((jjbitVec8[i2] & l2) != 0L); + case 6: + return ((jjbitVec9[i2] & l2) != 0L); + case 7: + return ((jjbitVec10[i2] & l2) != 0L); + case 9: + return ((jjbitVec11[i2] & l2) != 0L); + case 10: + return ((jjbitVec12[i2] & l2) != 0L); + case 11: + return ((jjbitVec13[i2] & l2) != 0L); + case 12: + return ((jjbitVec14[i2] & l2) != 0L); + case 13: + return ((jjbitVec15[i2] & l2) != 0L); + case 14: + return ((jjbitVec16[i2] & l2) != 0L); + case 15: + return ((jjbitVec17[i2] & l2) != 0L); + case 16: + return ((jjbitVec18[i2] & l2) != 0L); + case 17: + return ((jjbitVec19[i2] & l2) != 0L); + case 18: + return ((jjbitVec20[i2] & l2) != 0L); + case 19: + return ((jjbitVec21[i2] & l2) != 0L); + case 20: + return ((jjbitVec0[i2] & l2) != 0L); + case 22: + return ((jjbitVec22[i2] & l2) != 0L); + case 23: + return ((jjbitVec23[i2] & l2) != 0L); + case 24: + return ((jjbitVec24[i2] & l2) != 0L); + case 30: + return ((jjbitVec25[i2] & l2) != 0L); + case 31: + return ((jjbitVec26[i2] & l2) != 0L); + case 32: + return ((jjbitVec27[i2] & l2) != 0L); + case 33: + return ((jjbitVec28[i2] & l2) != 0L); + case 48: + return ((jjbitVec29[i2] & l2) != 0L); + case 49: + return ((jjbitVec30[i2] & l2) != 0L); + case 77: + return ((jjbitVec31[i2] & l2) != 0L); + case 159: + return ((jjbitVec32[i2] & l2) != 0L); + case 164: + return ((jjbitVec33[i2] & l2) != 0L); + case 215: + return ((jjbitVec34[i2] & l2) != 0L); + case 250: + return ((jjbitVec35[i2] & l2) != 0L); + case 251: + return ((jjbitVec36[i2] & l2) != 0L); + case 253: + return ((jjbitVec37[i2] & l2) != 0L); + case 254: + return ((jjbitVec38[i2] & l2) != 0L); + case 255: + return ((jjbitVec39[i2] & l2) != 0L); + default : + if ((jjbitVec3[i1] & l1) != 0L) + return true; + return false; + } +} +private static final boolean jjCanMove_2(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec40[i2] & l2) != 0L); + case 2: + return ((jjbitVec5[i2] & l2) != 0L); + case 3: + return ((jjbitVec41[i2] & l2) != 0L); + case 4: + return ((jjbitVec42[i2] & l2) != 0L); + case 5: + return ((jjbitVec43[i2] & l2) != 0L); + case 6: + return ((jjbitVec44[i2] & l2) != 0L); + case 7: + return ((jjbitVec45[i2] & l2) != 0L); + case 9: + return ((jjbitVec46[i2] & l2) != 0L); + case 10: + return ((jjbitVec47[i2] & l2) != 0L); + case 11: + return ((jjbitVec48[i2] & l2) != 0L); + case 12: + return ((jjbitVec49[i2] & l2) != 0L); + case 13: + return ((jjbitVec50[i2] & l2) != 0L); + case 14: + return ((jjbitVec51[i2] & l2) != 0L); + case 15: + return ((jjbitVec52[i2] & l2) != 0L); + case 16: + return ((jjbitVec53[i2] & l2) != 0L); + case 17: + return ((jjbitVec19[i2] & l2) != 0L); + case 18: + return ((jjbitVec20[i2] & l2) != 0L); + case 19: + return ((jjbitVec54[i2] & l2) != 0L); + case 20: + return ((jjbitVec0[i2] & l2) != 0L); + case 22: + return ((jjbitVec22[i2] & l2) != 0L); + case 23: + return ((jjbitVec55[i2] & l2) != 0L); + case 24: + return ((jjbitVec56[i2] & l2) != 0L); + case 30: + return ((jjbitVec25[i2] & l2) != 0L); + case 31: + return ((jjbitVec26[i2] & l2) != 0L); + case 32: + return ((jjbitVec57[i2] & l2) != 0L); + case 33: + return ((jjbitVec28[i2] & l2) != 0L); + case 48: + return ((jjbitVec58[i2] & l2) != 0L); + case 49: + return ((jjbitVec30[i2] & l2) != 0L); + case 77: + return ((jjbitVec31[i2] & l2) != 0L); + case 159: + return ((jjbitVec32[i2] & l2) != 0L); + case 164: + return ((jjbitVec33[i2] & l2) != 0L); + case 215: + return ((jjbitVec34[i2] & l2) != 0L); + case 250: + return ((jjbitVec35[i2] & l2) != 0L); + case 251: + return ((jjbitVec59[i2] & l2) != 0L); + case 253: + return ((jjbitVec37[i2] & l2) != 0L); + case 254: + return ((jjbitVec60[i2] & l2) != 0L); + case 255: + return ((jjbitVec61[i2] & l2) != 0L); + default : + if ((jjbitVec3[i1] & l1) != 0L) + return true; + return false; + } +} +public static final String[] jjstrLiteralImages = { +"", "\157\160\164\151\157\156\163", "\114\117\117\113\101\110\105\101\104", +"\111\107\116\117\122\105\137\103\101\123\105", "\120\101\122\123\105\122\137\102\105\107\111\116", +"\120\101\122\123\105\122\137\105\116\104", "\103\123\103\117\104\105", "\124\117\113\105\116", +"\123\120\105\103\111\101\114\137\124\117\113\105\116", "\115\117\122\105", "\123\113\111\120", +"\124\117\113\105\116\137\115\107\122\137\104\105\103\114\123", "\105\117\106", null, null, null, null, null, null, null, null, null, null, +null, null, null, null, null, "\141\142\163\164\162\141\143\164", +"\142\157\157\154", "\142\162\145\141\153", "\142\171\164\145", "\143\141\163\145", +"\143\141\164\143\150", "\143\150\141\162", "\143\154\141\163\163", "\143\157\156\163\164", +"\143\157\156\164\151\156\165\145", "\144\145\146\141\165\154\164", "\144\157", "\144\157\165\142\154\145", +"\145\154\163\145", "\145\156\165\155", "\146\141\154\163\145", +"\157\166\145\162\162\151\144\145", "\163\151\156\147\154\145", "\146\157\162", "\147\157\164\157", "\151\146", +"\165\163\151\156\147", "\151\156\164", "\151\156\164\145\162\146\141\143\145", "\154\157\156\147", +"\156\145\167", "\156\165\154\154", "\156\141\155\145\163\160\141\143\145", "\157\165\164", +"\160\162\151\166\141\164\145", "\160\162\157\164\145\143\164\145\144", "\160\165\142\154\151\143", +"\162\145\146", "\162\145\164\165\162\156", "\163\150\157\162\164", +"\163\164\141\164\151\143", "\142\141\163\145", "\163\167\151\164\143\150", "\164\150\151\163", +"\164\150\162\157\167", "\164\162\165\145", "\164\162\171", "\166\157\151\144", +"\167\150\151\154\145", "\146\157\162\145\141\143\150", "\160\141\162\164\151\141\154", +"\171\151\145\154\144", "\151\156\164\145\162\156\141\154", "\144\145\154\145\147\141\164\145", +"\162\145\141\144\157\156\154\171", "\146\151\170\145\144", "\165\156\163\141\146\145", "\166\141\162", null, null, +null, null, null, null, null, null, null, null, null, "\50", "\51", "\173", "\175", +"\133", "\135", "\73", "\54", "\56", "\75", "\74", "\41", "\176", "\77", "\72", +"\75\75", "\74\75", "\76\75", "\41\75", "\174\174", "\46\46", "\53\53", "\55\55", "\53", +"\55", "\52", "\57", "\46", "\174", "\136", "\45", "\53\75", "\55\75", "\52\75", +"\57\75", "\46\75", "\174\75", "\136\75", "\45\75", "\76\76\76", "\76\76", "\76", "\43", +"\147\145\164", "\163\145\164", "\56\56\56", "\74\74\75", "\76\76\75", "\76\76\76\75", +"\151\163", "\74\74", "\154\157\143\153", "\151\156", "\146\151\156\141\154\154\171", null, +null, null, }; +public static final String[] lexStateNames = { + "DEFAULT", + "AFTER_EGEN", + "IN_SINGLE_LINE_COMMENT", + "IN_PRAGMA", + "IN_FORMAL_COMMENT", + "IN_MULTI_LINE_COMMENT", +}; +public static final int[] jjnewLexState = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 0, 2, 4, 5, 3, 0, 0, + 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +}; +static final long[] jjtoToken = { + 0xfffffffff0001fffL, 0xfffffffffc23ffffL, 0x7ffffL, +}; +static final long[] jjtoSkip = { + 0x787e000L, 0x0L, 0x0L, +}; +static final long[] jjtoSpecial = { + 0x7800000L, 0x0L, 0x0L, +}; +static final long[] jjtoMore = { + 0x8780000L, 0x0L, 0x0L, +}; +protected JavaCharStream input_stream; +private final int[] jjrounds = new int[120]; +private final int[] jjstateSet = new int[240]; +StringBuffer image; +int jjimageLen; +int lengthOfMatch; +protected char curChar; +public CSJavaCCParserTokenManager(JavaCharStream stream){ + if (JavaCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + input_stream = stream; +} +public CSJavaCCParserTokenManager(JavaCharStream stream, int lexState){ + this(stream); + SwitchTo(lexState); +} +public void ReInit(JavaCharStream stream) +{ + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); +} +private final void ReInitRounds() +{ + int i; + jjround = 0x80000001; + for (i = 120; i-- > 0;) + jjrounds[i] = 0x80000000; +} +public void ReInit(JavaCharStream stream, int lexState) +{ + ReInit(stream); + SwitchTo(lexState); +} +public void SwitchTo(int lexState) +{ + if (lexState >= 6 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; +} + +protected Token jjFillToken() +{ + Token t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + String im = jjstrLiteralImages[jjmatchedKind]; + t.image = (im == null) ? input_stream.GetImage() : im; + t.beginLine = input_stream.getBeginLine(); + t.beginColumn = input_stream.getBeginColumn(); + t.endLine = input_stream.getEndLine(); + t.endColumn = input_stream.getEndColumn(); + return t; +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +public Token getNextToken() +{ + int kind; + Token specialToken = null; + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + matchedToken = jjFillToken(); + matchedToken.specialToken = specialToken; + return matchedToken; + } + image = null; + jjimageLen = 0; + + for (;;) + { + switch(curLexState) + { + case 0: + try { input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) + curChar = input_stream.BeginToken(); + } + catch (java.io.IOException e1) { continue EOFLoop; } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + break; + case 1: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_1(); + if (jjmatchedPos == 0 && jjmatchedKind > 18) + { + jjmatchedKind = 18; + } + break; + case 2: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_2(); + if (jjmatchedPos == 0 && jjmatchedKind > 27) + { + jjmatchedKind = 27; + } + break; + case 3: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_3(); + if (jjmatchedPos == 0 && jjmatchedKind > 27) + { + jjmatchedKind = 27; + } + break; + case 4: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_4(); + if (jjmatchedPos == 0 && jjmatchedKind > 27) + { + jjmatchedKind = 27; + } + break; + case 5: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_5(); + if (jjmatchedPos == 0 && jjmatchedKind > 27) + { + jjmatchedKind = 27; + } + break; + } + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + matchedToken.specialToken = specialToken; + TokenLexicalActions(matchedToken); + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + return matchedToken; + } + else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + if ((jjtoSpecial[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + if (specialToken == null) + specialToken = matchedToken; + else + { + matchedToken.specialToken = specialToken; + specialToken = (specialToken.next = matchedToken); + } + SkipLexicalActions(matchedToken); + } + else + SkipLexicalActions(null); + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + continue EOFLoop; + } + MoreLexicalActions(); + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + curPos = 0; + jjmatchedKind = 0x7fffffff; + try { + curChar = input_stream.readChar(); + continue; + } + catch (java.io.IOException e1) { } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + } + throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); + } + } +} + +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + case 18 : + if (image == null) + image = new StringBuffer(); + image.append(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1))); + restoreBeginLineCol(); input_stream.backup(1); + break; + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + case 20 : + if (image == null) + image = new StringBuffer(); + image.append(input_stream.GetSuffix(jjimageLen)); + jjimageLen = 0; + input_stream.backup(1); + break; + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + case 131 : + if (image == null) + image = new StringBuffer(); + image.append(jjstrLiteralImages[131]); + matchedToken.kind = GT; + ((Token.GTToken)matchedToken).realKind = RUNSIGNEDSHIFT; + input_stream.backup(2); + matchedToken.image = ">"; + break; + case 132 : + if (image == null) + image = new StringBuffer(); + image.append(jjstrLiteralImages[132]); + matchedToken.kind = GT; + ((Token.GTToken)matchedToken).realKind = RSIGNEDSHIFT; + input_stream.backup(1); + matchedToken.image = ">"; + break; + default : + break; + } +} +} diff --git a/csjavacc/parser/CSJavaCharStream.java b/csjavacc/parser/CSJavaCharStream.java new file mode 100644 index 0000000..e68034d --- /dev/null +++ b/csjavacc/parser/CSJavaCharStream.java @@ -0,0 +1,567 @@ +/* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 4.0 */ +/** + * This file contains the code for JavaCCParser generated + * by JavaCCParser itself. + */ + +package csjavacc.parser; + +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (with java-like unicode escape processing). + */ + +public class CSJavaCharStream +{ + public static final boolean staticFlag = false; + static final int hexval(char c) throws java.io.IOException { + switch(c) + { + case '0' : return 0; + case '1' : return 1; + case '2' : return 2; + case '3' : return 3; + case '4' : return 4; + case '5' : return 5; + case '6' : return 6; + case '7' : return 7; + case '8' : return 8; + case '9' : return 9; + + case 'a' : case 'A' : return 10; + case 'b' : case 'B' : return 11; + case 'c' : case 'C' : return 12; + case 'd' : case 'D' : return 13; + case 'e' : case 'E' : return 14; + case 'f' : case 'F' : return 15; + } + + throw new java.io.IOException(); // Should never come here + } + + public int bufpos = -1; + int bufsize; + int available; + int tokenBegin; + protected int bufline[]; + protected int bufcolumn[]; + + protected int column = 0; + protected int line = 1; + + protected boolean prevCharIsCR = false; + protected boolean prevCharIsLF = false; + + protected java.io.Reader inputStream; + + protected char[] nextCharBuf; + protected char[] buffer; + protected int maxNextCharInd = 0; + protected int nextCharInd = -1; + protected int inBuf = 0; + protected int tabSize = 8; + + protected void setTabSize(int i) { tabSize = i; } + protected int getTabSize(int i) { return tabSize; } + + protected void ExpandBuff(boolean wrapAround) + { + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; + + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, + bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + bufpos += (bufsize - tokenBegin); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + bufpos -= tokenBegin; + } + } + catch (Throwable t) + { + throw new Error(t.getMessage()); + } + + available = (bufsize += 2048); + tokenBegin = 0; + } + + protected void FillBuff() throws java.io.IOException + { + int i; + if (maxNextCharInd == 4096) + maxNextCharInd = nextCharInd = 0; + + try { + if ((i = inputStream.read(nextCharBuf, maxNextCharInd, + 4096 - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + if (bufpos != 0) + { + --bufpos; + backup(0); + } + else + { + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + throw e; + } + } + + protected char ReadByte() throws java.io.IOException + { + if (++nextCharInd >= maxNextCharInd) + FillBuff(); + + return nextCharBuf[nextCharInd]; + } + + public char BeginToken() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + tokenBegin = bufpos; + return buffer[bufpos]; + } + + tokenBegin = 0; + bufpos = -1; + + return readChar(); + } + + protected void AdjustBuffSize() + { + if (available == bufsize) + { + if (tokenBegin > 2048) + { + bufpos = 0; + available = tokenBegin; + } + else + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } + + protected void UpdateLineColumn(char c) + { + column++; + + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else + line += (column = 1); + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + return buffer[bufpos]; + } + + char c; + + if (++bufpos == available) + AdjustBuffSize(); + + if ((buffer[bufpos] = c = ReadByte()) == '\\') + { + UpdateLineColumn(c); + + int backSlashCnt = 1; + + for (;;) // Read all the backslashes + { + if (++bufpos == available) + AdjustBuffSize(); + + try + { + if ((buffer[bufpos] = c = ReadByte()) != '\\') + { + UpdateLineColumn(c); + // found a non-backslash char. + if ((c == 'u') && ((backSlashCnt & 1) == 1)) + { + if (--bufpos < 0) + bufpos = bufsize - 1; + + break; + } + + backup(backSlashCnt); + return '\\'; + } + } + catch(java.io.IOException e) + { + if (backSlashCnt > 1) + backup(backSlashCnt); + + return '\\'; + } + + UpdateLineColumn(c); + backSlashCnt++; + } + + // Here, we have seen an odd number of backslash's followed by a 'u' + try + { + while ((c = ReadByte()) == 'u') + ++column; + + buffer[bufpos] = c = (char)(hexval(c) << 12 | + hexval(ReadByte()) << 8 | + hexval(ReadByte()) << 4 | + hexval(ReadByte())); + + column += 4; + } + catch(java.io.IOException e) + { + throw new Error("Invalid escape character at line " + line + + " column " + column + "."); + } + + if (backSlashCnt == 1) + return c; + else + { + backup(backSlashCnt - 1); + return '\\'; + } + } + else + { + UpdateLineColumn(c); + return c; + } + } + + /** + * @deprecated + * @see #getEndColumn + */ + + public int getColumn() { + return bufcolumn[bufpos]; + } + + /** + * @deprecated + * @see #getEndLine + */ + + public int getLine() { + return bufline[bufpos]; + } + + public int getEndColumn() { + return bufcolumn[bufpos]; + } + + public int getEndLine() { + return bufline[bufpos]; + } + + public int getBeginColumn() { + return bufcolumn[tokenBegin]; + } + + public int getBeginLine() { + return bufline[tokenBegin]; + } + + public void backup(int amount) { + + inBuf += amount; + if ((bufpos -= amount) < 0) + bufpos += bufsize; + } + + public CSJavaCharStream(java.io.Reader dstream, + int startline, int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + nextCharBuf = new char[4096]; + } + + public CSJavaCharStream(java.io.Reader dstream, + int startline, int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + public CSJavaCharStream(java.io.Reader dstream) + { + this(dstream, 1, 1, 4096); + } + public void ReInit(java.io.Reader dstream, + int startline, int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + if (buffer == null || buffersize != buffer.length) + { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + nextCharBuf = new char[4096]; + } + prevCharIsLF = prevCharIsCR = false; + tokenBegin = inBuf = maxNextCharInd = 0; + nextCharInd = bufpos = -1; + } + + public void ReInit(java.io.Reader dstream, + int startline, int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + + public void ReInit(java.io.Reader dstream) + { + ReInit(dstream, 1, 1, 4096); + } + public CSJavaCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + public CSJavaCharStream(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); + } + + public CSJavaCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, 4096); + } + + public CSJavaCharStream(java.io.InputStream dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + public CSJavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, 4096); + } + + public CSJavaCharStream(java.io.InputStream dstream) + { + this(dstream, 1, 1, 4096); + } + + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, startline, startcolumn, 4096); + } + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, 1, 1, 4096); + } + + public void ReInit(java.io.InputStream dstream) + { + ReInit(dstream, 1, 1, 4096); + } + + public String GetImage() + { + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); + } + + public char[] GetSuffix(int len) + { + char[] ret = new char[len]; + + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } + + return ret; + } + + public void Done() + { + nextCharBuf = null; + buffer = null; + bufline = null; + bufcolumn = null; + } + + /** + * Method to adjust line and column numbers for the start of a token. + */ + public void adjustBeginLineColumn(int newLine, int newCol) + { + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && + bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } + + line = bufline[j]; + column = bufcolumn[j]; + } + +} diff --git a/csjavacc/parser/CSJavaFiles.java b/csjavacc/parser/CSJavaFiles.java new file mode 100644 index 0000000..867c7e6 --- /dev/null +++ b/csjavacc/parser/CSJavaFiles.java @@ -0,0 +1,2048 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.io.*; + +public class CSJavaFiles + extends CSJavaCCGlobals + implements CSJavaCCParserConstants +{ + + static PrintWriter ostr; + + /** + * ID of the latest version (of JavaCC) in which one of the CharStream classes + * or the CharStream interface is modified. + */ + static final String charStreamVersion = "4.0"; + + /** + * ID of the latest version (of JavaCC) in which the TokenManager interface is modified. + */ + static final String tokenManagerVersion = "3.0"; + + /** + * ID of the latest version (of JavaCC) in which the Token class is modified. + */ + static final String tokenVersion = "3.0"; + + /** + * ID of the latest version (of JavaCC) in which the ParseException class is + * modified. + */ + static final String parseExceptionVersion = "3.0"; + + /** + * ID of the latest version (of JavaCC) in which the TokenMgrError class is + * modified. + */ + static final String tokenMgrErrorVersion = "3.0"; + + /** + * Replaces all backslahes with double backslashes. + */ + static String replaceBackslash(String str) + { + StringBuffer b; + int i = 0, len = str.length(); + + while (i < len && str.charAt(i++) != '\\') ; + + if (i == len) // No backslash found. + return str; + + char c; + b = new StringBuffer(); + for (i = 0; i < len; i++) + if ((c = str.charAt(i)) == '\\') + b.append("\\\\"); + else + b.append(c); + + return b.toString(); + } + + static void CheckVersion(String fileName, String versionId) + { + fileName = replaceBackslash(fileName); + String firstLine = "/* " + getIdString(toolName, fileName) + + " Version " + versionId + " */"; + char[] buf = new char[firstLine.length()]; + + try { + File fp = new File(Options.getOutputDirectory(), fileName); + Reader stream = new FileReader(fp); + int read, total = 0; + + for (;;) + if ((read = stream.read(buf, 0, buf.length)) > 0){ + if ((total += read) == buf.length) + if (new String(buf).equals(firstLine)) + return; + else + break; + } + else + break; + } catch(FileNotFoundException e1) { + // This should never happen + CSJavaCCErrors.semantic_error("Could not open file " + fileName + " for writing."); + throw new Error(); + } catch(IOException e2) { + } + + CSJavaCCErrors.warning(fileName + ": File is obsolete. Please rename or delete this file so" + + " that a new one can be generated for you."); + } + + public static void gen_CSCharStream() { + File tmp; + boolean namespace = false; + if ((tmp = new File(Options.getOutputDirectory(), language+"CharStream"+extension)).exists()) { + CheckVersion(language+"CharStream"+extension, charStreamVersion); + return; + } + System.err.println("File \""+language+"CharStream"+extension+"\" does not exist. Will create one."); + try { + ostr = new PrintWriter( + new BufferedWriter( + new FileWriter(tmp), + 8192 + ) + ); + } catch (IOException e) { + CSJavaCCErrors.semantic_error("Could not open file "+language+"CharStream"+extension+" for writing."); + throw new Error(); + } + + ostr.println("/* " + getIdString(toolName, language+"CharStream"+extension) + " Version " + charStreamVersion + " */"); + + ostr.println("using System;"); + + if (cu_to_insertion_point_1.size() != 0 && ((Token)cu_to_insertion_point_1.elementAt(0)).kind == NAMESPACE) { + for (int i = 1; i < cu_to_insertion_point_1.size(); i++) { + if (((Token)cu_to_insertion_point_1.elementAt(i)).kind == SEMICOLON) { + cline = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginLine; + ccol = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginColumn; + for (int j = 0; j < i; j++) { + printToken((Token)(cu_to_insertion_point_1.elementAt(j)), ostr); + } + namespace = true; + ostr.println("{"); + ostr.println(""); + break; + } + } + } + String prefix = (Options.getStatic() ? " static " : " "); + ostr.println("/**"); + ostr.println(" * An implementation of interface CharStream, where the stream is assumed to"); + ostr.println(" * contain only ASCII characters (with java-like unicode escape processing)."); + ostr.println(" */"); + ostr.println(""); + ostr.println("public class "+language+"CharStream"); + ostr.println("{"); + ostr.println(" public static bool staticFlag = " + + Options.getStatic() + ";"); + ostr.println(" static int hexval(char c){"); + ostr.println(" switch(c){"); + ostr.println(" case '0' : return 0;"); + ostr.println(" case '1' : return 1;"); + ostr.println(" case '2' : return 2;"); + ostr.println(" case '3' : return 3;"); + ostr.println(" case '4' : return 4;"); + ostr.println(" case '5' : return 5;"); + ostr.println(" case '6' : return 6;"); + ostr.println(" case '7' : return 7;"); + ostr.println(" case '8' : return 8;"); + ostr.println(" case '9' : return 9;\n"); + ostr.println(" case 'a' : case 'A' : return 10;"); + ostr.println(" case 'b' : case 'B' : return 11;"); + ostr.println(" case 'c' : case 'C' : return 12;"); + ostr.println(" case 'd' : case 'D' : return 13;"); + ostr.println(" case 'e' : case 'E' : return 14;"); + ostr.println(" case 'f' : case 'F' : return 15;"); + ostr.println(" }\n"); + ostr.println(" throw Exception(); // Should never come here"); + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public int bufpos = -1;"); + ostr.println(prefix + "int bufsize;"); + ostr.println(prefix + "int available;"); + ostr.println(prefix + "int tokenBegin;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(prefix + "protected int bufline[];"); + ostr.println(prefix + "protected int bufcolumn[];"); + ostr.println(""); + ostr.println(prefix + "protected int column = 0;"); + ostr.println(prefix + "protected int line = 1;"); + ostr.println(""); + ostr.println(prefix + "protected bool prevCharIsCR = false;"); + ostr.println(prefix + "protected bool prevCharIsLF = false;"); + } + + ostr.println(""); + ostr.println(prefix + "protected System.IO.TextReader inputStream;"); + ostr.println(""); + ostr.println(prefix + "protected char[] nextCharBuf;"); + ostr.println(prefix + "protected char[] buffer;"); + ostr.println(prefix + "protected int maxNextCharInd = 0;"); + ostr.println(prefix + "protected int nextCharInd = -1;"); + ostr.println(prefix + "protected int inBuf = 0;"); + ostr.println(prefix + "protected int tabSize = 8;"); + ostr.println(""); + ostr.println(prefix + "protected void setTabSize(int i) { tabSize = i; }"); + ostr.println(prefix + "protected int getTabSize(int i) { return tabSize; }"); + ostr.println(""); + ostr.println(prefix + "protected void ExpandBuff(bool wrapAround)"); + ostr.println(" {"); + ostr.println(" char[] newbuffer = new char[bufsize + 2048];"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" int newbufline[] = new int[bufsize + 2048];"); + ostr.println(" int newbufcolumn[] = new int[bufsize + 2048];"); + } + + ostr.println(""); + ostr.println(" try{"); + ostr.println(" if (wrapAround){"); + ostr.println(" System.Array.Copy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);"); + ostr.println(" System.Array.Copy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);"); + ostr.println(" buffer = newbuffer;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(""); + ostr.println(" System.Array.Copy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);"); + ostr.println(" System.Array.Copy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);"); + ostr.println(" bufline = newbufline;"); + ostr.println(""); + ostr.println(" System.Array.Copy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);"); + ostr.println(" System.Array.Copy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);"); + ostr.println(" bufcolumn = newbufcolumn;"); + } + + ostr.println("\n bufpos += (bufsize - tokenBegin);"); + ostr.println(" }"); + ostr.println(" else{"); + ostr.println(" System.Array.Copy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);"); + ostr.println(" buffer = newbuffer;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(""); + ostr.println(" System.Array.Copy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);"); + ostr.println(" bufline = newbufline;"); + ostr.println(""); + ostr.println(" System.Array.Copy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);"); + ostr.println(" bufcolumn = newbufcolumn;"); + } + + ostr.println(""); + ostr.println(" bufpos -= tokenBegin;"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(" catch (System.Exception t){"); + ostr.println(" throw e;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" available = (bufsize += 2048);"); + ostr.println(" tokenBegin = 0;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "protected bool streamClosed = false;"); + ostr.println(prefix + "protected void FillBuff(){"); + ostr.println(" if(streamClosed)throw new TokenMgrError.EOFException();"); + ostr.println(" int i;"); + ostr.println(" if (maxNextCharInd == 4096)"); + ostr.println(" maxNextCharInd = nextCharInd = 0;"); + ostr.println(""); + ostr.println(" try {"); + ostr.println(" if ((i = inputStream.Read(nextCharBuf, maxNextCharInd, 4096 - maxNextCharInd)) <= 0){"); + ostr.println(" inputStream.Close();"); + ostr.println(" streamClosed = true;"); + ostr.println(" throw new TokenMgrError.EOFException();"); + ostr.println(" }else"); + ostr.println(" maxNextCharInd += i;"); + ostr.println(" return;"); + ostr.println(" }"); + ostr.println(" catch(System.IO.IOException e) {"); + ostr.println(" if (bufpos != 0){"); + ostr.println(" --bufpos;"); + ostr.println(" backup(0);"); + ostr.println(" }"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" else{"); + ostr.println(" bufline[bufpos] = line;"); + ostr.println(" bufcolumn[bufpos] = column;"); + ostr.println(" }"); + } + + ostr.println(" throw e;"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "protected char ReadByte(){"); + ostr.println(" if (++nextCharInd >= maxNextCharInd)"); + ostr.println(" FillBuff();"); + ostr.println(""); + ostr.println(" return nextCharBuf[nextCharInd];"); + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public char BeginToken(){"); + ostr.println(" if (inBuf > 0){"); + ostr.println(" --inBuf;"); + ostr.println(""); + ostr.println(" if (++bufpos == bufsize)"); + ostr.println(" bufpos = 0;"); + ostr.println(""); + ostr.println(" tokenBegin = bufpos;"); + ostr.println(" return buffer[bufpos];"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" tokenBegin = 0;"); + ostr.println(" bufpos = -1;"); + ostr.println(""); + ostr.println(" return readChar();"); + ostr.println(" } "); + ostr.println(""); + ostr.println(prefix + "protected void AdjustBuffSize(){"); + ostr.println(" if (available == bufsize){"); + ostr.println(" if (tokenBegin > 2048){"); + ostr.println(" bufpos = 0;"); + ostr.println(" available = tokenBegin;"); + ostr.println(" }else"); + ostr.println(" ExpandBuff(false);"); + ostr.println(" }"); + ostr.println(" else if (available > tokenBegin)"); + ostr.println(" available = bufsize;"); + ostr.println(" else if ((tokenBegin - available) < 2048)"); + ostr.println(" ExpandBuff(true);"); + ostr.println(" else"); + ostr.println(" available = tokenBegin;"); + ostr.println(" }"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(""); + ostr.println(prefix + "protected void UpdateLineColumn(char c){"); + ostr.println(" column++;"); + ostr.println(""); + ostr.println(" if (prevCharIsLF){"); + ostr.println(" prevCharIsLF = false;"); + ostr.println(" line += (column = 1);"); + ostr.println(" }else if (prevCharIsCR){"); + ostr.println(" prevCharIsCR = false;"); + ostr.println(" if (c == '\\n'){"); + ostr.println(" prevCharIsLF = true;"); + ostr.println(" }else"); + ostr.println(" line += (column = 1);"); + ostr.println(" }\n"); + ostr.println(" switch (c){"); + ostr.println(" case '\\r' :"); + ostr.println(" prevCharIsCR = true;"); + ostr.println(" break;"); + ostr.println(" case '\\n' :"); + ostr.println(" prevCharIsLF = true;"); + ostr.println(" break;"); + ostr.println(" case '\\t' :"); + ostr.println(" column--;"); + ostr.println(" column += (tabSize - (column % tabSize));"); + ostr.println(" break;"); + ostr.println(" default :"); + ostr.println(" break;"); + ostr.println(" }\n"); + ostr.println(" bufline[bufpos] = line;"); + ostr.println(" bufcolumn[bufpos] = column;"); + ostr.println(" }"); + } + + ostr.println(""); + ostr.println(prefix + "public char readChar(){"); + ostr.println(" if (inBuf > 0){"); + ostr.println(" --inBuf;\n"); + ostr.println(" if (++bufpos == bufsize)"); + ostr.println(" bufpos = 0;\n"); + ostr.println(" return buffer[bufpos];"); + ostr.println(" }\n"); + ostr.println(" char c;"); + ostr.println(" if (++bufpos == available)"); + ostr.println(" AdjustBuffSize();"); + ostr.println(""); + ostr.println(" if ((buffer[bufpos] = c = ReadByte()) == '\\\\'){"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" UpdateLineColumn(c);"); + } + + ostr.println(""); + ostr.println(" int backSlashCnt = 1;"); + ostr.println(""); + ostr.println(" for (;;) // Read all the backslashes"); + ostr.println(" {"); + ostr.println(" if (++bufpos == available)"); + ostr.println(" AdjustBuffSize();"); + ostr.println(""); + ostr.println(" try{"); + ostr.println(" if ((buffer[bufpos] = c = ReadByte()) != '\\\\'){"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" UpdateLineColumn(c);"); + } + + ostr.println(" // found a non-backslash char."); + ostr.println(" if ((c == 'u') && ((backSlashCnt & 1) == 1)){"); + ostr.println(" if (--bufpos < 0)"); + ostr.println(" bufpos = bufsize - 1;"); + ostr.println(" break;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" backup(backSlashCnt);"); + ostr.println(" return '\\\\';"); + ostr.println(" }"); + ostr.println(" }catch(System.IO.IOException e){"); + ostr.println(" if (backSlashCnt > 1)"); + ostr.println(" backup(backSlashCnt);"); + ostr.println(" return '\\\\';"); + ostr.println(" }"); + ostr.println(""); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" UpdateLineColumn(c);"); + } + + ostr.println(" backSlashCnt++;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" // Here, we have seen an odd number of backslash's followed by a 'u'"); + ostr.println(" try{"); + ostr.println(" while ((c = ReadByte()) == 'u')"); + + if (OtherFilesGen.keepLineCol) { + ostr.println(" ++column;"); + }else{ + ostr.println(" ;"); + } + + ostr.println(""); + ostr.println(" buffer[bufpos] = c = (char)(hexval(c) << 12 |"); + ostr.println(" hexval(ReadByte()) << 8 |"); + ostr.println(" hexval(ReadByte()) << 4 |"); + ostr.println(" hexval(ReadByte()));"); + ostr.println(""); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" column += 4;"); + } + + ostr.println(" }catch(System.IO.IOException e){"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" throw new Exception(\"Invalid escape character at line \" + line +"); + ostr.println(" \" column \" + column + \".\");"); + }else{ + ostr.println(" throw new Exception(\"Invalid escape character in input\");"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(" if (backSlashCnt == 1)"); + ostr.println(" return c;"); + ostr.println(" else{"); + ostr.println(" backup(backSlashCnt - 1);"); + ostr.println(" return '\\\\';"); + ostr.println(" }"); + ostr.println(" }else{"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" UpdateLineColumn(c);"); + } + + ostr.println(" return (c);"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * @deprecated "); + ostr.println(" * @see #getEndColumn"); + ostr.println(" */"); + ostr.println(""); + ostr.println(prefix + "public int getColumn() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufcolumn[bufpos];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * @deprecated "); + ostr.println(" * @see #getEndLine"); + ostr.println(" */"); + ostr.println(""); + ostr.println(prefix + "public int getLine() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufline[bufpos];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public int getEndColumn() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufcolumn[bufpos];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public int getEndLine() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufline[bufpos];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public int getBeginColumn() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufcolumn[tokenBegin];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public int getBeginLine() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufline[tokenBegin];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public void backup(int amount) {"); + ostr.println(" inBuf += amount;"); + ostr.println(" if ((bufpos -= amount) < 0)"); + ostr.println(" bufpos += bufsize;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" public "+language+"CharStream(System.IO.TextReader dstream, int startline, int startcolumn, int buffersize){"); + + if (Options.getStatic()){ + ostr.println(" if (inputStream != null)"); + ostr.println(" throw new System.Exception\"\\n ERROR: Second call to the constructor of a static JavaCharStream. You must\\n\" +"); + ostr.println(" \" either use ReInit() or set the JavaCC option STATIC to false\\n\" +"); + ostr.println(" \" during the generation of this class.\");"); + } + + ostr.println(" inputStream = dstream;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" line = startline;"); + ostr.println(" column = startcolumn - 1;"); + } + + ostr.println(""); + ostr.println(" available = bufsize = buffersize;"); + ostr.println(" buffer = new char[buffersize];"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" bufline = new int[buffersize];"); + ostr.println(" bufcolumn = new int[buffersize];"); + } + + ostr.println(" nextCharBuf = new char[4096];"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" public JavaCharStream(System.IO.TextReader dstream, int startline, int startcolumn)"); + ostr.println(" : this(dstream, startline, startcolumn, 4096){}"); + ostr.println(""); + ostr.println(" public JavaCharStream(System.IO.TextReader dstream)"); + ostr.println(" : this(dstream, 1, 1, 4096){}"); + ostr.println(""); + ostr.println(" public void ReInit(System.IO.TextReader dstream, int startline, int startcolumn, int buffersize){"); + ostr.println(" inputStream = dstream;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" line = startline;"); + ostr.println(" column = startcolumn - 1;"); + } + + ostr.println(""); + ostr.println(" if (buffer == null || buffersize != buffer.Length){"); + ostr.println(" available = bufsize = buffersize;"); + ostr.println(" buffer = new char[buffersize];"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" bufline = new int[buffersize];"); + ostr.println(" bufcolumn = new int[buffersize];"); + } + + ostr.println(" nextCharBuf = new char[4096];"); + ostr.println(" }"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" prevCharIsLF = prevCharIsCR = false;"); + } + + ostr.println(" tokenBegin = inBuf = maxNextCharInd = 0;"); + ostr.println(" nextCharInd = bufpos = -1;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" public void ReInit(System.IO.TextReader dstream, int startline, int startcolumn){"); + ostr.println(" ReInit(dstream, startline, startcolumn, 4096);"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" public void ReInit(System.IO.TextReader dstream){"); + ostr.println(" ReInit(dstream, 1, 1, 4096);"); + ostr.println(" }"); + //ostr.println(" public JavaCharStream(System.IO.Stream dstream, String encoding, int startline, int startcolumn, int buffersize)"); + //ostr.println(" : this(encoding == null ? new System.IO.StreamReader(dstream) : "); + //ostr.println(" new System.IO.StreamReader(dstream, encoding), startline, startcolumn, buffersize){}"); + //ostr.println(""); + ostr.println(" public JavaCharStream(System.IO.Stream dstream, int startline, int startcolumn, int buffersize)"); + ostr.println(" : this(new System.IO.StreamReader(dstream), startline, startcolumn, 4096){}"); + ostr.println(""); + //ostr.println(" public JavaCharStream(System.IO.Stream dstream, String encoding, int startline, int startcolumn)"); + //ostr.println(" : this(dstream, encoding, startline, startcolumn, 4096){}"); + //ostr.println(""); + ostr.println(" public JavaCharStream(System.IO.Stream dstream, int startline, int startcolumn)"); + ostr.println(" : this(dstream, startline, startcolumn, 4096){}"); + ostr.println(""); + //ostr.println(" public JavaCharStream(System.IO.Stream dstream, String encoding)"); + //ostr.println(" : this(dstream, encoding, 1, 1, 4096){}"); + //ostr.println(""); + ostr.println(" public JavaCharStream(System.IO.Stream dstream)"); + ostr.println(" : this(dstream, 1, 1, 4096){}"); + ostr.println(""); + //ostr.println(" public void ReInit(System.IO.Stream dstream, String encoding, int startline, int startcolumn, int buffersize){"); + //ostr.println(" ReInit(encoding == null ? new System.IO.StreamReader(dstream) : new System.IO.StreamReader(dstream, encoding), startline, startcolumn, buffersize);"); + //ostr.println(" }"); + ostr.println(""); + ostr.println(" public void ReInit(System.IO.Stream dstream, int startline, int startcolumn, int buffersize){"); + ostr.println(" ReInit(new System.IO.StreamReader(dstream), startline, startcolumn, buffersize);"); + ostr.println(" }"); + //ostr.println(" public void ReInit(System.IO.Stream dstream, String encoding, int startline, int startcolumn){"); + //ostr.println(" ReInit(dstream, encoding, startline, startcolumn, 4096);"); + //ostr.println(" }"); + ostr.println(" public void ReInit(System.IO.Stream dstream, int startline, int startcolumn){"); + ostr.println(" ReInit(dstream, startline, startcolumn, 4096);"); + ostr.println(" }"); + //ostr.println(" public void ReInit(System.IO.Stream dstream, String encoding){"); + //ostr.println(" ReInit(dstream, encoding, 1, 1, 4096);"); + //ostr.println(" }"); + ostr.println(""); + ostr.println(" public void ReInit(System.IO.Stream dstream){"); + ostr.println(" ReInit(dstream, 1, 1, 4096);"); + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public String GetImage(){"); + ostr.println(" if (bufpos >= tokenBegin)"); + ostr.println(" return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);"); + ostr.println(" else"); + ostr.println(" return new String(buffer, tokenBegin, bufsize - tokenBegin) +"); + ostr.println(" new String(buffer, 0, bufpos + 1);"); + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public char[] GetSuffix(int len){"); + ostr.println(" char[] ret = new char[len];"); + ostr.println(""); + ostr.println(" if ((bufpos + 1) >= len)"); + ostr.println(" System.Array.Copy(buffer, bufpos - len + 1, ret, 0, len);"); + ostr.println(" else{"); + ostr.println(" System.Array.Copy(buffer, bufsize - (len - bufpos - 1), ret, 0,"); + ostr.println(" len - bufpos - 1);"); + ostr.println(" System.Array.Copy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" return ret;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public void Done(){"); + ostr.println(" nextCharBuf = null;"); + ostr.println(" buffer = null;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" bufline = null;"); + ostr.println(" bufcolumn = null;"); + } + + ostr.println(" }"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Method to adjust line and column numbers for the start of a token."); + ostr.println(" */"); + ostr.println(prefix + "public void adjustBeginLineColumn(int newLine, int newCol){"); + ostr.println(" int start = tokenBegin;"); + ostr.println(" int len;"); + ostr.println(""); + ostr.println(" if (bufpos >= tokenBegin){"); + ostr.println(" len = bufpos - tokenBegin + inBuf + 1;"); + ostr.println(" }else{"); + ostr.println(" len = bufsize - tokenBegin + bufpos + 1 + inBuf;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" int i = 0, j = 0, k = 0;"); + ostr.println(" int nextColDiff = 0, columnDiff = 0;"); + ostr.println(""); + ostr.println(" while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]){"); + ostr.println(" bufline[j] = newLine;"); + ostr.println(" nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];"); + ostr.println(" bufcolumn[j] = newCol + columnDiff;"); + ostr.println(" columnDiff = nextColDiff;"); + ostr.println(" i++;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" if (i < len){"); + ostr.println(" bufline[j] = newLine++;"); + ostr.println(" bufcolumn[j] = newCol + columnDiff;"); + ostr.println(""); + ostr.println(" while (i++ < len){"); + ostr.println(" if (bufline[j = start % bufsize] != bufline[++start % bufsize])"); + ostr.println(" bufline[j] = newLine++;"); + ostr.println(" else"); + ostr.println(" bufline[j] = newLine;"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" line = bufline[j];"); + ostr.println(" column = bufcolumn[j];"); + ostr.println(" }"); + ostr.println(""); + } + + ostr.println("}"); + + ostr.println(""); + if(namespace) + ostr.println("}"); + + ostr.close(); + } + + public static void gen_SimpleCharStream() { + File tmp; + boolean namespace = false; + if ((tmp = new File(Options.getOutputDirectory(), "SimpleCharStream"+extension)).exists()) { + CheckVersion("SimpleCharStream"+extension, charStreamVersion); + return; + } + + System.err.println("File \"SimpleCharStream"+extension+"\" does not exist. Will create one."); + try { + ostr = new PrintWriter( + new BufferedWriter( + new FileWriter(tmp), + 8192 + ) + ); + } catch (IOException e) { + CSJavaCCErrors.semantic_error("Could not open file SimpleCharStream"+extension+" for writing."); + throw new Error(); + } + + ostr.println("/* " + getIdString(toolName, "SimpleCharStream"+extension) + " Version " + charStreamVersion + " */"); + + ostr.println("using System;"); + + if (cu_to_insertion_point_1.size() != 0 && + ((Token)cu_to_insertion_point_1.elementAt(0)).kind == NAMESPACE + ) { + for (int i = 1; i < cu_to_insertion_point_1.size(); i++) { + if (((Token)cu_to_insertion_point_1.elementAt(i)).kind == SEMICOLON) { + cline = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginLine; + ccol = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginColumn; + for (int j = 0; j < i; j++) { + printToken((Token)(cu_to_insertion_point_1.elementAt(j)), ostr); + } + namespace = true; + ostr.println("{"); + ostr.println(""); + break; + } + } + } + String prefix = (Options.getStatic() ? " static " : " "); + ostr.println("/**"); + ostr.println(" * An implementation of interface CharStream, where the stream is assumed to"); + ostr.println(" * contain only ASCII characters (without unicode processing)."); + ostr.println(" */"); + ostr.println(""); + ostr.println("public class SimpleCharStream{"); + ostr.println(" public static bool staticFlag = " + + Options.getStatic() + ";"); + ostr.println(prefix + "int bufsize;"); + ostr.println(prefix + "int available;"); + ostr.println(prefix + "int tokenBegin;"); + ostr.println(prefix + "public int bufpos = -1;"); + + if (OtherFilesGen.keepLineCol) + { + ostr.println(prefix + "protected int[] bufline;"); + ostr.println(prefix + "protected int[] bufcolumn;"); + ostr.println(""); + ostr.println(prefix + "protected int column = 0;"); + ostr.println(prefix + "protected int line = 1;"); + ostr.println(""); + ostr.println(prefix + "protected bool prevCharIsCR = false;"); + ostr.println(prefix + "protected bool prevCharIsLF = false;"); + } + + ostr.println(""); + ostr.println(prefix + "protected System.IO.TextReader inputStream;"); + ostr.println(""); + ostr.println(prefix + "protected char[] buffer;"); + ostr.println(prefix + "protected int maxNextCharInd = 0;"); + ostr.println(prefix + "protected int inBuf = 0;"); + ostr.println(prefix + "protected int tabSize = 8;"); + ostr.println(""); + ostr.println(prefix + "protected void setTabSize(int i) { tabSize = i; }"); + ostr.println(prefix + "protected int getTabSize(int i) { return tabSize; }"); + ostr.println(""); + ostr.println(""); + ostr.println(prefix + "protected void ExpandBuff(bool wrapAround){"); + ostr.println(" char[] newbuffer = new char[bufsize + 2048];"); + + if (OtherFilesGen.keepLineCol) + { + ostr.println(" int[] newbufline = new int[bufsize + 2048];"); + ostr.println(" int[] newbufcolumn = new int[bufsize + 2048];"); + } + + ostr.println(""); + ostr.println(" try{"); + ostr.println(" if (wrapAround){"); + ostr.println(" System.Array.Copy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);"); + ostr.println(" System.Array.Copy(buffer, 0, newbuffer,"); + ostr.println(" bufsize - tokenBegin, bufpos);"); + ostr.println(" buffer = newbuffer;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(""); + ostr.println(" System.Array.Copy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);"); + ostr.println(" System.Array.Copy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);"); + ostr.println(" bufline = newbufline;"); + ostr.println(""); + ostr.println(" System.Array.Copy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);"); + ostr.println(" System.Array.Copy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);"); + ostr.println(" bufcolumn = newbufcolumn;"); + } + + ostr.println(""); + ostr.println(" maxNextCharInd = (bufpos += (bufsize - tokenBegin));"); + ostr.println(" }else{"); + ostr.println(" System.Array.Copy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);"); + ostr.println(" buffer = newbuffer;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(""); + ostr.println(" System.Array.Copy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);"); + ostr.println(" bufline = newbufline;"); + ostr.println(""); + ostr.println(" System.Array.Copy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);"); + ostr.println(" bufcolumn = newbufcolumn;"); + } + + ostr.println(""); + ostr.println(" maxNextCharInd = (bufpos -= tokenBegin);"); + ostr.println(" }"); + ostr.println(" }catch (System.Exception t){"); + ostr.println(" throw new System.Exception(t.ToString());"); + ostr.println(" }"); + ostr.println(""); + ostr.println(""); + ostr.println(" bufsize += 2048;"); + ostr.println(" available = bufsize;"); + ostr.println(" tokenBegin = 0;"); + ostr.println(" }"); + ostr.println(""); + // New Fix for C# EOF + ostr.println(prefix + "bool stream_closed = false;"); + + ostr.println(prefix + "protected void FillBuff(){"); + ostr.println(" if (maxNextCharInd == available){"); + ostr.println(" if (available == bufsize){"); + ostr.println(" if (tokenBegin > 2048){"); + ostr.println(" bufpos = maxNextCharInd = 0;"); + ostr.println(" available = tokenBegin;"); + ostr.println(" }else if (tokenBegin < 0)"); + ostr.println(" bufpos = maxNextCharInd = 0;"); + ostr.println(" else"); + ostr.println(" ExpandBuff(false);"); + ostr.println(" }else if (available > tokenBegin)"); + ostr.println(" available = bufsize;"); + ostr.println(" else if ((tokenBegin - available) < 2048)"); + ostr.println(" ExpandBuff(true);"); + ostr.println(" else"); + ostr.println(" available = tokenBegin;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" int i;"); + ostr.println(" try {"); + + // New Fix for C# EOF + // * C# Reader returns "0" when reaching the end-of-file. After the stream + // has been closed, it throws an ObjectDisposedException, *not* and + // IOException. So we just jump in and handle that situation. + ostr.println(" if (stream_closed || (i = inputStream.Read(buffer, maxNextCharInd, available - maxNextCharInd)) <= 0){"); + ostr.println(" stream_closed = true;"); + + ostr.println(" inputStream.Close();"); + ostr.println(" throw new System.IO.IOException();"); + ostr.println(" }else"); + ostr.println(" maxNextCharInd += i;"); + ostr.println(" return;"); + ostr.println(" }"); + ostr.println(" catch(System.IO.IOException e) {"); + ostr.println(" --bufpos;"); + ostr.println(" backup(0);"); + ostr.println(" if (tokenBegin == -1)"); + ostr.println(" tokenBegin = bufpos;"); + ostr.println(" throw e;"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public char BeginToken(){"); + ostr.println(" tokenBegin = -1;"); + ostr.println(" char c = readChar();"); + ostr.println(" tokenBegin = bufpos;"); + ostr.println(""); + ostr.println(" return c;"); + ostr.println(" }"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(""); + ostr.println(prefix + "protected void UpdateLineColumn(char c){"); + ostr.println(" column++;"); + ostr.println(""); + ostr.println(" if (prevCharIsLF){"); + ostr.println(" prevCharIsLF = false;"); + ostr.println(" line += (column = 1);"); + ostr.println(" }"); + ostr.println(" else if (prevCharIsCR){"); + ostr.println(" prevCharIsCR = false;"); + ostr.println(" if (c == '\\n'){"); + ostr.println(" prevCharIsLF = true;"); + ostr.println(" }else"); + ostr.println(" line += (column = 1);"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" switch (c){"); + ostr.println(" case '\\r' :"); + ostr.println(" prevCharIsCR = true;"); + ostr.println(" break;"); + ostr.println(" case '\\n' :"); + ostr.println(" prevCharIsLF = true;"); + ostr.println(" break;"); + ostr.println(" case '\\t' :"); + ostr.println(" column--;"); + ostr.println(" column += (tabSize - (column % tabSize));"); + ostr.println(" break;"); + ostr.println(" default :"); + ostr.println(" break;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" bufline[bufpos] = line;"); + ostr.println(" bufcolumn[bufpos] = column;"); + ostr.println(" }"); + } + + ostr.println(""); + ostr.println(prefix + "public char readChar(){"); + ostr.println(" if (inBuf > 0){"); + ostr.println(" --inBuf;"); + ostr.println(""); + ostr.println(" if (++bufpos == bufsize)"); + ostr.println(" bufpos = 0;"); + ostr.println(""); + ostr.println(" return buffer[bufpos];"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" if (++bufpos >= maxNextCharInd)"); + ostr.println(" FillBuff();"); + ostr.println(""); + ostr.println(" char c = buffer[bufpos];"); + ostr.println(""); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" UpdateLineColumn(c);"); + } + + ostr.println(" return (c);"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * @deprecated "); + ostr.println(" * @see #getEndColumn"); + ostr.println(" */"); + ostr.println(""); + ostr.println(prefix + "public int getColumn() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufcolumn[bufpos];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * @deprecated "); + ostr.println(" * @see #getEndLine"); + ostr.println(" */"); + ostr.println(""); + ostr.println(prefix + "public int getLine() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufline[bufpos];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public int getEndColumn() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufcolumn[bufpos];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public int getEndLine() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufline[bufpos];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public int getBeginColumn() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufcolumn[tokenBegin];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public int getBeginLine() {"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" return bufline[tokenBegin];"); + }else{ + ostr.println(" return -1;"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public void backup(int amount) {"); + ostr.println(""); + ostr.println(" inBuf += amount;"); + ostr.println(" if ((bufpos -= amount) < 0)"); + ostr.println(" bufpos += bufsize;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" public SimpleCharStream(System.IO.TextReader dstream, int startline, int startcolumn, int buffersize){"); + + if (Options.getStatic()){ + ostr.println(" if (inputStream != null)"); + ostr.println(" throw new System.Exception\"\\n ERROR: Second call to the constructor of a static SimpleCharStream. You must\\n\" +"); + ostr.println(" \" either use ReInit() or set the JavaCC option STATIC to false\\n\" +"); + ostr.println(" \" during the generation of this class.\");"); + } + + ostr.println(" inputStream = dstream;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" line = startline;"); + ostr.println(" column = startcolumn - 1;"); + } + + ostr.println(""); + ostr.println(" available = bufsize = buffersize;"); + ostr.println(" buffer = new char[buffersize];"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" bufline = new int[buffersize];"); + ostr.println(" bufcolumn = new int[buffersize];"); + } + + ostr.println(" }"); + ostr.println(""); + ostr.println(" public SimpleCharStream(System.IO.TextReader dstream, int startline, int startcolumn)"); + ostr.println(" : this(dstream, startline, startcolumn, 4096){}"); + ostr.println(""); + ostr.println(" public SimpleCharStream(System.IO.TextReader dstream)"); + ostr.println(" : this(dstream, 1, 1, 4096){}"); + ostr.println(""); + ostr.println(" public void ReInit(System.IO.TextReader dstream, int startline, int startcolumn, int buffersize){"); + ostr.println(" inputStream = dstream;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" line = startline;"); + ostr.println(" column = startcolumn - 1;"); + } + + ostr.println(""); + ostr.println(" if (buffer == null || buffersize != buffer.Length){"); + ostr.println(" available = bufsize = buffersize;"); + ostr.println(" buffer = new char[buffersize];"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" bufline = new int[buffersize];"); + ostr.println(" bufcolumn = new int[buffersize];"); + } + + ostr.println(" }"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" prevCharIsLF = prevCharIsCR = false;"); + } + + ostr.println(" tokenBegin = inBuf = maxNextCharInd = 0;"); + ostr.println(" bufpos = -1;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" public void ReInit(System.IO.TextReader dstream, int startline, int startcolumn){"); + ostr.println(" ReInit(dstream, startline, startcolumn, 4096);"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" public void ReInit(System.IO.TextReader dstream){"); + ostr.println(" ReInit(dstream, 1, 1, 4096);"); + ostr.println(" }"); + //ostr.println(" public SimpleCharStream(System.IO.Stream dstream, String encoding, int startline, int startcolumn, int buffersize)"); + //ostr.println(" : this(encoding == null ? new System.IO.StreamReader(dstream) : new System.IO.StreamReader(dstream, encoding), startline, startcolumn, buffersize){}"); + //ostr.println(""); + ostr.println(" public SimpleCharStream(System.IO.Stream dstream, int startline, int startcolumn, int buffersize)"); + ostr.println(" : this(new System.IO.StreamReader(dstream), startline, startcolumn, buffersize){}"); + ostr.println(""); + //ostr.println(" public SimpleCharStream(System.IO.Stream dstream, String encoding, int startline, int startcolumn)"); + //ostr.println(" : this(dstream, encoding, startline, startcolumn, 4096){}"); + //ostr.println(""); + ostr.println(" public SimpleCharStream(System.IO.Stream dstream, int startline, int startcolumn)"); + ostr.println(" : this(dstream, startline, startcolumn, 4096){}"); + ostr.println(""); + //ostr.println(" public SimpleCharStream(System.IO.Stream dstream, String encoding)"); + //ostr.println(" : this(dstream, encoding, 1, 1, 4096){}"); + //ostr.println(""); + ostr.println(" public SimpleCharStream(System.IO.Stream dstream)"); + ostr.println(" : this(dstream, 1, 1, 4096){}"); + ostr.println(""); + //ostr.println(" public void ReInit(System.IO.Stream dstream, String encoding, int startline, int startcolumn, int buffersize){"); + //ostr.println(" ReInit(encoding == null ? new System.IO.StreamReader(dstream) : new System.IO.StreamReader(dstream, encoding), startline, startcolumn, buffersize);"); + //ostr.println(" }"); + ostr.println(""); + ostr.println(" public void ReInit(System.IO.Stream dstream, int startline, int startcolumn, int buffersize){"); + ostr.println(" ReInit(new System.IO.StreamReader(dstream), startline, startcolumn, buffersize);"); + ostr.println(" }"); + ostr.println(""); + //ostr.println(" public void ReInit(System.IO.Stream dstream, String encoding){"); + //ostr.println(" ReInit(dstream, encoding, 1, 1, 4096);"); + //ostr.println(" }"); + ostr.println(""); + ostr.println(" public void ReInit(System.IO.Stream dstream){"); + ostr.println(" ReInit(dstream, 1, 1, 4096);"); + ostr.println(" }"); + //ostr.println(" public void ReInit(System.IO.Stream dstream, String encoding, int startline, int startcolumn){"); + //ostr.println(" ReInit(dstream, encoding, startline, startcolumn, 4096);"); + //ostr.println(" }"); + ostr.println(" public void ReInit(System.IO.Stream dstream, int startline, int startcolumn){"); + ostr.println(" ReInit(dstream, startline, startcolumn, 4096);"); + ostr.println(" }"); + ostr.println(prefix + "public String GetImage(){"); + ostr.println(" if (bufpos >= tokenBegin)"); + ostr.println(" return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);"); + ostr.println(" else"); + ostr.println(" return new String(buffer, tokenBegin, bufsize - tokenBegin) +"); + ostr.println(" new String(buffer, 0, bufpos + 1);"); + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public char[] GetSuffix(int len){"); + ostr.println(" char[] ret = new char[len];"); + ostr.println(""); + ostr.println(" if ((bufpos + 1) >= len)"); + ostr.println(" System.Array.Copy(buffer, bufpos - len + 1, ret, 0, len);"); + ostr.println(" else{"); + ostr.println(" System.Array.Copy(buffer, bufsize - (len - bufpos - 1), ret, 0, len - bufpos - 1);"); + ostr.println(" System.Array.Copy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" return ret;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(prefix + "public void Done(){"); + ostr.println(" buffer = null;"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" bufline = null;"); + ostr.println(" bufcolumn = null;"); + } + + ostr.println(" }"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Method to adjust line and column numbers for the start of a token."); + ostr.println(" */"); + ostr.println(prefix + "public void adjustBeginLineColumn(int newLine, int newCol){"); + ostr.println(" int start = tokenBegin;"); + ostr.println(" int len;"); + ostr.println(""); + ostr.println(" if (bufpos >= tokenBegin){"); + ostr.println(" len = bufpos - tokenBegin + inBuf + 1;"); + ostr.println(" }else{"); + ostr.println(" len = bufsize - tokenBegin + bufpos + 1 + inBuf;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" int i = 0, j = 0, k = 0;"); + ostr.println(" int nextColDiff = 0, columnDiff = 0;"); + ostr.println(""); + ostr.println(" while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]){"); + ostr.println(" bufline[j] = newLine;"); + ostr.println(" nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];"); + ostr.println(" bufcolumn[j] = newCol + columnDiff;"); + ostr.println(" columnDiff = nextColDiff;"); + ostr.println(" i++;"); + ostr.println(" } "); + ostr.println(""); + ostr.println(" if (i < len){"); + ostr.println(" bufline[j] = newLine++;"); + ostr.println(" bufcolumn[j] = newCol + columnDiff;"); + ostr.println(""); + ostr.println(" while (i++ < len){"); + ostr.println(" if (bufline[j = start % bufsize] != bufline[++start % bufsize])"); + ostr.println(" bufline[j] = newLine++;"); + ostr.println(" else"); + ostr.println(" bufline[j] = newLine;"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" line = bufline[j];"); + ostr.println(" column = bufcolumn[j];"); + ostr.println(" }"); + ostr.println(""); + } + + ostr.println("}"); + + ostr.println(""); + if(namespace) + ostr.println("}"); + + ostr.close(); + } + + public static void gen_CharStream() { + File tmp; + boolean namespace = false; + if ((tmp = new File(Options.getOutputDirectory(), "CharStream"+extension)).exists()) { + CheckVersion("CharStream"+extension, charStreamVersion); + return; + } + System.err.println("File \"CharStream"+extension+"\" does not exist. Will create one."); + try { + ostr = new PrintWriter( + new BufferedWriter( + new FileWriter(tmp), + 8192 + ) + ); + } catch (IOException e) { + CSJavaCCErrors.semantic_error("Could not open file CharStream"+extension+" for writing."); + throw new Error(); + } + + ostr.println("/* " + getIdString(toolName, "CharStream"+extension) + " Version " + charStreamVersion + " */"); + + ostr.println("using System;"); + + if (cu_to_insertion_point_1.size() != 0 && ((Token)cu_to_insertion_point_1.elementAt(0)).kind == NAMESPACE) { + for (int i = 1; i < cu_to_insertion_point_1.size(); i++) { + if (((Token)cu_to_insertion_point_1.elementAt(i)).kind == SEMICOLON) { + cline = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginLine; + ccol = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginColumn; + for (int j = 0; j < i; j++) { + printToken((Token)(cu_to_insertion_point_1.elementAt(j)), ostr); + } + namespace = true; + ostr.println("{"); + ostr.println(""); + break; + } + } + } + ostr.println("/**"); + ostr.println(" * This interface describes a character stream that maintains line and"); + ostr.println(" * column number positions of the characters. It also has the capability"); + ostr.println(" * to backup the stream to some extent. An implementation of this"); + ostr.println(" * interface is used in the TokenManager implementation generated by"); + ostr.println(" * JavaCCParser."); + ostr.println(" *"); + ostr.println(" * All the methods except backup can be implemented in any fashion. backup"); + ostr.println(" * needs to be implemented correctly for the correct operation of the lexer."); + ostr.println(" * Rest of the methods are all used to get information like line number,"); + ostr.println(" * column number and the String that constitutes a token and are not used"); + ostr.println(" * by the lexer. Hence their implementation won't affect the generated lexer's"); + ostr.println(" * operation."); + ostr.println(" */"); + ostr.println(""); + ostr.println("public interface CharStream {"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns the next character from the selected input. The method"); + ostr.println(" * of selecting the input is the responsibility of the class"); + ostr.println(" * implementing this interface. Can throw any System.IO.IOException."); + ostr.println(" */"); + ostr.println(" char readChar();"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns the column position of the character last read."); + ostr.println(" * @deprecated "); + ostr.println(" * @see #getEndColumn"); + ostr.println(" */"); + ostr.println(" int getColumn();"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns the line number of the character last read."); + ostr.println(" * @deprecated "); + ostr.println(" * @see #getEndLine"); + ostr.println(" */"); + ostr.println(" int getLine();"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns the column number of the last character for current token (being"); + ostr.println(" * matched after the last call to BeginTOken)."); + ostr.println(" */"); + ostr.println(" int getEndColumn();"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns the line number of the last character for current token (being"); + ostr.println(" * matched after the last call to BeginTOken)."); + ostr.println(" */"); + ostr.println(" int getEndLine();"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns the column number of the first character for current token (being"); + ostr.println(" * matched after the last call to BeginTOken)."); + ostr.println(" */"); + ostr.println(" int getBeginColumn();"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns the line number of the first character for current token (being"); + ostr.println(" * matched after the last call to BeginTOken)."); + ostr.println(" */"); + ostr.println(" int getBeginLine();"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Backs up the input stream by amount steps. Lexer calls this method if it"); + ostr.println(" * had already read some characters, but could not use them to match a"); + ostr.println(" * (longer) token. So, they will be used again as the prefix of the next"); + ostr.println(" * token and it is the implemetation's responsibility to do this right."); + ostr.println(" */"); + ostr.println(" void backup(int amount);"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns the next character that marks the beginning of the next token."); + ostr.println(" * All characters must remain in the buffer between two successive calls"); + ostr.println(" * to this method to implement backup correctly."); + ostr.println(" */"); + ostr.println(" char BeginToken();"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns a string made up of characters from the marked token beginning "); + ostr.println(" * to the current buffer position. Implementations have the choice of returning"); + ostr.println(" * anything that they want to. For example, for efficiency, one might decide"); + ostr.println(" * to just return null, which is a valid implementation."); + ostr.println(" */"); + ostr.println(" String GetImage();"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns an array of characters that make up the suffix of length 'len' for"); + ostr.println(" * the currently matched token. This is used to build up the matched string"); + ostr.println(" * for use in actions in the case of MORE. A simple and inefficient"); + ostr.println(" * implementation of this is as follows :"); + ostr.println(" *"); + ostr.println(" * {"); + ostr.println(" * String t = GetImage();"); + ostr.println(" * return t.Substring(t.Length - len, t.Length).ToCharArray();"); + ostr.println(" * }"); + ostr.println(" */"); + ostr.println(" char[] GetSuffix(int len);"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * The lexer calls this function to indicate that it is done with the stream"); + ostr.println(" * and hence implementations can free any resources held by this class."); + ostr.println(" * Again, the body of this function can be just empty and it will not"); + ostr.println(" * affect the lexer's operation."); + ostr.println(" */"); + ostr.println(" void Done();"); + ostr.println(""); + ostr.println("}"); + + ostr.println(""); + if(namespace) + ostr.println("}"); + + ostr.close(); + } + + public static void gen_ParseException() { + File tmp; + boolean namespace = false; + if ((tmp = new File(Options.getOutputDirectory(), "ParseException"+extension)).exists()) { + CheckVersion("ParseException"+extension, parseExceptionVersion); + return; + } + System.err.println("File \"ParseException"+extension+"\" does not exist. Will create one."); + try { + ostr = new PrintWriter( + new BufferedWriter( + new FileWriter(tmp), + 8192 + ) + ); + } catch (IOException e) { + CSJavaCCErrors.semantic_error("Could not open file ParseException"+extension+" for writing."); + throw new Error(); + } + + ostr.println("/* " + getIdString(toolName, "ParseException"+extension) + " Version " + parseExceptionVersion + " */"); + + ostr.println("using System;"); + + if (cu_to_insertion_point_1.size() != 0 && + ((Token)cu_to_insertion_point_1.elementAt(0)).kind == NAMESPACE + ) { + for (int i = 1; i < cu_to_insertion_point_1.size(); i++) { + if (((Token)cu_to_insertion_point_1.elementAt(i)).kind == SEMICOLON) { + cline = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginLine; + ccol = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginColumn; + for (int j = 0; j < i; j++) { + printToken((Token)(cu_to_insertion_point_1.elementAt(j)), ostr); + } + namespace = true; + ostr.println("{"); + ostr.println(""); + break; + } + } + } + ostr.println("/**"); + ostr.println(" * This exception is thrown when parse errors are encountered."); + ostr.println(" * You can explicitly create objects of this exception type by"); + ostr.println(" * calling the method generateParseException in the generated"); + ostr.println(" * parser."); + ostr.println(" *"); + ostr.println(" * You can modify this class to customize your error reporting"); + ostr.println(" * mechanisms so long as you retain the public fields."); + ostr.println(" */"); + ostr.println("public class ParseException : System.Exception {"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * This constructor is used by the method \"generateParseException\""); + ostr.println(" * in the generated parser. Calling this constructor generates"); + ostr.println(" * a new object of this type with the fields \"currentToken\","); + ostr.println(" * \"expectedTokenSequences\", and \"tokenImage\" set. The bool"); + ostr.println(" * flag \"specialConstructor\" is also set to true to indicate that"); + ostr.println(" * this constructor was used to create this object."); + ostr.println(" * This constructor calls its super class with the empty string"); + ostr.println(" * to force the \"toString\" method of parent class \"System.Exception\" to"); + ostr.println(" * print the error message in the form:"); + ostr.println(" * ParseException: "); + ostr.println(" */"); + ostr.println(" public ParseException(Token currentTokenVal,"); + ostr.println(" long[][] expectedTokenSequencesVal,"); + ostr.println(" String[] tokenImageVal"); + ostr.println(" ) : base(\"\") {"); + ostr.println(" specialConstructor = true;"); + ostr.println(" currentToken = currentTokenVal;"); + ostr.println(" expectedTokenSequences = expectedTokenSequencesVal;"); + ostr.println(" tokenImage = tokenImageVal;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * The following constructors are for use by you for whatever"); + ostr.println(" * purpose you can think of. Constructing the exception in this"); + ostr.println(" * manner makes the exception behave in the normal way - i.e., as"); + ostr.println(" * documented in the class \"System.Exception\". The fields \"errorToken\","); + ostr.println(" * \"expectedTokenSequences\", and \"tokenImage\" do not contain"); + ostr.println(" * relevant information. The JavaCC generated code does not use"); + ostr.println(" * these constructors."); + ostr.println(" */"); + ostr.println(""); + ostr.println(" public ParseException(){ specialConstructor = false; }"); + ostr.println(""); + ostr.println(" public ParseException(String message) : base(message){"); + ostr.println(" specialConstructor = false;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * This variable determines which constructor was used to create"); + ostr.println(" * this object and thereby affects the semantics of the"); + ostr.println(" * \"getMessage\" method (see below)."); + ostr.println(" */"); + ostr.println(" protected bool specialConstructor;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * This is the last token that has been consumed successfully. If"); + ostr.println(" * this object has been created due to a parse error, the token"); + ostr.println(" * followng this token will (therefore) be the first error token."); + ostr.println(" */"); + ostr.println(" public Token currentToken;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Each entry in this array is an array of integers. Each array"); + ostr.println(" * of integers represents a sequence of tokens (by their ordinal"); + ostr.println(" * values) that is expected at this point of the parse."); + ostr.println(" */"); + ostr.println(" public long[][] expectedTokenSequences;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * This is a reference to the \"tokenImage\" array of the generated"); + ostr.println(" * parser within which the parse error occurred. This array is"); + ostr.println(" * defined in the generated ...Constants interface."); + ostr.println(" */"); + ostr.println(" public String[] tokenImage;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * This method has the standard behavior when this object has been"); + ostr.println(" * created using the standard constructors. Otherwise, it uses"); + ostr.println(" * \"currentToken\" and \"expectedTokenSequences\" to generate a parse"); + ostr.println(" * error message and returns it. If this object has been created"); + ostr.println(" * due to a parse error, and you do not catch it (it gets thrown"); + ostr.println(" * from the parser), then this method is called during the printing"); + ostr.println(" * of the final stack trace, and hence the correct error message"); + ostr.println(" * gets displayed."); + ostr.println(" */"); + ostr.println(" public override String Message{"); + ostr.println(" get{ if (!specialConstructor) {"); + ostr.println(" return base.Message;"); + ostr.println(" }"); + ostr.println(" System.Text.StringBuilder expected = new System.Text.StringBuilder();"); + ostr.println(" int maxSize = 0;"); + ostr.println(" for (int i = 0; i < expectedTokenSequences.Length; i++) {"); + ostr.println(" if (maxSize < expectedTokenSequences[i].Length) {"); + ostr.println(" maxSize = expectedTokenSequences[i].Length;"); + ostr.println(" }"); + ostr.println(" for (int j = 0; j < expectedTokenSequences[i].Length; j++) {"); + ostr.println(" expected.Append(tokenImage[expectedTokenSequences[i][j]]).Append(\" \");"); + ostr.println(" }"); + ostr.println(" if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0) {"); + ostr.println(" expected.Append(\"...\");"); + ostr.println(" }"); + ostr.println(" expected.Append(eol).Append(\" \");"); + ostr.println(" }"); + ostr.println(" String retval = \"Encountered \\\"\";"); + ostr.println(" Token tok = currentToken.next;"); + ostr.println(" for (int i = 0; i < maxSize; i++) {"); + ostr.println(" if (i != 0) retval += \" \";"); + ostr.println(" if (tok.kind == 0) {"); + ostr.println(" retval += tokenImage[0];"); + ostr.println(" break;"); + ostr.println(" }"); + ostr.println(" retval += add_escapes(tok.image);"); + ostr.println(" tok = tok.next; "); + ostr.println(" }"); + + if (OtherFilesGen.keepLineCol){ + ostr.println(" retval += \"\\\" at line \" + currentToken.next.beginLine + \", column \" + currentToken.next.beginColumn;"); + } + + ostr.println(" retval += \".\" + eol;"); + ostr.println(" if (expectedTokenSequences.Length == 1) {"); + ostr.println(" retval += \"Was expecting:\" + eol + \" \";"); + ostr.println(" } else {"); + ostr.println(" retval += \"Was expecting one of:\" + eol + \" \";"); + ostr.println(" }"); + ostr.println(" retval += expected.ToString();"); + ostr.println(" return retval;"); + ostr.println(" } }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * The end of line string for this machine."); + ostr.println(" */"); + // This needs to be looked up... + ostr.println(" protected String eol = \"\\n\"; //System.getProperty(\"line.separator\", \"\\n\");"); + ostr.println(" "); + ostr.println(" /**"); + ostr.println(" * Used to convert raw characters to their escaped version"); + ostr.println(" * when these raw version cannot be used as part of an ASCII"); + ostr.println(" * string literal."); + ostr.println(" */"); + ostr.println(" protected String add_escapes(String str) {"); + ostr.println(" System.Text.StringBuilder retval = new System.Text.StringBuilder();"); + ostr.println(" char ch;"); + ostr.println(" for (int i = 0; i < str.Length; i++) {"); + ostr.println(" switch (str[i]){"); + ostr.println(" case (char)0 : continue;"); + ostr.println(" case '\\b':"); + ostr.println(" retval.Append(\"\\\\b\");"); + ostr.println(" continue;"); + ostr.println(" case '\\t':"); + ostr.println(" retval.Append(\"\\\\t\");"); + ostr.println(" continue;"); + ostr.println(" case '\\n':"); + ostr.println(" retval.Append(\"\\\\n\");"); + ostr.println(" continue;"); + ostr.println(" case '\\f':"); + ostr.println(" retval.Append(\"\\\\f\");"); + ostr.println(" continue;"); + ostr.println(" case '\\r':"); + ostr.println(" retval.Append(\"\\\\r\");"); + ostr.println(" continue;"); + ostr.println(" case '\\\"':"); + ostr.println(" retval.Append(\"\\\\\\\"\");"); + ostr.println(" continue;"); + ostr.println(" case '\\'':"); + ostr.println(" retval.Append(\"\\\\\\'\");"); + ostr.println(" continue;"); + ostr.println(" case '\\\\':"); + ostr.println(" retval.Append(\"\\\\\\\\\");"); + ostr.println(" continue;"); + ostr.println(" default:"); + ostr.println(" if ((ch = str[i]) < 0x20 || ch > 0x7e) {"); + ostr.println(" String s = \"0000\" + ((int)ch).ToString(\"x\");"); + ostr.println(" retval.Append(\"\\\\u\" + s.Substring(s.Length - 4, s.Length));"); + ostr.println(" } else {"); + ostr.println(" retval.Append(ch);"); + ostr.println(" }"); + ostr.println(" continue;"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(" return retval.ToString();"); + ostr.println(" }"); + ostr.println(""); + ostr.println("}"); + + ostr.println(""); + if(namespace) + ostr.println("}"); + + ostr.close(); + } + + public static void gen_TokenMgrError() { + File tmp; + boolean namespace = false; + if ((tmp = new File(Options.getOutputDirectory(), "TokenMgrError"+extension)).exists()) { + CheckVersion("TokenMgrError"+extension, tokenMgrErrorVersion); + return; + } + System.err.println("File \"TokenMgrError"+extension+"\" does not exist. Will create one."); + try { + ostr = new PrintWriter( + new BufferedWriter( + new FileWriter(tmp), + 8192 + ) + ); + } catch (IOException e) { + CSJavaCCErrors.semantic_error("Could not open file TokenMgrError"+extension+" for writing."); + throw new Error(); + } + + ostr.println("/* " + getIdString(toolName, "TokenMgrError"+extension) + " Version " + tokenMgrErrorVersion + " */"); + + ostr.println("using System;"); + + if (cu_to_insertion_point_1.size() != 0 && ((Token)cu_to_insertion_point_1.elementAt(0)).kind == NAMESPACE) { + for (int i = 1; i < cu_to_insertion_point_1.size(); i++) { + if (((Token)cu_to_insertion_point_1.elementAt(i)).kind == SEMICOLON) { + cline = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginLine; + ccol = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginColumn; + for (int j = 0; j < i; j++) { + printToken((Token)(cu_to_insertion_point_1.elementAt(j)), ostr); + } + namespace = true; + ostr.println("{"); + ostr.println(""); + break; + } + } + } + ostr.println("public class TokenMgrError : System.Exception{"); + ostr.println(" public class EOFException : System.IO.IOException{}"); + ostr.println(" /*"); + ostr.println(" * Ordinals for various reasons why an Error of this type can be thrown."); + ostr.println(" */"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Lexical error occured."); + ostr.println(" */"); + ostr.println(" public static int LEXICAL_ERROR = 0;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * An attempt wass made to create a second instance of a static token manager."); + ostr.println(" */"); + ostr.println(" public static int STATIC_LEXER_ERROR = 1;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Tried to change to an invalid lexical state."); + ostr.println(" */"); + ostr.println(" public static int INVALID_LEXICAL_STATE = 2;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Detected (and bailed out of) an infinite loop in the token manager."); + ostr.println(" */"); + ostr.println(" public static int LOOP_DETECTED = 3;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Indicates the reason why the exception is thrown. It will have"); + ostr.println(" * one of the above 4 values."); + ostr.println(" */"); + ostr.println(" int errorCode;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Replaces unprintable characters by their espaced (or unicode escaped)"); + ostr.println(" * equivalents in the given string"); + ostr.println(" */"); + ostr.println(" public static String addEscapes(String str) {"); + ostr.println(" System.Text.StringBuilder retval = new System.Text.StringBuilder();"); + ostr.println(" char ch;"); + ostr.println(" for (int i = 0; i < str.Length; i++) {"); + ostr.println(" switch (str[i]){"); + ostr.println(" case (char)0 : continue;"); + ostr.println(" case '\\b':"); + ostr.println(" retval.Append(\"\\\\b\");"); + ostr.println(" continue;"); + ostr.println(" case '\\t':"); + ostr.println(" retval.Append(\"\\\\t\");"); + ostr.println(" continue;"); + ostr.println(" case '\\n':"); + ostr.println(" retval.Append(\"\\\\n\");"); + ostr.println(" continue;"); + ostr.println(" case '\\f':"); + ostr.println(" retval.Append(\"\\\\f\");"); + ostr.println(" continue;"); + ostr.println(" case '\\r':"); + ostr.println(" retval.Append(\"\\\\r\");"); + ostr.println(" continue;"); + ostr.println(" case '\\\"':"); + ostr.println(" retval.Append(\"\\\\\\\"\");"); + ostr.println(" continue;"); + ostr.println(" case '\\'':"); + ostr.println(" retval.Append(\"\\\\\\'\");"); + ostr.println(" continue;"); + ostr.println(" case '\\\\':"); + ostr.println(" retval.Append(\"\\\\\\\\\");"); + ostr.println(" continue;"); + ostr.println(" default:"); + ostr.println(" if ((ch = str[i]) < 0x20 || ch > 0x7e) {"); + ostr.println(" String s = \"0000\" + ((int)ch).ToString(\"X\");"); + ostr.println(" retval.Append(\"\\\\u\" + s.Substring(s.Length - 4, s.Length));"); + ostr.println(" } else {"); + ostr.println(" retval.Append(ch);"); + ostr.println(" }"); + ostr.println(" continue;"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(" return retval.ToString();"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns a detailed message for the Error when it is thrown by the"); + ostr.println(" * token manager to indicate a lexical error."); + ostr.println(" * Parameters : "); + ostr.println(" * EOFSeen : indicates if EOF caused the lexicl error"); + ostr.println(" * curLexState : lexical state in which this error occured"); + ostr.println(" * errorLine : line number when the error occured"); + ostr.println(" * errorColumn : column number when the error occured"); + ostr.println(" * errorAfter : prefix that was seen before this error occured"); + ostr.println(" * curchar : the offending character"); + ostr.println(" * Note: You can customize the lexical error message by modifying this method."); + ostr.println(" */"); + ostr.println(" protected static String LexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {"); + ostr.println(" return(\"Lexical error at line \" +"); + ostr.println(" errorLine + \", column \" +"); + ostr.println(" errorColumn + \". Encountered: \" +"); + ostr.println(" (EOFSeen ? \" \" : (\"\\\"\" + addEscapes(\"\"+(curChar)) + \"\\\"\") + \" (\" + (int)curChar + \"), \") +"); + ostr.println(" \"after : \\\"\" + addEscapes(errorAfter) + \"\\\"\");"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * You can also modify the body of this method to customize your error messages."); + ostr.println(" * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not"); + ostr.println(" * of end-users concern, so you can return something like : "); + ostr.println(" *"); + ostr.println(" * \"Internal Error : Please file a bug report .... \""); + ostr.println(" *"); + ostr.println(" * from this method for such cases in the release version of your parser."); + ostr.println(" */"); + ostr.println(" public override String Message {"); + ostr.println(" get { return base.Message; }"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" /*"); + ostr.println(" * Constructors of various flavors follow."); + ostr.println(" */"); + ostr.println(""); + ostr.println(" public TokenMgrError() {"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" public TokenMgrError(String message, int reason) : base(message)"); + ostr.println(" { errorCode = reason; }"); + ostr.println(""); + ostr.println(" public TokenMgrError(bool EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason)"); + ostr.println(" : this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason) {}"); + ostr.println("}"); + + ostr.println(""); + if(namespace) + ostr.println("}"); + + ostr.close(); + } + + public static void gen_Token() { + File tmp = null; + boolean namespace = false; + if ((tmp = new File(Options.getOutputDirectory(), "Token"+extension)).exists()) { + CheckVersion("Token"+extension, tokenVersion); + return; + } + System.err.println("File \"Token"+extension+"\" does not exist. Will create one."); + try { + ostr = new PrintWriter( + new BufferedWriter( + new FileWriter(tmp), + 8192 + ) + ); + } catch (IOException e) { + CSJavaCCErrors.semantic_error("Could not open file Token"+extension+" for writing."); + throw new Error(); + } + + ostr.println("/* " + getIdString(toolName, "Token"+extension) + " Version " + tokenVersion + " */"); + + ostr.println("using System;"); + + if (cu_to_insertion_point_1.size() != 0 && + ((Token)cu_to_insertion_point_1.elementAt(0)).kind == NAMESPACE + ) { + for (int i = 1; i < cu_to_insertion_point_1.size(); i++) { + if (((Token)cu_to_insertion_point_1.elementAt(i)).kind == SEMICOLON) { + cline = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginLine; + ccol = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginColumn; + for (int j = 0; j < i; j++) { + printToken((Token)(cu_to_insertion_point_1.elementAt(j)), ostr); + } + namespace = true; + ostr.println("{"); + ostr.println(""); + break; + } + } + } + ostr.println("/**"); + ostr.println(" * Describes the input token stream."); + ostr.println(" */"); + ostr.println(""); + ostr.println("public class Token {"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * An integer that describes the kind of this token. This numbering"); + ostr.println(" * system is determined by JavaCCParser, and a table of these numbers is"); + ostr.println(" * stored in the file ...Constants"+extension+"."); + ostr.println(" */"); + ostr.println(" public int kind;"); + if (OtherFilesGen.keepLineCol){ + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * beginLine and beginColumn describe the position of the first character"); + ostr.println(" * of this token; endLine and endColumn describe the position of the"); + ostr.println(" * last character of this token."); + ostr.println(" */"); + ostr.println(" public int beginLine, beginColumn, endLine, endColumn;"); + } + + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * The string image of the token."); + ostr.println(" */"); + ostr.println(" public String image;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * A reference to the next regular (non-special) token from the input"); + ostr.println(" * stream. If this is the last token from the input stream, or if the"); + ostr.println(" * token manager has not read tokens beyond this one, this field is"); + ostr.println(" * set to null. This is true only if this token is also a regular"); + ostr.println(" * token. Otherwise, see below for a description of the contents of"); + ostr.println(" * this field."); + ostr.println(" */"); + ostr.println(" public Token next;"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * This field is used to access special tokens that occur prior to this"); + ostr.println(" * token, but after the immediately preceding regular (non-special) token."); + ostr.println(" * If there are no such special tokens, this field is set to null."); + ostr.println(" * When there are more than one such special token, this field refers"); + ostr.println(" * to the last of these special tokens, which in turn refers to the next"); + ostr.println(" * previous special token through its specialToken field, and so on"); + ostr.println(" * until the first special token (whose specialToken field is null)."); + ostr.println(" * The next fields of special tokens refer to other special tokens that"); + ostr.println(" * immediately follow it (without an intervening regular token). If there"); + ostr.println(" * is no such token, this field is null."); + ostr.println(" */"); + ostr.println(" public Token specialToken;"); + ostr.println(""); + + ostr.println(" /**"); + ostr.println(" * No-argument constructor"); + ostr.println(" */"); + ostr.println(" public Token() : this(-1,null) {}"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Constructs a new token for the specified Image."); + ostr.println(" */"); + ostr.println(" public Token(int kind) : this(kind, null){ }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Constructs a new token for the specified Image and Kind."); + ostr.println(" */"); + ostr.println(" public Token(int kind, String image){"); + ostr.println(" this.kind = kind;"); + ostr.println(" this.image = image;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns the image."); + ostr.println(" */"); + ostr.println(" public override String ToString(){ return image; }"); + ostr.println(""); + ostr.println(" /**"); + ostr.println(" * Returns a new Token object, by default. However, if you want, you"); + ostr.println(" * can create and return subclass objects based on the value of ofKind."); + ostr.println(" * Simply add the cases to the switch for all those special cases."); + ostr.println(" * For example, if you have a subclass of Token called IDToken that"); + ostr.println(" * you want to create if ofKind is ID, simlpy add something like :"); + ostr.println(" *"); + ostr.println(" * case MyParserConstants.ID : return new IDToken(...);"); + ostr.println(" *"); + ostr.println(" * to the following switch statement. Then you can cast matchedToken"); + ostr.println(" * variable to the appropriate type and use it in your lexical actions."); + ostr.println(" */"); + ostr.println(" public static Token newToken(int ofKind, String img){"); + ostr.println(" switch(ofKind){"); + ostr.println(" default : return new Token(ofKind, img);"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(""); + ostr.println("}"); + + ostr.println(""); + if(namespace) + ostr.println("}"); + + ostr.close(); + } + + public static void gen_TokenManager() { + File tmp; + boolean namespace = false;; + if ((tmp = new File(Options.getOutputDirectory(), "TokenManager"+extension)).exists()) { + CheckVersion("TokenManager"+extension, tokenManagerVersion); + return; + } + System.err.println("File \"TokenManager"+extension+"\" does not exist. Will create one."); + try { + ostr = new PrintWriter( + new BufferedWriter( + new FileWriter(tmp), + 8192 + ) + ); + } catch (IOException e) { + CSJavaCCErrors.semantic_error("Could not open file TokenManager"+extension+" for writing."); + throw new Error(); + } + + ostr.println("/* " + getIdString(toolName, "TokenManager"+extension) + " Version " + tokenManagerVersion + " */"); + + ostr.println("using System;"); + + if (cu_to_insertion_point_1.size() != 0 && + ((Token)cu_to_insertion_point_1.elementAt(0)).kind == NAMESPACE + ) { + for (int i = 1; i < cu_to_insertion_point_1.size(); i++) { + if (((Token)cu_to_insertion_point_1.elementAt(i)).kind == SEMICOLON) { + cline = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginLine; + ccol = ((Token)(cu_to_insertion_point_1.elementAt(0))).beginColumn; + for (int j = 0; j < i; j++) { + printToken((Token)(cu_to_insertion_point_1.elementAt(j)), ostr); + } + namespace = true; + ostr.println("{"); + ostr.println(""); + break; + } + } + } + ostr.println("/**"); + ostr.println(" * An implementation for this interface is generated by"); + ostr.println(" * JavaCCParser. The user is free to use any implementation"); + ostr.println(" * of their choice."); + ostr.println(" */"); + ostr.println(""); + ostr.println("public interface TokenManager {"); + ostr.println(""); + ostr.println(" /** This gets the next token from the input stream."); + ostr.println(" * A token of kind 0 () should be returned on EOF."); + ostr.println(" */"); + ostr.println(" public Token getNextToken();"); + ostr.println(""); + ostr.println("}"); + + if(namespace) + ostr.println("}"); + + ostr.close(); + } + + public static void reInit() + { + ostr = null; + } + +} diff --git a/csjavacc/parser/ExpansionTreeWalker.java b/csjavacc/parser/ExpansionTreeWalker.java new file mode 100644 index 0000000..edfd9fe --- /dev/null +++ b/csjavacc/parser/ExpansionTreeWalker.java @@ -0,0 +1,142 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import csjavacc.struct.Choice; +import csjavacc.struct.Expansion; +import csjavacc.struct.Lookahead; +import csjavacc.struct.ROneOrMore; +import csjavacc.struct.RRepetitionRange; +import csjavacc.struct.RSequence; +import csjavacc.struct.RZeroOrMore; +import csjavacc.struct.RZeroOrOne; +import csjavacc.struct.TreeWalkerOp; +import csjavacc.struct.TryBlock; +import csjavacc.struct.ZeroOrMore; +import csjavacc.struct.ZeroOrOne; + +/** + * A set of routines that walk down the Expansion tree in + * various ways. + */ +public class ExpansionTreeWalker { + + /** + * Visits the nodes of the tree rooted at "node" in pre-order. + * i.e., it executes opObj.action first and then visits the + * children. + */ + static void preOrderWalk(Expansion node, TreeWalkerOp opObj) { + opObj.action(node); + if (opObj.goDeeper(node)) { + if (node instanceof Choice) { + for (java.util.Enumeration anEnum = ((Choice)node).choices.elements(); anEnum.hasMoreElements();) { + preOrderWalk((Expansion)anEnum.nextElement(), opObj); + } + } else if (node instanceof Sequence) { + for (java.util.Enumeration anEnum = ((Sequence)node).units.elements(); anEnum.hasMoreElements();) { + preOrderWalk((Expansion)anEnum.nextElement(), opObj); + } + } else if (node instanceof OneOrMore) { + preOrderWalk(((OneOrMore)node).expansion, opObj); + } else if (node instanceof ZeroOrMore) { + preOrderWalk(((ZeroOrMore)node).expansion, opObj); + } else if (node instanceof ZeroOrOne) { + preOrderWalk(((ZeroOrOne)node).expansion, opObj); + } else if (node instanceof Lookahead) { + Expansion nested_e = ((Lookahead)node).la_expansion; + if (!(nested_e instanceof Sequence && (Expansion)(((Sequence)nested_e).units.elementAt(0)) == node)) { + preOrderWalk(nested_e, opObj); + } + } else if (node instanceof TryBlock) { + preOrderWalk(((TryBlock)node).exp, opObj); + } else if (node instanceof RChoice) { + for (java.util.Enumeration anEnum = ((RChoice)node).choices.elements(); anEnum.hasMoreElements();) { + preOrderWalk((Expansion)anEnum.nextElement(), opObj); + } + } else if (node instanceof RSequence) { + for (java.util.Enumeration anEnum = ((RSequence)node).units.elements(); anEnum.hasMoreElements();) { + preOrderWalk((Expansion)anEnum.nextElement(), opObj); + } + } else if (node instanceof ROneOrMore) { + preOrderWalk(((ROneOrMore)node).regexpr, opObj); + } else if (node instanceof RZeroOrMore) { + preOrderWalk(((RZeroOrMore)node).regexpr, opObj); + } else if (node instanceof RZeroOrOne) { + preOrderWalk(((RZeroOrOne)node).regexpr, opObj); + } else if (node instanceof RRepetitionRange) { + preOrderWalk(((RRepetitionRange)node).regexpr, opObj); + } + } + } + + /** + * Visits the nodes of the tree rooted at "node" in post-order. + * i.e., it visits the children first and then executes + * opObj.action. + */ + static void postOrderWalk(Expansion node, TreeWalkerOp opObj) { + if (opObj.goDeeper(node)) { + if (node instanceof Choice) { + for (java.util.Enumeration anEnum = ((Choice)node).choices.elements(); anEnum.hasMoreElements();) { + postOrderWalk((Expansion)anEnum.nextElement(), opObj); + } + } else if (node instanceof Sequence) { + for (java.util.Enumeration anEnum = ((Sequence)node).units.elements(); anEnum.hasMoreElements();) { + postOrderWalk((Expansion)anEnum.nextElement(), opObj); + } + } else if (node instanceof OneOrMore) { + postOrderWalk(((OneOrMore)node).expansion, opObj); + } else if (node instanceof ZeroOrMore) { + postOrderWalk(((ZeroOrMore)node).expansion, opObj); + } else if (node instanceof ZeroOrOne) { + postOrderWalk(((ZeroOrOne)node).expansion, opObj); + } else if (node instanceof Lookahead) { + Expansion nested_e = ((Lookahead)node).la_expansion; + if (!(nested_e instanceof Sequence && (Expansion)(((Sequence)nested_e).units.elementAt(0)) == node)) { + postOrderWalk(nested_e, opObj); + } + } else if (node instanceof TryBlock) { + postOrderWalk(((TryBlock)node).exp, opObj); + } else if (node instanceof RChoice) { + for (java.util.Enumeration anEnum = ((RChoice)node).choices.elements(); anEnum.hasMoreElements();) { + postOrderWalk((Expansion)anEnum.nextElement(), opObj); + } + } else if (node instanceof RSequence) { + for (java.util.Enumeration anEnum = ((RSequence)node).units.elements(); anEnum.hasMoreElements();) { + postOrderWalk((Expansion)anEnum.nextElement(), opObj); + } + } else if (node instanceof ROneOrMore) { + postOrderWalk(((ROneOrMore)node).regexpr, opObj); + } else if (node instanceof RZeroOrMore) { + postOrderWalk(((RZeroOrMore)node).regexpr, opObj); + } else if (node instanceof RZeroOrOne) { + postOrderWalk(((RZeroOrOne)node).regexpr, opObj); + } else if (node instanceof RRepetitionRange) { + postOrderWalk(((RRepetitionRange)node).regexpr, opObj); + } + } + opObj.action(node); + } + +} diff --git a/csjavacc/parser/JavaCharStream.java b/csjavacc/parser/JavaCharStream.java new file mode 100644 index 0000000..d2d1c7f --- /dev/null +++ b/csjavacc/parser/JavaCharStream.java @@ -0,0 +1,589 @@ +/* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 4.0 */ +/** + * This file contains the code for CSJavaCCParser generated + * by CSJavaCCParser itself. + */ + +package csjavacc.parser; + +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (with java-like unicode escape processing). + */ + +public class JavaCharStream +{ + public static final boolean staticFlag = false; + static final int hexval(char c) throws java.io.IOException { + switch(c) + { + case '0' : + return 0; + case '1' : + return 1; + case '2' : + return 2; + case '3' : + return 3; + case '4' : + return 4; + case '5' : + return 5; + case '6' : + return 6; + case '7' : + return 7; + case '8' : + return 8; + case '9' : + return 9; + + case 'a' : + case 'A' : + return 10; + case 'b' : + case 'B' : + return 11; + case 'c' : + case 'C' : + return 12; + case 'd' : + case 'D' : + return 13; + case 'e' : + case 'E' : + return 14; + case 'f' : + case 'F' : + return 15; + } + + throw new java.io.IOException(); // Should never come here + } + + public int bufpos = -1; + int bufsize; + int available; + int tokenBegin; + protected int bufline[]; + protected int bufcolumn[]; + + protected int column = 0; + protected int line = 1; + + protected boolean prevCharIsCR = false; + protected boolean prevCharIsLF = false; + + protected java.io.Reader inputStream; + + protected char[] nextCharBuf; + protected char[] buffer; + protected int maxNextCharInd = 0; + protected int nextCharInd = -1; + protected int inBuf = 0; + protected int tabSize = 8; + + protected void setTabSize(int i) { tabSize = i; } + protected int getTabSize(int i) { return tabSize; } + + protected void ExpandBuff(boolean wrapAround) + { + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; + + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, + bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + bufpos += (bufsize - tokenBegin); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + bufpos -= tokenBegin; + } + } + catch (Throwable t) + { + throw new Error(t.getMessage()); + } + + available = (bufsize += 2048); + tokenBegin = 0; + } + + protected void FillBuff() throws java.io.IOException + { + int i; + if (maxNextCharInd == 4096) + maxNextCharInd = nextCharInd = 0; + + try { + if ((i = inputStream.read(nextCharBuf, maxNextCharInd, + 4096 - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + if (bufpos != 0) + { + --bufpos; + backup(0); + } + else + { + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + throw e; + } + } + + protected char ReadByte() throws java.io.IOException + { + if (++nextCharInd >= maxNextCharInd) + FillBuff(); + + return nextCharBuf[nextCharInd]; + } + + public char BeginToken() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + tokenBegin = bufpos; + return buffer[bufpos]; + } + + tokenBegin = 0; + bufpos = -1; + + return readChar(); + } + + protected void AdjustBuffSize() + { + if (available == bufsize) + { + if (tokenBegin > 2048) + { + bufpos = 0; + available = tokenBegin; + } + else + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } + + protected void UpdateLineColumn(char c) + { + column++; + + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else + line += (column = 1); + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + return buffer[bufpos]; + } + + char c; + + if (++bufpos == available) + AdjustBuffSize(); + + if ((buffer[bufpos] = c = ReadByte()) == '\\') + { + UpdateLineColumn(c); + + int backSlashCnt = 1; + + for (;;) // Read all the backslashes + { + if (++bufpos == available) + AdjustBuffSize(); + + try + { + if ((buffer[bufpos] = c = ReadByte()) != '\\') + { + UpdateLineColumn(c); + // found a non-backslash char. + if ((c == 'u') && ((backSlashCnt & 1) == 1)) + { + if (--bufpos < 0) + bufpos = bufsize - 1; + + break; + } + + backup(backSlashCnt); + return '\\'; + } + } + catch(java.io.IOException e) + { + if (backSlashCnt > 1) + backup(backSlashCnt); + + return '\\'; + } + + UpdateLineColumn(c); + backSlashCnt++; + } + + // Here, we have seen an odd number of backslash's followed by a 'u' + try + { + while ((c = ReadByte()) == 'u') + ++column; + + buffer[bufpos] = c = (char)(hexval(c) << 12 | + hexval(ReadByte()) << 8 | + hexval(ReadByte()) << 4 | + hexval(ReadByte())); + + column += 4; + } + catch(java.io.IOException e) + { + throw new Error("Invalid escape character at line " + line + + " column " + column + "."); + } + + if (backSlashCnt == 1) + return c; + else + { + backup(backSlashCnt - 1); + return '\\'; + } + } + else + { + UpdateLineColumn(c); + return (c); + } + } + + /** + * @deprecated + * @see #getEndColumn + */ + + public int getColumn() { + return bufcolumn[bufpos]; + } + + /** + * @deprecated + * @see #getEndLine + */ + + public int getLine() { + return bufline[bufpos]; + } + + public int getEndColumn() { + return bufcolumn[bufpos]; + } + + public int getEndLine() { + return bufline[bufpos]; + } + + public int getBeginColumn() { + return bufcolumn[tokenBegin]; + } + + public int getBeginLine() { + return bufline[tokenBegin]; + } + + public void backup(int amount) { + + inBuf += amount; + if ((bufpos -= amount) < 0) + bufpos += bufsize; + } + + public JavaCharStream(java.io.Reader dstream, + int startline, int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + nextCharBuf = new char[4096]; + } + + public JavaCharStream(java.io.Reader dstream, + int startline, int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + public JavaCharStream(java.io.Reader dstream) + { + this(dstream, 1, 1, 4096); + } + public void ReInit(java.io.Reader dstream, + int startline, int startcolumn, int buffersize) + { + inputStream = dstream; + line = startline; + column = startcolumn - 1; + + if (buffer == null || buffersize != buffer.length) + { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + nextCharBuf = new char[4096]; + } + prevCharIsLF = prevCharIsCR = false; + tokenBegin = inBuf = maxNextCharInd = 0; + nextCharInd = bufpos = -1; + } + + public void ReInit(java.io.Reader dstream, + int startline, int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + + public void ReInit(java.io.Reader dstream) + { + ReInit(dstream, 1, 1, 4096); + } + public JavaCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + public JavaCharStream(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); + } + + public JavaCharStream(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, 4096); + } + + public JavaCharStream(java.io.InputStream dstream, int startline, + int startcolumn) + { + this(dstream, startline, startcolumn, 4096); + } + + public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, 4096); + } + + public JavaCharStream(java.io.InputStream dstream) + { + this(dstream, 1, 1, 4096); + } + + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException + { + ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn, int buffersize) + { + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + } + public void ReInit(java.io.InputStream dstream, String encoding, int startline, + int startcolumn) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, startline, startcolumn, 4096); + } + public void ReInit(java.io.InputStream dstream, int startline, + int startcolumn) + { + ReInit(dstream, startline, startcolumn, 4096); + } + public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException + { + ReInit(dstream, encoding, 1, 1, 4096); + } + + public void ReInit(java.io.InputStream dstream) + { + ReInit(dstream, 1, 1, 4096); + } + + public String GetImage() + { + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); + } + + public char[] GetSuffix(int len) + { + char[] ret = new char[len]; + + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } + + return ret; + } + + public void Done() + { + nextCharBuf = null; + buffer = null; + bufline = null; + bufcolumn = null; + } + + /** + * Method to adjust line and column numbers for the start of a token. + */ + public void adjustBeginLineColumn(int newLine, int newCol) + { + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && + bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } + + line = bufline[j]; + column = bufcolumn[j]; + } + +} diff --git a/csjavacc/parser/LexGen.java b/csjavacc/parser/LexGen.java new file mode 100644 index 0000000..cbf8b96 --- /dev/null +++ b/csjavacc/parser/LexGen.java @@ -0,0 +1,1464 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.util.*; +import java.io.*; + +import csjavacc.struct.Action; +import csjavacc.struct.Nfa; +import csjavacc.struct.RegularExpression; +import csjavacc.struct.TokenProduction; + + +public class LexGen extends CSJavaCCGlobals implements CSJavaCCParserConstants{ + static private java.io.PrintWriter ostr; + static private String staticString; + static private String tokMgrClassName; + + // Hashtable of vectors + static Hashtable allTpsForState = new Hashtable(); + public static int lexStateIndex = 0; + static int[] kinds; + public static int maxOrdinal = 1; + public static String lexStateSuffix; + static String[] newLexState; + public static int[] lexStates; + public static boolean[] ignoreCase; + public static Action[] actions; + public static Hashtable initStates = new Hashtable(); + public static int stateSetSize; + public static int maxLexStates; + public static String[] lexStateName; + static NfaState[] singlesToSkip; + public static long[] toSkip; + public static long[] toSpecial; + public static long[] toMore; + public static long[] toToken; + public static int defaultLexState; + public static RegularExpression[] rexprs; + public static int[] maxLongsReqd; + public static int[] initMatch; + public static int[] canMatchAnyChar; + public static boolean hasEmptyMatch; + public static boolean[] canLoop; + public static boolean[] stateHasActions; + public static boolean hasLoop = false; + public static boolean[] canReachOnMore; + public static boolean[] hasNfa; + public static boolean[] mixed; + public static NfaState initialState; + public static int curKind; + static boolean hasSkipActions = false; + static boolean hasMoreActions = false; + static boolean hasTokenActions = false; + static boolean hasSpecial = false; + static boolean hasSkip = false; + static boolean hasMore = false; + static boolean hasToken = false; + public static RegularExpression curRE; + public static boolean keepLineCol; + static boolean namespace = false; + + static void PrintClassHead() + { + int i, j; + try { + File tmp = new File(Options.getOutputDirectory(), tokMgrClassName + extension); + ostr = new java.io.PrintWriter( + new java.io.BufferedWriter( + new java.io.FileWriter(tmp), + 8092 + ) + ); + Vector tn = (Vector)(toolNames.clone()); + tn.addElement(toolName); + + ostr.println("/* " + getIdString(tn, tokMgrClassName + extension) + " */"); + + int l = 0, kind; + i = 1; + boolean namehit = false; + for (;;){ + if (cu_to_insertion_point_1.size() <= l) + break; + + kind = ((Token)cu_to_insertion_point_1.elementAt(l)).kind; + if(kind == NAMESPACE || kind == IMPORT) { + if(kind == NAMESPACE){ + namespace = true; + namehit = true; + } + for (; i < cu_to_insertion_point_1.size(); i++) { + kind = ((Token)cu_to_insertion_point_1.elementAt(i)).kind; + if (kind == SEMICOLON || kind == ABSTRACT || + kind == OVERRIDE || kind == PUBLIC || + kind == CLASS || kind == INTERFACE) + { + cline = ((Token)(cu_to_insertion_point_1.elementAt(l))).beginLine; + ccol = ((Token)(cu_to_insertion_point_1.elementAt(l))).beginColumn; + for (j = l; j < i; j++) { + printToken((Token)(cu_to_insertion_point_1.elementAt(j)), ostr); + } + if (kind == SEMICOLON){ + if(namehit){ + ostr.println("{"); + namehit = false; + }else + printToken((Token)(cu_to_insertion_point_1.elementAt(j)), ostr); + } + ostr.println(""); + break; + } + } + l = ++i; + } + else + break; + } + + ostr.println(""); + ostr.println("public class " + tokMgrClassName + " : " + + cu_name + "Constants"); + ostr.println("{"); // } + } + catch (java.io.IOException err) { + CSJavaCCErrors.semantic_error("Could not create file : " + tokMgrClassName + extension+"\n"); + throw new Error(); + } + + if (token_mgr_decls != null && token_mgr_decls.size() > 0) + { + Token t = (Token)token_mgr_decls.elementAt(0); + boolean commonTokenActionSeen = false; + boolean commonTokenActionNeeded = Options.getCommonTokenAction(); + + printTokenSetup((Token)token_mgr_decls.elementAt(0)); + ccol = 1; + + for (j = 0; j < token_mgr_decls.size(); j++) + { + t = (Token)token_mgr_decls.elementAt(j); + if (t.kind == IDENTIFIER && + commonTokenActionNeeded && + !commonTokenActionSeen) + commonTokenActionSeen = t.image.equals("CommonTokenAction"); + + printToken(t, ostr); + } + + ostr.println(""); + if (commonTokenActionNeeded && !commonTokenActionSeen) + CSJavaCCErrors.warning("You have the COMMON_TOKEN_ACTION option set. But it appears you have not defined the method :\n"+ + " " + staticString + "void CommonTokenAction(Token t)\n" + + "in your TOKEN_MGR_DECLS. The generated token manager will not compile."); + + } + else if (Options.getCommonTokenAction()) + { + CSJavaCCErrors.warning("You have the COMMON_TOKEN_ACTION option set. But you have not defined the method :\n"+ + " " + staticString + "void CommonTokenAction(Token t)\n" + + "in your TOKEN_MGR_DECLS. The generated token manager will not compile."); + } + + ostr.println(" public " + staticString + " System.IO.TextWriter debugStream = new System.IO.StreamWriter(System.Console.OpenStandardError());"); + ostr.println(" public " + staticString + " void setDebugStream(System.IO.TextWriter ds) { debugStream = ds; }"); + + if(Options.getTokenManagerUsesParser() && !Options.getStatic()){ + ostr.println(" public " + cu_name + " parser = null;"); + } + } + + static void DumpDebugMethods() + { + + ostr.println(" " + staticString + " int kindCnt = 0;"); + ostr.println(" protected " + staticString + " String jjKindsForBitVector(int i, long vec){"); + ostr.println(" String retVal = \"\";"); + ostr.println(" if (i == 0)"); + ostr.println(" kindCnt = 0;"); + ostr.println(" for (int j = 0; j < 64; j++){"); + ostr.println(" if ((vec & (1L << j)) != 0L){"); + ostr.println(" if (kindCnt++ > 0)"); + ostr.println(" retVal += \", \";"); + ostr.println(" if (kindCnt % 5 == 0)"); + ostr.println(" retVal += \"\\n \";"); + ostr.println(" retVal += tokenImage[i * 64 + j];"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(" return retVal;"); + ostr.println(" }"); + ostr.println(""); + + ostr.println(" protected " + staticString + " String jjKindsForStateVector(int lexState, int[] vec, int start, int end){"); + ostr.println(" bool[] kindDone = new bool[" + maxOrdinal + "];"); + ostr.println(" String retVal = \"\";"); + ostr.println(" int cnt = 0;"); + ostr.println(" for (int i = start; i < end; i++){"); + ostr.println(" if (vec[i] == -1)"); + ostr.println(" continue;"); + ostr.println(" int[] stateSet = statesForState[curLexState][vec[i]];"); + ostr.println(" for (int j = 0; j < stateSet.Length; j++){"); + ostr.println(" int state = stateSet[j];"); + ostr.println(" if (!kindDone[kindForState[lexState][state]]){"); + ostr.println(" kindDone[kindForState[lexState][state]] = true;"); + ostr.println(" if (cnt++ > 0)"); + ostr.println(" retVal += \", \";"); + ostr.println(" if (cnt % 5 == 0)"); + ostr.println(" retVal += \"\\n \";"); + ostr.println(" retVal += tokenImage[kindForState[lexState][state]];"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(" if (cnt == 0)"); + ostr.println(" return \"{ }\";"); + ostr.println(" else"); + ostr.println(" return \"{ \" + retVal + \" }\";"); + ostr.println(" }"); + ostr.println(""); + } + + static void BuildLexStatesTable() + { + Enumeration e = rexprlist.elements(); + TokenProduction tp; + int i; + + String[] tmpLexStateName = new String[lexstate_I2S.size()]; + while (e.hasMoreElements()) + { + tp = (TokenProduction)e.nextElement(); + Vector respecs = tp.respecs; + Vector tps; + + for (i = 0; i < tp.lexStates.length; i++) + { + if ((tps = (Vector)allTpsForState.get(tp.lexStates[i])) == null) + { + tmpLexStateName[maxLexStates++] = tp.lexStates[i]; + allTpsForState.put(tp.lexStates[i], tps = new Vector()); + } + + tps.addElement(tp); + } + + if (respecs == null || respecs.size() == 0) + continue; + + RegularExpression re; + for (i = 0; i < respecs.size(); i++) + if (maxOrdinal <= (re = ((RegExprSpec)respecs.elementAt(i)).rexp).ordinal) + maxOrdinal = re.ordinal + 1; + } + + kinds = new int[maxOrdinal]; + toSkip = new long[maxOrdinal / 64 + 1]; + toSpecial = new long[maxOrdinal / 64 + 1]; + toMore = new long[maxOrdinal / 64 + 1]; + toToken = new long[maxOrdinal / 64 + 1]; + toToken[0] = 1L; + actions = new Action[maxOrdinal]; + actions[0] = actForEof; + hasTokenActions = actForEof != null; + initStates = new Hashtable(); + canMatchAnyChar = new int[maxLexStates]; + canLoop = new boolean[maxLexStates]; + stateHasActions = new boolean[maxLexStates]; + lexStateName = new String[maxLexStates]; + singlesToSkip = new NfaState[maxLexStates]; + System.arraycopy(tmpLexStateName, 0, lexStateName, 0, maxLexStates); + + for (i = 0; i < maxLexStates; i++) + canMatchAnyChar[i] = -1; + + hasNfa = new boolean[maxLexStates]; + mixed = new boolean[maxLexStates]; + maxLongsReqd = new int[maxLexStates]; + initMatch = new int[maxLexStates]; + newLexState = new String[maxOrdinal]; + newLexState[0] = nextStateForEof; + hasEmptyMatch = false; + lexStates = new int[maxOrdinal]; + ignoreCase = new boolean[maxOrdinal]; + rexprs = new RegularExpression[maxOrdinal]; + RStringLiteral.allImages = new String[maxOrdinal]; + canReachOnMore = new boolean[maxLexStates]; + } + + static int GetIndex(String name) + { + for (int i = 0; i < lexStateName.length; i++) + if (lexStateName[i] != null && lexStateName[i].equals(name)) + return i; + + throw new Error(); // Should never come here + } + + public static void AddCharToSkip(char c, int kind) + { + singlesToSkip[lexStateIndex].AddChar(c); + singlesToSkip[lexStateIndex].kind = kind; + } + + public static void start() + { + if (!Options.getBuildTokenManager() || + Options.getUserTokenManager() || + CSJavaCCErrors.get_error_count() > 0) + return; + + keepLineCol = Options.getKeepLineColumn(); + Vector choices = new Vector(); + Enumeration e; + TokenProduction tp; + int i, j; + + staticString = (Options.getStatic() ? "static " : ""); + tokMgrClassName = cu_name + "TokenManager"; + + PrintClassHead(); + BuildLexStatesTable(); + + e = allTpsForState.keys(); + + boolean ignoring = false; + + while (e.hasMoreElements()) + { + NfaState.ReInit(); + RStringLiteral.ReInit(); + + String key = (String)e.nextElement(); + + lexStateIndex = GetIndex(key); + lexStateSuffix = "_" + lexStateIndex; + Vector allTps = (Vector)allTpsForState.get(key); + initStates.put(key, initialState = new NfaState()); + ignoring = false; + + singlesToSkip[lexStateIndex] = new NfaState(); + singlesToSkip[lexStateIndex].dummy = true; + + if (key.equals("DEFAULT")) + defaultLexState = lexStateIndex; + + for (i = 0; i < allTps.size(); i++) + { + tp = (TokenProduction)allTps.elementAt(i); + int kind = tp.kind; + boolean ignore = tp.ignoreCase; + Vector rexps = tp.respecs; + + if (i == 0) + ignoring = ignore; + + for (j = 0; j < rexps.size(); j++) + { + RegExprSpec respec = (RegExprSpec)rexps.elementAt(j); + curRE = respec.rexp; + + rexprs[curKind = curRE.ordinal] = curRE; + lexStates[curRE.ordinal] = lexStateIndex; + ignoreCase[curRE.ordinal] = ignore; + + if (curRE.private_rexp) + { + kinds[curRE.ordinal] = -1; + continue; + } + + if (curRE instanceof RStringLiteral && + !((RStringLiteral)curRE).image.equals("")) + { + ((RStringLiteral)curRE).GenerateDfa(ostr, curRE.ordinal); + if (i != 0 && !mixed[lexStateIndex] && ignoring != ignore) + mixed[lexStateIndex] = true; + } + else if (curRE.CanMatchAnyChar()) + { + if (canMatchAnyChar[lexStateIndex] == -1 || + canMatchAnyChar[lexStateIndex] > curRE.ordinal) + canMatchAnyChar[lexStateIndex] = curRE.ordinal; + } + else + { + Nfa temp; + + if (curRE instanceof RChoice) + choices.addElement(curRE); + + temp = curRE.GenerateNfa(ignore); + temp.end.isFinal = true; + temp.end.kind = curRE.ordinal; + initialState.AddMove(temp.start); + } + + if (kinds.length < curRE.ordinal) + { + int[] tmp = new int[curRE.ordinal + 1]; + + System.arraycopy(kinds, 0, tmp, 0, kinds.length); + kinds = tmp; + } + //System.err.println(" ordinal : " + curRE.ordinal); + + kinds[curRE.ordinal] = kind; + + if (respec.nextState != null && + !respec.nextState.equals(lexStateName[lexStateIndex])) + newLexState[curRE.ordinal] = respec.nextState; + + if (respec.act != null && respec.act.action_tokens != null && + respec.act.action_tokens.size() > 0) + actions[curRE.ordinal] = respec.act; + + switch(kind) + { + case TokenProduction.SPECIAL : + hasSkipActions |= (actions[curRE.ordinal] != null) || + (newLexState[curRE.ordinal] != null); + hasSpecial = true; + toSpecial[curRE.ordinal / 64] |= 1L << (curRE.ordinal % 64); + toSkip[curRE.ordinal / 64] |= 1L << (curRE.ordinal % 64); + break; + case TokenProduction.SKIP : + hasSkipActions |= (actions[curRE.ordinal] != null); + hasSkip = true; + toSkip[curRE.ordinal / 64] |= 1L << (curRE.ordinal % 64); + break; + case TokenProduction.MORE : + hasMoreActions |= (actions[curRE.ordinal] != null); + hasMore = true; + toMore[curRE.ordinal / 64] |= 1L << (curRE.ordinal % 64); + + if (newLexState[curRE.ordinal] != null) + canReachOnMore[GetIndex(newLexState[curRE.ordinal])] = true; + else + canReachOnMore[lexStateIndex] = true; + + break; + case TokenProduction.TOKEN : + hasTokenActions |= (actions[curRE.ordinal] != null); + hasToken = true; + toToken[curRE.ordinal / 64] |= 1L << (curRE.ordinal % 64); + break; + } + } + } + + // Generate a static block for initializing the nfa transitions + NfaState.ComputeClosures(); + + for (i = 0; i < initialState.epsilonMoves.size(); i++) + ((NfaState)initialState.epsilonMoves.elementAt(i)).GenerateCode(); + + if (hasNfa[lexStateIndex] = (NfaState.generatedStates != 0)) + { + initialState.GenerateCode(); + initialState.GenerateInitMoves(ostr); + } + + if (initialState.kind != Integer.MAX_VALUE && initialState.kind != 0) + { + if ((toSkip[initialState.kind / 64] & (1L << initialState.kind)) != 0L || + (toSpecial[initialState.kind / 64] & (1L << initialState.kind)) != 0L) + hasSkipActions = true; + else if ((toMore[initialState.kind / 64] & (1L << initialState.kind)) != 0L) + hasMoreActions = true; + else + hasTokenActions = true; + + if (initMatch[lexStateIndex] == 0 || + initMatch[lexStateIndex] > initialState.kind) + { + initMatch[lexStateIndex] = initialState.kind; + hasEmptyMatch = true; + } + } + else if (initMatch[lexStateIndex] == 0) + initMatch[lexStateIndex] = Integer.MAX_VALUE; + + RStringLiteral.FillSubString(); + + if (hasNfa[lexStateIndex] && !mixed[lexStateIndex]) + RStringLiteral.GenerateNfaStartStates(ostr, initialState); + + RStringLiteral.DumpDfaCode(ostr); + + if (hasNfa[lexStateIndex]) + NfaState.DumpMoveNfa(ostr); + + if (stateSetSize < NfaState.generatedStates) + stateSetSize = NfaState.generatedStates; + } + + for (i = 0; i < choices.size(); i++) + ((RChoice)choices.elementAt(i)).CheckUnmatchability(); + + NfaState.DumpStateSets(ostr); + CheckEmptyStringMatch(); + NfaState.DumpNonAsciiMoveMethods(ostr); + RStringLiteral.DumpStrLiteralImages(ostr); + DumpStaticVarDeclarations(); + DumpFillToken(); + DumpGetNextToken(); + + if (Options.getDebugTokenManager()) + { + NfaState.DumpStatesForKind(ostr); + DumpDebugMethods(); + } + + if (hasLoop) + { + ostr.println(staticString + "int[] jjemptyLineNo = new int[" + maxLexStates + "];"); + ostr.println(staticString + "int[] jjemptyColNo = new int[" + maxLexStates + "];"); + ostr.println(staticString + "bool[] jjbeenHere = new bool[" + maxLexStates + "];"); + } + + if (hasSkipActions) + DumpSkipActions(); + if (hasMoreActions) + DumpMoreActions(); + if (hasTokenActions) + DumpTokenActions(); + + ostr.println("}"); + + if(namespace) + ostr.println("}"); + + ostr.close(); + } + + static void CheckEmptyStringMatch() + { + int i, j, k, len; + boolean[] seen = new boolean[maxLexStates]; + boolean[] done = new boolean[maxLexStates]; + String cycle; + String reList; + + Outer: + for (i = 0; i < maxLexStates; i++) + { + if (done[i] || initMatch[i] == 0 || initMatch[i] == Integer.MAX_VALUE || + canMatchAnyChar[i] != -1) + continue; + + done[i] = true; + len = 0; + cycle = ""; + reList = ""; + + for (k = 0; k < maxLexStates; k++) + seen[k] = false; + + j = i; + seen[i] = true; + cycle += lexStateName[j] + "-->"; + while (newLexState[initMatch[j]] != null) + { + cycle += newLexState[initMatch[j]]; + if (seen[j = GetIndex(newLexState[initMatch[j]])]) + break; + + cycle += "-->"; + done[j] = true; + seen[j] = true; + if (initMatch[j] == 0 || initMatch[j] == Integer.MAX_VALUE || + canMatchAnyChar[j] != -1) + continue Outer; + if (len != 0) + reList += "; "; + reList += "line " + rexprs[initMatch[j]].line + ", column " + + rexprs[initMatch[j]].column; + len++; + } + + if (newLexState[initMatch[j]] == null) + cycle += lexStateName[lexStates[initMatch[j]]]; + + for (k = 0; k < maxLexStates; k++) + canLoop[k] |= seen[k]; + + hasLoop = true; + if (len == 0) + CSJavaCCErrors.warning(rexprs[initMatch[i]], + "Regular expression" + ((rexprs[initMatch[i]].label.equals("")) + ? "" : (" for " + rexprs[initMatch[i]].label)) + + " can be matched by the empty string (\"\") in lexical state " + + lexStateName[i] + ". This can result in an endless loop of " + + "empty string matches."); + else + { + CSJavaCCErrors.warning(rexprs[initMatch[i]], + "Regular expression" + ((rexprs[initMatch[i]].label.equals("")) + ? "" : (" for " + rexprs[initMatch[i]].label)) + + " can be matched by the empty string (\"\") in lexical state " + + lexStateName[i] + ". This regular expression along with the " + + "regular expressions at " + reList + " forms the cycle \n " + + cycle + "\ncontaining regular expressions with empty matches." + + " This can result in an endless loop of empty string matches."); + } + } + } + + static void PrintArrayInitializer(int noElems) + { + ostr.print("{"); + for (int i = 0; i < noElems; i++) + { + if (i % 25 == 0) + ostr.print("\n "); + ostr.print("0, "); + } + ostr.println("\n};"); + } + + static void DumpStaticVarDeclarations() + { + int i; + String charStreamName; + + ostr.println("public static String[] lexStateNames = {"); + for (i = 0; i < maxLexStates; i++) + ostr.println(" \"" + lexStateName[i] + "\", "); + ostr.println("};"); + + if (maxLexStates > 1){ + ostr.print("public static int[] jjnewLexState = {"); + + for (i = 0; i < maxOrdinal; i++){ + if (i % 25 == 0) + ostr.print("\n "); + + if (newLexState[i] == null) + ostr.print("-1, "); + else + ostr.print(GetIndex(newLexState[i]) + ", "); + } + ostr.println("\n};"); + } + + if (hasSkip || hasMore || hasSpecial){ + // Bit vector for TOKEN + ostr.print("static long[] jjtoToken = {"); + for (i = 0; i < maxOrdinal / 64 + 1; i++){ + if (i % 4 == 0)ostr.print("\n "); + ostr.print("0x" + Long.toHexString(toToken[i]) + "L, "); + } + ostr.println("\n};"); + } + + if (hasSkip || hasSpecial){ + // Bit vector for SKIP + ostr.print("static long[] jjtoSkip = {"); + for (i = 0; i < maxOrdinal / 64 + 1; i++){ + if (i % 4 == 0)ostr.print("\n "); + ostr.print("0x" + Long.toHexString(toSkip[i]) + "L, "); + } + ostr.println("\n};"); + } + + if (hasSpecial) + { + // Bit vector for SPECIAL + ostr.print("static long[] jjtoSpecial = {"); + for (i = 0; i < maxOrdinal / 64 + 1; i++) + { + if (i % 4 == 0) + ostr.print("\n "); + ostr.print("0x" + Long.toHexString(toSpecial[i]) + "L, "); + } + ostr.println("\n};"); + } + + if (hasMore) + { + // Bit vector for MORE + ostr.print("static long[] jjtoMore = {"); + for (i = 0; i < maxOrdinal / 64 + 1; i++) + { + if (i % 4 == 0) + ostr.print("\n "); + ostr.print("0x" + Long.toHexString(toMore[i]) + "L, "); + } + ostr.println("\n};"); + } + + if (Options.getUserCharStream()) + charStreamName = "CharStream"; + else + { + if (Options.getCSUnicodeEscape()) + charStreamName = "JavaCharStream"; + else + charStreamName = "SimpleCharStream"; + } + + ostr.println(staticString + "protected " + charStreamName + " input_stream;"); + + ostr.println(staticString + "private long[] jjrounds = " + + "new long[" + stateSetSize + "];"); + ostr.println(staticString + "private int[] jjstateSet = " + + "new int[" + (2 * stateSetSize) + "];"); + + if (hasMoreActions || hasSkipActions || hasTokenActions) + { + ostr.println(staticString + "StringBuffer image;"); + ostr.println(staticString + "int jjimageLen;"); + ostr.println(staticString + "int lengthOfMatch;"); + } + + ostr.println(staticString + "protected char curChar;"); + + if(Options.getTokenManagerUsesParser() && !Options.getStatic()){ + ostr.println("public " + tokMgrClassName + "(" + cu_name + " parserArg, " + charStreamName + " stream){"); + ostr.println(" parser = parserArg;"); + } else { + ostr.println("public " + tokMgrClassName + "(" + charStreamName + " stream){"); + } + + if (Options.getStatic() && !Options.getUserCharStream()) + { + ostr.println(" if (input_stream != null)"); + ostr.println(" throw new TokenMgrError(\"ERROR: Second call to constructor of static lexer. You must use ReInit() to initialize the static variables.\", TokenMgrError.STATIC_LEXER_ERROR);"); + } + else if (!Options.getUserCharStream()) + { + if (Options.getCSUnicodeEscape()) + ostr.println(" if (JavaCharStream.staticFlag)"); + else + ostr.println(" if (SimpleCharStream.staticFlag)"); + + ostr.println(" throw new Exception(\"ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.\");"); + } + + ostr.println(" input_stream = stream;"); + + ostr.println("}"); + + if(Options.getTokenManagerUsesParser() && !Options.getStatic()){ + ostr.println("public " + tokMgrClassName + "(" + cu_name + " parserArg, " + charStreamName + " stream, int lexState): this(parserArg, stream){"); + } else { + ostr.println("public " + tokMgrClassName + "(" + charStreamName + " stream, int lexState) : this(stream){"); + } + ostr.println(" SwitchTo(lexState);"); + ostr.println("}"); + + // Reinit method for reinitializing the parser (for static parsers). + ostr.println(staticString + "public void ReInit(" + charStreamName + " stream)"); + ostr.println("{"); + ostr.println(" jjmatchedPos = jjnewStateCnt = 0;"); + ostr.println(" curLexState = defaultLexState;"); + ostr.println(" input_stream = stream;"); + ostr.println(" ReInitRounds();"); + ostr.println("}"); + + // Method to reinitialize the jjrounds array. + ostr.println(staticString + "private void ReInitRounds()"); + ostr.println("{"); + ostr.println(" int i;"); + ostr.println(" jjround = 0x" + Integer.toHexString(Integer.MIN_VALUE + 1)+ ";"); + ostr.println(" for (i = " + stateSetSize + "; i-- > 0;)"); + ostr.println(" jjrounds[i] = 0x" + Integer.toHexString(Integer.MIN_VALUE) + ";"); + ostr.println("}"); + + // Reinit method for reinitializing the parser (for static parsers). + ostr.println(staticString + "public void ReInit(" + charStreamName + " stream, int lexState)"); + ostr.println("{"); + ostr.println(" ReInit(stream);"); + ostr.println(" SwitchTo(lexState);"); + ostr.println("}"); + + ostr.println(staticString + "public void SwitchTo(int lexState)"); + ostr.println("{"); + ostr.println(" if (lexState >= " + lexStateName.length + " || lexState < 0)"); + ostr.println(" throw new TokenMgrError(\"Error: Ignoring invalid lexical state : \"" + + " + lexState + \". State unchanged.\", TokenMgrError.INVALID_LEXICAL_STATE);"); + ostr.println(" else"); + ostr.println(" curLexState = lexState;"); + ostr.println("}"); + + ostr.println(""); + } + + // Assumes l != 0L + static char MaxChar(long l) + { + for (int i = 64; i-- > 0; ) + if ((l & (1L << i)) != 0L) + return (char)i; + + return 0xffff; + } + + static void DumpFillToken() + { + ostr.println(staticString + "protected Token jjFillToken(){"); + ostr.println(" String im = jjstrLiteralImages[jjmatchedKind];"); + ostr.println(" String curTokenIm;"); + if (keepLineCol){ + ostr.println(" int beginLine;"); + ostr.println(" int beginColumn;"); + ostr.println(" int endLine;"); + ostr.println(" int endColumn;"); + } + if (hasEmptyMatch){ + ostr.println(" if (jjmatchedPos < 0){"); + ostr.println(" if (image == null) curTokenIm = \"\";"); + ostr.println(" else curTokenIm = image.toString();"); + if (keepLineCol){ + ostr.println(" beginLine = endLine = input_stream.getBeginLine();"); + ostr.println(" beginColumn = endColumn = input_stream.getBeginColumn();"); + } + ostr.println(" }else{"); + } + ostr.println(" curTokenIm = (im == null) ? input_stream.GetImage() : im;"); + + if (keepLineCol){ + ostr.println(" beginLine = input_stream.getBeginLine();"); + ostr.println(" beginColumn = input_stream.getBeginColumn();"); + ostr.println(" endLine = input_stream.getEndLine();"); + ostr.println(" endColumn = input_stream.getEndColumn();"); + } + + if (hasEmptyMatch){ + ostr.println(" }"); + } + ostr.println(""); + ostr.println(" Token t = Token.newToken(jjmatchedKind, curTokenIm);"); + ostr.println(" t.beginLine = beginLine;"); + ostr.println(" t.beginColumn = beginColumn;"); + ostr.println(" t.endLine = endLine;"); + ostr.println(" t.endColumn = endColumn;"); + + ostr.println(" return t;"); + ostr.println("}"); + } + + static void DumpGetNextToken() + { + int i; + + ostr.println(""); + ostr.println(staticString + "int curLexState = " + defaultLexState + ";"); + ostr.println(staticString + "int defaultLexState = " + defaultLexState + ";"); + ostr.println(staticString + "int jjnewStateCnt;"); + ostr.println(staticString + "long jjround;"); + ostr.println(staticString + "int jjmatchedPos;"); + ostr.println(staticString + "int jjmatchedKind;"); + ostr.println(""); + ostr.println("public " + staticString + "Token getNextToken()" + + " "); + ostr.println("{"); + ostr.println(" int kind;"); + ostr.println(" Token specialToken = null;"); + ostr.println(" Token matchedToken;"); + ostr.println(" int curPos = 0;"); + ostr.println(""); + ostr.println(" EOFLoop :\n for (;;){"); + ostr.println(" try{ "); + ostr.println(" curChar = input_stream.BeginToken();"); + ostr.println(" }catch(System.IO.IOException e){"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(\"Returning the token.\");"); + + ostr.println(" jjmatchedKind = 0;"); + ostr.println(" matchedToken = jjFillToken();"); + + if (hasSpecial) + ostr.println(" matchedToken.specialToken = specialToken;"); + + if (nextStateForEof != null || actForEof != null) + ostr.println(" TokenLexicalActions(matchedToken);"); + + if (Options.getCommonTokenAction()) + ostr.println(" CommonTokenAction(matchedToken);"); + + ostr.println(" return matchedToken;"); + ostr.println(" }"); + + if (hasMoreActions || hasSkipActions || hasTokenActions){ + ostr.println(" image = null;"); + ostr.println(" jjimageLen = 0;"); + } + + ostr.println(""); + + String prefix = ""; + if (hasMore){ + ostr.println(" for (;;){"); + prefix = " "; + } + + String endSwitch = ""; + String caseStr = ""; + // this also sets up the start state of the nfa + if (maxLexStates > 1){ + ostr.println(prefix + " switch(curLexState){"); + endSwitch = prefix + " }"; + caseStr = prefix + " case "; + prefix += " "; + } + + prefix += " "; + for(i = 0; i < maxLexStates; i++){ + if (maxLexStates > 1) + ostr.println(caseStr + i + ":"); + + if (singlesToSkip[i].HasTransitions()) + { + // added the backup(0) to make JIT happy + ostr.println(prefix + "try { input_stream.backup(0);"); + if (singlesToSkip[i].asciiMoves[0] != 0L && + singlesToSkip[i].asciiMoves[1] != 0L){ + ostr.println(prefix + " while ((curChar < 64" + " && (0x" + + Long.toHexString(singlesToSkip[i].asciiMoves[0]) + + "L & (1L << curChar)) != 0L) || \n" + + prefix + " (curChar >> 6) == 1" + + " && (0x" + + Long.toHexString(singlesToSkip[i].asciiMoves[1]) + + "L & (1L << (curChar & 0x3F))) != 0L)"); + } + else if (singlesToSkip[i].asciiMoves[1] == 0L) + { + ostr.println(prefix + " while (curChar <= " + + (int)MaxChar(singlesToSkip[i].asciiMoves[0]) + " && (0x" + + Long.toHexString(singlesToSkip[i].asciiMoves[0]) + + "L & (1L << curChar)) != 0L)"); + } + else if (singlesToSkip[i].asciiMoves[0] == 0L) + { + ostr.println(prefix + " while (curChar > 63 && curChar <= " + + ((int)MaxChar(singlesToSkip[i].asciiMoves[1]) + 64) + + " && (0x" + + Long.toHexString(singlesToSkip[i].asciiMoves[1]) + + "L & (1L << (curChar & 0x3F))) != 0L)"); + } + + if (Options.getDebugTokenManager()) + { + ostr.println(prefix + "{"); + ostr.println(" debugStream.WriteLine(" + (maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState]\n + \">\" + " : "") + "\"Skipping character : \" + " + + "TokenMgrError.addEscapes(\"\"+(curChar)) + \" (\" + (int)curChar + \")\");"); + } + ostr.println(prefix + " curChar = input_stream.BeginToken();"); + + if (Options.getDebugTokenManager()) + ostr.println(prefix + "}"); + + ostr.println(prefix + "}"); + ostr.println(prefix + "catch (System.IO.IOException e1) { goto EOFLoop; }"); + } + + if (initMatch[i] != Integer.MAX_VALUE && initMatch[i] != 0) + { + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(\" Matched the empty string as \" + tokenImage[" + + initMatch[i] + "] + \" token.\");"); + + ostr.println(prefix + "jjmatchedKind = " + initMatch[i] + ";"); + ostr.println(prefix + "jjmatchedPos = -1;"); + ostr.println(prefix + "curPos = 0;"); + } + else + { + ostr.println(prefix + "jjmatchedKind = 0x" + Integer.toHexString(Integer.MAX_VALUE) + ";"); + ostr.println(prefix + "jjmatchedPos = 0;"); + } + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(" + (maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + "\"Current character : \" + " + + "TokenMgrError.addEscapes(\"\"+(curChar)) + \" (\" + (int)curChar + \") at line \" + input_stream.getLine() + \" column \" + input_stream.getColumn());"); + + ostr.println(prefix + "curPos = jjMoveStringLiteralDfa0_" + i + "();"); + + if (canMatchAnyChar[i] != -1) + { + if (initMatch[i] != Integer.MAX_VALUE && initMatch[i] != 0) + ostr.println(prefix + "if (jjmatchedPos < 0 || (jjmatchedPos == 0 && jjmatchedKind > " + + canMatchAnyChar[i] + "))"); + else + ostr.println(prefix + "if (jjmatchedPos == 0 && jjmatchedKind > " + + canMatchAnyChar[i] + ")"); + ostr.println(prefix + "{"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(\" Current character matched as a \" + tokenImage[" + + canMatchAnyChar[i] + "] + \" token.\");"); + ostr.println(prefix + " jjmatchedKind = " + canMatchAnyChar[i] + ";"); + + if (initMatch[i] != Integer.MAX_VALUE && initMatch[i] != 0) + ostr.println(prefix + " jjmatchedPos = 0;"); + + ostr.println(prefix + "}"); + } + + if (maxLexStates > 1) + ostr.println(prefix + "break;"); + } + + if (maxLexStates > 1) + ostr.println(endSwitch); + else if (maxLexStates == 0) + ostr.println(" jjmatchedKind = 0x" + Integer.toHexString(Integer.MAX_VALUE) + ";"); + + if (maxLexStates > 1)prefix = " "; + else prefix = ""; + + if (maxLexStates > 0){ + ostr.println(prefix + " if (jjmatchedKind != 0x" + Integer.toHexString(Integer.MAX_VALUE) + "){"); + ostr.println(prefix + " if (jjmatchedPos + 1 < curPos)"); + + if (Options.getDebugTokenManager()) + ostr.println(prefix + " { debugStream.WriteLine(\" Putting back \" + (curPos - jjmatchedPos - 1) + \" characters into the input stream.\");"); + + ostr.println(prefix + " input_stream.backup(curPos - jjmatchedPos - 1);"); + + if (Options.getDebugTokenManager()) + ostr.println(prefix + " }"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(\"****** FOUND A \" + tokenImage[jjmatchedKind] + \" MATCH (\" + TokenMgrError.addEscapes(new String(input_stream.GetSuffix(jjmatchedPos + 1))) + \") ******\\n\");"); + + if (hasSkip || hasMore || hasSpecial){ + ostr.println(prefix + " if (((ulong)jjtoToken[jjmatchedKind >> 6] & (1UL << (jjmatchedKind & 0x3F))) != 0){"); + } + + ostr.println(prefix + " matchedToken = jjFillToken();"); + + if (hasSpecial) + ostr.println(prefix + " matchedToken.specialToken = specialToken;"); + + if (hasTokenActions) + ostr.println(prefix + " TokenLexicalActions(matchedToken);"); + + if (maxLexStates > 1){ + ostr.println(" if (jjnewLexState[jjmatchedKind] != -1)"); + ostr.println(prefix + " curLexState = jjnewLexState[jjmatchedKind];"); + } + + if (Options.getCommonTokenAction()) + ostr.println(prefix + " CommonTokenAction(matchedToken);"); + + ostr.println(prefix + " return matchedToken;"); + + if (hasSkip || hasMore || hasSpecial) + { + ostr.println(prefix + " }"); + + if (hasSkip || hasSpecial) + { + if (hasMore) + { + ostr.println(prefix + " else if ((jjtoSkip[jjmatchedKind >> 6] & " + + "(1L << (jjmatchedKind & 0x3F))) != 0L)"); + } + else + ostr.println(prefix + " else"); + + ostr.println(prefix + " {"); + + if (hasSpecial){ + ostr.println(prefix + " if ((jjtoSpecial[jjmatchedKind >> 6] & " + + "(1L << (jjmatchedKind & 0x3F))) != 0L)"); + ostr.println(prefix + " {"); + + ostr.println(prefix + " matchedToken = jjFillToken();"); + + ostr.println(prefix + " if (specialToken == null)"); + ostr.println(prefix + " specialToken = matchedToken;"); + ostr.println(prefix + " else"); + ostr.println(prefix + " {"); + ostr.println(prefix + " matchedToken.specialToken = specialToken;"); + ostr.println(prefix + " specialToken = (specialToken.next = matchedToken);"); + ostr.println(prefix + " }"); + + if (hasSkipActions) + ostr.println(prefix + " SkipLexicalActions(matchedToken);"); + + ostr.println(prefix + " }"); + + if (hasSkipActions) + { + ostr.println(prefix + " else "); + ostr.println(prefix + " SkipLexicalActions(null);"); + } + } + else if (hasSkipActions) + ostr.println(prefix + " SkipLexicalActions(null);"); + + if (maxLexStates > 1) + { + ostr.println(" if (jjnewLexState[jjmatchedKind] != -1)"); + ostr.println(prefix + " curLexState = jjnewLexState[jjmatchedKind];"); + } + + ostr.println(prefix + " goto EOFLoop;"); + ostr.println(prefix + " }"); + } + + if (hasMore) + { + if (hasMoreActions) + ostr.println(prefix + " MoreLexicalActions();"); + else if (hasSkipActions || hasTokenActions) + ostr.println(prefix + " jjimageLen += jjmatchedPos + 1;"); + + if (maxLexStates > 1) + { + ostr.println(" if (jjnewLexState[jjmatchedKind] != -1)"); + ostr.println(prefix + " curLexState = jjnewLexState[jjmatchedKind];"); + } + ostr.println(prefix + " curPos = 0;"); + ostr.println(prefix + " jjmatchedKind = 0x" + Integer.toHexString(Integer.MAX_VALUE) + ";"); + + ostr.println(prefix + " try {"); + ostr.println(prefix + " curChar = input_stream.readChar();"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(" + (maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + "\"Current character : \" + " + + "TokenMgrError.addEscapes(\"\"+(curChar)) + \" (\" + (int)curChar + \") at line \" + input_stream.getLine() + \" column \" + input_stream.getColumn());"); + ostr.println(prefix + " continue;"); + ostr.println(prefix + " }"); + ostr.println(prefix + " catch (System.IO.IOException e1) { }"); + } + } + + ostr.println(prefix + " }"); + ostr.println(prefix + " int error_line = input_stream.getEndLine();"); + ostr.println(prefix + " int error_column = input_stream.getEndColumn();"); + ostr.println(prefix + " String error_after = null;"); + ostr.println(prefix + " bool EOFSeen = false;"); + ostr.println(prefix + " try { input_stream.readChar(); input_stream.backup(1); }"); + ostr.println(prefix + " catch (System.IO.IOException e1) {"); + ostr.println(prefix + " EOFSeen = true;"); + ostr.println(prefix + " error_after = curPos <= 1 ? \"\" : input_stream.GetImage();"); + ostr.println(prefix + " if (curChar == '\\n' || curChar == '\\r') {"); + ostr.println(prefix + " error_line++;"); + ostr.println(prefix + " error_column = 0;"); + ostr.println(prefix + " }"); + ostr.println(prefix + " else"); + ostr.println(prefix + " error_column++;"); + ostr.println(prefix + " }"); + ostr.println(prefix + " if (!EOFSeen) {"); + ostr.println(prefix + " input_stream.backup(1);"); + ostr.println(prefix + " error_after = curPos <= 1 ? \"\" : input_stream.GetImage();"); + ostr.println(prefix + " }"); + ostr.println(prefix + " throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);"); + } + + if (hasMore) + ostr.println(prefix + " }"); + + ostr.println(" }"); + ostr.println("}"); + ostr.println(""); + } + + public static void DumpSkipActions() + { + Action act; + + ostr.println(staticString + "void SkipLexicalActions(Token matchedToken)"); + ostr.println("{"); + ostr.println(" switch(jjmatchedKind)"); + ostr.println(" {"); + + Outer: + for (int i = 0; i < maxOrdinal; i++) + { + if ((toSkip[i / 64] & (1L << (i % 64))) == 0L) + continue; + + for (;;) + { + if (((act = (Action)actions[i]) == null || + act.action_tokens == null || + act.action_tokens.size() == 0) && !canLoop[lexStates[i]]) + continue Outer; + + ostr.println(" case " + i + " :"); + + if (initMatch[lexStates[i]] == i && canLoop[lexStates[i]]) + { + ostr.println(" if (jjmatchedPos == -1)"); + ostr.println(" {"); + ostr.println(" if (jjbeenHere[" + lexStates[i] + "] &&"); + ostr.println(" jjemptyLineNo[" + lexStates[i] + "] == input_stream.getBeginLine() && "); + ostr.println(" jjemptyColNo[" + lexStates[i] + "] == input_stream.getBeginColumn())"); + ostr.println(" throw new TokenMgrError((\"Error: Bailing out of infinite loop caused by repeated empty string matches at line \" + input_stream.getBeginLine() + \", column \" + input_stream.getBeginColumn() + \".\"), TokenMgrError.LOOP_DETECTED);"); + ostr.println(" jjemptyLineNo[" + lexStates[i] + "] = input_stream.getBeginLine();"); + ostr.println(" jjemptyColNo[" + lexStates[i] + "] = input_stream.getBeginColumn();"); + ostr.println(" jjbeenHere[" + lexStates[i] + "] = true;"); + ostr.println(" }"); + } + + if ((act = (Action)actions[i]) == null || + act.action_tokens.size() == 0) + break; + + ostr.println(" if (image == null)"); + ostr.println(" image = new StringBuffer();"); + + ostr.print(" image.append"); + if (RStringLiteral.allImages[i] != null) + ostr.println("(jjstrLiteralImages[" + i + "]);"); + else + if (Options.getCSUnicodeEscape() || + Options.getUserCharStream()) + ostr.println("(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1)));"); + else + ostr.println("(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1)));"); + + printTokenSetup((Token)act.action_tokens.elementAt(0)); + ccol = 1; + + for (int j = 0; j < act.action_tokens.size(); j++) + printToken((Token)act.action_tokens.elementAt(j), ostr); + ostr.println(""); + + break; + } + + ostr.println(" break;"); + } + + ostr.println(" default :"); + ostr.println(" break;"); + ostr.println(" }"); + ostr.println("}"); + } + + public static void DumpMoreActions() + { + Action act; + + ostr.println(staticString + "void MoreLexicalActions()"); + ostr.println("{"); + ostr.println(" jjimageLen += (lengthOfMatch = jjmatchedPos + 1);"); + ostr.println(" switch(jjmatchedKind)"); + ostr.println(" {"); + + Outer: + for (int i = 0; i < maxOrdinal; i++) + { + if ((toMore[i / 64] & (1L << (i % 64))) == 0L) + continue; + + for (;;) + { + if (((act = (Action)actions[i]) == null || + act.action_tokens == null || + act.action_tokens.size() == 0) && !canLoop[lexStates[i]]) + continue Outer; + + ostr.println(" case " + i + " :"); + + if (initMatch[lexStates[i]] == i && canLoop[lexStates[i]]) + { + ostr.println(" if (jjmatchedPos == -1)"); + ostr.println(" {"); + ostr.println(" if (jjbeenHere[" + lexStates[i] + "] &&"); + ostr.println(" jjemptyLineNo[" + lexStates[i] + "] == input_stream.getBeginLine() && "); + ostr.println(" jjemptyColNo[" + lexStates[i] + "] == input_stream.getBeginColumn())"); + ostr.println(" throw new TokenMgrError((\"Error: Bailing out of infinite loop caused by repeated empty string matches at line \" + input_stream.getBeginLine() + \", column \" + input_stream.getBeginColumn() + \".\"), TokenMgrError.LOOP_DETECTED);"); + ostr.println(" jjemptyLineNo[" + lexStates[i] + "] = input_stream.getBeginLine();"); + ostr.println(" jjemptyColNo[" + lexStates[i] + "] = input_stream.getBeginColumn();"); + ostr.println(" jjbeenHere[" + lexStates[i] + "] = true;"); + ostr.println(" }"); + } + + if ((act = (Action)actions[i]) == null || + act.action_tokens.size() == 0) + { + break; + } + + ostr.println(" if (image == null)"); + ostr.println(" image = new StringBuffer();"); + ostr.print(" image.append"); + + if (RStringLiteral.allImages[i] != null) + ostr.println("(jjstrLiteralImages[" + i + "]);"); + else + if (Options.getCSUnicodeEscape() || + Options.getUserCharStream()) + ostr.println("(input_stream.GetSuffix(jjimageLen));"); + else + ostr.println("(input_stream.GetSuffix(jjimageLen));"); + + ostr.println(" jjimageLen = 0;"); + printTokenSetup((Token)act.action_tokens.elementAt(0)); + ccol = 1; + + for (int j = 0; j < act.action_tokens.size(); j++) + printToken((Token)act.action_tokens.elementAt(j), ostr); + ostr.println(""); + + break; + } + + ostr.println(" break;"); + } + + ostr.println(" default : "); + ostr.println(" break;"); + + ostr.println(" }"); + ostr.println("}"); + } + + public static void DumpTokenActions() + { + Action act; + int i; + + ostr.println(staticString + "void TokenLexicalActions(Token matchedToken)"); + ostr.println("{"); + ostr.println(" switch(jjmatchedKind)"); + ostr.println(" {"); + + Outer: + for (i = 0; i < maxOrdinal; i++) + { + if ((toToken[i / 64] & (1L << (i % 64))) == 0L) + continue; + + for (;;) + { + if (((act = (Action)actions[i]) == null || + act.action_tokens == null || + act.action_tokens.size() == 0) && !canLoop[lexStates[i]]) + continue Outer; + + ostr.println(" case " + i + " :"); + + if (initMatch[lexStates[i]] == i && canLoop[lexStates[i]]) + { + ostr.println(" if (jjmatchedPos == -1)"); + ostr.println(" {"); + ostr.println(" if (jjbeenHere[" + lexStates[i] + "] &&"); + ostr.println(" jjemptyLineNo[" + lexStates[i] + "] == input_stream.getBeginLine() && "); + ostr.println(" jjemptyColNo[" + lexStates[i] + "] == input_stream.getBeginColumn())"); + ostr.println(" throw new TokenMgrError((\"Error: Bailing out of infinite loop caused by repeated empty string matches at line \" + input_stream.getBeginLine() + \", column \" + input_stream.getBeginColumn() + \".\"), TokenMgrError.LOOP_DETECTED);"); + ostr.println(" jjemptyLineNo[" + lexStates[i] + "] = input_stream.getBeginLine();"); + ostr.println(" jjemptyColNo[" + lexStates[i] + "] = input_stream.getBeginColumn();"); + ostr.println(" jjbeenHere[" + lexStates[i] + "] = true;"); + ostr.println(" }"); + } + + if ((act = (Action)actions[i]) == null || + act.action_tokens.size() == 0) + break; + + if (i == 0) + { + ostr.println(" image = null;"); // For EOF no image is there + } + else + { + ostr.println(" if (image == null)"); + ostr.println(" image = new StringBuffer();"); + ostr.print(" image.append"); + + if (RStringLiteral.allImages[i] != null) + ostr.println("(jjstrLiteralImages[" + i + "]);"); + else + if (Options.getCSUnicodeEscape() || + Options.getUserCharStream()) + ostr.println("(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1)));"); + else + ostr.println("(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1)));"); + + } + printTokenSetup((Token)act.action_tokens.elementAt(0)); + ccol = 1; + + for (int j = 0; j < act.action_tokens.size(); j++) + printToken((Token)act.action_tokens.elementAt(j), ostr); + ostr.println(""); + + break; + } + + ostr.println(" break;"); + } + + ostr.println(" default : "); + ostr.println(" break;"); + ostr.println(" }"); + ostr.println("}"); + } + + public static void reInit() + { + ostr = null; + staticString = null; + tokMgrClassName = null; + allTpsForState = new Hashtable(); + lexStateIndex = 0; + kinds = null; + maxOrdinal = 1; + lexStateSuffix = null; + newLexState = null; + lexStates = null; + ignoreCase = null; + actions = null; + initStates = new Hashtable(); + stateSetSize = 0; + maxLexStates = 0; + lexStateName = null; + singlesToSkip = null; + toSkip = null; + toSpecial = null; + toMore = null; + toToken = null; + defaultLexState = 0; + rexprs = null; + maxLongsReqd = null; + initMatch = null; + canMatchAnyChar = null; + hasEmptyMatch = false; + canLoop = null; + stateHasActions = null; + hasLoop = false; + canReachOnMore = null; + hasNfa = null; + mixed = null; + initialState = null; + curKind = 0; + hasSkipActions = false; + hasMoreActions = false; + hasTokenActions = false; + hasSpecial = false; + hasSkip = false; + hasMore = false; + hasToken = false; + curRE = null; + } + +} diff --git a/csjavacc/parser/LookaheadCalc.java b/csjavacc/parser/LookaheadCalc.java new file mode 100644 index 0000000..7e6229f --- /dev/null +++ b/csjavacc/parser/LookaheadCalc.java @@ -0,0 +1,261 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.util.Vector; + +import csjavacc.struct.Choice; +import csjavacc.struct.Expansion; +import csjavacc.struct.Lookahead; +import csjavacc.struct.MatchInfo; +import csjavacc.struct.RegularExpression; +import csjavacc.struct.ZeroOrMore; + +public class LookaheadCalc extends CSJavaCCGlobals { + + static MatchInfo overlap(Vector v1, Vector v2) { + MatchInfo m1, m2, m3; + int size; + boolean diff; + for (int i = 0; i < v1.size(); i++) { + m1 = (MatchInfo)v1.elementAt(i); + for (int j = 0; j < v2.size(); j++) { + m2 = (MatchInfo)v2.elementAt(j); + size = m1.firstFreeLoc; m3 = m1; + if (size > m2.firstFreeLoc) { + size = m2.firstFreeLoc; m3 = m2; + } + if (size == 0) return null; + // we wish to ignore empty expansions and the CSCODE stuff here. + diff = false; + for (int k = 0; k < size; k++) { + if (m1.match[k] != m2.match[k]) { + diff = true; + break; + } + } + if (!diff) return m3; + } + } + return null; + } + + static boolean csCodeCheck(Vector v) { + for (int i = 0; i < v.size(); i++) { + if (((MatchInfo)v.elementAt(i)).firstFreeLoc == 0) { + return true; + } + } + return false; + } + + static String image(MatchInfo m) { + String ret = ""; + for (int i = 0; i < m.firstFreeLoc; i++) { + if (m.match[i] == 0) { + ret += " "; + } else { + RegularExpression re = (RegularExpression)rexps_of_tokens.get(new Integer(m.match[i])); + if (re instanceof RStringLiteral) { + ret += " \"" + add_escapes(((RStringLiteral)re).image) + "\""; + } else if (re.label != null && !re.label.equals("")) { + ret += " <" + re.label + ">"; + } else { + ret += " "; + } + } + } + if (m.firstFreeLoc == 0) { + return ""; + } else { + return ret.substring(1); + } + } + + public static void choiceCalc(Choice ch) { + int first = firstChoice(ch); + // dbl[i] and dbr[i] are vectors of size limited matches for choice i + // of ch. dbl ignores matches with semantic lookaheads (when force_la_check + // is false), while dbr ignores semantic lookahead. + Vector[] dbl = new Vector[ch.choices.size()]; + Vector[] dbr = new Vector[ch.choices.size()]; + int[] minLA = new int[ch.choices.size()-1]; + MatchInfo[] overlapInfo = new MatchInfo[ch.choices.size()-1]; + int[] other = new int[ch.choices.size()-1]; + MatchInfo m; + Vector v; + boolean overlapDetected; + for (int la = 1; la <= Options.getChoiceAmbiguityCheck(); la++) { + MatchInfo.laLimit = la; + LookaheadWalk.considerSemanticLA = !Options.getForceLaCheck(); + for (int i = first; i < ch.choices.size()-1; i++) { + LookaheadWalk.sizeLimitedMatches = new java.util.Vector(); + m = new MatchInfo(); + m.firstFreeLoc = 0; + v = new java.util.Vector(); + v.addElement(m); + LookaheadWalk.genFirstSet(v, (Expansion)ch.choices.elementAt(i)); + dbl[i] = LookaheadWalk.sizeLimitedMatches; + } + LookaheadWalk.considerSemanticLA = false; + for (int i = first+1; i < ch.choices.size(); i++) { + LookaheadWalk.sizeLimitedMatches = new java.util.Vector(); + m = new MatchInfo(); + m.firstFreeLoc = 0; + v = new java.util.Vector(); + v.addElement(m); + LookaheadWalk.genFirstSet(v, (Expansion)ch.choices.elementAt(i)); + dbr[i] = LookaheadWalk.sizeLimitedMatches; + } + if (la == 1) { + for (int i = first; i < ch.choices.size()-1; i++) { + Expansion exp = (Expansion)ch.choices.elementAt(i); + if (Semanticize.emptyExpansionExists(exp)) { + CSJavaCCErrors.warning(exp, "This choice can expand to the empty token sequence and will therefore always be taken in favor of the choices appearing later."); + break; + } else if (csCodeCheck(dbl[i])) { + CSJavaCCErrors.warning(exp, "CSCODE non-terminal will force this choice to be taken in favor of the choices appearing later."); + break; + } + } + } + overlapDetected = false; + for (int i = first; i < ch.choices.size()-1; i++) { + for (int j = i+1; j < ch.choices.size(); j++) { + if ((m = overlap(dbl[i], dbr[j])) != null) { + minLA[i] = la+1; + overlapInfo[i] = m; + other[i] = j; + overlapDetected = true; + break; + } + } + } + if (!overlapDetected) { + break; + } + } + for (int i = first; i < ch.choices.size()-1; i++) { + if (explicitLA((Expansion)ch.choices.elementAt(i)) && !Options.getForceLaCheck()) { + continue; + } + if (minLA[i] > Options.getChoiceAmbiguityCheck()) { + CSJavaCCErrors.warning("Choice conflict involving two expansions at"); + System.err.print(" line " + ((Expansion)ch.choices.elementAt(i)).line); + System.err.print(", column " + ((Expansion)ch.choices.elementAt(i)).column); + System.err.print(" and line " + ((Expansion)ch.choices.elementAt(other[i])).line); + System.err.print(", column " + ((Expansion)ch.choices.elementAt(other[i])).column); + System.err.println(" respectively."); + System.err.println(" A common prefix is: " + image(overlapInfo[i])); + System.err.println(" Consider using a lookahead of " + minLA[i] + " or more for earlier expansion."); + } else if (minLA[i] > 1) { + CSJavaCCErrors.warning("Choice conflict involving two expansions at"); + System.err.print(" line " + ((Expansion)ch.choices.elementAt(i)).line); + System.err.print(", column " + ((Expansion)ch.choices.elementAt(i)).column); + System.err.print(" and line " + ((Expansion)ch.choices.elementAt(other[i])).line); + System.err.print(", column " + ((Expansion)ch.choices.elementAt(other[i])).column); + System.err.println(" respectively."); + System.err.println(" A common prefix is: " + image(overlapInfo[i])); + System.err.println(" Consider using a lookahead of " + minLA[i] + " for earlier expansion."); + } + } + } + + static boolean explicitLA(Expansion exp) { + if (!(exp instanceof Sequence)) { + return false; + } + Sequence seq = (Sequence)exp; + Object obj = seq.units.elementAt(0); + if (!(obj instanceof Lookahead)) { + return false; + } + Lookahead la = (Lookahead)obj; + return la.isExplicit; + } + + static int firstChoice(Choice ch) { + if (Options.getForceLaCheck()) { + return 0; + } + for (int i = 0; i < ch.choices.size(); i++) { + if (!explicitLA((Expansion)ch.choices.elementAt(i))) { + return i; + } + } + return ch.choices.size(); + } + + private static String image(Expansion exp) { + if (exp instanceof OneOrMore) { + return "(...)+"; + } else if (exp instanceof ZeroOrMore) { + return "(...)*"; + } else /* if (exp instanceof ZeroOrOne) */ { + return "[...]"; + } + } + + public static void ebnfCalc(Expansion exp, Expansion nested) { + // exp is one of OneOrMore, ZeroOrMore, ZeroOrOne + MatchInfo m, m1 = null; + Vector v, first, follow; + int la; + for (la = 1; la <= Options.getOtherAmbiguityCheck(); la++) { + MatchInfo.laLimit = la; + LookaheadWalk.sizeLimitedMatches = new java.util.Vector(); + m = new MatchInfo(); + m.firstFreeLoc = 0; + v = new java.util.Vector(); + v.addElement(m); + LookaheadWalk.considerSemanticLA = !Options.getForceLaCheck(); + LookaheadWalk.genFirstSet(v, nested); + first = LookaheadWalk.sizeLimitedMatches; + LookaheadWalk.sizeLimitedMatches = new java.util.Vector(); + LookaheadWalk.considerSemanticLA = false; + LookaheadWalk.genFollowSet(v, exp, Expansion.nextGenerationIndex++); + follow = LookaheadWalk.sizeLimitedMatches; + if (la == 1) { + if (csCodeCheck(first)) { + CSJavaCCErrors.warning(nested, "CSCODE non-terminal within " + image(exp) + " construct will force this construct to be entered in favor of expansions occurring after construct."); + } + } + if ((m = overlap(first, follow)) == null) { + break; + } + m1 = m; + } + if (la > Options.getOtherAmbiguityCheck()) { + CSJavaCCErrors.warning("Choice conflict in " + image(exp) + " construct at line " + exp.line + ", column " + exp.column + "."); + System.err.println(" Expansion nested within construct and expansion following construct"); + System.err.println(" have common prefixes, one of which is: " + image(m1)); + System.err.println(" Consider using a lookahead of " + la + " or more for nested expansion."); + } else if (la > 1) { + CSJavaCCErrors.warning("Choice conflict in " + image(exp) + " construct at line " + exp.line + ", column " + exp.column + "."); + System.err.println(" Expansion nested within construct and expansion following construct"); + System.err.println(" have common prefixes, one of which is: " + image(m1)); + System.err.println(" Consider using a lookahead of " + la + " for nested expansion."); + } + } + +} diff --git a/csjavacc/parser/LookaheadWalk.java b/csjavacc/parser/LookaheadWalk.java new file mode 100644 index 0000000..cec1ec6 --- /dev/null +++ b/csjavacc/parser/LookaheadWalk.java @@ -0,0 +1,217 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.util.Vector; + +import csjavacc.struct.Choice; +import csjavacc.struct.Expansion; +import csjavacc.struct.CSCodeProduction; +import csjavacc.struct.Lookahead; +import csjavacc.struct.MatchInfo; +import csjavacc.struct.NonTerminal; +import csjavacc.struct.RegularExpression; +import csjavacc.struct.TryBlock; +import csjavacc.struct.ZeroOrMore; +import csjavacc.struct.ZeroOrOne; + +public class LookaheadWalk { + + public static boolean considerSemanticLA; + + public static Vector sizeLimitedMatches; + + public static void vectorAppend(Vector vToAppendTo, Vector vToAppend) { + for (int i = 0; i < vToAppend.size(); i++) { + vToAppendTo.addElement(vToAppend.elementAt(i)); + } + } + + public static Vector genFirstSet(Vector partialMatches, Expansion exp) { + if (exp instanceof RegularExpression) { + Vector retval = new Vector(); + for (int i = 0; i < partialMatches.size(); i++) { + MatchInfo m = (MatchInfo)partialMatches.elementAt(i); + MatchInfo mnew = new MatchInfo(); + for (int j = 0; j < m.firstFreeLoc; j++) { + mnew.match[j] = m.match[j]; + } + mnew.firstFreeLoc = m.firstFreeLoc; + mnew.match[mnew.firstFreeLoc++] = ((RegularExpression)exp).ordinal; + if (mnew.firstFreeLoc == MatchInfo.laLimit) { + sizeLimitedMatches.addElement(mnew); + } else { + retval.addElement(mnew); + } + } + return retval; + } else if (exp instanceof NonTerminal) { + NormalProduction prod = ((NonTerminal)exp).prod; + if (prod instanceof CSCodeProduction) { + return new Vector(); + } else { + return genFirstSet(partialMatches, prod.expansion); + } + } else if (exp instanceof Choice) { + Vector retval = new Vector(); + Choice ch = (Choice)exp; + for (int i = 0; i < ch.choices.size(); i++) { + Vector v = genFirstSet(partialMatches, (Expansion)ch.choices.elementAt(i)); + vectorAppend(retval, v); + } + return retval; + } else if (exp instanceof Sequence) { + Vector v = partialMatches; + Sequence seq = (Sequence)exp; + for (int i = 0; i < seq.units.size(); i++) { + v = genFirstSet(v, (Expansion)seq.units.elementAt(i)); + if (v.size() == 0) break; + } + return v; + } else if (exp instanceof OneOrMore) { + Vector retval = new Vector(); + Vector v = partialMatches; + OneOrMore om = (OneOrMore)exp; + while (true) { + v = genFirstSet(v, om.expansion); + if (v.size() == 0) break; + vectorAppend(retval, v); + } + return retval; + } else if (exp instanceof ZeroOrMore) { + Vector retval = new Vector(); + vectorAppend(retval, partialMatches); + Vector v = partialMatches; + ZeroOrMore zm = (ZeroOrMore)exp; + while (true) { + v = genFirstSet(v, zm.expansion); + if (v.size() == 0) break; + vectorAppend(retval, v); + } + return retval; + } else if (exp instanceof ZeroOrOne) { + Vector retval = new Vector(); + vectorAppend(retval, partialMatches); + vectorAppend(retval, genFirstSet(partialMatches, ((ZeroOrOne)exp).expansion)); + return retval; + } else if (exp instanceof TryBlock) { + return genFirstSet(partialMatches, ((TryBlock)exp).exp); + } else if (considerSemanticLA && + exp instanceof Lookahead && + ((Lookahead)exp).action_tokens.size() != 0 + ) { + return new Vector(); + } else { + Vector retval = new Vector(); + vectorAppend(retval, partialMatches); + return retval; + } + } + + public static void vectorSplit(Vector toSplit, Vector mask, Vector partInMask, Vector rest) { + OuterLoop: + for (int i = 0; i < toSplit.size(); i++) { + for (int j = 0; j < mask.size(); j++) { + if (toSplit.elementAt(i) == mask.elementAt(j)) { + partInMask.addElement(toSplit.elementAt(i)); + continue OuterLoop; + } + } + rest.addElement(toSplit.elementAt(i)); + } + } + + public static Vector genFollowSet(Vector partialMatches, Expansion exp, long generation) { + if (exp.myGeneration == generation) { + return new Vector(); + } +// System.err.println("*** Parent: " + exp.parent); + exp.myGeneration = generation; + if (exp.parent == null) { + Vector retval = new Vector(); + vectorAppend(retval, partialMatches); + return retval; + } else if (exp.parent instanceof NormalProduction) { + Vector parents = ((NormalProduction)exp.parent).parents; + Vector retval = new Vector(); +// System.err.println("1; gen: " + generation + "; exp: " + exp); + for (int i = 0; i < parents.size(); i++) { + Vector v = genFollowSet(partialMatches, (Expansion)parents.elementAt(i), generation); + vectorAppend(retval, v); + } + return retval; + } else if (exp.parent instanceof Sequence) { + Sequence seq = (Sequence)exp.parent; + Vector v = partialMatches; + for (int i = exp.ordinal+1; i < seq.units.size(); i++) { + v = genFirstSet(v, (Expansion)seq.units.elementAt(i)); + if (v.size() == 0) return v; + } + Vector v1 = new Vector(); + Vector v2 = new Vector(); + vectorSplit(v, partialMatches, v1, v2); + if (v1.size() != 0) { +// System.err.println("2; gen: " + generation + "; exp: " + exp); + v1 = genFollowSet(v1, seq, generation); + } + if (v2.size() != 0) { +// System.err.println("3; gen: " + generation + "; exp: " + exp); + v2 = genFollowSet(v2, seq, Expansion.nextGenerationIndex++); + } + vectorAppend(v2, v1); + return v2; + } else if (exp.parent instanceof OneOrMore || exp.parent instanceof ZeroOrMore) { + Vector moreMatches = new Vector(); + vectorAppend(moreMatches, partialMatches); + Vector v = partialMatches; + while (true) { + v = genFirstSet(v, exp); + if (v.size() == 0) break; + vectorAppend(moreMatches, v); + } + Vector v1 = new Vector(); + Vector v2 = new Vector(); + vectorSplit(moreMatches, partialMatches, v1, v2); + if (v1.size() != 0) { +// System.err.println("4; gen: " + generation + "; exp: " + exp); + v1 = genFollowSet(v1, (Expansion)exp.parent, generation); + } + if (v2.size() != 0) { +// System.err.println("5; gen: " + generation + "; exp: " + exp); + v2 = genFollowSet(v2, (Expansion)exp.parent, Expansion.nextGenerationIndex++); + } + vectorAppend(v2, v1); + return v2; + } else { +// System.err.println("6; gen: " + generation + "; exp: " + exp); + return genFollowSet(partialMatches, (Expansion)exp.parent, generation); + } + } + + public static void reInit() + { + considerSemanticLA = false; + sizeLimitedMatches = null; + } + +} diff --git a/csjavacc/parser/Main.java b/csjavacc/parser/Main.java new file mode 100644 index 0000000..6c0d3f7 --- /dev/null +++ b/csjavacc/parser/Main.java @@ -0,0 +1,207 @@ +/* + * 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. + */ + +package csjavacc.parser; + + +public class Main { + + static void help_message() { + System.err.println("Usage:"); + System.err.println(" csjavacc option-settings inputfile"); + System.err.println(""); + System.err.println("\"option-settings\" is a sequence of settings separated by spaces."); + System.err.println("Each option setting must be of one of the following forms:"); + System.err.println(""); + System.err.println(" -optionname=value (e.g., -STATIC=false)"); + System.err.println(" -optionname:value (e.g., -STATIC:false)"); + System.err.println(" -optionname (equivalent to -optionname=true. e.g., -STATIC)"); + System.err.println(" -NOoptionname (equivalent to -optionname=false. e.g., -NOSTATIC)"); + System.err.println(""); + System.err.println("Option settings are not case-sensitive, so one can say \"-nOsTaTiC\" instead"); + System.err.println("of \"-NOSTATIC\". Option values must be appropriate for the corresponding"); + System.err.println("option, and must be either an integer, a bool, or a string value."); + System.err.println(""); + System.err.println("The integer valued options are:"); + System.err.println(""); + System.err.println(" LOOKAHEAD (default 1)"); + System.err.println(" CHOICE_AMBIGUITY_CHECK (default 2)"); + System.err.println(" OTHER_AMBIGUITY_CHECK (default 1)"); + System.err.println(""); + System.err.println("The bool valued options are:"); + System.err.println(""); + System.err.println(" STATIC (default true)"); + System.err.println(" DEBUG_PARSER (default false)"); + System.err.println(" DEBUG_LOOKAHEAD (default false)"); + System.err.println(" DEBUG_TOKEN_MANAGER (default false)"); + System.err.println(" OPTIMIZE_TOKEN_MANAGER (default true)"); + System.err.println(" ERROR_REPORTING (default true)"); + System.err.println(" CS_UNICODE_ESCAPE (default false)"); + System.err.println(" UNICODE_INPUT (default false)"); + System.err.println(" IGNORE_CASE (default false)"); + System.err.println(" COMMON_TOKEN_ACTION (default false)"); + System.err.println(" USER_TOKEN_MANAGER (default false)"); + System.err.println(" USER_CHAR_STREAM (default false)"); + System.err.println(" BUILD_PARSER (default true)"); + System.err.println(" BUILD_TOKEN_MANAGER (default true)"); + System.err.println(" TOKEN_MANAGER_USES_PARSER (default false)"); + System.err.println(" SANITY_CHECK (default true)"); + System.err.println(" FORCE_LA_CHECK (default false)"); + System.err.println(" CACHE_TOKENS (default false)"); + System.err.println(" KEEP_LINE_COLUMN (default true)"); + System.err.println(""); + System.err.println("The string valued options are:"); + System.err.println(""); + System.err.println(" OUTPUT_DIRECTORY (default Current Directory)"); + System.err.println(""); + System.err.println("EXAMPLE:"); + System.err.println(" csjavacc -STATIC=false -LOOKAHEAD:2 -debug_parser mygrammar.jj"); + System.err.println(""); + } + + /** + * A main program that exercises the parser. + */ + public static void main(String args[]) throws Exception { + int errorcode = mainProgram(args); + System.exit(errorcode); + } + + /** + * The method to call to exercise the parser from other Java programs. + * It returns an error code. See how the main program above uses + * this method. + */ + public static int mainProgram(String args[]) throws Exception { + + // Initialize all static state + reInitAll(); + + CSJavaCCGlobals.bannerLine("Parser Generator", ""); + + CSJavaCCParser parser = null; + if (args.length == 0) { + System.err.println(""); + help_message(); + return 1; + } else { + System.err.println("(type \"csjavacc\" with no arguments for help)"); + } + + if (Options.isOption(args[args.length-1])) { + System.err.println("Last argument \"" + args[args.length-1] + "\" is not a filename."); + return 1; + } + for (int arg = 0; arg < args.length-1; arg++) { + if (!Options.isOption(args[arg])) { + System.err.println("Argument \"" + args[arg] + "\" must be an option setting."); + return 1; + } + Options.setCmdLineOption(args[arg]); + } + + try { + java.io.File fp = new java.io.File(args[args.length-1]); + if (!fp.exists()) { + System.err.println("File " + args[args.length-1] + " not found."); + return 1; + } + if (fp.isDirectory()) { + System.err.println(args[args.length-1] + " is a directory. Please use a valid file name."); + return 1; + } + parser = new CSJavaCCParser(new java.io.FileReader(args[args.length-1])); + } catch (NullPointerException ne) { // Should never happen + } catch (SecurityException se) { + System.err.println("Security voilation while trying to open " + args[args.length-1]); + return 1; + } catch (java.io.FileNotFoundException e) { + System.err.println("File " + args[args.length-1] + " not found."); + return 1; + } + + try { + System.err.println("Reading from file " + args[args.length-1] + " . . ."); + CSJavaCCGlobals.fileName = CSJavaCCGlobals.origFileName = args[args.length-1]; + CSJavaCCGlobals.jjtreeGenerated = CSJavaCCGlobals.isGeneratedBy("JJTree", args[args.length-1]); + CSJavaCCGlobals.jjcovGenerated = CSJavaCCGlobals.isGeneratedBy("JJCov", args[args.length-1]); + CSJavaCCGlobals.toolNames = CSJavaCCGlobals.getToolNames(args[args.length-1]); + parser.csjavacc_input(); + CSJavaCCGlobals.createOutputDir(Options.getOutputDirectory()); + + if (Options.getUnicodeInput()) + { + NfaState.unicodeWarningGiven = true; + System.err.println("Note: UNICODE_INPUT option is specified. " + + "Please make sure you create the parser/lexer using a Reader with the correct character encoding."); + } + + Semanticize.start(); + ParseGen.start(); + LexGen.start(); + OtherFilesGen.start(); + + if ((CSJavaCCErrors.get_error_count() == 0) && (Options.getBuildParser() || Options.getBuildTokenManager())) { + if (CSJavaCCErrors.get_warning_count() == 0) { + System.err.println("Parser generated successfully."); + } else { + System.err.println("Parser generated with 0 errors and " + + CSJavaCCErrors.get_warning_count() + " warnings."); + } + return 0; + } else { + System.err.println("Detected " + CSJavaCCErrors.get_error_count() + " errors and " + + CSJavaCCErrors.get_warning_count() + " warnings."); + return (CSJavaCCErrors.get_error_count()==0)?0:1; + } + } catch (MetaParseException e) { + System.err.println("Detected " + CSJavaCCErrors.get_error_count() + " errors and " + + CSJavaCCErrors.get_warning_count() + " warnings."); + return 1; + } catch (ParseException e) { + System.err.println(e.toString()); + System.err.println("Detected " + (CSJavaCCErrors.get_error_count()+1) + " errors and " + + CSJavaCCErrors.get_warning_count() + " warnings."); + return 1; + } + } + + public static void reInitAll() + { + csjavacc.struct.Expansion.reInit(); + csjavacc.parser.CSJavaCCErrors.reInit(); + csjavacc.parser.CSJavaCCGlobals.reInit(); + Options.init(); + csjavacc.parser.CSJavaCCParserInternals.reInit(); + csjavacc.parser.RStringLiteral.reInit(); + csjavacc.parser.CSJavaFiles.reInit(); + csjavacc.parser.LexGen.reInit(); + csjavacc.parser.NfaState.reInit(); + csjavacc.struct.MatchInfo.reInit(); + csjavacc.parser.LookaheadWalk.reInit(); + csjavacc.parser.Semanticize.reInit(); + csjavacc.parser.ParseGen.reInit(); + csjavacc.parser.OtherFilesGen.reInit(); + csjavacc.parser.ParseEngine.reInit(); + } + +} diff --git a/csjavacc/parser/MetaParseException.java b/csjavacc/parser/MetaParseException.java new file mode 100644 index 0000000..e088211 --- /dev/null +++ b/csjavacc/parser/MetaParseException.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package csjavacc.parser; + +public class MetaParseException extends ParseException { +} diff --git a/csjavacc/parser/NfaState.java b/csjavacc/parser/NfaState.java new file mode 100644 index 0000000..a9a4491 --- /dev/null +++ b/csjavacc/parser/NfaState.java @@ -0,0 +1,2967 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.util.*; + + +public class NfaState +{ + public static boolean unicodeWarningGiven = false; + public static int generatedStates = 0; + static int idCnt = 0; + static int lohiByteCnt; + static int dummyStateIndex = -1; + static boolean done; + static boolean mark[]; + static boolean stateDone[]; + static boolean nonAsciiIntersections[][] = new boolean[20][20]; + + static Vector allStates = new Vector(); + static Vector indexedAllStates = new Vector(); + static Vector nonAsciiTableForMethod = new Vector(); + static Hashtable equivStatesTable = new Hashtable(); + static Hashtable allNextStates = new Hashtable(); + static Hashtable lohiByteTab = new Hashtable(); + static Hashtable stateNameForComposite = new Hashtable(); + static Hashtable compositeStateTable = new Hashtable(); + static Hashtable stateBlockTable = new Hashtable(); + static Hashtable stateSetsToFix = new Hashtable(); + + public static void ReInit() + { + generatedStates = 0; + idCnt = 0; + dummyStateIndex = -1; + done = false; + mark = null; + stateDone = null; + + allStates.removeAllElements(); + indexedAllStates.removeAllElements(); + equivStatesTable.clear(); + allNextStates.clear(); + compositeStateTable.clear(); + stateBlockTable.clear(); + stateNameForComposite.clear(); + stateSetsToFix.clear(); + } + + public long[] asciiMoves = new long[2]; + public char[] charMoves = null; + public char[] rangeMoves = null; + public NfaState next = null; + public NfaState stateForCase; + public Vector epsilonMoves = new Vector(); + public String epsilonMovesString; + public NfaState[] epsilonMoveArray; + + public int id; + public int stateName = -1; + public int kind = Integer.MAX_VALUE; + public int lookingFor; + public int usefulEpsilonMoves = 0; + public int inNextOf; + private int lexState; + public int nonAsciiMethod = -1; + public int kindToPrint = Integer.MAX_VALUE; + public boolean dummy = false; + public boolean isComposite = false; + public int[] compositeStates = null; + public boolean isFinal = false; + public Vector loByteVec; + public int[] nonAsciiMoveIndices; + public int round = 0; + public int onlyChar = 0; + public char matchSingleChar; + + public NfaState() + { + id = idCnt++; + allStates.addElement(this); + lexState = LexGen.lexStateIndex; + lookingFor = LexGen.curKind; + } + + public NfaState CreateClone() + { + NfaState retVal = new NfaState(); + + retVal.isFinal = isFinal; + retVal.kind = kind; + retVal.lookingFor = lookingFor; + retVal.lexState = lexState; + retVal.inNextOf = inNextOf; + + retVal.MergeMoves(this); + + return retVal; + } + + public static void InsertInOrder(Vector v, NfaState s) + { + int j; + + for (j = 0; j < v.size(); j++) + if (((NfaState)v.elementAt(j)).id > s.id) + break; + else if (((NfaState)v.elementAt(j)).id == s.id) + return; + + v.insertElementAt(s, j); + } + + private static char[] ExpandCharArr(char[] oldArr, int incr) + { + char[] ret = new char[oldArr.length + incr]; + System.arraycopy(oldArr, 0, ret, 0, oldArr.length); + return ret; + } + + public void AddMove(NfaState newState) + { + if (!epsilonMoves.contains(newState)) + InsertInOrder(epsilonMoves, newState); + } + + private final void AddASCIIMove(char c) + { + asciiMoves[c / 64] |= (1L << (c % 64)); + } + + public void AddChar(char c) + { + onlyChar++; + matchSingleChar = c; + int i; + char temp; + char temp1; + + if ((int)c < 128) // ASCII char + { + AddASCIIMove(c); + return; + } + + if (charMoves == null) + charMoves = new char[10]; + + int len = charMoves.length; + + if (charMoves[len - 1] != 0) + { + charMoves = ExpandCharArr(charMoves, 10); + len += 10; + } + + for (i = 0; i < len; i++) + if (charMoves[i] == 0 || charMoves[i] > c) + break; + + if (!unicodeWarningGiven && c > 0xff && + !Options.getCSUnicodeEscape() && + !Options.getUserCharStream()) + { + unicodeWarningGiven = true; + CSJavaCCErrors.warning(LexGen.curRE, "Non-ASCII characters used in regular expression.\n" + + "Please make sure you use the correct Reader when you create the parser that can handle your character set."); + } + + temp = charMoves[i]; + charMoves[i] = c; + + for (i++; i < len; i++) + { + if (temp == 0) + break; + + temp1 = charMoves[i]; + charMoves[i] = temp; + temp = temp1; + } + } + + public void AddRange(char left, char right) + { + onlyChar = 2; + int i; + char tempLeft1, tempLeft2, tempRight1, tempRight2; + + if (left < 128) + { + if (right < 128) + { + for (; left <= right; left++) + AddASCIIMove(left); + + return; + } + + for (; left < 128; left++) + AddASCIIMove(left); + } + + if (!unicodeWarningGiven && (left > 0xff || right > 0xff) && + !Options.getCSUnicodeEscape() && + !Options.getUserCharStream()) + { + unicodeWarningGiven = true; + CSJavaCCErrors.warning(LexGen.curRE, "Non-ASCII characters used in regular expression.\n" + + "Please make sure you use the correct Reader when you create the parser that can handle your character set."); + } + + if (rangeMoves == null) + rangeMoves = new char[20]; + + int len = rangeMoves.length; + + if (rangeMoves[len - 1] != 0) + { + rangeMoves = ExpandCharArr(rangeMoves, 20); + len += 20; + } + + for (i = 0; i < len; i += 2) + if (rangeMoves[i] == 0 || + (rangeMoves[i] > left) || + ((rangeMoves[i] == left) && (rangeMoves[i + 1] > right))) + break; + + tempLeft1 = rangeMoves[i]; + tempRight1 = rangeMoves[i + 1]; + rangeMoves[i] = left; + rangeMoves[i + 1] = right; + + for (i += 2; i < len; i += 2) + { + if (tempLeft1 == 0) + break; + + tempLeft2 = rangeMoves[i]; + tempRight2 = rangeMoves[i + 1]; + rangeMoves[i] = tempLeft1; + rangeMoves[i + 1] = tempRight1; + tempLeft1 = tempLeft2; + tempRight1 = tempRight2; + } + } + + // From hereon down all the functions are used for code generation + + private static boolean EqualCharArr(char[] arr1, char[] arr2) + { + if (arr1 == arr2) + return true; + + if (arr1 != null && + arr2 != null && + arr1.length == arr2.length) + { + for (int i = arr1.length; i-- > 0;) + if (arr1[i] != arr2[i]) + return false; + + return true; + } + + return false; + } + + private boolean closureDone = false; + + /** This function computes the closure and also updates the kind so that + * any time there is a move to this state, it can go on epsilon to a + * new state in the epsilon moves that might have a lower kind of token + * number for the same length. + */ + + private void EpsilonClosure() + { + int i = 0; + + if (closureDone || mark[id]) + return; + + mark[id] = true; + + // Recursively do closure + for (i = 0; i < epsilonMoves.size(); i++) + ((NfaState)epsilonMoves.elementAt(i)).EpsilonClosure(); + + Enumeration e = epsilonMoves.elements(); + + while (e.hasMoreElements()) + { + NfaState tmp = (NfaState)e.nextElement(); + + for (i = 0; i < tmp.epsilonMoves.size(); i++) + { + NfaState tmp1 = (NfaState)tmp.epsilonMoves.elementAt(i); + if (tmp1.UsefulState() && !epsilonMoves.contains(tmp1)) + { + InsertInOrder(epsilonMoves, tmp1); + done = false; + } + } + + if (kind > tmp.kind) + kind = tmp.kind; + } + + if (HasTransitions() && !epsilonMoves.contains(this)) + InsertInOrder(epsilonMoves, this); + } + + private boolean UsefulState() + { + return isFinal || HasTransitions(); + } + + public boolean HasTransitions() + { + return (asciiMoves[0] != 0L || asciiMoves[1] != 0L || + (charMoves != null && charMoves[0] != 0) || + (rangeMoves != null && rangeMoves[0] != 0)); + } + + public void MergeMoves(NfaState other) + { + // Warning : This function does not merge epsilon moves + if (asciiMoves == other.asciiMoves) + { + CSJavaCCErrors.semantic_error("Bug in JavaCC : Please send " + + "a report along with the input that caused this. Thank you."); + throw new Error(); + } + + asciiMoves[0] = asciiMoves[0] | other.asciiMoves[0]; + asciiMoves[1] = asciiMoves[1] | other.asciiMoves[1]; + + if (other.charMoves != null) + { + if (charMoves == null) + charMoves = other.charMoves; + else + { + char[] tmpCharMoves = new char[charMoves.length + + other.charMoves.length]; + System.arraycopy(charMoves, 0, tmpCharMoves, 0, charMoves.length); + charMoves = tmpCharMoves; + + for (int i = 0; i < other.charMoves.length; i++) + AddChar(other.charMoves[i]); + } + } + + if (other.rangeMoves != null) + { + if (rangeMoves == null) + rangeMoves = other.rangeMoves; + else + { + char[] tmpRangeMoves = new char[rangeMoves.length + + other.rangeMoves.length]; + System.arraycopy(rangeMoves, 0, tmpRangeMoves, + 0, rangeMoves.length); + rangeMoves = tmpRangeMoves; + for (int i = 0; i < other.rangeMoves.length; i += 2) + AddRange(other.rangeMoves[i], other.rangeMoves[i + 1]); + } + } + + if (other.kind < kind) + kind = other.kind; + + if (other.kindToPrint < kindToPrint) + kindToPrint = other.kindToPrint; + + isFinal |= other.isFinal; + } + + public NfaState CreateEquivState(Vector states) + { + NfaState newState = ((NfaState)states.elementAt(0)).CreateClone(); + + newState.next = new NfaState(); + + InsertInOrder(newState.next.epsilonMoves, + ((NfaState)states.elementAt(0)).next); + + for (int i = 1; i < states.size(); i++) + { + NfaState tmp2 = ((NfaState)states.elementAt(i)); + + if (tmp2.kind < newState.kind) + newState.kind = tmp2.kind; + + newState.isFinal |= tmp2.isFinal; + + InsertInOrder(newState.next.epsilonMoves, tmp2.next); + } + + return newState; + } + + private NfaState GetEquivalentRunTimeState() + { + Outer : + for (int i = allStates.size(); i-- > 0;) + { + NfaState other = (NfaState)allStates.elementAt(i); + + if (this != other && other.stateName != -1 && + kindToPrint == other.kindToPrint && + asciiMoves[0] == other.asciiMoves[0] && + asciiMoves[1] == other.asciiMoves[1] && + EqualCharArr(charMoves, other.charMoves) && + EqualCharArr(rangeMoves, other.rangeMoves)) + { + if (next == other.next) + return other; + else if (next != null && other.next != null) + { + if (next.epsilonMoves.size() == other.next.epsilonMoves.size()) + { + for (int j = 0; j < next.epsilonMoves.size(); j++) + if (next.epsilonMoves.elementAt(j) != + other.next.epsilonMoves.elementAt(j)) + continue Outer; + + return other; + } + } + } + } + + return null; + } + + // generates code (without outputting it) and returns the name used. + public void GenerateCode() + { + if (stateName != -1) + return; + + if (next != null) + { + next.GenerateCode(); + if (next.kind != Integer.MAX_VALUE) + kindToPrint = next.kind; + } + + if (stateName == -1 && HasTransitions()) + { + NfaState tmp = GetEquivalentRunTimeState(); + + if (tmp != null) + { + stateName = tmp.stateName; +//???? + //tmp.inNextOf += inNextOf; +//???? + dummy = true; + return; + } + + stateName = generatedStates++; + indexedAllStates.addElement(this); + GenerateNextStatesCode(); + } + } + + public static void ComputeClosures() + { + for (int i = allStates.size(); i-- > 0; ) + { + NfaState tmp = (NfaState)allStates.elementAt(i); + + if (!tmp.closureDone) + tmp.OptimizeEpsilonMoves(true); + } + + for (int i = 0; i < allStates.size(); i++) + { + NfaState tmp = (NfaState)allStates.elementAt(i); + + if (!tmp.closureDone) + tmp.OptimizeEpsilonMoves(false); + } + + for (int i = 0; i < allStates.size(); i++) + { + NfaState tmp = (NfaState)allStates.elementAt(i); + tmp.epsilonMoveArray = new NfaState[tmp.epsilonMoves.size()]; + tmp.epsilonMoves.copyInto(tmp.epsilonMoveArray); + } + } + + void OptimizeEpsilonMoves(boolean optReqd) + { + int i; + + // First do epsilon closure + done = false; + while (!done) + { + if (mark == null || mark.length < allStates.size()) + mark = new boolean[allStates.size()]; + + for (i = allStates.size(); i-- > 0;) + mark[i] = false; + + done = true; + EpsilonClosure(); + } + + for (i = allStates.size(); i-- > 0;) + ((NfaState)allStates.elementAt(i)).closureDone = + mark[((NfaState)allStates.elementAt(i)).id]; + + // Warning : The following piece of code is just an optimization. + // in case of trouble, just remove this piece. + + boolean sometingOptimized = true; + + NfaState newState = null; + NfaState tmp1, tmp2; + int j; + Vector equivStates = null; + + while (sometingOptimized) + { + sometingOptimized = false; + for (i = 0; optReqd && i < epsilonMoves.size(); i++) + { + if ((tmp1 = (NfaState)epsilonMoves.elementAt(i)).HasTransitions()) + { + for (j = i + 1; j < epsilonMoves.size(); j++) + { + if ((tmp2 = (NfaState)epsilonMoves.elementAt(j)). + HasTransitions() && + (tmp1.asciiMoves[0] == tmp2.asciiMoves[0] && + tmp1.asciiMoves[1] == tmp2.asciiMoves[1] && + EqualCharArr(tmp1.charMoves, tmp2.charMoves) && + EqualCharArr(tmp1.rangeMoves, tmp2.rangeMoves))) + { + if (equivStates == null) + { + equivStates = new Vector(); + equivStates.addElement(tmp1); + } + + InsertInOrder(equivStates, tmp2); + epsilonMoves.removeElementAt(j--); + } + } + } + + if (equivStates != null) + { + sometingOptimized = true; + String tmp = ""; + for (int l = 0; l < equivStates.size(); l++) + tmp += String.valueOf( + ((NfaState)equivStates.elementAt(l)).id) + ", "; + + if ((newState = (NfaState)equivStatesTable.get(tmp)) == null) + { + newState = CreateEquivState(equivStates); + equivStatesTable.put(tmp, newState); + } + + epsilonMoves.removeElementAt(i--); + epsilonMoves.addElement(newState); + equivStates = null; + newState = null; + } + } + + for (i = 0; i < epsilonMoves.size(); i++) + { + //if ((tmp1 = (NfaState)epsilonMoves.elementAt(i)).next == null) + //continue; + tmp1 = (NfaState)epsilonMoves.elementAt(i); + + for (j = i + 1; j < epsilonMoves.size(); j++) + { + tmp2 = (NfaState)epsilonMoves.elementAt(j); + + if (tmp1.next == tmp2.next) + { + if (newState == null) + { + newState = tmp1.CreateClone(); + newState.next = tmp1.next; + sometingOptimized = true; + } + + newState.MergeMoves(tmp2); + epsilonMoves.removeElementAt(j--); + } + } + + if (newState != null) + { + epsilonMoves.removeElementAt(i--); + epsilonMoves.addElement(newState); + newState = null; + } + } + } + + // End Warning + + // Generate an array of states for epsilon moves (not vector) + if (epsilonMoves.size() > 0) + { + for (i = 0; i < epsilonMoves.size(); i++) + // Since we are doing a closure, just epsilon moves are unncessary + if (((NfaState)epsilonMoves.elementAt(i)).HasTransitions()) + usefulEpsilonMoves++; + else + epsilonMoves.removeElementAt(i--); + } + } + + public void GenerateNextStatesCode() + { + if (next.usefulEpsilonMoves > 0) + next.GetEpsilonMovesString(); + } + + public String GetEpsilonMovesString() + { + int[] stateNames = new int[usefulEpsilonMoves]; + int cnt = 0; + + if (epsilonMovesString != null) + return epsilonMovesString; + + if (usefulEpsilonMoves > 0) + { + NfaState tempState; + epsilonMovesString = "{ "; + for (int i = 0; i < epsilonMoves.size(); i++) + { + if ((tempState = (NfaState)epsilonMoves.elementAt(i)). + HasTransitions()) + { + if (tempState.stateName == -1) + tempState.GenerateCode(); + + ((NfaState)indexedAllStates.elementAt(tempState.stateName)).inNextOf++; + stateNames[cnt] = tempState.stateName; + epsilonMovesString += tempState.stateName + ", "; + if (cnt++ > 0 && cnt % 16 == 0) + epsilonMovesString += "\n"; + } + } + + epsilonMovesString += "};"; + } + + usefulEpsilonMoves = cnt; + if (epsilonMovesString != null && + allNextStates.get(epsilonMovesString) == null) + { + int[] statesToPut = new int[usefulEpsilonMoves]; + + System.arraycopy(stateNames, 0, statesToPut, 0, cnt); + allNextStates.put(epsilonMovesString, statesToPut); + } + + return epsilonMovesString; + } + + public static boolean CanStartNfaUsingAscii(char c) + { + if (c >= 128) + throw new Error("JavaCC Bug: Please send mail to sankar@cs.stanford.edu"); + + String s = LexGen.initialState.GetEpsilonMovesString(); + + if (s == null || s.equals("null;")) + return false; + + int[] states = (int[])allNextStates.get(s); + + for (int i = 0; i < states.length; i++) + { + NfaState tmp = (NfaState)indexedAllStates.elementAt(states[i]); + + if ((tmp.asciiMoves[c / 64 ] & (1L << c % 64)) != 0L) + return true; + } + + return false; + } + + public final boolean CanMoveUsingChar(char c) + { + int i; + + if (onlyChar == 1) + return c == matchSingleChar; + + if (c < 128) + return ((asciiMoves[c / 64 ] & (1L << c % 64)) != 0L); + + // Just check directly if there is a move for this char + if (charMoves != null && charMoves[0] != 0) + { + for (i = 0; i < charMoves.length; i++) + { + if (c == charMoves[i]) + return true; + else if (c < charMoves[i] || charMoves[i] == 0) + break; + } + } + + + // For ranges, iterate thru the table to see if the current char + // is in some range + if (rangeMoves != null && rangeMoves[0] != 0) + for (i = 0; i < rangeMoves.length; i += 2) + if (c >= rangeMoves[i] && c <= rangeMoves[i + 1]) + return true; + else if (c < rangeMoves[i] || rangeMoves[i] == 0) + break; + + //return (nextForNegatedList != null); + return false; + } + + public int getFirstValidPos(String s, int i, int len) + { + if (onlyChar == 1) + { + char c = matchSingleChar; + while (c != s.charAt(i) && ++i < len); + return i; + } + + do + { + if (CanMoveUsingChar(s.charAt(i))) + return i; + } while (++i < len); + + return i; + } + + public int MoveFrom(char c, Vector newStates) + { + if (CanMoveUsingChar(c)) + { + for (int i = next.epsilonMoves.size(); i-- > 0;) + InsertInOrder(newStates, (NfaState)next.epsilonMoves.elementAt(i)); + + return kindToPrint; + } + + return Integer.MAX_VALUE; + } + + public static int MoveFromSet(char c, Vector states, Vector newStates) + { + int tmp; + int retVal = Integer.MAX_VALUE; + + for (int i = states.size(); i-- > 0;) + if (retVal > + (tmp = ((NfaState)states.elementAt(i)).MoveFrom(c, newStates))) + retVal = tmp; + + return retVal; + } + + public static int moveFromSetForRegEx(char c, NfaState[] states, NfaState[] newStates, int round) + { + int start = 0; + int sz = states.length; + + for (int i = 0; i < sz; i++) + { + NfaState tmp1, tmp2; + + if ((tmp1 = states[i]) == null) + break; + + if (tmp1.CanMoveUsingChar(c)) + { + if (tmp1.kindToPrint != Integer.MAX_VALUE) + { + newStates[start] = null; + return 1; + } + + NfaState[] v = tmp1.next.epsilonMoveArray; + for (int j = v.length; j-- > 0;) + { + if ((tmp2 = v[j]).round != round) + { + tmp2.round = round; + newStates[start++] = tmp2; + } + } + } + } + + newStates[start] = null; + return Integer.MAX_VALUE; + } + + static Vector allBitVectors = new Vector(); + + /* This function generates the bit vectors of low and hi bytes for common + bit vectors and retunrs those that are not common with anything (in + loBytes) and returns an array of indices that can be used to generate + the function names for char matching using the common bit vectors. + It also generates code to match a char with the common bit vectors. + (Need a better comment). */ + + static int[] tmpIndices = new int[512]; // 2 * 256 + public void GenerateNonAsciiMoves(java.io.PrintWriter ostr) + { + int i = 0, j = 0; + char hiByte; + int cnt = 0; + long[][] loBytes = new long[256][4]; + + if ((charMoves == null || charMoves[0] == 0) && + (rangeMoves == null || rangeMoves[0] == 0)) + return; + + if (charMoves != null) + { + for (i = 0; i < charMoves.length; i++) + { + if (charMoves[i] == 0) + break; + + hiByte = (char)(charMoves[i] >> 8); + loBytes[hiByte][(charMoves[i] & 0xff) / 64] |= + (1L << ((charMoves[i] & 0xff) % 64)); + } + } + + if (rangeMoves != null) + { + for (i = 0; i < rangeMoves.length; i += 2) + { + if (rangeMoves[i] == 0) + break; + + char c, r; + + r = (char)(rangeMoves[i + 1] & 0xff); + hiByte = (char)(rangeMoves[i] >> 8); + + if (hiByte == (char)(rangeMoves[i + 1] >> 8)) + { + for (c = (char)(rangeMoves[i] & 0xff); c <= r; c++) + loBytes[hiByte][c / 64] |= (1L << (c % 64)); + + continue; + } + + for (c = (char)(rangeMoves[i] & 0xff); c <= 0xff; c++) + loBytes[hiByte][c / 64] |= (1L << (c % 64)); + + while (++hiByte < (char)(rangeMoves[i + 1] >> 8)) + { + loBytes[hiByte][0] |= 0xffffffffffffffffL; + loBytes[hiByte][1] |= 0xffffffffffffffffL; + loBytes[hiByte][2] |= 0xffffffffffffffffL; + loBytes[hiByte][3] |= 0xffffffffffffffffL; + } + + for (c = 0; c <= r; c++) + loBytes[hiByte][c / 64] |= (1L << (c % 64)); + } + } + + long[] common = null; + boolean[] done = new boolean[256]; + + for (i = 0; i <= 255; i++) + { + if (done[i] || + (done[i] = + loBytes[i][0] == 0 && + loBytes[i][1] == 0 && + loBytes[i][2] == 0 && + loBytes[i][3] == 0)) + continue; + + for (j = i + 1; j < 256; j++) + { + if (done[j]) + continue; + + if (loBytes[i][0] == loBytes[j][0] && + loBytes[i][1] == loBytes[j][1] && + loBytes[i][2] == loBytes[j][2] && + loBytes[i][3] == loBytes[j][3]) + { + done[j] = true; + if (common == null) + { + done[i] = true; + common = new long[4]; + common[i / 64] |= (1L << (i % 64)); + } + + common[j / 64] |= (1L << (j % 64)); + } + } + + if (common != null) + { + Integer ind; + String tmp; + + tmp = "{\n 0x" + Long.toHexString(common[0]) + "L, " + + "0x" + Long.toHexString(common[1]) + "L, " + + "0x" + Long.toHexString(common[2]) + "L, " + + "0x" + Long.toHexString(common[3]) + "L\n};"; + if ((ind = (Integer)lohiByteTab.get(tmp)) == null) + { + allBitVectors.addElement(tmp); + + if (!AllBitsSet(tmp)) + ostr.println("static ulong[] jjbitVec" + lohiByteCnt + " = " + tmp); + lohiByteTab.put(tmp, ind = new Integer(lohiByteCnt++)); + } + + tmpIndices[cnt++] = ind.intValue(); + + tmp = "{\n 0x" + Long.toHexString(loBytes[i][0]) + "L, " + + "0x" + Long.toHexString(loBytes[i][1]) + "L, " + + "0x" + Long.toHexString(loBytes[i][2]) + "L, " + + "0x" + Long.toHexString(loBytes[i][3]) + "L\n};"; + if ((ind = (Integer)lohiByteTab.get(tmp)) == null) + { + allBitVectors.addElement(tmp); + + if (!AllBitsSet(tmp)) + ostr.println("static ulong[] jjbitVec" + lohiByteCnt + " = " + tmp); + lohiByteTab.put(tmp, ind = new Integer(lohiByteCnt++)); + } + + tmpIndices[cnt++] = ind.intValue(); + + common = null; + } + } + + nonAsciiMoveIndices = new int[cnt]; + System.arraycopy(tmpIndices, 0, nonAsciiMoveIndices, 0, cnt); + +/* + System.err.println("state : " + stateName + " cnt : " + cnt); + while (cnt > 0) + { + System.err.print(nonAsciiMoveIndices[cnt - 1] + ", " + nonAsciiMoveIndices[cnt - 2] + ", "); + cnt -= 2; + } + System.err.println(""); +*/ + + for (i = 0; i < 256; i++) + { + if (done[i]) + loBytes[i] = null; + else + { + //System.err.print(i + ", "); + String tmp; + Integer ind; + + tmp = "{\n 0x" + Long.toHexString(loBytes[i][0]) + "L, " + + "0x" + Long.toHexString(loBytes[i][1]) + "L, " + + "0x" + Long.toHexString(loBytes[i][2]) + "L, " + + "0x" + Long.toHexString(loBytes[i][3]) + "L\n};"; + + if ((ind = (Integer)lohiByteTab.get(tmp)) == null) + { + allBitVectors.addElement(tmp); + + if (!AllBitsSet(tmp)) + ostr.println("static ulong[] jjbitVec" + lohiByteCnt + " = " + tmp); + lohiByteTab.put(tmp, ind = new Integer(lohiByteCnt++)); + } + + if (loByteVec == null) + loByteVec = new Vector(); + + loByteVec.addElement(new Integer(i)); + loByteVec.addElement(ind); + } + } + //System.err.println(""); + UpdateDuplicateNonAsciiMoves(); + } + + private void UpdateDuplicateNonAsciiMoves() + { + for (int i = 0; i < nonAsciiTableForMethod.size(); i++) + { + NfaState tmp = (NfaState)nonAsciiTableForMethod.elementAt(i); + if (EqualLoByteVectors(loByteVec, tmp.loByteVec) && + EqualNonAsciiMoveIndices(nonAsciiMoveIndices, tmp.nonAsciiMoveIndices)) + { + nonAsciiMethod = i; + return; + } + } + + nonAsciiMethod = nonAsciiTableForMethod.size(); + nonAsciiTableForMethod.addElement(this); + } + + private static boolean EqualLoByteVectors(Vector vec1, Vector vec2) + { + if (vec1 == null || vec2 == null) + return false; + + if (vec1 == vec2) + return true; + + if (vec1.size() != vec2.size()) + return false; + + for (int i = 0; i < vec1.size(); i++) + { + if (((Integer)vec1.elementAt(i)).intValue() != + ((Integer)vec2.elementAt(i)).intValue()) + return false; + } + + return true; + } + + private static boolean EqualNonAsciiMoveIndices(int[] moves1, int[] moves2) + { + if (moves1 == moves2) + return true; + + if (moves1 == null || moves2 == null) + return false; + + if (moves1.length != moves2.length) + return false; + + for (int i = 0; i < moves1.length;i++) + { + if (moves1[i] != moves2[i]) + return false; + } + + return true; + } + + static String allBits = "{\n 0xffffffffffffffffL, " + + "0xffffffffffffffffL, " + + "0xffffffffffffffffL, " + + "0xffffffffffffffffL\n};"; + + static boolean AllBitsSet(String bitVec) + { + return bitVec.equals(allBits); + } + + public static int AddStartStateSet(String stateSetString) + { + return AddCompositeStateSet(stateSetString, true); + } + + private static int AddCompositeStateSet(String stateSetString, boolean starts) + { + Integer stateNameToReturn; + + if ((stateNameToReturn = (Integer)stateNameForComposite.get(stateSetString)) != null) + return stateNameToReturn.intValue(); + + int toRet = 0; + int[] nameSet = (int[])allNextStates.get(stateSetString); + + if (!starts) + stateBlockTable.put(stateSetString, stateSetString); + + if (nameSet == null) + throw new Error("JavaCC Bug: Please send mail to sankar@cs.stanford.edu; nameSet null for : " + stateSetString); + + if (nameSet.length == 1) + { + stateNameToReturn = new Integer(nameSet[0]); + stateNameForComposite.put(stateSetString, stateNameToReturn); + return nameSet[0]; + } + + for (int i = 0; i < nameSet.length; i++) + { + if (nameSet[i] == -1) + continue; + + NfaState st = (NfaState)indexedAllStates.elementAt(nameSet[i]); + st.isComposite = true; + st.compositeStates = nameSet; + } + + while (toRet < nameSet.length && + (starts && ((NfaState)indexedAllStates.elementAt(nameSet[toRet])).inNextOf > 1)) + toRet++; + + Enumeration e = compositeStateTable.keys(); + String s; + while (e.hasMoreElements()) + { + s = (String)e.nextElement(); + if (!s.equals(stateSetString) && Intersect(stateSetString, s)) + { + int[] other = (int[])compositeStateTable.get(s); + + while (toRet < nameSet.length && + ((starts && ((NfaState)indexedAllStates.elementAt(nameSet[toRet])).inNextOf > 1) || + ElemOccurs(nameSet[toRet], other) >= 0)) + toRet++; + } + } + + int tmp; + + if (toRet >= nameSet.length) + { + if (dummyStateIndex == -1) + tmp = dummyStateIndex = generatedStates; + else + tmp = ++dummyStateIndex; + } + else + tmp = nameSet[toRet]; + + stateNameToReturn = new Integer(tmp); + stateNameForComposite.put(stateSetString, stateNameToReturn); + compositeStateTable.put(stateSetString, nameSet); + + return tmp; + } + + private static int StateNameForComposite(String stateSetString) + { + return ((Integer)stateNameForComposite.get(stateSetString)).intValue(); + } + + public static int InitStateName() + { + String s = LexGen.initialState.GetEpsilonMovesString(); + + if (LexGen.initialState.usefulEpsilonMoves != 0) + return StateNameForComposite(s); + return -1; + } + + public void GenerateInitMoves(java.io.PrintWriter ostr) + { + GetEpsilonMovesString(); + + if (epsilonMovesString == null) + epsilonMovesString = "null;"; + + AddStartStateSet(epsilonMovesString); + } + + static Hashtable tableToDump = new Hashtable(); + static Vector orderedStateSet = new Vector(); + + static int lastIndex = 0; + private static int[] GetStateSetIndicesForUse(String arrayString) + { + int[] ret; + int[] set = (int[])allNextStates.get(arrayString); + + if ((ret = (int[])tableToDump.get(arrayString)) == null) + { + ret = new int[2]; + ret[0] = lastIndex; + ret[1] = lastIndex + set.length - 1; + lastIndex += set.length; + tableToDump.put(arrayString, ret); + orderedStateSet.addElement(set); + } + + return ret; + } + + public static void DumpStateSets(java.io.PrintWriter ostr) + { + int cnt = 0; + + ostr.print("static int[] jjnextStates = {"); + for (int i = 0; i < orderedStateSet.size(); i++) + { + int[] set = (int[])orderedStateSet.elementAt(i); + + for (int j = 0; j < set.length; j++) + { + if (cnt++ % 16 == 0) + ostr.print("\n "); + + ostr.print(set[j] + ", "); + } + } + + ostr.println("\n};"); + } + + static String GetStateSetString(int[] states) + { + String retVal = "{ "; + for (int i = 0; i < states.length; ) + { + retVal += states[i] + ", "; + + if (i++ > 0 && i % 16 == 0) + retVal += "\n"; + } + + retVal += "};"; + allNextStates.put(retVal, states); + return retVal; + } + + static String GetStateSetString(Vector states) + { + if (states == null || states.size() == 0) + return "null;"; + + int[] set = new int[states.size()]; + String retVal = "{ "; + for (int i = 0; i < states.size(); ) + { + int k; + retVal += (k = ((NfaState)states.elementAt(i)).stateName) + ", "; + set[i] = k; + + if (i++ > 0 && i % 16 == 0) + retVal += "\n"; + } + + retVal += "};"; + allNextStates.put(retVal, set); + return retVal; + } + + static int NumberOfBitsSet(long l) + { + int ret = 0; + for (int i = 0; i < 63; i++) + if (((l >> i) & 1L) != 0L) + ret++; + + return ret; + } + + static int OnlyOneBitSet(long l) + { + int oneSeen = -1; + for (int i = 0; i < 64; i++) + if (((l >> i) & 1L) != 0L) + { + if (oneSeen >= 0) + return -1; + oneSeen = i; + } + + return oneSeen; + } + + private static int ElemOccurs(int elem, int[] arr) + { + for (int i = arr.length; i-- > 0;) + if (arr[i] == elem) + return i; + + return -1; + } + + private boolean FindCommonBlocks() + { + if (next == null || next.usefulEpsilonMoves <= 1) + return false; + + if (stateDone == null) + stateDone = new boolean[generatedStates]; + + String set = next.epsilonMovesString; + + int[] nameSet = (int[])allNextStates.get(set); + + if (nameSet.length <= 2 || compositeStateTable.get(set) != null) + return false; + + int i; + int freq[] = new int[nameSet.length]; + boolean live[] = new boolean[nameSet.length]; + int[] count = new int[allNextStates.size()]; + + for (i = 0; i < nameSet.length; i++) + { + if (nameSet[i] != -1) + { + if (live[i] = !stateDone[nameSet[i]]) + count[0]++; + } + } + + int j, blockLen = 0, commonFreq = 0; + Enumeration e = allNextStates.keys(); + boolean needUpdate; + + while (e.hasMoreElements()) + { + int[] tmpSet = (int[])allNextStates.get(e.nextElement()); + if (tmpSet == nameSet) + continue; + + needUpdate = false; + for (j = 0; j < nameSet.length; j++) + { + if (nameSet[j] == -1) + continue; + + if (live[j] && ElemOccurs(nameSet[j], tmpSet) >= 0) + { + if (!needUpdate) + { + needUpdate = true; + commonFreq++; + } + + count[freq[j]]--; + count[commonFreq]++; + freq[j] = commonFreq; + } + } + + if (needUpdate) + { + int foundFreq = -1; + blockLen = 0; + + for (j = 0; j <= commonFreq; j++) + if (count[j] > blockLen) + { + foundFreq = j; + blockLen = count[j]; + } + + if (blockLen <= 1) + return false; + + for (j = 0; j < nameSet.length; j++) + if (nameSet[j] != -1 && freq[j] != foundFreq) + { + live[j] = false; + count[freq[j]]--; + } + } + } + + if (blockLen <= 1) + return false; + + int[] commonBlock = new int[blockLen]; + int cnt = 0; + //System.err.println("Common Block for " + set + " : "); + for (i = 0; i < nameSet.length; i++) + { + if (live[i]) + { + if (((NfaState)indexedAllStates.elementAt(nameSet[i])).isComposite) + return false; + + stateDone[nameSet[i]] = true; + commonBlock[cnt++] = nameSet[i]; + //System.err.print(nameSet[i] + ", "); + } + } + + //System.err.println(""); + + String s = GetStateSetString(commonBlock); + e = allNextStates.keys(); + + Outer : + while (e.hasMoreElements()) + { + int at; + boolean firstOne = true; + String stringToFix; + int[] setToFix = (int[])allNextStates.get(stringToFix = (String)e.nextElement()); + + if (setToFix == commonBlock) + continue; + + for (int k = 0; k < cnt; k++) + { + if ((at = ElemOccurs(commonBlock[k], setToFix)) >= 0) + { + if (!firstOne) + setToFix[at] = -1; + firstOne = false; + } + else + continue Outer; + } + + if (stateSetsToFix.get(stringToFix) == null) + stateSetsToFix.put(stringToFix, setToFix); + } + + next.usefulEpsilonMoves -= blockLen - 1; + AddCompositeStateSet(s, false); + return true; + } + + private boolean CheckNextOccursTogether() + { + if (next == null || next.usefulEpsilonMoves <= 1) + return true; + + String set = next.epsilonMovesString; + + int[] nameSet = (int[])allNextStates.get(set); + + if (nameSet.length == 1 || compositeStateTable.get(set) != null || + stateSetsToFix.get(set) != null) + return false; + + int i; + Hashtable occursIn = new Hashtable(); + NfaState tmp = (NfaState)allStates.elementAt(nameSet[0]); + + for (i = 1; i < nameSet.length; i++) + { + NfaState tmp1 = (NfaState)allStates.elementAt(nameSet[i]); + + if (tmp.inNextOf != tmp1.inNextOf) + return false; + } + + int isPresent, j; + Enumeration e = allNextStates.keys(); + while (e.hasMoreElements()) + { + String s; + int[] tmpSet = (int[])allNextStates.get(s = (String)e.nextElement()); + + if (tmpSet == nameSet) + continue; + + isPresent = 0; + Outer: + for (j = 0; j < nameSet.length; j++) + { + if (ElemOccurs(nameSet[j], tmpSet) >= 0) + isPresent++; + else if (isPresent > 0) + return false; + } + + if (isPresent == j) + { + if (tmpSet.length > nameSet.length) + occursIn.put(s, tmpSet); + + /* May not need. But safe. */ + if (compositeStateTable.get(s) != null || + stateSetsToFix.get(s) != null) + return false; + } + else if (isPresent != 0) + return false; + } + + e = occursIn.keys(); + while (e.hasMoreElements()) + { + String s; + int[] setToFix = (int[])occursIn.get(s = (String)e.nextElement()); + + if (stateSetsToFix.get(s) == null) + stateSetsToFix.put(s, setToFix); + + for (int k = 0; k < setToFix.length; k++) + if (ElemOccurs(setToFix[k], nameSet) > 0) // Not >= since need the first one (0) + setToFix[k] = -1; + } + + next.usefulEpsilonMoves = 1; + AddCompositeStateSet(next.epsilonMovesString, false); + return true; + } + + private static void FixStateSets() + { + Hashtable fixedSets = new Hashtable(); + Enumeration e = stateSetsToFix.keys(); + int[] tmp = new int[generatedStates]; + int i; + + while (e.hasMoreElements()) + { + String s; + int[] toFix = (int[])stateSetsToFix.get(s = (String)e.nextElement()); + int cnt = 0; + + //System.err.print("Fixing : "); + for (i = 0; i < toFix.length; i++) + { + //System.err.print(toFix[i] + ", "); + if (toFix[i] != -1) + tmp[cnt++] = toFix[i]; + } + + int[] fixed = new int[cnt]; + System.arraycopy(tmp, 0, fixed, 0, cnt); + fixedSets.put(s, fixed); + allNextStates.put(s, fixed); + //System.err.println(" as " + GetStateSetString(fixed)); + } + + for (i = 0; i < allStates.size(); i++) + { + NfaState tmpState = (NfaState)allStates.elementAt(i); + int[] newSet; + + if (tmpState.next == null || tmpState.next.usefulEpsilonMoves == 0) + continue; + + /*if (compositeStateTable.get(tmpState.next.epsilonMovesString) != null) + tmpState.next.usefulEpsilonMoves = 1; + else*/ if ((newSet = (int[])fixedSets.get(tmpState.next.epsilonMovesString)) != null) + tmpState.FixNextStates(newSet); + } + } + + private final void FixNextStates(int[] newSet) + { + next.usefulEpsilonMoves = newSet.length; + //next.epsilonMovesString = GetStateSetString(newSet); + } + + private static boolean Intersect(String set1, String set2) + { + if (set1 == null || set2 == null) + return false; + + int[] nameSet1 = (int[])allNextStates.get(set1); + int[] nameSet2 = (int[])allNextStates.get(set2); + + if (nameSet1 == null || nameSet2 == null) + return false; + + if (nameSet1 == nameSet2) + return true; + + for (int i = nameSet1.length; i-- > 0; ) + for (int j = nameSet2.length; j-- > 0; ) + if (nameSet1[i] == nameSet2[j]) + return true; + + return false; + } + + private static void DumpHeadForCase(java.io.PrintWriter ostr, int byteNum) + { + if (byteNum == 0) + ostr.println(" ulong l = 1UL << curChar;"); + else if (byteNum == 1) + ostr.println(" ulong l = 1UL << (curChar & 0x3F);"); + + else + { + if (Options.getCSUnicodeEscape() || unicodeWarningGiven) + { + ostr.println(" int hiByte = (int)(curChar >> 8);"); + ostr.println(" int i1 = hiByte >> 6;"); + ostr.println(" ulong l1 = 1UL << (hiByte & 0x3F);"); + } + + ostr.println(" int i2 = (curChar & 0xff) >> 6;"); + ostr.println(" ulong l2 = 1UL << (curChar & 0x3F);"); + } + + ostr.println(" MatchLoop: do"); + ostr.println(" {"); + + ostr.println(" switch(jjstateSet[--i])"); + ostr.println(" {"); + } + + private static Vector PartitionStatesSetForAscii(int[] states, int byteNum) + { + int[] cardinalities = new int[states.length]; + Vector original = new Vector(); + Vector partition = new Vector(); + NfaState tmp; + + original.setSize(states.length); + int cnt = 0; + for (int i = 0; i < states.length; i++) + { + tmp = (NfaState)allStates.elementAt(states[i]); + + if (tmp.asciiMoves[byteNum] != 0L) + { + int j; + int p = NumberOfBitsSet(tmp.asciiMoves[byteNum]); + + for (j = 0; j < i; j++) + if (cardinalities[j] <= p) + break; + + for (int k = i; k > j; k--) + cardinalities[k] = cardinalities[k - 1]; + + cardinalities[j] = p; + + original.insertElementAt(tmp, j); + cnt++; + } + } + + original.setSize(cnt); + + while (original.size() > 0) + { + tmp = (NfaState)original.elementAt(0); + original.removeElement(tmp); + + long bitVec = tmp.asciiMoves[byteNum]; + Vector subSet = new Vector(); + subSet.addElement(tmp); + + for (int j = 0; j < original.size(); j++) + { + NfaState tmp1 = (NfaState)original.elementAt(j); + + if ((tmp1.asciiMoves[byteNum] & bitVec) == 0L) + { + bitVec |= tmp1.asciiMoves[byteNum]; + subSet.addElement(tmp1); + original.removeElementAt(j--); + } + } + + partition.addElement(subSet); + } + + return partition; + } + + private String PrintNoBreak(java.io.PrintWriter ostr, int byteNum, boolean[] dumped) + { + if (inNextOf != 1) + throw new Error("JavaCC Bug: Please send mail to sankar@cs.stanford.edu"); + + dumped[stateName] = true; + + if (byteNum >= 0) + { + if (asciiMoves[byteNum] != 0L) + { + ostr.println(" case " + stateName + ":"); + DumpAsciiMoveForCompositeState(ostr, byteNum, false); + return ""; + } + } + else if (nonAsciiMethod != -1) + { + ostr.println(" case " + stateName + ":"); + DumpNonAsciiMoveForCompositeState(ostr); + return ""; + } + + return (" case " + stateName + ":\n"); + } + + private static void DumpCompositeStatesAsciiMoves(java.io.PrintWriter ostr, + String key, int byteNum, boolean[] dumped) + { + int i; + + int[] nameSet = (int[])allNextStates.get(key); + + if (nameSet.length == 1 || dumped[StateNameForComposite(key)]) + return; + + NfaState toBePrinted = null; + int neededStates = 0; + NfaState tmp; + NfaState stateForCase = null; + String toPrint = ""; + boolean stateBlock = (stateBlockTable.get(key) != null); + + for (i = 0; i < nameSet.length; i++) + { + tmp = (NfaState)allStates.elementAt(nameSet[i]); + + if (tmp.asciiMoves[byteNum] != 0L) + { + if (neededStates++ == 1) + break; + else + toBePrinted = tmp; + } + else + dumped[tmp.stateName] = true; + + if (tmp.stateForCase != null) + { + if (stateForCase != null) + throw new Error("JavaCC Bug: Please send mail to sankar@cs.stanford.edu : "); + + stateForCase = tmp.stateForCase; + } + } + + if (stateForCase != null) + toPrint = stateForCase.PrintNoBreak(ostr, byteNum, dumped); + + if (neededStates == 0) + { + if (stateForCase != null && toPrint.equals("")) + ostr.println(" break;"); + return; + } + + if (neededStates == 1) + { + //if (byteNum == 1) + //System.err.println(toBePrinted.stateName + " is the only state for " + //+ key + " ; and key is : " + StateNameForComposite(key)); + + if (!toPrint.equals("")) + ostr.print(toPrint); + + ostr.println(" case " + StateNameForComposite(key) + ":"); + + if (!dumped[toBePrinted.stateName] && !stateBlock && toBePrinted.inNextOf > 1) + ostr.println(" case " + toBePrinted.stateName + ":"); + + dumped[toBePrinted.stateName] = true; + toBePrinted.DumpAsciiMove(ostr, byteNum, dumped); + return; + } + + Vector partition = PartitionStatesSetForAscii(nameSet, byteNum); + + if (!toPrint.equals("")) + ostr.print(toPrint); + + int keyState = StateNameForComposite(key); + ostr.println(" case " + keyState + ":"); + if (keyState < generatedStates) + dumped[keyState] = true; + + for (i = 0; i < partition.size(); i++) + { + Vector subSet = (Vector)partition.elementAt(i); + + for (int j = 0; j < subSet.size(); j++) + { + tmp = (NfaState)subSet.elementAt(j); + + if (stateBlock) + dumped[tmp.stateName] = true; + tmp.DumpAsciiMoveForCompositeState(ostr, byteNum, j != 0); + } + } + + if (stateBlock) + ostr.println(" break;"); + else + ostr.println(" break;"); + } + + private boolean selfLoop() + { + if (next == null || next.epsilonMovesString == null) + return false; + + int[] set = (int[])allNextStates.get(next.epsilonMovesString); + return ElemOccurs(stateName, set) >= 0; + } + + private void DumpAsciiMoveForCompositeState(java.io.PrintWriter ostr, int byteNum, boolean elseNeeded) + { + boolean nextIntersects = selfLoop(); + + for (int j = 0; j < allStates.size(); j++) + { + NfaState temp1 = (NfaState)allStates.elementAt(j); + + if (this == temp1 || temp1.stateName == -1 || temp1.dummy || + stateName == temp1.stateName || temp1.asciiMoves[byteNum] == 0L) + continue; + + if (!nextIntersects && Intersect(temp1.next.epsilonMovesString, + next.epsilonMovesString)) + { + nextIntersects = true; + break; + } + } + + //System.err.println(stateName + " \'s nextIntersects : " + nextIntersects); + String prefix = ""; + if (asciiMoves[byteNum] != 0xffffffffffffffffL) + { + int oneBit = OnlyOneBitSet(asciiMoves[byteNum]); + + if (oneBit != -1) + ostr.println(" " + (elseNeeded ? "else " : "") + "if (curChar == " + + (64 * byteNum + oneBit) + ")"); + else + ostr.println(" " + (elseNeeded ? "else " : "") + "if ((0x" + Long.toHexString(asciiMoves[byteNum]) + + "L & l) != 0L)"); + prefix = " "; + } + + if (kindToPrint != Integer.MAX_VALUE) + { + if (asciiMoves[byteNum] != 0xffffffffffffffffL) + { + ostr.println(" {"); + } + + ostr.println(prefix + " if (kind > " + kindToPrint + ")"); + ostr.println(prefix + " kind = " + kindToPrint + ";"); + } + + if (next != null && next.usefulEpsilonMoves > 0) + { + int[] stateNames = (int[])allNextStates.get( + next.epsilonMovesString); + if (next.usefulEpsilonMoves == 1) + { + int name = stateNames[0]; + + if (nextIntersects) + ostr.println(prefix + " jjCheckNAdd(" + name + ");"); + else + ostr.println(prefix + " jjstateSet[jjnewStateCnt++] = " + name + ";"); + } + else if (next.usefulEpsilonMoves == 2 && nextIntersects) + { + ostr.println(prefix + " jjCheckNAddTwoStates(" + + stateNames[0] + ", " + stateNames[1] + ");"); + } + else + { + int[] indices = GetStateSetIndicesForUse(next.epsilonMovesString); + boolean notTwo = (indices[0] + 1 != indices[1]); + + if (nextIntersects) + ostr.println(prefix + " jjCheckNAddStates(" + + indices[0] + (notTwo ? (", " + indices[1]) : "") + ");"); + else + ostr.println(prefix + " jjAddStates(" + + indices[0] + ", " + indices[1] + ");"); + } + } + + if (asciiMoves[byteNum] != 0xffffffffffffffffL && kindToPrint != Integer.MAX_VALUE) + ostr.println(" }"); + } + + private void DumpAsciiMove(java.io.PrintWriter ostr, int byteNum, boolean dumped[]) + { + boolean nextIntersects = selfLoop() && isComposite; + boolean onlyState = true; + + for (int j = 0; j < allStates.size(); j++) + { + NfaState temp1 = (NfaState)allStates.elementAt(j); + + if (this == temp1 || temp1.stateName == -1 || temp1.dummy || + stateName == temp1.stateName || temp1.asciiMoves[byteNum] == 0L) + continue; + + if (onlyState && (asciiMoves[byteNum] & temp1.asciiMoves[byteNum]) != 0L) + onlyState = false; + + if (!nextIntersects && Intersect(temp1.next.epsilonMovesString, + next.epsilonMovesString)) + nextIntersects = true; + + if (!dumped[temp1.stateName] && !temp1.isComposite && + asciiMoves[byteNum] == temp1.asciiMoves[byteNum] && + kindToPrint == temp1.kindToPrint && + (next.epsilonMovesString == temp1.next.epsilonMovesString || + (next.epsilonMovesString != null && + temp1.next.epsilonMovesString != null && + next.epsilonMovesString.equals( + temp1.next.epsilonMovesString)))) + { + dumped[temp1.stateName] = true; + ostr.println(" case " + temp1.stateName + ":"); + } + } + + //if (onlyState) + //nextIntersects = false; + + int oneBit = OnlyOneBitSet(asciiMoves[byteNum]); + if (asciiMoves[byteNum] != 0xffffffffffffffffL) + { + if ((next == null || next.usefulEpsilonMoves == 0) && + kindToPrint != Integer.MAX_VALUE) + { + String kindCheck = ""; + + if (!onlyState) + kindCheck = " && kind > " + kindToPrint; + + if (oneBit != -1) + ostr.println(" if (curChar == " + + (64 * byteNum + oneBit) + kindCheck + ")"); + else + ostr.println(" if ((0x" + + Long.toHexString(asciiMoves[byteNum]) + + "L & l) != 0L" + kindCheck + ")"); + + ostr.println(" kind = " + kindToPrint + ";"); + + if (onlyState) + ostr.println(" break;"); + else + ostr.println(" break;"); + + return; + } + } + + String prefix = ""; + if (kindToPrint != Integer.MAX_VALUE) + { + + if (oneBit != -1) + { + ostr.println(" if (curChar != " + + (64 * byteNum + oneBit) + ")"); + ostr.println(" break;"); + } + else if (asciiMoves[byteNum] != 0xffffffffffffffffL) + { + ostr.println(" if ((0x" + Long.toHexString(asciiMoves[byteNum]) + "L & l) == 0L)"); + ostr.println(" break;"); + } + + if (onlyState) + { + ostr.println(" kind = " + kindToPrint + ";"); + } + else + { + ostr.println(" if (kind > " + kindToPrint + ")"); + ostr.println(" kind = " + kindToPrint + ";"); + } + } + else + { + if (oneBit != -1) + { + ostr.println(" if (curChar == " + + (64 * byteNum + oneBit) + ")"); + prefix = " "; + } + else if (asciiMoves[byteNum] != 0xffffffffffffffffL) + { + ostr.println(" if ((0x" + Long.toHexString(asciiMoves[byteNum]) + "L & l) != 0L)"); + prefix = " "; + } + } + + if (next != null && next.usefulEpsilonMoves > 0) + { + int[] stateNames = (int[])allNextStates.get( + next.epsilonMovesString); + if (next.usefulEpsilonMoves == 1) + { + int name = stateNames[0]; + if (nextIntersects) + ostr.println(prefix + " jjCheckNAdd(" + name + ");"); + else + ostr.println(prefix + " jjstateSet[jjnewStateCnt++] = " + name + ";"); + } + else if (next.usefulEpsilonMoves == 2 && nextIntersects) + { + ostr.println(prefix + " jjCheckNAddTwoStates(" + + stateNames[0] + ", " + stateNames[1] + ");"); + } + else + { + int[] indices = GetStateSetIndicesForUse(next.epsilonMovesString); + boolean notTwo = (indices[0] + 1 != indices[1]); + + if (nextIntersects) + ostr.println(prefix + " jjCheckNAddStates(" + + indices[0] + (notTwo ? (", " + indices[1]) : "") + ");"); + else + ostr.println(prefix + " jjAddStates(" + + indices[0] + ", " + indices[1] + ");"); + } + } + + if (onlyState) + ostr.println(" break;"); + else + ostr.println(" break;"); + } + + private static void DumpAsciiMoves(java.io.PrintWriter ostr, int byteNum) + { + boolean[] dumped = new boolean[Math.max(generatedStates, dummyStateIndex + 1)]; + Enumeration e = compositeStateTable.keys(); + + DumpHeadForCase(ostr, byteNum); + + while (e.hasMoreElements()) + DumpCompositeStatesAsciiMoves(ostr, (String)e.nextElement(), byteNum, dumped); + + for (int i = 0; i < allStates.size(); i++) + { + NfaState temp = (NfaState)allStates.elementAt(i); + + if (dumped[temp.stateName] || temp.lexState != LexGen.lexStateIndex || + !temp.HasTransitions() || temp.dummy || + temp.stateName == -1) + continue; + + String toPrint = ""; + + if (temp.stateForCase != null) + { + if (temp.inNextOf == 1) + continue; + + if (dumped[temp.stateForCase.stateName]) + continue; + + toPrint = (temp.stateForCase.PrintNoBreak(ostr, byteNum, dumped)); + + if (temp.asciiMoves[byteNum] == 0L) + { + if (toPrint.equals("")) + ostr.println(" break;"); + + continue; + } + } + + if (temp.asciiMoves[byteNum] == 0L) + continue; + + if (!toPrint.equals("")) + ostr.print(toPrint); + + dumped[temp.stateName] = true; + ostr.println(" case " + temp.stateName + ":"); + temp.DumpAsciiMove(ostr, byteNum, dumped); + } + + ostr.println(" default : break;"); + ostr.println(" }"); + ostr.println(" } while(i != startsAt);"); + } + + private static void DumpCompositeStatesNonAsciiMoves(java.io.PrintWriter ostr, + String key, boolean[] dumped) + { + int i; + int[] nameSet = (int[])allNextStates.get(key); + + if (nameSet.length == 1 || dumped[StateNameForComposite(key)]) + return; + + NfaState toBePrinted = null; + int neededStates = 0; + NfaState tmp; + NfaState stateForCase = null; + String toPrint = ""; + boolean stateBlock = (stateBlockTable.get(key) != null); + + for (i = 0; i < nameSet.length; i++) + { + tmp = (NfaState)allStates.elementAt(nameSet[i]); + + if (tmp.nonAsciiMethod != -1) + { + if (neededStates++ == 1) + break; + else + toBePrinted = tmp; + } + else + dumped[tmp.stateName] = true; + + if (tmp.stateForCase != null) + { + if (stateForCase != null) + throw new Error("JavaCC Bug: Please send mail to sankar@cs.stanford.edu : "); + + stateForCase = tmp.stateForCase; + } + } + + if (stateForCase != null) + toPrint = stateForCase.PrintNoBreak(ostr, -1, dumped); + + if (neededStates == 0) + { + if (stateForCase != null && toPrint.equals("")) + ostr.println(" break;"); + + return; + } + + if (neededStates == 1) + { + if (!toPrint.equals("")) + ostr.print(toPrint); + + ostr.println(" case " + StateNameForComposite(key) + ":"); + + if (!dumped[toBePrinted.stateName] && !stateBlock && toBePrinted.inNextOf > 1) + ostr.println(" case " + toBePrinted.stateName + ":"); + + dumped[toBePrinted.stateName] = true; + toBePrinted.DumpNonAsciiMove(ostr, dumped); + return; + } + + if (!toPrint.equals("")) + ostr.print(toPrint); + + int keyState = StateNameForComposite(key); + ostr.println(" case " + keyState + ":"); + if (keyState < generatedStates) + dumped[keyState] = true; + + for (i = 0; i < nameSet.length; i++) + { + tmp = (NfaState)allStates.elementAt(nameSet[i]); + + if (tmp.nonAsciiMethod != -1) + { + if (stateBlock) + dumped[tmp.stateName] = true; + tmp.DumpNonAsciiMoveForCompositeState(ostr); + } + } + + if (stateBlock) + ostr.println(" break;"); + else + ostr.println(" break;"); + } + + private final void DumpNonAsciiMoveForCompositeState(java.io.PrintWriter ostr) + { + boolean nextIntersects = selfLoop(); + for (int j = 0; j < allStates.size(); j++) + { + NfaState temp1 = (NfaState)allStates.elementAt(j); + + if (this == temp1 || temp1.stateName == -1 || temp1.dummy || + stateName == temp1.stateName || (temp1.nonAsciiMethod == -1)) + continue; + + if (!nextIntersects && Intersect(temp1.next.epsilonMovesString, + next.epsilonMovesString)) + { + nextIntersects = true; + break; + } + } + + if (!Options.getCSUnicodeEscape() && !unicodeWarningGiven) + { + if (loByteVec != null && loByteVec.size() > 1) + ostr.println(" if ((jjbitVec" + + ((Integer)loByteVec.elementAt(1)).intValue() + "[i2" + + "] & l2) != 0L)"); + } + else + { + ostr.println(" if (jjCanMove_" + nonAsciiMethod + + "(hiByte, i1, i2, l1, l2))"); + } + + if (kindToPrint != Integer.MAX_VALUE) + { + ostr.println(" {"); + ostr.println(" if (kind > " + kindToPrint + ")"); + ostr.println(" kind = " + kindToPrint + ";"); + } + + if (next != null && next.usefulEpsilonMoves > 0) + { + int[] stateNames = (int[])allNextStates.get( + next.epsilonMovesString); + if (next.usefulEpsilonMoves == 1) + { + int name = stateNames[0]; + if (nextIntersects) + ostr.println(" jjCheckNAdd(" + name + ");"); + else + ostr.println(" jjstateSet[jjnewStateCnt++] = " + name + ";"); + } + else if (next.usefulEpsilonMoves == 2 && nextIntersects) + { + ostr.println(" jjCheckNAddTwoStates(" + + stateNames[0] + ", " + stateNames[1] + ");"); + } + else + { + int[] indices = GetStateSetIndicesForUse(next.epsilonMovesString); + boolean notTwo = (indices[0] + 1 != indices[1]); + + if (nextIntersects) + ostr.println(" jjCheckNAddStates(" + + indices[0] + (notTwo ? (", " + indices[1]) : "") + ");"); + else + ostr.println(" jjAddStates(" + + indices[0] + ", " + indices[1] + ");"); + } + } + + if (kindToPrint != Integer.MAX_VALUE) + ostr.println(" }"); + } + + private final void DumpNonAsciiMove(java.io.PrintWriter ostr, boolean dumped[]) + { + boolean nextIntersects = selfLoop() && isComposite; + + for (int j = 0; j < allStates.size(); j++) + { + NfaState temp1 = (NfaState)allStates.elementAt(j); + + if (this == temp1 || temp1.stateName == -1 || temp1.dummy || + stateName == temp1.stateName || (temp1.nonAsciiMethod == -1)) + continue; + + if (!nextIntersects && Intersect(temp1.next.epsilonMovesString, + next.epsilonMovesString)) + nextIntersects = true; + + if (!dumped[temp1.stateName] && !temp1.isComposite && + nonAsciiMethod == temp1.nonAsciiMethod && + kindToPrint == temp1.kindToPrint && + (next.epsilonMovesString == temp1.next.epsilonMovesString || + (next.epsilonMovesString != null && + temp1.next.epsilonMovesString != null && + next.epsilonMovesString.equals(temp1.next.epsilonMovesString)))) + { + dumped[temp1.stateName] = true; + ostr.println(" case " + temp1.stateName + ":"); + } + } + + if (next == null || next.usefulEpsilonMoves <= 0) + { + String kindCheck = " && kind > " + kindToPrint; + + if (!Options.getCSUnicodeEscape() && !unicodeWarningGiven) + { + if (loByteVec != null && loByteVec.size() > 1) + ostr.println(" if ((jjbitVec" + + ((Integer)loByteVec.elementAt(1)).intValue() + "[i2" + + "] & l2) != 0L" + kindCheck + ")"); + } + else + { + ostr.println(" if (jjCanMove_" + nonAsciiMethod + + "(hiByte, i1, i2, l1, l2)" + kindCheck + ")"); + } + ostr.println(" kind = " + kindToPrint + ";"); + ostr.println(" break;"); + return; + } + + String prefix = " "; + if (kindToPrint != Integer.MAX_VALUE) + { + if (!Options.getCSUnicodeEscape() && !unicodeWarningGiven) + { + if (loByteVec != null && loByteVec.size() > 1) + { + ostr.println(" if ((jjbitVec" + + ((Integer)loByteVec.elementAt(1)).intValue() + "[i2" + + "] & l2) == 0L)"); + ostr.println(" break;"); + } + } + else + { + ostr.println(" if (!jjCanMove_" + nonAsciiMethod + + "(hiByte, i1, i2, l1, l2))"); + ostr.println(" break;"); + } + + ostr.println(" if (kind > " + kindToPrint + ")"); + ostr.println(" kind = " + kindToPrint + ";"); + prefix = ""; + } + else if (!Options.getCSUnicodeEscape() && !unicodeWarningGiven) + { + if (loByteVec != null && loByteVec.size() > 1) + ostr.println(" if ((jjbitVec" + + ((Integer)loByteVec.elementAt(1)).intValue() + "[i2" + + "] & l2) != 0L)"); + } + else + { + ostr.println(" if (jjCanMove_" + nonAsciiMethod + + "(hiByte, i1, i2, l1, l2))"); + } + + if (next != null && next.usefulEpsilonMoves > 0) + { + int[] stateNames = (int[])allNextStates.get( + next.epsilonMovesString); + if (next.usefulEpsilonMoves == 1) + { + int name = stateNames[0]; + if (nextIntersects) + ostr.println(prefix + " jjCheckNAdd(" + name + ");"); + else + ostr.println(prefix + " jjstateSet[jjnewStateCnt++] = " + name + ";"); + } + else if (next.usefulEpsilonMoves == 2 && nextIntersects) + { + ostr.println(prefix + " jjCheckNAddTwoStates(" + + stateNames[0] + ", " + stateNames[1] + ");"); + } + else + { + int[] indices = GetStateSetIndicesForUse(next.epsilonMovesString); + boolean notTwo = (indices[0] + 1 != indices[1]); + + if (nextIntersects) + ostr.println(prefix + " jjCheckNAddStates(" + + indices[0] + (notTwo ? (", " + indices[1]) : "") + ");"); + else + ostr.println(prefix + " jjAddStates(" + + indices[0] + ", " + indices[1] + ");"); + } + } + + ostr.println(" break;"); + } + + public static void DumpCharAndRangeMoves(java.io.PrintWriter ostr) + { + boolean[] dumped = new boolean[Math.max(generatedStates, dummyStateIndex + 1)]; + Enumeration e = compositeStateTable.keys(); + int i; + + DumpHeadForCase(ostr, -1); + + while (e.hasMoreElements()) + DumpCompositeStatesNonAsciiMoves(ostr, (String)e.nextElement(), dumped); + + for (i = 0; i < allStates.size(); i++) + { + NfaState temp = (NfaState)allStates.elementAt(i); + + if (dumped[temp.stateName] || temp.lexState != LexGen.lexStateIndex || + !temp.HasTransitions() || temp.dummy || temp.stateName == -1) + continue; + + String toPrint = ""; + + if (temp.stateForCase != null) + { + if (temp.inNextOf == 1) + continue; + + if (dumped[temp.stateForCase.stateName]) + continue; + + toPrint = (temp.stateForCase.PrintNoBreak(ostr, -1, dumped)); + + if (temp.nonAsciiMethod == -1) + { + if (toPrint.equals("")) + ostr.println(" break;"); + + continue; + } + } + + if (temp.nonAsciiMethod == -1) + continue; + + if (!toPrint.equals("")) + ostr.print(toPrint); + + dumped[temp.stateName] = true; + //System.err.println("case : " + temp.stateName); + ostr.println(" case " + temp.stateName + ":"); + temp.DumpNonAsciiMove(ostr, dumped); + } + + ostr.println(" default : break;"); + ostr.println(" }"); + ostr.println(" } while(i != startsAt);"); + } + + public static void DumpNonAsciiMoveMethods(java.io.PrintWriter ostr) + { + if (!Options.getCSUnicodeEscape() && !unicodeWarningGiven) + return; + + if (nonAsciiTableForMethod.size() <= 0) + return; + + for (int i = 0; i < nonAsciiTableForMethod.size(); i++) + { + NfaState tmp = (NfaState)nonAsciiTableForMethod.elementAt(i); + tmp.DumpNonAsciiMoveMethod(ostr); + } + } + + void DumpNonAsciiMoveMethod(java.io.PrintWriter ostr) + { + int j; + ostr.println("private static bool jjCanMove_" + nonAsciiMethod + + "(int hiByte, int i1, int i2, long l1, long l2)"); + ostr.println("{"); + ostr.println(" switch(hiByte)"); + ostr.println(" {"); + + if (loByteVec != null && loByteVec.size() > 0) + { + for (j = 0; j < loByteVec.size(); j += 2) + { + ostr.println(" case " + + ((Integer)loByteVec.elementAt(j)).intValue() + ":"); + if (!AllBitsSet((String)allBitVectors.elementAt( + ((Integer)loByteVec.elementAt(j + 1)).intValue()))) + { + ostr.println(" return ((jjbitVec" + + ((Integer)loByteVec.elementAt(j + 1)).intValue() + "[i2" + + "] & l2) != 0L);"); + } + else + ostr.println(" return true;"); + } + } + + ostr.println(" default : "); + + if (nonAsciiMoveIndices != null && + (j = nonAsciiMoveIndices.length) > 0) + { + do + { + if (!AllBitsSet((String)allBitVectors.elementAt( + nonAsciiMoveIndices[j - 2]))) + ostr.println(" if ((jjbitVec" + nonAsciiMoveIndices[j - 2] + + "[i1] & l1) != 0L)"); + if (!AllBitsSet((String)allBitVectors.elementAt( + nonAsciiMoveIndices[j - 1]))) + { + ostr.println(" if ((jjbitVec" + nonAsciiMoveIndices[j - 1] + + "[i2] & l2) == 0L)"); + ostr.println(" return false;"); + ostr.println(" else"); + } + ostr.println(" return true;"); + } + while ((j -= 2) > 0); + } + + ostr.println(" return false;"); + ostr.println(" }"); + ostr.println("}"); + } + + private static void ReArrange() + { + Vector v = allStates; + allStates = new Vector(); + allStates.setSize(generatedStates); + + for (int j = 0; j < v.size(); j++) + { + NfaState tmp = (NfaState)v.elementAt(j); + if (tmp.stateName != -1 && !tmp.dummy) + allStates.setElementAt(tmp, tmp.stateName); + } + } + + private static boolean boilerPlateDumped = false; + static void PrintBoilerPlate(java.io.PrintWriter ostr) + { + ostr.println((Options.getStatic() ? "static " : "") + "private void " + + "jjCheckNAdd(int state)"); + ostr.println("{"); + ostr.println(" if (jjrounds[state] != jjround)"); + ostr.println(" {"); + ostr.println(" jjstateSet[jjnewStateCnt++] = state;"); + ostr.println(" jjrounds[state] = jjround;"); + ostr.println(" }"); + ostr.println("}"); + + ostr.println((Options.getStatic() ? "static " : "") + "private void " + + "jjAddStates(int start, int end)"); + ostr.println("{"); + ostr.println(" do {"); + ostr.println(" jjstateSet[jjnewStateCnt++] = jjnextStates[start];"); + ostr.println(" } while (start++ != end);"); + ostr.println("}"); + + ostr.println((Options.getStatic() ? "static " : "") + "private void " + + "jjCheckNAddTwoStates(int state1, int state2)"); + ostr.println("{"); + ostr.println(" jjCheckNAdd(state1);"); + ostr.println(" jjCheckNAdd(state2);"); + ostr.println("}"); + + ostr.println((Options.getStatic() ? "static " : "") + "private void " + + "jjCheckNAddStates(int start, int end)"); + ostr.println("{"); + ostr.println(" do {"); + ostr.println(" jjCheckNAdd(jjnextStates[start]);"); + ostr.println(" } while (start++ != end);"); + ostr.println("}"); + + ostr.println((Options.getStatic() ? "static " : "") + "private void " + + "jjCheckNAddStates(int start)"); + ostr.println("{"); + ostr.println(" jjCheckNAdd(jjnextStates[start]);"); + ostr.println(" jjCheckNAdd(jjnextStates[start + 1]);"); + ostr.println("}"); + } + + private static void FindStatesWithNoBreak() + { + Hashtable printed = new Hashtable(); + boolean[] put = new boolean[generatedStates]; + int cnt = 0; + int i, j, foundAt = 0; + + Outer : + for (j = 0; j < allStates.size(); j++) + { + NfaState stateForCase = null; + NfaState tmpState = (NfaState)allStates.elementAt(j); + + if (tmpState.stateName == -1 || tmpState.dummy || !tmpState.UsefulState() || + tmpState.next == null || tmpState.next.usefulEpsilonMoves < 1) + continue; + + String s = tmpState.next.epsilonMovesString; + + if (compositeStateTable.get(s) != null || printed.get(s) != null) + continue; + + printed.put(s, s); + int[] nexts = (int[])allNextStates.get(s); + + if (nexts.length == 1) + continue; + + int state = cnt; + //System.err.println("State " + tmpState.stateName + " : " + s); + for (i = 0; i < nexts.length; i++) + { + if ((state = nexts[i]) == -1) + continue; + + NfaState tmp = (NfaState)allStates.elementAt(state); + + if (!tmp.isComposite && tmp.inNextOf == 1) + { + if (put[state]) + throw new Error("JavaCC Bug: Please send mail to sankar@cs.stanford.edu"); + + foundAt = i; + cnt++; + stateForCase = tmp; + put[state] = true; + + //System.err.print(state + " : " + tmp.inNextOf + ", "); + break; + } + } + //System.err.println(""); + + if (stateForCase == null) + continue; + + for (i = 0; i < nexts.length; i++) + { + if ((state = nexts[i]) == -1) + continue; + + NfaState tmp = (NfaState)allStates.elementAt(state); + + if (!put[state] && tmp.inNextOf > 1 && !tmp.isComposite && tmp.stateForCase == null) + { + cnt++; + nexts[i] = -1; + put[state] = true; + + int toSwap = nexts[0]; + nexts[0] = nexts[foundAt]; + nexts[foundAt] = toSwap; + + tmp.stateForCase = stateForCase; + stateForCase.stateForCase = tmp; + stateSetsToFix.put(s, nexts); + + //System.err.println("For : " + s + "; " + stateForCase.stateName + + //" and " + tmp.stateName); + + continue Outer; + } + } + + for (i = 0; i < nexts.length; i++) + { + if ((state = nexts[i]) == -1) + continue; + + NfaState tmp = (NfaState)allStates.elementAt(state); + if (tmp.inNextOf <= 1) + put[state] = false; + } + } + } + + static int[][] kinds; + static int[][][] statesForState; + public static void DumpMoveNfa(java.io.PrintWriter ostr) + { + if (!boilerPlateDumped) + PrintBoilerPlate(ostr); + + boilerPlateDumped = true; + int i; + int[] kindsForStates = null; + + if (kinds == null) + { + kinds = new int[LexGen.maxLexStates][]; + statesForState = new int[LexGen.maxLexStates][][]; + } + + ReArrange(); + + for (i = 0; i < allStates.size(); i++) + { + NfaState temp = (NfaState)allStates.elementAt(i); + + if (temp.lexState != LexGen.lexStateIndex || + !temp.HasTransitions() || temp.dummy || + temp.stateName == -1) + continue; + + if (kindsForStates == null) + { + kindsForStates = new int[generatedStates]; + statesForState[LexGen.lexStateIndex] = new int[Math.max(generatedStates, dummyStateIndex + 1)][]; + } + + kindsForStates[temp.stateName] = temp.lookingFor; + statesForState[LexGen.lexStateIndex][temp.stateName] = temp.compositeStates; + + temp.GenerateNonAsciiMoves(ostr); + } + + Enumeration e = stateNameForComposite.keys(); + + while (e.hasMoreElements()) + { + String s = (String)e.nextElement(); + int state = ((Integer)stateNameForComposite.get(s)).intValue(); + + if (state >= generatedStates) + statesForState[LexGen.lexStateIndex][state] = (int[])allNextStates.get(s); + } + + if (stateSetsToFix.size() != 0) + FixStateSets(); + + kinds[LexGen.lexStateIndex] = kindsForStates; + + ostr.println((Options.getStatic() ? "static " : "") + "private int " + + "jjMoveNfa" + LexGen.lexStateSuffix + "(int startState, int curPos)"); + ostr.println("{"); + + if (generatedStates == 0) + { + ostr.println(" return curPos;"); + ostr.println("}"); + return; + } + + if (LexGen.mixed[LexGen.lexStateIndex]) + { + ostr.println(" int strKind = jjmatchedKind;"); + ostr.println(" int strPos = jjmatchedPos;"); + ostr.println(" int seenUpto;"); + ostr.println(" input_stream.backup(seenUpto = curPos + 1);"); + ostr.println(" try { curChar = input_stream.readChar(); }"); + ostr.println(" catch(System.IO.IOException e) { throw new Error(\"Internal Error\"); }"); + ostr.println(" curPos = 0;"); + } + + ostr.println(" int[] nextStates;"); + ostr.println(" int startsAt = 0;"); + ostr.println(" jjnewStateCnt = " + generatedStates + ";"); + ostr.println(" int i = 1;"); + ostr.println(" jjstateSet[0] = startState;"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(\" Starting NFA to match one of : \" + " + + "jjKindsForStateVector(curLexState, jjstateSet, 0, 1));"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(" + (LexGen.maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + "\"Current character : \" + " + + "TokenMgrError.addEscapes(\"\"+(curChar)) + \" (\" + (int)curChar + \") at line \" + input_stream.getLine() + \" column \" + input_stream.getColumn());"); + + ostr.println(" int j, kind = 0x" + Integer.toHexString(Integer.MAX_VALUE) + ";"); + ostr.println(" for (;;)"); + ostr.println(" {"); + ostr.println(" if (++jjround == 0x" + Integer.toHexString(Integer.MAX_VALUE) + ")"); + ostr.println(" ReInitRounds();"); + ostr.println(" if (curChar < 64)"); + ostr.println(" {"); + + DumpAsciiMoves(ostr, 0); + + ostr.println(" }"); + + ostr.println(" else if (curChar < 128)"); + + ostr.println(" {"); + + DumpAsciiMoves(ostr, 1); + + ostr.println(" }"); + + ostr.println(" else"); + ostr.println(" {"); + + DumpCharAndRangeMoves(ostr); + + ostr.println(" }"); + + ostr.println(" if (kind != 0x" + Integer.toHexString(Integer.MAX_VALUE) + ")"); + ostr.println(" {"); + ostr.println(" jjmatchedKind = kind;"); + ostr.println(" jjmatchedPos = curPos;"); + ostr.println(" kind = 0x" + Integer.toHexString(Integer.MAX_VALUE) + ";"); + ostr.println(" }"); + ostr.println(" ++curPos;"); + + if (Options.getDebugTokenManager()) + { + ostr.println(" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + Integer.toHexString(Integer.MAX_VALUE) + ")"); + ostr.println(" debugStream.WriteLine(\" Currently matched the first \" + (jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); + } + + ostr.println(" if ((i = jjnewStateCnt) == (startsAt = " + + generatedStates + " - (jjnewStateCnt = startsAt)))"); + if (LexGen.mixed[LexGen.lexStateIndex]) + ostr.println(" break;"); + else + ostr.println(" return curPos;"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(\" Possible kinds of longer matches : \" + " + + "jjKindsForStateVector(curLexState, jjstateSet, startsAt, i));"); + + ostr.println(" try { curChar = input_stream.readChar(); }"); + + if (LexGen.mixed[LexGen.lexStateIndex]) + ostr.println(" catch(System.IO.IOException e) { break; }"); + else + ostr.println(" catch(System.IO.IOException e) { return curPos; }"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(" + (LexGen.maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + "\"Current character : \" + " + + "TokenMgrError.addEscapes(\"\"+(curChar)) + \" (\" + (int)curChar + \") at line \" + input_stream.getLine() + \" column \" + input_stream.getColumn());"); + + ostr.println(" }"); + + if (LexGen.mixed[LexGen.lexStateIndex]) + { + ostr.println(" if (jjmatchedPos > strPos)"); + ostr.println(" return curPos;"); + ostr.println(""); + ostr.println(" int toRet = Math.max(curPos, seenUpto);"); + ostr.println(""); + ostr.println(" if (curPos < toRet)"); + ostr.println(" for (i = toRet - Math.min(curPos, seenUpto); i-- > 0; )"); + ostr.println(" try { curChar = input_stream.readChar(); }"); + ostr.println(" catch(System.IO.IOException e) { throw new Error(\"Internal Error : Please send a bug report.\"); }"); + ostr.println(""); + ostr.println(" if (jjmatchedPos < strPos)"); + ostr.println(" {"); + ostr.println(" jjmatchedKind = strKind;"); + ostr.println(" jjmatchedPos = strPos;"); + ostr.println(" }"); + ostr.println(" else if (jjmatchedPos == strPos && jjmatchedKind > strKind)"); + ostr.println(" jjmatchedKind = strKind;"); + ostr.println(""); + ostr.println(" return toRet;"); + } + + ostr.println("}"); + allStates.removeAllElements(); + } + + public static void DumpStatesForState(java.io.PrintWriter ostr) + { + ostr.print("protected static int[][][] statesForState = "); + + if (statesForState == null){ + ostr.println("null;"); + return; + }else + ostr.println("new int[][][]{"); + + for (int i = 0; i < statesForState.length; i++){ + if (statesForState[i] == null){ + ostr.println(" null, "); + continue; + } + + ostr.println(" new int[][]{"); + + for (int j = 0; j < statesForState[i].length; j++){ + int[] stateSet = statesForState[i][j]; + + if (stateSet == null){ + ostr.println(" new int[]{ " + j + " }, "); + continue; + } + + ostr.print(" new int[]{ "); + + for (int k = 0; k < stateSet.length; k++) + ostr.print(stateSet[k] + ", "); + + ostr.println("},"); + } + ostr.println(" },"); + } + ostr.println("\n};"); + } + + public static void DumpStatesForKind(java.io.PrintWriter ostr) + { + DumpStatesForState(ostr); + boolean moreThanOne = false; + int cnt = 0; + + ostr.print("protected static int[][] kindForState = "); + + if (kinds == null){ + ostr.println("null;"); + return; + }else + ostr.println("{"); + + for (int i = 0; i < kinds.length; i++){ + if (moreThanOne) + ostr.println(", "); + moreThanOne = true; + + if (kinds[i] == null) + ostr.println("null"); + else{ + cnt = 0; + ostr.print("new int[]{ "); + for (int j = 0; j < kinds[i].length; j++){ + if (cnt++ > 0) + ostr.print(", "); + + if (cnt % 15 == 0) + ostr.print("\n "); + + ostr.print(kinds[i][j]); + } + ostr.print("}"); + } + } + ostr.println("\n};"); + } + + public static void reInit() + { + unicodeWarningGiven = false; + generatedStates = 0; + idCnt = 0; + lohiByteCnt = 0; + dummyStateIndex = -1; + done = false; + mark = null; + stateDone = null; + nonAsciiIntersections = new boolean[20][20]; + allStates = new Vector(); + indexedAllStates = new Vector(); + nonAsciiTableForMethod = new Vector(); + equivStatesTable = new Hashtable(); + allNextStates = new Hashtable(); + lohiByteTab = new Hashtable(); + stateNameForComposite = new Hashtable(); + compositeStateTable = new Hashtable(); + stateBlockTable = new Hashtable(); + stateSetsToFix = new Hashtable(); + allBitVectors = new Vector(); + tmpIndices = new int[512]; + allBits = "{\n 0xffffffffffffffffL, " + + "0xffffffffffffffffL, " + + "0xffffffffffffffffL, " + + "0xffffffffffffffffL\n};"; + tableToDump = new Hashtable(); + orderedStateSet = new Vector(); + lastIndex = 0; + boilerPlateDumped = false; + kinds = null; + statesForState = null; + } + +} diff --git a/csjavacc/parser/NormalProduction.java b/csjavacc/parser/NormalProduction.java new file mode 100644 index 0000000..fcf4fcc --- /dev/null +++ b/csjavacc/parser/NormalProduction.java @@ -0,0 +1,105 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import csjavacc.struct.Expansion; + +/** + * Describes JavaCC productions. + */ + +public class NormalProduction { + + /** + * The line and column number of the construct that corresponds + * most closely to this node. + */ + public int line, column; + + /** + * The NonTerminal nodes which refer to this production. + */ + java.util.Vector parents = new java.util.Vector(); + + /** + * The access modifier of this production. + */ + public String accessMod; + + /** + * The name of the non-terminal of this production. + */ + public String lhs; + + /** + * The tokens that make up the return type of this production. + */ + public java.util.Vector return_type_tokens = new java.util.Vector(); + + /** + * The tokens that make up the parameters of this production. + */ + public java.util.Vector parameter_list_tokens = new java.util.Vector(); + + /** + * Each entry in this vector is a vector of tokens that represents an + * exception in the throws list of this production. This list does not + * include ParseException which is always thrown. + */ + public java.util.Vector throws_list = new java.util.Vector(); + + /** + * The RHS of this production. Not used for JavaCodeProduction. + */ + public Expansion expansion; + + /** + * This boolean flag is true if this production can expand to empty. + */ + boolean emptyPossible = false; + + /** + * A list of all non-terminals that this one can expand to without + * having to consume any tokens. Also an index that shows how many + * pointers exist. + */ + NormalProduction[] leftExpansions = new NormalProduction[10]; + int leIndex = 0; + + /** + * The following variable is used to maintain state information for the + * left-recursion determination algorithm: It is initialized to 0, and + * set to -1 if this node has been visited in a pre-order walk, and then + * it is set to 1 if the pre-order walk of the whole graph from this + * node has been traversed. i.e., -1 indicates partially processed, + * and 1 indicates fully processed. + */ + int walkStatus = 0; + + /** + * The first and last tokens from the input stream that represent this + * production. + */ + public Token firstToken, lastToken; + +} diff --git a/csjavacc/parser/OneOrMore.java b/csjavacc/parser/OneOrMore.java new file mode 100644 index 0000000..5cdef7b --- /dev/null +++ b/csjavacc/parser/OneOrMore.java @@ -0,0 +1,38 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import csjavacc.struct.Expansion; + +/** + * Describes one-or-more expansions (e.g., foo+). + */ + +public class OneOrMore extends Expansion { + + /** + * The expansion which is repeated one or more times. + */ + public Expansion expansion; + +} diff --git a/csjavacc/parser/Options.java b/csjavacc/parser/Options.java new file mode 100644 index 0000000..17f4547 --- /dev/null +++ b/csjavacc/parser/Options.java @@ -0,0 +1,518 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.io.File; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * A class with static state that stores all option information. + */ +public class Options { + + /** + * Limit subclassing to derived classes. + */ + protected Options() { + } + + /** + * A mapping of option names (Strings) to values (Integer, Boolean, String). + * This table is initialized by the main program. Its contents defines the + * set of legal options. Its initial values define the default option + * values, and the option types can be determined from these values too. + */ + protected static Map optionValues = null; + + /** + * Convenience method to retrieve integer options. + */ + protected static int intValue(final String option) { + return ((Integer) optionValues.get(option)).intValue(); + } + + /** + * Convenience method to retrieve boolean options. + */ + protected static boolean booleanValue(final String option) { + return ((Boolean) optionValues.get(option)).booleanValue(); + } + + /** + * Convenience method to retrieve string options. + */ + protected static String stringValue(final String option) { + return (String) optionValues.get(option); + } + + /** + * Keep track of what options were set as a command line argument. We use + * this to see if the options set from the command line and the ones set in + * the input files clash in any way. + */ + private static Set cmdLineSetting = null; + + /** + * Keep track of what options were set from the grammar file. We use this to + * see if the options set from the command line and the ones set in the + * input files clash in any way. + */ + private static Set inputFileSetting = null; + + /** + * Initialize for JavaCC + */ + public static void init() { + optionValues = new HashMap(); + cmdLineSetting = new HashSet(); + inputFileSetting = new HashSet(); + + optionValues.put("LOOKAHEAD", new Integer(1)); + optionValues.put("CHOICE_AMBIGUITY_CHECK", new Integer(2)); + optionValues.put("OTHER_AMBIGUITY_CHECK", new Integer(1)); + + optionValues.put("STATIC", Boolean.TRUE); + optionValues.put("DEBUG_PARSER", Boolean.FALSE); + optionValues.put("DEBUG_LOOKAHEAD", Boolean.FALSE); + optionValues.put("DEBUG_TOKEN_MANAGER", Boolean.FALSE); + optionValues.put("ERROR_REPORTING", Boolean.TRUE); + optionValues.put("CS_UNICODE_ESCAPE", Boolean.FALSE); + optionValues.put("UNICODE_INPUT", Boolean.FALSE); + optionValues.put("IGNORE_CASE", Boolean.FALSE); + optionValues.put("USER_TOKEN_MANAGER", Boolean.FALSE); + optionValues.put("USER_CHAR_STREAM", Boolean.FALSE); + optionValues.put("BUILD_PARSER", Boolean.TRUE); + optionValues.put("BUILD_TOKEN_MANAGER", Boolean.TRUE); + optionValues.put("TOKEN_MANAGER_USES_PARSER", Boolean.FALSE); + optionValues.put("SANITY_CHECK", Boolean.TRUE); + optionValues.put("FORCE_LA_CHECK", Boolean.FALSE); + optionValues.put("COMMON_TOKEN_ACTION", Boolean.FALSE); + optionValues.put("CACHE_TOKENS", Boolean.FALSE); + optionValues.put("KEEP_LINE_COLUMN", Boolean.TRUE); + + optionValues.put("OUTPUT_DIRECTORY", "."); + } + + /** + * Determine if a given command line argument might be an option flag. + * Command line options start with a dash (-). + * + * @param opt + * The command line argument to examine. + * @return True when the argument looks like an option flag. + */ + public static boolean isOption(final String opt) { + return opt != null && opt.length() > 1 && opt.charAt(0) == '-'; + } + + public static void setInputFileOption(Object nameloc, Object valueloc, + String name, int value) { + String s = name.toUpperCase(); + if (!optionValues.containsKey(s)) { + CSJavaCCErrors.warning(nameloc, "Bad option name \"" + name + + "\". Option setting will be ignored."); + return; + } + Object Val = optionValues.get(s); + if (Val != null) { + if (!(Val instanceof Integer) || value <= 0) { + CSJavaCCErrors.warning(valueloc, "Bad option value \"" + value + + "\" for \"" + name + + "\". Option setting will be ignored."); + return; + } + if (inputFileSetting.contains(s)) { + CSJavaCCErrors.warning(nameloc, "Duplicate option setting for \"" + + name + "\" will be ignored."); + return; + } + if (cmdLineSetting.contains(s)) { + if (((Integer) Val).intValue() != value) { + CSJavaCCErrors.warning(nameloc, "Command line setting of \"" + + name + "\" modifies option value in file."); + } + return; + } + } + + optionValues.put(s, new Integer(value)); + inputFileSetting.add(s); + } + + public static void setInputFileOption(Object nameloc, Object valueloc, + String name, boolean value) { + String s = name.toUpperCase(); + if (!optionValues.containsKey(s)) { + CSJavaCCErrors.warning(nameloc, "Bad option name \"" + name + + "\". Option setting will be ignored."); + return; + } + Object Val = optionValues.get(s); + if (Val != null) { + if (!(Val instanceof Boolean)) { + CSJavaCCErrors.warning(valueloc, "Bad option value \"" + value + + "\" for \"" + name + + "\". Option setting will be ignored."); + return; + } + if (inputFileSetting.contains(s)) { + CSJavaCCErrors.warning(nameloc, "Duplicate option setting for \"" + + name + "\" will be ignored."); + return; + } + if (cmdLineSetting.contains(s)) { + if (((Boolean) Val).booleanValue() != value) { + CSJavaCCErrors.warning(nameloc, "Command line setting of \"" + + name + "\" modifies option value in file."); + } + return; + } + } + + optionValues.put(s, (value ? Boolean.TRUE : Boolean.FALSE)); + inputFileSetting.add(s); + } + + public static void setInputFileOption(Object nameloc, Object valueloc, + String name, String value) { + String s = name.toUpperCase(); + if (!optionValues.containsKey(s)) { + CSJavaCCErrors.warning(nameloc, "Bad option name \"" + name + + "\". Option setting will be ignored."); + return; + } + Object Val = optionValues.get(s); + if (Val != null) { + if (!(Val instanceof String)) { + CSJavaCCErrors.warning(valueloc, "Bad option value \"" + value + + "\" for \"" + name + + "\". Option setting will be ignored."); + return; + } + if (inputFileSetting.contains(s)) { + CSJavaCCErrors.warning(nameloc, "Duplicate option setting for \"" + + name + "\" will be ignored."); + return; + } + if (cmdLineSetting.contains(s)) { + if (!Val.equals(value)) { + CSJavaCCErrors.warning(nameloc, "Command line setting of \"" + + name + "\" modifies option value in file."); + } + return; + } + } + + optionValues.put(s, value); + inputFileSetting.add(s); + } + + /** + * + * @param arg + */ + public static void setCmdLineOption(String arg) { + String s = arg.toUpperCase(); + int index = 0; + String name; + Object Val; + while (index < s.length() && s.charAt(index) != '=' + && s.charAt(index) != ':') { + index++; + } + if (index < 2 || index >= s.length() - 1) { + if (index == s.length()) { + if (s.length() > 3 && s.charAt(1) == 'N' && s.charAt(2) == 'O') { + name = s.substring(3); + Val = Boolean.FALSE; + } else { + name = s.substring(1); + Val = Boolean.TRUE; + } + } else { + System.err.println("Warning: Bad option \"" + arg + + "\" will be ignored."); + return; + } + } else { + if (s.substring(index + 1).equals("TRUE")) { + Val = Boolean.TRUE; + } else if (s.substring(index + 1).equals("FALSE")) { + Val = Boolean.FALSE; + } else { + try { + int i = Integer.parseInt(s.substring(index + 1)); + if (i <= 0) { + System.err.println("Warning: Bad option value in \"" + + arg + "\" will be ignored."); + return; + } + Val = new Integer(i); + } catch (NumberFormatException e) { + Val = arg.substring(index + 1); + if (arg.length() > index + 2) { + // i.e., there is space for two '"'s in value + if (arg.charAt(index + 1) == '"' + && arg.charAt(arg.length() - 1) == '"') { + // remove the two '"'s. + Val = arg.substring(index + 2, arg.length() - 1); + } + } + } + } + name = s.substring(1, index); + } + if (!optionValues.containsKey(name)) { + System.err.println("Warning: Bad option \"" + arg + + "\" will be ignored."); + return; + } + Object valOrig = optionValues.get(name); + if (Val.getClass() != valOrig.getClass()) { + System.err.println("Warning: Bad option value in \"" + arg + + "\" will be ignored."); + return; + } + if (cmdLineSetting.contains(name)) { + System.err.println("Warning: Duplicate option setting \"" + arg + + "\" will be ignored."); + return; + } + + optionValues.put(name, Val); + cmdLineSetting.add(name); + } + + public static void normalize() { + if (getDebugLookahead() && !getDebugParser()) { + if (cmdLineSetting.contains("DEBUG_PARSER") + || inputFileSetting.contains("DEBUG_PARSER")) { + CSJavaCCErrors + .warning("True setting of option DEBUG_LOOKAHEAD overrides false setting of option DEBUG_PARSER."); + } + optionValues.put("DEBUG_PARSER", Boolean.TRUE); + } + } + + /** + * Find the lookahead setting. + * + * @return The requested lookahead value. + */ + public static int getLookahead() { + return intValue("LOOKAHEAD"); + } + + /** + * Find the choice ambiguity check value. + * + * @return The requested choice ambiguity check value. + */ + public static int getChoiceAmbiguityCheck() { + return intValue("CHOICE_AMBIGUITY_CHECK"); + } + + /** + * Find the other ambiguity check value. + * + * @return The requested other ambiguity check value. + */ + public static int getOtherAmbiguityCheck() { + return intValue("OTHER_AMBIGUITY_CHECK"); + } + + /** + * Find the static value. + * + * @return The requested static value. + */ + public static boolean getStatic() { + return booleanValue("STATIC"); + } + + /** + * Find the debug parser value. + * + * @return The requested debug parser value. + */ + public static boolean getDebugParser() { + return booleanValue("DEBUG_PARSER"); + } + + /** + * Find the debug lookahead value. + * + * @return The requested debug lookahead value. + */ + public static boolean getDebugLookahead() { + return booleanValue("DEBUG_LOOKAHEAD"); + } + + /** + * Find the debug tokenmanager value. + * + * @return The requested debug tokenmanager value. + */ + public static boolean getDebugTokenManager() { + return booleanValue("DEBUG_TOKEN_MANAGER"); + } + + /** + * Find the error reporting value. + * + * @return The requested error reporting value. + */ + public static boolean getErrorReporting() { + return booleanValue("ERROR_REPORTING"); + } + + /** + * Find the Java unicode escape value. + * + * @return The requested Java unicode escape value. + */ + public static boolean getCSUnicodeEscape() { + return booleanValue("CS_UNICODE_ESCAPE"); + } + + /** + * Find the unicode input value. + * + * @return The requested unicode input value. + */ + public static boolean getUnicodeInput() { + return booleanValue("UNICODE_INPUT"); + } + + /** + * Find the ignore case value. + * + * @return The requested ignore case value. + */ + public static boolean getIgnoreCase() { + return booleanValue("IGNORE_CASE"); + } + + /** + * Find the user tokenmanager value. + * + * @return The requested user tokenmanager value. + */ + public static boolean getUserTokenManager() { + return booleanValue("USER_TOKEN_MANAGER"); + } + + /** + * Find the user charstream value. + * + * @return The requested user charstream value. + */ + public static boolean getUserCharStream() { + return booleanValue("USER_CHAR_STREAM"); + } + + /** + * Find the build parser value. + * + * @return The requested build parser value. + */ + public static boolean getBuildParser() { + return booleanValue("BUILD_PARSER"); + } + + /** + * Find the build token manager value. + * + * @return The requested build token manager value. + */ + public static boolean getBuildTokenManager() { + return booleanValue("BUILD_TOKEN_MANAGER"); + } + + /** + * Find the token manager uses parser value. + * + * @return The requested token manager uses parser value; + */ + public static boolean getTokenManagerUsesParser(){ + return booleanValue("TOKEN_MANAGER_USES_PARSER"); + } + + /** + * Find the sanity check value. + * + * @return The requested sanity check value. + */ + public static boolean getSanityCheck() { + return booleanValue("SANITY_CHECK"); + } + + /** + * Find the force lookahead check value. + * + * @return The requested force lookahead value. + */ + public static boolean getForceLaCheck() { + return booleanValue("FORCE_LA_CHECK"); + } + + /** + * Find the common token action value. + * + * @return The requested common token action value. + */ + + public static boolean getCommonTokenAction() { + return booleanValue("COMMON_TOKEN_ACTION"); + } + + /** + * Find the cache tokens value. + * + * @return The requested cache tokens value. + */ + public static boolean getCacheTokens() { + return booleanValue("CACHE_TOKENS"); + } + + /** + * Find the keep line column value. + * + * @return The requested keep line column value. + */ + public static boolean getKeepLineColumn() { + return booleanValue("KEEP_LINE_COLUMN"); + } + + /** + * Find the output directory. + * + * @return The requested output directory. + */ + public static File getOutputDirectory() { + return new File(stringValue("OUTPUT_DIRECTORY")); + } +} diff --git a/csjavacc/parser/OtherFilesGen.java b/csjavacc/parser/OtherFilesGen.java new file mode 100644 index 0000000..e4bbf7c --- /dev/null +++ b/csjavacc/parser/OtherFilesGen.java @@ -0,0 +1,147 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import csjavacc.struct.RegularExpression; +import csjavacc.struct.TokenProduction; + + +public class OtherFilesGen extends CSJavaCCGlobals implements CSJavaCCParserConstants { + + public static boolean keepLineCol; + static public void start() throws MetaParseException { + + Token t = null; + keepLineCol = Options.getKeepLineColumn(); + + if (CSJavaCCErrors.get_error_count() != 0) throw new MetaParseException(); + + CSJavaFiles.gen_TokenMgrError(); + CSJavaFiles.gen_ParseException(); + CSJavaFiles.gen_Token(); + if (Options.getUserTokenManager()) { + CSJavaFiles.gen_TokenManager(); + } else if (Options.getUserCharStream()) { + CSJavaFiles.gen_CharStream(); + } else { + if (Options.getCSUnicodeEscape()) { + CSJavaFiles.gen_CSCharStream(); + } else { + CSJavaFiles.gen_SimpleCharStream(); + } + } + + try { + ostr = new java.io.PrintWriter( + new java.io.BufferedWriter( + new java.io.FileWriter( + new java.io.File(Options.getOutputDirectory(), cu_name + "Constants"+extension) + ), + 8192 + ) + ); + } catch (java.io.IOException e) { + CSJavaCCErrors.semantic_error("Could not open file " + cu_name + "Constants"+extension+" for writing."); + throw new Error(); + } + boolean namespace = false; + java.util.Vector tn = (java.util.Vector)(toolNames.clone()); + tn.addElement(toolName); + ostr.println("/* " + getIdString(tn, cu_name + "Constants"+extension) + " */"); + + if (cu_to_insertion_point_1.size() != 0 && + ((Token)cu_to_insertion_point_1.elementAt(0)).kind == NAMESPACE + ) { + for (int i = 1; i < cu_to_insertion_point_1.size(); i++) { + if (((Token)cu_to_insertion_point_1.elementAt(i)).kind == SEMICOLON) { + printTokenSetup((Token)(cu_to_insertion_point_1.elementAt(0))); + for (int j = 0; j < i; j++) { + t = (Token)(cu_to_insertion_point_1.elementAt(j)); + printToken(t, ostr); + } + namespace = true; + ostr.println("{"); + printTrailingComments(t, ostr); + ostr.println(""); + ostr.println(""); + break; + } + } + } + ostr.println("using System;"); + ostr.println("public class " + cu_name + "Constants {"); + ostr.println(""); + RegularExpression re; + ostr.println(" public const int EOF = 0;"); + for (java.util.Enumeration anEnum = ordered_named_tokens.elements(); anEnum.hasMoreElements();) { + re = (RegularExpression)anEnum.nextElement(); + ostr.println(" public const int " + re.label + " = " + re.ordinal + ";"); + } + ostr.println(""); + if (!Options.getUserTokenManager() && Options.getBuildTokenManager()) { + for (int i = 0; i < LexGen.lexStateName.length; i++) { + ostr.println(" public const int " + LexGen.lexStateName[i] + " = " + i + ";"); + } + ostr.println(""); + } + ostr.println(" public String[] tokenImage = {"); + ostr.println(" \"\","); + + for (java.util.Enumeration anEnum = rexprlist.elements(); anEnum.hasMoreElements();) { + TokenProduction tp = (TokenProduction)(anEnum.nextElement()); + java.util.Vector respecs = tp.respecs; + for (java.util.Enumeration enum1 = respecs.elements(); enum1.hasMoreElements();) { + RegExprSpec res = (RegExprSpec)(enum1.nextElement()); + re = res.rexp; + if (re instanceof RStringLiteral) { + ostr.println(" \"\\\"" + add_escapes(add_escapes(((RStringLiteral)re).image)) + "\\\"\","); + } else if (!re.label.equals("")) { + ostr.println(" \"<" + re.label + ">\","); + } else { + if (re.tpContext.kind == TokenProduction.TOKEN) { + CSJavaCCErrors.warning(re, "Consider giving this non-string token a label for better error reporting."); + } + ostr.println(" \"\","); + } + + } + } + ostr.println(" };"); + ostr.println(""); + ostr.println("}"); + + if(namespace) + ostr.println("}"); + + ostr.close(); + + } + + static private java.io.PrintWriter ostr; + + public static void reInit() + { + ostr = null; + } + +} diff --git a/csjavacc/parser/ParseEngine.java b/csjavacc/parser/ParseEngine.java new file mode 100644 index 0000000..fd5a7e3 --- /dev/null +++ b/csjavacc/parser/ParseEngine.java @@ -0,0 +1,1224 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.util.Hashtable; + +import csjavacc.struct.Action; +import csjavacc.struct.BNFProduction; +import csjavacc.struct.Choice; +import csjavacc.struct.Expansion; +import csjavacc.struct.CSCodeProduction; +import csjavacc.struct.Lookahead; +import csjavacc.struct.NonTerminal; +import csjavacc.struct.RegularExpression; +import csjavacc.struct.TryBlock; +import csjavacc.struct.ZeroOrMore; +import csjavacc.struct.ZeroOrOne; + + +public class ParseEngine extends CSJavaCCGlobals { + + static private java.io.PrintWriter ostr; + static private int gensymindex = 0; + static private int indentamt; + static private boolean jj2LA; + + /** + * These lists are used to maintain expansions for which code generation + * in phase 2 and phase 3 is required. Whenever a call is generated to + * a phase 2 or phase 3 routine, a corresponding entry is added here if + * it has not already been added. + * The phase 3 routines have been optimized in version 0.7pre2. Essentially + * only those methods (and only those portions of these methods) are + * generated that are required. The lookahead amount is used to determine + * this. This change requires the use of a hash table because it is now + * possible for the same phase 3 routine to be requested multiple times + * with different lookaheads. The hash table provides a easily searchable + * capability to determine the previous requests. + * The phase 3 routines now are performed in a two step process - the first + * step gathers the requests (replacing requests with lower lookaheads with + * those requiring larger lookaheads). The second step then generates these + * methods. + * This optimization and the hashtable makes it look like we do not need + * the flag "phase3done" any more. But this has not been removed yet. + */ + static private java.util.Vector phase2list = new java.util.Vector(); + static private java.util.Vector phase3list = new java.util.Vector(); + static private java.util.Hashtable phase3table = new java.util.Hashtable(); + + /** + * The phase 1 routines generates their output into String's and dumps + * these String's once for each method. These String's contain the + * special characters '\u0001' to indicate a positive indent, and '\u0002' + * to indicate a negative indent. '\n' is used to indicate a line terminator. + * The characters '\u0003' and '\u0004' are used to delineate portions of + * text where '\n's should not be followed by an indentation. + */ + + /** + * Returns true if there is a CSCODE production that the argument expansion + * may directly expand to (without consuming tokens). + */ + static private boolean csCodeCheck(Expansion exp) { + if (exp instanceof RegularExpression) { + return false; + } else if (exp instanceof NonTerminal) { + NormalProduction prod = ((NonTerminal)exp).prod; + if (prod instanceof CSCodeProduction) { + return true; + } else { + return csCodeCheck(prod.expansion); + } + } else if (exp instanceof Choice) { + Choice ch = (Choice)exp; + for (int i = 0; i < ch.choices.size(); i++) { + if (csCodeCheck((Expansion)(ch.choices.elementAt(i)))) { + return true; + } + } + return false; + } else if (exp instanceof Sequence) { + Sequence seq = (Sequence)exp; + for (int i = 0; i < seq.units.size(); i++) { + if (csCodeCheck((Expansion)(seq.units.elementAt(i)))) { + return true; + } else if (!Semanticize.emptyExpansionExists((Expansion)(seq.units.elementAt(i)))) { + return false; + } + } + return false; + } else if (exp instanceof OneOrMore) { + OneOrMore om = (OneOrMore)exp; + return csCodeCheck(om.expansion); + } else if (exp instanceof ZeroOrMore) { + ZeroOrMore zm = (ZeroOrMore)exp; + return csCodeCheck(zm.expansion); + } else if (exp instanceof ZeroOrOne) { + ZeroOrOne zo = (ZeroOrOne)exp; + return csCodeCheck(zo.expansion); + } else if (exp instanceof TryBlock) { + TryBlock tb = (TryBlock)exp; + return csCodeCheck(tb.exp); + } else { + return false; + } + } + + /** + * An array used to store the first sets generated by the following method. + * A true entry means that the corresponding token is in the first set. + */ + static private boolean[] firstSet; + + /** + * Sets up the array "firstSet" above based on the Expansion argument + * passed to it. Since this is a recursive function, it assumes that + * "firstSet" has been reset before the first call. + */ + static private void genFirstSet(Expansion exp) { + if (exp instanceof RegularExpression) { + firstSet[((RegularExpression)exp).ordinal] = true; + } else if (exp instanceof NonTerminal) { + genFirstSet(((BNFProduction)(((NonTerminal)exp).prod)).expansion); + } else if (exp instanceof Choice) { + Choice ch = (Choice)exp; + for (int i = 0; i < ch.choices.size(); i++) { + genFirstSet((Expansion)(ch.choices.elementAt(i))); + } + } else if (exp instanceof Sequence) { + Sequence seq = (Sequence)exp; + Object obj = seq.units.elementAt(0); + if ((obj instanceof Lookahead) && (((Lookahead)obj).action_tokens.size() != 0)) { + jj2LA = true; + } + for (int i = 0; i < seq.units.size(); i++) { + genFirstSet((Expansion)(seq.units.elementAt(i))); + if (!Semanticize.emptyExpansionExists((Expansion)(seq.units.elementAt(i)))) { + break; + } + } + } else if (exp instanceof OneOrMore) { + OneOrMore om = (OneOrMore)exp; + genFirstSet(om.expansion); + } else if (exp instanceof ZeroOrMore) { + ZeroOrMore zm = (ZeroOrMore)exp; + genFirstSet(zm.expansion); + } else if (exp instanceof ZeroOrOne) { + ZeroOrOne zo = (ZeroOrOne)exp; + genFirstSet(zo.expansion); + } else if (exp instanceof TryBlock) { + TryBlock tb = (TryBlock)exp; + genFirstSet(tb.exp); + } + } + + /** + * Constants used in the following method "buildLookaheadChecker". + */ + static final int NOOPENSTM = 0; + static final int OPENIF = 1; + static final int OPENSWITCH = 2; + + /** + * This method takes two parameters - an array of Lookahead's + * "conds", and an array of String's "actions". "actions" contains + * exactly one element more than "conds". "actions" are Java source + * code, and "conds" translate to conditions - so lets say + * "f(conds[i])" is true if the lookahead required by "conds[i]" is + * indeed the case. This method returns a string corresponding to + * the Java code for: + * + * if (f(conds[0]) actions[0] + * else if (f(conds[1]) actions[1] + * . . . + * else actions[action.length-1] + * + * A particular action entry ("actions[i]") can be null, in which + * case, a noop is generated for that action. + */ + static String buildLookaheadChecker(Lookahead[] conds, String[] actions) { + + // The state variables. + int state = NOOPENSTM; + int indentAmt = 0; + boolean[] casedValues = new boolean[tokenCount]; + String retval = ""; + Lookahead la; + Token t = null; + int tokenMaskSize = (tokenCount-1)/32 + 1; + int[] tokenMask = null; + + // Iterate over all the conditions. + int index = 0; + java.util.List needsBreak = new java.util.ArrayList(); + while (index < conds.length) { + + la = conds[index]; + jj2LA = false; + + if ((la.amount == 0) || + Semanticize.emptyExpansionExists(la.la_expansion) || + csCodeCheck(la.la_expansion) + ) { + + // This handles the following cases: + // . If syntactic lookahead is not wanted (and hence explicitly specified + // as 0). + // . If it is possible for the lookahead expansion to recognize the empty + // string - in which case the lookahead trivially passes. + // . If the lookahead expansion has a JAVACODE production that it directly + // expands to - in which case the lookahead trivially passes. + if (la.action_tokens.size() == 0) { + // In addition, if there is no semantic lookahead, then the + // lookahead trivially succeeds. So break the main loop and + // treat this case as the default last action. + break; + } else { + // This case is when there is only semantic lookahead + // (without any preceding syntactic lookahead). In this + // case, an "if" statement is generated. + switch (state) { + case NOOPENSTM: + retval += "\n" + "if ("; + indentAmt++; + break; + case OPENIF: + retval += "\u0002\n" + "} else if ("; + break; + case OPENSWITCH: + retval += "\u0002\n" + "default:" + "\u0001"; + if (Options.getErrorReporting()) { + retval += "\njj_la1[" + maskindex + "] = jj_gen;"; + maskindex++; + } + needsBreak.add(indentAmt); + maskVals.addElement(tokenMask); + + retval += "\n" + "if ("; + indentAmt++; + } + printTokenSetup((Token)(la.action_tokens.elementAt(0))); + for (java.util.Enumeration anEnum = la.action_tokens.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + retval += printToken(t); + } + retval += printTrailingComments(t); + retval += ") {\u0001" + actions[index]; + state = OPENIF; + } + + } else if (la.amount == 1 && la.action_tokens.size() == 0) { + // Special optimal processing when the lookahead is exactly 1, and there + // is no semantic lookahead. + + if (firstSet == null) { + firstSet = new boolean[tokenCount]; + } + for (int i = 0; i < tokenCount; i++) { + firstSet[i] = false; + } + // jj2LA is set to false at the beginning of the containing "if" statement. + // It is checked immediately after the end of the same statement to determine + // if lookaheads are to be performed using calls to the jj2 methods. + genFirstSet(la.la_expansion); + // genFirstSet may find that semantic attributes are appropriate for the next + // token. In which case, it sets jj2LA to true. + if (!jj2LA) { + + // This case is if there is no applicable semantic lookahead and the lookahead + // is one (excluding the earlier cases such as JAVACODE, etc.). + switch (state) { + case OPENIF: + retval += "\u0002\n" + "} else {\u0001"; + // Control flows through to next case. + case NOOPENSTM: + retval += "\n" + "switch ("; + if (Options.getCacheTokens()) { + retval += "jj_nt.kind) {\u0001"; + } else { + retval += "(jj_ntk==-1)?jj_init_ntk():jj_ntk) {\u0001"; + } + for (int i = 0; i < tokenCount; i++) { + casedValues[i] = false; + } + indentAmt++; + tokenMask = new int[tokenMaskSize]; + for (int i = 0; i < tokenMaskSize; i++) { + tokenMask[i] = 0; + } + // Don't need to do anything if state is OPENSWITCH. + } + for (int i = 0; i < tokenCount; i++) { + if (firstSet[i]) { + if (!casedValues[i]) { + casedValues[i] = true; + retval += "\u0002\ncase "; + int j1 = i/32; + int j2 = i%32; + tokenMask[j1] |= 1 << j2; + String s = (String)(names_of_tokens.get(new Integer(i))); + if (s == null) { + retval += i; + } else { + retval += s; + } + retval += ":\u0001"; + } + } + } + retval += actions[index]; + retval += "\nbreak;"; + state = OPENSWITCH; + + } + + } else { + // This is the case when lookahead is determined through calls to + // jj2 methods. The other case is when lookahead is 1, but semantic + // attributes need to be evaluated. Hence this crazy control structure. + + jj2LA = true; + } + + if (jj2LA) { + // In this case lookahead is determined by the jj2 methods. + + switch (state) { + case NOOPENSTM: + retval += "\n" + "if ("; + indentAmt++; + break; + case OPENIF: + retval += "\u0002\n" + "} else if ("; + break; + case OPENSWITCH: + retval += "\u0002\n" + "default:" + "\u0001"; + if (Options.getErrorReporting()) { + retval += "\njj_la1[" + maskindex + "] = jj_gen;"; + maskindex++; + } + needsBreak.add(indentAmt); + maskVals.addElement(tokenMask); + + retval += "\n" + "if ("; + indentAmt++; + } + jj2index++; + // At this point, la.la_expansion.internal_name must be "". + la.la_expansion.internal_name = "_" + jj2index; + phase2list.addElement(la); + retval += "jj_2" + la.la_expansion.internal_name + "(" + la.amount + ")"; + if (la.action_tokens.size() != 0) { + // In addition, there is also a semantic lookahead. So concatenate + // the semantic check with the syntactic one. + retval += " && ("; + printTokenSetup((Token)(la.action_tokens.elementAt(0))); + for (java.util.Enumeration anEnum = la.action_tokens.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + retval += printToken(t); + } + retval += printTrailingComments(t); + retval += ")"; + } + retval += ") {\u0001" + actions[index]; + state = OPENIF; + } + index++; + } + + // Generate code for the default case. Note this may not + // be the last entry of "actions" if any condition can be + // statically determined to be always "true". + switch (state) { + case NOOPENSTM: + retval += actions[index]; + break; + case OPENIF: + retval += "\u0002\n" + "} else {\u0001" + actions[index]; + break; + case OPENSWITCH: + retval += "\u0002\n" + "default:" + "\u0001"; + if (Options.getErrorReporting()) { + retval += "\njj_la1[" + maskindex + "] = jj_gen;"; + maskVals.addElement(tokenMask); + maskindex++; + } + retval += actions[index]; + // New for CS... need to break empty default cases + retval += "break;\n"; + } + for (int i = 0; i < indentAmt; i++){ + retval += "\u0002\n}"; + if(needsBreak.contains(indentAmt-i-1)){ + needsBreak.remove((Object)(indentAmt-i-1)); + retval += "break;"; + } + } + + return retval; + } + + static void dumpFormattedString(String str) { + char ch = ' '; + char prevChar; + boolean indentOn = true; + for (int i = 0; i < str.length(); i++) { + prevChar = ch; + ch = str.charAt(i); + if (ch == '\n' && prevChar == '\r') { + // do nothing - we've already printed a new line for the '\r' + // during the previous iteration. + } else if (ch == '\n' || ch == '\r') { + if (indentOn) { + phase1NewLine(); + } else { + ostr.println(""); + } + } else if (ch == '\u0001') { + indentamt += 2; + } else if (ch == '\u0002') { + indentamt -= 2; + } else if (ch == '\u0003') { + indentOn = false; + } else if (ch == '\u0004') { + indentOn = true; + } else { + ostr.print(ch); + } + } + } + + static void buildPhase1Routine(BNFProduction p) { + Token t; + t = (Token)(p.return_type_tokens.elementAt(0)); + boolean voidReturn = false; + if (t.kind == CSJavaCCParserConstants.VOID) { + voidReturn = true; + } + printTokenSetup(t); ccol = 1; + printLeadingComments(t, ostr); + ostr.print(" " + staticOpt() +(p.accessMod != null ? p.accessMod : "public")+ " "); + cline = t.beginLine; ccol = t.beginColumn; + printTokenOnly(t, ostr); + for (int i = 1; i < p.return_type_tokens.size(); i++) { + t = (Token)(p.return_type_tokens.elementAt(i)); + printToken(t, ostr); + } + printTrailingComments(t, ostr); + ostr.print(" " + p.lhs + "("); + if (p.parameter_list_tokens.size() != 0) { + printTokenSetup((Token)(p.parameter_list_tokens.elementAt(0))); + for (java.util.Enumeration anEnum = p.parameter_list_tokens.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + printToken(t, ostr); + } + printTrailingComments(t, ostr); + } + ostr.print(")"); + for (java.util.Enumeration anEnum = p.throws_list.elements(); anEnum.hasMoreElements();) { + ostr.print(", "); + java.util.Vector name = (java.util.Vector)anEnum.nextElement(); + for (java.util.Enumeration enum1 = name.elements(); enum1.hasMoreElements();) { + t = (Token)enum1.nextElement(); + ostr.print(t.image); + } + } + ostr.print(" {"); + indentamt = 4; + if (Options.getDebugParser()) { + ostr.println(""); + ostr.println(" trace_call(\"" + p.lhs + "\");"); + ostr.print(" try {"); + indentamt = 6; + } + if (p.declaration_tokens.size() != 0) { + printTokenSetup((Token)(p.declaration_tokens.elementAt(0))); cline--; + for (java.util.Enumeration anEnum = p.declaration_tokens.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + printToken(t, ostr); + } + printTrailingComments(t, ostr); + } + String code = phase1ExpansionGen(p.expansion); + dumpFormattedString(code); + ostr.println(""); + if (p.jumpPatched && !voidReturn) { + ostr.println(" throw new System.Exception(\"Missing return statement in function\");"); + } + if (Options.getDebugParser()) { + ostr.println(" } finally {"); + ostr.println(" trace_return(\"" + p.lhs + "\");"); + ostr.println(" }"); + } + ostr.println(" }"); + ostr.println(""); + } + + static void phase1NewLine() { + ostr.println(""); + for (int i = 0; i < indentamt; i++) { + ostr.print(" "); + } + } + + static String phase1ExpansionGen(Expansion e) { + String retval = ""; + Token t = null; + Lookahead[] conds; + String[] actions; + if (e instanceof RegularExpression) { + RegularExpression e_nrw = (RegularExpression)e; + retval += "\n"; + if (e_nrw.lhsTokens.size() != 0) { + printTokenSetup((Token)(e_nrw.lhsTokens.elementAt(0))); + for (java.util.Enumeration anEnum = e_nrw.lhsTokens.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + retval += printToken(t); + } + retval += printTrailingComments(t); + retval += " = "; + } + String tail = e_nrw.rhsToken == null ? ");" : ")." + e_nrw.rhsToken.image + ";"; + if (e_nrw.label.equals("")) { + Object label = names_of_tokens.get(new Integer(e_nrw.ordinal)); + if (label != null) { + retval += "jj_consume_token(" + (String)label + tail; + } else { + retval += "jj_consume_token(" + e_nrw.ordinal + tail; + } + } else { + retval += "jj_consume_token(" + e_nrw.label + tail; + } + } else if (e instanceof NonTerminal) { + NonTerminal e_nrw = (NonTerminal)e; + retval += "\n"; + if (e_nrw.lhsTokens.size() != 0) { + printTokenSetup((Token)(e_nrw.lhsTokens.elementAt(0))); + for (java.util.Enumeration anEnum = e_nrw.lhsTokens.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + retval += printToken(t); + } + retval += printTrailingComments(t); + retval += " = "; + } + retval += e_nrw.name + "("; + if (e_nrw.argument_tokens.size() != 0) { + printTokenSetup((Token)(e_nrw.argument_tokens.elementAt(0))); + for (java.util.Enumeration anEnum = e_nrw.argument_tokens.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + retval += printToken(t); + } + retval += printTrailingComments(t); + } + retval += ");"; + } else if (e instanceof Action) { + Action e_nrw = (Action)e; + retval += "\u0003\n"; + if (e_nrw.action_tokens.size() != 0) { + printTokenSetup((Token)(e_nrw.action_tokens.elementAt(0))); ccol = 1; + for (java.util.Enumeration anEnum = e_nrw.action_tokens.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + retval += printToken(t); + } + retval += printTrailingComments(t); + } + retval += "\u0004"; + } else if (e instanceof Choice) { + Choice e_nrw = (Choice)e; + conds = new Lookahead[e_nrw.choices.size()]; + actions = new String[e_nrw.choices.size() + 1]; + actions[e_nrw.choices.size()] = "\n" + "jj_consume_token(-1);\n" + "throw new ParseException();"; + // In previous line, the "throw" never throws an exception since the + // evaluation of jj_consume_token(-1) causes ParseException to be + // thrown first. + Sequence nestedSeq; + for (int i = 0; i < e_nrw.choices.size(); i++) { + nestedSeq = (Sequence)(e_nrw.choices.elementAt(i)); + actions[i] = phase1ExpansionGen(nestedSeq); + conds[i] = (Lookahead)(nestedSeq.units.elementAt(0)); + } + retval = buildLookaheadChecker(conds, actions); + } else if (e instanceof Sequence) { + Sequence e_nrw = (Sequence)e; + // We skip the first element in the following iteration since it is the + // Lookahead object. + for (int i = 1; i < e_nrw.units.size(); i++) { + retval += phase1ExpansionGen((Expansion)(e_nrw.units.elementAt(i))); + } + } else if (e instanceof OneOrMore) { + OneOrMore e_nrw = (OneOrMore)e; + Expansion nested_e = e_nrw.expansion; + Lookahead la; + if (nested_e instanceof Sequence) { + la = (Lookahead)(((Sequence)nested_e).units.elementAt(0)); + } else { + la = new Lookahead(); + la.amount = Options.getLookahead(); + la.la_expansion = nested_e; + } + retval += "\n"; + int labelIndex = ++gensymindex; + // Removed for CS fix... + //retval += "label_" + labelIndex + ":\n"; + retval += "while (true) {\u0001"; + retval += phase1ExpansionGen(nested_e); + conds = new Lookahead[1]; + conds[0] = la; + actions = new String[2]; + actions[0] = "\n;"; + //actions[1] = "\nbreak label_" + labelIndex + ";"; + // New for CS fix... + actions[1] = "\ngoto label_" + labelIndex + ";"; + retval += buildLookaheadChecker(conds, actions); + retval += "\u0002\n" + "}\n"; + // New for CS fix... also needs an empty statement, in case it comes + // at the end of a block/method + retval += "label_" + labelIndex + ": ;\n"; + } else if (e instanceof ZeroOrMore) { + ZeroOrMore e_nrw = (ZeroOrMore)e; + Expansion nested_e = e_nrw.expansion; + Lookahead la; + if (nested_e instanceof Sequence) { + la = (Lookahead)(((Sequence)nested_e).units.elementAt(0)); + } else { + la = new Lookahead(); + la.amount = Options.getLookahead(); + la.la_expansion = nested_e; + } + retval += "\n"; + int labelIndex = ++gensymindex; + // Removed for CS fix... + //retval += "label_" + labelIndex + ":\n"; + retval += "while (true) {\u0001"; + conds = new Lookahead[1]; + conds[0] = la; + actions = new String[2]; + actions[0] = "\n;"; + //actions[1] = "\nbreak label_" + labelIndex + ";"; + // New for CS fix... + actions[1] = "\ngoto label_" + labelIndex + ";"; + retval += buildLookaheadChecker(conds, actions); + retval += phase1ExpansionGen(nested_e); + retval += "\u0002\n" + "}\n"; + // New for CS fix... + retval += "label_" + labelIndex + ": ;\n"; + } else if (e instanceof ZeroOrOne) { + ZeroOrOne e_nrw = (ZeroOrOne)e; + Expansion nested_e = e_nrw.expansion; + Lookahead la; + if (nested_e instanceof Sequence) { + la = (Lookahead)(((Sequence)nested_e).units.elementAt(0)); + } else { + la = new Lookahead(); + la.amount = Options.getLookahead(); + la.la_expansion = nested_e; + } + conds = new Lookahead[1]; + conds[0] = la; + actions = new String[2]; + actions[0] = phase1ExpansionGen(nested_e); + actions[1] = "\n;"; + retval += buildLookaheadChecker(conds, actions); + } else if (e instanceof TryBlock) { + TryBlock e_nrw = (TryBlock)e; + Expansion nested_e = e_nrw.exp; + java.util.Vector v; + retval += "\n"; + retval += "try {\u0001"; + retval += phase1ExpansionGen(nested_e); + retval += "\u0002\n" + "}"; + for (int i = 0; i < e_nrw.catchblks.size(); i++) { + retval += " catch ("; + v = (java.util.Vector)(e_nrw.types.elementAt(i)); + if (v.size() != 0) { + printTokenSetup((Token)(v.elementAt(0))); + for (java.util.Enumeration anEnum = v.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + retval += printToken(t); + } + retval += printTrailingComments(t); + } + retval += " "; + t = (Token)(e_nrw.ids.elementAt(i)); + printTokenSetup(t); + retval += printToken(t); + retval += printTrailingComments(t); + retval += ") {\u0003\n"; + v = (java.util.Vector)(e_nrw.catchblks.elementAt(i)); + if (v.size() != 0) { + printTokenSetup((Token)(v.elementAt(0))); ccol = 1; + for (java.util.Enumeration anEnum = v.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + retval += printToken(t); + } + retval += printTrailingComments(t); + } + retval += "\u0004\n" + "}"; + } + if (e_nrw.finallyblk != null) { + retval += " finally {\u0003\n"; + if (e_nrw.finallyblk.size() != 0) { + printTokenSetup((Token)(e_nrw.finallyblk.elementAt(0))); ccol = 1; + for (java.util.Enumeration anEnum = e_nrw.finallyblk.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + retval += printToken(t); + } + retval += printTrailingComments(t); + } + retval += "\u0004\n" + "}"; + } + } + return retval; + } + + static void buildPhase2Routine(Lookahead la) { + Expansion e = la.la_expansion; + ostr.println(" " + staticOpt() + "private bool jj_2" + e.internal_name + "(int xla) {"); + ostr.println(" jj_la = xla; jj_lastpos = jj_scanpos = token;"); + ostr.println(" try { return !jj_3" + e.internal_name + "(); }"); + ostr.println(" catch(LookaheadSuccess ls) { return true; }"); + if (Options.getErrorReporting()) + ostr.println(" finally { jj_save(" + (Integer.parseInt(e.internal_name.substring(1))-1) + ", xla); }"); + ostr.println(" }"); + ostr.println(""); + Phase3Data p3d = new Phase3Data(e, la.amount); + phase3list.addElement(p3d); + phase3table.put(e, p3d); + } + + static private boolean xsp_declared; + + static Expansion jj3_expansion; + + static String genReturn(boolean value) { + String retval = (value ? "true" : "false"); + if (Options.getDebugLookahead() && jj3_expansion != null) { + String tracecode = "trace_return(\"" + ((NormalProduction)jj3_expansion.parent).lhs + + "(LOOKAHEAD " + (value ? "FAILED" : "SUCCEEDED") + ")\");"; + if (Options.getErrorReporting()) { + tracecode = "if (!jj_rescan) " + tracecode; + } + return "{ " + tracecode + " return " + retval + "; }"; + } else { + return "return " + retval + ";"; + } + } + + private static void generate3R(Expansion e, Phase3Data inf) + { + Expansion seq = e; + if (e.internal_name.equals("")) + { + while (true) + { + if (seq instanceof Sequence && ((Sequence)seq).units.size() == 2) + { + seq = (Expansion)((Sequence)seq).units.elementAt(1); + } + else if (seq instanceof NonTerminal) + { + NonTerminal e_nrw = (NonTerminal)seq; + NormalProduction ntprod = (NormalProduction)(production_table.get(e_nrw.name)); + if (ntprod instanceof CSCodeProduction) + { + break; // nothing to do here + } + else + { + seq = ntprod.expansion; + } + } + else + break; + } + + if (seq instanceof RegularExpression) + { + e.internal_name = "jj_scan_token(" + ((RegularExpression)seq).ordinal + ")"; + return; + } + + gensymindex++; +//if (gensymindex == 100) +//{ +//new Error().printStackTrace(); +//System.err.println(" ***** seq: " + seq.internal_name + "; size: " + ((Sequence)seq).units.size()); +//} + e.internal_name = "R_" + gensymindex; + } + Phase3Data p3d = (Phase3Data)(phase3table.get(e)); + if (p3d == null || p3d.count < inf.count) { + p3d = new Phase3Data(e, inf.count); + phase3list.addElement(p3d); + phase3table.put(e, p3d); + } + } + + static void setupPhase3Builds(Phase3Data inf) { + Expansion e = inf.exp; + if (e instanceof RegularExpression) { + ; // nothing to here + } else if (e instanceof NonTerminal) { + // All expansions of non-terminals have the "name" fields set. So + // there's no need to check it below for "e_nrw" and "ntexp". In + // fact, we rely here on the fact that the "name" fields of both these + // variables are the same. + NonTerminal e_nrw = (NonTerminal)e; + NormalProduction ntprod = (NormalProduction)(production_table.get(e_nrw.name)); + if (ntprod instanceof CSCodeProduction) { + ; // nothing to do here + } else { + generate3R(ntprod.expansion, inf); + } + } else if (e instanceof Choice) { + Choice e_nrw = (Choice)e; + for (int i = 0; i < e_nrw.choices.size(); i++) { + generate3R((Expansion)(e_nrw.choices.elementAt(i)), inf); + } + } else if (e instanceof Sequence) { + Sequence e_nrw = (Sequence)e; + // We skip the first element in the following iteration since it is the + // Lookahead object. + int cnt = inf.count; + for (int i = 1; i < e_nrw.units.size(); i++) { + Expansion eseq = (Expansion)(e_nrw.units.elementAt(i)); + setupPhase3Builds(new Phase3Data(eseq, cnt)); + cnt -= minimumSize(eseq); + if (cnt <= 0) break; + } + } else if (e instanceof TryBlock) { + TryBlock e_nrw = (TryBlock)e; + setupPhase3Builds(new Phase3Data(e_nrw.exp, inf.count)); + } else if (e instanceof OneOrMore) { + OneOrMore e_nrw = (OneOrMore)e; + generate3R(e_nrw.expansion, inf); + } else if (e instanceof ZeroOrMore) { + ZeroOrMore e_nrw = (ZeroOrMore)e; + generate3R(e_nrw.expansion, inf); + } else if (e instanceof ZeroOrOne) { + ZeroOrOne e_nrw = (ZeroOrOne)e; + generate3R(e_nrw.expansion, inf); + } + } + + private static String genjj_3Call(Expansion e) + { + if (e.internal_name.startsWith("jj_scan_token")) + return e.internal_name; + else + return "jj_3" + e.internal_name + "()"; + } + + static Hashtable generated = new Hashtable(); + static void buildPhase3Routine(Phase3Data inf, boolean recursive_call) { + Expansion e = inf.exp; + Token t = null; + if (e.internal_name.startsWith("jj_scan_token")) + return; + + if (!recursive_call) { + ostr.println(" " + staticOpt() + "private bool jj_3" + e.internal_name + "() {"); + xsp_declared = false; + if (Options.getDebugLookahead() && e.parent instanceof NormalProduction) { + ostr.print(" "); + if (Options.getErrorReporting()) { + ostr.print("if (!jj_rescan) "); + } + ostr.println("trace_call(\"" + ((NormalProduction)e.parent).lhs + "(LOOKING AHEAD...)\");"); + jj3_expansion = e; + } else { + jj3_expansion = null; + } + } + if (e instanceof RegularExpression) { + RegularExpression e_nrw = (RegularExpression)e; + if (e_nrw.label.equals("")) { + Object label = names_of_tokens.get(new Integer(e_nrw.ordinal)); + if (label != null) { + ostr.println(" if (jj_scan_token(" + (String)label + ")) " + genReturn(true)); + } else { + ostr.println(" if (jj_scan_token(" + e_nrw.ordinal + ")) " + genReturn(true)); + } + } else { + ostr.println(" if (jj_scan_token(" + e_nrw.label + ")) " + genReturn(true)); + } + //ostr.println(" if (jj_la == 0 && jj_scanpos == jj_lastpos) " + genReturn(false)); + } else if (e instanceof NonTerminal) { + // All expansions of non-terminals have the "name" fields set. So + // there's no need to check it below for "e_nrw" and "ntexp". In + // fact, we rely here on the fact that the "name" fields of both these + // variables are the same. + NonTerminal e_nrw = (NonTerminal)e; + NormalProduction ntprod = (NormalProduction)(production_table.get(e_nrw.name)); + if (ntprod instanceof CSCodeProduction) { + ostr.println(" if (true) { jj_la = 0; jj_scanpos = jj_lastpos; " + genReturn(false) + "}"); + } else { + Expansion ntexp = ntprod.expansion; + //ostr.println(" if (jj_3" + ntexp.internal_name + "()) " + genReturn(true)); + ostr.println(" if (" + genjj_3Call(ntexp)+ ") " + genReturn(true)); + //ostr.println(" if (jj_la == 0 && jj_scanpos == jj_lastpos) " + genReturn(false)); + } + } else if (e instanceof Choice) { + if (!xsp_declared) { + xsp_declared = true; + ostr.println(" Token xsp;"); + } + ostr.println(" xsp = jj_scanpos;"); + Sequence nested_seq; + Choice e_nrw = (Choice)e; + for (int i = 0; i < e_nrw.choices.size(); i++) { + nested_seq = (Sequence)(e_nrw.choices.elementAt(i)); + Lookahead la = (Lookahead)(nested_seq.units.elementAt(0)); + if (la.action_tokens.size() != 0) { + // We have semantic lookahead that must be evaluated. + ostr.println(" lookingAhead = true;"); + ostr.print(" jj_semLA = "); + printTokenSetup((Token)(la.action_tokens.elementAt(0))); + for (java.util.Enumeration anEnum = la.action_tokens.elements(); anEnum.hasMoreElements();) { + t = (Token)anEnum.nextElement(); + printToken(t, ostr); + } + printTrailingComments(t, ostr); + ostr.println(";"); + ostr.println(" lookingAhead = false;"); + } + ostr.print(" if ("); + if (la.action_tokens.size() != 0) { + ostr.print("!jj_semLA || "); + } + if (i != e_nrw.choices.size() - 1) { + //ostr.println("jj_3" + nested_seq.internal_name + "()) {"); + ostr.println(genjj_3Call(nested_seq) + ") {"); + ostr.println(" jj_scanpos = xsp;"); + } else { + //ostr.println("jj_3" + nested_seq.internal_name + "()) " + genReturn(true)); + ostr.println(genjj_3Call(nested_seq) + ") " + genReturn(true)); + //ostr.println(" if (jj_la == 0 && jj_scanpos == jj_lastpos) " + genReturn(false)); + } + } + for (int i = 1; i < e_nrw.choices.size(); i++) { + //ostr.println(" } else if (jj_la == 0 && jj_scanpos == jj_lastpos) " + genReturn(false)); + ostr.println(" }"); + } + } else if (e instanceof Sequence) { + Sequence e_nrw = (Sequence)e; + // We skip the first element in the following iteration since it is the + // Lookahead object. + int cnt = inf.count; + for (int i = 1; i < e_nrw.units.size(); i++) { + Expansion eseq = (Expansion)(e_nrw.units.elementAt(i)); + buildPhase3Routine(new Phase3Data(eseq, cnt), true); + +//System.err.println("minimumSize: line: " + eseq.line + ", column: " + eseq.column + ": " + minimumSize(eseq));//Test Code + + cnt -= minimumSize(eseq); + if (cnt <= 0) break; + } + } else if (e instanceof TryBlock) { + TryBlock e_nrw = (TryBlock)e; + buildPhase3Routine(new Phase3Data(e_nrw.exp, inf.count), true); + } else if (e instanceof OneOrMore) { + if (!xsp_declared) { + xsp_declared = true; + ostr.println(" Token xsp;"); + } + OneOrMore e_nrw = (OneOrMore)e; + Expansion nested_e = e_nrw.expansion; + //ostr.println(" if (jj_3" + nested_e.internal_name + "()) " + genReturn(true)); + ostr.println(" if (" + genjj_3Call(nested_e) + ") " + genReturn(true)); + //ostr.println(" if (jj_la == 0 && jj_scanpos == jj_lastpos) " + genReturn(false)); + ostr.println(" while (true) {"); + ostr.println(" xsp = jj_scanpos;"); + //ostr.println(" if (jj_3" + nested_e.internal_name + "()) { jj_scanpos = xsp; break; }"); + ostr.println(" if (" + genjj_3Call(nested_e) + ") { jj_scanpos = xsp; break; }"); + //ostr.println(" if (jj_la == 0 && jj_scanpos == jj_lastpos) " + genReturn(false)); + ostr.println(" }"); + } else if (e instanceof ZeroOrMore) { + if (!xsp_declared) { + xsp_declared = true; + ostr.println(" Token xsp;"); + } + ZeroOrMore e_nrw = (ZeroOrMore)e; + Expansion nested_e = e_nrw.expansion; + ostr.println(" while (true) {"); + ostr.println(" xsp = jj_scanpos;"); + //ostr.println(" if (jj_3" + nested_e.internal_name + "()) { jj_scanpos = xsp; break; }"); + ostr.println(" if (" + genjj_3Call(nested_e) + ") { jj_scanpos = xsp; break; }"); + //ostr.println(" if (jj_la == 0 && jj_scanpos == jj_lastpos) " + genReturn(false)); + ostr.println(" }"); + } else if (e instanceof ZeroOrOne) { + if (!xsp_declared) { + xsp_declared = true; + ostr.println(" Token xsp;"); + } + ZeroOrOne e_nrw = (ZeroOrOne)e; + Expansion nested_e = e_nrw.expansion; + ostr.println(" xsp = jj_scanpos;"); + //ostr.println(" if (jj_3" + nested_e.internal_name + "()) jj_scanpos = xsp;"); + ostr.println(" if (" + genjj_3Call(nested_e) + ") jj_scanpos = xsp;"); + //ostr.println(" else if (jj_la == 0 && jj_scanpos == jj_lastpos) " + genReturn(false)); + } + if (!recursive_call) { + ostr.println(" " + genReturn(false)); + ostr.println(" }"); + ostr.println(""); + } + } + + static int minimumSize(Expansion e) { + return minimumSize(e, Integer.MAX_VALUE); + } + + /* + * Returns the minimum number of tokens that can parse to this expansion. + */ + static int minimumSize(Expansion e, int oldMin) { + int retval = 0; // should never be used. Will be bad if it is. + if (e.inMinimumSize) { + // recursive search for minimum size unnecessary. + return Integer.MAX_VALUE; + } + e.inMinimumSize = true; + if (e instanceof RegularExpression) { + retval = 1; + } else if (e instanceof NonTerminal) { + NonTerminal e_nrw = (NonTerminal)e; + NormalProduction ntprod = (NormalProduction)(production_table.get(e_nrw.name)); + if (ntprod instanceof CSCodeProduction) { + retval = Integer.MAX_VALUE; + // Make caller think this is unending (for we do not go beyond JAVACODE during + // phase3 execution). + } else { + Expansion ntexp = ntprod.expansion; + retval = minimumSize(ntexp); + } + } else if (e instanceof Choice) { + int min = oldMin; + Expansion nested_e; + Choice e_nrw = (Choice)e; + for (int i = 0; min > 1 && i < e_nrw.choices.size(); i++) { + nested_e = (Expansion)(e_nrw.choices.elementAt(i)); + int min1 = minimumSize(nested_e, min); + if (min > min1) min = min1; + } + retval = min; + } else if (e instanceof Sequence) { + int min = 0; + Sequence e_nrw = (Sequence)e; + // We skip the first element in the following iteration since it is the + // Lookahead object. + for (int i = 1; i < e_nrw.units.size(); i++) { + Expansion eseq = (Expansion)(e_nrw.units.elementAt(i)); + int mineseq = minimumSize(eseq); + if (min == Integer.MAX_VALUE || mineseq == Integer.MAX_VALUE) { + min = Integer.MAX_VALUE; // Adding infinity to something results in infinity. + } else { + min += mineseq; + if (min > oldMin) + break; + } + } + retval = min; + } else if (e instanceof TryBlock) { + TryBlock e_nrw = (TryBlock)e; + retval = minimumSize(e_nrw.exp); + } else if (e instanceof OneOrMore) { + OneOrMore e_nrw = (OneOrMore)e; + retval = minimumSize(e_nrw.expansion); + } else if (e instanceof ZeroOrMore) { + retval = 0; + } else if (e instanceof ZeroOrOne) { + retval = 0; + } else if (e instanceof Lookahead) { + retval = 0; + } else if (e instanceof Action) { + retval = 0; + } + e.inMinimumSize = false; + return retval; + } + + static void build(java.io.PrintWriter ps) { + NormalProduction p; + CSCodeProduction jp; + Token t = null; + + ostr = ps; + + for (java.util.Enumeration anEnum = bnfproductions.elements(); anEnum.hasMoreElements();) { + p = (NormalProduction)anEnum.nextElement(); + if (p instanceof CSCodeProduction) { + jp = (CSCodeProduction)p; + t = (Token)(jp.return_type_tokens.elementAt(0)); + printTokenSetup(t); ccol = 1; + printLeadingComments(t, ostr); + ostr.print(" " + staticOpt() + (p.accessMod != null ? p.accessMod + " " : "")); + cline = t.beginLine; ccol = t.beginColumn; + printTokenOnly(t, ostr); + for (int i = 1; i < jp.return_type_tokens.size(); i++) { + t = (Token)(jp.return_type_tokens.elementAt(i)); + printToken(t, ostr); + } + printTrailingComments(t, ostr); + ostr.print(" " + jp.lhs + "("); + if (jp.parameter_list_tokens.size() != 0) { + printTokenSetup((Token)(jp.parameter_list_tokens.elementAt(0))); + for (java.util.Enumeration enum1 = jp.parameter_list_tokens.elements(); enum1.hasMoreElements();) { + t = (Token)enum1.nextElement(); + printToken(t, ostr); + } + printTrailingComments(t, ostr); + } + ostr.print(") throws ParseException"); + for (java.util.Enumeration enum1 = jp.throws_list.elements(); enum1.hasMoreElements();) { + ostr.print(", "); + java.util.Vector name = (java.util.Vector)enum1.nextElement(); + for (java.util.Enumeration enum2 = name.elements(); enum2.hasMoreElements();) { + t = (Token)enum2.nextElement(); + ostr.print(t.image); + } + } + ostr.print(" {"); + if (Options.getDebugParser()) { + ostr.println(""); + ostr.println(" trace_call(\"" + jp.lhs + "\");"); + ostr.print(" try {"); + } + if (jp.code_tokens.size() != 0) { + printTokenSetup((Token)(jp.code_tokens.elementAt(0))); cline--; + for (java.util.Enumeration enum1 = jp.code_tokens.elements(); enum1.hasMoreElements();) { + t = (Token)enum1.nextElement(); + printToken(t, ostr); + } + printTrailingComments(t, ostr); + } + ostr.println(""); + if (Options.getDebugParser()) { + ostr.println(" } finally {"); + ostr.println(" trace_return(\"" + jp.lhs + "\");"); + ostr.println(" }"); + } + ostr.println(" }"); + ostr.println(""); + } else { + buildPhase1Routine((BNFProduction)p); + } + } + + for (int phase2index = 0; phase2index < phase2list.size(); phase2index++) { + buildPhase2Routine((Lookahead)(phase2list.elementAt(phase2index))); + } + + int phase3index = 0; + + while (phase3index < phase3list.size()) { + for (; phase3index < phase3list.size(); phase3index++) { + setupPhase3Builds((Phase3Data)(phase3list.elementAt(phase3index))); + } + } + + for (java.util.Enumeration anEnum = phase3table.elements(); anEnum.hasMoreElements();) { + buildPhase3Routine((Phase3Data)(anEnum.nextElement()), false); + } + + } + + public static void reInit() + { + ostr = null; + gensymindex = 0; + indentamt = 0; + jj2LA = false; + phase2list = new java.util.Vector(); + phase3list = new java.util.Vector(); + phase3table = new java.util.Hashtable(); + firstSet = null; + xsp_declared = false; + jj3_expansion = null; + } + +} + +/* + * This class stored information to pass from phase 2 to phase 3. + */ +class Phase3Data { + + /* + * This is the expansion to generate the jj3 method for. + */ + Expansion exp; + + /* + * This is the number of tokens that can still be consumed. This + * number is used to limit the number of jj3 methods generated. + */ + int count; + + Phase3Data(Expansion e, int c) { + exp = e; + count = c; + } + +} diff --git a/csjavacc/parser/ParseException.java b/csjavacc/parser/ParseException.java new file mode 100644 index 0000000..535eb75 --- /dev/null +++ b/csjavacc/parser/ParseException.java @@ -0,0 +1,197 @@ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ +/** + * This file contains the code for CSJavaCCParser generated + * by CSJavaCCParser itself. + */ + +package csjavacc.parser; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. The boolean + * flag "specialConstructor" is also set to true to indicate that + * this constructor was used to create this object. + * This constructor calls its super class with the empty string + * to force the "toString" method of parent class "Throwable" to + * print the error message in the form: + * ParseException: + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + super(""); + specialConstructor = true; + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + specialConstructor = false; + } + + public ParseException(String message) { + super(message); + specialConstructor = false; + } + + /** + * This variable determines which constructor was used to create + * this object and thereby affects the semantics of the + * "getMessage" method (see below). + */ + protected boolean specialConstructor; + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * This method has the standard behavior when this object has been + * created using the standard constructors. Otherwise, it uses + * "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser), then this method is called during the printing + * of the final stack trace, and hence the correct error message + * gets displayed. + */ + public String getMessage() { + if (!specialConstructor) { + return super.getMessage(); + } + StringBuffer expected = new StringBuffer(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) { + maxSize = expectedTokenSequences[i].length; + } + for (int j = 0; j < expectedTokenSequences[i].length; j++) { + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" "); + } + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { + expected.append("..."); + } + expected.append(eol).append(" "); + } + String retval = "Encountered \""; + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + if (i != 0) retval += " "; + if (tok.kind == 0) { + retval += tokenImage[0]; + break; + } + retval += add_escapes(tok.image); + tok = tok.next; + } + retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; + retval += "." + eol; + if (expectedTokenSequences.length == 1) { + retval += "Was expecting:" + eol + " "; + } else { + retval += "Was expecting one of:" + eol + " "; + } + retval += expected.toString(); + return retval; + } + + /** + * The end of line string for this machine. + */ + protected String eol = System.getProperty("line.separator", "\n"); + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + protected String add_escapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + +} diff --git a/csjavacc/parser/ParseGen.java b/csjavacc/parser/ParseGen.java new file mode 100644 index 0000000..2babdaa --- /dev/null +++ b/csjavacc/parser/ParseGen.java @@ -0,0 +1,716 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.util.*; +import java.io.*; + +public class ParseGen extends CSJavaCCGlobals implements CSJavaCCParserConstants { + + static public void start() throws MetaParseException { + + Token t = null; + boolean namespace = false; + if (CSJavaCCErrors.get_error_count() != 0) throw new MetaParseException(); + + if (Options.getBuildParser()) { + + try { + ostr = new PrintWriter( + new BufferedWriter( + new FileWriter( + new File(Options.getOutputDirectory(), cu_name + extension) + ), + 8192 + ) + ); + } catch (IOException e) { + CSJavaCCErrors.semantic_error("Could not open file " + cu_name + extension+" for writing."); + throw new Error(); + } + + Vector tn = (Vector)(toolNames.clone()); + tn.addElement(toolName); + ostr.println("/* " + getIdString(tn, cu_name + ""+extension) + " */"); + + boolean implementsExists = false; + + if (cu_to_insertion_point_1.size() != 0) { + Enumeration e = cu_to_insertion_point_1.elements(); + printTokenSetup((Token)(cu_to_insertion_point_1.elementAt(0))); ccol = 1; + if(((Token)cu_to_insertion_point_1.elementAt(0)).kind == NAMESPACE) { + for (int i = 1; i < cu_to_insertion_point_1.size(); i++) { + if (((Token)cu_to_insertion_point_1.elementAt(i)).kind == SEMICOLON) { + for (int j = 0; j < i; j++) { + e.nextElement(); + printToken((Token)(cu_to_insertion_point_1.elementAt(j)), ostr); + } + e.nextElement(); + namespace = true; + ostr.println("{"); + ostr.println(""); + break; + } + } + } + for (; e.hasMoreElements();) { + t = (Token)e.nextElement(); + if (t.kind == CLASS) { + implementsExists = false; + } + printToken(t, ostr); + } + } + if (implementsExists) { + ostr.print(", "); + } else { + ostr.print(" : "); + } + ostr.print(cu_name + "Constants "); + if (cu_to_insertion_point_2.size() != 0) { + printTokenSetup((Token)(cu_to_insertion_point_2.elementAt(0))); + for (Enumeration e = cu_to_insertion_point_2.elements(); e.hasMoreElements();) { + t = (Token)e.nextElement(); + printToken(t, ostr); + } + } + + ostr.println(""); + ostr.println(""); + + ParseEngine.build(ostr); + + if (Options.getStatic()) { + ostr.println(" static private bool jj_initialized_once = false;"); + } + if (Options.getUserTokenManager()) { + ostr.println(" " + staticOpt() + "public TokenManager token_source;"); + } else { + ostr.println(" " + staticOpt() + "public " + cu_name + "TokenManager token_source;"); + if (!Options.getUserCharStream()) { + if (Options.getCSUnicodeEscape()) { + ostr.println(" " + staticOpt() + language+"CharStream jj_input_stream;"); + } else { + ostr.println(" " + staticOpt() + "SimpleCharStream jj_input_stream;"); + } + } + } + ostr.println(" " + staticOpt() + "public Token token, jj_nt;"); + if (!Options.getCacheTokens()) { + ostr.println(" " + staticOpt() + "private long jj_ntk;"); + } + if (jj2index != 0) { + ostr.println(" " + staticOpt() + "private Token jj_scanpos, jj_lastpos;"); + ostr.println(" " + staticOpt() + "private long jj_la;"); + ostr.println(" " + staticOpt() + "public bool lookingAhead = false;"); + ostr.println(" " + staticOpt() + "private bool jj_semLA;"); + } + if (Options.getErrorReporting()) { + ostr.println(" " + staticOpt() + "private long jj_gen;"); + ostr.println(" " + staticOpt() + "private long[] jj_la1 = new long[" + maskindex + "];"); + int tokenMaskSize = (tokenCount-1)/32 + 1; + for (int i = 0; i < tokenMaskSize; i++) + ostr.println(" static private long[] jj_la1_" + i + ";"); + ostr.println(" static "+cu_name+"(){"); + for (int i = 0; i < tokenMaskSize; i++) + ostr.println(" jj_la1_init_" + i + "();"); + ostr.println(" }"); + for (int i = 0; i < tokenMaskSize; i++) { + ostr.println(" private static void jj_la1_init_" + i + "() {"); + ostr.print(" jj_la1_" + i + " = new long[] {"); + for (Enumeration e = maskVals.elements(); e.hasMoreElements();) { + int[] tokenMask = (int[])(e.nextElement()); + ostr.print("0x" + Integer.toHexString(tokenMask[i]) + ","); + } + ostr.println("};"); + ostr.println(" }"); + } + } + if (jj2index != 0 && Options.getErrorReporting()) { + ostr.println(" " + staticOpt() + "private JJCalls[] jj_2_rtns = new JJCalls[" + jj2index + "];"); + ostr.println(" " + staticOpt() + "private bool jj_rescan = false;"); + ostr.println(" " + staticOpt() + "private long jj_gc = 0;"); + } + ostr.println(""); + + if (!Options.getUserTokenManager()) { + if (Options.getUserCharStream()) { + ostr.println(" public " + cu_name + "(CharStream stream) {"); + if (Options.getStatic()) { + ostr.println(" if (jj_initialized_once) {"); + ostr.println(" System.Console.WriteLine(\"ERROR: Second call to constructor of static parser. You must\");"); + ostr.println(" System.Console.WriteLine(\" either use ReInit() or set the JavaCC option STATIC to false\");"); + ostr.println(" System.Console.WriteLine(\" during parser generation.\");"); + ostr.println(" throw new System.Exception();"); + ostr.println(" }"); + ostr.println(" jj_initialized_once = true;"); + } + if(Options.getTokenManagerUsesParser() && !Options.getStatic()){ + ostr.println(" token_source = new " + cu_name + "TokenManager(this, stream);"); + } else { + ostr.println(" token_source = new " + cu_name + "TokenManager(stream);"); + } + ostr.println(" token = new Token();"); + if (Options.getCacheTokens()) { + ostr.println(" token.next = jj_nt = token_source.getNextToken();"); + } else { + ostr.println(" jj_ntk = -1;"); + } + if (Options.getErrorReporting()) { + ostr.println(" jj_gen = 0;"); + ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); + if (jj2index != 0) { + ostr.println(" for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();"); + } + } + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "public void ReInit(CharStream stream) {"); + ostr.println(" token_source.ReInit(stream);"); + ostr.println(" token = new Token();"); + if (Options.getCacheTokens()) { + ostr.println(" token.next = jj_nt = token_source.getNextToken();"); + } else { + ostr.println(" jj_ntk = -1;"); + } + if (jjtreeGenerated) { + ostr.println(" jjtree.reset();"); + } + if (Options.getErrorReporting()) { + ostr.println(" jj_gen = 0;"); + ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); + if (jj2index != 0) { + ostr.println(" for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();"); + } + } + ostr.println(" }"); + } else { + ostr.println(" public " + cu_name + "(System.IO.Stream stream) {"); + if (Options.getStatic()) { + ostr.println(" if (jj_initialized_once) {"); + ostr.println(" System.Console.WriteLine(\"ERROR: Second call to constructor of static parser. You must\");"); + ostr.println(" System.Console.WriteLine(\" either use ReInit() or set the JavaCC option STATIC to false\");"); + ostr.println(" System.Console.WriteLine(\" during parser generation.\");"); + ostr.println(" throw new System.Exception();"); + ostr.println(" }"); + ostr.println(" jj_initialized_once = true;"); + } + if (Options.getCSUnicodeEscape()) { + ostr.println(" jj_input_stream = new "+language+"CharStream(stream, 1, 1);"); + } else { + ostr.println(" jj_input_stream = new SimpleCharStream(stream, 1, 1);"); + } + if(Options.getTokenManagerUsesParser() && !Options.getStatic()){ + ostr.println(" token_source = new " + cu_name + "TokenManager(this, jj_input_stream);"); + } else { + ostr.println(" token_source = new " + cu_name + "TokenManager(jj_input_stream);"); + } + ostr.println(" token = new Token();"); + if (Options.getCacheTokens()) { + ostr.println(" token.next = jj_nt = token_source.getNextToken();"); + } else { + ostr.println(" jj_ntk = -1;"); + } + if (Options.getErrorReporting()) { + ostr.println(" jj_gen = 0;"); + ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); + if (jj2index != 0) { + ostr.println(" for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();"); + } + } + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "public void ReInit(System.IO.Stream stream) {"); + ostr.println(" jj_input_stream.ReInit(stream, 1, 1);"); + ostr.println(" token_source.ReInit(jj_input_stream);"); + ostr.println(" token = new Token();"); + if (Options.getCacheTokens()) { + ostr.println(" token.next = jj_nt = token_source.getNextToken();"); + } else { + ostr.println(" jj_ntk = -1;"); + } + if (jjtreeGenerated) { + ostr.println(" jjtree.reset();"); + } + if (Options.getErrorReporting()) { + ostr.println(" jj_gen = 0;"); + ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); + if (jj2index != 0) { + ostr.println(" for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();"); + } + } + ostr.println(" }"); + ostr.println(""); + ostr.println(" public " + cu_name + "(System.IO.TextReader stream) {"); + if (Options.getStatic()) { + ostr.println(" if (jj_initialized_once) {"); + ostr.println(" System.Console.WriteLine(\"ERROR: Second call to constructor of static parser. You must\");"); + ostr.println(" System.Console.WriteLine(\" either use ReInit() or set the JavaCC option STATIC to false\");"); + ostr.println(" System.Console.WriteLine(\" during parser generation.\");"); + ostr.println(" throw new Error();"); + ostr.println(" }"); + ostr.println(" jj_initialized_once = true;"); + } + if (Options.getCSUnicodeEscape()) { + ostr.println(" jj_input_stream = new JavaCharStream(stream, 1, 1);"); + } else { + ostr.println(" jj_input_stream = new SimpleCharStream(stream, 1, 1);"); + } + if(Options.getTokenManagerUsesParser() && !Options.getStatic()){ + ostr.println(" token_source = new " + cu_name + "TokenManager(this, jj_input_stream);"); + } else { + ostr.println(" token_source = new " + cu_name + "TokenManager(jj_input_stream);"); + } + ostr.println(" token = new Token();"); + if (Options.getCacheTokens()) { + ostr.println(" token.next = jj_nt = token_source.getNextToken();"); + } else { + ostr.println(" jj_ntk = -1;"); + } + if (Options.getErrorReporting()) { + ostr.println(" jj_gen = 0;"); + ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); + if (jj2index != 0) { + ostr.println(" for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();"); + } + } + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "public void ReInit(System.IO.TextReader stream) {"); + if (Options.getCSUnicodeEscape()) { + ostr.println(" jj_input_stream.ReInit(stream, 1, 1);"); + } else { + ostr.println(" jj_input_stream.ReInit(stream, 1, 1);"); + } + ostr.println(" token_source.ReInit(jj_input_stream);"); + ostr.println(" token = new Token();"); + if (Options.getCacheTokens()) { + ostr.println(" token.next = jj_nt = token_source.getNextToken();"); + } else { + ostr.println(" jj_ntk = -1;"); + } + if (jjtreeGenerated) { + ostr.println(" jjtree.reset();"); + } + if (Options.getErrorReporting()) { + ostr.println(" jj_gen = 0;"); + ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); + if (jj2index != 0) { + ostr.println(" for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();"); + } + } + ostr.println(" }"); + } + } + ostr.println(""); + if (Options.getUserTokenManager()) { + ostr.println(" public " + cu_name + "(TokenManager tm) {"); + } else { + ostr.println(" public " + cu_name + "(" + cu_name + "TokenManager tm) {"); + } + if (Options.getStatic()) { + ostr.println(" if (jj_initialized_once) {"); + ostr.println(" System.Console.WriteLine(\"ERROR: Second call to constructor of static parser. You must\");"); + ostr.println(" System.Console.WriteLine(\" either use ReInit() or set the JavaCC option STATIC to false\");"); + ostr.println(" System.Console.WriteLine(\" during parser generation.\");"); + ostr.println(" throw new Error();"); + ostr.println(" }"); + ostr.println(" jj_initialized_once = true;"); + } + ostr.println(" token_source = tm;"); + ostr.println(" token = new Token();"); + if (Options.getCacheTokens()) { + ostr.println(" token.next = jj_nt = token_source.getNextToken();"); + } else { + ostr.println(" jj_ntk = -1;"); + } + if (Options.getErrorReporting()) { + ostr.println(" jj_gen = 0;"); + ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); + if (jj2index != 0) { + ostr.println(" for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();"); + } + } + ostr.println(" }"); + ostr.println(""); + if (Options.getUserTokenManager()) { + ostr.println(" public void ReInit(TokenManager tm) {"); + } else { + ostr.println(" public void ReInit(" + cu_name + "TokenManager tm) {"); + } + ostr.println(" token_source = tm;"); + ostr.println(" token = new Token();"); + if (Options.getCacheTokens()) { + ostr.println(" token.next = jj_nt = token_source.getNextToken();"); + } else { + ostr.println(" jj_ntk = -1;"); + } + if (jjtreeGenerated) { + ostr.println(" jjtree.reset();"); + } + if (Options.getErrorReporting()) { + ostr.println(" jj_gen = 0;"); + ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); + if (jj2index != 0) { + ostr.println(" for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();"); + } + } + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "private Token jj_consume_token(int kind){"); + if (Options.getCacheTokens()) { + ostr.println(" Token oldToken = token;"); + ostr.println(" if ((token = jj_nt).next != null) jj_nt = jj_nt.next;"); + ostr.println(" else jj_nt = jj_nt.next = token_source.getNextToken();"); + } else { + ostr.println(" Token oldToken;"); + ostr.println(" if ((oldToken = token).next != null) token = token.next;"); + ostr.println(" else token = token.next = token_source.getNextToken();"); + ostr.println(" jj_ntk = -1;"); + } + ostr.println(" if (token.kind == kind) {"); + if (Options.getErrorReporting()) { + ostr.println(" jj_gen++;"); + if (jj2index != 0) { + ostr.println(" if (++jj_gc > 100) {"); + ostr.println(" jj_gc = 0;"); + ostr.println(" for (int i = 0; i < jj_2_rtns.Length; i++) {"); + ostr.println(" JJCalls c = jj_2_rtns[i];"); + ostr.println(" while (c != null) {"); + ostr.println(" if (c.gen < jj_gen) c.first = null;"); + ostr.println(" c = c.next;"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(" }"); + } + } + if (Options.getDebugParser()) { + ostr.println(" trace_token(token, \"\");"); + } + ostr.println(" return token;"); + ostr.println(" }"); + if (Options.getCacheTokens()) { + ostr.println(" jj_nt = token;"); + } + ostr.println(" token = oldToken;"); + if (Options.getErrorReporting()) { + ostr.println(" jj_kind = kind;"); + } + ostr.println(" throw generateParseException();"); + ostr.println(" }"); + ostr.println(""); + if (jj2index != 0) { + ostr.println(" class LookaheadSuccess : System.Exception{ }"); + ostr.println(" " + staticOpt() + "private LookaheadSuccess jj_ls = new LookaheadSuccess();"); + ostr.println(" " + staticOpt() + "private bool jj_scan_token(int kind) {"); + ostr.println(" if (jj_scanpos == jj_lastpos) {"); + ostr.println(" jj_la--;"); + ostr.println(" if (jj_scanpos.next == null) {"); + ostr.println(" jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();"); + ostr.println(" } else {"); + ostr.println(" jj_lastpos = jj_scanpos = jj_scanpos.next;"); + ostr.println(" }"); + ostr.println(" } else {"); + ostr.println(" jj_scanpos = jj_scanpos.next;"); + ostr.println(" }"); + if (Options.getErrorReporting()) { + ostr.println(" if (jj_rescan) {"); + ostr.println(" int i = 0; Token tok = token;"); + ostr.println(" while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }"); + ostr.println(" if (tok != null) jj_add_error_token(kind, i);"); + if (Options.getDebugLookahead()) { + ostr.println(" } else {"); + ostr.println(" trace_scan(jj_scanpos, kind);"); + } + ostr.println(" }"); + } else if (Options.getDebugLookahead()) { + ostr.println(" trace_scan(jj_scanpos, kind);"); + } + ostr.println(" if (jj_scanpos.kind != kind) return true;"); + ostr.println(" if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;"); + ostr.println(" return false;"); + ostr.println(" }"); + ostr.println(""); + } + ostr.println(" " + staticOpt() + "public Token getNextToken() {"); + if (Options.getCacheTokens()) { + ostr.println(" if ((token = jj_nt).next != null) jj_nt = jj_nt.next;"); + ostr.println(" else jj_nt = jj_nt.next = token_source.getNextToken();"); + } else { + ostr.println(" if (token.next != null) token = token.next;"); + ostr.println(" else token = token.next = token_source.getNextToken();"); + ostr.println(" jj_ntk = -1;"); + } + if (Options.getErrorReporting()) { + ostr.println(" jj_gen++;"); + } + if (Options.getDebugParser()) { + ostr.println(" trace_token(token, \" (in getNextToken)\");"); + } + ostr.println(" return token;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "public Token getToken(int index) {"); + if (jj2index != 0) { + ostr.println(" Token t = lookingAhead ? jj_scanpos : token;"); + } else { + ostr.println(" Token t = token;"); + } + ostr.println(" for (int i = 0; i < index; i++) {"); + ostr.println(" if (t.next != null) t = t.next;"); + ostr.println(" else t = t.next = token_source.getNextToken();"); + ostr.println(" }"); + ostr.println(" return t;"); + ostr.println(" }"); + ostr.println(""); + if (!Options.getCacheTokens()) { + ostr.println(" " + staticOpt() + "private long jj_init_ntk() {"); + ostr.println(" if ((jj_nt=token.next) == null)"); + ostr.println(" return (jj_ntk = (token.next=token_source.getNextToken()).kind);"); + ostr.println(" else"); + ostr.println(" return (jj_ntk = jj_nt.kind);"); + ostr.println(" }"); + ostr.println(""); + } + if (Options.getErrorReporting()) { + ostr.println(" " + staticOpt() + "private System.Collections.Generic.List jj_expentries = new System.Collections.Generic.List();"); + ostr.println(" " + staticOpt() + "private long[] jj_expentry;"); + ostr.println(" " + staticOpt() + "private long jj_kind = -1;"); + if (jj2index != 0) { + ostr.println(" " + staticOpt() + "private long[] jj_lasttokens = new long[100];"); + ostr.println(" " + staticOpt() + "private long jj_endpos;"); + ostr.println(""); + ostr.println(" " + staticOpt() + "private void jj_add_error_token(int kind, int pos) {"); + ostr.println(" if (pos >= 100) return;"); + ostr.println(" if (pos == jj_endpos + 1) {"); + ostr.println(" jj_lasttokens[jj_endpos++] = kind;"); + ostr.println(" } else if (jj_endpos != 0) {"); + ostr.println(" jj_expentry = new long[jj_endpos];"); + ostr.println(" for (int i = 0; i < jj_endpos; i++) {"); + ostr.println(" jj_expentry[i] = jj_lasttokens[i];"); + ostr.println(" }"); + ostr.println(" bool exists = false;"); + ostr.println(" foreach(long[] oldentry in jj_expentries) {"); + ostr.println(" if (oldentry.Length == jj_expentry.Length) {"); + ostr.println(" exists = true;"); + ostr.println(" for (int i = 0; i < jj_expentry.Length; i++) {"); + ostr.println(" if (oldentry[i] != jj_expentry[i]) {"); + ostr.println(" exists = false;"); + ostr.println(" break;"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(" if (exists) break;"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(" if (!exists) jj_expentries.Add(jj_expentry);"); + ostr.println(" if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;"); + ostr.println(" }"); + ostr.println(" }"); + } + ostr.println(""); + ostr.println(" " + staticOpt() + "public ParseException generateParseException() {"); + ostr.println(" jj_expentries.Clear();"); + ostr.println(" bool[] la1tokens = new bool[" + tokenCount + "];"); + ostr.println(" for (int i = 0; i < " + tokenCount + "; i++) {"); + ostr.println(" la1tokens[i] = false;"); + ostr.println(" }"); + ostr.println(" if (jj_kind >= 0) {"); + ostr.println(" la1tokens[jj_kind] = true;"); + ostr.println(" jj_kind = -1;"); + ostr.println(" }"); + ostr.println(" for (int i = 0; i < " + maskindex + "; i++) {"); + ostr.println(" if (jj_la1[i] == jj_gen) {"); + ostr.println(" for (int j = 0; j < 32; j++) {"); + for (int i = 0; i < (tokenCount-1)/32 + 1; i++) { + ostr.println(" if ((jj_la1_" + i + "[i] & (1<. Encountered: \" + mess);"); + ostr.println(" }"); + } + ostr.println(""); + + if (Options.getDebugParser()) { + ostr.println(" " + staticOpt() + "private int trace_indent = 0;"); + ostr.println(" " + staticOpt() + "private bool trace_enabled = true;"); + ostr.println(""); + ostr.println(" " + staticOpt() + "public void enable_tracing() {"); + ostr.println(" trace_enabled = true;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "public void disable_tracing() {"); + ostr.println(" trace_enabled = false;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "private void trace_call(String s) {"); + ostr.println(" if (trace_enabled) {"); + ostr.println(" for (int i = 0; i < trace_indent; i++) { System.Console.Write(\" \"); }"); + ostr.println(" System.Console.WriteLine(\"Call: \" + s);"); + ostr.println(" }"); + ostr.println(" trace_indent = trace_indent + 2;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "private void trace_return(String s) {"); + ostr.println(" trace_indent = trace_indent - 2;"); + ostr.println(" if (trace_enabled) {"); + ostr.println(" for (int i = 0; i < trace_indent; i++) { System.Console.Write(\" \"); }"); + ostr.println(" System.Console.WriteLine(\"Return: \" + s);"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "private void trace_token(Token t, String where) {"); + ostr.println(" if (trace_enabled) {"); + ostr.println(" for (int i = 0; i < trace_indent; i++) { System.Console.Write(\" \"); }"); + ostr.println(" System.Console.Write(\"Consumed token: <\" + tokenImage[t.kind]);"); + ostr.println(" if (t.kind != 0 && !tokenImage[t.kind].equals(\"\\\"\" + t.image + \"\\\"\")) {"); + ostr.println(" System.Console.Write(\": \\\"\" + t.image + \"\\\"\");"); + ostr.println(" }"); + ostr.println(" System.Console.WriteLine(\" at line \" + t.beginLine + \" column \" + t.beginColumn + \">\" + where);"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "private void trace_scan(Token t1, int t2) {"); + ostr.println(" if (trace_enabled) {"); + ostr.println(" for (int i = 0; i < trace_indent; i++) { System.Console.Write(\" \"); }"); + ostr.println(" System.Console.Write(\"Visited token: <\" + tokenImage[t1.kind]);"); + ostr.println(" if (t1.kind != 0 && !tokenImage[t1.kind].equals(\"\\\"\" + t1.image + \"\\\"\")) {"); + ostr.println(" System.Console.Write(\": \\\"\" + t1.image + \"\\\"\");"); + ostr.println(" }"); + ostr.println(" System.Console.WriteLine(\" at line \" + t1.beginLine + \" column \" + t1.beginColumn + \">; Expected token: <\" + tokenImage[t2] + \">\");"); + ostr.println(" }"); + ostr.println(" }"); + ostr.println(""); + } else { + ostr.println(" " + staticOpt() + "public void enable_tracing() {"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "public void disable_tracing() {"); + ostr.println(" }"); + ostr.println(""); + } + + if (jj2index != 0 && Options.getErrorReporting()) { + ostr.println(" " + staticOpt() + "private void jj_rescan_token() {"); + ostr.println(" jj_rescan = true;"); + ostr.println(" for (int i = 0; i < " + jj2index + "; i++) {"); + ostr.println(" try {"); + ostr.println(" JJCalls p = jj_2_rtns[i];"); + ostr.println(" do {"); + ostr.println(" if (p.gen > jj_gen) {"); + ostr.println(" jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;"); + ostr.println(" switch (i) {"); + for (int i = 0; i < jj2index; i++) { + ostr.println(" case " + i + ": jj_3_" + (i+1) + "(); break;"); + } + ostr.println(" }"); + ostr.println(" }"); + ostr.println(" p = p.next;"); + ostr.println(" } while (p != null);"); + ostr.println(" } catch(LookaheadSuccess ls) { }"); + ostr.println(" }"); + ostr.println(" jj_rescan = false;"); + ostr.println(" }"); + ostr.println(""); + ostr.println(" " + staticOpt() + "private void jj_save(int index, int xla) {"); + ostr.println(" JJCalls p = jj_2_rtns[index];"); + ostr.println(" while (p.gen > jj_gen) {"); + ostr.println(" if (p.next == null) { p = p.next = new JJCalls(); break; }"); + ostr.println(" p = p.next;"); + ostr.println(" }"); + ostr.println(" p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;"); + ostr.println(" }"); + ostr.println(""); + } + + if (jj2index != 0 && Options.getErrorReporting()) { + ostr.println(" class JJCalls {"); + ostr.println(" public long gen;"); + ostr.println(" public Token first;"); + ostr.println(" public int arg;"); + ostr.println(" public JJCalls next;"); + ostr.println(" }"); + ostr.println(""); + } + + if (cu_from_insertion_point_2.size() != 0) { + printTokenSetup((Token)(cu_from_insertion_point_2.elementAt(0))); ccol = 1; + for (Enumeration e = cu_from_insertion_point_2.elements(); e.hasMoreElements();) { + t = (Token)e.nextElement(); + printToken(t, ostr); + } + printTrailingComments(t, ostr); + } + ostr.println(""); + + if(namespace) + ostr.println("}"); + + ostr.println(""); + ostr.close(); + + } // matches "if (Options.getBuildParser())" + } + + static private PrintWriter ostr; + + public static void reInit() + { + ostr = null; + } + +} diff --git a/csjavacc/parser/RCharacterList.java b/csjavacc/parser/RCharacterList.java new file mode 100644 index 0000000..76a0d35 --- /dev/null +++ b/csjavacc/parser/RCharacterList.java @@ -0,0 +1,617 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.util.*; + +import csjavacc.struct.CharacterRange; +import csjavacc.struct.Nfa; +import csjavacc.struct.RegularExpression; + +/** + * Describes character lists. + */ + +public class RCharacterList extends RegularExpression { + + /** + * This is true if a tilde (~) appears before the character list. + * Otherwise, this is false. + */ + public boolean negated_list = false; + + /** + * This is the list of descriptors of the character list. Each vector + * entry will narrow to either SingleCharacter or to CharacterRange. + */ + public java.util.Vector descriptors = new java.util.Vector(); + +static final char[] diffLowerCaseRanges = { +65, 90, 192, 214, 216, 222, 256, 256, 258, 258, 260, 260, 262, 262, 264, 264, +266, 266, 268, 268, 270, 270, 272, 272, 274, 274, 276, 276, 278, 278, 280, 280, +282, 282, 284, 284, 286, 286, 288, 288, 290, 290, 292, 292, 294, 294, 296, 296, +298, 298, 300, 300, 302, 302, /* new for fixing 1.0.2 */ 304, 304, /* End new */ +306, 306, 308, 308, 310, 310, 313, 313, 315, 315, +317, 317, 319, 319, 321, 321, 323, 323, 325, 325, 327, 327, 330, 330, 332, 332, +334, 334, 336, 336, 338, 338, 340, 340, 342, 342, 344, 344, 346, 346, 348, 348, +350, 350, 352, 352, 354, 354, 356, 356, 358, 358, 360, 360, 362, 362, 364, 364, +366, 366, 368, 368, 370, 370, 372, 372, 374, 374, 376, 376, 377, 377, 379, 379, +381, 381, 385, 385, 386, 386, 388, 388, 390, 390, 391, 391, +/* new for fixing 1.0.2 */ 393, 393, /* End new */ 394, 394, 395, 395, +/*398, Sreeni fixed for 1.2*/ 399, 399, 400, 400, 401, 401, 403, 403, 404, 404, 406, 406, 407, 407, 408, 408, +412, 412, 413, 413, 416, 416, 418, 418, 420, 420, 423, 423, 425, 425, 428, 428, +430, 430, 431, 431, 433, 434, 435, 435, 437, 437, 439, 439, 440, 440, 444, 444, +452, 452, 453, 453, 455, 455, 456, 456, 458, 458, 459, 459, 461, 461, 463, 463, +465, 465, 467, 467, 469, 469, 471, 471, 473, 473, 475, 475, 478, 478, 480, 480, +482, 482, 484, 484, 486, 486, 488, 488, 490, 490, 492, 492, 494, 494, 497, 497, +498, 498, 500, 500, 506, 506, 508, 508, 510, 510, 512, 512, 514, 514, 516, 516, +518, 518, 520, 520, 522, 522, 524, 524, 526, 526, 528, 528, 530, 530, 532, 532, +534, 534, 902, 902, 904, 906, 908, 908, 910, 911, 913, 929, 931, 939, 994, 994, +996, 996, 998, 998, 1000, 1000, 1002, 1002, 1004, 1004, 1006, 1006, 1025, 1036, +1038, 1039, 1040, 1040, 1041, 1041, 1042, 1071, 1120, 1120, 1122, 1122, +1124, 1124, 1126, 1126, 1128, 1128, 1130, 1130, 1132, 1132, 1134, 1134, +1136, 1136, 1138, 1138, 1140, 1140, 1142, 1142, 1144, 1144, 1146, 1146, +1148, 1148, 1150, 1150, 1152, 1152, 1168, 1168, 1170, 1170, 1172, 1172, +1174, 1174, 1176, 1176, 1178, 1178, 1180, 1180, 1182, 1182, 1184, 1184, +1186, 1186, 1188, 1188, 1190, 1190, 1192, 1192, 1194, 1194, 1196, 1196, +1198, 1198, 1200, 1200, 1202, 1202, 1204, 1204, 1206, 1206, 1208, 1208, +1210, 1210, 1212, 1212, 1214, 1214, 1217, 1217, 1219, 1219, 1223, 1223, +1227, 1227, 1232, 1232, 1234, 1234, 1236, 1236, 1238, 1238, 1240, 1240, +1242, 1242, 1244, 1244, 1246, 1246, 1248, 1248, 1250, 1250, 1252, 1252, +1254, 1254, 1256, 1256, 1258, 1258, 1262, 1262, 1264, 1264, 1266, 1266, +1268, 1268, 1272, 1272, 1329, 1366, 4256, 4293, 7680, 7680, 7682, 7682, +7684, 7684, 7686, 7686, 7688, 7688, 7690, 7690, 7692, 7692, 7694, 7694, +7696, 7696, 7698, 7698, 7700, 7700, 7702, 7702, 7704, 7704, 7706, 7706, +7708, 7708, 7710, 7710, 7712, 7712, 7714, 7714, 7716, 7716, 7718, 7718, +7720, 7720, 7722, 7722, 7724, 7724, 7726, 7726, 7728, 7728, 7730, 7730, +7732, 7732, 7734, 7734, 7736, 7736, 7738, 7738, 7740, 7740, 7742, 7742, +7744, 7744, 7746, 7746, 7748, 7748, 7750, 7750, 7752, 7752, 7754, 7754, +7756, 7756, 7758, 7758, 7760, 7760, 7762, 7762, 7764, 7764, 7766, 7766, +7768, 7768, 7770, 7770, 7772, 7772, 7774, 7774, 7776, 7776, 7778, 7778, +7780, 7780, 7782, 7782, 7784, 7784, 7786, 7786, 7788, 7788, 7790, 7790, +7792, 7792, 7794, 7794, 7796, 7796, 7798, 7798, 7800, 7800, 7802, 7802, +7804, 7804, 7806, 7806, 7808, 7808, 7810, 7810, 7812, 7812, 7814, 7814, +7816, 7816, 7818, 7818, 7820, 7820, 7822, 7822, 7824, 7824, 7826, 7826, +7828, 7828, 7840, 7840, 7842, 7842, 7844, 7844, 7846, 7846, 7848, 7848, +7850, 7850, 7852, 7852, 7854, 7854, 7856, 7856, 7858, 7858, 7860, 7860, +7862, 7862, 7864, 7864, 7866, 7866, 7868, 7868, 7870, 7870, 7872, 7872, +7874, 7874, 7876, 7876, 7878, 7878, 7880, 7880, 7882, 7882, 7884, 7884, +7886, 7886, 7888, 7888, 7890, 7890, 7892, 7892, 7894, 7894, 7896, 7896, +7898, 7898, 7900, 7900, 7902, 7902, 7904, 7904, 7906, 7906, 7908, 7908, +7910, 7910, 7912, 7912, 7914, 7914, 7916, 7916, 7918, 7918, 7920, 7920, +7922, 7922, 7924, 7924, 7926, 7926, 7928, 7928, 7944, 7951, 7960, 7965, +7976, 7983, 7992, 7999, 8008, 8013, 8025, 8025, 8027, 8027, 8029, 8029, +8031, 8031, 8040, 8047, 8072, 8079, 8088, 8095, 8104, 8111, 8120, 8121, +8122, 8123, 8124, 8124, 8136, 8139, 8140, 8140, 8152, 8153, 8154, 8155, +8168, 8169, 8170, 8171, 8172, 8172, 8184, 8185, 8186, 8187, 8188, 8188, +8544, 8559, 9398, 9423, 65313, 65338, 65339, 0xfffe, 0xffff, 0xffff +}; + +static final char[] diffUpperCaseRanges = { +97, 122, 224, 246, 248, 254, 255, 255, 257, 257, 259, 259, 261, 261, 263, 263, +265, 265, 267, 267, 269, 269, 271, 271, 273, 273, 275, 275, 277, 277, 279, 279, +281, 281, 283, 283, 285, 285, 287, 287, 289, 289, 291, 291, 293, 293, 295, 295, +297, 297, 299, 299, 301, 301, 303, 303, 305, 305, 307, 307, 309, 309, 311, 311, +314, 314, 316, 316, 318, 318, 320, 320, 322, 322, 324, 324, 326, 326, 328, 328, +331, 331, 333, 333, 335, 335, 337, 337, 339, 339, 341, 341, 343, 343, 345, 345, +347, 347, 349, 349, 351, 351, 353, 353, 355, 355, 357, 357, 359, 359, 361, 361, +363, 363, 365, 365, 367, 367, 369, 369, 371, 371, 373, 373, 375, 375, 378, 378, +380, 380, 382, 382, 383, 383, 387, 387, 389, 389, 392, 392, 396, 396, 402, 402, +409, 409, 417, 417, 419, 419, 421, 421, 424, 424, 429, 429, 432, 432, 436, 436, +438, 438, 441, 441, 445, 445, 453, 453, 454, 454, 456, 456, 457, 457, 459, 459, +460, 460, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, +476, 476, 479, 479, 481, 481, 483, 483, 485, 485, 487, 487, 489, 489, 491, 491, +493, 493, 495, 495, 498, 498, 499, 499, 501, 501, 507, 507, 509, 509, 511, 511, +513, 513, 515, 515, 517, 517, 519, 519, 521, 521, 523, 523, 525, 525, 527, 527, +529, 529, 531, 531, 533, 533, 535, 535, 595, 595, 596, 596, 598, +/* new for fixing 1.0.2 */ 598, 599, /* End new */ 599, /*600, Sreeni fixed for 1.2 */ +601, 601, +603, 603, 608, 608, 611, 611, 616, 616, 617, 617, 623, 623, 626, 626, 643, 643, +648, 648, 650, 651, 658, 658, 940, 940, 941, 943, 945, 961, +/* new for fixing 1.0.2 */ 962, 962, /* End new */ 963, 971, 972, 972, +973, 974, 976, 976, 977, 977, 981, 981, 982, 982, 995, 995, 997, 997, 999, 999, +1001, 1001, 1003, 1003, 1005, 1005, 1007, 1007, 1008, 1008, 1009, 1009, +1072, 1103, 1105, 1116, 1118, 1119, 1121, 1121, 1123, 1123, 1125, 1125, +1127, 1127, 1129, 1129, 1131, 1131, 1133, 1133, 1135, 1135, 1137, 1137, +1139, 1139, 1141, 1141, 1143, 1143, 1145, 1145, 1147, 1147, 1149, 1149, +1151, 1151, 1153, 1153, 1169, 1169, 1171, 1171, 1173, 1173, 1175, 1175, +1177, 1177, 1179, 1179, 1181, 1181, 1183, 1183, 1185, 1185, 1187, 1187, +1189, 1189, 1191, 1191, 1193, 1193, 1195, 1195, 1197, 1197, 1199, 1199, +1201, 1201, 1203, 1203, 1205, 1205, 1207, 1207, 1209, 1209, 1211, 1211, +1213, 1213, 1215, 1215, 1218, 1218, 1220, 1220, 1224, 1224, 1228, 1228, +1233, 1233, 1235, 1235, 1237, 1237, 1239, 1239, 1241, 1241, 1243, 1243, +1245, 1245, 1247, 1247, 1249, 1249, 1251, 1251, 1253, 1253, 1255, 1255, +1257, 1257, 1259, 1259, 1263, 1263, 1265, 1265, 1267, 1267, 1269, 1269, +1273, 1273, 1377, 1414, 7681, 7681, 7683, 7683, 7685, 7685, 7687, 7687, +7689, 7689, 7691, 7691, 7693, 7693, 7695, 7695, 7697, 7697, 7699, 7699, +7701, 7701, 7703, 7703, 7705, 7705, 7707, 7707, 7709, 7709, 7711, 7711, +7713, 7713, 7715, 7715, 7717, 7717, 7719, 7719, 7721, 7721, 7723, 7723, +7725, 7725, 7727, 7727, 7729, 7729, 7731, 7731, 7733, 7733, 7735, 7735, +7737, 7737, 7739, 7739, 7741, 7741, 7743, 7743, 7745, 7745, 7747, 7747, +7749, 7749, 7751, 7751, 7753, 7753, 7755, 7755, 7757, 7757, 7759, 7759, +7761, 7761, 7763, 7763, 7765, 7765, 7767, 7767, 7769, 7769, 7771, 7771, +7773, 7773, 7775, 7775, 7777, 7777, 7779, 7779, 7781, 7781, 7783, 7783, +7785, 7785, 7787, 7787, 7789, 7789, 7791, 7791, 7793, 7793, 7795, 7795, +7797, 7797, 7799, 7799, 7801, 7801, 7803, 7803, 7805, 7805, 7807, 7807, +7809, 7809, 7811, 7811, 7813, 7813, 7815, 7815, 7817, 7817, 7819, 7819, +7821, 7821, 7823, 7823, 7825, 7825, 7827, 7827, 7829, 7829, 7841, 7841, +7843, 7843, 7845, 7845, 7847, 7847, 7849, 7849, 7851, 7851, 7853, 7853, +7855, 7855, 7857, 7857, 7859, 7859, 7861, 7861, 7863, 7863, 7865, 7865, +7867, 7867, 7869, 7869, 7871, 7871, 7873, 7873, 7875, 7875, 7877, 7877, +7879, 7879, 7881, 7881, 7883, 7883, 7885, 7885, 7887, 7887, 7889, 7889, +7891, 7891, 7893, 7893, 7895, 7895, 7897, 7897, 7899, 7899, 7901, 7901, +7903, 7903, 7905, 7905, 7907, 7907, 7909, 7909, 7911, 7911, 7913, 7913, +7915, 7915, 7917, 7917, 7919, 7919, 7921, 7921, 7923, 7923, 7925, 7925, +7927, 7927, 7929, 7929, 7936, 7943, 7952, 7957, 7968, 7975, 7984, 7991, +8000, 8005, 8017, 8017, 8019, 8019, 8021, 8021, 8023, 8023, 8032, 8039, +8048, 8049, 8050, 8053, 8054, 8055, 8056, 8057, 8058, 8059, 8060, 8061, +8064, 8071, 8080, 8087, 8096, 8103, 8112, 8113, 8115, 8115, 8131, 8131, +8144, 8145, 8160, 8161, 8165, 8165, 8179, 8179, 8560, 8575, 9424, 9449, +65345, 65370, 65371, 0xfffe, 0xffff, 0xffff +}; + + void ToCaseNeutral() + { + int cnt = descriptors.size(); + + OuterLoop: + for (int i = 0; i < cnt; i++) + { + if (descriptors.elementAt(i) instanceof SingleCharacter) + { + char ch = ((SingleCharacter)descriptors.elementAt(i)).ch; + + if (ch != Character.toLowerCase(ch)) + descriptors.addElement(new + SingleCharacter(Character.toLowerCase(ch))); + if (ch != Character.toUpperCase(ch)) + descriptors.addElement(new + SingleCharacter(Character.toUpperCase(ch))); + } + else + { + char l = ((CharacterRange)descriptors.elementAt(i)).left; + char r = ((CharacterRange)descriptors.elementAt(i)).right; + int j = 0; + + /* Add ranges for which lower case is different. */ + for (;;) + { + while (l > diffLowerCaseRanges[j]) + j += 2; + + if (l < diffLowerCaseRanges[j]) + { + if (r < diffLowerCaseRanges[j]) + break; + + if (r <= diffLowerCaseRanges[j + 1]) + { + descriptors.addElement(new CharacterRange(Character.toLowerCase(diffLowerCaseRanges[j]), + (char)(Character.toLowerCase(diffLowerCaseRanges[j]) + r - diffLowerCaseRanges[j]))); + break; + } + + descriptors.addElement(new CharacterRange(Character.toLowerCase(diffLowerCaseRanges[j]), + Character.toLowerCase(diffLowerCaseRanges[j + 1]))); + } + else + { + if (r <= diffLowerCaseRanges[j + 1]) + { + descriptors.addElement(new CharacterRange( + (char)(Character.toLowerCase(diffLowerCaseRanges[j]) + l - diffLowerCaseRanges[j]), + (char)(Character.toLowerCase(diffLowerCaseRanges[j]) + r - diffLowerCaseRanges[j]))); + break; + } + + descriptors.addElement(new CharacterRange( + (char)(Character.toLowerCase(diffLowerCaseRanges[j]) + l - diffLowerCaseRanges[j]), + Character.toLowerCase(diffLowerCaseRanges[j + 1]))); + } + + j += 2; + while (r > diffLowerCaseRanges[j]) + { + if (r <= diffLowerCaseRanges[j + 1]) + { + descriptors.addElement(new CharacterRange(Character.toLowerCase(diffLowerCaseRanges[j]), + (char)(Character.toLowerCase(diffLowerCaseRanges[j]) + r - diffLowerCaseRanges[j]))); + break; + } + + descriptors.addElement(new CharacterRange(Character.toLowerCase(diffLowerCaseRanges[j]), + Character.toLowerCase(diffLowerCaseRanges[j + 1]))); + j += 2; + } + break; + } + + /* Add ranges for which upper case is different. */ + j = 0; + while (l > diffUpperCaseRanges[j]) + j += 2; + + if (l < diffUpperCaseRanges[j]) + { + if (r < diffUpperCaseRanges[j]) + continue; + + if (r <= diffUpperCaseRanges[j + 1]) + { + descriptors.addElement(new CharacterRange(Character.toUpperCase(diffUpperCaseRanges[j]), + (char)(Character.toUpperCase(diffUpperCaseRanges[j]) + r - diffUpperCaseRanges[j]))); + continue; + } + + descriptors.addElement(new CharacterRange(Character.toUpperCase(diffUpperCaseRanges[j]), + Character.toUpperCase(diffUpperCaseRanges[j + 1]))); + } + else + { + if (r <= diffUpperCaseRanges[j + 1]) + { + descriptors.addElement(new CharacterRange( + (char)(Character.toUpperCase(diffUpperCaseRanges[j]) + l - diffUpperCaseRanges[j]), + (char)(Character.toUpperCase(diffUpperCaseRanges[j]) + r - diffUpperCaseRanges[j]))); + continue; + } + + descriptors.addElement(new CharacterRange( + (char)(Character.toUpperCase(diffUpperCaseRanges[j]) + l - diffUpperCaseRanges[j]), + Character.toUpperCase(diffUpperCaseRanges[j + 1]))); + } + + j += 2; + while (r > diffUpperCaseRanges[j]) + { + if (r <= diffUpperCaseRanges[j + 1]) + { + descriptors.addElement(new CharacterRange(Character.toUpperCase(diffUpperCaseRanges[j]), + (char)(Character.toUpperCase(diffUpperCaseRanges[j]) + r - diffUpperCaseRanges[j]))); + break; + } + + descriptors.addElement(new CharacterRange(Character.toUpperCase(diffUpperCaseRanges[j]), + Character.toUpperCase(diffUpperCaseRanges[j + 1]))); + j += 2; + } + } + } + } + + boolean transformed = false; + public Nfa GenerateNfa(boolean ignoreCase) + { + if (!transformed) + { + if (Options.getIgnoreCase() || ignoreCase) + { +/* + int i; + System.err.println("Before:"); + for (i = 0; i < descriptors.size(); i++) + { + if (descriptors.elementAt(i) instanceof SingleCharacter) + { + char c = ((SingleCharacter)descriptors.elementAt(i)).ch; + System.err.print((int)c + " "); + } + else + { + char l = ((CharacterRange)descriptors.elementAt(i)).left; + char r = ((CharacterRange)descriptors.elementAt(i)).right; + + System.err.print((int)l + "-" + (int)r + " "); + } + if ((i + 1) % 6 == 0) + System.err.println(""); + } + System.err.println(""); +*/ + + ToCaseNeutral(); + SortDescriptors(); + +/* + System.err.println("After:"); + for (i = 0; i < descriptors.size(); i++) + { + if (descriptors.elementAt(i) instanceof SingleCharacter) + { + char c = ((SingleCharacter)descriptors.elementAt(i)).ch; + System.err.print((int)c + " "); + } + else + { + char l = ((CharacterRange)descriptors.elementAt(i)).left; + char r = ((CharacterRange)descriptors.elementAt(i)).right; + + System.err.print((int)l + "-" + (int)r + " "); + } + if ((i + 1) % 6 == 0) + System.err.println(""); + } + System.err.println(""); +*/ + } + + if (negated_list) + RemoveNegation(); // This also sorts the list + else + SortDescriptors(); + } + + transformed = true; + Nfa retVal = new Nfa(); + NfaState startState = retVal.start; + NfaState finalState = retVal.end; + int i; + + for (i = 0; i < descriptors.size(); i++) + { + if (descriptors.elementAt(i) instanceof SingleCharacter) + startState.AddChar(((SingleCharacter)descriptors.elementAt(i)).ch); + else // if (descriptors.elementAt(i) instanceof CharacterRange) + { + CharacterRange cr = (CharacterRange)descriptors.elementAt(i); + + if (cr.left == cr.right) + startState.AddChar(cr.left); + else + startState.AddRange(cr.left, cr.right); + } + } + + startState.next = finalState; + + return retVal; + } + + static boolean Overlaps(CharacterRange r1, CharacterRange r2) + { + return (r1.left <= r2.right && r1.right > r2.right); + } + + static boolean SubRange(CharacterRange r1, CharacterRange r2) + { + return (r1.left >= r2.left && r1.right <= r2.right); + } + + static boolean InRange(char c, CharacterRange range) + { + return (c >= range.left && c <= range.right); + } + + void SortDescriptors() + { + int j; + + Vector newDesc = new Vector(descriptors.size()); + int cnt = 0; + + Outer: + for (int i = 0; i < descriptors.size(); i++) + { + SingleCharacter s; + CharacterRange range; + + if (descriptors.elementAt(i) instanceof SingleCharacter) + { + s = (SingleCharacter)descriptors.elementAt(i); + + for (j = 0; j < cnt; j++) + { + if (newDesc.elementAt(j) instanceof SingleCharacter) + { + if (((SingleCharacter)newDesc.elementAt(j)).ch > s.ch) + break; + else if (((SingleCharacter)newDesc.elementAt(j)).ch == s.ch) + continue Outer; + } + else + { + char l = ((CharacterRange)newDesc.elementAt(j)).left; + + if (InRange(s.ch, (CharacterRange)newDesc.elementAt(j))) + continue Outer; + else if (l > s.ch) + break; + } + } + + newDesc.insertElementAt(s, j); + cnt++; + } + else + { + range = (CharacterRange)descriptors.elementAt(i); + + for (j = 0; j < cnt; j++) + { + if (newDesc.elementAt(j) instanceof SingleCharacter) + { + if (InRange(((SingleCharacter)newDesc.elementAt(j)).ch, range)) + { + newDesc.removeElementAt(j--); + cnt--; + } + else if (((SingleCharacter)newDesc.elementAt(j)).ch > range.right) + break; + } + else + { + if (SubRange(range, (CharacterRange)newDesc.elementAt(j))) + { + continue Outer; + } + else if (SubRange((CharacterRange)newDesc.elementAt(j), range)) + { + newDesc.setElementAt(range, j); + continue Outer; + } + else if (Overlaps(range, (CharacterRange)newDesc.elementAt(j))) + { + range.left = (char)(((CharacterRange)newDesc.elementAt(j)).right + 1); + } + else if (Overlaps((CharacterRange)newDesc.elementAt(j), range)) + { + CharacterRange tmp = range; + ((CharacterRange)newDesc.elementAt(j)).right = (char)(range.left + 1); + range = (CharacterRange)newDesc.elementAt(j); + newDesc.setElementAt(tmp, j); + } + else if (((CharacterRange)newDesc.elementAt(j)).left > range.right) + break; + } + } + + newDesc.insertElementAt(range, j); + cnt++; + } + } + + newDesc.trimToSize(); + descriptors = newDesc; + } + + void RemoveNegation() + { + int i; + + SortDescriptors(); + +/* + System.err.println("REM. NEG Before:"); + for (i = 0; i < descriptors.size(); i++) + { + if (descriptors.elementAt(i) instanceof SingleCharacter) + { + char c = ((SingleCharacter)descriptors.elementAt(i)).ch; + System.err.print((int)c + " "); + } + else + { + char l = ((CharacterRange)descriptors.elementAt(i)).left; + char r = ((CharacterRange)descriptors.elementAt(i)).right; + + System.err.print((int)l + "-" + (int)r + " "); + } + } + System.err.println(""); +*/ + + Vector newDescriptors = new Vector(); + int lastRemoved = -1; // One less than the first valid character. + + OuterLoop: + for (i = 0; i < descriptors.size(); i++) + { + if (descriptors.elementAt(i) instanceof SingleCharacter) + { + char c = ((SingleCharacter)descriptors.elementAt(i)).ch; + + if (c >= 0 && c <= lastRemoved + 1) + { + lastRemoved = c; + continue; + } + + //System.err.println("lastRemoved : " + (int)lastRemoved + "; char : " + (int)c); + newDescriptors.addElement(new CharacterRange((char)(lastRemoved + 1), + (char)((lastRemoved = c) - 1))); + } + else + { + char l = ((CharacterRange)descriptors.elementAt(i)).left; + char r = ((CharacterRange)descriptors.elementAt(i)).right; + + if (l >= 0 && l <= lastRemoved + 1) + { + lastRemoved = r; + continue; + } + + //System.err.println("lastRemoved : " + (int)lastRemoved + "; left : " + l + "; right : " + (int)r); + newDescriptors.addElement(new CharacterRange((char)(lastRemoved + 1), + (char)(l - 1))); + lastRemoved = r; + } + } + + //System.err.println("lastRem : " + (int)lastRemoved); + if (NfaState.unicodeWarningGiven || Options.getCSUnicodeEscape()) + { + if (lastRemoved < (char)0xffff) + newDescriptors.addElement(new CharacterRange((char)(lastRemoved + 1), + (char)0xffff)); + } + else + { + if (lastRemoved < (char)0xff) + newDescriptors.addElement(new CharacterRange((char)(lastRemoved + 1), + (char)0xff)); + } + + descriptors = newDescriptors; + negated_list = false; + +/* + System.err.println("REM NEG After:"); + for (i = 0; i < descriptors.size(); i++) + { + if (descriptors.elementAt(i) instanceof SingleCharacter) + { + char c = ((SingleCharacter)descriptors.elementAt(i)).ch; + System.err.print((int)c + " "); + } + else + { + char l = ((CharacterRange)descriptors.elementAt(i)).left; + char r = ((CharacterRange)descriptors.elementAt(i)).right; + + System.err.print((int)l + "-" + (int)r + " "); + } + } + System.err.println(""); +*/ + } + + public RCharacterList() + { + } + + public RCharacterList(char c) + { + descriptors = new Vector(); + descriptors.addElement(new SingleCharacter(c)); + negated_list = false; + ordinal = Integer.MAX_VALUE; + } + + public boolean CanMatchAnyChar() + { + // Return true only if it is ~[] + return negated_list && (descriptors == null || descriptors.size() == 0); + } +} diff --git a/csjavacc/parser/RChoice.java b/csjavacc/parser/RChoice.java new file mode 100644 index 0000000..c68cd44 --- /dev/null +++ b/csjavacc/parser/RChoice.java @@ -0,0 +1,153 @@ +/* + * 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. + */ + +package csjavacc.parser; +import java.util.Vector; + +import csjavacc.struct.Nfa; +import csjavacc.struct.RJustName; +import csjavacc.struct.RegularExpression; + + +/** + * Describes regular expressions which are choices from + * from among included regular expressions. + */ + +public class RChoice extends RegularExpression { + + /** + * The list of choices of this regular expression. Each + * Vector component will narrow to RegularExpression. + */ + public java.util.Vector choices = new java.util.Vector(); + + public Nfa GenerateNfa(boolean ignoreCase) + { + CompressCharLists(); + + if (choices.size() == 1) + return ((RegularExpression)choices.elementAt(0)).GenerateNfa(ignoreCase); + + Nfa retVal = new Nfa(); + NfaState startState = retVal.start; + NfaState finalState = retVal.end; + + for (int i = 0; i < choices.size(); i++) + { + Nfa temp; + RegularExpression curRE = (RegularExpression)choices.elementAt(i); + + temp = curRE.GenerateNfa(ignoreCase); + + startState.AddMove(temp.start); + temp.end.AddMove(finalState); + } + + return retVal; + } + + void CompressCharLists() + { + CompressChoices(); // Unroll nested choices + RegularExpression curRE; + RCharacterList curCharList = null; + + for (int i = 0; i < choices.size(); i++) + { + curRE = (RegularExpression)choices.elementAt(i); + + while (curRE instanceof RJustName) + curRE = ((RJustName)curRE).regexpr; + + if (curRE instanceof RStringLiteral && + ((RStringLiteral)curRE).image.length() == 1) + choices.setElementAt(curRE = new RCharacterList( + ((RStringLiteral)curRE).image.charAt(0)), i); + + if (curRE instanceof RCharacterList) + { + if (((RCharacterList)curRE).negated_list) + ((RCharacterList)curRE).RemoveNegation(); + + Vector tmp = ((RCharacterList)curRE).descriptors; + + if (curCharList == null) + choices.setElementAt(curRE = curCharList = + new RCharacterList(), i); + else + choices.removeElementAt(i--); + + for (int j = tmp.size(); j-- > 0;) + curCharList.descriptors.addElement(tmp.elementAt(j)); + } + + } + } + + void CompressChoices() + { + RegularExpression curRE; + + for (int i = 0; i < choices.size(); i++) + { + curRE = (RegularExpression)choices.elementAt(i); + + while (curRE instanceof RJustName) + curRE = ((RJustName)curRE).regexpr; + + if (curRE instanceof RChoice) + { + choices.removeElementAt(i--); + for (int j = ((RChoice)curRE).choices.size(); j-- > 0;) + choices.addElement(((RChoice)curRE).choices.elementAt(j)); + } + } + } + + public void CheckUnmatchability() + { + RegularExpression curRE; + int numStrings = 0; + + for (int i = 0; i < choices.size(); i++) + { + if (!(curRE = (RegularExpression)choices.elementAt(i)).private_rexp && + //curRE instanceof RJustName && + curRE.ordinal > 0 && curRE.ordinal < ordinal && + LexGen.lexStates[curRE.ordinal] == LexGen.lexStates[ordinal]) + { + if (label != null) + CSJavaCCErrors.warning(this, "Regular Expression choice : " + + curRE.label + " can never be matched as : " + label); + else + CSJavaCCErrors.warning(this, "Regular Expression choice : " + + curRE.label + " can never be matched as token of kind : " + + ordinal); + } + + if (!curRE.private_rexp && curRE instanceof RStringLiteral) + numStrings++; + } + } + +} diff --git a/csjavacc/parser/RStringLiteral.java b/csjavacc/parser/RStringLiteral.java new file mode 100644 index 0000000..f7f9f34 --- /dev/null +++ b/csjavacc/parser/RStringLiteral.java @@ -0,0 +1,1306 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import java.util.*; + +import csjavacc.struct.Nfa; +import csjavacc.struct.RegularExpression; + + +final class KindInfo +{ + long[] validKinds; + long[] finalKinds; + int validKindCnt = 0; + int finalKindCnt = 0; + + KindInfo(int maxKind) + { + validKinds = new long[maxKind / 64 + 1]; + finalKinds = new long[maxKind / 64 + 1]; + } + + public void InsertValidKind(int kind) + { + validKinds[kind / 64] |= (1L << (kind % 64)); + validKindCnt++; + } + + public void InsertFinalKind(int kind) + { + finalKinds[kind / 64] |= (1L << (kind % 64)); + finalKindCnt++; + } +}; + +/** + * Describes string literals. + */ + +public class RStringLiteral extends RegularExpression { + + /** + * The string image of the literal. + */ + public String image; + + static int maxStrKind = 0; + static int maxLen = 0; + static int charCnt = 0; + static Vector charPosKind = new Vector(); // Elements are hashtables + // with single char keys; + static int[] maxLenForActive = new int[100]; // 6400 tokens + public static String[] allImages; + static int[][] intermediateKinds; + static int[][] intermediateMatchedPos; + + static int startStateCnt = 0; + static boolean subString[]; + static boolean subStringAtPos[]; + static Hashtable[] statesForPos; + + // Need to call this method after gnerating code for each lexical state. It + // initializes all the static variables, so that there is no interference + // between the various states of the lexer. + public static void ReInit() + { + maxStrKind = 0; + maxLen = 0; + charPosKind = new Vector(); + maxLenForActive = new int[100]; // 6400 tokens + intermediateKinds = null; + intermediateMatchedPos = null; + startStateCnt = 0; + subString = null; + subStringAtPos = null; + statesForPos = null; + } + + public static void DumpStrLiteralImages(java.io.PrintWriter ostr) + { + String image; + int charCnt = 0, i; + + ostr.println("public static String[] jjstrLiteralImages = {"); + + if (allImages == null || allImages.length == 0){ + ostr.println("};"); + return; + } + + allImages[0] = ""; + for (i = 0; i < allImages.length; i++) + { + if ((image = allImages[i]) == null || + ((LexGen.toSkip[i / 64] & (1L << (i % 64))) == 0L && + (LexGen.toMore[i / 64] & (1L << (i % 64))) == 0L && + (LexGen.toToken[i / 64] & (1L << (i % 64))) == 0L) || + (LexGen.toSkip[i / 64] & (1L << (i % 64))) != 0L || + (LexGen.toMore[i / 64] & (1L << (i % 64))) != 0L || + LexGen.canReachOnMore[LexGen.lexStates[i]] || + ((Options.getIgnoreCase() || LexGen.ignoreCase[i]) && + (!image.equals(image.toLowerCase()) || + !image.equals(image.toUpperCase())))) + { + allImages[i] = null; + if ((charCnt += 6) > 80){ + ostr.println(""); + charCnt = 0; + } + + ostr.print("null, "); + continue; + } + + String toPrint = "\""; + + for (int j = 0; j < image.length(); j++){ + if (image.charAt(j) <= 0xff) + // C# (csharp) doesn't allow octal char literals + toPrint += ("\\x" + Integer.toHexString((int)image.charAt(j))); + else{ + String hexVal = Integer.toHexString((int)image.charAt(j)); + + if (hexVal.length() == 3) + hexVal = "0" + hexVal; + toPrint += ("\\u" + hexVal); + } + } + + toPrint += ( "\", "); + + if ((charCnt += toPrint.length()) >= 80) + { + ostr.println(""); + charCnt = 0; + } + + ostr.print(toPrint); + } + + while (++i < LexGen.maxOrdinal) + { + if ((charCnt += 6) > 80) + { + ostr.println(""); + charCnt = 0; + } + + ostr.print("null, "); + continue; + } + + ostr.println("};"); + } + + // Used for top level string literals + public void GenerateDfa(java.io.PrintWriter ostr, int kind) + { + String s; + Hashtable temp; + KindInfo info; + int len; + + if (maxStrKind <= ordinal) + maxStrKind = ordinal + 1; + + if ((len = image.length()) > maxLen) + maxLen = len; + + char c; + for (int i = 0; i < len; i++) + { + if (Options.getIgnoreCase()) + s = ("" + (c = image.charAt(i))).toLowerCase(); + else + s = "" + (c = image.charAt(i)); + + if (!NfaState.unicodeWarningGiven && c > 0xff && + !Options.getCSUnicodeEscape() && + !Options.getUserCharStream()) + { + NfaState.unicodeWarningGiven = true; + CSJavaCCErrors.warning(LexGen.curRE, "Non-ASCII characters used in regular expression." + + "Please make sure you use the correct Reader when you create the parser that can handle your character set."); + } + + if (i >= charPosKind.size()) // Kludge, but OK + charPosKind.addElement(temp = new Hashtable()); + else + temp = (Hashtable)charPosKind.elementAt(i); + + if ((info = (KindInfo)temp.get(s)) == null) + temp.put(s, info = new KindInfo(LexGen.maxOrdinal)); + + if (i + 1 == len) + info.InsertFinalKind(ordinal); + else + info.InsertValidKind(ordinal); + + if (!Options.getIgnoreCase() && LexGen.ignoreCase[ordinal] && + c != Character.toLowerCase(c)) + { + s = ("" + image.charAt(i)).toLowerCase(); + + if (i >= charPosKind.size()) // Kludge, but OK + charPosKind.addElement(temp = new Hashtable()); + else + temp = (Hashtable)charPosKind.elementAt(i); + + if ((info = (KindInfo)temp.get(s)) == null) + temp.put(s, info = new KindInfo(LexGen.maxOrdinal)); + + if (i + 1 == len) + info.InsertFinalKind(ordinal); + else + info.InsertValidKind(ordinal); + } + + if (!Options.getIgnoreCase() && LexGen.ignoreCase[ordinal] && + c != Character.toUpperCase(c)) + { + s = ("" + image.charAt(i)).toUpperCase(); + + if (i >= charPosKind.size()) // Kludge, but OK + charPosKind.addElement(temp = new Hashtable()); + else + temp = (Hashtable)charPosKind.elementAt(i); + + if ((info = (KindInfo)temp.get(s)) == null) + temp.put(s, info = new KindInfo(LexGen.maxOrdinal)); + + if (i + 1 == len) + info.InsertFinalKind(ordinal); + else + info.InsertValidKind(ordinal); + } + } + + maxLenForActive[ordinal / 64] = Math.max(maxLenForActive[ordinal / 64], + len -1); + allImages[ordinal] = image; + } + + public Nfa GenerateNfa(boolean ignoreCase) + { + if (image.length() == 1) + { + RCharacterList temp = new RCharacterList(image.charAt(0)); + return temp.GenerateNfa(ignoreCase); + } + + NfaState startState = new NfaState(); + NfaState theStartState = startState; + NfaState finalState = null; + + if (image.length() == 0) + return new Nfa(theStartState, theStartState); + + int i; + + for (i = 0; i < image.length(); i++) + { + finalState = new NfaState(); + startState.charMoves = new char[1]; + startState.AddChar(image.charAt(i)); + + if (Options.getIgnoreCase() || ignoreCase) + { + startState.AddChar(Character.toLowerCase(image.charAt(i))); + startState.AddChar(Character.toUpperCase(image.charAt(i))); + } + + startState.next = finalState; + startState = finalState; + } + + return new Nfa(theStartState, finalState); + } + + static void DumpNullStrLiterals(java.io.PrintWriter ostr) + { + ostr.println("{"); + + if (NfaState.generatedStates != 0) + ostr.println(" return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", 0);"); + else + ostr.println(" return 1;"); + + ostr.println("}"); + } + + private static int GetStateSetForKind(int pos, int kind) + { + if (LexGen.mixed[LexGen.lexStateIndex] || NfaState.generatedStates == 0) + return -1; + + Hashtable allStateSets = statesForPos[pos]; + + if (allStateSets == null) + return -1; + + Enumeration e = allStateSets.keys(); + + while (e.hasMoreElements()) + { + String s = (String)e.nextElement(); + long[] actives = (long[])allStateSets.get(s); + + s = s.substring(s.indexOf(", ") + 2); + s = s.substring(s.indexOf(", ") + 2); + + if (s.equals("null;")) + continue; + + if (actives != null && + (actives[kind / 64] & (1L << (kind % 64))) != 0L) + { + return NfaState.AddStartStateSet(s); + } + } + + return -1; + } + + static String GetLabel(int kind) + { + RegularExpression re = LexGen.rexprs[kind]; + + if (re instanceof RStringLiteral) + return " \"" + CSJavaCCGlobals.add_escapes(((RStringLiteral)re).image) + "\""; + else if (!re.label.equals("")) + return " <" + re.label + ">"; + else + return " "; + } + + static int GetLine(int kind) + { + return LexGen.rexprs[kind].line; + } + + static int GetColumn(int kind) + { + return LexGen.rexprs[kind].column; + } + + /** + * Returns true if s1 starts with s2 (ignoring case for each character). + */ + static private boolean StartsWithIgnoreCase(String s1, String s2) + { + if (s1.length() < s2.length()) + return false; + + for (int i = 0; i < s2.length(); i++) + { + char c1 = s1.charAt(i), c2 = s2.charAt(i); + + if (c1 != c2 && Character.toLowerCase(c2) != c1 && + Character.toUpperCase(c2) != c1) + return false; + } + + return true; + } + + static void FillSubString() + { + String image; + subString = new boolean[maxStrKind + 1]; + subStringAtPos = new boolean[maxLen]; + + for (int i = 0; i < maxStrKind; i++) + { + subString[i] = false; + + if ((image = allImages[i]) == null || + LexGen.lexStates[i] != LexGen.lexStateIndex) + continue; + + if (LexGen.mixed[LexGen.lexStateIndex]) + { + // We will not optimize for mixed case + subString[i] = true; + subStringAtPos[image.length() - 1] = true; + continue; + } + + for (int j = 0; j < maxStrKind; j++) + { + if (j != i && LexGen.lexStates[j] == LexGen.lexStateIndex && + ((String)allImages[j]) != null) + { + if (((String)allImages[j]).indexOf(image) == 0) + { + subString[i] = true; + subStringAtPos[image.length() - 1] = true; + break; + } + else if (Options.getIgnoreCase() && + StartsWithIgnoreCase((String)allImages[j], image)) + { + subString[i] = true; + subStringAtPos[image.length() - 1] = true; + break; + } + } + } + } + } + + static void DumpStartWithStates(java.io.PrintWriter ostr) + { + ostr.println((Options.getStatic() ? "static " : "") + "private int " + + "jjStartNfaWithStates" + LexGen.lexStateSuffix + "(int pos, int kind, int state)"); + ostr.println("{"); + ostr.println(" jjmatchedKind = kind;"); + ostr.println(" jjmatchedPos = pos;"); + + if (Options.getDebugTokenManager()) + { + ostr.println(" debugStream.WriteLine(\" No more string literal token matches are possible.\");"); + ostr.println(" debugStream.WriteLine(\" Currently matched the first \" + (jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); + } + + ostr.println(" try { curChar = input_stream.readChar(); }"); + ostr.println(" catch(System.IO.IOException e) { return pos + 1; }"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(" + (LexGen.maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + "\"Current character : \" + " + + "TokenMgrError.addEscapes(\"\"+(curChar)) + \" (\" + (int)curChar + \") at line \" + input_stream.getLine() + \" column \" + input_stream.getColumn());"); + + ostr.println(" return jjMoveNfa" + LexGen.lexStateSuffix + "(state, pos + 1);"); + ostr.println("}"); + } + + private static boolean boilerPlateDumped = false; + static void DumpBoilerPlate(java.io.PrintWriter ostr) + { + ostr.println((Options.getStatic() ? "static " : "") + "private int " + + "jjStopAtPos(int pos, int kind)"); + ostr.println("{"); + ostr.println(" jjmatchedKind = kind;"); + ostr.println(" jjmatchedPos = pos;"); + + if (Options.getDebugTokenManager()) + { + ostr.println(" debugStream.WriteLine(\" No more string literal token matches are possible.\");"); + ostr.println(" debugStream.WriteLine(\" Currently matched the first \" + (jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); + } + + ostr.println(" return pos + 1;"); + ostr.println("}"); + } + + static String[] ReArrange(Hashtable tab) + { + String[] ret = new String[tab.size()]; + Enumeration e = tab.keys(); + int cnt = 0; + + while (e.hasMoreElements()) + { + int i = 0, j; + String s; + char c = (s = (String)e.nextElement()).charAt(0); + + while (i < cnt && ret[i].charAt(0) < c) i++; + + if (i < cnt) + for (j = cnt - 1; j >= i; j--) + ret[j + 1] = ret[j]; + + ret[i] = s; + cnt++; + } + + return ret; + } + + static void DumpDfaCode(java.io.PrintWriter ostr) + { + Hashtable tab; + String key; + KindInfo info; + int maxLongsReqd = maxStrKind / 64 + 1; + int i, j, k; + boolean ifGenerated; + LexGen.maxLongsReqd[LexGen.lexStateIndex] = maxLongsReqd; + + if (maxLen == 0) + { + ostr.println((Options.getStatic() ? "static " : "") + "private int " + + "jjMoveStringLiteralDfa0" + LexGen.lexStateSuffix + "()"); + + DumpNullStrLiterals(ostr); + return; + } + + if (!boilerPlateDumped) + { + DumpBoilerPlate(ostr); + boilerPlateDumped = true; + } + + if (!LexGen.mixed[LexGen.lexStateIndex] && NfaState.generatedStates != 0) + DumpStartWithStates(ostr); + + boolean startNfaNeeded; + for (i = 0; i < maxLen; i++) + { + boolean atLeastOne = false; + startNfaNeeded = false; + tab = (Hashtable)charPosKind.elementAt(i); + String[] keys = ReArrange(tab); + + ostr.print((Options.getStatic() ? "static " : "") + "private int " + + "jjMoveStringLiteralDfa" + i + LexGen.lexStateSuffix + "("); + + if (i != 0) + { + if (i == 1) + { + for (j = 0; j < maxLongsReqd - 1; j++) + if (i <= maxLenForActive[j]) + { + if (atLeastOne) + ostr.print(", "); + else + atLeastOne = true; + ostr.print("long active" + j); + } + + if (i <= maxLenForActive[j]) + { + if (atLeastOne) + ostr.print(", "); + ostr.print("long active" + j); + } + } + else + { + for (j = 0; j < maxLongsReqd - 1; j++) + if (i <= maxLenForActive[j] + 1) + { + if (atLeastOne) + ostr.print(", "); + else + atLeastOne = true; + ostr.print("long old" + j + ", long active" + j); + } + + if (i <= maxLenForActive[j] + 1) + { + if (atLeastOne) + ostr.print(", "); + ostr.print("long old" + j + ", long active" + j); + } + } + } + ostr.println(")"); + ostr.println("{"); + + if (i != 0) + { + if (i > 1) + { + atLeastOne = false; + ostr.print(" if (("); + + for (j = 0; j < maxLongsReqd - 1; j++) + if (i <= maxLenForActive[j] + 1) + { + if (atLeastOne) + ostr.print(" | "); + else + atLeastOne = true; + ostr.print("(active" + j + " &= old" + j + ")"); + } + + if (i <= maxLenForActive[j] + 1) + { + if (atLeastOne) + ostr.print(" | "); + ostr.print("(active" + j + " &= old" + j + ")"); + } + + ostr.println(") == 0L)"); + if (!LexGen.mixed[LexGen.lexStateIndex] && NfaState.generatedStates != 0) + { + ostr.print(" return jjStartNfa" + LexGen.lexStateSuffix + + "(" + (i - 2) + ", "); + for (j = 0; j < maxLongsReqd - 1; j++) + if (i <= maxLenForActive[j] + 1) + ostr.print("old" + j + ", "); + else + ostr.print("0L, "); + if (i <= maxLenForActive[j] + 1) + ostr.println("old" + j + "); "); + else + ostr.println("0L);"); + } + else if (NfaState.generatedStates != 0) + ostr.println(" return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", " + (i - 1) + ");"); + else + ostr.println(" return " + i + ";"); + } + + if (i != 0 && Options.getDebugTokenManager()) + { + ostr.println(" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + Integer.toHexString(Integer.MAX_VALUE) + ")"); + ostr.println(" debugStream.WriteLine(\" Currently matched the first \" + (jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); + + ostr.println(" debugStream.WriteLine(\" Possible string literal matches : { \""); + + for (int vecs = 0; vecs < maxStrKind / 64 + 1; vecs++) + { + if (i <= maxLenForActive[vecs]) + { + ostr.println(" + "); + ostr.print(" jjKindsForBitVector(" + vecs + ", "); + ostr.print("active" + vecs + ") "); + } + } + + ostr.println(" + \" } \");"); + } + + ostr.println(" try { curChar = input_stream.readChar(); }"); + ostr.println(" catch(System.IO.IOException e) {"); + + if (!LexGen.mixed[LexGen.lexStateIndex] && NfaState.generatedStates != 0) + { + ostr.print(" jjStopStringLiteralDfa" + LexGen.lexStateSuffix + "(" + (i - 1) + ", "); + for (k = 0; k < maxLongsReqd - 1; k++) + if (i <= maxLenForActive[k]) + ostr.print("active" + k + ", "); + else + ostr.print("0L, "); + + if (i <= maxLenForActive[k]) + ostr.println("active" + k + ");"); + else + ostr.println("0L);"); + + + if (i != 0 && Options.getDebugTokenManager()) + { + ostr.println(" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + Integer.toHexString(Integer.MAX_VALUE) + ")"); + ostr.println(" debugStream.WriteLine(\" Currently matched the first \" + (jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); + } + ostr.println(" return " + i + ";"); + } + else if (NfaState.generatedStates != 0) + ostr.println(" return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", " + (i - 1) + ");"); + else + ostr.println(" return " + i + ";"); + + ostr.println(" }"); + } + + if (i != 0 && Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(" + (LexGen.maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + "\"Current character : \" + " + + "TokenMgrError.addEscapes(\"\"+(curChar)) + \" (\" + (int)curChar + \") at line \" + input_stream.getLine() + \" column \" + input_stream.getColumn());"); + + ostr.println(" switch((int)curChar)"); + ostr.println(" {"); + + CaseLoop: + for (int q = 0; q < keys.length; q++) + { + key = keys[q]; + info = (KindInfo)tab.get(key); + ifGenerated = false; + char c = key.charAt(0); + + if (i == 0 && c < 128 && info.finalKindCnt != 0 && + (NfaState.generatedStates == 0 || !NfaState.CanStartNfaUsingAscii(c))) + { + int kind; + Outer: + for (j = 0; j < maxLongsReqd; j++) + if (info.finalKinds[j] != 0L) + break; + + for (k = 0; k < 64; k++) + if ((info.finalKinds[j] & (1L << k)) != 0L && + !subString[kind = (j * 64 + k)]) + { + if ((intermediateKinds != null && + intermediateKinds[(j * 64 + k)] != null && + intermediateKinds[(j * 64 + k)][i] < (j * 64 + k) && + intermediateMatchedPos != null && + intermediateMatchedPos[(j * 64 + k)][i] == i) || + (LexGen.canMatchAnyChar[LexGen.lexStateIndex] >= 0 && + LexGen.canMatchAnyChar[LexGen.lexStateIndex] < (j * 64 + k))) + break; + else if ((LexGen.toSkip[kind / 64] & (1L << (kind % 64))) != 0L && + (LexGen.toSpecial[kind / 64] & (1L << (kind % 64))) == 0L && + LexGen.actions[kind] == null && + LexGen.newLexState[kind] == null) + { + LexGen.AddCharToSkip(c, kind); + + if (Options.getIgnoreCase()) + { + if (c != Character.toUpperCase(c)) + LexGen.AddCharToSkip(Character.toUpperCase(c), kind); + + if (c != Character.toLowerCase(c)) + LexGen.AddCharToSkip(Character.toLowerCase(c), kind); + } + continue CaseLoop; + } + } + } + + // Since we know key is a single character ... + if (Options.getIgnoreCase()) + { + if (c != Character.toUpperCase(c)) + ostr.println(" case " + (int)Character.toUpperCase(c) + ":"); + + if (c != Character.toLowerCase(c)) + ostr.println(" case " + (int)Character.toLowerCase(c) + ":"); + } + + ostr.println(" case " + (int)c + ":"); + + long matchedKind; + String prefix = (i == 0) ? " " : " "; + + if (info.finalKindCnt != 0) + { + for (j = 0; j < maxLongsReqd; j++) + { + if ((matchedKind = info.finalKinds[j]) == 0L) + continue; + + for (k = 0; k < 64; k++) + { + if ((matchedKind & (1L << k)) == 0L) + continue; + + if (ifGenerated) + { + ostr.print(" else if "); + } + else if (i != 0) + ostr.print(" if "); + + ifGenerated = true; + + int kindToPrint; + if (i != 0) + { + ostr.println("((active" + j + + " & 0x" + Long.toHexString(1L << k) + "L) != 0L)"); + } + + if (intermediateKinds != null && + intermediateKinds[(j * 64 + k)] != null && + intermediateKinds[(j * 64 + k)][i] < (j * 64 + k) && + intermediateMatchedPos != null && + intermediateMatchedPos[(j * 64 + k)][i] == i) + { + CSJavaCCErrors.warning(" \"" + + CSJavaCCGlobals.add_escapes(allImages[j * 64 + k]) + + "\" cannot be matched as a string literal token " + + "at line " + GetLine(j * 64 + k) + ", column " + GetColumn(j * 64 + k) + + ". It will be matched as " + + GetLabel(intermediateKinds[(j * 64 + k)][i]) + "."); + kindToPrint = intermediateKinds[(j * 64 + k)][i]; + } + else if (i == 0 && + LexGen.canMatchAnyChar[LexGen.lexStateIndex] >= 0 && + LexGen.canMatchAnyChar[LexGen.lexStateIndex] < (j * 64 + k)) + { + CSJavaCCErrors.warning(" \"" + + CSJavaCCGlobals.add_escapes(allImages[j * 64 + k]) + + "\" cannot be matched as a string literal token " + + "at line " + GetLine(j * 64 + k) + ", column " + GetColumn(j * 64 + k) + + ". It will be matched as " + + GetLabel(LexGen.canMatchAnyChar[LexGen.lexStateIndex]) + "."); + kindToPrint = LexGen.canMatchAnyChar[LexGen.lexStateIndex]; + } + else + kindToPrint = j * 64 + k; + + if (!subString[(j * 64 + k)]) + { + int stateSetName = GetStateSetForKind(i, j * 64 + k); + + if (stateSetName != -1) + { + ostr.println(prefix + "return jjStartNfaWithStates" + + LexGen.lexStateSuffix + "(" + i + + ", " + kindToPrint + ", " + stateSetName + ");"); + } + else + ostr.println(prefix + "return jjStopAtPos" + "(" + i + ", " + kindToPrint + ");"); + } + else + { + if ((LexGen.initMatch[LexGen.lexStateIndex] != 0 && + LexGen.initMatch[LexGen.lexStateIndex] != Integer.MAX_VALUE) || + i != 0) + { + ostr.println(" {"); + ostr.println(prefix + "jjmatchedKind = " + + kindToPrint + ";"); + ostr.println(prefix + "jjmatchedPos = " + i + ";"); + ostr.println(" }"); + } + else + ostr.println(prefix + "jjmatchedKind = " + + kindToPrint + ";"); + } + } + } + } + + if (info.validKindCnt != 0) + { + atLeastOne = false; + + if (i == 0) + { + ostr.print(" return "); + + ostr.print("jjMoveStringLiteralDfa" + (i + 1) + + LexGen.lexStateSuffix + "("); + for (j = 0; j < maxLongsReqd - 1; j++) + if ((i + 1) <= maxLenForActive[j]) + { + if (atLeastOne) + ostr.print(", "); + else + atLeastOne = true; + + ostr.print("0x" + Long.toHexString(info.validKinds[j]) + "L"); + } + + if ((i + 1) <= maxLenForActive[j]) + { + if (atLeastOne) + ostr.print(", "); + + ostr.print("0x" + Long.toHexString(info.validKinds[j]) + "L"); + } + ostr.println(");"); + } + else + { + ostr.print(" return "); + + ostr.print("jjMoveStringLiteralDfa" + (i + 1) + + LexGen.lexStateSuffix + "("); + + for (j = 0; j < maxLongsReqd - 1; j++) + if ((i + 1) <= maxLenForActive[j] + 1) + { + if (atLeastOne) + ostr.print(", "); + else + atLeastOne = true; + + if (info.validKinds[j] != 0L) + ostr.print("active" + j + ", 0x" + + Long.toHexString(info.validKinds[j]) + "L"); + else + ostr.print("active" + j + ", 0L"); + } + + if ((i + 1) <= maxLenForActive[j] + 1) + { + if (atLeastOne) + ostr.print(", "); + if (info.validKinds[j] != 0L) + ostr.print("active" + j + ", 0x" + + Long.toHexString(info.validKinds[j]) + "L"); + else + ostr.print("active" + j + ", 0L"); + } + + ostr.println(");"); + } + } + else + { + // A very special case. + if (i == 0 && LexGen.mixed[LexGen.lexStateIndex]) + { + + if (NfaState.generatedStates != 0) + ostr.println(" return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", 0);"); + else + ostr.println(" return 1;"); + } + else if (i != 0) // No more str literals to look for + { + ostr.println(" break;"); + startNfaNeeded = true; + } + } + } + + /* default means that the current character is not in any of the + strings at this position. */ + ostr.println(" default :"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(\" No string literal matches possible.\");"); + + if (NfaState.generatedStates != 0) + { + if (i == 0) + { + /* This means no string literal is possible. Just move nfa with + this guy and return. */ + ostr.println(" return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", 0);"); + } + else + { + ostr.println(" break;"); + startNfaNeeded = true; + } + } + else + { + ostr.println(" return " + (i + 1) + ";"); + } + + + ostr.println(" }"); + + if (i != 0) + { + if (startNfaNeeded) + { + if (!LexGen.mixed[LexGen.lexStateIndex] && NfaState.generatedStates != 0) + { + /* Here, a string literal is successfully matched and no more + string literals are possible. So set the kind and state set + upto and including this position for the matched string. */ + + ostr.print(" return jjStartNfa" + LexGen.lexStateSuffix + "(" + (i - 1) + ", "); + for (k = 0; k < maxLongsReqd - 1; k++) + if (i <= maxLenForActive[k]) + ostr.print("active" + k + ", "); + else + ostr.print("0L, "); + if (i <= maxLenForActive[k]) + ostr.println("active" + k + ");"); + else + ostr.println("0L);"); + } + else if (NfaState.generatedStates != 0) + ostr.println(" return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", " + i + ");"); + else + ostr.println(" return " + (i + 1) + ";"); + } + } + + ostr.println("}"); + } + } + + static final int GetStrKind(String str) + { + for (int i = 0; i < maxStrKind; i++) + { + if (LexGen.lexStates[i] != LexGen.lexStateIndex) + continue; + + String image = allImages[i]; + if (image != null && image.equals(str)) + return i; + } + + return Integer.MAX_VALUE; + } + + static void GenerateNfaStartStates(java.io.PrintWriter ostr, + NfaState initialState) + { + boolean[] seen = new boolean[NfaState.generatedStates]; + Hashtable stateSets = new Hashtable(); + String stateSetString = ""; + int i, j, kind, jjmatchedPos = 0; + int maxKindsReqd = maxStrKind / 64 + 1; + long[] actives; + Vector newStates = new Vector(); + Vector oldStates = null, jjtmpStates; + + statesForPos = new Hashtable[maxLen]; + intermediateKinds = new int[maxStrKind + 1][]; + intermediateMatchedPos = new int[maxStrKind + 1][]; + + for (i = 0; i < maxStrKind; i++) + { + if (LexGen.lexStates[i] != LexGen.lexStateIndex) + continue; + + String image = allImages[i]; + + if (image == null || image.length() < 1) + continue; + + try + { + if ((oldStates = (Vector)initialState.epsilonMoves.clone()) == null || + oldStates.size() == 0) + { + DumpNfaStartStatesCode(statesForPos, ostr); + return; + } + } + catch(Exception e) + { + CSJavaCCErrors.semantic_error("Error cloning state vector"); + } + + intermediateKinds[i] = new int[image.length()]; + intermediateMatchedPos[i] = new int[image.length()]; + jjmatchedPos = 0; + kind = Integer.MAX_VALUE; + + for (j = 0; j < image.length(); j++) + { + if (oldStates == null || oldStates.size() <= 0) + { + // Here, j > 0 + kind = intermediateKinds[i][j] = intermediateKinds[i][j - 1]; + jjmatchedPos = intermediateMatchedPos[i][j] = intermediateMatchedPos[i][j - 1]; + } + else + { + kind = NfaState.MoveFromSet(image.charAt(j), oldStates, newStates); + oldStates.removeAllElements(); + + if (j == 0 && kind != Integer.MAX_VALUE && + LexGen.canMatchAnyChar[LexGen.lexStateIndex] != -1 && + kind > LexGen.canMatchAnyChar[LexGen.lexStateIndex]) + kind = LexGen.canMatchAnyChar[LexGen.lexStateIndex]; + + if (GetStrKind(image.substring(0, j + 1)) < kind) + { + intermediateKinds[i][j] = kind = Integer.MAX_VALUE; + jjmatchedPos = 0; + } + else if (kind != Integer.MAX_VALUE) + { + intermediateKinds[i][j] = kind; + jjmatchedPos = intermediateMatchedPos[i][j] = j; + } + else if (j == 0) + kind = intermediateKinds[i][j] = Integer.MAX_VALUE; + else + { + kind = intermediateKinds[i][j] = intermediateKinds[i][j - 1]; + jjmatchedPos = intermediateMatchedPos[i][j] = intermediateMatchedPos[i][j - 1]; + } + + stateSetString = NfaState.GetStateSetString(newStates); + } + + if (kind == Integer.MAX_VALUE && + (newStates == null || newStates.size() == 0)) + continue; + + int p; + if (stateSets.get(stateSetString) == null) + { + stateSets.put(stateSetString, stateSetString); + for (p = 0; p < newStates.size(); p++) + { + if (seen[((NfaState)newStates.elementAt(p)).stateName]) + ((NfaState)newStates.elementAt(p)).inNextOf++; + else + seen[((NfaState)newStates.elementAt(p)).stateName] = true; + } + } + else + { + for (p = 0; p < newStates.size(); p++) + seen[((NfaState)newStates.elementAt(p)).stateName] = true; + } + + jjtmpStates = oldStates; + oldStates = newStates; + (newStates = jjtmpStates).removeAllElements(); + + if (statesForPos[j] == null) + statesForPos[j] = new Hashtable(); + + if ((actives = ((long[])statesForPos[j].get(kind + ", " + + jjmatchedPos + ", " + stateSetString))) == null) + { + actives = new long[maxKindsReqd]; + statesForPos[j].put(kind + ", " + jjmatchedPos + ", " + + stateSetString, actives); + } + + actives[i / 64] |= 1L << (i % 64); + //String name = NfaState.StoreStateSet(stateSetString); + } + } + + DumpNfaStartStatesCode(statesForPos, ostr); + } + + static void DumpNfaStartStatesCode(Hashtable[] statesForPos, + java.io.PrintWriter ostr) + { + if (maxStrKind == 0) { // No need to generate this function + return; + } + + int i, maxKindsReqd = maxStrKind / 64 + 1; + boolean condGenerated = false; + int ind = 0; + + ostr.print("private" + (Options.getStatic() ? " static" : "") + " int jjStopStringLiteralDfa" + + LexGen.lexStateSuffix + "(int pos, "); + for (i = 0; i < maxKindsReqd - 1; i++) + ostr.print("long active" + i + ", "); + ostr.println("long active" + i + ")\n{"); + + if (Options.getDebugTokenManager()) + ostr.println(" debugStream.WriteLine(\" No more string literal token matches are possible.\");"); + + ostr.println(" switch (pos)\n {"); + + for (i = 0; i < maxLen - 1; i++) + { + if (statesForPos[i] == null) + continue; + + ostr.println(" case " + i + ":"); + + Enumeration e = statesForPos[i].keys(); + while (e.hasMoreElements()) + { + String stateSetString = (String)e.nextElement(); + long[] actives = (long[])statesForPos[i].get(stateSetString); + + for (int j = 0; j < maxKindsReqd; j++) + { + if (actives[j] == 0L) + continue; + + if (condGenerated) + ostr.print(" || "); + else + ostr.print(" if ("); + + condGenerated = true; + + ostr.print("(active" + j + " & 0x" + + Long.toHexString(actives[j]) + "L) != 0L"); + } + + if (condGenerated) + { + ostr.println(")"); + + String kindStr = stateSetString.substring(0, + ind = stateSetString.indexOf(", ")); + String afterKind = stateSetString.substring(ind + 2); + int jjmatchedPos = Integer.parseInt( + afterKind.substring(0, afterKind.indexOf(", "))); + + if (!kindStr.equals(String.valueOf(Integer.MAX_VALUE))) + ostr.println(" {"); + + if (!kindStr.equals(String.valueOf(Integer.MAX_VALUE))) + { + if (i == 0) + { + ostr.println(" jjmatchedKind = " + kindStr + ";"); + + if ((LexGen.initMatch[LexGen.lexStateIndex] != 0 && + LexGen.initMatch[LexGen.lexStateIndex] != Integer.MAX_VALUE)) + ostr.println(" jjmatchedPos = 0;"); + } + else if (i == jjmatchedPos) + { + if (subStringAtPos[i]) + { + ostr.println(" if (jjmatchedPos != " + i + ")"); + ostr.println(" {"); + ostr.println(" jjmatchedKind = " + kindStr + ";"); + ostr.println(" jjmatchedPos = " + i + ";"); + ostr.println(" }"); + } + else + { + ostr.println(" jjmatchedKind = " + kindStr + ";"); + ostr.println(" jjmatchedPos = " + i + ";"); + } + } + else + { + if (jjmatchedPos > 0) + ostr.println(" if (jjmatchedPos < " + jjmatchedPos + ")"); + else + ostr.println(" if (jjmatchedPos == 0)"); + ostr.println(" {"); + ostr.println(" jjmatchedKind = " + kindStr + ";"); + ostr.println(" jjmatchedPos = " + jjmatchedPos + ";"); + ostr.println(" }"); + } + } + + kindStr = stateSetString.substring(0, + ind = stateSetString.indexOf(", ")); + afterKind = stateSetString.substring(ind + 2); + stateSetString = afterKind.substring( + afterKind.indexOf(", ") + 2); + + if (stateSetString.equals("null;")) + ostr.println(" return -1;"); + else + ostr.println(" return " + + NfaState.AddStartStateSet(stateSetString) + ";"); + + if (!kindStr.equals(String.valueOf(Integer.MAX_VALUE))) + ostr.println(" }"); + condGenerated = false; + } + } + + ostr.println(" return -1;"); + } + + ostr.println(" default :"); + ostr.println(" return -1;"); + ostr.println(" }"); + ostr.println("}"); + + ostr.print("private" + (Options.getStatic() ? " static" : "") + " int jjStartNfa" + + LexGen.lexStateSuffix + "(int pos, "); + for (i = 0; i < maxKindsReqd - 1; i++) + ostr.print("long active" + i + ", "); + ostr.println("long active" + i + ")\n{"); + + if (LexGen.mixed[LexGen.lexStateIndex]) + { + if (NfaState.generatedStates != 0) + ostr.println(" return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", pos + 1);"); + else + ostr.println(" return pos + 1;"); + + ostr.println("}"); + return; + } + + ostr.print(" return jjMoveNfa" + LexGen.lexStateSuffix + "(" + + "jjStopStringLiteralDfa" + LexGen.lexStateSuffix + "(pos, "); + for (i = 0; i < maxKindsReqd - 1; i++) + ostr.print("active" + i + ", "); + ostr.print("active" + i + ")"); + ostr.println(", pos + 1);"); + ostr.println("}"); + } + + public static void reInit() + { + maxStrKind = 0; + maxLen = 0; + charCnt = 0; + charPosKind = new Vector(); + maxLenForActive = new int[100]; + allImages = null; + intermediateKinds = null; + intermediateMatchedPos = null; + startStateCnt = 0; + subString = null; + subStringAtPos = null; + statesForPos = null; + boilerPlateDumped = false; + } + +} diff --git a/csjavacc/parser/RegExprSpec.java b/csjavacc/parser/RegExprSpec.java new file mode 100644 index 0000000..0e11036 --- /dev/null +++ b/csjavacc/parser/RegExprSpec.java @@ -0,0 +1,60 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import csjavacc.struct.Action; +import csjavacc.struct.RegularExpression; + + +/** + * The object type of entries in the vector "respecs" of class + * "TokenProduction". + */ + +public class RegExprSpec { + + /** + * The regular expression of this specification. + */ + public RegularExpression rexp; + + /** + * The action corresponding to this specification. + */ + public Action act; + + /** + * The next state corresponding to this specification. If no + * next state has been specified, this field is set to "null". + */ + public String nextState; + + /** + * If the next state specification was explicit in the previous + * case, then this token is that of the identifier denoting + * the next state. This is used for location information, etc. + * in error reporting. + */ + public Token nsTok; + +} diff --git a/csjavacc/parser/Semanticize.java b/csjavacc/parser/Semanticize.java new file mode 100644 index 0000000..964e0d3 --- /dev/null +++ b/csjavacc/parser/Semanticize.java @@ -0,0 +1,841 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import csjavacc.struct.Action; +import csjavacc.struct.Choice; +import csjavacc.struct.Expansion; +import csjavacc.struct.Lookahead; +import csjavacc.struct.NonTerminal; +import csjavacc.struct.REndOfFile; +import csjavacc.struct.RJustName; +import csjavacc.struct.ROneOrMore; +import csjavacc.struct.RRepetitionRange; +import csjavacc.struct.RSequence; +import csjavacc.struct.RZeroOrMore; +import csjavacc.struct.RZeroOrOne; +import csjavacc.struct.RegularExpression; +import csjavacc.struct.TokenProduction; +import csjavacc.struct.TreeWalkerOp; +import csjavacc.struct.TryBlock; +import csjavacc.struct.ZeroOrMore; +import csjavacc.struct.ZeroOrOne; + + +public class Semanticize extends CSJavaCCGlobals { + + static java.util.Vector removeList = new java.util.Vector(); + static java.util.Vector itemList = new java.util.Vector(); + + static void prepareToRemove(java.util.Vector vec, Object item) { + removeList.addElement(vec); + itemList.addElement(item); + } + + static void removePreparedItems() { + for (int i = 0; i < removeList.size(); i++) { + java.util.Vector vec = (java.util.Vector)(removeList.elementAt(i)); + vec.removeElement(itemList.elementAt(i)); + } + removeList.removeAllElements(); + itemList.removeAllElements(); + } + + static public void start() throws MetaParseException { + + if (CSJavaCCErrors.get_error_count() != 0) throw new MetaParseException(); + + if (Options.getLookahead() > 1 && !Options.getForceLaCheck() && Options.getSanityCheck()) { + CSJavaCCErrors.warning("Lookahead adequacy checking not being performed since option LOOKAHEAD is more than 1. Set option FORCE_LA_CHECK to true to force checking."); + } + + /* + * The following walks the entire parse tree to convert all LOOKAHEAD's + * that are not at choice points (but at beginning of sequences) and converts + * them to trivial choices. This way, their semantic lookahead specification + * can be evaluated during other lookahead evaluations. + */ + for (java.util.Enumeration anEnum = bnfproductions.elements(); anEnum.hasMoreElements();) { + ExpansionTreeWalker.postOrderWalk(((NormalProduction)anEnum.nextElement()).expansion, new LookaheadFixer()); + } + + /* + * The following loop populates "production_table" + */ + for (java.util.Enumeration anEnum = bnfproductions.elements(); anEnum.hasMoreElements();) { + NormalProduction p = (NormalProduction)anEnum.nextElement(); + if (production_table.put(p.lhs, p) != null) { + CSJavaCCErrors.semantic_error(p, p.lhs + " occurs on the left hand side of more than one production."); + } + } + + /* + * The following walks the entire parse tree to make sure that all + * non-terminals on RHS's are defined on the LHS. + */ + for (java.util.Enumeration anEnum = bnfproductions.elements(); anEnum.hasMoreElements();) { + ExpansionTreeWalker.preOrderWalk(((NormalProduction)anEnum.nextElement()).expansion, new ProductionDefinedChecker()); + } + + /* + * The following loop ensures that all target lexical states are + * defined. Also piggybacking on this loop is the detection of + * and in token productions. After reporting an + * error, these entries are removed. Also checked are definitions + * on inline private regular expressions. + * This loop works slightly differently when USER_TOKEN_MANAGER + * is set to true. In this case, occurrences are OK, while + * regular expression specs generate a warning. + */ + for (java.util.Enumeration anEnum = rexprlist.elements(); anEnum.hasMoreElements();) { + TokenProduction tp = (TokenProduction)(anEnum.nextElement()); + java.util.Vector respecs = tp.respecs; + for (java.util.Enumeration enum1 = respecs.elements(); enum1.hasMoreElements();) { + RegExprSpec res = (RegExprSpec)(enum1.nextElement()); + if (res.nextState != null) { + if (lexstate_S2I.get(res.nextState) == null) { + CSJavaCCErrors.semantic_error(res.nsTok, "Lexical state \"" + res.nextState + "\" has not been defined."); + } + } + if (res.rexp instanceof REndOfFile) { + //JavaCCErrors.semantic_error(res.rexp, "Badly placed ."); + if (tp.lexStates != null) + CSJavaCCErrors.semantic_error(res.rexp, "EOF action/state change must be specified for all states, i.e., <*>TOKEN:."); + if (tp.kind != TokenProduction.TOKEN) + CSJavaCCErrors.semantic_error(res.rexp, "EOF action/state change can be specified only in a TOKEN specification."); + if (nextStateForEof != null || actForEof != null) + CSJavaCCErrors.semantic_error(res.rexp, "Duplicate action/state change specification for ."); + actForEof = res.act; + nextStateForEof = res.nextState; + prepareToRemove(respecs, res); + } else if (tp.isExplicit && Options.getUserTokenManager()) { + CSJavaCCErrors.warning(res.rexp, "Ignoring regular expression specification since option USER_TOKEN_MANAGER has been set to true."); + } else if (tp.isExplicit && !Options.getUserTokenManager() && res.rexp instanceof RJustName) { + CSJavaCCErrors.warning(res.rexp, "Ignoring free-standing regular expression reference. If you really want this, you must give it a different label as >."); + prepareToRemove(respecs, res); + } else if (!tp.isExplicit && res.rexp.private_rexp) { + CSJavaCCErrors.semantic_error(res.rexp, "Private (#) regular expression cannot be defined within grammar productions."); + } + } + } + + removePreparedItems(); + + /* + * The following loop inserts all names of regular expressions into + * "named_tokens_table" and "ordered_named_tokens". + * Duplications are flagged as errors. + */ + for (java.util.Enumeration anEnum = rexprlist.elements(); anEnum.hasMoreElements();) { + TokenProduction tp = (TokenProduction)(anEnum.nextElement()); + java.util.Vector respecs = tp.respecs; + for (java.util.Enumeration enum1 = respecs.elements(); enum1.hasMoreElements();) { + RegExprSpec res = (RegExprSpec)(enum1.nextElement()); + if (!(res.rexp instanceof RJustName) && !res.rexp.label.equals("")) { + String s = res.rexp.label; + Object obj = named_tokens_table.put(s, res.rexp); + if (obj != null) { + CSJavaCCErrors.semantic_error(res.rexp, "Multiply defined lexical token name \"" + s + "\"."); + } else { + ordered_named_tokens.addElement(res.rexp); + } + if (lexstate_S2I.get(s) != null) { + CSJavaCCErrors.semantic_error(res.rexp, "Lexical token name \"" + s + "\" is the same as that of a lexical state."); + } + } + } + } + + /* + * The following code merges multiple uses of the same string in the same + * lexical state and produces error messages when there are multiple + * explicit occurrences (outside the BNF) of the string in the same + * lexical state, or when within BNF occurrences of a string are duplicates + * of those that occur as non-TOKEN's (SKIP, MORE, SPECIAL_TOKEN) or private + * regular expressions. While doing this, this code also numbers all + * regular expressions (by setting their ordinal values), and populates the + * table "names_of_tokens". + */ + + tokenCount = 1; + for (java.util.Enumeration anEnum = rexprlist.elements(); anEnum.hasMoreElements();) { + TokenProduction tp = (TokenProduction)(anEnum.nextElement()); + java.util.Vector respecs = tp.respecs; + if (tp.lexStates == null) { + tp.lexStates = new String[lexstate_I2S.size()]; + int i = 0; + for (java.util.Enumeration enum1 = lexstate_I2S.elements(); enum1.hasMoreElements();) { + tp.lexStates[i++] = (String)(enum1.nextElement()); + } + } + java.util.Hashtable table[] = new java.util.Hashtable[tp.lexStates.length]; + for (int i = 0; i < tp.lexStates.length; i++) { + table[i] = (java.util.Hashtable)simple_tokens_table.get(tp.lexStates[i]); + } + for (java.util.Enumeration enum1 = respecs.elements(); enum1.hasMoreElements();) { + RegExprSpec res = (RegExprSpec)(enum1.nextElement()); + if (res.rexp instanceof RStringLiteral) { + RStringLiteral sl = (RStringLiteral)res.rexp; + // This loop performs the checks and actions with respect to each lexical state. + for (int i = 0; i < table.length; i++) { + // Get table of all case variants of "sl.image" into table2. + java.util.Hashtable table2 = (java.util.Hashtable)(table[i].get(sl.image.toUpperCase())); + if (table2 == null) { + // There are no case variants of "sl.image" earlier than the current one. + // So go ahead and insert this item. + if (sl.ordinal == 0) { + sl.ordinal = tokenCount++; + } + table2 = new java.util.Hashtable(); + table2.put(sl.image, sl); + table[i].put(sl.image.toUpperCase(), table2); + } else if (hasIgnoreCase(table2, sl.image)) { // hasIgnoreCase sets "other" if it is found. + // Since IGNORE_CASE version exists, current one is useless and bad. + if (!sl.tpContext.isExplicit) { + // inline BNF string is used earlier with an IGNORE_CASE. + CSJavaCCErrors.semantic_error(sl, "String \"" + sl.image + "\" can never be matched due to presence of more general (IGNORE_CASE) regular expression at line " + other.line + ", column " + other.column + "."); + } else { + // give the standard error message. + CSJavaCCErrors.semantic_error(sl, "Duplicate definition of string token \"" + sl.image + "\" can never be matched."); + } + } else if (sl.tpContext.ignoreCase) { + // This has to be explicit. A warning needs to be given with respect + // to all previous strings. + String pos = ""; int count = 0; + for (java.util.Enumeration enum2 = table2.elements(); enum2.hasMoreElements();) { + RegularExpression rexp = (RegularExpression)(enum2.nextElement()); + if (count != 0) pos += ","; + pos += " line " + rexp.line; + count++; + } + if (count == 1) { + CSJavaCCErrors.warning(sl, "String with IGNORE_CASE is partially superceded by string at" + pos + "."); + } else { + CSJavaCCErrors.warning(sl, "String with IGNORE_CASE is partially superceded by strings at" + pos + "."); + } + // This entry is legitimate. So insert it. + if (sl.ordinal == 0) { + sl.ordinal = tokenCount++; + } + table2.put(sl.image, sl); + // The above "put" may override an existing entry (that is not IGNORE_CASE) and that's + // the desired behavior. + } else { + // The rest of the cases do not involve IGNORE_CASE. + RegularExpression re = (RegularExpression)table2.get(sl.image); + if (re == null) { + if (sl.ordinal == 0) { + sl.ordinal = tokenCount++; + } + table2.put(sl.image, sl); + } else if (tp.isExplicit) { + // This is an error even if the first occurrence was implicit. + if (tp.lexStates[i].equals("DEFAULT")) { + CSJavaCCErrors.semantic_error(sl, "Duplicate definition of string token \"" + sl.image + "\"."); + } else { + CSJavaCCErrors.semantic_error(sl, "Duplicate definition of string token \"" + sl.image + "\" in lexical state \"" + tp.lexStates[i] + "\"."); + } + } else if (re.tpContext.kind != TokenProduction.TOKEN) { + CSJavaCCErrors.semantic_error(sl, "String token \"" + sl.image + "\" has been defined as a \"" + TokenProduction.kindImage[re.tpContext.kind] + "\" token."); + } else if (re.private_rexp) { + CSJavaCCErrors.semantic_error(sl, "String token \"" + sl.image + "\" has been defined as a private regular expression."); + } else { + // This is now a legitimate reference to an existing RStringLiteral. + // So we assign it a number and take it out of "rexprlist". + // Therefore, if all is OK (no errors), then there will be only unequal + // string literals in each lexical state. Note that the only way + // this can be legal is if this is a string declared inline within the + // BNF. Hence, it belongs to only one lexical state - namely "DEFAULT". + sl.ordinal = re.ordinal; + prepareToRemove(respecs, res); + } + } + } + } else if (!(res.rexp instanceof RJustName)) { + res.rexp.ordinal = tokenCount++; + } + if (!(res.rexp instanceof RJustName) && !res.rexp.label.equals("")) { + names_of_tokens.put(new Integer(res.rexp.ordinal), res.rexp.label); + } + if (!(res.rexp instanceof RJustName)) { + rexps_of_tokens.put(new Integer(res.rexp.ordinal), res.rexp); + } + } + } + + removePreparedItems(); + + /* + * The following code performs a tree walk on all regular expressions + * attaching links to "RJustName"s. Error messages are given if + * undeclared names are used, or if "RJustNames" refer to private + * regular expressions or to regular expressions of any kind other + * than TOKEN. In addition, this loop also removes top level + * "RJustName"s from "rexprlist". + * This code is not executed if Options.getUserTokenManager() is set to + * true. Instead the following block of code is executed. + */ + + if (!Options.getUserTokenManager()) { + FixRJustNames frjn = new FixRJustNames(); + for (java.util.Enumeration anEnum = rexprlist.elements(); anEnum.hasMoreElements();) { + TokenProduction tp = (TokenProduction)(anEnum.nextElement()); + java.util.Vector respecs = tp.respecs; + for (java.util.Enumeration enum1 = respecs.elements(); enum1.hasMoreElements();) { + RegExprSpec res = (RegExprSpec)(enum1.nextElement()); + frjn.root = res.rexp; + ExpansionTreeWalker.preOrderWalk(res.rexp, frjn); + if (res.rexp instanceof RJustName) { + prepareToRemove(respecs, res); + } + } + } + } + + removePreparedItems(); + + /* + * The following code is executed only if Options.getUserTokenManager() is + * set to true. This code visits all top-level "RJustName"s (ignores + * "RJustName"s nested within regular expressions). Since regular expressions + * are optional in this case, "RJustName"s without corresponding regular + * expressions are given ordinal values here. If "RJustName"s refer to + * a named regular expression, their ordinal values are set to reflect this. + * All but one "RJustName" node is removed from the lists by the end of + * execution of this code. + */ + + if (Options.getUserTokenManager()) { + for (java.util.Enumeration anEnum = rexprlist.elements(); anEnum.hasMoreElements();) { + TokenProduction tp = (TokenProduction)(anEnum.nextElement()); + java.util.Vector respecs = tp.respecs; + for (java.util.Enumeration enum1 = respecs.elements(); enum1.hasMoreElements();) { + RegExprSpec res = (RegExprSpec)(enum1.nextElement()); + if (res.rexp instanceof RJustName) { + + RJustName jn = (RJustName)res.rexp; + RegularExpression rexp = (RegularExpression)named_tokens_table.get(jn.label); + if (rexp == null) { + jn.ordinal = tokenCount++; + named_tokens_table.put(jn.label, jn); + ordered_named_tokens.addElement(jn); + names_of_tokens.put(new Integer(jn.ordinal), jn.label); + } else { + jn.ordinal = rexp.ordinal; + prepareToRemove(respecs, res); + } + } + } + } + } + + removePreparedItems(); + + /* + * The following code is executed only if Options.getUserTokenManager() is + * set to true. This loop labels any unlabeled regular expression and + * prints a warning that it is doing so. These labels are added to + * "ordered_named_tokens" so that they may be generated into the ...Constants + * file. + */ + if (Options.getUserTokenManager()) { + for (java.util.Enumeration anEnum = rexprlist.elements(); anEnum.hasMoreElements();) { + TokenProduction tp = (TokenProduction)(anEnum.nextElement()); + java.util.Vector respecs = tp.respecs; + for (java.util.Enumeration enum1 = respecs.elements(); enum1.hasMoreElements();) { + RegExprSpec res = (RegExprSpec)(enum1.nextElement()); + Integer ii = new Integer(res.rexp.ordinal); + if (names_of_tokens.get(ii) == null) { + CSJavaCCErrors.warning(res.rexp, "Unlabeled regular expression cannot be referred to by user generated token manager."); + } + } + } + } + + if (CSJavaCCErrors.get_error_count() != 0) throw new MetaParseException(); + + // The following code sets the value of the "emptyPossible" field of NormalProduction + // nodes. This field is initialized to false, and then the entire list of + // productions is processed. This is repeated as long as at least one item + // got updated from false to true in the pass. + boolean emptyUpdate = true; + while (emptyUpdate) { + emptyUpdate = false; + for (java.util.Enumeration anEnum = bnfproductions.elements(); anEnum.hasMoreElements();) { + NormalProduction prod = (NormalProduction)anEnum.nextElement(); + if (emptyExpansionExists(prod.expansion)) { + if (!prod.emptyPossible) { + emptyUpdate = prod.emptyPossible = true; + } + } + } + } + + if (Options.getSanityCheck() && CSJavaCCErrors.get_error_count() == 0) { + + // The following code checks that all ZeroOrMore, ZeroOrOne, and OneOrMore nodes + // do not contain expansions that can expand to the empty token list. + for (java.util.Enumeration anEnum = bnfproductions.elements(); anEnum.hasMoreElements();) { + ExpansionTreeWalker.preOrderWalk(((NormalProduction)anEnum.nextElement()).expansion, new EmptyChecker()); + } + + // The following code goes through the productions and adds pointers to other + // productions that it can expand to without consuming any tokens. Once this is + // done, a left-recursion check can be performed. + for (java.util.Enumeration anEnum = bnfproductions.elements(); anEnum.hasMoreElements();) { + NormalProduction prod = (NormalProduction)anEnum.nextElement(); + addLeftMost(prod, prod.expansion); + } + + // Now the following loop calls a recursive walk routine that searches for + // actual left recursions. The way the algorithm is coded, once a node has + // been determined to participate in a left recursive loop, it is not tried + // in any other loop. + for (java.util.Enumeration anEnum = bnfproductions.elements(); anEnum.hasMoreElements();) { + NormalProduction prod = (NormalProduction)anEnum.nextElement(); + if (prod.walkStatus == 0) { + prodWalk(prod); + } + } + + // Now we do a similar, but much simpler walk for the regular expression part of + // the grammar. Here we are looking for any kind of loop, not just left recursions, + // so we only need to do the equivalent of the above walk. + // This is not done if option USER_TOKEN_MANAGER is set to true. + if (!Options.getUserTokenManager()) { + for (java.util.Enumeration anEnum = rexprlist.elements(); anEnum.hasMoreElements();) { + TokenProduction tp = (TokenProduction)(anEnum.nextElement()); + java.util.Vector respecs = tp.respecs; + for (java.util.Enumeration enum1 = respecs.elements(); enum1.hasMoreElements();) { + RegExprSpec res = (RegExprSpec)(enum1.nextElement()); + RegularExpression rexp = res.rexp; + if (rexp.walkStatus == 0) { + rexp.walkStatus = -1; + if (rexpWalk(rexp)) { + loopString = "..." + rexp.label + "... --> " + loopString; + CSJavaCCErrors.semantic_error(rexp, "Loop in regular expression detected: \"" + loopString + "\""); + } + rexp.walkStatus = 1; + } + } + } + } + + /* + * The following code performs the lookahead ambiguity checking. + */ + if (CSJavaCCErrors.get_error_count() == 0) { + for (java.util.Enumeration anEnum = bnfproductions.elements(); anEnum.hasMoreElements();) { + ExpansionTreeWalker.preOrderWalk(((NormalProduction)anEnum.nextElement()).expansion, new LookaheadChecker()); + } + } + + } // matches "if (Options.getSanityCheck()) {" + + if (CSJavaCCErrors.get_error_count() != 0) throw new MetaParseException(); + + } + + public static RegularExpression other; + + // Checks to see if the "str" is superceded by another equal (except case) string + // in table. + public static boolean hasIgnoreCase(java.util.Hashtable table, String str) { + RegularExpression rexp; + rexp = (RegularExpression)(table.get(str)); + if (rexp != null && !rexp.tpContext.ignoreCase) { + return false; + } + for (java.util.Enumeration anEnum = table.elements(); anEnum.hasMoreElements();) { + rexp = (RegularExpression)(anEnum.nextElement()); + if (rexp.tpContext.ignoreCase) { + other = rexp; + return true; + } + } + return false; + } + + // returns true if "exp" can expand to the empty string, returns false otherwise. + public static boolean emptyExpansionExists(Expansion exp) { + if (exp instanceof NonTerminal) { + return ((NonTerminal)exp).prod.emptyPossible; + } else if (exp instanceof Action) { + return true; + } else if (exp instanceof RegularExpression) { + return false; + } else if (exp instanceof OneOrMore) { + return emptyExpansionExists(((OneOrMore)exp).expansion); + } else if (exp instanceof ZeroOrMore || exp instanceof ZeroOrOne) { + return true; + } else if (exp instanceof Lookahead) { + return true; + } else if (exp instanceof Choice) { + for (java.util.Enumeration anEnum = ((Choice)exp).choices.elements(); anEnum.hasMoreElements();) { + if (emptyExpansionExists((Expansion)anEnum.nextElement())) { + return true; + } + } + return false; + } else if (exp instanceof Sequence) { + for (java.util.Enumeration anEnum = ((Sequence)exp).units.elements(); anEnum.hasMoreElements();) { + if (!emptyExpansionExists((Expansion)anEnum.nextElement())) { + return false; + } + } + return true; + } else if (exp instanceof TryBlock) { + return emptyExpansionExists(((TryBlock)exp).exp); + } else { + return false; // This should be dead code. + } + } + + // Updates prod.leftExpansions based on a walk of exp. + static private void addLeftMost(NormalProduction prod, Expansion exp) { + if (exp instanceof NonTerminal) { + for (int i=0; i " + prod.leftExpansions[i].lhs + "..."; + if (prod.walkStatus == -2) { + prod.walkStatus = 1; + CSJavaCCErrors.semantic_error(prod, "Left recursion detected: \"" + loopString + "\""); + return false; + } else { + prod.walkStatus = 1; + return true; + } + } else if (prod.leftExpansions[i].walkStatus == 0) { + if (prodWalk(prod.leftExpansions[i])) { + loopString = prod.lhs + "... --> " + loopString; + if (prod.walkStatus == -2) { + prod.walkStatus = 1; + CSJavaCCErrors.semantic_error(prod, "Left recursion detected: \"" + loopString + "\""); + return false; + } else { + prod.walkStatus = 1; + return true; + } + } + } + } + prod.walkStatus = 1; + return false; + } + + // Returns true to indicate an unraveling of a detected loop, + // and returns false otherwise. + static private boolean rexpWalk(RegularExpression rexp) { + if (rexp instanceof RJustName) { + RJustName jn = (RJustName)rexp; + if (jn.regexpr.walkStatus == -1) { + jn.regexpr.walkStatus = -2; + loopString = "..." + jn.regexpr.label + "..."; + // Note: Only the regexpr's of RJustName nodes and the top leve + // regexpr's can have labels. Hence it is only in these cases that + // the labels are checked for to be added to the loopString. + return true; + } else if (jn.regexpr.walkStatus == 0) { + jn.regexpr.walkStatus = -1; + if (rexpWalk(jn.regexpr)) { + loopString = "..." + jn.regexpr.label + "... --> " + loopString; + if (jn.regexpr.walkStatus == -2) { + jn.regexpr.walkStatus = 1; + CSJavaCCErrors.semantic_error(jn.regexpr, "Loop in regular expression detected: \"" + loopString + "\""); + return false; + } else { + jn.regexpr.walkStatus = 1; + return true; + } + } else { + jn.regexpr.walkStatus = 1; + return false; + } + } + } else if (rexp instanceof RChoice) { + for (java.util.Enumeration anEnum = ((RChoice)rexp).choices.elements(); anEnum.hasMoreElements();) { + if (rexpWalk((RegularExpression)anEnum.nextElement())) { + return true; + } + } + return false; + } else if (rexp instanceof RSequence) { + for (java.util.Enumeration anEnum = ((RSequence)rexp).units.elements(); anEnum.hasMoreElements();) { + if (rexpWalk((RegularExpression)anEnum.nextElement())) { + return true; + } + } + return false; + } else if (rexp instanceof ROneOrMore) { + return rexpWalk(((ROneOrMore)rexp).regexpr); + } else if (rexp instanceof RZeroOrMore) { + return rexpWalk(((RZeroOrMore)rexp).regexpr); + } else if (rexp instanceof RZeroOrOne) { + return rexpWalk(((RZeroOrOne)rexp).regexpr); + } else if (rexp instanceof RRepetitionRange) { + return rexpWalk(((RRepetitionRange)rexp).regexpr); + } + return false; + } + + /** + * Objects of this class are created from class Semanticize to work on + * references to regular expressions from RJustName's. + */ + static class FixRJustNames extends CSJavaCCGlobals implements TreeWalkerOp { + + public RegularExpression root; + + public boolean goDeeper(Expansion e) { + return true; + } + + public void action(Expansion e) { + if (e instanceof RJustName) { + RJustName jn = (RJustName)e; + RegularExpression rexp = (RegularExpression)named_tokens_table.get(jn.label); + if (rexp == null) { + CSJavaCCErrors.semantic_error(e, "Undefined lexical token name \"" + jn.label + "\"."); + } else if (jn == root && !jn.tpContext.isExplicit && rexp.private_rexp) { + CSJavaCCErrors.semantic_error(e, "Token name \"" + jn.label + "\" refers to a private (with a #) regular expression."); + } else if (jn == root && !jn.tpContext.isExplicit && rexp.tpContext.kind != TokenProduction.TOKEN) { + CSJavaCCErrors.semantic_error(e, "Token name \"" + jn.label + "\" refers to a non-token (SKIP, MORE, IGNORE_IN_BNF) regular expression."); + } else { + jn.ordinal = rexp.ordinal; + jn.regexpr = rexp; + } + } + } + + } + + static class LookaheadFixer extends CSJavaCCGlobals implements TreeWalkerOp { + + public boolean goDeeper(Expansion e) { + if (e instanceof RegularExpression) { + return false; + } else { + return true; + } + } + + public void action(Expansion e) { + if (e instanceof Sequence) { + if (e.parent instanceof Choice || e.parent instanceof ZeroOrMore || + e.parent instanceof OneOrMore || e.parent instanceof ZeroOrOne) { + return; + } + Sequence seq = (Sequence)e; + Lookahead la = (Lookahead)(seq.units.elementAt(0)); + if (!la.isExplicit) { + return; + } + // Create a singleton choice with an empty action. + Choice ch = new Choice(); + ch.line = la.line; ch.column = la.column; + ch.parent = seq; + Sequence seq1 = new Sequence(); + seq1.line = la.line; seq1.column = la.column; + seq1.parent = ch; + seq1.units.addElement(la); + la.parent = seq1; + Action act = new Action(); + act.line = la.line; act.column = la.column; + act.parent = seq1; + seq1.units.addElement(act); + ch.choices.addElement(seq1); + if (la.amount != 0) { + if (la.action_tokens.size() != 0) { + CSJavaCCErrors.warning(la, "Encountered LOOKAHEAD(...) at a non-choice location. Only semantic lookahead will be considered here."); + } else { + CSJavaCCErrors.warning(la, "Encountered LOOKAHEAD(...) at a non-choice location. This will be ignored."); + } + } + // Now we have moved the lookahead into the singleton choice. Now create + // a new dummy lookahead node to replace this one at its original location. + Lookahead la1 = new Lookahead(); + la1.isExplicit = false; + la1.line = la.line; la1.column = la.column; + la1.parent = seq; + // Now set the la_expansion field of la and la1 with a dummy expansion (we use EOF). + la.la_expansion = new REndOfFile(); + la1.la_expansion = new REndOfFile(); + seq.units.setElementAt(la1, 0); + seq.units.insertElementAt(ch, 1); + } + } + + } + + static class ProductionDefinedChecker extends CSJavaCCGlobals implements TreeWalkerOp { + + public boolean goDeeper(Expansion e) { + if (e instanceof RegularExpression) { + return false; + } else { + return true; + } + } + + public void action(Expansion e) { + if (e instanceof NonTerminal) { + NonTerminal nt = (NonTerminal)e; + if ((nt.prod = (NormalProduction)production_table.get(nt.name)) == null) { + CSJavaCCErrors.semantic_error(e, "Non-terminal " + nt.name + " has not been defined."); + } else { + nt.prod.parents.addElement(nt); + } + } + } + + } + + static class EmptyChecker extends CSJavaCCGlobals implements TreeWalkerOp { + + public boolean goDeeper(Expansion e) { + if (e instanceof RegularExpression) { + return false; + } else { + return true; + } + } + + public void action(Expansion e) { + if (e instanceof OneOrMore) { + if (Semanticize.emptyExpansionExists(((OneOrMore)e).expansion)) { + CSJavaCCErrors.semantic_error(e, "Expansion within \"(...)+\" can be matched by empty string."); + } + } else if (e instanceof ZeroOrMore) { + if (Semanticize.emptyExpansionExists(((ZeroOrMore)e).expansion)) { + CSJavaCCErrors.semantic_error(e, "Expansion within \"(...)*\" can be matched by empty string."); + } + } else if (e instanceof ZeroOrOne) { + if (Semanticize.emptyExpansionExists(((ZeroOrOne)e).expansion)) { + CSJavaCCErrors.semantic_error(e, "Expansion within \"(...)?\" can be matched by empty string."); + } + } + } + + } + + static class LookaheadChecker extends CSJavaCCGlobals implements TreeWalkerOp { + + public boolean goDeeper(Expansion e) { + if (e instanceof RegularExpression) { + return false; + } else if (e instanceof Lookahead) { + return false; + } else { + return true; + } + } + + public void action(Expansion e) { + if (e instanceof Choice) { + if (Options.getLookahead() == 1 || Options.getForceLaCheck()) { + LookaheadCalc.choiceCalc((Choice)e); + } + } else if (e instanceof OneOrMore) { + OneOrMore exp = (OneOrMore)e; + if (Options.getForceLaCheck() || (implicitLA(exp.expansion) && Options.getLookahead() == 1)) { + LookaheadCalc.ebnfCalc(exp, exp.expansion); + } + } else if (e instanceof ZeroOrMore) { + ZeroOrMore exp = (ZeroOrMore)e; + if (Options.getForceLaCheck() || (implicitLA(exp.expansion) && Options.getLookahead() == 1)) { + LookaheadCalc.ebnfCalc(exp, exp.expansion); + } + } else if (e instanceof ZeroOrOne) { + ZeroOrOne exp = (ZeroOrOne)e; + if (Options.getForceLaCheck() || (implicitLA(exp.expansion) && Options.getLookahead() == 1)) { + LookaheadCalc.ebnfCalc(exp, exp.expansion); + } + } + } + + static boolean implicitLA(Expansion exp) { + if (!(exp instanceof Sequence)) { + return true; + } + Sequence seq = (Sequence)exp; + Object obj = seq.units.elementAt(0); + if (!(obj instanceof Lookahead)) { + return true; + } + Lookahead la = (Lookahead)obj; + return !la.isExplicit; + } + + } + + public static void reInit() + { + removeList = new java.util.Vector(); + itemList = new java.util.Vector(); + other = null; + loopString = null; + } + +} diff --git a/csjavacc/parser/Sequence.java b/csjavacc/parser/Sequence.java new file mode 100644 index 0000000..ea1dbf5 --- /dev/null +++ b/csjavacc/parser/Sequence.java @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package csjavacc.parser; + +import csjavacc.struct.Expansion; + +/** + * Describes expansions that are sequences of expansion + * units. (c1 c2 ...) + */ + +public class Sequence extends Expansion { + + /** + * The list of units in this expansion sequence. Each + * Vector component will narrow to Expansion. + */ + public java.util.Vector units = new java.util.Vector(); + +} diff --git a/csjavacc/parser/SingleCharacter.java b/csjavacc/parser/SingleCharacter.java new file mode 100644 index 0000000..fe08652 --- /dev/null +++ b/csjavacc/parser/SingleCharacter.java @@ -0,0 +1,51 @@ +/* + * 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. + */ + +package csjavacc.parser; + +/** + * Describes single character descriptors in a character list. + */ + +public class SingleCharacter { + + /** + * The line and column number of the construct that corresponds + * most closely to this node. + */ + int line, column; + + /** + * The character of this descriptor. + */ + public char ch; + + SingleCharacter() + { + } + + SingleCharacter(char c) + { + ch = c; + } + +} diff --git a/csjavacc/parser/Token.java b/csjavacc/parser/Token.java new file mode 100644 index 0000000..3b10245 --- /dev/null +++ b/csjavacc/parser/Token.java @@ -0,0 +1,89 @@ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ +package csjavacc.parser; + +/** + * Describes the input token stream. + */ + +public class Token { + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** + * beginLine and beginColumn describe the position of the first character + * of this token; endLine and endColumn describe the position of the + * last character of this token. + */ + public int beginLine, beginColumn, endLine, endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * Returns the image. + */ + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simlpy add something like : + * + * case MyParserConstants.ID : return new IDToken(); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use it in your lexical actions. + */ + public static final Token newToken(int ofKind) + { + switch(ofKind) + { + default : return new Token(); + case CSJavaCCParserConstants.RUNSIGNEDSHIFT: + case CSJavaCCParserConstants.RSIGNEDSHIFT: + case CSJavaCCParserConstants.GT: + return new GTToken(); + } + } + + public static class GTToken extends Token + { + int realKind = CSJavaCCParserConstants.GT; + } +} diff --git a/csjavacc/parser/TokenMgrError.java b/csjavacc/parser/TokenMgrError.java new file mode 100644 index 0000000..68ae7c0 --- /dev/null +++ b/csjavacc/parser/TokenMgrError.java @@ -0,0 +1,138 @@ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ +/** + * This file contains the code for CSJavaCCParser generated + * by CSJavaCCParser itself. + */ + +package csjavacc.parser; + +public class TokenMgrError extends Error +{ + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occured. + */ + static final int LEXICAL_ERROR = 0; + + /** + * An attempt wass made to create a second instance of a static token manager. + */ + static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their espaced (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexicl error + * curLexState : lexical state in which this error occured + * errorLine : line number when the error occured + * errorColumn : column number when the error occured + * errorAfter : prefix that was seen before this error occured + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + + public TokenMgrError() { + } + + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } + + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} diff --git a/csjavacc/struct/Action.java b/csjavacc/struct/Action.java new file mode 100644 index 0000000..70ee5fa --- /dev/null +++ b/csjavacc/struct/Action.java @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package csjavacc.struct; + + + +/** + * Describes actions that may occur on the right hand side + * of productions. + */ + +public class Action extends Expansion { + + /** + * Contains the list of tokens that make up the action. This + * list does not include the surrounding braces. + */ + public java.util.Vector action_tokens = new java.util.Vector(); + +} diff --git a/csjavacc/struct/BNFProduction.java b/csjavacc/struct/BNFProduction.java new file mode 100644 index 0000000..1b119db --- /dev/null +++ b/csjavacc/struct/BNFProduction.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import csjavacc.parser.NormalProduction; + +/** + * Describes BNF productions. + */ + +public class BNFProduction extends NormalProduction { + + /** + * The declarations of this production. + */ + public java.util.Vector declaration_tokens = new java.util.Vector(); + + /** + * This flag keeps track of whether or not return and throw + * statements have been patched within this production's actions to + * include a preceding "if (true)". + */ + public boolean jumpPatched; + +} diff --git a/csjavacc/struct/CSCodeProduction.java b/csjavacc/struct/CSCodeProduction.java new file mode 100644 index 0000000..c07d6c2 --- /dev/null +++ b/csjavacc/struct/CSCodeProduction.java @@ -0,0 +1,38 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import csjavacc.parser.NormalProduction; + +/** + * Describes JAVACODE productions. + */ + +public class CSCodeProduction extends NormalProduction { + + /** + * The tokens that implement this JAVACODE production. + */ + public java.util.Vector code_tokens = new java.util.Vector(); + +} diff --git a/csjavacc/struct/CharacterRange.java b/csjavacc/struct/CharacterRange.java new file mode 100644 index 0000000..c6c47cd --- /dev/null +++ b/csjavacc/struct/CharacterRange.java @@ -0,0 +1,55 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import csjavacc.parser.CSJavaCCErrors; + +/** + * Describes character range descriptors in a character list. + */ + +public class CharacterRange { + + /** + * The line and column number of the construct that corresponds + * most closely to this node. + */ + public int line, column; + + /** + * The leftmost and the rightmost characters in this character range. + */ + public char left, right; + + public CharacterRange() { } + + public CharacterRange(char l, char r) + { + if (l > r) + CSJavaCCErrors.semantic_error(this, "Invalid range : \"" + (int)l + "\" - \"" + + (int)r + "\". First character shoud be less than or equal to the second one in a range."); + + left = l; + right = r; + } +} diff --git a/csjavacc/struct/Choice.java b/csjavacc/struct/Choice.java new file mode 100644 index 0000000..40d746f --- /dev/null +++ b/csjavacc/struct/Choice.java @@ -0,0 +1,39 @@ +/* + * 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. + */ + +package csjavacc.struct; + + +/** + * Describes expansions where one of many choices + * is taken (c1|c2|...). + */ + +public class Choice extends Expansion { + + /** + * The list of choices of this expansion unit. Each + * Vector component will narrow to ExpansionUnit. + */ + public java.util.Vector choices = new java.util.Vector(); + +} diff --git a/csjavacc/struct/Container.java b/csjavacc/struct/Container.java new file mode 100644 index 0000000..522f069 --- /dev/null +++ b/csjavacc/struct/Container.java @@ -0,0 +1,33 @@ +/* + * 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. + */ + +package csjavacc.struct; + +/** + * An object container. Used to pass references to objects as parameter. + */ + +public class Container { + + public Object member; + +} diff --git a/csjavacc/struct/Expansion.java b/csjavacc/struct/Expansion.java new file mode 100644 index 0000000..eb30f52 --- /dev/null +++ b/csjavacc/struct/Expansion.java @@ -0,0 +1,98 @@ +/* + * 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. + */ + +package csjavacc.struct; + +/** + * Describes expansions - entities that may occur on the + * right hand sides of productions. This is the base class of + * a bunch of other more specific classes. + */ + +public class Expansion { + + /** + * The line and column number of the construct that corresponds + * most closely to this node. + */ + public int line, column; + + /** + * A reimplementing of Object.hashCode() to be deterministic. This uses + * the line and column fields to generate an arbitrary number - we assume + * that this method is called only after line and column are set to + * their actual values. + */ + public int hashCode() { + return line + column; + } + + /** + * An internal name for this expansion. This is used to generate parser + * routines. + */ + public String internal_name = ""; + + /** + * The parser routines are generated in three phases. The generation + * of the second and third phase are on demand only, and the third phase + * can be recursive. This variable is used to keep track of the + * expansions for which phase 3 generations have been already added to + * a list so that the recursion can be terminated. + */ + public boolean phase3done = false; + + /** + * The parent of this expansion node. In case this is the top level + * expansion of the production it is a reference to the production node + * otherwise it is a reference to another Expansion node. In case this + * is the top level of a lookahead expansion,then the parent is null. + */ + public Object parent; + + /** + * The ordinal of this node with respect to its parent. + */ + public int ordinal; + + /** + * To avoid right-recursive loops when calculating follow sets, we use + * a generation number which indicates if this expansion was visited + * by LookaheadWalk.genFollowSet in the same generation. New generations + * are obtained by incrementing the static counter below, and the current + * generation is stored in the non-static variable below. + */ + public static long nextGenerationIndex = 1; + public long myGeneration = 0; + + /** + * This flag is used for bookkeeping by the minimumSize method in class + * ParseEngine. + */ + public boolean inMinimumSize = false; + + public static void reInit() + { + nextGenerationIndex = 1; + } + +} diff --git a/csjavacc/struct/Lookahead.java b/csjavacc/struct/Lookahead.java new file mode 100644 index 0000000..60ee58a --- /dev/null +++ b/csjavacc/struct/Lookahead.java @@ -0,0 +1,66 @@ +/* + * 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. + */ + +package csjavacc.struct; + + +/** + * Describes lookahead rule for a particular expansion or expansion + * sequence (See Sequence.java). In case this describes the lookahead + * rule for a single expansion unit, then a sequence is created with + * this node as the first element, and the expansion unit as the second + * and last element. + */ + +public class Lookahead extends Expansion { + + /** + * Contains the list of tokens that make up the semantic lookahead + * if any. If this node represents a different kind of lookahead (other + * than semantic lookahead), then this vector contains nothing. If + * this vector contains something, then it is the boolean expression + * that forms the semantic lookahead. In this case, the following + * fields "amount" and "la_expansion" are ignored. + */ + public java.util.Vector action_tokens = new java.util.Vector(); + + /** + * The lookahead amount. Its default value essentially gives us + * infinite lookahead. + */ + public int amount = Integer.MAX_VALUE; + + /** + * The expansion used to determine whether or not to choose the + * corresponding parse option. This expansion is parsed upto + * "amount" tokens of lookahead or until a complete match for it + * is found. Usually, this is the same as the expansion to be + * parsed. + */ + public Expansion la_expansion; + + /** + * Is set to true if this is an explicit lookahead specification. + */ + public boolean isExplicit; + +} diff --git a/csjavacc/struct/MatchInfo.java b/csjavacc/struct/MatchInfo.java new file mode 100644 index 0000000..bb96142 --- /dev/null +++ b/csjavacc/struct/MatchInfo.java @@ -0,0 +1,34 @@ +/* + * 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. + */ + +package csjavacc.struct; + +public class MatchInfo { + public static int laLimit; + public int[] match = new int[laLimit]; + public int firstFreeLoc; + + public static void reInit() + { + laLimit = 0; + } +} diff --git a/csjavacc/struct/Nfa.java b/csjavacc/struct/Nfa.java new file mode 100644 index 0000000..1b63729 --- /dev/null +++ b/csjavacc/struct/Nfa.java @@ -0,0 +1,43 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import csjavacc.parser.NfaState; + +public class Nfa +{ + public NfaState start; + public NfaState end; + + public Nfa() + { + start = new NfaState(); + end = new NfaState(); + } + + public Nfa(NfaState startGiven, NfaState finalGiven) + { + start = startGiven; + end = finalGiven; + } +} diff --git a/csjavacc/struct/NonTerminal.java b/csjavacc/struct/NonTerminal.java new file mode 100644 index 0000000..bcddf9a --- /dev/null +++ b/csjavacc/struct/NonTerminal.java @@ -0,0 +1,55 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import csjavacc.parser.NormalProduction; + +/** + * Describes non terminals. + */ + +public class NonTerminal extends Expansion { + + /** + * The LHS to which the return value of the non-terminal + * is assigned. In case there is no LHS, then the vector + * remains empty. + */ + public java.util.Vector lhsTokens = new java.util.Vector(); + + /** + * The name of the non-terminal. + */ + public String name; + + /** + * The list of all tokens in the argument list. + */ + public java.util.Vector argument_tokens = new java.util.Vector(); + + /** + * The production this non-terminal corresponds to. + */ + public NormalProduction prod; + +} diff --git a/csjavacc/struct/REndOfFile.java b/csjavacc/struct/REndOfFile.java new file mode 100644 index 0000000..d87dfb0 --- /dev/null +++ b/csjavacc/struct/REndOfFile.java @@ -0,0 +1,36 @@ +/* + * 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. + */ + +package csjavacc.struct; + + +/** + * Describes the EOF regular expression + */ + +public class REndOfFile extends RegularExpression { + + public Nfa GenerateNfa(boolean ignoreCase) + { + return null; + } +} diff --git a/csjavacc/struct/RJustName.java b/csjavacc/struct/RJustName.java new file mode 100644 index 0000000..a0b60ce --- /dev/null +++ b/csjavacc/struct/RJustName.java @@ -0,0 +1,44 @@ +/* + * 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. + */ + +package csjavacc.struct; + + +/** + * Describes regular expressions which are referred to just by + * their name. This means that a regular expression with this + * name has been declared earlier. + */ + +public class RJustName extends RegularExpression { + + /** + * "regexpr" points to the regular expression denoted by the name. + */ + public RegularExpression regexpr; + + public Nfa GenerateNfa(boolean ignoreCase) + { + return regexpr.GenerateNfa(ignoreCase); + } + +} diff --git a/csjavacc/struct/ROneOrMore.java b/csjavacc/struct/ROneOrMore.java new file mode 100644 index 0000000..203eff9 --- /dev/null +++ b/csjavacc/struct/ROneOrMore.java @@ -0,0 +1,52 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import csjavacc.parser.NfaState; + +/** + * Describes one-or-more regular expressions (). + */ + +public class ROneOrMore extends RegularExpression { + + /** + * The regular expression which is repeated one or more times. + */ + public RegularExpression regexpr; + + public Nfa GenerateNfa(boolean ignoreCase) + { + Nfa retVal = new Nfa(); + NfaState startState = retVal.start; + NfaState finalState = retVal.end; + + Nfa temp = regexpr.GenerateNfa(ignoreCase); + + startState.AddMove(temp.start); + temp.end.AddMove(temp.start); + temp.end.AddMove(finalState); + + return retVal; + } +} diff --git a/csjavacc/struct/RRepetitionRange.java b/csjavacc/struct/RRepetitionRange.java new file mode 100644 index 0000000..e0a17a2 --- /dev/null +++ b/csjavacc/struct/RRepetitionRange.java @@ -0,0 +1,69 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import java.util.Vector; + + +/** + * Describes one-or-more regular expressions (). + */ + +public class RRepetitionRange extends RegularExpression { + + /** + * The regular expression which is repeated one or more times. + */ + public RegularExpression regexpr; + public int min = 0; + public int max = -1; + public boolean hasMax; + + public Nfa GenerateNfa(boolean ignoreCase) + { + Vector units = new Vector(); + RSequence seq; + int i; + + for (i = 0; i < min; i++) + { + units.addElement(regexpr); + } + + if (hasMax && max == -1) // Unlimited + { + RZeroOrMore zoo = new RZeroOrMore(); + zoo.regexpr = regexpr; + units.addElement(zoo); + } + + while (i++ < max) + { + RZeroOrOne zoo = new RZeroOrOne(); + zoo.regexpr = regexpr; + units.addElement(zoo); + } + seq = new RSequence(units); + return seq.GenerateNfa(ignoreCase); + } +} diff --git a/csjavacc/struct/RSequence.java b/csjavacc/struct/RSequence.java new file mode 100644 index 0000000..5de96f0 --- /dev/null +++ b/csjavacc/struct/RSequence.java @@ -0,0 +1,82 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import java.util.*; + +import csjavacc.parser.NfaState; + +/** + * Describes regular expressions which are sequences of + * other regular expressions. + */ + +public class RSequence extends RegularExpression { + + /** + * The list of units in this regular expression sequence. Each + * Vector component will narrow to RegularExpression. + */ + public java.util.Vector units = new java.util.Vector(); + + public Nfa GenerateNfa(boolean ignoreCase) + { + if (units.size() == 1) + return ((RegularExpression)units.elementAt(0)).GenerateNfa(ignoreCase); + + Nfa retVal = new Nfa(); + NfaState startState = retVal.start; + NfaState finalState = retVal.end; + Nfa temp1; + Nfa temp2 = null; + + RegularExpression curRE; + + curRE = (RegularExpression)units.elementAt(0); + temp1 = curRE.GenerateNfa(ignoreCase); + startState.AddMove(temp1.start); + + for (int i = 1; i < units.size(); i++) + { + curRE = (RegularExpression)units.elementAt(i); + + temp2 = curRE.GenerateNfa(ignoreCase); + temp1.end.AddMove(temp2.start); + temp1 = temp2; + } + + temp2.end.AddMove(finalState); + + return retVal; + } + + public RSequence() + { + } + + public RSequence(Vector seq) + { + ordinal = Integer.MAX_VALUE; + units = seq; + } +} diff --git a/csjavacc/struct/RZeroOrMore.java b/csjavacc/struct/RZeroOrMore.java new file mode 100644 index 0000000..5a7a3d0 --- /dev/null +++ b/csjavacc/struct/RZeroOrMore.java @@ -0,0 +1,54 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import csjavacc.parser.NfaState; + +/** + * Describes zero-or-more regular expressions (). + */ + +public class RZeroOrMore extends RegularExpression { + + /** + * The regular expression which is repeated zero or more times. + */ + public RegularExpression regexpr; + + public Nfa GenerateNfa(boolean ignoreCase) + { + Nfa retVal = new Nfa(); + NfaState startState = retVal.start; + NfaState finalState = retVal.end; + + Nfa temp = regexpr.GenerateNfa(ignoreCase); + + startState.AddMove(temp.start); + startState.AddMove(finalState); + temp.end.AddMove(finalState); + temp.end.AddMove(temp.start); + + return retVal; + } + +} diff --git a/csjavacc/struct/RZeroOrOne.java b/csjavacc/struct/RZeroOrOne.java new file mode 100644 index 0000000..62e9d27 --- /dev/null +++ b/csjavacc/struct/RZeroOrOne.java @@ -0,0 +1,53 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import csjavacc.parser.NfaState; + +/** + * Describes zero-or-one regular expressions (). + */ + +public class RZeroOrOne extends RegularExpression { + + /** + * The regular expression which is repeated zero or one times. + */ + public RegularExpression regexpr; + + public Nfa GenerateNfa(boolean ignoreCase) + { + Nfa retVal = new Nfa(); + NfaState startState = retVal.start; + NfaState finalState = retVal.end; + + Nfa temp = regexpr.GenerateNfa(ignoreCase); + + startState.AddMove(temp.start); + startState.AddMove(finalState); + temp.end.AddMove(finalState); + + return retVal; + } + +} diff --git a/csjavacc/struct/RegularExpression.java b/csjavacc/struct/RegularExpression.java new file mode 100644 index 0000000..1a24821 --- /dev/null +++ b/csjavacc/struct/RegularExpression.java @@ -0,0 +1,89 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import csjavacc.parser.Token; + +/** + * Describes regular expressions. + */ + +abstract public class RegularExpression extends Expansion { + + /** + * The label of the regular expression (if any). If no label is + * present, this is set to "". + */ + public String label = ""; + + /** + * The ordinal value assigned to the regular expression. It is + * used for internal processing and passing information between + * the parser and the lexical analyzer. + */ + public int ordinal; + + /** + * The LHS to which the token value of the regular expression + * is assigned. In case there is no LHS, then the vector + * remains empty. + */ + public java.util.Vector lhsTokens = new java.util.Vector(); + + /** + * We now allow qualified access to token members. Store it here. + */ + public Token rhsToken; + + /** + * This flag is set if the regular expression has a label prefixed + * with the # symbol - this indicates that the purpose of the regular + * expression is solely for defining other regular expressions. + */ + public boolean private_rexp = false; + + /** + * If this is a top-level regular expression (nested directly + * within a TokenProduction), then this field point to that + * TokenProduction object. + */ + public TokenProduction tpContext = null; + + abstract public Nfa GenerateNfa(boolean ignoreCase); + + public boolean CanMatchAnyChar() + { + return false; + } + + /** + * The following variable is used to maintain state information for the + * loop determination algorithm: It is initialized to 0, and + * set to -1 if this node has been visited in a pre-order walk, and then + * it is set to 1 if the pre-order walk of the whole graph from this + * node has been traversed. i.e., -1 indicates partially processed, + * and 1 indicates fully processed. + */ + public int walkStatus = 0; + +} diff --git a/csjavacc/struct/TokenProduction.java b/csjavacc/struct/TokenProduction.java new file mode 100644 index 0000000..acd949e --- /dev/null +++ b/csjavacc/struct/TokenProduction.java @@ -0,0 +1,94 @@ +/* + * 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. + */ + +package csjavacc.struct; + +import csjavacc.parser.Token; + +/** + * Describes the various regular expression productions. + */ + +public class TokenProduction { + + /** + * Definitions of constants that identify the kind of regular + * expression production this is. + */ + public static final int TOKEN = 0, + SKIP = 1, + MORE = 2, + SPECIAL = 3; + + /** + * The image of the above constants. + */ + public static final String[] kindImage = { + "TOKEN", "SKIP", "MORE", "SPECIAL" + }; + + /** + * The starting line and column of this token production. + */ + public int line, column; + + /** + * The states in which this regular expression production exists. If + * this array is null, then "<*>" has been specified and this regular + * expression exists in all states. However, this null value is + * replaced by a String array that includes all lexical state names + * during the semanticization phase. + */ + public String[] lexStates; + + /** + * The kind of this token production - TOKEN, SKIP, MORE, or SPECIAL. + */ + public int kind; + + /** + * The list of regular expression specifications that comprise this + * production. Each entry is a "RegExprSpec". + */ + public java.util.Vector respecs = new java.util.Vector(); + + /** + * This is true if this corresponds to a production that actually + * appears in the input grammar. Otherwise (if this is created to + * describe a regular expression that is part of the BNF) this is set + * to false. + */ + public boolean isExplicit = true; + + /** + * This is true if case is to be ignored within the regular expressions + * of this token production. + */ + public boolean ignoreCase = false; + + /** + * The first and last tokens from the input stream that represent this + * production. + */ + public Token firstToken, lastToken; + +} diff --git a/csjavacc/struct/TreeWalkerOp.java b/csjavacc/struct/TreeWalkerOp.java new file mode 100644 index 0000000..de16499 --- /dev/null +++ b/csjavacc/struct/TreeWalkerOp.java @@ -0,0 +1,44 @@ +/* + * 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. + */ + +package csjavacc.struct; + + +/** + * Objects of this type are passed to the tree walker + * routines in ExpansionTreeWalker. + */ +public interface TreeWalkerOp { + + /** + * When called at a particular node, this specifies to the + * tree walker if it should visit more nodes under this node. + */ + boolean goDeeper(Expansion e); + + /** + * When a node is visited, this method is invoked with the + * node as parameter. + */ + void action(Expansion e); + +} diff --git a/csjavacc/struct/TryBlock.java b/csjavacc/struct/TryBlock.java new file mode 100644 index 0000000..29bfe00 --- /dev/null +++ b/csjavacc/struct/TryBlock.java @@ -0,0 +1,61 @@ +/* + * 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. + */ + +package csjavacc.struct; + + +/** + * Describes expansions of the form "try {...} ..." + */ + +public class TryBlock extends Expansion { + + /** + * The expansion contained within the try block. + */ + public Expansion exp; + + /** + * The types of each catch block. Each vector entry is itself a + * vector which in turn contains tokens as entries. + */ + public java.util.Vector types; + + /** + * The exception identifiers of each catch block. Each vector entry + * is a token. + */ + public java.util.Vector ids; + + /** + * The block part of each catch block. Each vector entry is itself a + * vector which in turn contains tokens as entries. + */ + public java.util.Vector catchblks; + + /** + * The block part of the finally block. Each vector entry is a token. + * If there is no finally block, this is null. + */ + public java.util.Vector finallyblk; + +} diff --git a/csjavacc/struct/ZeroOrMore.java b/csjavacc/struct/ZeroOrMore.java new file mode 100644 index 0000000..58021a3 --- /dev/null +++ b/csjavacc/struct/ZeroOrMore.java @@ -0,0 +1,37 @@ +/* + * 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. + */ + +package csjavacc.struct; + + +/** + * Describes zero-or-more expansions (e.g., foo*). + */ + +public class ZeroOrMore extends Expansion { + + /** + * The expansion which is repeated zero or more times. + */ + public Expansion expansion; + +} diff --git a/csjavacc/struct/ZeroOrOne.java b/csjavacc/struct/ZeroOrOne.java new file mode 100644 index 0000000..63edb50 --- /dev/null +++ b/csjavacc/struct/ZeroOrOne.java @@ -0,0 +1,37 @@ +/* + * 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. + */ + +package csjavacc.struct; + + +/** + * Describes zero-or-one expansions (e.g., [foo], foo?). + */ + +public class ZeroOrOne extends Expansion { + + /** + * The expansion which is repeated zero or one times. + */ + public Expansion expansion; + +}