Initial commit
This commit is contained in:
49
csjavacc.java
Normal file
49
csjavacc.java
Normal file
@@ -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); }
|
||||
}
|
||||
5
csjavacc/Version.java
Normal file
5
csjavacc/Version.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package csjavacc;
|
||||
public interface Version {
|
||||
String version = "4.0 (12/04/2018)";
|
||||
}
|
||||
|
||||
2996
csjavacc/parser/CSJavaCC.jj
Normal file
2996
csjavacc/parser/CSJavaCC.jj
Normal file
File diff suppressed because it is too large
Load Diff
116
csjavacc/parser/CSJavaCCErrors.java
Normal file
116
csjavacc/parser/CSJavaCCErrors.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
548
csjavacc/parser/CSJavaCCGlobals.java
Normal file
548
csjavacc/parser/CSJavaCCGlobals.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
7661
csjavacc/parser/CSJavaCCParser.java
Normal file
7661
csjavacc/parser/CSJavaCCParser.java
Normal file
File diff suppressed because it is too large
Load Diff
299
csjavacc/parser/CSJavaCCParserConstants.java
Normal file
299
csjavacc/parser/CSJavaCCParserConstants.java
Normal file
@@ -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 = {
|
||||
"<EOF>",
|
||||
"\"options\"",
|
||||
"\"LOOKAHEAD\"",
|
||||
"\"IGNORE_CASE\"",
|
||||
"\"PARSER_BEGIN\"",
|
||||
"\"PARSER_END\"",
|
||||
"\"CSCODE\"",
|
||||
"\"TOKEN\"",
|
||||
"\"SPECIAL_TOKEN\"",
|
||||
"\"MORE\"",
|
||||
"\"SKIP\"",
|
||||
"\"TOKEN_MGR_DECLS\"",
|
||||
"\"EOF\"",
|
||||
"\" \"",
|
||||
"\"\\t\"",
|
||||
"\"\\n\"",
|
||||
"\"\\r\"",
|
||||
"\"\\f\"",
|
||||
"<token of kind 18>",
|
||||
"\"//\"",
|
||||
"<token of kind 20>",
|
||||
"\"/*\"",
|
||||
"<token of kind 22>",
|
||||
"<SINGLE_LINE_COMMENT>",
|
||||
"<PRAGMA>",
|
||||
"\"*/\"",
|
||||
"\"*/\"",
|
||||
"<token of kind 27>",
|
||||
"\"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\"",
|
||||
"<INTEGER_LITERAL>",
|
||||
"<DECIMAL_LITERAL>",
|
||||
"<HEX_LITERAL>",
|
||||
"<OCTAL_LITERAL>",
|
||||
"<FLOATING_POINT_LITERAL>",
|
||||
"<DECIMAL_FLOATING_POINT_LITERAL>",
|
||||
"<DECIMAL_EXPONENT>",
|
||||
"<HEXADECIMAL_FLOATING_POINT_LITERAL>",
|
||||
"<HEXADECIMAL_EXPONENT>",
|
||||
"<CHARACTER_LITERAL>",
|
||||
"<STRING_LITERAL>",
|
||||
"\"(\"",
|
||||
"\")\"",
|
||||
"\"{\"",
|
||||
"\"}\"",
|
||||
"\"[\"",
|
||||
"\"]\"",
|
||||
"\";\"",
|
||||
"\",\"",
|
||||
"\".\"",
|
||||
"\"=\"",
|
||||
"\"<\"",
|
||||
"\"!\"",
|
||||
"\"~\"",
|
||||
"\"?\"",
|
||||
"\":\"",
|
||||
"\"==\"",
|
||||
"\"<=\"",
|
||||
"\">=\"",
|
||||
"\"!=\"",
|
||||
"\"||\"",
|
||||
"\"&&\"",
|
||||
"\"++\"",
|
||||
"\"--\"",
|
||||
"\"+\"",
|
||||
"\"-\"",
|
||||
"\"*\"",
|
||||
"\"/\"",
|
||||
"\"&\"",
|
||||
"\"|\"",
|
||||
"\"^\"",
|
||||
"\"%\"",
|
||||
"\"+=\"",
|
||||
"\"-=\"",
|
||||
"\"*=\"",
|
||||
"\"/=\"",
|
||||
"\"&=\"",
|
||||
"\"|=\"",
|
||||
"\"^=\"",
|
||||
"\"%=\"",
|
||||
"\">>>\"",
|
||||
"\">>\"",
|
||||
"\">\"",
|
||||
"\"#\"",
|
||||
"\"get\"",
|
||||
"\"set\"",
|
||||
"\"...\"",
|
||||
"\"<<=\"",
|
||||
"\">>=\"",
|
||||
"\">>>=\"",
|
||||
"\"is\"",
|
||||
"\"<<\"",
|
||||
"\"lock\"",
|
||||
"\"in\"",
|
||||
"\"finally\"",
|
||||
"<IDENTIFIER>",
|
||||
"<LETTER>",
|
||||
"<PART_LETTER>",
|
||||
};
|
||||
|
||||
}
|
||||
307
csjavacc/parser/CSJavaCCParserInternals.java
Normal file
307
csjavacc/parser/CSJavaCCParserInternals.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
2765
csjavacc/parser/CSJavaCCParserTokenManager.java
Normal file
2765
csjavacc/parser/CSJavaCCParserTokenManager.java
Normal file
File diff suppressed because it is too large
Load Diff
567
csjavacc/parser/CSJavaCharStream.java
Normal file
567
csjavacc/parser/CSJavaCharStream.java
Normal file
@@ -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];
|
||||
}
|
||||
|
||||
}
|
||||
2048
csjavacc/parser/CSJavaFiles.java
Normal file
2048
csjavacc/parser/CSJavaFiles.java
Normal file
File diff suppressed because it is too large
Load Diff
142
csjavacc/parser/ExpansionTreeWalker.java
Normal file
142
csjavacc/parser/ExpansionTreeWalker.java
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
589
csjavacc/parser/JavaCharStream.java
Normal file
589
csjavacc/parser/JavaCharStream.java
Normal file
@@ -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];
|
||||
}
|
||||
|
||||
}
|
||||
1464
csjavacc/parser/LexGen.java
Normal file
1464
csjavacc/parser/LexGen.java
Normal file
File diff suppressed because it is too large
Load Diff
261
csjavacc/parser/LookaheadCalc.java
Normal file
261
csjavacc/parser/LookaheadCalc.java
Normal file
@@ -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 += " <EOF>";
|
||||
} 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 += " <token of kind " + i + ">";
|
||||
}
|
||||
}
|
||||
}
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
217
csjavacc/parser/LookaheadWalk.java
Normal file
217
csjavacc/parser/LookaheadWalk.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
207
csjavacc/parser/Main.java
Normal file
207
csjavacc/parser/Main.java
Normal file
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
26
csjavacc/parser/MetaParseException.java
Normal file
26
csjavacc/parser/MetaParseException.java
Normal file
@@ -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 {
|
||||
}
|
||||
2967
csjavacc/parser/NfaState.java
Normal file
2967
csjavacc/parser/NfaState.java
Normal file
File diff suppressed because it is too large
Load Diff
105
csjavacc/parser/NormalProduction.java
Normal file
105
csjavacc/parser/NormalProduction.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
38
csjavacc/parser/OneOrMore.java
Normal file
38
csjavacc/parser/OneOrMore.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
518
csjavacc/parser/Options.java
Normal file
518
csjavacc/parser/Options.java
Normal file
@@ -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"));
|
||||
}
|
||||
}
|
||||
147
csjavacc/parser/OtherFilesGen.java
Normal file
147
csjavacc/parser/OtherFilesGen.java
Normal file
@@ -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(" \"<EOF>\",");
|
||||
|
||||
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(" \"<token of kind " + re.ordinal + ">\",");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
ostr.println(" };");
|
||||
ostr.println("");
|
||||
ostr.println("}");
|
||||
|
||||
if(namespace)
|
||||
ostr.println("}");
|
||||
|
||||
ostr.close();
|
||||
|
||||
}
|
||||
|
||||
static private java.io.PrintWriter ostr;
|
||||
|
||||
public static void reInit()
|
||||
{
|
||||
ostr = null;
|
||||
}
|
||||
|
||||
}
|
||||
1224
csjavacc/parser/ParseEngine.java
Normal file
1224
csjavacc/parser/ParseEngine.java
Normal file
File diff suppressed because it is too large
Load Diff
197
csjavacc/parser/ParseException.java
Normal file
197
csjavacc/parser/ParseException.java
Normal file
@@ -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: <result of getMessage>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
716
csjavacc/parser/ParseGen.java
Normal file
716
csjavacc/parser/ParseGen.java
Normal file
@@ -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<long[]> jj_expentries = new System.Collections.Generic.List<long[]>();");
|
||||
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<<j)) != 0) {");
|
||||
ostr.print(" la1tokens[");
|
||||
if (i != 0) {
|
||||
ostr.print((32*i) + "+");
|
||||
}
|
||||
ostr.println("j] = true;");
|
||||
ostr.println(" }");
|
||||
}
|
||||
ostr.println(" }");
|
||||
ostr.println(" }");
|
||||
ostr.println(" }");
|
||||
ostr.println(" for (int i = 0; i < " + tokenCount + "; i++) {");
|
||||
ostr.println(" if (la1tokens[i]) {");
|
||||
ostr.println(" jj_expentry = new long[1];");
|
||||
ostr.println(" jj_expentry[0] = i;");
|
||||
ostr.println(" jj_expentries.Add(jj_expentry);");
|
||||
ostr.println(" }");
|
||||
ostr.println(" }");
|
||||
if (jj2index != 0) {
|
||||
ostr.println(" jj_endpos = 0;");
|
||||
ostr.println(" jj_rescan_token();");
|
||||
ostr.println(" jj_add_error_token(0, 0);");
|
||||
}
|
||||
ostr.println(" long[][] exptokseq = new long[jj_expentries.Count][];");
|
||||
ostr.println(" for (int i = 0; i < jj_expentries.Count; i++) {");
|
||||
ostr.println(" exptokseq[i] = (long[])jj_expentries[i];");
|
||||
ostr.println(" }");
|
||||
ostr.println(" return new ParseException(token, exptokseq, tokenImage);");
|
||||
ostr.println(" }");
|
||||
} else {
|
||||
ostr.println(" " + staticOpt() + "public ParseException generateParseException() {");
|
||||
ostr.println(" Token errortok = token.next;");
|
||||
if (Options.getKeepLineColumn())
|
||||
ostr.println(" int line = errortok.beginLine, column = errortok.beginColumn;");
|
||||
ostr.println(" String mess = (errortok.kind == 0) ? tokenImage[0] : errortok.image;");
|
||||
if (Options.getKeepLineColumn())
|
||||
ostr.println(" return new ParseException(\"Parse error at line \" + line + \", column \" + column + \". Encountered: \" + mess);");
|
||||
else
|
||||
ostr.println(" return new ParseException(\"Parse error at <unknown location>. 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;
|
||||
}
|
||||
|
||||
}
|
||||
617
csjavacc/parser/RCharacterList.java
Normal file
617
csjavacc/parser/RCharacterList.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
153
csjavacc/parser/RChoice.java
Normal file
153
csjavacc/parser/RChoice.java
Normal file
@@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1306
csjavacc/parser/RStringLiteral.java
Normal file
1306
csjavacc/parser/RStringLiteral.java
Normal file
File diff suppressed because it is too large
Load Diff
60
csjavacc/parser/RegExprSpec.java
Normal file
60
csjavacc/parser/RegExprSpec.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
841
csjavacc/parser/Semanticize.java
Normal file
841
csjavacc/parser/Semanticize.java
Normal file
@@ -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
|
||||
* <EOF> and <name> 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, <name> 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 <EOF>.");
|
||||
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 <EOF>.");
|
||||
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 <NEWLABEL:<" + res.rexp.label + ">>.");
|
||||
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.leIndex; i++) {
|
||||
if (prod.leftExpansions[i] == ((NonTerminal)exp).prod) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (prod.leIndex == prod.leftExpansions.length) {
|
||||
NormalProduction[] newle = new NormalProduction[prod.leIndex*2];
|
||||
System.arraycopy(prod.leftExpansions, 0, newle, 0, prod.leIndex);
|
||||
prod.leftExpansions = newle;
|
||||
}
|
||||
prod.leftExpansions[prod.leIndex++] = ((NonTerminal)exp).prod;
|
||||
} else if (exp instanceof OneOrMore) {
|
||||
addLeftMost(prod, ((OneOrMore)exp).expansion);
|
||||
} else if (exp instanceof ZeroOrMore) {
|
||||
addLeftMost(prod, ((ZeroOrMore)exp).expansion);
|
||||
} else if (exp instanceof ZeroOrOne) {
|
||||
addLeftMost(prod, ((ZeroOrOne)exp).expansion);
|
||||
} else if (exp instanceof Choice) {
|
||||
for (java.util.Enumeration anEnum = ((Choice)exp).choices.elements(); anEnum.hasMoreElements();) {
|
||||
addLeftMost(prod, (Expansion)anEnum.nextElement());
|
||||
}
|
||||
} else if (exp instanceof Sequence) {
|
||||
for (java.util.Enumeration anEnum = ((Sequence)exp).units.elements(); anEnum.hasMoreElements();) {
|
||||
Expansion e = (Expansion)anEnum.nextElement();
|
||||
addLeftMost(prod, e);
|
||||
if (!emptyExpansionExists(e)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (exp instanceof TryBlock) {
|
||||
addLeftMost(prod, ((TryBlock)exp).exp);
|
||||
}
|
||||
}
|
||||
|
||||
// The string in which the following methods store information.
|
||||
static private String loopString;
|
||||
|
||||
// Returns true to indicate an unraveling of a detected left recursion loop,
|
||||
// and returns false otherwise.
|
||||
static private boolean prodWalk(NormalProduction prod) {
|
||||
prod.walkStatus = -1;
|
||||
for (int i = 0; i < prod.leIndex; i++) {
|
||||
if (prod.leftExpansions[i].walkStatus == -1) {
|
||||
prod.leftExpansions[i].walkStatus = -2;
|
||||
loopString = prod.lhs + "... --> " + 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;
|
||||
}
|
||||
|
||||
}
|
||||
40
csjavacc/parser/Sequence.java
Normal file
40
csjavacc/parser/Sequence.java
Normal file
@@ -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();
|
||||
|
||||
}
|
||||
51
csjavacc/parser/SingleCharacter.java
Normal file
51
csjavacc/parser/SingleCharacter.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
89
csjavacc/parser/Token.java
Normal file
89
csjavacc/parser/Token.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
138
csjavacc/parser/TokenMgrError.java
Normal file
138
csjavacc/parser/TokenMgrError.java
Normal file
@@ -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 ? "<EOF> " : ("\"" + 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);
|
||||
}
|
||||
}
|
||||
40
csjavacc/struct/Action.java
Normal file
40
csjavacc/struct/Action.java
Normal file
@@ -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();
|
||||
|
||||
}
|
||||
45
csjavacc/struct/BNFProduction.java
Normal file
45
csjavacc/struct/BNFProduction.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
38
csjavacc/struct/CSCodeProduction.java
Normal file
38
csjavacc/struct/CSCodeProduction.java
Normal file
@@ -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();
|
||||
|
||||
}
|
||||
55
csjavacc/struct/CharacterRange.java
Normal file
55
csjavacc/struct/CharacterRange.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
39
csjavacc/struct/Choice.java
Normal file
39
csjavacc/struct/Choice.java
Normal file
@@ -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();
|
||||
|
||||
}
|
||||
33
csjavacc/struct/Container.java
Normal file
33
csjavacc/struct/Container.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
98
csjavacc/struct/Expansion.java
Normal file
98
csjavacc/struct/Expansion.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
66
csjavacc/struct/Lookahead.java
Normal file
66
csjavacc/struct/Lookahead.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
34
csjavacc/struct/MatchInfo.java
Normal file
34
csjavacc/struct/MatchInfo.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
43
csjavacc/struct/Nfa.java
Normal file
43
csjavacc/struct/Nfa.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
55
csjavacc/struct/NonTerminal.java
Normal file
55
csjavacc/struct/NonTerminal.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
36
csjavacc/struct/REndOfFile.java
Normal file
36
csjavacc/struct/REndOfFile.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
44
csjavacc/struct/RJustName.java
Normal file
44
csjavacc/struct/RJustName.java
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
52
csjavacc/struct/ROneOrMore.java
Normal file
52
csjavacc/struct/ROneOrMore.java
Normal file
@@ -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 (<foo+>).
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
69
csjavacc/struct/RRepetitionRange.java
Normal file
69
csjavacc/struct/RRepetitionRange.java
Normal file
@@ -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 (<foo+>).
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
82
csjavacc/struct/RSequence.java
Normal file
82
csjavacc/struct/RSequence.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
54
csjavacc/struct/RZeroOrMore.java
Normal file
54
csjavacc/struct/RZeroOrMore.java
Normal file
@@ -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 (<foo*>).
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
53
csjavacc/struct/RZeroOrOne.java
Normal file
53
csjavacc/struct/RZeroOrOne.java
Normal file
@@ -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 (<foo?>).
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
89
csjavacc/struct/RegularExpression.java
Normal file
89
csjavacc/struct/RegularExpression.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
94
csjavacc/struct/TokenProduction.java
Normal file
94
csjavacc/struct/TokenProduction.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
44
csjavacc/struct/TreeWalkerOp.java
Normal file
44
csjavacc/struct/TreeWalkerOp.java
Normal file
@@ -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);
|
||||
|
||||
}
|
||||
61
csjavacc/struct/TryBlock.java
Normal file
61
csjavacc/struct/TryBlock.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
37
csjavacc/struct/ZeroOrMore.java
Normal file
37
csjavacc/struct/ZeroOrMore.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
37
csjavacc/struct/ZeroOrOne.java
Normal file
37
csjavacc/struct/ZeroOrOne.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user