diff --git a/open-nars/JLex/Main.java b/open-nars/JLex/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..89ba5bbcb7a6d9870bae6da4c49346fd5844c885 --- /dev/null +++ b/open-nars/JLex/Main.java @@ -0,0 +1,7841 @@ +/************************************************************** + JLex: A Lexical Analyzer Generator for Java(TM) + Written by Elliot Berk <ejberk@cs.princeton.edu>. Copyright 1996. + Maintained by C. Scott Ananian <cananian@alumni.princeton.edu>. + See below for copyright notice, license, and disclaimer. + New releases from http://www.cs.princeton.edu/~appel/modern/java/JLex/ + + Version 1.2.6, 2/7/03, [C. Scott Ananian] + Renamed 'assert' function 'ASSERT' to accomodate Java 1.4's new keyword. + Fixed a bug which certain forms of comment in the JLex directives section + (which are not allowed) to be incorrectly parsed as macro definitions. + Version 1.2.5, 7/25/99-5/16/00, [C. Scott Ananian] + Stomped on one more 8-bit character bug. Should work now (really!). + Added unicode support, including unicode escape sequences. + Rewrote internal JavaLexBitSet class as SparseBitSet for efficient + unicoding. + Added an NFA character class simplification pass for unicode efficiency. + Changed byte- and stream-oriented I/O routines to use characters and + java.io.Reader and java.io.Writer instead --- which means we read in + unicode specifications correctly and write out a proper unicode java + source file. As a happy side-effect, the output java file is written + with your platform's preferred newline character(s). + Rewrote CInput to fix bugs with line-counting in the specification file + and "unusual behaviour" when the last line of the specification wasn't + terminated with a newline. Thanks to Matt Hanna <mhanna@cs.caltech.edu> + for pointing out the bug. + Fixed a bug that would cause JLex not to terminate given certain input + specifications. Thanks to Mark Greenstreet <mrg@cs.ubc.ca> and + Frank B. Brokken <frank@suffix.icce.rug.nl> for reporting this. + CUP parser integration improved according to suggestions made by + David MacMahon <davidm@smartsc.com>. The %cup directive now tells + JLex to generate a parser conforming to the java_cup.runtime.Scanner + interface; see manual for more details. + Fixed bug with null string literals ("") in regexps. Reported by + Charles Fischer <fischer@cs.wisc.edu>. + Rewrote start-of-line and end-of-line handling, closing active bug #5. + Also fixed line-counting code, closing active bug #12. All + new-line handling is now platform-independent. + Used unpackFromString more extensively to allow larger cmap, etc, + tables. This helps unicode support work reliably. It's also + prettier now if you happen to read the source to the generated + lexer. + Generated lexer now accepts unicode LS (U+2028) and PS (U+2029) as + line separators for strict unicode compliance; see + http://www.unicode.org/unicode/reports/tr18/ + Fixed bug with character constants in action strings. Reported by + Andrew Appel against 1.2.5b3. + Fixed bug with illegal \^C-style escape sequences. Reported by + Toshiya Iwai <iwai@isdnet.co.jp> against 1.2.5b4. + Fixed "newline in quoted string" error when unpaired single- or + double-quotes were present in comments in the action phrase. + Reported by Stephen Ostermiller <1010JLex@ostermiller.com> + against 1.2.5b4. Reported by Eric Esposito <eric.esposito@unh.edu> + against 1.2.4 and 1.2.5b2. + Fixed "newline in quoted string" error when /* or // appeared + in quoted strings in the action phrase. Reported by + David Eichmann <david-eichmann@uiowa.edu> against 1.2.5b5. + Fixed 'illegal constant' errors in case statements caused by + Sun's JDK 1.3 more closely adhering to the Java Language + Specification. Reported by a number of people, but + Harold Grovesteen <hgrovesteen@home.com> was the first to direct me to + a Sun bug report (4119776) which quoted the relevant section of the + JLS (15.27) to convince me that the JLex construction actually was + illegal. Reported against 1.2.5b6, but this bit of code has been + present since the very first version of JLex (1.1.1). + + Version 1.2.4, 7/24/99, [C. Scott Ananian] + Correct the parsing of '-' in character classes, closing active + bug #1. Behaviour follows egrep: leading and trailing dashes in + a character class lose their special meaning, so [-+] and [+-] do + what you would expect them to. + New %ignorecase directive for generating case-insensitive lexers by + expanding matched character classes in a unicode-friendly way. + Handle unmatched braces in quoted strings or comments within + action code blocks. + Fixed input lexer to allow whitespace in character classes, closing + active bug #9. Whitespace in quotes had been previously fixed. + Made Yylex.YYEOF and %yyeof work like the manual says they should. + + Version 1.2.3, 6/26/97, [Raimondas Lencevicius] + Fixed the yy_nxt[][] assignment that has generated huge code + exceeding 64K method size limit. Now the assignment + is handled by unpacking a string encoding of integer array. + To achieve that, added + "private int [][] unpackFromString(int size1, int size2, String st)" + function and coded the yy_nxt[][] values into a string + by printing integers into a string and representing + integer sequences as "value:length" pairs. + Improvement: generated .java file reduced 2 times, .class file + reduced 6 times for sample grammar. No 64K errors. + Possible negatives: Some editors and OSs may not be able to handle + the huge one-line generated string. String unpacking may be slower + than direct array initialization. + + Version 1.2.2, 10/24/97, [Martin Dirichs] + Notes: + Changed yy_instream to yy_reader of type BufferedReader. This reflects + the improvements in the JDK 1.1 concerning InputStreams. As a + consequence, changed yy_buffer from byte[] to char[]. + The lexer can now be initialized with either an InputStream + or a Reader. A third, private constructor is called by the other + two to execute user specified constructor code. + + Version 1.2.1, 9/15/97 [A. Appel] + Fixed bugs 6 (character codes > 127) and 10 (deprecated String constructor). + + Version 1.2, 5/5/97, [Elliot Berk] + Notes: + Simply changed the name from JavaLex to JLex. No other changes. + + Version 1.1.5, 2/25/97, [Elliot Berk] + Notes: + Simple optimization to the creation of the source files. + Added a BufferedOutputStream in the creation of the DataOutputStream + field m_outstream of the class CLexGen. This helps performance by + doing some buffering, and was suggested by Max Hailperin, + Associate Professor of Computer Science, Gustavus Adolphus College. + + Version 1.1.4, 12/12/96, [Elliot Berk] + Notes: + Added %public directive to make generated class public. + + Version 1.1.3, 12/11/96, [Elliot Berk] + Notes: + Converted assertion failure on invalid character class + when a dash '-' is not preceded with a start-of-range character. + Converted this into parse error E_DASH. + + Version 1.1.2, October 30, 1996 [Elliot Berk] + Fixed BitSet bugs by installing a BitSet class of my own, + called JavaLexBitSet. Fixed support for '\r', non-UNIX + sequences. Added try/catch block around lexer generation + in main routine to moderate error information presented + to user. Fixed macro expansion, so that macros following + quotes are expanded correctly in regular expressions. + Fixed dynamic reallocation of accept action buffers. + + Version 1.1.1, September 3, 1996 [Andrew Appel] + Made the class "Main" instead of "JavaLex", + improved the installation instructions to reflect this. + + Version 1.1, August 15, 1996 [Andrew Appel] + Made yychar, yyline, yytext global to the lexer so that + auxiliary functions can access them. + **************************************************************/ + +/*************************************************************** + JLEX COPYRIGHT NOTICE, LICENSE, AND DISCLAIMER + Copyright 1996-2000 by Elliot Joel Berk and C. Scott Ananian + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose and without fee is hereby granted, + provided that the above copyright notice appear in all copies and that + both the copyright notice and this permission notice and warranty + disclaimer appear in supporting documentation, and that the name of + the authors or their employers not be used in advertising or publicity + pertaining to distribution of the software without specific, written + prior permission. + + The authors and their employers disclaim all warranties with regard to + this software, including all implied warranties of merchantability and + fitness. In no event shall the authors or their employers be liable + for any special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether in an + action of contract, negligence or other tortious action, arising out + of or in connection with the use or performance of this software. + **************************************************************/ + +/*************************************************************** + Package Declaration + **************************************************************/ +package JLex; + +/*************************************************************** + Imported Packages + **************************************************************/ +import java.lang.System; +import java.lang.Integer; +import java.lang.Character; + +import java.util.Enumeration; +import java.util.Stack; +import java.util.Hashtable; +import java.util.Vector; + +/****************************** + Questions: + 2) How should I use the Java package system + to make my tool more modularized and + coherent? + + Unimplemented: + !) Fix BitSet issues -- expand only when necessary. + 2) Repeated accept rules. + 6) Clean up the CAlloc class and use buffered + allocation. + 9) Add to spec about extending character set. + 11) m_verbose -- what should be done with it? + 12) turn lexical analyzer into a coherent + Java package + 13) turn lexical analyzer generator into a + coherent Java package + 16) pretty up generated code + 17) make it possible to have white space in + regular expressions + 18) clean up all of the class files the lexer + generator produces when it is compiled, + and reduce this number in some way. + 24) character format to and from file: writeup + and implementation + 25) Debug by testing all arcane regular expression cases. + 26) Look for and fix all UNDONE comments below. + 27) Fix package system. + 28) Clean up unnecessary classes. + *****************************/ + +/*************************************************************** + Class: CSpec + **************************************************************/ +class CSpec +{ + /*************************************************************** + Member Variables + **************************************************************/ + + /* Lexical States. */ + Hashtable m_states; /* Hashtable taking state indices (Integer) + to state name (String). */ + + /* Regular Expression Macros. */ + Hashtable m_macros; /* Hashtable taking macro name (String) + to corresponding char buffer that + holds macro definition. */ + + /* NFA Machine. */ + CNfa m_nfa_start; /* Start state of NFA machine. */ + Vector m_nfa_states; /* Vector of states, with index + corresponding to label. */ + + Vector m_state_rules[]; /* An array of Vectors of Integers. + The ith Vector represents the lexical state + with index i. The contents of the ith + Vector are the indices of the NFA start + states that can be matched while in + the ith lexical state. */ + + + int m_state_dtrans[]; + + /* DFA Machine. */ + Vector m_dfa_states; /* Vector of states, with index + corresponding to label. */ + Hashtable m_dfa_sets; /* Hashtable taking set of NFA states + to corresponding DFA state, + if the latter exists. */ + + /* Accept States and Corresponding Anchors. */ + Vector m_accept_vector; + int m_anchor_array[]; + + /* Transition Table. */ + Vector m_dtrans_vector; + int m_dtrans_ncols; + int m_row_map[]; + int m_col_map[]; + + /* Special pseudo-characters for beginning-of-line and end-of-file. */ + static final int NUM_PSEUDO=2; + int BOL; // beginning-of-line + int EOF; // end-of-line + + /** NFA character class minimization map. */ + int m_ccls_map[]; + + /* Regular expression token variables. */ + int m_current_token; + char m_lexeme; + boolean m_in_quote; + boolean m_in_ccl; + + /* Verbose execution flag. */ + boolean m_verbose; + + /* JLex directives flags. */ + boolean m_integer_type; + boolean m_intwrap_type; + boolean m_yyeof; + boolean m_count_chars; + boolean m_count_lines; + boolean m_cup_compatible; + boolean m_unix; + boolean m_public; + boolean m_ignorecase; + + char m_init_code[]; + int m_init_read; + + char m_init_throw_code[]; + int m_init_throw_read; + + char m_class_code[]; + int m_class_read; + + char m_eof_code[]; + int m_eof_read; + + char m_eof_value_code[]; + int m_eof_value_read; + + char m_eof_throw_code[]; + int m_eof_throw_read; + + char m_yylex_throw_code[]; + int m_yylex_throw_read; + + /* Class, function, type names. */ + char m_class_name[] = { + 'Y', 'y', 'l', + 'e', 'x' + }; + char m_implements_name[] = {}; + char m_function_name[] = { + 'y', 'y', 'l', + 'e', 'x' + }; + char m_type_name[] = { + 'Y', 'y', 't', + 'o', 'k', 'e', + 'n' + }; + + /* Lexical Generator. */ + private CLexGen m_lexGen; + + /*************************************************************** + Constants + ***********************************************************/ + static final int NONE = 0; + static final int START = 1; + static final int END = 2; + + /*************************************************************** + Function: CSpec + Description: Constructor. + **************************************************************/ + CSpec + ( + CLexGen lexGen + ) + { + m_lexGen = lexGen; + + /* Initialize regular expression token variables. */ + m_current_token = m_lexGen.EOS; + m_lexeme = '\0'; + m_in_quote = false; + m_in_ccl = false; + + /* Initialize hashtable for lexer states. */ + m_states = new Hashtable(); + m_states.put(new String("YYINITIAL"),new Integer(m_states.size())); + + /* Initialize hashtable for lexical macros. */ + m_macros = new Hashtable(); + + /* Initialize variables for lexer options. */ + m_integer_type = false; + m_intwrap_type = false; + m_count_lines = false; + m_count_chars = false; + m_cup_compatible = false; + m_unix = true; + m_public = false; + m_yyeof = false; + m_ignorecase = false; + + /* Initialize variables for JLex runtime options. */ + m_verbose = true; + + m_nfa_start = null; + m_nfa_states = new Vector(); + + m_dfa_states = new Vector(); + m_dfa_sets = new Hashtable(); + + m_dtrans_vector = new Vector(); + m_dtrans_ncols = CUtility.MAX_SEVEN_BIT + 1; + m_row_map = null; + m_col_map = null; + + m_accept_vector = null; + m_anchor_array = null; + + m_init_code = null; + m_init_read = 0; + + m_init_throw_code = null; + m_init_throw_read = 0; + + m_yylex_throw_code = null; + m_yylex_throw_read = 0; + + m_class_code = null; + m_class_read = 0; + + m_eof_code = null; + m_eof_read = 0; + + m_eof_value_code = null; + m_eof_value_read = 0; + + m_eof_throw_code = null; + m_eof_throw_read = 0; + + m_state_dtrans = null; + + m_state_rules = null; + } +} + +/*************************************************************** + Class: CEmit + **************************************************************/ +class CEmit +{ + /*************************************************************** + Member Variables + **************************************************************/ + private CSpec m_spec; + private java.io.PrintWriter m_outstream; + + /*************************************************************** + Constants: Anchor Types + **************************************************************/ + private final int START = 1; + private final int END = 2; + private final int NONE = 4; + + /*************************************************************** + Constants + **************************************************************/ + private final boolean EDBG = true; + private final boolean NOT_EDBG = false; + + /*************************************************************** + Function: CEmit + Description: Constructor. + **************************************************************/ + CEmit + ( + ) + { + reset(); + } + + /*************************************************************** + Function: reset + Description: Clears member variables. + **************************************************************/ + private void reset + ( + ) + { + m_spec = null; + m_outstream = null; + } + + /*************************************************************** + Function: set + Description: Initializes member variables. + **************************************************************/ + private void set + ( + CSpec spec, + java.io.PrintWriter outstream + ) + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != spec); + CUtility.ASSERT(null != outstream); + } + + m_spec = spec; + m_outstream = outstream; + } + + /*************************************************************** + Function: emit_imports + Description: Emits import packages at top of + generated source file. + **************************************************************/ + /*void emit_imports + ( + CSpec spec, + OutputStream outstream + ) + throws java.io.IOException + { + set(spec,outstream); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != m_spec); + CUtility.ASSERT(null != m_outstream); + }*/ + + /*m_outstream.println("import java.lang.String;"); + m_outstream.println("import java.lang.System;"); + m_outstream.println("import java.io.BufferedReader;"); + m_outstream.println("import java.io.InputStream;");*/ + /* + reset(); + }*/ + + /*************************************************************** + Function: print_details + Description: Debugging output. + **************************************************************/ + private void print_details + ( + ) + { + int i; + int j; + int next; + int state; + CDTrans dtrans; + CAccept accept; + boolean tr; + + System.out.println("---------------------- Transition Table " + + "----------------------"); + + for (i = 0; i < m_spec.m_row_map.length; ++i) + { + System.out.print("State " + i); + + accept = (CAccept) m_spec.m_accept_vector.elementAt(i); + if (null == accept) + { + System.out.println(" [nonaccepting]"); + } + else + { + System.out.println(" [accepting, line " + + accept.m_line_number + + " <" + + (new java.lang.String(accept.m_action,0, + accept.m_action_read)) + + ">]"); + } + dtrans = (CDTrans) m_spec.m_dtrans_vector.elementAt(m_spec.m_row_map[i]); + + tr = false; + state = dtrans.m_dtrans[m_spec.m_col_map[0]]; + if (CDTrans.F != state) + { + tr = true; + System.out.print("\tgoto " + state + " on [" + ((char) 0)); + } + for (j = 1; j < m_spec.m_dtrans_ncols; ++j) + { + next = dtrans.m_dtrans[m_spec.m_col_map[j]]; + if (state == next) + { + if (CDTrans.F != state) + { + System.out.print((char) j); + } + } + else + { + state = next; + if (tr) + { + System.out.println("]"); + tr = false; + } + if (CDTrans.F != state) + { + tr = true; + System.out.print("\tgoto " + state + " on [" + ((char) j)); + } + } + } + if (tr) + { + System.out.println("]"); + } + } + + System.out.println("---------------------- Transition Table " + + "----------------------"); + } + + /*************************************************************** + Function: emit + Description: High-level access function to module. + **************************************************************/ + void emit + ( + CSpec spec, + java.io.PrintWriter outstream + ) + throws java.io.IOException + { + set(spec,outstream); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != m_spec); + CUtility.ASSERT(null != m_outstream); + } + + if (CUtility.OLD_DEBUG) { + print_details(); + } + + emit_header(); + emit_construct(); + emit_helpers(); + emit_driver(); + emit_footer(); + + reset(); + } + + /*************************************************************** + Function: emit_construct + Description: Emits constructor, member variables, + and constants. + **************************************************************/ + private void emit_construct + ( + ) + throws java.io.IOException + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != m_spec); + CUtility.ASSERT(null != m_outstream); + } + + /* Constants */ + m_outstream.println("\tprivate final int YY_BUFFER_SIZE = 512;"); + + m_outstream.println("\tprivate final int YY_F = -1;"); + m_outstream.println("\tprivate final int YY_NO_STATE = -1;"); + + m_outstream.println("\tprivate final int YY_NOT_ACCEPT = 0;"); + m_outstream.println("\tprivate final int YY_START = 1;"); + m_outstream.println("\tprivate final int YY_END = 2;"); + m_outstream.println("\tprivate final int YY_NO_ANCHOR = 4;"); + + // internal + m_outstream.println("\tprivate final int YY_BOL = "+m_spec.BOL+";"); + m_outstream.println("\tprivate final int YY_EOF = "+m_spec.EOF+";"); + // external + if (m_spec.m_integer_type || true == m_spec.m_yyeof) + m_outstream.println("\tpublic final int YYEOF = -1;"); + + /* User specified class code. */ + if (null != m_spec.m_class_code) + { + m_outstream.print(new String(m_spec.m_class_code,0, + m_spec.m_class_read)); + } + + /* Member Variables */ + m_outstream.println("\tprivate java.io.BufferedReader yy_reader;"); + m_outstream.println("\tprivate int yy_buffer_index;"); + m_outstream.println("\tprivate int yy_buffer_read;"); + m_outstream.println("\tprivate int yy_buffer_start;"); + m_outstream.println("\tprivate int yy_buffer_end;"); + m_outstream.println("\tprivate char yy_buffer[];"); + if (m_spec.m_count_chars) + { + m_outstream.println("\tprivate int yychar;"); + } + if (m_spec.m_count_lines) + { + m_outstream.println("\tprivate int yyline;"); + } + m_outstream.println("\tprivate boolean yy_at_bol;"); + m_outstream.println("\tprivate int yy_lexical_state;"); + /*if (m_spec.m_count_lines || true == m_spec.m_count_chars) + { + m_outstream.println("\tprivate int yy_buffer_prev_start;"); + }*/ + m_outstream.println(); + + + /* Function: first constructor (Reader) */ + m_outstream.print("\t"); + if (true == m_spec.m_public) { + m_outstream.print("public "); + } + m_outstream.print(new String(m_spec.m_class_name)); + m_outstream.print(" (java.io.Reader reader)"); + + if (null != m_spec.m_init_throw_code) + { + m_outstream.println(); + m_outstream.print("\t\tthrows "); + m_outstream.print(new String(m_spec.m_init_throw_code,0, + m_spec.m_init_throw_read)); + m_outstream.println(); + m_outstream.println("\t\t{"); + } + else + { + m_outstream.println(" {"); + } + + m_outstream.println("\t\tthis ();"); + m_outstream.println("\t\tif (null == reader) {"); + m_outstream.println("\t\t\tthrow (new Error(\"Error: Bad input " + + "stream initializer.\"));"); + m_outstream.println("\t\t}"); + m_outstream.println("\t\tyy_reader = new java.io.BufferedReader(reader);"); + m_outstream.println("\t}"); + m_outstream.println(); + + + /* Function: second constructor (InputStream) */ + m_outstream.print("\t"); + if (true == m_spec.m_public) { + m_outstream.print("public "); + } + m_outstream.print(new String(m_spec.m_class_name)); + m_outstream.print(" (java.io.InputStream instream)"); + + if (null != m_spec.m_init_throw_code) + { + m_outstream.println(); + m_outstream.print("\t\tthrows "); + m_outstream.println(new String(m_spec.m_init_throw_code,0, + m_spec.m_init_throw_read)); + m_outstream.println("\t\t{"); + } + else + { + m_outstream.println(" {"); + } + + m_outstream.println("\t\tthis ();"); + m_outstream.println("\t\tif (null == instream) {"); + m_outstream.println("\t\t\tthrow (new Error(\"Error: Bad input " + + "stream initializer.\"));"); + m_outstream.println("\t\t}"); + m_outstream.println("\t\tyy_reader = new java.io.BufferedReader(new java.io.InputStreamReader(instream));"); + m_outstream.println("\t}"); + m_outstream.println(); + + + /* Function: third, private constructor - only for internal use */ + m_outstream.print("\tprivate "); + m_outstream.print(new String(m_spec.m_class_name)); + m_outstream.print(" ()"); + + if (null != m_spec.m_init_throw_code) + { + m_outstream.println(); + m_outstream.print("\t\tthrows "); + m_outstream.println(new String(m_spec.m_init_throw_code,0, + m_spec.m_init_throw_read)); + m_outstream.println("\t\t{"); + } + else + { + m_outstream.println(" {"); + } + + m_outstream.println("\t\tyy_buffer = new char[YY_BUFFER_SIZE];"); + m_outstream.println("\t\tyy_buffer_read = 0;"); + m_outstream.println("\t\tyy_buffer_index = 0;"); + m_outstream.println("\t\tyy_buffer_start = 0;"); + m_outstream.println("\t\tyy_buffer_end = 0;"); + if (m_spec.m_count_chars) + { + m_outstream.println("\t\tyychar = 0;"); + } + if (m_spec.m_count_lines) + { + m_outstream.println("\t\tyyline = 0;"); + } + m_outstream.println("\t\tyy_at_bol = true;"); + m_outstream.println("\t\tyy_lexical_state = YYINITIAL;"); + /*if (m_spec.m_count_lines || true == m_spec.m_count_chars) + { + m_outstream.println("\t\tyy_buffer_prev_start = 0;"); + }*/ + + /* User specified constructor code. */ + if (null != m_spec.m_init_code) + { + m_outstream.print(new String(m_spec.m_init_code,0, + m_spec.m_init_read)); + } + + m_outstream.println("\t}"); + m_outstream.println(); + + } + + /*************************************************************** + Function: emit_states + Description: Emits constants that serve as lexical states, + including YYINITIAL. + **************************************************************/ + private void emit_states + ( + ) + throws java.io.IOException + { + Enumeration states; + String state; + int index; + + states = m_spec.m_states.keys(); + /*index = 0;*/ + while (states.hasMoreElements()) + { + state = (String) states.nextElement(); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != state); + } + + m_outstream.println("\tprivate final int " + + state + + " = " + + (m_spec.m_states.get(state)).toString() + + ";"); + /*++index;*/ + } + + m_outstream.println("\tprivate final int yy_state_dtrans[] = {"); + for (index = 0; index < m_spec.m_state_dtrans.length; ++index) + { + m_outstream.print("\t\t" + m_spec.m_state_dtrans[index]); + if (index < m_spec.m_state_dtrans.length - 1) + { + m_outstream.println(","); + } + else + { + m_outstream.println(); + } + } + m_outstream.println("\t};"); + } + + /*************************************************************** + Function: emit_helpers + Description: Emits helper functions, particularly + error handling and input buffering. + **************************************************************/ + private void emit_helpers + ( + ) + throws java.io.IOException + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != m_spec); + CUtility.ASSERT(null != m_outstream); + } + + /* Function: yy_do_eof */ + m_outstream.println("\tprivate boolean yy_eof_done = false;"); + if (null != m_spec.m_eof_code) + { + m_outstream.print("\tprivate void yy_do_eof ()"); + + if (null != m_spec.m_eof_throw_code) + { + m_outstream.println(); + m_outstream.print("\t\tthrows "); + m_outstream.println(new String(m_spec.m_eof_throw_code,0, + m_spec.m_eof_throw_read)); + m_outstream.println("\t\t{"); + } + else + { + m_outstream.println(" {"); + } + + m_outstream.println("\t\tif (false == yy_eof_done) {"); + m_outstream.print(new String(m_spec.m_eof_code,0, + m_spec.m_eof_read)); + m_outstream.println("\t\t}"); + m_outstream.println("\t\tyy_eof_done = true;"); + m_outstream.println("\t}"); + } + + emit_states(); + + /* Function: yybegin */ + m_outstream.println("\tprivate void yybegin (int state) {"); + m_outstream.println("\t\tyy_lexical_state = state;"); + m_outstream.println("\t}"); + + /* Function: yy_initial_dtrans */ + /*m_outstream.println("\tprivate int yy_initial_dtrans (int state) {"); + m_outstream.println("\t\treturn yy_state_dtrans[state];"); + m_outstream.println("\t}");*/ + + /* Function: yy_advance */ + m_outstream.println("\tprivate int yy_advance ()"); + m_outstream.println("\t\tthrows java.io.IOException {"); + /*m_outstream.println("\t\t{");*/ + m_outstream.println("\t\tint next_read;"); + m_outstream.println("\t\tint i;"); + m_outstream.println("\t\tint j;"); + m_outstream.println(); + + m_outstream.println("\t\tif (yy_buffer_index < yy_buffer_read) {"); + m_outstream.println("\t\t\treturn yy_buffer[yy_buffer_index++];"); + /*m_outstream.println("\t\t\t++yy_buffer_index;");*/ + m_outstream.println("\t\t}"); + m_outstream.println(); + + m_outstream.println("\t\tif (0 != yy_buffer_start) {"); + m_outstream.println("\t\t\ti = yy_buffer_start;"); + m_outstream.println("\t\t\tj = 0;"); + m_outstream.println("\t\t\twhile (i < yy_buffer_read) {"); + m_outstream.println("\t\t\t\tyy_buffer[j] = yy_buffer[i];"); + m_outstream.println("\t\t\t\t++i;"); + m_outstream.println("\t\t\t\t++j;"); + m_outstream.println("\t\t\t}"); + m_outstream.println("\t\t\tyy_buffer_end = yy_buffer_end - yy_buffer_start;"); + m_outstream.println("\t\t\tyy_buffer_start = 0;"); + m_outstream.println("\t\t\tyy_buffer_read = j;"); + m_outstream.println("\t\t\tyy_buffer_index = j;"); + m_outstream.println("\t\t\tnext_read = yy_reader.read(yy_buffer,"); + m_outstream.println("\t\t\t\t\tyy_buffer_read,"); + m_outstream.println("\t\t\t\t\tyy_buffer.length - yy_buffer_read);"); + m_outstream.println("\t\t\tif (-1 == next_read) {"); + m_outstream.println("\t\t\t\treturn YY_EOF;"); + m_outstream.println("\t\t\t}"); + m_outstream.println("\t\t\tyy_buffer_read = yy_buffer_read + next_read;"); + m_outstream.println("\t\t}"); + m_outstream.println(); + + m_outstream.println("\t\twhile (yy_buffer_index >= yy_buffer_read) {"); + m_outstream.println("\t\t\tif (yy_buffer_index >= yy_buffer.length) {"); + m_outstream.println("\t\t\t\tyy_buffer = yy_double(yy_buffer);"); + m_outstream.println("\t\t\t}"); + m_outstream.println("\t\t\tnext_read = yy_reader.read(yy_buffer,"); + m_outstream.println("\t\t\t\t\tyy_buffer_read,"); + m_outstream.println("\t\t\t\t\tyy_buffer.length - yy_buffer_read);"); + m_outstream.println("\t\t\tif (-1 == next_read) {"); + m_outstream.println("\t\t\t\treturn YY_EOF;"); + m_outstream.println("\t\t\t}"); + m_outstream.println("\t\t\tyy_buffer_read = yy_buffer_read + next_read;"); + m_outstream.println("\t\t}"); + + m_outstream.println("\t\treturn yy_buffer[yy_buffer_index++];"); + m_outstream.println("\t}"); + + /* Function: yy_move_end */ + m_outstream.println("\tprivate void yy_move_end () {"); + m_outstream.println("\t\tif (yy_buffer_end > yy_buffer_start &&"); + m_outstream.println("\t\t '\\n' == yy_buffer[yy_buffer_end-1])"); + m_outstream.println("\t\t\tyy_buffer_end--;"); + m_outstream.println("\t\tif (yy_buffer_end > yy_buffer_start &&"); + m_outstream.println("\t\t '\\r' == yy_buffer[yy_buffer_end-1])"); + m_outstream.println("\t\t\tyy_buffer_end--;"); + m_outstream.println("\t}"); + + /* Function: yy_mark_start */ + m_outstream.println("\tprivate boolean yy_last_was_cr=false;"); + m_outstream.println("\tprivate void yy_mark_start () {"); + if (m_spec.m_count_lines || true == m_spec.m_count_chars) + { + if (m_spec.m_count_lines) + { + m_outstream.println("\t\tint i;"); + m_outstream.println("\t\tfor (i = yy_buffer_start; " + + "i < yy_buffer_index; ++i) {"); + m_outstream.println("\t\t\tif ('\\n' == yy_buffer[i] && !yy_last_was_cr) {"); + m_outstream.println("\t\t\t\t++yyline;"); + m_outstream.println("\t\t\t}"); + m_outstream.println("\t\t\tif ('\\r' == yy_buffer[i]) {"); + m_outstream.println("\t\t\t\t++yyline;"); + m_outstream.println("\t\t\t\tyy_last_was_cr=true;"); + m_outstream.println("\t\t\t} else yy_last_was_cr=false;"); + m_outstream.println("\t\t}"); + } + if (m_spec.m_count_chars) + { + m_outstream.println("\t\tyychar = yychar"); + m_outstream.println("\t\t\t+ yy_buffer_index - yy_buffer_start;"); + } + } + m_outstream.println("\t\tyy_buffer_start = yy_buffer_index;"); + m_outstream.println("\t}"); + + /* Function: yy_mark_end */ + m_outstream.println("\tprivate void yy_mark_end () {"); + m_outstream.println("\t\tyy_buffer_end = yy_buffer_index;"); + m_outstream.println("\t}"); + + /* Function: yy_to_mark */ + m_outstream.println("\tprivate void yy_to_mark () {"); + m_outstream.println("\t\tyy_buffer_index = yy_buffer_end;"); + m_outstream.println("\t\tyy_at_bol = "+ + "(yy_buffer_end > yy_buffer_start) &&"); + m_outstream.println("\t\t "+ + "('\\r' == yy_buffer[yy_buffer_end-1] ||"); + m_outstream.println("\t\t "+ + " '\\n' == yy_buffer[yy_buffer_end-1] ||"); + m_outstream.println("\t\t "+ /* unicode LS */ + " 2028/*LS*/ == yy_buffer[yy_buffer_end-1] ||"); + m_outstream.println("\t\t "+ /* unicode PS */ + " 2029/*PS*/ == yy_buffer[yy_buffer_end-1]);"); + m_outstream.println("\t}"); + + /* Function: yytext */ + m_outstream.println("\tprivate java.lang.String yytext () {"); + m_outstream.println("\t\treturn (new java.lang.String(yy_buffer,"); + m_outstream.println("\t\t\tyy_buffer_start,"); + m_outstream.println("\t\t\tyy_buffer_end - yy_buffer_start));"); + m_outstream.println("\t}"); + + /* Function: yylength */ + m_outstream.println("\tprivate int yylength () {"); + m_outstream.println("\t\treturn yy_buffer_end - yy_buffer_start;"); + m_outstream.println("\t}"); + + /* Function: yy_double */ + m_outstream.println("\tprivate char[] yy_double (char buf[]) {"); + m_outstream.println("\t\tint i;"); + m_outstream.println("\t\tchar newbuf[];"); + m_outstream.println("\t\tnewbuf = new char[2*buf.length];"); + m_outstream.println("\t\tfor (i = 0; i < buf.length; ++i) {"); + m_outstream.println("\t\t\tnewbuf[i] = buf[i];"); + m_outstream.println("\t\t}"); + m_outstream.println("\t\treturn newbuf;"); + m_outstream.println("\t}"); + + /* Function: yy_error */ + m_outstream.println("\tprivate final int YY_E_INTERNAL = 0;"); + m_outstream.println("\tprivate final int YY_E_MATCH = 1;"); + m_outstream.println("\tprivate java.lang.String yy_error_string[] = {"); + m_outstream.println("\t\t\"Error: Internal error.\\n\","); + m_outstream.println("\t\t\"Error: Unmatched input.\\n\""); + m_outstream.println("\t};"); + m_outstream.println("\tprivate void yy_error (int code,boolean fatal) {"); + m_outstream.println("\t\tjava.lang.System.out.print(yy_error_string[code]);"); + m_outstream.println("\t\tjava.lang.System.out.flush();"); + m_outstream.println("\t\tif (fatal) {"); + m_outstream.println("\t\t\tthrow new Error(\"Fatal Error.\\n\");"); + m_outstream.println("\t\t}"); + m_outstream.println("\t}"); + + /* Function: yy_next */ + /*m_outstream.println("\tprivate int yy_next (int current,char lookahead) {"); + m_outstream.println("\t\treturn yy_nxt[yy_rmap[current]][yy_cmap[lookahead]];"); + m_outstream.println("\t}");*/ + + /* Function: yy_accept */ + /*m_outstream.println("\tprivate int yy_accept (int current) {"); + m_outstream.println("\t\treturn yy_acpt[current];"); + m_outstream.println("\t}");*/ + + + // Function: private int [][] unpackFromString(int size1, int size2, String st) + // Added 6/24/98 Raimondas Lencevicius + // May be made more efficient by replacing String operations + // Assumes correctly formed input String. Performs no error checking + m_outstream.println("\tprivate int[][] unpackFromString"+ + "(int size1, int size2, String st) {"); + m_outstream.println("\t\tint colonIndex = -1;"); + m_outstream.println("\t\tString lengthString;"); + m_outstream.println("\t\tint sequenceLength = 0;"); + m_outstream.println("\t\tint sequenceInteger = 0;"); + m_outstream.println(); + m_outstream.println("\t\tint commaIndex;"); + m_outstream.println("\t\tString workString;"); + m_outstream.println(); + m_outstream.println("\t\tint res[][] = new int[size1][size2];"); + m_outstream.println("\t\tfor (int i= 0; i < size1; i++) {"); + m_outstream.println("\t\t\tfor (int j= 0; j < size2; j++) {"); + m_outstream.println("\t\t\t\tif (sequenceLength != 0) {"); + m_outstream.println("\t\t\t\t\tres[i][j] = sequenceInteger;"); + m_outstream.println("\t\t\t\t\tsequenceLength--;"); + m_outstream.println("\t\t\t\t\tcontinue;"); + m_outstream.println("\t\t\t\t}"); + m_outstream.println("\t\t\t\tcommaIndex = st.indexOf(',');"); + m_outstream.println("\t\t\t\tworkString = (commaIndex==-1) ? st :"); + m_outstream.println("\t\t\t\t\tst.substring(0, commaIndex);"); + m_outstream.println("\t\t\t\tst = st.substring(commaIndex+1);"); + m_outstream.println("\t\t\t\tcolonIndex = workString.indexOf(':');"); + m_outstream.println("\t\t\t\tif (colonIndex == -1) {"); + m_outstream.println("\t\t\t\t\tres[i][j]=Integer.parseInt(workString);"); + m_outstream.println("\t\t\t\t\tcontinue;"); + m_outstream.println("\t\t\t\t}"); + m_outstream.println("\t\t\t\tlengthString ="); + m_outstream.println("\t\t\t\t\tworkString.substring(colonIndex+1);"); + m_outstream.println("\t\t\t\tsequenceLength="+ + "Integer.parseInt(lengthString);"); + m_outstream.println("\t\t\t\tworkString="+ + "workString.substring(0,colonIndex);"); + m_outstream.println("\t\t\t\tsequenceInteger="+ + "Integer.parseInt(workString);"); + m_outstream.println("\t\t\t\tres[i][j] = sequenceInteger;"); + m_outstream.println("\t\t\t\tsequenceLength--;"); + m_outstream.println("\t\t\t}"); + m_outstream.println("\t\t}"); + m_outstream.println("\t\treturn res;"); + m_outstream.println("\t}"); + } + + /*************************************************************** + Function: emit_header + Description: Emits class header. + **************************************************************/ + private void emit_header + ( + ) + throws java.io.IOException + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != m_spec); + CUtility.ASSERT(null != m_outstream); + } + + m_outstream.println(); + m_outstream.println(); + if (true == m_spec.m_public) { + m_outstream.print("public "); + } + m_outstream.print("class "); + m_outstream.print(new String(m_spec.m_class_name,0, + m_spec.m_class_name.length)); + if (m_spec.m_implements_name.length > 0) { + m_outstream.print(" implements "); + m_outstream.print(new String(m_spec.m_implements_name,0, + m_spec.m_implements_name.length)); + } + m_outstream.println(" {"); + } + + /*************************************************************** + Function: emit_table + Description: Emits transition table. + **************************************************************/ + private void emit_table + ( + ) + throws java.io.IOException + { + int i; + int elem; + int size; + CDTrans dtrans; + boolean is_start; + boolean is_end; + CAccept accept; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != m_spec); + CUtility.ASSERT(null != m_outstream); + } + + m_outstream.println("\tprivate int yy_acpt[] = {"); + size = m_spec.m_accept_vector.size(); + for (elem = 0; elem < size; ++elem) + { + accept = (CAccept) m_spec.m_accept_vector.elementAt(elem); + + m_outstream.print("\t\t/* "+elem+" */ "); + if (null != accept) + { + is_start = (0 != (m_spec.m_anchor_array[elem] & CSpec.START)); + is_end = (0 != (m_spec.m_anchor_array[elem] & CSpec.END)); + + if (is_start && true == is_end) + { + m_outstream.print("YY_START | YY_END"); + } + else if (is_start) + { + m_outstream.print("YY_START"); + } + else if (is_end) + { + m_outstream.print("YY_END"); + } + else + { + m_outstream.print("YY_NO_ANCHOR"); + } + } + else + { + m_outstream.print("YY_NOT_ACCEPT"); + } + + if (elem < size - 1) + { + m_outstream.print(","); + } + + m_outstream.println(); + } + m_outstream.println("\t};"); + + // CSA: modified yy_cmap to use string packing 9-Aug-1999 + int[] yy_cmap = new int[m_spec.m_ccls_map.length]; + for (i = 0; i < m_spec.m_ccls_map.length; ++i) + yy_cmap[i] = m_spec.m_col_map[m_spec.m_ccls_map[i]]; + m_outstream.print("\tprivate int yy_cmap[] = unpackFromString("); + emit_table_as_string(new int[][] { yy_cmap }); + m_outstream.println(")[0];"); + m_outstream.println(); + + // CSA: modified yy_rmap to use string packing 9-Aug-1999 + m_outstream.print("\tprivate int yy_rmap[] = unpackFromString("); + emit_table_as_string(new int[][] { m_spec.m_row_map }); + m_outstream.println(")[0];"); + m_outstream.println(); + + // 6/24/98 Raimondas Lencevicius + // modified to use + // int[][] unpackFromString(int size1, int size2, String st) + size = m_spec.m_dtrans_vector.size(); + int[][] yy_nxt = new int[size][]; + for (elem=0; elem<size; elem++) { + dtrans = (CDTrans) m_spec.m_dtrans_vector.elementAt(elem); + CUtility.ASSERT(dtrans.m_dtrans.length==m_spec.m_dtrans_ncols); + yy_nxt[elem] = dtrans.m_dtrans; + } + m_outstream.print + ("\tprivate int yy_nxt[][] = unpackFromString("); + emit_table_as_string(yy_nxt); + m_outstream.println(");"); + m_outstream.println(); + } + + /*************************************************************** + Function: emit_driver + Description: Output an integer table as a string. Written by + Raimondas Lencevicius 6/24/98; reorganized by CSA 9-Aug-1999. + From his original comments: + yy_nxt[][] values are coded into a string + by printing integers and representing + integer sequences as "value:length" pairs. + **************************************************************/ + private void emit_table_as_string(int[][] ia) { + int sequenceLength = 0; // RL - length of the number sequence + boolean sequenceStarted = false; // RL - has number sequence started? + int previousInt = -20; // RL - Bogus -20 state. + + // RL - Output matrix size + m_outstream.print(ia.length); + m_outstream.print(","); + m_outstream.print(ia.length>0?ia[0].length:0); + m_outstream.println(","); + + StringBuffer outstr = new StringBuffer(); + + // RL - Output matrix + for (int elem = 0; elem < ia.length; ++elem) + { + for (int i = 0; i < ia[elem].length; ++i) + { + int writeInt = ia[elem][i]; + if (writeInt == previousInt) // RL - sequence? + { + if (sequenceStarted) + { + sequenceLength++; + } + else + { + outstr.append(writeInt); + outstr.append(":"); + sequenceLength = 2; + sequenceStarted = true; + } + } + else // RL - no sequence or end sequence + { + if (sequenceStarted) + { + outstr.append(sequenceLength); + outstr.append(","); + sequenceLength = 0; + sequenceStarted = false; + } + else + { + if (previousInt != -20) + { + outstr.append(previousInt); + outstr.append(","); + } + } + } + previousInt = writeInt; + // CSA: output in 75 character chunks. + if (outstr.length() > 75) { + String s = outstr.toString(); + m_outstream.println("\""+s.substring(0,75)+"\" +"); + outstr = new StringBuffer(s.substring(75)); + } + } + } + if (sequenceStarted) + { + outstr.append(sequenceLength); + } + else + { + outstr.append(previousInt); + } + // CSA: output in 75 character chunks. + if (outstr.length() > 75) { + String s = outstr.toString(); + m_outstream.println("\""+s.substring(0,75)+"\" +"); + outstr = new StringBuffer(s.substring(75)); + } + m_outstream.print("\""+outstr+"\""); + } + + /*************************************************************** + Function: emit_driver + Description: + **************************************************************/ + private void emit_driver + ( + ) + throws java.io.IOException + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != m_spec); + CUtility.ASSERT(null != m_outstream); + } + + emit_table(); + + if (m_spec.m_integer_type) + { + m_outstream.print("\tpublic int "); + m_outstream.print(new String(m_spec.m_function_name)); + m_outstream.println(" ()"); + } + else if (m_spec.m_intwrap_type) + { + m_outstream.print("\tpublic java.lang.Integer "); + m_outstream.print(new String(m_spec.m_function_name)); + m_outstream.println(" ()"); + } + else + { + m_outstream.print("\tpublic "); + m_outstream.print(new String(m_spec.m_type_name)); + m_outstream.print(" "); + m_outstream.print(new String(m_spec.m_function_name)); + m_outstream.println(" ()"); + } + + /*m_outstream.println("\t\tthrows java.io.IOException {");*/ + m_outstream.print("\t\tthrows java.io.IOException"); + if (null != m_spec.m_yylex_throw_code) + { + m_outstream.print(", "); + m_outstream.print(new String(m_spec.m_yylex_throw_code,0, + m_spec.m_yylex_throw_read)); + m_outstream.println(); + m_outstream.println("\t\t{"); + } + else + { + m_outstream.println(" {"); + } + + m_outstream.println("\t\tint yy_lookahead;"); + m_outstream.println("\t\tint yy_anchor = YY_NO_ANCHOR;"); + /*m_outstream.println("\t\tint yy_state " + + "= yy_initial_dtrans(yy_lexical_state);");*/ + m_outstream.println("\t\tint yy_state " + + "= yy_state_dtrans[yy_lexical_state];"); + m_outstream.println("\t\tint yy_next_state = YY_NO_STATE;"); + /*m_outstream.println("\t\tint yy_prev_stave = YY_NO_STATE;");*/ + m_outstream.println("\t\tint yy_last_accept_state = YY_NO_STATE;"); + m_outstream.println("\t\tboolean yy_initial = true;"); + m_outstream.println("\t\tint yy_this_accept;"); + m_outstream.println(); + + m_outstream.println("\t\tyy_mark_start();"); + /*m_outstream.println("\t\tyy_this_accept = yy_accept(yy_state);");*/ + m_outstream.println("\t\tyy_this_accept = yy_acpt[yy_state];"); + m_outstream.println("\t\tif (YY_NOT_ACCEPT != yy_this_accept) {"); + m_outstream.println("\t\t\tyy_last_accept_state = yy_state;"); + m_outstream.println("\t\t\tyy_mark_end();"); + m_outstream.println("\t\t}"); + + if (NOT_EDBG) + { + m_outstream.println("\t\tjava.lang.System.out.println(\"Begin\");"); + } + + m_outstream.println("\t\twhile (true) {"); + + m_outstream.println("\t\t\tif (yy_initial && yy_at_bol) "+ + "yy_lookahead = YY_BOL;"); + m_outstream.println("\t\t\telse yy_lookahead = yy_advance();"); + m_outstream.println("\t\t\tyy_next_state = YY_F;"); + /*m_outstream.println("\t\t\t\tyy_next_state = " + + "yy_next(yy_state,yy_lookahead);");*/ + m_outstream.println("\t\t\tyy_next_state = " + + "yy_nxt[yy_rmap[yy_state]][yy_cmap[yy_lookahead]];"); + + if (NOT_EDBG) + { + m_outstream.println("java.lang.System.out.println(\"Current state: \"" + + " + yy_state"); + m_outstream.println("+ \"\tCurrent input: \""); + m_outstream.println(" + ((char) yy_lookahead));"); + } + if (NOT_EDBG) + { + m_outstream.println("\t\t\tjava.lang.System.out.println(\"State = \"" + + "+ yy_state);"); + m_outstream.println("\t\t\tjava.lang.System.out.println(\"Accepting status = \"" + + "+ yy_this_accept);"); + m_outstream.println("\t\t\tjava.lang.System.out.println(\"Last accepting state = \"" + + "+ yy_last_accept_state);"); + m_outstream.println("\t\t\tjava.lang.System.out.println(\"Next state = \"" + + "+ yy_next_state);"); + m_outstream.println("\t\t\tjava.lang.System.out.println(\"Lookahead input = \"" + + "+ ((char) yy_lookahead));"); + } + + // handle bare EOF. + m_outstream.println("\t\t\tif (YY_EOF == yy_lookahead " + + "&& true == yy_initial) {"); + if (null != m_spec.m_eof_code) + { + m_outstream.println("\t\t\t\tyy_do_eof();"); + } + if (true == m_spec.m_integer_type) + { + m_outstream.println("\t\t\t\treturn YYEOF;"); + } + else if (null != m_spec.m_eof_value_code) + { + m_outstream.print(new String(m_spec.m_eof_value_code,0, + m_spec.m_eof_value_read)); + } + else + { + m_outstream.println("\t\t\t\treturn null;"); + } + m_outstream.println("\t\t\t}"); + + m_outstream.println("\t\t\tif (YY_F != yy_next_state) {"); + m_outstream.println("\t\t\t\tyy_state = yy_next_state;"); + m_outstream.println("\t\t\t\tyy_initial = false;"); + /*m_outstream.println("\t\t\t\tyy_this_accept = yy_accept(yy_state);");*/ + m_outstream.println("\t\t\t\tyy_this_accept = yy_acpt[yy_state];"); + m_outstream.println("\t\t\t\tif (YY_NOT_ACCEPT != yy_this_accept) {"); + m_outstream.println("\t\t\t\t\tyy_last_accept_state = yy_state;"); + m_outstream.println("\t\t\t\t\tyy_mark_end();"); + m_outstream.println("\t\t\t\t}"); + /*m_outstream.println("\t\t\t\tyy_prev_state = yy_state;");*/ + /*m_outstream.println("\t\t\t\tyy_state = yy_next_state;");*/ + m_outstream.println("\t\t\t}"); + + m_outstream.println("\t\t\telse {"); + + m_outstream.println("\t\t\t\tif (YY_NO_STATE == yy_last_accept_state) {"); + + + /*m_outstream.println("\t\t\t\t\tyy_error(YY_E_MATCH,false);"); + m_outstream.println("\t\t\t\t\tyy_initial = true;"); + m_outstream.println("\t\t\t\t\tyy_state " + + "= yy_state_dtrans[yy_lexical_state];"); + m_outstream.println("\t\t\t\t\tyy_next_state = YY_NO_STATE;");*/ + /*m_outstream.println("\t\t\t\t\tyy_prev_state = YY_NO_STATE;");*/ + /*m_outstream.println("\t\t\t\t\tyy_last_accept_state = YY_NO_STATE;"); + m_outstream.println("\t\t\t\t\tyy_mark_start();");*/ + /*m_outstream.println("\t\t\t\t\tyy_this_accept = yy_accept(yy_state);");*/ + /*m_outstream.println("\t\t\t\t\tyy_this_accept = yy_acpt[yy_state];"); + m_outstream.println("\t\t\t\t\tif (YY_NOT_ACCEPT != yy_this_accept) {"); + m_outstream.println("\t\t\t\t\t\tyy_last_accept_state = yy_state;"); + m_outstream.println("\t\t\t\t\t}");*/ + + m_outstream.println("\t\t\t\t\tthrow (new Error(\"Lexical Error: Unmatched Input.\"));"); + m_outstream.println("\t\t\t\t}"); + + m_outstream.println("\t\t\t\telse {"); + + m_outstream.println("\t\t\t\t\tyy_anchor = yy_acpt[yy_last_accept_state];"); + /*m_outstream.println("\t\t\t\t\tyy_anchor " + + "= yy_accept(yy_last_accept_state);");*/ + m_outstream.println("\t\t\t\t\tif (0 != (YY_END & yy_anchor)) {"); + m_outstream.println("\t\t\t\t\t\tyy_move_end();"); + m_outstream.println("\t\t\t\t\t}"); + m_outstream.println("\t\t\t\t\tyy_to_mark();"); + + m_outstream.println("\t\t\t\t\tswitch (yy_last_accept_state) {"); + + emit_actions("\t\t\t\t\t"); + + m_outstream.println("\t\t\t\t\tdefault:"); + m_outstream.println("\t\t\t\t\t\tyy_error(YY_E_INTERNAL,false);"); + /*m_outstream.println("\t\t\t\t\t\treturn null;");*/ + m_outstream.println("\t\t\t\t\tcase -1:"); + m_outstream.println("\t\t\t\t\t}"); + + m_outstream.println("\t\t\t\t\tyy_initial = true;"); + m_outstream.println("\t\t\t\t\tyy_state " + + "= yy_state_dtrans[yy_lexical_state];"); + m_outstream.println("\t\t\t\t\tyy_next_state = YY_NO_STATE;"); + /*m_outstream.println("\t\t\t\t\tyy_prev_state = YY_NO_STATE;");*/ + m_outstream.println("\t\t\t\t\tyy_last_accept_state = YY_NO_STATE;"); + + m_outstream.println("\t\t\t\t\tyy_mark_start();"); + + /*m_outstream.println("\t\t\t\t\tyy_this_accept = yy_accept(yy_state);");*/ + m_outstream.println("\t\t\t\t\tyy_this_accept = yy_acpt[yy_state];"); + m_outstream.println("\t\t\t\t\tif (YY_NOT_ACCEPT != yy_this_accept) {"); + m_outstream.println("\t\t\t\t\t\tyy_last_accept_state = yy_state;"); + m_outstream.println("\t\t\t\t\t\tyy_mark_end();"); + m_outstream.println("\t\t\t\t\t}"); + + m_outstream.println("\t\t\t\t}"); + m_outstream.println("\t\t\t}"); + m_outstream.println("\t\t}"); + m_outstream.println("\t}"); + + /*m_outstream.println("\t\t\t\t"); + m_outstream.println("\t\t\t"); + m_outstream.println("\t\t\t"); + m_outstream.println("\t\t\t"); + m_outstream.println("\t\t\t"); + m_outstream.println("\t\t}");*/ + } + + /*************************************************************** + Function: emit_actions + Description: + **************************************************************/ + private void emit_actions + ( + String tabs + ) + throws java.io.IOException + { + int elem; + int size; + int bogus_index; + CAccept accept; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(m_spec.m_accept_vector.size() + == m_spec.m_anchor_array.length); + } + + bogus_index = -2; + size = m_spec.m_accept_vector.size(); + for (elem = 0; elem < size; ++elem) + { + accept = (CAccept) m_spec.m_accept_vector.elementAt(elem); + if (null != accept) + { + m_outstream.println(tabs + "case " + elem + + ":"); + m_outstream.print(tabs + "\t"); + m_outstream.print(new String(accept.m_action,0, + accept.m_action_read)); + m_outstream.println(); + m_outstream.println(tabs + "case " + bogus_index + ":"); + m_outstream.println(tabs + "\tbreak;"); + --bogus_index; + } + } + } + + /*************************************************************** + Function: emit_footer + Description: + **************************************************************/ + private void emit_footer + ( + ) + throws java.io.IOException + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != m_spec); + CUtility.ASSERT(null != m_outstream); + } + + m_outstream.println("}"); + } +} + +/*************************************************************** + Class: CBunch + **************************************************************/ +class CBunch +{ + /*************************************************************** + Member Variables + **************************************************************/ + Vector m_nfa_set; /* Vector of CNfa states in dfa state. */ + SparseBitSet m_nfa_bit; /* BitSet representation of CNfa labels. */ + CAccept m_accept; /* Accepting actions, or null if nonaccepting state. */ + int m_anchor; /* Anchors on regular expression. */ + int m_accept_index; /* CNfa index corresponding to accepting actions. */ + + /*************************************************************** + Function: CBunch + Description: Constructor. + **************************************************************/ + CBunch + ( + ) + { + m_nfa_set = null; + m_nfa_bit = null; + m_accept = null; + m_anchor = CSpec.NONE; + m_accept_index = -1; + } +} + +/*************************************************************** + Class: CMakeNfa + **************************************************************/ +class CMakeNfa +{ + /*************************************************************** + Member Variables + **************************************************************/ + private CSpec m_spec; + private CLexGen m_lexGen; + private CInput m_input; + + /*************************************************************** + Function: CMakeNfa + Description: Constructor. + **************************************************************/ + CMakeNfa + ( + ) + { + reset(); + } + + /*************************************************************** + Function: reset + Description: Resets CMakeNfa member variables. + **************************************************************/ + private void reset + ( + ) + { + m_input = null; + m_lexGen = null; + m_spec = null; + } + + /*************************************************************** + Function: set + Description: Sets CMakeNfa member variables. + **************************************************************/ + private void set + ( + CLexGen lexGen, + CSpec spec, + CInput input + ) + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != input); + CUtility.ASSERT(null != lexGen); + CUtility.ASSERT(null != spec); + } + + m_input = input; + m_lexGen = lexGen; + m_spec = spec; + } + + /*************************************************************** + Function: allocate_BOL_EOF + Description: Expands character class to include special BOL and + EOF characters. Puts numeric index of these characters in + input CSpec. + **************************************************************/ + void allocate_BOL_EOF + ( + CSpec spec + ) + { + CUtility.ASSERT(CSpec.NUM_PSEUDO==2); + spec.BOL = spec.m_dtrans_ncols++; + spec.EOF = spec.m_dtrans_ncols++; + } + + /*************************************************************** + Function: thompson + Description: High level access function to module. + Deposits result in input CSpec. + **************************************************************/ + void thompson + ( + CLexGen lexGen, + CSpec spec, + CInput input + ) + throws java.io.IOException + { + int i; + CNfa elem; + int size; + + /* Set member variables. */ + reset(); + set(lexGen,spec,input); + + size = m_spec.m_states.size(); + m_spec.m_state_rules = new Vector[size]; + for (i = 0; i < size; ++i) + { + m_spec.m_state_rules[i] = new Vector(); + } + + /* Initialize current token variable + and create nfa. */ + /*m_spec.m_current_token = m_lexGen.EOS; + m_lexGen.advance();*/ + + m_spec.m_nfa_start = machine(); + + /* Set labels in created nfa machine. */ + size = m_spec.m_nfa_states.size(); + for (i = 0; i < size; ++i) + { + elem = (CNfa) m_spec.m_nfa_states.elementAt(i); + elem.m_label = i; + } + + /* Debugging output. */ + if (CUtility.DO_DEBUG) + { + m_lexGen.print_nfa(); + } + + if (m_spec.m_verbose) + { + System.out.println("NFA comprised of " + + (m_spec.m_nfa_states.size() + 1) + + " states."); + } + + reset(); + } + + /*************************************************************** + Function: discardCNfa + Description: + **************************************************************/ + private void discardCNfa + ( + CNfa nfa + ) + { + m_spec.m_nfa_states.removeElement(nfa); + } + + /*************************************************************** + Function: processStates + Description: + **************************************************************/ + private void processStates + ( + SparseBitSet states, + CNfa current + ) + { + int size; + int i; + + size = m_spec.m_states.size(); + for (i = 0; i < size; ++i) + { + if (states.get(i)) + { + m_spec.m_state_rules[i].addElement(current); + } + } + } + + /*************************************************************** + Function: machine + Description: Recursive descent regular expression parser. + **************************************************************/ + private CNfa machine + ( + ) + throws java.io.IOException + { + CNfa start; + CNfa p; + SparseBitSet states; + + if (CUtility.DESCENT_DEBUG) + { + CUtility.enter("machine",m_spec.m_lexeme,m_spec.m_current_token); + } + + start = CAlloc.newCNfa(m_spec); + p = start; + + states = m_lexGen.getStates(); + + /* Begin: Added for states. */ + m_spec.m_current_token = m_lexGen.EOS; + m_lexGen.advance(); + /* End: Added for states. */ + + if (m_lexGen.END_OF_INPUT != m_spec.m_current_token) // CSA fix. + { + p.m_next = rule(); + + processStates(states,p.m_next); + } + + while (m_lexGen.END_OF_INPUT != m_spec.m_current_token) + { + /* Make state changes HERE. */ + states = m_lexGen.getStates(); + + /* Begin: Added for states. */ + m_lexGen.advance(); + if (m_lexGen.END_OF_INPUT == m_spec.m_current_token) + { + break; + } + /* End: Added for states. */ + + p.m_next2 = CAlloc.newCNfa(m_spec); + p = p.m_next2; + p.m_next = rule(); + + processStates(states,p.m_next); + } + + // CSA: add pseudo-rules for BOL and EOF + SparseBitSet all_states = new SparseBitSet(); + for (int i = 0; i < m_spec.m_states.size(); ++i) + all_states.set(i); + p.m_next2 = CAlloc.newCNfa(m_spec); + p = p.m_next2; + p.m_next = CAlloc.newCNfa(m_spec); + p.m_next.m_edge = CNfa.CCL; + p.m_next.m_next = CAlloc.newCNfa(m_spec); + p.m_next.m_set = new CSet(); + p.m_next.m_set.add(m_spec.BOL); + p.m_next.m_set.add(m_spec.EOF); + p.m_next.m_next.m_accept = // do-nothing accept rule + new CAccept(new char[0], 0, m_input.m_line_number+1); + processStates(all_states,p.m_next); + // CSA: done. + + if (CUtility.DESCENT_DEBUG) + { + CUtility.leave("machine",m_spec.m_lexeme,m_spec.m_current_token); + } + + return start; + } + + /*************************************************************** + Function: rule + Description: Recursive descent regular expression parser. + **************************************************************/ + private CNfa rule + ( + ) + throws java.io.IOException + { + CNfaPair pair; + CNfa p; + CNfa start = null; + CNfa end = null; + int anchor = CSpec.NONE; + + if (CUtility.DESCENT_DEBUG) + { + CUtility.enter("rule",m_spec.m_lexeme,m_spec.m_current_token); + } + + pair = CAlloc.newCNfaPair(); + + if (m_lexGen.AT_BOL == m_spec.m_current_token) + { + anchor = anchor | CSpec.START; + m_lexGen.advance(); + expr(pair); + + // CSA: fixed beginning-of-line operator. 8-aug-1999 + start = CAlloc.newCNfa(m_spec); + start.m_edge = m_spec.BOL; + start.m_next = pair.m_start; + end = pair.m_end; + } + else + { + expr(pair); + start = pair.m_start; + end = pair.m_end; + } + + if (m_lexGen.AT_EOL == m_spec.m_current_token) + { + m_lexGen.advance(); + // CSA: fixed end-of-line operator. 8-aug-1999 + CNfaPair nlpair = CAlloc.newNLPair(m_spec); + end.m_next = CAlloc.newCNfa(m_spec); + end.m_next.m_next = nlpair.m_start; + end.m_next.m_next2 = CAlloc.newCNfa(m_spec); + end.m_next.m_next2.m_edge = m_spec.EOF; + end.m_next.m_next2.m_next = nlpair.m_end; + end = nlpair.m_end; + anchor = anchor | CSpec.END; + } + + /* Check for null rules. Charles Fischer found this bug. [CSA] */ + if (end==null) + CError.parse_error(CError.E_ZERO, m_input.m_line_number); + + /* Handle end of regular expression. See page 103. */ + end.m_accept = m_lexGen.packAccept(); + end.m_anchor = anchor; + + /* Begin: Removed for states. */ + /*m_lexGen.advance();*/ + /* End: Removed for states. */ + + if (CUtility.DESCENT_DEBUG) + { + CUtility.leave("rule",m_spec.m_lexeme,m_spec.m_current_token); + } + + return start; + } + + /*************************************************************** + Function: expr + Description: Recursive descent regular expression parser. + **************************************************************/ + private void expr + ( + CNfaPair pair + ) + throws java.io.IOException + { + CNfaPair e2_pair; + CNfa p; + + if (CUtility.DESCENT_DEBUG) + { + CUtility.enter("expr",m_spec.m_lexeme,m_spec.m_current_token); + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != pair); + } + + e2_pair = CAlloc.newCNfaPair(); + + cat_expr(pair); + + while (m_lexGen.OR == m_spec.m_current_token) + { + m_lexGen.advance(); + cat_expr(e2_pair); + + p = CAlloc.newCNfa(m_spec); + p.m_next2 = e2_pair.m_start; + p.m_next = pair.m_start; + pair.m_start = p; + + p = CAlloc.newCNfa(m_spec); + pair.m_end.m_next = p; + e2_pair.m_end.m_next = p; + pair.m_end = p; + } + + if (CUtility.DESCENT_DEBUG) + { + CUtility.leave("expr",m_spec.m_lexeme,m_spec.m_current_token); + } + } + + /*************************************************************** + Function: cat_expr + Description: Recursive descent regular expression parser. + **************************************************************/ + private void cat_expr + ( + CNfaPair pair + ) + throws java.io.IOException + { + CNfaPair e2_pair; + + if (CUtility.DESCENT_DEBUG) + { + CUtility.enter("cat_expr",m_spec.m_lexeme,m_spec.m_current_token); + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != pair); + } + + e2_pair = CAlloc.newCNfaPair(); + + if (first_in_cat(m_spec.m_current_token)) + { + factor(pair); + } + + while (first_in_cat(m_spec.m_current_token)) + { + factor(e2_pair); + + /* Destroy */ + pair.m_end.mimic(e2_pair.m_start); + discardCNfa(e2_pair.m_start); + + pair.m_end = e2_pair.m_end; + } + + if (CUtility.DESCENT_DEBUG) + { + CUtility.leave("cat_expr",m_spec.m_lexeme,m_spec.m_current_token); + } + } + + /*************************************************************** + Function: first_in_cat + Description: Recursive descent regular expression parser. + **************************************************************/ + private boolean first_in_cat + ( + int token + ) + { + switch (token) + { + case CLexGen.CLOSE_PAREN: + case CLexGen.AT_EOL: + case CLexGen.OR: + case CLexGen.EOS: + return false; + + case CLexGen.CLOSURE: + case CLexGen.PLUS_CLOSE: + case CLexGen.OPTIONAL: + CError.parse_error(CError.E_CLOSE,m_input.m_line_number); + return false; + + case CLexGen.CCL_END: + CError.parse_error(CError.E_BRACKET,m_input.m_line_number); + return false; + + case CLexGen.AT_BOL: + CError.parse_error(CError.E_BOL,m_input.m_line_number); + return false; + + default: + break; + } + + return true; + } + + /*************************************************************** + Function: factor + Description: Recursive descent regular expression parser. + **************************************************************/ + private void factor + ( + CNfaPair pair + ) + throws java.io.IOException + { + CNfa start = null; + CNfa end = null; + + if (CUtility.DESCENT_DEBUG) + { + CUtility.enter("factor",m_spec.m_lexeme,m_spec.m_current_token); + } + + term(pair); + + if (m_lexGen.CLOSURE == m_spec.m_current_token + || m_lexGen.PLUS_CLOSE == m_spec.m_current_token + || m_lexGen.OPTIONAL == m_spec.m_current_token) + { + start = CAlloc.newCNfa(m_spec); + end = CAlloc.newCNfa(m_spec); + + start.m_next = pair.m_start; + pair.m_end.m_next = end; + + if (m_lexGen.CLOSURE == m_spec.m_current_token + || m_lexGen.OPTIONAL == m_spec.m_current_token) + { + start.m_next2 = end; + } + + if (m_lexGen.CLOSURE == m_spec.m_current_token + || m_lexGen.PLUS_CLOSE == m_spec.m_current_token) + { + pair.m_end.m_next2 = pair.m_start; + } + + pair.m_start = start; + pair.m_end = end; + m_lexGen.advance(); + } + + if (CUtility.DESCENT_DEBUG) + { + CUtility.leave("factor",m_spec.m_lexeme,m_spec.m_current_token); + } + } + + /*************************************************************** + Function: term + Description: Recursive descent regular expression parser. + **************************************************************/ + private void term + ( + CNfaPair pair + ) + throws java.io.IOException + { + CNfa start; + boolean isAlphaL; + int c; + + if (CUtility.DESCENT_DEBUG) + { + CUtility.enter("term",m_spec.m_lexeme,m_spec.m_current_token); + } + + if (m_lexGen.OPEN_PAREN == m_spec.m_current_token) + { + m_lexGen.advance(); + expr(pair); + + if (m_lexGen.CLOSE_PAREN == m_spec.m_current_token) + { + m_lexGen.advance(); + } + else + { + CError.parse_error(CError.E_SYNTAX,m_input.m_line_number); + } + } + else + { + start = CAlloc.newCNfa(m_spec); + pair.m_start = start; + + start.m_next = CAlloc.newCNfa(m_spec); + pair.m_end = start.m_next; + + if (m_lexGen.L == m_spec.m_current_token && + Character.isLetter(m_spec.m_lexeme)) + { + isAlphaL = true; + } + else + { + isAlphaL = false; + } + if (false == (m_lexGen.ANY == m_spec.m_current_token + || m_lexGen.CCL_START == m_spec.m_current_token + || (m_spec.m_ignorecase && isAlphaL))) + { + start.m_edge = m_spec.m_lexeme; + m_lexGen.advance(); + } + else + { + start.m_edge = CNfa.CCL; + + start.m_set = new CSet(); + + /* Match case-insensitive letters using character class. */ + if (m_spec.m_ignorecase && isAlphaL) + { + start.m_set.addncase(m_spec.m_lexeme); + } + /* Match dot (.) using character class. */ + else if (m_lexGen.ANY == m_spec.m_current_token) + { + start.m_set.add('\n'); + start.m_set.add('\r'); + // CSA: exclude BOL and EOF from character classes + start.m_set.add(m_spec.BOL); + start.m_set.add(m_spec.EOF); + start.m_set.complement(); + } + else + { + m_lexGen.advance(); + if (m_lexGen.AT_BOL == m_spec.m_current_token) + { + m_lexGen.advance(); + + // CSA: exclude BOL and EOF from character classes + start.m_set.add(m_spec.BOL); + start.m_set.add(m_spec.EOF); + start.m_set.complement(); + } + if (false == (m_lexGen.CCL_END == m_spec.m_current_token)) + { + dodash(start.m_set); + } + /*else + { + for (c = 0; c <= ' '; ++c) + { + start.m_set.add((byte) c); + } + }*/ + } + m_lexGen.advance(); + } + } + + if (CUtility.DESCENT_DEBUG) + { + CUtility.leave("term",m_spec.m_lexeme,m_spec.m_current_token); + } + } + + /*************************************************************** + Function: dodash + Description: Recursive descent regular expression parser. + **************************************************************/ + private void dodash + ( + CSet set + ) + throws java.io.IOException + { + int first = -1; + + if (CUtility.DESCENT_DEBUG) + { + CUtility.enter("dodash",m_spec.m_lexeme,m_spec.m_current_token); + } + + while (m_lexGen.EOS != m_spec.m_current_token + && m_lexGen.CCL_END != m_spec.m_current_token) + { + // DASH loses its special meaning if it is first in class. + if (m_lexGen.DASH == m_spec.m_current_token && -1 != first) + { + m_lexGen.advance(); + // DASH loses its special meaning if it is last in class. + if (m_spec.m_current_token == m_lexGen.CCL_END) + { + // 'first' already in set. + set.add('-'); + break; + } + for ( ; first <= m_spec.m_lexeme; ++first) + { + if (m_spec.m_ignorecase) + set.addncase((char)first); + else + set.add(first); + } + } + else + { + first = m_spec.m_lexeme; + if (m_spec.m_ignorecase) + set.addncase(m_spec.m_lexeme); + else + set.add(m_spec.m_lexeme); + } + + m_lexGen.advance(); + } + + if (CUtility.DESCENT_DEBUG) + { + CUtility.leave("dodash",m_spec.m_lexeme,m_spec.m_current_token); + } + } +} + +/** + * Extract character classes from NFA and simplify. + * @author C. Scott Ananian 25-Jul-1999 + */ +class CSimplifyNfa +{ + private int[] ccls; // character class mapping. + private int original_charset_size; // original charset size + private int mapped_charset_size; // reduced charset size + + void simplify(CSpec m_spec) { + computeClasses(m_spec); // initialize fields. + + // now rewrite the NFA using our character class mapping. + for (Enumeration e=m_spec.m_nfa_states.elements(); e.hasMoreElements(); ) { + CNfa nfa = (CNfa) e.nextElement(); + if (nfa.m_edge==CNfa.EMPTY || nfa.m_edge==CNfa.EPSILON) + continue; // no change. + if (nfa.m_edge==CNfa.CCL) { + CSet ncset = new CSet(); + ncset.map(nfa.m_set, ccls); // map it. + nfa.m_set = ncset; + } else { // single character + nfa.m_edge = ccls[nfa.m_edge]; // map it. + } + } + + // now update m_spec with the mapping. + m_spec.m_ccls_map = ccls; + m_spec.m_dtrans_ncols = mapped_charset_size; + } + /** Compute minimum set of character classes needed to disambiguate + * edges. We optimistically assume that every character belongs to + * a single character class, and then incrementally split classes + * as we see edges that require discrimination between characters in + * the class. [CSA, 25-Jul-1999] */ + private void computeClasses(CSpec m_spec) { + this.original_charset_size = m_spec.m_dtrans_ncols; + this.ccls = new int[original_charset_size]; // initially all zero. + + int nextcls = 1; + SparseBitSet clsA = new SparseBitSet(), clsB = new SparseBitSet(); + Hashtable h = new Hashtable(); + + System.out.print("Working on character classes."); + for (Enumeration e=m_spec.m_nfa_states.elements(); e.hasMoreElements(); ) { + CNfa nfa = (CNfa) e.nextElement(); + if (nfa.m_edge==CNfa.EMPTY || nfa.m_edge==CNfa.EPSILON) + continue; // no discriminatory information. + clsA.clearAll(); clsB.clearAll(); + for (int i=0; i<ccls.length; i++) + if (nfa.m_edge==i || // edge labeled with a character + nfa.m_edge==CNfa.CCL && nfa.m_set.contains(i)) // set of characters + clsA.set(ccls[i]); + else + clsB.set(ccls[i]); + // now figure out which character classes we need to split. + clsA.and(clsB); // split the classes which show up on both sides of edge + System.out.print(clsA.size()==0?".":":"); + if (clsA.size()==0) continue; // nothing to do. + // and split them. + h.clear(); // h will map old to new class name + for (int i=0; i<ccls.length; i++) + if (clsA.get(ccls[i])) // a split class + if (nfa.m_edge==i || + nfa.m_edge==CNfa.CCL && nfa.m_set.contains(i)) { // on A side + Integer split = new Integer(ccls[i]); + if (!h.containsKey(split)) + h.put(split, new Integer(nextcls++)); // make new class + ccls[i] = ((Integer)h.get(split)).intValue(); + } + } + System.out.println(); + System.out.println("NFA has "+nextcls+" distinct character classes."); + + this.mapped_charset_size = nextcls; + } +} + +/*************************************************************** + Class: CMinimize + **************************************************************/ +class CMinimize +{ + /*************************************************************** + Member Variables + **************************************************************/ + CSpec m_spec; + Vector m_group; + int m_ingroup[]; + + /*************************************************************** + Function: CMinimize + Description: Constructor. + **************************************************************/ + CMinimize + ( + ) + { + reset(); + } + + /*************************************************************** + Function: reset + Description: Resets member variables. + **************************************************************/ + private void reset + ( + ) + { + m_spec = null; + m_group = null; + m_ingroup = null; + } + + /*************************************************************** + Function: set + Description: Sets member variables. + **************************************************************/ + private void set + ( + CSpec spec + ) + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != spec); + } + + m_spec = spec; + m_group = null; + m_ingroup = null; + } + + /*************************************************************** + Function: min_dfa + Description: High-level access function to module. + **************************************************************/ + void min_dfa + ( + CSpec spec + ) + { + set(spec); + + /* Remove redundant states. */ + minimize(); + + /* Column and row compression. + Save accept states in auxilary vector. */ + reduce(); + + reset(); + } + + /*************************************************************** + Function: col_copy + Description: Copies source column into destination column. + **************************************************************/ + private void col_copy + ( + int dest, + int src + ) + { + int n; + int i; + CDTrans dtrans; + + n = m_spec.m_dtrans_vector.size(); + for (i = 0; i < n; ++i) + { + dtrans = (CDTrans) m_spec.m_dtrans_vector.elementAt(i); + dtrans.m_dtrans[dest] = dtrans.m_dtrans[src]; + } + } + + /*************************************************************** + Function: trunc_col + Description: Truncates each column to the 'correct' length. + **************************************************************/ + private void trunc_col + ( + ) + { + int n; + int i; + CDTrans dtrans; + + n = m_spec.m_dtrans_vector.size(); + for (i = 0; i < n; ++i) + { + int[] ndtrans = new int[m_spec.m_dtrans_ncols]; + dtrans = (CDTrans) m_spec.m_dtrans_vector.elementAt(i); + System.arraycopy(dtrans.m_dtrans, 0, ndtrans, 0, ndtrans.length); + dtrans.m_dtrans = ndtrans; + } + } + /*************************************************************** + Function: row_copy + Description: Copies source row into destination row. + **************************************************************/ + private void row_copy + ( + int dest, + int src + ) + { + CDTrans dtrans; + + dtrans = (CDTrans) m_spec.m_dtrans_vector.elementAt(src); + m_spec.m_dtrans_vector.setElementAt(dtrans,dest); + } + + /*************************************************************** + Function: col_equiv + Description: + **************************************************************/ + private boolean col_equiv + ( + int col1, + int col2 + ) + { + int n; + int i; + CDTrans dtrans; + + n = m_spec.m_dtrans_vector.size(); + for (i = 0; i < n; ++i) + { + dtrans = (CDTrans) m_spec.m_dtrans_vector.elementAt(i); + if (dtrans.m_dtrans[col1] != dtrans.m_dtrans[col2]) + { + return false; + } + } + + return true; + } + + /*************************************************************** + Function: row_equiv + Description: + **************************************************************/ + private boolean row_equiv + ( + int row1, + int row2 + ) + { + int i; + CDTrans dtrans1; + CDTrans dtrans2; + + dtrans1 = (CDTrans) m_spec.m_dtrans_vector.elementAt(row1); + dtrans2 = (CDTrans) m_spec.m_dtrans_vector.elementAt(row2); + + for (i = 0; i < m_spec.m_dtrans_ncols; ++i) + { + if (dtrans1.m_dtrans[i] != dtrans2.m_dtrans[i]) + { + return false; + } + } + + return true; + } + + /*************************************************************** + Function: reduce + Description: + **************************************************************/ + private void reduce + ( + ) + { + int i; + int j; + int k; + int nrows; + int reduced_ncols; + int reduced_nrows; + SparseBitSet set; + CDTrans dtrans; + int size; + + set = new SparseBitSet(); + + /* Save accept nodes and anchor entries. */ + size = m_spec.m_dtrans_vector.size(); + m_spec.m_anchor_array = new int[size]; + m_spec.m_accept_vector = new Vector(); + for (i = 0; i < size; ++i) + { + dtrans = (CDTrans) m_spec.m_dtrans_vector.elementAt(i); + m_spec.m_accept_vector.addElement(dtrans.m_accept); + m_spec.m_anchor_array[i] = dtrans.m_anchor; + dtrans.m_accept = null; + } + + /* Allocate column map. */ + m_spec.m_col_map = new int[m_spec.m_dtrans_ncols]; + for (i = 0; i < m_spec.m_dtrans_ncols; ++i) + { + m_spec.m_col_map[i] = -1; + } + + /* Process columns for reduction. */ + for (reduced_ncols = 0; ; ++reduced_ncols) + { + if (CUtility.DEBUG) + { + for (i = 0; i < reduced_ncols; ++i) + { + CUtility.ASSERT(-1 != m_spec.m_col_map[i]); + } + } + + for (i = reduced_ncols; i < m_spec.m_dtrans_ncols; ++i) + { + if (-1 == m_spec.m_col_map[i]) + { + break; + } + } + + if (i >= m_spec.m_dtrans_ncols) + { + break; + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT(false == set.get(i)); + CUtility.ASSERT(-1 == m_spec.m_col_map[i]); + } + + set.set(i); + + m_spec.m_col_map[i] = reduced_ncols; + + /* UNDONE: Optimize by doing all comparisons in one batch. */ + for (j = i + 1; j < m_spec.m_dtrans_ncols; ++j) + { + if (-1 == m_spec.m_col_map[j] && true == col_equiv(i,j)) + { + m_spec.m_col_map[j] = reduced_ncols; + } + } + } + + /* Reduce columns. */ + k = 0; + for (i = 0; i < m_spec.m_dtrans_ncols; ++i) + { + if (set.get(i)) + { + ++k; + + set.clear(i); + + j = m_spec.m_col_map[i]; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(j <= i); + } + + if (j == i) + { + continue; + } + + col_copy(j,i); + } + } + m_spec.m_dtrans_ncols = reduced_ncols; + /* truncate m_dtrans at proper length (freeing extra) */ + trunc_col(); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(k == reduced_ncols); + } + + /* Allocate row map. */ + nrows = m_spec.m_dtrans_vector.size(); + m_spec.m_row_map = new int[nrows]; + for (i = 0; i < nrows; ++i) + { + m_spec.m_row_map[i] = -1; + } + + /* Process rows to reduce. */ + for (reduced_nrows = 0; ; ++reduced_nrows) + { + if (CUtility.DEBUG) + { + for (i = 0; i < reduced_nrows; ++i) + { + CUtility.ASSERT(-1 != m_spec.m_row_map[i]); + } + } + + for (i = reduced_nrows; i < nrows; ++i) + { + if (-1 == m_spec.m_row_map[i]) + { + break; + } + } + + if (i >= nrows) + { + break; + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT(false == set.get(i)); + CUtility.ASSERT(-1 == m_spec.m_row_map[i]); + } + + set.set(i); + + m_spec.m_row_map[i] = reduced_nrows; + + /* UNDONE: Optimize by doing all comparisons in one batch. */ + for (j = i + 1; j < nrows; ++j) + { + if (-1 == m_spec.m_row_map[j] && true == row_equiv(i,j)) + { + m_spec.m_row_map[j] = reduced_nrows; + } + } + } + + /* Reduce rows. */ + k = 0; + for (i = 0; i < nrows; ++i) + { + if (set.get(i)) + { + ++k; + + set.clear(i); + + j = m_spec.m_row_map[i]; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(j <= i); + } + + if (j == i) + { + continue; + } + + row_copy(j,i); + } + } + m_spec.m_dtrans_vector.setSize(reduced_nrows); + + if (CUtility.DEBUG) + { + /*System.out.println("k = " + k + "\nreduced_nrows = " + reduced_nrows + "");*/ + CUtility.ASSERT(k == reduced_nrows); + } + } + + /*************************************************************** + Function: fix_dtrans + Description: Updates CDTrans table after minimization + using groups, removing redundant transition table states. + **************************************************************/ + private void fix_dtrans + ( + ) + { + Vector new_vector; + int i; + int size; + Vector dtrans_group; + CDTrans first; + int c; + + new_vector = new Vector(); + + size = m_spec.m_state_dtrans.length; + for (i = 0; i < size; ++i) + { + if (CDTrans.F != m_spec.m_state_dtrans[i]) + { + m_spec.m_state_dtrans[i] = m_ingroup[m_spec.m_state_dtrans[i]]; + } + } + + size = m_group.size(); + for (i = 0; i < size; ++i) + { + dtrans_group = (Vector) m_group.elementAt(i); + first = (CDTrans) dtrans_group.elementAt(0); + new_vector.addElement(first); + + for (c = 0; c < m_spec.m_dtrans_ncols; ++c) + { + if (CDTrans.F != first.m_dtrans[c]) + { + first.m_dtrans[c] = m_ingroup[first.m_dtrans[c]]; + } + } + } + + m_group = null; + m_spec.m_dtrans_vector = new_vector; + } + + /*************************************************************** + Function: minimize + Description: Removes redundant transition table states. + **************************************************************/ + private void minimize + ( + ) + { + Vector dtrans_group; + Vector new_group; + int i; + int j; + int old_group_count; + int group_count; + CDTrans next; + CDTrans first; + int goto_first; + int goto_next; + int c; + int group_size; + boolean added; + + init_groups(); + + group_count = m_group.size(); + old_group_count = group_count - 1; + + while (old_group_count != group_count) + { + old_group_count = group_count; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(m_group.size() == group_count); + } + + for (i = 0; i < group_count; ++i) + { + dtrans_group = (Vector) m_group.elementAt(i); + + group_size = dtrans_group.size(); + if (group_size <= 1) + { + continue; + } + + new_group = new Vector(); + added = false; + + first = (CDTrans) dtrans_group.elementAt(0); + for (j = 1; j < group_size; ++j) + { + next = (CDTrans) dtrans_group.elementAt(j); + + for (c = 0; c < m_spec.m_dtrans_ncols; ++c) + { + goto_first = first.m_dtrans[c]; + goto_next = next.m_dtrans[c]; + + if (goto_first != goto_next + && (goto_first == CDTrans.F + || goto_next == CDTrans.F + || m_ingroup[goto_next] != m_ingroup[goto_first])) + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(dtrans_group.elementAt(j) == next); + } + + dtrans_group.removeElementAt(j); + --j; + --group_size; + new_group.addElement(next); + if (false == added) + { + added = true; + ++group_count; + m_group.addElement(new_group); + } + m_ingroup[next.m_label] = m_group.size() - 1; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(m_group.contains(new_group) + == true); + CUtility.ASSERT(m_group.contains(dtrans_group) + == true); + CUtility.ASSERT(dtrans_group.contains(first) + == true); + CUtility.ASSERT(dtrans_group.contains(next) + == false); + CUtility.ASSERT(new_group.contains(first) + == false); + CUtility.ASSERT(new_group.contains(next) + == true); + CUtility.ASSERT(dtrans_group.size() == group_size); + CUtility.ASSERT(i == m_ingroup[first.m_label]); + CUtility.ASSERT((m_group.size() - 1) + == m_ingroup[next.m_label]); + } + + break; + } + } + } + } + } + + System.out.println(m_group.size() + " states after removal of redundant states."); + + if (m_spec.m_verbose + && true == CUtility.OLD_DUMP_DEBUG) + { + System.out.println(); + System.out.println("States grouped as follows after minimization"); + pgroups(); + } + + fix_dtrans(); + } + + /*************************************************************** + Function: init_groups + Description: + **************************************************************/ + private void init_groups + ( + ) + { + int i; + int j; + int group_count; + int size; + CAccept accept; + CDTrans dtrans; + Vector dtrans_group; + CDTrans first; + boolean group_found; + + m_group = new Vector(); + group_count = 0; + + size = m_spec.m_dtrans_vector.size(); + m_ingroup = new int[size]; + + for (i = 0; i < size; ++i) + { + group_found = false; + dtrans = (CDTrans) m_spec.m_dtrans_vector.elementAt(i); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(i == dtrans.m_label); + CUtility.ASSERT(false == group_found); + CUtility.ASSERT(group_count == m_group.size()); + } + + for (j = 0; j < group_count; ++j) + { + dtrans_group = (Vector) m_group.elementAt(j); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(false == group_found); + CUtility.ASSERT(0 < dtrans_group.size()); + } + + first = (CDTrans) dtrans_group.elementAt(0); + + if (CUtility.SLOW_DEBUG) + { + CDTrans check; + int k; + int s; + + s = dtrans_group.size(); + CUtility.ASSERT(0 < s); + + for (k = 1; k < s; ++k) + { + check = (CDTrans) dtrans_group.elementAt(k); + CUtility.ASSERT(check.m_accept == first.m_accept); + } + } + + if (first.m_accept == dtrans.m_accept) + { + dtrans_group.addElement(dtrans); + m_ingroup[i] = j; + group_found = true; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(j == m_ingroup[dtrans.m_label]); + } + + break; + } + } + + if (false == group_found) + { + dtrans_group = new Vector(); + dtrans_group.addElement(dtrans); + m_ingroup[i] = m_group.size(); + m_group.addElement(dtrans_group); + ++group_count; + } + } + + if (m_spec.m_verbose + && true == CUtility.OLD_DUMP_DEBUG) + { + System.out.println("Initial grouping:"); + pgroups(); + System.out.println(); + } + } + + /*************************************************************** + Function: pset + **************************************************************/ + private void pset + ( + Vector dtrans_group + ) + { + int i; + int size; + CDTrans dtrans; + + size = dtrans_group.size(); + for (i = 0; i < size; ++i) + { + dtrans = (CDTrans) dtrans_group.elementAt(i); + System.out.print(dtrans.m_label + " "); + } + } + + /*************************************************************** + Function: pgroups + **************************************************************/ + private void pgroups + ( + ) + { + int i; + int dtrans_size; + int group_size; + + group_size = m_group.size(); + for (i = 0; i < group_size; ++i) + { + System.out.print("\tGroup " + i + " {"); + pset((Vector) m_group.elementAt(i)); + System.out.println("}"); + System.out.println(); + } + + System.out.println(); + dtrans_size = m_spec.m_dtrans_vector.size(); + for (i = 0; i < dtrans_size; ++i) + { + System.out.println("\tstate " + i + + " is in group " + + m_ingroup[i]); + } + } +} + +/*************************************************************** + Class: CNfa2Dfa + **************************************************************/ +class CNfa2Dfa +{ + /*************************************************************** + Member Variables + **************************************************************/ + private CSpec m_spec; + private int m_unmarked_dfa; + private CLexGen m_lexGen; + + /*************************************************************** + Constants + **************************************************************/ + private static final int NOT_IN_DSTATES = -1; + + /*************************************************************** + Function: CNfa2Dfa + **************************************************************/ + CNfa2Dfa + ( + ) + { + reset(); + } + + /*************************************************************** + Function: set + Description: + **************************************************************/ + private void set + ( + CLexGen lexGen, + CSpec spec + ) + { + m_lexGen = lexGen; + m_spec = spec; + m_unmarked_dfa = 0; + } + + /*************************************************************** + Function: reset + Description: + **************************************************************/ + private void reset + ( + ) + { + m_lexGen = null; + m_spec = null; + m_unmarked_dfa = 0; + } + + /*************************************************************** + Function: make_dfa + Description: High-level access function to module. + **************************************************************/ + void make_dfa + ( + CLexGen lexGen, + CSpec spec + ) + { + int i; + + reset(); + set(lexGen,spec); + + make_dtrans(); + free_nfa_states(); + + if (m_spec.m_verbose && true == CUtility.OLD_DUMP_DEBUG) + { + System.out.println(m_spec.m_dfa_states.size() + + " DFA states in original machine."); + } + + free_dfa_states(); + } + + /*************************************************************** + Function: make_dtrans + Description: Creates uncompressed CDTrans transition table. + **************************************************************/ + private void make_dtrans + ( + ) + /* throws java.lang.CloneNotSupportedException*/ + { + CDfa next; + CDfa dfa; + CBunch bunch; + int i; + int nextstate; + int size; + CDTrans dtrans; + CNfa nfa; + int istate; + int nstates; + + System.out.print("Working on DFA states."); + + /* Reference passing type and initializations. */ + bunch = new CBunch(); + m_unmarked_dfa = 0; + + /* Allocate mapping array. */ + nstates = m_spec.m_state_rules.length; + m_spec.m_state_dtrans = new int[nstates]; + + for (istate = 0; nstates > istate; ++istate) + { + /* CSA bugfix: if we skip all zero size rules, then + an specification with no rules produces an illegal + lexer (0 states) instead of a lexer that rejects + everything (1 nonaccepting state). [27-Jul-1999] + if (0 == m_spec.m_state_rules[istate].size()) + { + m_spec.m_state_dtrans[istate] = CDTrans.F; + continue; + } + */ + + /* Create start state and initialize fields. */ + bunch.m_nfa_set = (Vector) m_spec.m_state_rules[istate].clone(); + sortStates(bunch.m_nfa_set); + + bunch.m_nfa_bit = new SparseBitSet(); + + /* Initialize bit set. */ + size = bunch.m_nfa_set.size(); + for (i = 0; size > i; ++i) + { + nfa = (CNfa) bunch.m_nfa_set.elementAt(i); + bunch.m_nfa_bit.set(nfa.m_label); + } + + bunch.m_accept = null; + bunch.m_anchor = CSpec.NONE; + bunch.m_accept_index = CUtility.INT_MAX; + + e_closure(bunch); + add_to_dstates(bunch); + + m_spec.m_state_dtrans[istate] = m_spec.m_dtrans_vector.size(); + + /* Main loop of CDTrans creation. */ + while (null != (dfa = get_unmarked())) + { + System.out.print("."); + System.out.flush(); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(false == dfa.m_mark); + } + + /* Get first unmarked node, then mark it. */ + dfa.m_mark = true; + + /* Allocate new CDTrans, then initialize fields. */ + dtrans = new CDTrans(m_spec.m_dtrans_vector.size(),m_spec); + dtrans.m_accept = dfa.m_accept; + dtrans.m_anchor = dfa.m_anchor; + + /* Set CDTrans array for each character transition. */ + for (i = 0; i < m_spec.m_dtrans_ncols; ++i) + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(0 <= i); + CUtility.ASSERT(m_spec.m_dtrans_ncols > i); + } + + /* Create new dfa set by attempting character transition. */ + move(dfa.m_nfa_set,dfa.m_nfa_bit,i,bunch); + if (null != bunch.m_nfa_set) + { + e_closure(bunch); + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT((null == bunch.m_nfa_set + && null == bunch.m_nfa_bit) + || (null != bunch.m_nfa_set + && null != bunch.m_nfa_bit)); + } + + /* Create new state or set state to empty. */ + if (null == bunch.m_nfa_set) + { + nextstate = CDTrans.F; + } + else + { + nextstate = in_dstates(bunch); + + if (NOT_IN_DSTATES == nextstate) + { + nextstate = add_to_dstates(bunch); + } + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT(nextstate < m_spec.m_dfa_states.size()); + } + + dtrans.m_dtrans[i] = nextstate; + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT(m_spec.m_dtrans_vector.size() == dfa.m_label); + } + + m_spec.m_dtrans_vector.addElement(dtrans); + } + } + + System.out.println(); + } + + /*************************************************************** + Function: free_dfa_states + **************************************************************/ + private void free_dfa_states + ( + ) + { + m_spec.m_dfa_states = null; + m_spec.m_dfa_sets = null; + } + + /*************************************************************** + Function: free_nfa_states + **************************************************************/ + private void free_nfa_states + ( + ) + { + /* UNDONE: Remove references to nfas from within dfas. */ + /* UNDONE: Don't free CAccepts. */ + + m_spec.m_nfa_states = null; + m_spec.m_nfa_start = null; + m_spec.m_state_rules = null; + } + + /*************************************************************** + Function: e_closure + Description: Alters and returns input set. + **************************************************************/ + private void e_closure + ( + CBunch bunch + ) + { + Stack nfa_stack; + int size; + int i; + CNfa state; + + /* Debug checks. */ + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != bunch); + CUtility.ASSERT(null != bunch.m_nfa_set); + CUtility.ASSERT(null != bunch.m_nfa_bit); + } + + bunch.m_accept = null; + bunch.m_anchor = CSpec.NONE; + bunch.m_accept_index = CUtility.INT_MAX; + + /* Create initial stack. */ + nfa_stack = new Stack(); + size = bunch.m_nfa_set.size(); + for (i = 0; i < size; ++i) + { + state = (CNfa) bunch.m_nfa_set.elementAt(i); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(bunch.m_nfa_bit.get(state.m_label)); + } + + nfa_stack.push(state); + } + + /* Main loop. */ + while (false == nfa_stack.empty()) + { + state = (CNfa) nfa_stack.pop(); + + if (CUtility.OLD_DUMP_DEBUG) + { + if (null != state.m_accept) + { + System.out.println("Looking at accepting state " + state.m_label + + " with <" + + (new String(state.m_accept.m_action,0, + state.m_accept.m_action_read)) + + ">"); + } + } + + if (null != state.m_accept + && state.m_label < bunch.m_accept_index) + { + bunch.m_accept_index = state.m_label; + bunch.m_accept = state.m_accept; + bunch.m_anchor = state.m_anchor; + + if (CUtility.OLD_DUMP_DEBUG) + { + System.out.println("Found accepting state " + state.m_label + + " with <" + + (new String(state.m_accept.m_action,0, + state.m_accept.m_action_read)) + + ">"); + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != bunch.m_accept); + CUtility.ASSERT(CSpec.NONE == bunch.m_anchor + || 0 != (bunch.m_anchor & CSpec.END) + || 0 != (bunch.m_anchor & CSpec.START)); + } + } + + if (CNfa.EPSILON == state.m_edge) + { + if (null != state.m_next) + { + if (false == bunch.m_nfa_set.contains(state.m_next)) + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(false == bunch.m_nfa_bit.get(state.m_next.m_label)); + } + + bunch.m_nfa_bit.set(state.m_next.m_label); + bunch.m_nfa_set.addElement(state.m_next); + nfa_stack.push(state.m_next); + } + } + + if (null != state.m_next2) + { + if (false == bunch.m_nfa_set.contains(state.m_next2)) + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(false == bunch.m_nfa_bit.get(state.m_next2.m_label)); + } + + bunch.m_nfa_bit.set(state.m_next2.m_label); + bunch.m_nfa_set.addElement(state.m_next2); + nfa_stack.push(state.m_next2); + } + } + } + } + + if (null != bunch.m_nfa_set) + { + sortStates(bunch.m_nfa_set); + } + + return; + } + + /*************************************************************** + Function: move + Description: Returns null if resulting NFA set is empty. + **************************************************************/ + void move + ( + Vector nfa_set, + SparseBitSet nfa_bit, + int b, + CBunch bunch + ) + { + int size; + int index; + CNfa state; + + bunch.m_nfa_set = null; + bunch.m_nfa_bit = null; + + size = nfa_set.size(); + for (index = 0; index < size; ++index) + { + state = (CNfa) nfa_set.elementAt(index); + + if (b == state.m_edge + || (CNfa.CCL == state.m_edge + && true == state.m_set.contains(b))) + { + if (null == bunch.m_nfa_set) + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null == bunch.m_nfa_bit); + } + + bunch.m_nfa_set = new Vector(); + /*bunch.m_nfa_bit + = new SparseBitSet(m_spec.m_nfa_states.size());*/ + bunch.m_nfa_bit = new SparseBitSet(); + } + + bunch.m_nfa_set.addElement(state.m_next); + /*System.out.println("Size of bitset: " + bunch.m_nfa_bit.size()); + System.out.println("Reference index: " + state.m_next.m_label); + System.out.flush();*/ + bunch.m_nfa_bit.set(state.m_next.m_label); + } + } + + if (null != bunch.m_nfa_set) + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != bunch.m_nfa_bit); + } + + sortStates(bunch.m_nfa_set); + } + + return; + } + + /*************************************************************** + Function: sortStates + **************************************************************/ + private void sortStates + ( + Vector nfa_set + ) + { + CNfa elem; + int begin; + int size; + int index; + int value; + int smallest_index; + int smallest_value; + CNfa begin_elem; + + size = nfa_set.size(); + for (begin = 0; begin < size; ++begin) + { + elem = (CNfa) nfa_set.elementAt(begin); + smallest_value = elem.m_label; + smallest_index = begin; + + for (index = begin + 1; index < size; ++index) + { + elem = (CNfa) nfa_set.elementAt(index); + value = elem.m_label; + + if (value < smallest_value) + { + smallest_index = index; + smallest_value = value; + } + } + + begin_elem = (CNfa) nfa_set.elementAt(begin); + elem = (CNfa) nfa_set.elementAt(smallest_index); + nfa_set.setElementAt(elem,begin); + nfa_set.setElementAt(begin_elem,smallest_index); + } + + if (CUtility.OLD_DEBUG) + { + System.out.print("NFA vector indices: "); + + for (index = 0; index < size; ++index) + { + elem = (CNfa) nfa_set.elementAt(index); + System.out.print(elem.m_label + " "); + } + System.out.println(); + } + + return; + } + + /*************************************************************** + Function: get_unmarked + Description: Returns next unmarked DFA state. + **************************************************************/ + private CDfa get_unmarked + ( + ) + { + int size; + CDfa dfa; + + size = m_spec.m_dfa_states.size(); + while (m_unmarked_dfa < size) + { + dfa = (CDfa) m_spec.m_dfa_states.elementAt(m_unmarked_dfa); + + if (false == dfa.m_mark) + { + if (CUtility.OLD_DUMP_DEBUG) + { + System.out.print("*"); + System.out.flush(); + } + + if (m_spec.m_verbose && true == CUtility.OLD_DUMP_DEBUG) + { + System.out.println("---------------"); + System.out.print("working on DFA state " + + m_unmarked_dfa + + " = NFA states: "); + m_lexGen.print_set(dfa.m_nfa_set); + System.out.println(); + } + + return dfa; + } + + ++m_unmarked_dfa; + } + + return null; + } + + /*************************************************************** + function: add_to_dstates + Description: Takes as input a CBunch with details of + a dfa state that needs to be created. + 1) Allocates a new dfa state and saves it in + the appropriate CSpec vector. + 2) Initializes the fields of the dfa state + with the information in the CBunch. + 3) Returns index of new dfa. + **************************************************************/ + private int add_to_dstates + ( + CBunch bunch + ) + { + CDfa dfa; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != bunch.m_nfa_set); + CUtility.ASSERT(null != bunch.m_nfa_bit); + CUtility.ASSERT(null != bunch.m_accept + || CSpec.NONE == bunch.m_anchor); + } + + /* Allocate, passing CSpec so dfa label can be set. */ + dfa = CAlloc.newCDfa(m_spec); + + /* Initialize fields, including the mark field. */ + dfa.m_nfa_set = (Vector) bunch.m_nfa_set.clone(); + dfa.m_nfa_bit = (SparseBitSet) bunch.m_nfa_bit.clone(); + dfa.m_accept = bunch.m_accept; + dfa.m_anchor = bunch.m_anchor; + dfa.m_mark = false; + + /* Register dfa state using BitSet in CSpec Hashtable. */ + m_spec.m_dfa_sets.put(dfa.m_nfa_bit,dfa); + /*registerCDfa(dfa);*/ + + if (CUtility.OLD_DUMP_DEBUG) + { + System.out.print("Registering set : "); + m_lexGen.print_set(dfa.m_nfa_set); + System.out.println(); + } + + return dfa.m_label; + } + + /*************************************************************** + Function: in_dstates + **************************************************************/ + private int in_dstates + ( + CBunch bunch + ) + { + CDfa dfa; + + if (CUtility.OLD_DEBUG) + { + System.out.print("Looking for set : "); + m_lexGen.print_set(bunch.m_nfa_set); + } + + dfa = (CDfa) m_spec.m_dfa_sets.get(bunch.m_nfa_bit); + + if (null != dfa) + { + if (CUtility.OLD_DUMP_DEBUG) + { + System.out.println(" FOUND!"); + } + + return dfa.m_label; + } + + if (CUtility.OLD_DUMP_DEBUG) + { + System.out.println(" NOT FOUND!"); + } + return NOT_IN_DSTATES; + } + +} + +/*************************************************************** + Class: CAlloc + **************************************************************/ +class CAlloc +{ + /*************************************************************** + Function: newCDfa + **************************************************************/ + static CDfa newCDfa + ( + CSpec spec + ) + { + CDfa dfa; + + dfa = new CDfa(spec.m_dfa_states.size()); + spec.m_dfa_states.addElement(dfa); + + return dfa; + } + + /*************************************************************** + Function: newCNfaPair + Description: + **************************************************************/ + static CNfaPair newCNfaPair + ( + ) + { + CNfaPair pair = new CNfaPair(); + + return pair; + } + /*************************************************************** + Function: newNLPair + Description: return a new CNfaPair that matches a new + line: (\r\n?|[\n\uu2028\uu2029]) + Added by CSA 8-Aug-1999, updated 10-Aug-1999 + **************************************************************/ + static CNfaPair newNLPair(CSpec spec) { + CNfaPair pair = newCNfaPair(); + pair.m_end=newCNfa(spec); // newline accepting state + pair.m_start=newCNfa(spec); // new state with two epsilon edges + pair.m_start.m_next = newCNfa(spec); + pair.m_start.m_next.m_edge = CNfa.CCL; + pair.m_start.m_next.m_set = new CSet(); + pair.m_start.m_next.m_set.add('\n'); + if (spec.m_dtrans_ncols-CSpec.NUM_PSEUDO > 2029) { + pair.m_start.m_next.m_set.add(2028); /*U+2028 is LS, the line separator*/ + pair.m_start.m_next.m_set.add(2029); /*U+2029 is PS, the paragraph sep.*/ + } + pair.m_start.m_next.m_next = pair.m_end; // accept '\n', U+2028, or U+2029 + pair.m_start.m_next2 = newCNfa(spec); + pair.m_start.m_next2.m_edge = '\r'; + pair.m_start.m_next2.m_next = newCNfa(spec); + pair.m_start.m_next2.m_next.m_next = pair.m_end; // accept '\r'; + pair.m_start.m_next2.m_next.m_next2 = newCNfa(spec); + pair.m_start.m_next2.m_next.m_next2.m_edge = '\n'; + pair.m_start.m_next2.m_next.m_next2.m_next = pair.m_end; // accept '\r\n'; + return pair; + } + + /*************************************************************** + Function: newCNfa + Description: + **************************************************************/ + static CNfa newCNfa + ( + CSpec spec + ) + { + CNfa p; + + /* UNDONE: Buffer this? */ + + p = new CNfa(); + + /*p.m_label = spec.m_nfa_states.size();*/ + spec.m_nfa_states.addElement(p); + p.m_edge = CNfa.EPSILON; + + return p; + } +} + +/*************************************************************** + Class: Main + Description: Top-level lexical analyzer generator function. + **************************************************************/ +public class Main +{ + /*************************************************************** + Function: main + **************************************************************/ + public static void main + ( + String arg[] + ) + throws java.io.IOException + { + CLexGen lg; + + if (arg.length < 1) + { + System.out.println("Usage: JLex.Main <filename>"); + return; + } + + /* Note: For debuging, it may be helpful to remove the try/catch + block and permit the Exception to propagate to the top level. + This gives more information. */ + try + { + lg = new CLexGen(arg[0]); + lg.generate(); + } + catch (Error e) + { + System.out.println(e.getMessage()); + } + } +} + +/*************************************************************** + Class: CDTrans + **************************************************************/ +class CDTrans +{ + /************************************************************* + Member Variables + ***********************************************************/ + int m_dtrans[]; + CAccept m_accept; + int m_anchor; + int m_label; + + /************************************************************* + Constants + ***********************************************************/ + static final int F = -1; + + /************************************************************* + Function: CTrans + ***********************************************************/ + CDTrans + ( + int label, + CSpec spec + ) + { + m_dtrans = new int[spec.m_dtrans_ncols]; + m_accept = null; + m_anchor = CSpec.NONE; + m_label = label; + } +} + +/*************************************************************** + Class: CDfa + **************************************************************/ +class CDfa +{ + /*************************************************************** + Member Variables + ***********************************************************/ + int m_group; + boolean m_mark; + CAccept m_accept; + int m_anchor; + Vector m_nfa_set; + SparseBitSet m_nfa_bit; + int m_label; + + /*************************************************************** + Function: CDfa + **************************************************************/ + CDfa + ( + int label + ) + { + m_group = 0; + m_mark = false; + + m_accept = null; + m_anchor = CSpec.NONE; + + m_nfa_set = null; + m_nfa_bit = null; + + m_label = label; + } +} + +/*************************************************************** + Class: CAccept + **************************************************************/ +class CAccept +{ + /*************************************************************** + Member Variables + **************************************************************/ + char m_action[]; + int m_action_read; + int m_line_number; + + /*************************************************************** + Function: CAccept + **************************************************************/ + CAccept + ( + char action[], + int action_read, + int line_number + ) + { + int elem; + + m_action_read = action_read; + + m_action = new char[m_action_read]; + for (elem = 0; elem < m_action_read; ++elem) + { + m_action[elem] = action[elem]; + } + + m_line_number = line_number; + } + + /*************************************************************** + Function: CAccept + **************************************************************/ + CAccept + ( + CAccept accept + ) + { + int elem; + + m_action_read = accept.m_action_read; + + m_action = new char[m_action_read]; + for (elem = 0; elem < m_action_read; ++elem) + { + m_action[elem] = accept.m_action[elem]; + } + + m_line_number = accept.m_line_number; + } + + /*************************************************************** + Function: mimic + **************************************************************/ + void mimic + ( + CAccept accept + ) + { + int elem; + + m_action_read = accept.m_action_read; + + m_action = new char[m_action_read]; + for (elem = 0; elem < m_action_read; ++elem) + { + m_action[elem] = accept.m_action[elem]; + } + } +} + +/*************************************************************** + Class: CAcceptAnchor + **************************************************************/ +class CAcceptAnchor +{ + /*************************************************************** + Member Variables + **************************************************************/ + CAccept m_accept; + int m_anchor; + + /*************************************************************** + Function: CAcceptAnchor + **************************************************************/ + CAcceptAnchor + ( + ) + { + m_accept = null; + m_anchor = CSpec.NONE; + } +} + +/*************************************************************** + Class: CNfaPair + **************************************************************/ +class CNfaPair +{ + /*************************************************************** + Member Variables + **************************************************************/ + CNfa m_start; + CNfa m_end; + + /*************************************************************** + Function: CNfaPair + **************************************************************/ + CNfaPair + ( + ) + { + m_start = null; + m_end = null; + } +} + +/*************************************************************** + Class: CInput + Description: + **************************************************************/ +class CInput +{ + /*************************************************************** + Member Variables + **************************************************************/ + private java.io.BufferedReader m_input; /* JLex specification file. */ + + boolean m_eof_reached; /* Whether EOF has been encountered. */ + boolean m_pushback_line; + + char m_line[]; /* Line buffer. */ + int m_line_read; /* Number of bytes read into line buffer. */ + int m_line_index; /* Current index into line buffer. */ + + int m_line_number; /* Current line number. */ + + /*************************************************************** + Constants + **************************************************************/ + static final boolean EOF = true; + static final boolean NOT_EOF = false; + + /*************************************************************** + Function: CInput + Description: + **************************************************************/ + CInput + ( + java.io.Reader input + ) + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != input); + } + + /* Initialize input stream. */ + m_input = new java.io.BufferedReader(input); + + /* Initialize buffers and index counters. */ + m_line = null; + m_line_read = 0; + m_line_index = 0; + + /* Initialize state variables. */ + m_eof_reached = false; + m_line_number = 0; + m_pushback_line = false; + } + + /*************************************************************** + Function: getLine + Description: Returns true on EOF, false otherwise. + Guarantees not to return a blank line, or a line + of zero length. + **************************************************************/ + boolean getLine + ( + ) + throws java.io.IOException + { + String lineStr; + int elem; + + /* Has EOF already been reached? */ + if (m_eof_reached) + { + return EOF; + } + + /* Pushback current line? */ + if (m_pushback_line) + { + m_pushback_line = false; + + /* Check for empty line. */ + for (elem = 0; elem < m_line_read; ++elem) + { + if (false == CUtility.isspace(m_line[elem])) + { + break; + } + } + + /* Nonempty? */ + if (elem < m_line_read) + { + m_line_index = 0; + return NOT_EOF; + } + } + + while (true) + { + if (null == (lineStr = m_input.readLine())) + { + m_eof_reached = true; + m_line_index = 0; + return EOF; + } + m_line = (lineStr + "\n").toCharArray(); + m_line_read=m_line.length; + ++m_line_number; + + /* Check for empty lines and discard them. */ + elem = 0; + while (CUtility.isspace(m_line[elem])) + { + ++elem; + if (elem == m_line_read) + { + break; + } + } + + if (elem < m_line_read) + { + break; + } + } + + m_line_index = 0; + return NOT_EOF; + } +} + +/******************************************************** + Class: Utility + *******************************************************/ +class CUtility +{ + /******************************************************** + Constants + *******************************************************/ + static final boolean DEBUG = true; + static final boolean SLOW_DEBUG = true; + static final boolean DUMP_DEBUG = true; + /*static final boolean DEBUG = false; + static final boolean SLOW_DEBUG = false; + static final boolean DUMP_DEBUG = false;*/ + static final boolean DESCENT_DEBUG = false; + static final boolean OLD_DEBUG = false; + static final boolean OLD_DUMP_DEBUG = false; + static final boolean FOODEBUG = false; + static final boolean DO_DEBUG = false; + + /******************************************************** + Constants: Integer Bounds + *******************************************************/ + static final int INT_MAX = 2147483647; + + static final int MAX_SEVEN_BIT = 127; + static final int MAX_EIGHT_BIT = 255; + static final int MAX_SIXTEEN_BIT=65535; + + /******************************************************** + Function: enter + Description: Debugging routine. + *******************************************************/ + static void enter + ( + String descent, + char lexeme, + int token + ) + { + System.out.println("Entering " + descent + + " [lexeme: " + lexeme + + "] [token: " + token + "]"); + } + + /******************************************************** + Function: leave + Description: Debugging routine. + *******************************************************/ + static void leave + ( + String descent, + char lexeme, + int token + ) + { + System.out.println("Leaving " + descent + + " [lexeme:" + lexeme + + "] [token:" + token + "]"); + } + + /******************************************************** + Function: ASSERT + Description: Debugging routine. + *******************************************************/ + static void ASSERT + ( + boolean expr + ) + { + if (DEBUG && false == expr) + { + System.out.println("Assertion Failed"); + throw new Error("Assertion Failed."); + } + } + + /*************************************************************** + Function: doubleSize + **************************************************************/ + static char[] doubleSize + ( + char oldBuffer[] + ) + { + char newBuffer[] = new char[2 * oldBuffer.length]; + int elem; + + for (elem = 0; elem < oldBuffer.length; ++elem) + { + newBuffer[elem] = oldBuffer[elem]; + } + + return newBuffer; + } + + /*************************************************************** + Function: doubleSize + **************************************************************/ + static byte[] doubleSize + ( + byte oldBuffer[] + ) + { + byte newBuffer[] = new byte[2 * oldBuffer.length]; + int elem; + + for (elem = 0; elem < oldBuffer.length; ++elem) + { + newBuffer[elem] = oldBuffer[elem]; + } + + return newBuffer; + } + + /******************************************************** + Function: hex2bin + *******************************************************/ + static char hex2bin + ( + char c + ) + { + if ('0' <= c && '9' >= c) + { + return (char) (c - '0'); + } + else if ('a' <= c && 'f' >= c) + { + return (char) (c - 'a' + 10); + } + else if ('A' <= c && 'F' >= c) + { + return (char) (c - 'A' + 10); + } + + CError.impos("Bad hexidecimal digit" + c); + return 0; + } + + /******************************************************** + Function: ishexdigit + *******************************************************/ + static boolean ishexdigit + ( + char c + ) + { + if (('0' <= c && '9' >= c) + || ('a' <= c && 'f' >= c) + || ('A' <= c && 'F' >= c)) + { + return true; + } + + return false; + } + + /******************************************************** + Function: oct2bin + *******************************************************/ + static char oct2bin + ( + char c + ) + { + if ('0' <= c && '7' >= c) + { + return (char) (c - '0'); + } + + CError.impos("Bad octal digit " + c); + return 0; + } + + /******************************************************** + Function: isoctdigit + *******************************************************/ + static boolean isoctdigit + ( + char c + ) + { + if ('0' <= c && '7' >= c) + { + return true; + } + + return false; + } + + /******************************************************** + Function: isspace + *******************************************************/ + static boolean isspace + ( + char c + ) + { + if ('\b' == c + || '\t' == c + || '\n' == c + || '\f' == c + || '\r' == c + || ' ' == c) + { + return true; + } + + return false; + } + + /******************************************************** + Function: isnewline + *******************************************************/ + static boolean isnewline + ( + char c + ) + { + if ('\n' == c + || '\r' == c) + { + return true; + } + + return false; + } + + /******************************************************** + Function: bytencmp + Description: Compares up to n elements of + byte array a[] against byte array b[]. + The first byte comparison is made between + a[a_first] and b[b_first]. Comparisons continue + until the null terminating byte '\0' is reached + or until n bytes are compared. + Return Value: Returns 0 if arrays are the + same up to and including the null terminating byte + or up to and including the first n bytes, + whichever comes first. + *******************************************************/ + static int bytencmp + ( + byte a[], + int a_first, + byte b[], + int b_first, + int n + ) + { + int elem; + + for (elem = 0; elem < n; ++elem) + { + /*System.out.print((char) a[a_first + elem]); + System.out.print((char) b[b_first + elem]);*/ + + if ('\0' == a[a_first + elem] && '\0' == b[b_first + elem]) + { + /*System.out.println("return 0");*/ + return 0; + } + if (a[a_first + elem] < b[b_first + elem]) + { + /*System.out.println("return 1");*/ + return 1; + } + else if (a[a_first + elem] > b[b_first + elem]) + { + /*System.out.println("return -1");*/ + return -1; + } + } + + /*System.out.println("return 0");*/ + return 0; + } + + /******************************************************** + Function: charncmp + *******************************************************/ + static int charncmp + ( + char a[], + int a_first, + char b[], + int b_first, + int n + ) + { + int elem; + + for (elem = 0; elem < n; ++elem) + { + if ('\0' == a[a_first + elem] && '\0' == b[b_first + elem]) + { + return 0; + } + if (a[a_first + elem] < b[b_first + elem]) + { + return 1; + } + else if (a[a_first + elem] > b[b_first + elem]) + { + return -1; + } + } + + return 0; + } +} + +/******************************************************** + Class: CError + *******************************************************/ +class CError +{ + /******************************************************** + Function: impos + Description: + *******************************************************/ + static void impos + ( + String message + ) + { + System.out.println("JLex Error: " + message); + } + + /******************************************************** + Constants + Description: Error codes for parse_error(). + *******************************************************/ + static final int E_BADEXPR = 0; + static final int E_PAREN = 1; + static final int E_LENGTH = 2; + static final int E_BRACKET = 3; + static final int E_BOL = 4; + static final int E_CLOSE = 5; + static final int E_NEWLINE = 6; + static final int E_BADMAC = 7; + static final int E_NOMAC = 8; + static final int E_MACDEPTH = 9; + static final int E_INIT = 10; + static final int E_EOF = 11; + static final int E_DIRECT = 12; + static final int E_INTERNAL = 13; + static final int E_STATE = 14; + static final int E_MACDEF = 15; + static final int E_SYNTAX = 16; + static final int E_BRACE = 17; + static final int E_DASH = 18; + static final int E_ZERO = 19; + static final int E_BADCTRL = 20; + + /******************************************************** + Constants + Description: String messages for parse_error(); + *******************************************************/ + static final String errmsg[] = + { + "Malformed regular expression.", + "Missing close parenthesis.", + "Too many regular expressions or expression too long.", + "Missing [ in character class.", + "^ must be at start of expression or after [.", + "+ ? or * must follow an expression or subexpression.", + "Newline in quoted string.", + "Missing } in macro expansion.", + "Macro does not exist.", + "Macro expansions nested too deeply.", + "JLex has not been successfully initialized.", + "Unexpected end-of-file found.", + "Undefined or badly-formed JLex directive.", + "Internal JLex error.", + "Unitialized state name.", + "Badly formed macro definition.", + "Syntax error.", + "Missing brace at start of lexical action.", + "Special character dash - in character class [...] must\n" + + "\tbe preceded by start-of-range character.", + "Zero-length regular expression.", + "Illegal \\^C-style escape sequence (character following caret must\n" + + "\tbe alphabetic).", + }; + + /******************************************************** + Function: parse_error + Description: + *******************************************************/ + static void parse_error + ( + int error_code, + int line_number + ) + { + System.out.println("Error: Parse error at line " + + line_number + "."); + System.out.println("Description: " + errmsg[error_code]); + throw new Error("Parse error."); + } +} + +/******************************************************** + Class: CSet + *******************************************************/ +class CSet +{ + /******************************************************** + Member Variables + *******************************************************/ + private SparseBitSet m_set; + private boolean m_complement; + + /******************************************************** + Function: CSet + *******************************************************/ + CSet + ( + ) + { + m_set = new SparseBitSet(); + m_complement = false; + } + + /******************************************************** + Function: complement + *******************************************************/ + void complement + ( + ) + { + m_complement = true; + } + + /******************************************************** + Function: add + *******************************************************/ + void add + ( + int i + ) + { + m_set.set(i); + } + + /******************************************************** + Function: addncase + *******************************************************/ + void addncase // add, ignoring case. + ( + char c + ) + { + /* Do this in a Unicode-friendly way. */ + /* (note that duplicate adds have no effect) */ + add(c); + add(Character.toLowerCase(c)); + add(Character.toTitleCase(c)); + add(Character.toUpperCase(c)); + } + + /******************************************************** + Function: contains + *******************************************************/ + boolean contains + ( + int i + ) + { + boolean result; + + result = m_set.get(i); + + if (m_complement) + { + return (false == result); + } + + return result; + } + + /******************************************************** + Function: mimic + *******************************************************/ + void mimic + ( + CSet set + ) + { + m_complement = set.m_complement; + m_set = (SparseBitSet) set.m_set.clone(); + } + + /** Map set using character classes [CSA] */ + void map(CSet set, int[] mapping) { + m_complement = set.m_complement; + m_set.clearAll(); + for (Enumeration e=set.m_set.elements(); e.hasMoreElements(); ) { + int old_value =((Integer)e.nextElement()).intValue(); + if (old_value<mapping.length) // skip unmapped characters + m_set.set(mapping[old_value]); + } + } +} + +/******************************************************** + Class: CNfa + *******************************************************/ +class CNfa +{ + /******************************************************** + Member Variables + *******************************************************/ + int m_edge; /* Label for edge type: + character code, + CCL (character class), + [STATE, + SCL (state class),] + EMPTY, + EPSILON. */ + + CSet m_set; /* Set to store character classes. */ + CNfa m_next; /* Next state (or null if none). */ + + CNfa m_next2; /* Another state with type == EPSILON + and null if not used. + The NFA construction should result in two + outgoing edges only if both are EPSILON edges. */ + + CAccept m_accept; /* Set to null if nonaccepting state. */ + int m_anchor; /* Says if and where pattern is anchored. */ + + int m_label; + + SparseBitSet m_states; + + /******************************************************** + Constants + *******************************************************/ + static final int NO_LABEL = -1; + + /******************************************************** + Constants: Edge Types + Note: Edge transitions on one specific character + are labelled with the character Ascii (Unicode) + codes. So none of the constants below should + overlap with the natural character codes. + *******************************************************/ + static final int CCL = -1; + static final int EMPTY = -2; + static final int EPSILON = -3; + + /******************************************************** + Function: CNfa + *******************************************************/ + CNfa + ( + ) + { + m_edge = EMPTY; + m_set = null; + m_next = null; + m_next2 = null; + m_accept = null; + m_anchor = CSpec.NONE; + m_label = NO_LABEL; + m_states = null; + } + + /******************************************************** + Function: mimic + Description: Converts this NFA state into a copy of + the input one. + *******************************************************/ + void mimic + ( + CNfa nfa + ) + { + m_edge = nfa.m_edge; + + if (null != nfa.m_set) + { + if (null == m_set) + { + m_set = new CSet(); + } + m_set.mimic(nfa.m_set); + } + else + { + m_set = null; + } + + m_next = nfa.m_next; + m_next2 = nfa.m_next2; + m_accept = nfa.m_accept; + m_anchor = nfa.m_anchor; + + if (null != nfa.m_states) + { + m_states = (SparseBitSet) nfa.m_states.clone(); + } + else + { + m_states = null; + } + } +} + +/*************************************************************** + Class: CLexGen + **************************************************************/ +class CLexGen +{ + /*************************************************************** + Member Variables + **************************************************************/ + private java.io.Reader m_instream; /* JLex specification file. */ + private java.io.PrintWriter m_outstream; /* Lexical analyzer source file. */ + + private CInput m_input; /* Input buffer class. */ + + private Hashtable m_tokens; /* Hashtable that maps characters to their + corresponding lexical code for + the internal lexical analyzer. */ + private CSpec m_spec; /* Spec class holds information + about the generated lexer. */ + private boolean m_init_flag; /* Flag set to true only upon + successful initialization. */ + + private CMakeNfa m_makeNfa; /* NFA machine generator module. */ + private CNfa2Dfa m_nfa2dfa; /* NFA to DFA machine (transition table) + conversion module. */ + private CMinimize m_minimize; /* Transition table compressor. */ + private CSimplifyNfa m_simplifyNfa; /* NFA simplifier using char classes */ + private CEmit m_emit; /* Output module that emits source code + into the generated lexer file. */ + + + /******************************************************** + Constants + *******************************************************/ + private static final boolean ERROR = false; + private static final boolean NOT_ERROR = true; + private static final int BUFFER_SIZE = 1024; + + /******************************************************** + Constants: Token Types + *******************************************************/ + static final int EOS = 1; + static final int ANY = 2; + static final int AT_BOL = 3; + static final int AT_EOL = 4; + static final int CCL_END = 5; + static final int CCL_START = 6; + static final int CLOSE_CURLY = 7; + static final int CLOSE_PAREN = 8; + static final int CLOSURE = 9; + static final int DASH = 10; + static final int END_OF_INPUT = 11; + static final int L = 12; + static final int OPEN_CURLY = 13; + static final int OPEN_PAREN = 14; + static final int OPTIONAL = 15; + static final int OR = 16; + static final int PLUS_CLOSE = 17; + + /*************************************************************** + Function: CLexGen + **************************************************************/ + CLexGen + ( + String filename + ) + throws java.io.FileNotFoundException, java.io.IOException + { + /* Successful initialization flag. */ + m_init_flag = false; + + /* Open input stream. */ + m_instream = new java.io.FileReader(filename); + if (null == m_instream) + { + System.out.println("Error: Unable to open input file " + + filename + "."); + return; + } + + /* Open output stream. */ + m_outstream + = new java.io.PrintWriter(new java.io.BufferedWriter( + new java.io.FileWriter(filename + ".java"))); + if (null == m_outstream) + { + System.out.println("Error: Unable to open output file " + + filename + ".java."); + return; + } + + /* Create input buffer class. */ + m_input = new CInput(m_instream); + + /* Initialize character hash table. */ + m_tokens = new Hashtable(); + m_tokens.put(new Character('$'),new Integer(AT_EOL)); + m_tokens.put(new Character('('),new Integer(OPEN_PAREN)); + m_tokens.put(new Character(')'),new Integer(CLOSE_PAREN)); + m_tokens.put(new Character('*'),new Integer(CLOSURE)); + m_tokens.put(new Character('+'),new Integer(PLUS_CLOSE)); + m_tokens.put(new Character('-'),new Integer(DASH)); + m_tokens.put(new Character('.'),new Integer(ANY)); + m_tokens.put(new Character('?'),new Integer(OPTIONAL)); + m_tokens.put(new Character('['),new Integer(CCL_START)); + m_tokens.put(new Character(']'),new Integer(CCL_END)); + m_tokens.put(new Character('^'),new Integer(AT_BOL)); + m_tokens.put(new Character('{'),new Integer(OPEN_CURLY)); + m_tokens.put(new Character('|'),new Integer(OR)); + m_tokens.put(new Character('}'),new Integer(CLOSE_CURLY)); + + /* Initialize spec structure. */ + m_spec = new CSpec(this); + + /* Nfa to dfa converter. */ + m_nfa2dfa = new CNfa2Dfa(); + m_minimize = new CMinimize(); + m_makeNfa = new CMakeNfa(); + m_simplifyNfa = new CSimplifyNfa(); + + m_emit = new CEmit(); + + /* Successful initialization flag. */ + m_init_flag = true; + } + + /*************************************************************** + Function: generate + Description: + **************************************************************/ + void generate + ( + ) + throws java.io.IOException, java.io.FileNotFoundException + { + if (false == m_init_flag) + { + CError.parse_error(CError.E_INIT,0); + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != this); + CUtility.ASSERT(null != m_outstream); + CUtility.ASSERT(null != m_input); + CUtility.ASSERT(null != m_tokens); + CUtility.ASSERT(null != m_spec); + CUtility.ASSERT(m_init_flag); + } + + /*m_emit.emit_imports(m_spec,m_outstream);*/ + + if (m_spec.m_verbose) + { + System.out.println("Processing first section -- user code."); + } + userCode(); + if (m_input.m_eof_reached) + { + CError.parse_error(CError.E_EOF,m_input.m_line_number); + } + + if (m_spec.m_verbose) + { + System.out.println("Processing second section -- " + + "JLex declarations."); + } + userDeclare(); + if (m_input.m_eof_reached) + { + CError.parse_error(CError.E_EOF,m_input.m_line_number); + } + + if (m_spec.m_verbose) + { + System.out.println("Processing third section -- lexical rules."); + } + userRules(); + if (CUtility.DO_DEBUG) + { + print_header(); + } + + if (m_spec.m_verbose) + { + System.out.println("Outputting lexical analyzer code."); + } + m_emit.emit(m_spec,m_outstream); + + if (m_spec.m_verbose && true == CUtility.OLD_DUMP_DEBUG) + { + details(); + } + + m_outstream.close(); + } + + /*************************************************************** + Function: userCode + Description: Process first section of specification, + echoing it into output file. + **************************************************************/ + private void userCode + ( + ) + throws java.io.IOException + { + int count = 0; + + if (false == m_init_flag) + { + CError.parse_error(CError.E_INIT,0); + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != this); + CUtility.ASSERT(null != m_outstream); + CUtility.ASSERT(null != m_input); + CUtility.ASSERT(null != m_tokens); + CUtility.ASSERT(null != m_spec); + } + + if (m_input.m_eof_reached) + { + CError.parse_error(CError.E_EOF,0); + } + + while (true) + { + if (m_input.getLine()) + { + /* Eof reached. */ + CError.parse_error(CError.E_EOF,0); + } + + if (2 <= m_input.m_line_read + && '%' == m_input.m_line[0] + && '%' == m_input.m_line[1]) + { + /* Discard remainder of line. */ + m_input.m_line_index = m_input.m_line_read; + return; + } + + m_outstream.print(new String(m_input.m_line,0, + m_input.m_line_read)); + } + } + + /*************************************************************** + Function: getName + **************************************************************/ + private char[] getName + ( + ) + { + char buffer[]; + int elem; + + /* Skip white space. */ + while (m_input.m_line_index < m_input.m_line_read + && true == CUtility.isspace(m_input.m_line[m_input.m_line_index])) + { + ++m_input.m_line_index; + } + + /* No name? */ + if (m_input.m_line_index >= m_input.m_line_read) + { + CError.parse_error(CError.E_DIRECT,0); + } + + /* Determine length. */ + elem = m_input.m_line_index; + while (elem < m_input.m_line_read + && false == CUtility.isnewline(m_input.m_line[elem])) + { + ++elem; + } + + /* Allocate non-terminated buffer of exact length. */ + buffer = new char[elem - m_input.m_line_index]; + + /* Copy. */ + elem = 0; + while (m_input.m_line_index < m_input.m_line_read + && false == CUtility.isnewline(m_input.m_line[m_input.m_line_index])) + { + buffer[elem] = m_input.m_line[m_input.m_line_index]; + ++elem; + ++m_input.m_line_index; + } + + return buffer; + } + + private final int CLASS_CODE = 0; + private final int INIT_CODE = 1; + private final int EOF_CODE = 2; + private final int INIT_THROW_CODE = 3; + private final int YYLEX_THROW_CODE = 4; + private final int EOF_THROW_CODE = 5; + private final int EOF_VALUE_CODE = 6; + + /*************************************************************** + Function: packCode + Description: + **************************************************************/ + private char[] packCode + ( + char start_dir[], + char end_dir[], + char prev_code[], + int prev_read, + int specified + ) + throws java.io.IOException + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(INIT_CODE == specified + || CLASS_CODE == specified + || EOF_CODE == specified + || EOF_VALUE_CODE == specified + || INIT_THROW_CODE == specified + || YYLEX_THROW_CODE == specified + || EOF_THROW_CODE == specified); + } + + if (0 != CUtility.charncmp(m_input.m_line, + 0, + start_dir, + 0, + start_dir.length - 1)) + { + CError.parse_error(CError.E_INTERNAL,0); + } + + if (null == prev_code) + { + prev_code = new char[BUFFER_SIZE]; + prev_read = 0; + } + + if (prev_read >= prev_code.length) + { + prev_code = CUtility.doubleSize(prev_code); + } + + m_input.m_line_index = start_dir.length - 1; + while (true) + { + while (m_input.m_line_index >= m_input.m_line_read) + { + if (m_input.getLine()) + { + CError.parse_error(CError.E_EOF,m_input.m_line_number); + } + + if (0 == CUtility.charncmp(m_input.m_line, + 0, + end_dir, + 0, + end_dir.length - 1)) + { + m_input.m_line_index = end_dir.length - 1; + + switch (specified) + { + case CLASS_CODE: + m_spec.m_class_read = prev_read; + break; + + case INIT_CODE: + m_spec.m_init_read = prev_read; + break; + + case EOF_CODE: + m_spec.m_eof_read = prev_read; + break; + + case EOF_VALUE_CODE: + m_spec.m_eof_value_read = prev_read; + break; + + case INIT_THROW_CODE: + m_spec.m_init_throw_read = prev_read; + break; + + case YYLEX_THROW_CODE: + m_spec.m_yylex_throw_read = prev_read; + break; + + case EOF_THROW_CODE: + m_spec.m_eof_throw_read = prev_read; + break; + + default: + CError.parse_error(CError.E_INTERNAL,m_input.m_line_number); + break; + } + + return prev_code; + } + } + + while (m_input.m_line_index < m_input.m_line_read) + { + prev_code[prev_read] = m_input.m_line[m_input.m_line_index]; + ++prev_read; + ++m_input.m_line_index; + + if (prev_read >= prev_code.length) + { + prev_code = CUtility.doubleSize(prev_code); + } + } + } + } + + /*************************************************************** + Member Variables: JLex directives. + **************************************************************/ + private char m_state_dir[] = { + '%', 's', 't', + 'a', 't', 'e', + '\0' + }; + + private char m_char_dir[] = { + '%', 'c', 'h', + 'a', 'r', + '\0' + }; + + private char m_line_dir[] = { + '%', 'l', 'i', + 'n', 'e', + '\0' + }; + + private char m_cup_dir[] = { + '%', 'c', 'u', + 'p', + '\0' + }; + + private char m_class_dir[] = { + '%', 'c', 'l', + 'a', 's', 's', + '\0' + }; + + private char m_implements_dir[] = { + '%', 'i', 'm', 'p', 'l', 'e', 'm', 'e', 'n', 't', 's', + '\0' + }; + + private char m_function_dir[] = { + '%', 'f', 'u', + 'n', 'c', 't', + 'i', 'o', 'n', + '\0' + }; + + private char m_type_dir[] = { + '%', 't', 'y', + 'p', 'e', + '\0' + }; + + private char m_integer_dir[] = { + '%', 'i', 'n', + 't', 'e', 'g', + 'e', 'r', + '\0' + }; + + private char m_intwrap_dir[] = { + '%', 'i', 'n', + 't', 'w', 'r', + 'a', 'p', + '\0' + }; + + private char m_full_dir[] = { + '%', 'f', 'u', + 'l', 'l', + '\0' + }; + + private char m_unicode_dir[] = { + '%', 'u', 'n', + 'i', 'c', 'o', + 'd', 'e', + '\0' + }; + + private char m_ignorecase_dir[] = { + '%', 'i', 'g', + 'n', 'o', 'r', + 'e', 'c', 'a', + 's', 'e', + '\0' + }; + + private char m_notunix_dir[] = { + '%', 'n', 'o', + 't', 'u', 'n', + 'i', 'x', + '\0' + }; + + private char m_init_code_dir[] = { + '%', 'i', 'n', + 'i', 't', '{', + '\0' + }; + + private char m_init_code_end_dir[] = { + '%', 'i', 'n', + 'i', 't', '}', + '\0' + }; + + private char m_init_throw_code_dir[] = { + '%', 'i', 'n', + 'i', 't', 't', + 'h', 'r', 'o', + 'w', '{', + '\0' + }; + + private char m_init_throw_code_end_dir[] = { + '%', 'i', 'n', + 'i', 't', 't', + 'h', 'r', 'o', + 'w', '}', + '\0' + }; + + private char m_yylex_throw_code_dir[] = { + '%', 'y', 'y', 'l', + 'e', 'x', 't', + 'h', 'r', 'o', + 'w', '{', + '\0' + }; + + private char m_yylex_throw_code_end_dir[] = { + '%', 'y', 'y', 'l', + 'e', 'x', 't', + 'h', 'r', 'o', + 'w', '}', + '\0' + }; + + private char m_eof_code_dir[] = { + '%', 'e', 'o', + 'f', '{', + '\0' + }; + + private char m_eof_code_end_dir[] = { + '%', 'e', 'o', + 'f', '}', + '\0' + }; + + private char m_eof_value_code_dir[] = { + '%', 'e', 'o', + 'f', 'v', 'a', + 'l', '{', + '\0' + }; + + private char m_eof_value_code_end_dir[] = { + '%', 'e', 'o', + 'f', 'v', 'a', + 'l', '}', + '\0' + }; + + private char m_eof_throw_code_dir[] = { + '%', 'e', 'o', + 'f', 't', 'h', + 'r', 'o', 'w', + '{', + '\0' + }; + + private char m_eof_throw_code_end_dir[] = { + '%', 'e', 'o', + 'f', 't', 'h', + 'r', 'o', 'w', + '}', + '\0' + }; + + private char m_class_code_dir[] = { + '%', '{', + '\0' + }; + + private char m_class_code_end_dir[] = { + '%', '}', + '\0' + }; + + private char m_yyeof_dir[] = { + '%', 'y', 'y', + 'e', 'o', 'f', + '\0' + }; + + private char m_public_dir[] = { + '%', 'p', 'u', + 'b', 'l', 'i', + 'c', '\0' + }; + + /*************************************************************** + Function: userDeclare + Description: + **************************************************************/ + private void userDeclare + ( + ) + throws java.io.IOException + { + int elem; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != this); + CUtility.ASSERT(null != m_outstream); + CUtility.ASSERT(null != m_input); + CUtility.ASSERT(null != m_tokens); + CUtility.ASSERT(null != m_spec); + } + + if (m_input.m_eof_reached) + { + /* End-of-file. */ + CError.parse_error(CError.E_EOF, + m_input.m_line_number); + } + + while (false == m_input.getLine()) + { + /* Look for double percent. */ + if (2 <= m_input.m_line_read + && '%' == m_input.m_line[0] + && '%' == m_input.m_line[1]) + { + /* Mess around with line. */ + m_input.m_line_read -= 2; + System.arraycopy(m_input.m_line, 2, + m_input.m_line, 0, m_input.m_line_read); + + m_input.m_pushback_line = true; + /* Check for and discard empty line. */ + if (0 == m_input.m_line_read + || '\n' == m_input.m_line[0]) + { + m_input.m_pushback_line = false; + } + + return; + } + + if (0 == m_input.m_line_read) + { + continue; + } + + if ('%' == m_input.m_line[0]) + { + /* Special lex declarations. */ + if (1 >= m_input.m_line_read) + { + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + continue; + } + + switch (m_input.m_line[1]) + { + case '{': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_class_code_dir, + 0, + m_class_code_dir.length - 1)) + { + m_spec.m_class_code = packCode(m_class_code_dir, + m_class_code_end_dir, + m_spec.m_class_code, + m_spec.m_class_read, + CLASS_CODE); + break; + } + + /* Bad directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 'c': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_char_dir, + 0, + m_char_dir.length - 1)) + { + /* Set line counting to ON. */ + m_input.m_line_index = m_char_dir.length; + m_spec.m_count_chars = true; + break; + } + else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_class_dir, + 0, + m_class_dir.length - 1)) + { + m_input.m_line_index = m_class_dir.length; + m_spec.m_class_name = getName(); + break; + } + else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_cup_dir, + 0, + m_cup_dir.length - 1)) + { + /* Set Java CUP compatibility to ON. */ + m_input.m_line_index = m_cup_dir.length; + m_spec.m_cup_compatible = true; + // this is what %cup does: [CSA, 27-Jul-1999] + m_spec.m_implements_name = + "java_cup.runtime.Scanner".toCharArray(); + m_spec.m_function_name = + "next_token".toCharArray(); + m_spec.m_type_name = + "java_cup.runtime.Symbol".toCharArray(); + break; + } + + /* Bad directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 'e': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_eof_code_dir, + 0, + m_eof_code_dir.length - 1)) + { + m_spec.m_eof_code = packCode(m_eof_code_dir, + m_eof_code_end_dir, + m_spec.m_eof_code, + m_spec.m_eof_read, + EOF_CODE); + break; + } + else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_eof_value_code_dir, + 0, + m_eof_value_code_dir.length - 1)) + { + m_spec.m_eof_value_code = packCode(m_eof_value_code_dir, + m_eof_value_code_end_dir, + m_spec.m_eof_value_code, + m_spec.m_eof_value_read, + EOF_VALUE_CODE); + break; + } + else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_eof_throw_code_dir, + 0, + m_eof_throw_code_dir.length - 1)) + { + m_spec.m_eof_throw_code = packCode(m_eof_throw_code_dir, + m_eof_throw_code_end_dir, + m_spec.m_eof_throw_code, + m_spec.m_eof_throw_read, + EOF_THROW_CODE); + break; + } + + /* Bad directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 'f': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_function_dir, + 0, + m_function_dir.length - 1)) + { + /* Set line counting to ON. */ + m_input.m_line_index = m_function_dir.length; + m_spec.m_function_name = getName(); + break; + } + else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_full_dir, + 0, + m_full_dir.length - 1)) + { + m_input.m_line_index = m_full_dir.length; + m_spec.m_dtrans_ncols = CUtility.MAX_EIGHT_BIT + 1; + break; + } + + /* Bad directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 'i': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_integer_dir, + 0, + m_integer_dir.length - 1)) + { + /* Set line counting to ON. */ + m_input.m_line_index = m_integer_dir.length; + m_spec.m_integer_type = true; + break; + } + else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_intwrap_dir, + 0, + m_intwrap_dir.length - 1)) + { + /* Set line counting to ON. */ + m_input.m_line_index = m_integer_dir.length; + m_spec.m_intwrap_type = true; + break; + } + else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_init_code_dir, + 0, + m_init_code_dir.length - 1)) + { + m_spec.m_init_code = packCode(m_init_code_dir, + m_init_code_end_dir, + m_spec.m_init_code, + m_spec.m_init_read, + INIT_CODE); + break; + } + else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_init_throw_code_dir, + 0, + m_init_throw_code_dir.length - 1)) + { + m_spec.m_init_throw_code = packCode(m_init_throw_code_dir, + m_init_throw_code_end_dir, + m_spec.m_init_throw_code, + m_spec.m_init_throw_read, + INIT_THROW_CODE); + break; + } + else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_implements_dir, + 0, + m_implements_dir.length - 1)) + { + m_input.m_line_index = m_implements_dir.length; + m_spec.m_implements_name = getName(); + break; + } + else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_ignorecase_dir, + 0, + m_ignorecase_dir.length-1)) + { + /* Set m_ignorecase to ON. */ + m_input.m_line_index = m_ignorecase_dir.length; + m_spec.m_ignorecase = true; + break; + } + + /* Bad directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 'l': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_line_dir, + 0, + m_line_dir.length - 1)) + { + /* Set line counting to ON. */ + m_input.m_line_index = m_line_dir.length; + m_spec.m_count_lines = true; + break; + } + + /* Bad directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 'n': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_notunix_dir, + 0, + m_notunix_dir.length - 1)) + { + /* Set line counting to ON. */ + m_input.m_line_index = m_notunix_dir.length; + m_spec.m_unix = false; + break; + } + + /* Bad directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 'p': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_public_dir, + 0, + m_public_dir.length - 1)) + { + /* Set public flag. */ + m_input.m_line_index = m_public_dir.length; + m_spec.m_public = true; + break; + } + + /* Bad directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 's': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_state_dir, + 0, + m_state_dir.length - 1)) + { + /* Recognize state list. */ + m_input.m_line_index = m_state_dir.length; + saveStates(); + break; + } + + /* Undefined directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 't': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_type_dir, + 0, + m_type_dir.length - 1)) + { + /* Set Java CUP compatibility to ON. */ + m_input.m_line_index = m_type_dir.length; + m_spec.m_type_name = getName(); + break; + } + + /* Undefined directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 'u': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_unicode_dir, + 0, + m_unicode_dir.length - 1)) + { + m_input.m_line_index = m_unicode_dir.length; + m_spec.m_dtrans_ncols= CUtility.MAX_SIXTEEN_BIT + 1; + break; + } + + /* Bad directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + case 'y': + if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_yyeof_dir, + 0, + m_yyeof_dir.length - 1)) + { + m_input.m_line_index = m_yyeof_dir.length; + m_spec.m_yyeof = true; + break; + } else if (0 == CUtility.charncmp(m_input.m_line, + 0, + m_yylex_throw_code_dir, + 0, + m_yylex_throw_code_dir.length - 1)) + { + m_spec.m_yylex_throw_code = packCode(m_yylex_throw_code_dir, + m_yylex_throw_code_end_dir, + m_spec.m_yylex_throw_code, + m_spec.m_yylex_throw_read, + YYLEX_THROW_CODE); + break; + } + + + /* Bad directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + + default: + /* Undefined directive. */ + CError.parse_error(CError.E_DIRECT, + m_input.m_line_number); + break; + } + } + else + { + /* Regular expression macro. */ + m_input.m_line_index = 0; + saveMacro(); + } + + if (CUtility.OLD_DEBUG) + { + System.out.println("Line number " + + m_input.m_line_number + ":"); + System.out.print(new String(m_input.m_line, + 0,m_input.m_line_read)); + } + } + } + + /*************************************************************** + Function: userRules + Description: Processes third section of JLex + specification and creates minimized transition table. + **************************************************************/ + private void userRules + ( + ) + throws java.io.IOException + { + int code; + + if (false == m_init_flag) + { + CError.parse_error(CError.E_INIT,0); + } + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != this); + CUtility.ASSERT(null != m_outstream); + CUtility.ASSERT(null != m_input); + CUtility.ASSERT(null != m_tokens); + CUtility.ASSERT(null != m_spec); + } + + /* UNDONE: Need to handle states preceding rules. */ + + if (m_spec.m_verbose) + { + System.out.println("Creating NFA machine representation."); + } + m_makeNfa.allocate_BOL_EOF(m_spec); + m_makeNfa.thompson(this,m_spec,m_input); + + m_simplifyNfa.simplify(m_spec); + + /*print_nfa();*/ + + if (CUtility.DEBUG) + { + CUtility.ASSERT(END_OF_INPUT == m_spec.m_current_token); + } + + if (m_spec.m_verbose) + { + System.out.println("Creating DFA transition table."); + } + m_nfa2dfa.make_dfa(this,m_spec); + + if (CUtility.FOODEBUG) { + print_header(); + } + + if (m_spec.m_verbose) + { + System.out.println("Minimizing DFA transition table."); + } + m_minimize.min_dfa(m_spec); + } + + /*************************************************************** + Function: printccl + Description: Debugging routine that outputs readable form + of character class. + **************************************************************/ + private void printccl + ( + CSet set + ) + { + int i; + + System.out.print(" ["); + for (i = 0; i < m_spec.m_dtrans_ncols; ++i) + { + if (set.contains(i)) + { + System.out.print(interp_int(i)); + } + } + System.out.print(']'); + } + + /*************************************************************** + Function: plab + Description: + **************************************************************/ + private String plab + ( + CNfa state + ) + { + int index; + + if (null == state) + { + return (new String("--")); + } + + index = m_spec.m_nfa_states.indexOf(state); + + return ((new Integer(index)).toString()); + } + + /*************************************************************** + Function: interp_int + Description: + **************************************************************/ + private String interp_int + ( + int i + ) + { + switch (i) + { + case (int) '\b': + return (new String("\\b")); + + case (int) '\t': + return (new String("\\t")); + + case (int) '\n': + return (new String("\\n")); + + case (int) '\f': + return (new String("\\f")); + + case (int) '\r': + return (new String("\\r")); + + case (int) ' ': + return (new String("\\ ")); + + default: + return ((new Character((char) i)).toString()); + } + } + + /*************************************************************** + Function: print_nfa + Description: + **************************************************************/ + void print_nfa + ( + ) + { + int elem; + CNfa nfa; + int size; + Enumeration states; + Integer index; + int i; + int j; + int vsize; + String state; + + System.out.println("--------------------- NFA -----------------------"); + + size = m_spec.m_nfa_states.size(); + for (elem = 0; elem < size; ++elem) + { + nfa = (CNfa) m_spec.m_nfa_states.elementAt(elem); + + System.out.print("Nfa state " + plab(nfa) + ": "); + + if (null == nfa.m_next) + { + System.out.print("(TERMINAL)"); + } + else + { + System.out.print("--> " + plab(nfa.m_next)); + System.out.print("--> " + plab(nfa.m_next2)); + + switch (nfa.m_edge) + { + case CNfa.CCL: + printccl(nfa.m_set); + break; + + case CNfa.EPSILON: + System.out.print(" EPSILON "); + break; + + default: + System.out.print(" " + interp_int(nfa.m_edge)); + break; + } + } + + if (0 == elem) + { + System.out.print(" (START STATE)"); + } + + if (null != nfa.m_accept) + { + System.out.print(" accepting " + + ((0 != (nfa.m_anchor & CSpec.START)) ? "^" : "") + + "<" + + (new String(nfa.m_accept.m_action,0, + nfa.m_accept.m_action_read)) + + ">" + + ((0 != (nfa.m_anchor & CSpec.END)) ? "$" : "")); + } + + System.out.println(); + } + + states = m_spec.m_states.keys(); + while (states.hasMoreElements()) + { + state = (String) states.nextElement(); + index = (Integer) m_spec.m_states.get(state); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != state); + CUtility.ASSERT(null != index); + } + + System.out.println("State \"" + state + + "\" has identifying index " + + index.toString() + "."); + System.out.print("\tStart states of matching rules: "); + + i = index.intValue(); + vsize = m_spec.m_state_rules[i].size(); + + for (j = 0; j < vsize; ++j) + { + nfa = (CNfa) m_spec.m_state_rules[i].elementAt(j); + + System.out.print(m_spec.m_nfa_states.indexOf(nfa) + " "); + } + + System.out.println(); + } + + System.out.println("-------------------- NFA ----------------------"); + } + + /*************************************************************** + Function: getStates + Description: Parses the state area of a rule, + from the beginning of a line. + < state1, state2 ... > regular_expression { action } + Returns null on only EOF. Returns all_states, + initialied properly to correspond to all states, + if no states are found. + Special Notes: This function treats commas as optional + and permits states to be spread over multiple lines. + **************************************************************/ + private SparseBitSet all_states = null; + SparseBitSet getStates + ( + ) + throws java.io.IOException + { + int start_state; + int count_state; + SparseBitSet states; + String name; + Integer index; + int i; + int size; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != this); + CUtility.ASSERT(null != m_outstream); + CUtility.ASSERT(null != m_input); + CUtility.ASSERT(null != m_tokens); + CUtility.ASSERT(null != m_spec); + } + + states = null; + + /* Skip white space. */ + while (CUtility.isspace(m_input.m_line[m_input.m_line_index])) + { + ++m_input.m_line_index; + + while (m_input.m_line_index >= m_input.m_line_read) + { + /* Must just be an empty line. */ + if (m_input.getLine()) + { + /* EOF found. */ + return null; + } + } + } + + /* Look for states. */ + if ('<' == m_input.m_line[m_input.m_line_index]) + { + ++m_input.m_line_index; + + states = new SparseBitSet(); + + /* Parse states. */ + while (true) + { + /* We may have reached the end of the line. */ + while (m_input.m_line_index >= m_input.m_line_read) + { + if (m_input.getLine()) + { + /* EOF found. */ + CError.parse_error(CError.E_EOF,m_input.m_line_number); + return states; + } + } + + while (true) + { + /* Skip white space. */ + while (CUtility.isspace(m_input.m_line[m_input.m_line_index])) + { + ++m_input.m_line_index; + + while (m_input.m_line_index >= m_input.m_line_read) + { + if (m_input.getLine()) + { + /* EOF found. */ + CError.parse_error(CError.E_EOF,m_input.m_line_number); + return states; + } + } + } + + if (',' != m_input.m_line[m_input.m_line_index]) + { + break; + } + + ++m_input.m_line_index; + } + + if ('>' == m_input.m_line[m_input.m_line_index]) + { + ++m_input.m_line_index; + if (m_input.m_line_index < m_input.m_line_read) + { + m_advance_stop = true; + } + return states; + } + + /* Read in state name. */ + start_state = m_input.m_line_index; + while (false == CUtility.isspace(m_input.m_line[m_input.m_line_index]) + && ',' != m_input.m_line[m_input.m_line_index] + && '>' != m_input.m_line[m_input.m_line_index]) + { + ++m_input.m_line_index; + + if (m_input.m_line_index >= m_input.m_line_read) + { + /* End of line means end of state name. */ + break; + } + } + count_state = m_input.m_line_index - start_state; + + /* Save name after checking definition. */ + name = new String(m_input.m_line, + start_state, + count_state); + index = (Integer) m_spec.m_states.get(name); + if (null == index) + { + /* Uninitialized state. */ + System.out.println("Uninitialized State Name: " + name); + CError.parse_error(CError.E_STATE,m_input.m_line_number); + } + states.set(index.intValue()); + } + } + + if (null == all_states) + { + all_states = new SparseBitSet(); + + size = m_spec.m_states.size(); + for (i = 0; i < size; ++i) + { + all_states.set(i); + } + } + + if (m_input.m_line_index < m_input.m_line_read) + { + m_advance_stop = true; + } + return all_states; + } + + /******************************************************** + Function: expandMacro + Description: Returns false on error, true otherwise. + *******************************************************/ + private boolean expandMacro + ( + ) + { + int elem; + int start_macro; + int end_macro; + int start_name; + int count_name; + String def; + int def_elem; + String name; + char replace[]; + int rep_elem; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != this); + CUtility.ASSERT(null != m_outstream); + CUtility.ASSERT(null != m_input); + CUtility.ASSERT(null != m_tokens); + CUtility.ASSERT(null != m_spec); + } + + /* Check for macro. */ + if ('{' != m_input.m_line[m_input.m_line_index]) + { + CError.parse_error(CError.E_INTERNAL,m_input.m_line_number); + return ERROR; + } + + start_macro = m_input.m_line_index; + elem = m_input.m_line_index + 1; + if (elem >= m_input.m_line_read) + { + CError.impos("Unfinished macro name"); + return ERROR; + } + + /* Get macro name. */ + start_name = elem; + while ('}' != m_input.m_line[elem]) + { + ++elem; + if (elem >= m_input.m_line_read) + { + CError.impos("Unfinished macro name at line " + + m_input.m_line_number); + return ERROR; + } + } + count_name = elem - start_name; + end_macro = elem; + + /* Check macro name. */ + if (0 == count_name) + { + CError.impos("Nonexistent macro name"); + return ERROR; + } + + /* Debug checks. */ + if (CUtility.DEBUG) + { + CUtility.ASSERT(0 < count_name); + } + + /* Retrieve macro definition. */ + name = new String(m_input.m_line,start_name,count_name); + def = (String) m_spec.m_macros.get(name); + if (null == def) + { + /*CError.impos("Undefined macro \"" + name + "\".");*/ + System.out.println("Error: Undefined macro \"" + name + "\"."); + CError.parse_error(CError.E_NOMAC, m_input.m_line_number); + return ERROR; + } + if (CUtility.OLD_DUMP_DEBUG) + { + System.out.println("expanded escape: " + def); + } + + /* Replace macro in new buffer, + beginning by copying first part of line buffer. */ + replace = new char[m_input.m_line.length]; + for (rep_elem = 0; rep_elem < start_macro; ++rep_elem) + { + replace[rep_elem] = m_input.m_line[rep_elem]; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(rep_elem < replace.length); + } + } + + /* Copy macro definition. */ + if (rep_elem >= replace.length) + { + replace = CUtility.doubleSize(replace); + } + for (def_elem = 0; def_elem < def.length(); ++def_elem) + { + replace[rep_elem] = def.charAt(def_elem); + + ++rep_elem; + if (rep_elem >= replace.length) + { + replace = CUtility.doubleSize(replace); + } + } + + /* Copy last part of line. */ + if (rep_elem >= replace.length) + { + replace = CUtility.doubleSize(replace); + } + for (elem = end_macro + 1; elem < m_input.m_line_read; ++elem) + { + replace[rep_elem] = m_input.m_line[elem]; + + ++rep_elem; + if (rep_elem >= replace.length) + { + replace = CUtility.doubleSize(replace); + } + } + + /* Replace buffer. */ + m_input.m_line = replace; + m_input.m_line_read = rep_elem; + + if (CUtility.OLD_DEBUG) + { + System.out.println(new String(m_input.m_line,0,m_input.m_line_read)); + } + return NOT_ERROR; + } + + /*************************************************************** + Function: saveMacro + Description: Saves macro definition of form: + macro_name = macro_definition + **************************************************************/ + private void saveMacro + ( + ) + { + int elem; + int start_name; + int count_name; + int start_def; + int count_def; + boolean saw_escape; + boolean in_quote; + boolean in_ccl; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != this); + CUtility.ASSERT(null != m_outstream); + CUtility.ASSERT(null != m_input); + CUtility.ASSERT(null != m_tokens); + CUtility.ASSERT(null != m_spec); + } + + /* Macro declarations are of the following form: + macro_name macro_definition */ + + elem = 0; + + /* Skip white space preceding macro name. */ + while (CUtility.isspace(m_input.m_line[elem])) + { + ++elem; + if (elem >= m_input.m_line_read) + { + /* End of line has been reached, + and line was found to be empty. */ + return; + } + } + + /* Read macro name. */ + start_name = elem; + while (false == CUtility.isspace(m_input.m_line[elem]) + && '=' != m_input.m_line[elem]) + { + ++elem; + if (elem >= m_input.m_line_read) + { + /* Macro name but no associated definition. */ + CError.parse_error(CError.E_MACDEF,m_input.m_line_number); + } + } + count_name = elem - start_name; + + /* Check macro name. */ + if (0 == count_name) + { + /* Nonexistent macro name. */ + CError.parse_error(CError.E_MACDEF,m_input.m_line_number); + } + + /* Skip white space between name and definition. */ + while (CUtility.isspace(m_input.m_line[elem])) + { + ++elem; + if (elem >= m_input.m_line_read) + { + /* Macro name but no associated definition. */ + CError.parse_error(CError.E_MACDEF,m_input.m_line_number); + } + } + + if ('=' == m_input.m_line[elem]) + { + ++elem; + if (elem >= m_input.m_line_read) + { + /* Macro name but no associated definition. */ + CError.parse_error(CError.E_MACDEF,m_input.m_line_number); + } + } + else /* macro definition without = */ + CError.parse_error(CError.E_MACDEF,m_input.m_line_number); + + /* Skip white space between name and definition. */ + while (CUtility.isspace(m_input.m_line[elem])) + { + ++elem; + if (elem >= m_input.m_line_read) + { + /* Macro name but no associated definition. */ + CError.parse_error(CError.E_MACDEF,m_input.m_line_number); + } + } + + /* Read macro definition. */ + start_def = elem; + in_quote = false; + in_ccl = false; + saw_escape = false; + while (false == CUtility.isspace(m_input.m_line[elem]) + || true == in_quote + || true == in_ccl + || true == saw_escape) + { + if ('\"' == m_input.m_line[elem] && false == saw_escape) + { + in_quote = !in_quote; + } + + if ('\\' == m_input.m_line[elem] && false == saw_escape) + { + saw_escape = true; + } + else + { + saw_escape = false; + } + if (false == saw_escape && false == in_quote) { // CSA, 24-jul-99 + if ('[' == m_input.m_line[elem] && false == in_ccl) + in_ccl = true; + if (']' == m_input.m_line[elem] && true == in_ccl) + in_ccl = false; + } + + ++elem; + if (elem >= m_input.m_line_read) + { + /* End of line. */ + break; + } + } + count_def = elem - start_def; + + /* Check macro definition. */ + if (0 == count_def) + { + /* Nonexistent macro name. */ + CError.parse_error(CError.E_MACDEF,m_input.m_line_number); + } + + /* Debug checks. */ + if (CUtility.DEBUG) + { + CUtility.ASSERT(0 < count_def); + CUtility.ASSERT(0 < count_name); + CUtility.ASSERT(null != m_spec.m_macros); + } + + if (CUtility.OLD_DEBUG) + { + System.out.println("macro name \"" + + new String(m_input.m_line,start_name,count_name) + + "\"."); + System.out.println("macro definition \"" + + new String(m_input.m_line,start_def,count_def) + + "\"."); + } + + /* Add macro name and definition to table. */ + m_spec.m_macros.put(new String(m_input.m_line,start_name,count_name), + new String(m_input.m_line,start_def,count_def)); + } + + /*************************************************************** + Function: saveStates + Description: Takes state declaration and makes entries + for them in state hashtable in CSpec structure. + State declaration should be of the form: + %state name0[, name1, name2 ...] + (But commas are actually optional as long as there is + white space in between them.) + **************************************************************/ + private void saveStates + ( + ) + { + int start_state; + int count_state; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != this); + CUtility.ASSERT(null != m_outstream); + CUtility.ASSERT(null != m_input); + CUtility.ASSERT(null != m_tokens); + CUtility.ASSERT(null != m_spec); + } + + /* EOF found? */ + if (m_input.m_eof_reached) + { + return; + } + + /* Debug checks. */ + if (CUtility.DEBUG) + { + CUtility.ASSERT('%' == m_input.m_line[0]); + CUtility.ASSERT('s' == m_input.m_line[1]); + CUtility.ASSERT(m_input.m_line_index <= m_input.m_line_read); + CUtility.ASSERT(0 <= m_input.m_line_index); + CUtility.ASSERT(0 <= m_input.m_line_read); + } + + /* Blank line? No states? */ + if (m_input.m_line_index >= m_input.m_line_read) + { + return; + } + + while (m_input.m_line_index < m_input.m_line_read) + { + if (CUtility.OLD_DEBUG) + { + System.out.println("line read " + m_input.m_line_read + + "\tline index = " + m_input.m_line_index); + } + + /* Skip white space. */ + while (CUtility.isspace(m_input.m_line[m_input.m_line_index])) + { + ++m_input.m_line_index; + if (m_input.m_line_index >= m_input.m_line_read) + { + /* No more states to be found. */ + return; + } + } + + /* Look for state name. */ + start_state = m_input.m_line_index; + while (false == CUtility.isspace(m_input.m_line[m_input.m_line_index]) + && ',' != m_input.m_line[m_input.m_line_index]) + { + ++m_input.m_line_index; + if (m_input.m_line_index >= m_input.m_line_read) + { + /* End of line and end of state name. */ + break; + } + } + count_state = m_input.m_line_index - start_state; + + if (CUtility.OLD_DEBUG) + { + System.out.println("State name \"" + + new String(m_input.m_line,start_state,count_state) + + "\"."); + System.out.println("Integer index \"" + + m_spec.m_states.size() + + "\"."); + } + + /* Enter new state name, along with unique index. */ + m_spec.m_states.put(new String(m_input.m_line,start_state,count_state), + new Integer(m_spec.m_states.size())); + + /* Skip comma. */ + if (',' == m_input.m_line[m_input.m_line_index]) + { + ++m_input.m_line_index; + if (m_input.m_line_index >= m_input.m_line_read) + { + /* End of line. */ + return; + } + } + } + } + + /******************************************************** + Function: expandEscape + Description: Takes escape sequence and returns + corresponding character code. + *******************************************************/ + private char expandEscape + ( + ) + { + char r; + + /* Debug checks. */ + if (CUtility.DEBUG) + { + CUtility.ASSERT(m_input.m_line_index < m_input.m_line_read); + CUtility.ASSERT(0 < m_input.m_line_read); + CUtility.ASSERT(0 <= m_input.m_line_index); + } + + if ('\\' != m_input.m_line[m_input.m_line_index]) + { + ++m_input.m_line_index; + return m_input.m_line[m_input.m_line_index - 1]; + } + else + { + boolean unicode_escape = false; + ++m_input.m_line_index; + switch (m_input.m_line[m_input.m_line_index]) + { + case 'b': + ++m_input.m_line_index; + return '\b'; + + case 't': + ++m_input.m_line_index; + return '\t'; + + case 'n': + ++m_input.m_line_index; + return '\n'; + + case 'f': + ++m_input.m_line_index; + return '\f'; + + case 'r': + ++m_input.m_line_index; + return '\r'; + + case '^': + ++m_input.m_line_index; + r=Character.toUpperCase(m_input.m_line[m_input.m_line_index]); + if (r<'@' || r>'Z') // non-fatal + CError.parse_error(CError.E_BADCTRL,m_input.m_line_number); + r = (char) (r - '@'); + ++m_input.m_line_index; + return r; + + case 'u': + unicode_escape = true; + case 'x': + ++m_input.m_line_index; + r = 0; + for (int i=0; i<(unicode_escape?4:2); i++) + if (CUtility.ishexdigit(m_input.m_line[m_input.m_line_index])) + { + r = (char) (r << 4); + r = (char) (r | CUtility.hex2bin(m_input.m_line[m_input.m_line_index])); + ++m_input.m_line_index; + } + else break; + + return r; + + default: + if (false == CUtility.isoctdigit(m_input.m_line[m_input.m_line_index])) + { + r = m_input.m_line[m_input.m_line_index]; + ++m_input.m_line_index; + } + else + { + r = 0; + for (int i=0; i<3; i++) + if (CUtility.isoctdigit(m_input.m_line[m_input.m_line_index])) + { + r = (char) (r << 3); + r = (char) (r | CUtility.oct2bin(m_input.m_line[m_input.m_line_index])); + ++m_input.m_line_index; + } + else break; + } + return r; + } + } + } + + /******************************************************** + Function: packAccept + Description: Packages and returns CAccept + for action next in input stream. + *******************************************************/ + CAccept packAccept + ( + ) + throws java.io.IOException + { + CAccept accept; + char action[]; + int action_index; + int brackets; + boolean insinglequotes; + boolean indoublequotes; + boolean instarcomment; + boolean inslashcomment; + boolean escaped; + boolean slashed; + + action = new char[BUFFER_SIZE]; + action_index = 0; + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != this); + CUtility.ASSERT(null != m_outstream); + CUtility.ASSERT(null != m_input); + CUtility.ASSERT(null != m_tokens); + CUtility.ASSERT(null != m_spec); + } + + /* Get a new line, if needed. */ + while (m_input.m_line_index >= m_input.m_line_read) + { + if (m_input.getLine()) + { + CError.parse_error(CError.E_EOF,m_input.m_line_number); + return null; + } + } + + /* Look for beginning of action. */ + while (CUtility.isspace(m_input.m_line[m_input.m_line_index])) + { + ++m_input.m_line_index; + + /* Get a new line, if needed. */ + while (m_input.m_line_index >= m_input.m_line_read) + { + if (m_input.getLine()) + { + CError.parse_error(CError.E_EOF,m_input.m_line_number); + return null; + } + } + } + + /* Look for brackets. */ + if ('{' != m_input.m_line[m_input.m_line_index]) + { + CError.parse_error(CError.E_BRACE,m_input.m_line_number); + } + + /* Copy new line into action buffer. */ + brackets = 0; + insinglequotes = indoublequotes = inslashcomment = instarcomment = + escaped = slashed = false; + while (true) + { + action[action_index] = m_input.m_line[m_input.m_line_index]; + + /* Look for quotes. */ + if ((insinglequotes || indoublequotes) && escaped) + escaped=false; // only protects one char, but this is enough. + else if ((insinglequotes || indoublequotes) && + '\\' == m_input.m_line[m_input.m_line_index]) + escaped=true; + else if (!(insinglequotes || inslashcomment || instarcomment) && + '\"' == m_input.m_line[m_input.m_line_index]) + indoublequotes=!indoublequotes; // unescaped double quote. + else if (!(indoublequotes || inslashcomment || instarcomment) && + '\'' == m_input.m_line[m_input.m_line_index]) + insinglequotes=!insinglequotes; // unescaped single quote. + /* Look for comments. */ + if (instarcomment) { // inside "/*" comment; look for "*/" + if (slashed && '/' == m_input.m_line[m_input.m_line_index]) + instarcomment = slashed = false; + else // note that inside a star comment, slashed means starred + slashed = ('*' == m_input.m_line[m_input.m_line_index]); + } else if (!inslashcomment && !insinglequotes && !indoublequotes) { + // not in comment, look for /* or // + inslashcomment = + (slashed && '/' == m_input.m_line[m_input.m_line_index]); + instarcomment = + (slashed && '*' == m_input.m_line[m_input.m_line_index]); + slashed = ('/' == m_input.m_line[m_input.m_line_index]); + } + + /* Look for brackets. */ + if (!insinglequotes && !indoublequotes && + !instarcomment && !inslashcomment) { + if ('{' == m_input.m_line[m_input.m_line_index]) + { + ++brackets; + } + else if ('}' == m_input.m_line[m_input.m_line_index]) + { + --brackets; + + if (0 == brackets) + { + ++action_index; + ++m_input.m_line_index; + + break; + } + } + } + + ++action_index; + /* Double the buffer size, if needed. */ + if (action_index >= action.length) + { + action = CUtility.doubleSize(action); + } + + ++m_input.m_line_index; + /* Get a new line, if needed. */ + while (m_input.m_line_index >= m_input.m_line_read) + { + inslashcomment = slashed = false; + if (insinglequotes || indoublequotes) { // non-fatal + CError.parse_error(CError.E_NEWLINE,m_input.m_line_number); + insinglequotes = indoublequotes = false; + } + if (m_input.getLine()) + { + CError.parse_error(CError.E_SYNTAX,m_input.m_line_number); + return null; + } + } + } + + accept = new CAccept(action,action_index,m_input.m_line_number); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != accept); + } + + if (CUtility.DESCENT_DEBUG) + { + System.out.print("Accepting action:"); + System.out.println(new String(accept.m_action,0,accept.m_action_read)); + } + + return accept; + } + + /******************************************************** + Function: advance + Description: Returns code for next token. + *******************************************************/ + private boolean m_advance_stop = false; + int advance + ( + ) + throws java.io.IOException + { + boolean saw_escape = false; + Integer code; + + /*if (m_input.m_line_index > m_input.m_line_read) { + System.out.println("m_input.m_line_index = " + m_input.m_line_index); + System.out.println("m_input.m_line_read = " + m_input.m_line_read); + CUtility.ASSERT(m_input.m_line_index <= m_input.m_line_read); + }*/ + + if (m_input.m_eof_reached) + { + /* EOF has already been reached, + so return appropriate code. */ + + m_spec.m_current_token = END_OF_INPUT; + m_spec.m_lexeme = '\0'; + return m_spec.m_current_token; + } + + /* End of previous regular expression? + Refill line buffer? */ + if (EOS == m_spec.m_current_token + /* ADDED */ + || m_input.m_line_index >= m_input.m_line_read) + /* ADDED */ + { + if (m_spec.m_in_quote) + { + CError.parse_error(CError.E_SYNTAX,m_input.m_line_number); + } + + while (true) + { + if (false == m_advance_stop + || m_input.m_line_index >= m_input.m_line_read) + { + if (m_input.getLine()) + { + /* EOF has already been reached, + so return appropriate code. */ + + m_spec.m_current_token = END_OF_INPUT; + m_spec.m_lexeme = '\0'; + return m_spec.m_current_token; + } + m_input.m_line_index = 0; + } + else + { + m_advance_stop = false; + } + + while (m_input.m_line_index < m_input.m_line_read + && true == CUtility.isspace(m_input.m_line[m_input.m_line_index])) + { + ++m_input.m_line_index; + } + + if (m_input.m_line_index < m_input.m_line_read) + { + break; + } + } + } + + if (CUtility.DEBUG) { + CUtility.ASSERT(m_input.m_line_index <= m_input.m_line_read); + } + + while (true) + { + if (false == m_spec.m_in_quote + && '{' == m_input.m_line[m_input.m_line_index]) + { + if (false == expandMacro()) + { + break; + } + + if (m_input.m_line_index >= m_input.m_line_read) + { + m_spec.m_current_token = EOS; + m_spec.m_lexeme = '\0'; + return m_spec.m_current_token; + } + } + else if ('\"' == m_input.m_line[m_input.m_line_index]) + { + m_spec.m_in_quote = !m_spec.m_in_quote; + ++m_input.m_line_index; + + if (m_input.m_line_index >= m_input.m_line_read) + { + m_spec.m_current_token = EOS; + m_spec.m_lexeme = '\0'; + return m_spec.m_current_token; + } + } + else + { + break; + } + } + + if (m_input.m_line_index > m_input.m_line_read) { + System.out.println("m_input.m_line_index = " + m_input.m_line_index); + System.out.println("m_input.m_line_read = " + m_input.m_line_read); + CUtility.ASSERT(m_input.m_line_index <= m_input.m_line_read); + } + + /* Look for backslash, and corresponding + escape sequence. */ + if ('\\' == m_input.m_line[m_input.m_line_index]) + { + saw_escape = true; + } + else + { + saw_escape = false; + } + + if (false == m_spec.m_in_quote) + { + if (false == m_spec.m_in_ccl && + CUtility.isspace(m_input.m_line[m_input.m_line_index])) + { + /* White space means the end of + the current regular expression. */ + + m_spec.m_current_token = EOS; + m_spec.m_lexeme = '\0'; + return m_spec.m_current_token; + } + + /* Process escape sequence, if needed. */ + if (saw_escape) + { + m_spec.m_lexeme = expandEscape(); + } + else + { + m_spec.m_lexeme = m_input.m_line[m_input.m_line_index]; + ++m_input.m_line_index; + } + } + else + { + if (saw_escape + && (m_input.m_line_index + 1) < m_input.m_line_read + && '\"' == m_input.m_line[m_input.m_line_index + 1]) + { + m_spec.m_lexeme = '\"'; + m_input.m_line_index = m_input.m_line_index + 2; + } + else + { + m_spec.m_lexeme = m_input.m_line[m_input.m_line_index]; + ++m_input.m_line_index; + } + } + + code = (Integer) m_tokens.get(new Character(m_spec.m_lexeme)); + if (m_spec.m_in_quote || true == saw_escape) + { + m_spec.m_current_token = L; + } + else + { + if (null == code) + { + m_spec.m_current_token = L; + } + else + { + m_spec.m_current_token = code.intValue(); + } + } + + if (CCL_START == m_spec.m_current_token) m_spec.m_in_ccl = true; + if (CCL_END == m_spec.m_current_token) m_spec.m_in_ccl = false; + + if (CUtility.FOODEBUG) + { + System.out.println("Lexeme: " + m_spec.m_lexeme + + "\tToken: " + m_spec.m_current_token + + "\tIndex: " + m_input.m_line_index); + } + + return m_spec.m_current_token; + } + + /*************************************************************** + Function: details + Description: High level debugging routine. + **************************************************************/ + private void details + ( + ) + { + Enumeration names; + String name; + String def; + Enumeration states; + String state; + Integer index; + int elem; + int size; + + System.out.println(); + System.out.println("\t** Macros **"); + names = m_spec.m_macros.keys(); + while (names.hasMoreElements()) + { + name = (String) names.nextElement(); + def = (String) m_spec.m_macros.get(name); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != name); + CUtility.ASSERT(null != def); + } + + System.out.println("Macro name \"" + name + + "\" has definition \"" + + def + "\"."); + } + + System.out.println(); + System.out.println("\t** States **"); + states = m_spec.m_states.keys(); + while (states.hasMoreElements()) + { + state = (String) states.nextElement(); + index = (Integer) m_spec.m_states.get(state); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != state); + CUtility.ASSERT(null != index); + } + + System.out.println("State \"" + state + + "\" has identifying index " + + index.toString() + "."); + } + + System.out.println(); + System.out.println("\t** Character Counting **"); + if (false == m_spec.m_count_chars) + { + System.out.println("Character counting is off."); + } + else + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(m_spec.m_count_lines); + } + + System.out.println("Character counting is on."); + } + + System.out.println(); + System.out.println("\t** Line Counting **"); + if (false == m_spec.m_count_lines) + { + System.out.println("Line counting is off."); + } + else + { + if (CUtility.DEBUG) + { + CUtility.ASSERT(m_spec.m_count_lines); + } + + System.out.println("Line counting is on."); + } + + System.out.println(); + System.out.println("\t** Operating System Specificity **"); + if (false == m_spec.m_unix) + { + System.out.println("Not generating UNIX-specific code."); + System.out.println("(This means that \"\\r\\n\" is a " + + "newline, rather than \"\\n\".)"); + } + else + { + System.out.println("Generating UNIX-specific code."); + System.out.println("(This means that \"\\n\" is a " + + "newline, rather than \"\\r\\n\".)"); + } + + System.out.println(); + System.out.println("\t** Java CUP Compatibility **"); + if (false == m_spec.m_cup_compatible) + { + System.out.println("Generating CUP compatible code."); + System.out.println("(Scanner implements " + + "java_cup.runtime.Scanner.)"); + } + else + { + System.out.println("Not generating CUP compatible code."); + } + + if (CUtility.FOODEBUG) { + if (null != m_spec.m_nfa_states && null != m_spec.m_nfa_start) + { + System.out.println(); + System.out.println("\t** NFA machine **"); + print_nfa(); + } + } + + if (null != m_spec.m_dtrans_vector) + { + System.out.println(); + System.out.println("\t** DFA transition table **"); + /*print_header();*/ + } + + /*if (null != m_spec.m_accept_vector && null != m_spec.m_anchor_array) + { + System.out.println(); + System.out.println("\t** Accept States and Anchor Vector **"); + print_accept(); + }*/ + } + + /*************************************************************** + function: print_set + **************************************************************/ + void print_set + ( + Vector nfa_set + ) + { + int size; + int elem; + CNfa nfa; + + size = nfa_set.size(); + + if (0 == size) + { + System.out.print("empty "); + } + + for (elem = 0; elem < size; ++elem) + { + nfa = (CNfa) nfa_set.elementAt(elem); + /*System.out.print(m_spec.m_nfa_states.indexOf(nfa) + " ");*/ + System.out.print(nfa.m_label + " "); + } + } + + /*************************************************************** + Function: print_header + **************************************************************/ + private void print_header + ( + ) + { + Enumeration states; + int i; + int j; + int chars_printed=0; + CDTrans dtrans; + int last_transition; + String str; + CAccept accept; + String state; + Integer index; + + System.out.println("/*---------------------- DFA -----------------------"); + + states = m_spec.m_states.keys(); + while (states.hasMoreElements()) + { + state = (String) states.nextElement(); + index = (Integer) m_spec.m_states.get(state); + + if (CUtility.DEBUG) + { + CUtility.ASSERT(null != state); + CUtility.ASSERT(null != index); + } + + System.out.println("State \"" + state + + "\" has identifying index " + + index.toString() + "."); + + i = index.intValue(); + if (CDTrans.F != m_spec.m_state_dtrans[i]) + { + System.out.println("\tStart index in transition table: " + + m_spec.m_state_dtrans[i]); + } + else + { + System.out.println("\tNo associated transition states."); + } + } + + for (i = 0; i < m_spec.m_dtrans_vector.size(); ++i) + { + dtrans = (CDTrans) m_spec.m_dtrans_vector.elementAt(i); + + if (null == m_spec.m_accept_vector && null == m_spec.m_anchor_array) + { + if (null == dtrans.m_accept) + { + System.out.print(" * State " + i + " [nonaccepting]"); + } + else + { + System.out.print(" * State " + i + + " [accepting, line " + + dtrans.m_accept.m_line_number + + " <" + + (new String(dtrans.m_accept.m_action,0, + dtrans.m_accept.m_action_read)) + + ">]"); + if (CSpec.NONE != dtrans.m_anchor) + { + System.out.print(" Anchor: " + + ((0 != (dtrans.m_anchor & CSpec.START)) + ? "start " : "") + + ((0 != (dtrans.m_anchor & CSpec.END)) + ? "end " : "")); + } + } + } + else + { + accept = (CAccept) m_spec.m_accept_vector.elementAt(i); + + if (null == accept) + { + System.out.print(" * State " + i + " [nonaccepting]"); + } + else + { + System.out.print(" * State " + i + + " [accepting, line " + + accept.m_line_number + + " <" + + (new String(accept.m_action,0, + accept.m_action_read)) + + ">]"); + if (CSpec.NONE != m_spec.m_anchor_array[i]) + { + System.out.print(" Anchor: " + + ((0 != (m_spec.m_anchor_array[i] & CSpec.START)) + ? "start " : "") + + ((0 != (m_spec.m_anchor_array[i] & CSpec.END)) + ? "end " : "")); + } + } + } + + last_transition = -1; + for (j = 0; j < m_spec.m_dtrans_ncols; ++j) + { + if (CDTrans.F != dtrans.m_dtrans[j]) + { + if (last_transition != dtrans.m_dtrans[j]) + { + System.out.println(); + System.out.print(" * goto " + dtrans.m_dtrans[j] + + " on "); + chars_printed = 0; + } + + str = interp_int((int) j); + System.out.print(str); + + chars_printed = chars_printed + str.length(); + if (56 < chars_printed) + { + System.out.println(); + System.out.print(" * "); + chars_printed = 0; + } + + last_transition = dtrans.m_dtrans[j]; + } + } + System.out.println(); + } + System.out.println(" */"); + System.out.println(); + } +} + +/* + * SparseBitSet 25-Jul-1999. + * C. Scott Ananian <cananian@alumni.princeton.edu> + * + * Re-implementation of the standard java.util.BitSet to support sparse + * sets, which we need to efficiently support unicode character classes. + */ + +/** + * A set of bits. The set automatically grows as more bits are + * needed. + * + * @version 1.00, 25 Jul 1999 + * @author C. Scott Ananian + */ +final class SparseBitSet implements Cloneable { + /** Sorted array of bit-block offsets. */ + int offs[]; + /** Array of bit-blocks; each holding BITS bits. */ + long bits[]; + /** Number of blocks currently in use. */ + int size; + /** log base 2 of BITS, for the identity: x/BITS == x >> LG_BITS */ + static final private int LG_BITS = 6; + /** Number of bits in a block. */ + static final private int BITS = 1<<LG_BITS; + /** BITS-1, using the identity: x % BITS == x & (BITS-1) */ + static final private int BITS_M1 = BITS-1; + + /** + * Creates an empty set. + */ + public SparseBitSet() { + bits = new long[4]; + offs = new int [4]; + size = 0; + } + + /** + * Creates an empty set with the specified size. + * @param nbits the size of the set + */ + public SparseBitSet(int nbits) { + this(); + } + + /** + * Creates an empty set with the same size as the given set. + */ + public SparseBitSet(SparseBitSet set) { + bits = new long[set.size]; + offs = new int [set.size]; + size = 0; + } + + private void new_block(int bnum) { + new_block(bsearch(bnum), bnum); + } + private void new_block(int idx, int bnum) { + if (size==bits.length) { // resize + long[] nbits = new long[size*3]; + int [] noffs = new int [size*3]; + System.arraycopy(bits, 0, nbits, 0, size); + System.arraycopy(offs, 0, noffs, 0, size); + bits = nbits; + offs = noffs; + } + CUtility.ASSERT(size<bits.length); + insert_block(idx, bnum); + } + private void insert_block(int idx, int bnum) { + CUtility.ASSERT(idx<=size); + CUtility.ASSERT(idx==size || offs[idx]!=bnum); + System.arraycopy(bits, idx, bits, idx+1, size-idx); + System.arraycopy(offs, idx, offs, idx+1, size-idx); + offs[idx]=bnum; + bits[idx]=0; //clear them bits. + size++; + } + private int bsearch(int bnum) { + int l=0, r=size; // search interval is [l, r) + while (l<r) { + int p = (l+r)/2; + if (bnum<offs[p]) r=p; + else if (bnum>offs[p]) l=p+1; + else return p; + } + CUtility.ASSERT(l==r); + return l; // index at which the bnum *should* be, if it's not. + } + + /** + * Sets a bit. + * @param bit the bit to be set + */ + public void set(int bit) { + int bnum = bit >> LG_BITS; + int idx = bsearch(bnum); + if (idx >= size || offs[idx]!=bnum) + new_block(idx, bnum); + bits[idx] |= (1L << (bit & BITS_M1) ); + } + + /** + * Clears a bit. + * @param bit the bit to be cleared + */ + public void clear(int bit) { + int bnum = bit >> LG_BITS; + int idx = bsearch(bnum); + if (idx >= size || offs[idx]!=bnum) + new_block(idx, bnum); + bits[idx] &= ~(1L << (bit & BITS_M1) ); + } + + /** + * Clears all bits. + */ + public void clearAll() { + size = 0; + } + + /** + * Gets a bit. + * @param bit the bit to be gotten + */ + public boolean get(int bit) { + int bnum = bit >> LG_BITS; + int idx = bsearch(bnum); + if (idx >= size || offs[idx]!=bnum) + return false; + return 0 != ( bits[idx] & (1L << (bit & BITS_M1) ) ); + } + + /** + * Logically ANDs this bit set with the specified set of bits. + * @param set the bit set to be ANDed with + */ + public void and(SparseBitSet set) { + binop(this, set, AND); + } + + /** + * Logically ORs this bit set with the specified set of bits. + * @param set the bit set to be ORed with + */ + public void or(SparseBitSet set) { + binop(this, set, OR); + } + + /** + * Logically XORs this bit set with the specified set of bits. + * @param set the bit set to be XORed with + */ + public void xor(SparseBitSet set) { + binop(this, set, XOR); + } + + // BINARY OPERATION MACHINERY + private static interface BinOp { + public long op(long a, long b); + } + private static final BinOp AND = new BinOp() { + public final long op(long a, long b) { return a & b; } + }; + private static final BinOp OR = new BinOp() { + public final long op(long a, long b) { return a | b; } + }; + private static final BinOp XOR = new BinOp() { + public final long op(long a, long b) { return a ^ b; } + }; + private static final void binop(SparseBitSet a, SparseBitSet b, BinOp op) { + int nsize = a.size + b.size; + long[] nbits; + int [] noffs; + int a_zero, a_size; + // be very clever and avoid allocating more memory if we can. + if (a.bits.length < nsize) { // oh well, have to make working space. + nbits = new long[nsize]; + noffs = new int [nsize]; + a_zero = 0; a_size = a.size; + } else { // reduce, reuse, recycle! + nbits = a.bits; + noffs = a.offs; + a_zero = a.bits.length - a.size; a_size = a.bits.length; + System.arraycopy(a.bits, 0, a.bits, a_zero, a.size); + System.arraycopy(a.offs, 0, a.offs, a_zero, a.size); + } + // ok, crunch through and binop those sets! + nsize = 0; + for (int i=a_zero, j=0; i<a_size || j<b.size; ) { + long nb; int no; + if (i<a_size && (j>=b.size || a.offs[i] < b.offs[j])) { + nb = op.op(a.bits[i], 0); + no = a.offs[i]; + i++; + } else if (j<b.size && (i>=a_size || a.offs[i] > b.offs[j])) { + nb = op.op(0, b.bits[j]); + no = b.offs[j]; + j++; + } else { // equal keys; merge. + nb = op.op(a.bits[i], b.bits[j]); + no = a.offs[i]; + i++; j++; + } + if (nb!=0) { + nbits[nsize] = nb; + noffs[nsize] = no; + nsize++; + } + } + a.bits = nbits; + a.offs = noffs; + a.size = nsize; + } + + /** + * Gets the hashcode. + */ + public int hashCode() { + long h = 1234; + for (int i=0; i<size; i++) + h ^= bits[i] * offs[i]; + return (int)((h >> 32) ^ h); + } + + /** + * Calculates and returns the set's size + */ + public int size() { + return (size==0)?0:((1+offs[size-1]) << LG_BITS); + } + + /** + * Compares this object against the specified object. + * @param obj the object to commpare with + * @return true if the objects are the same; false otherwise. + */ + public boolean equals(Object obj) { + if ((obj != null) && (obj instanceof SparseBitSet)) + return equals(this, (SparseBitSet)obj); + return false; + } + /** + * Compares two SparseBitSets for equality. + * @return true if the objects are the same; false otherwise. + */ + public static boolean equals(SparseBitSet a, SparseBitSet b) { + for (int i=0, j=0; i<a.size || j<b.size; ) { + if (i<a.size && (j>=b.size || a.offs[i] < b.offs[j])) { + if (a.bits[i++]!=0) return false; + } else if (j<b.size && (i>=a.size || a.offs[i] > b.offs[j])) { + if (b.bits[j++]!=0) return false; + } else { // equal keys + if (a.bits[i++]!=b.bits[j++]) return false; + } + } + return true; + } + + /** + * Clones the SparseBitSet. + */ + public Object clone() { + try { + SparseBitSet set = (SparseBitSet)super.clone(); + set.bits = (long[]) bits.clone(); + set.offs = (int []) offs.clone(); + return set; + } catch (CloneNotSupportedException e) { + // this shouldn't happen, since we are Cloneable + throw new InternalError(); + } + } + + /** + * Return an <code>Enumeration</code> of <code>Integer</code>s + * which represent set bit indices in this SparseBitSet. + */ + public Enumeration elements() { + return new Enumeration() { + int idx=-1, bit=BITS; + { advance(); } + public boolean hasMoreElements() { + return (idx<size); + } + public Object nextElement() { + int r = bit + (offs[idx] << LG_BITS); + advance(); + return new Integer(r); + } + private void advance() { + while (idx<size) { + while (++bit<BITS) + if (0!=(bits[idx] & (1L<<bit))) + return; + idx++; bit=-1; + } + } + }; + } + /** + * Converts the SparseBitSet to a String. + */ + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append('{'); + for (Enumeration e=elements(); e.hasMoreElements(); ) { + if (sb.length() > 1) sb.append(", "); + sb.append(e.nextElement()); + } + sb.append('}'); + return sb.toString(); + } + + /** Check validity. */ + private boolean isValid() { + if (bits.length!=offs.length) return false; + if (size>bits.length) return false; + if (size!=0 && 0<=offs[0]) return false; + for (int i=1; i<size; i++) + if (offs[i] < offs[i-1]) + return false; + return true; + } + /** Self-test. */ + public static void main(String[] args) { + final int ITER = 500; + final int RANGE= 65536; + SparseBitSet a = new SparseBitSet(); + CUtility.ASSERT(!a.get(0) && !a.get(1)); + CUtility.ASSERT(!a.get(123329)); + a.set(0); CUtility.ASSERT(a.get(0) && !a.get(1)); + a.set(1); CUtility.ASSERT(a.get(0) && a.get(1)); + a.clearAll(); + CUtility.ASSERT(!a.get(0) && !a.get(1)); + java.util.Random r = new java.util.Random(); + java.util.Vector v = new java.util.Vector(); + for (int n=0; n<ITER; n++) { + int rr = ((r.nextInt()>>>1) % RANGE) << 1; + a.set(rr); v.addElement(new Integer(rr)); + // check that all the numbers are there. + CUtility.ASSERT(a.get(rr) && !a.get(rr+1) && !a.get(rr-1)); + for (int i=0; i<v.size(); i++) + CUtility.ASSERT(a.get(((Integer)v.elementAt(i)).intValue())); + } + SparseBitSet b = (SparseBitSet) a.clone(); + CUtility.ASSERT(a.equals(b) && b.equals(a)); + for (int n=0; n<ITER/2; n++) { + int rr = (r.nextInt()>>>1) % v.size(); + int m = ((Integer)v.elementAt(rr)).intValue(); + b.clear(m); v.removeElementAt(rr); + // check that numbers are removed properly. + CUtility.ASSERT(!b.get(m)); + } + CUtility.ASSERT(!a.equals(b)); + SparseBitSet c = (SparseBitSet) a.clone(); + SparseBitSet d = (SparseBitSet) a.clone(); + c.and(a); + CUtility.ASSERT(c.equals(a) && a.equals(c)); + c.xor(a); + CUtility.ASSERT(!c.equals(a) && c.size()==0); + d.or(b); + CUtility.ASSERT(d.equals(a) && !b.equals(d)); + d.and(b); + CUtility.ASSERT(!d.equals(a) && b.equals(d)); + d.xor(a); + CUtility.ASSERT(!d.equals(a) && !b.equals(d)); + c.or(d); c.or(b); + CUtility.ASSERT(c.equals(a) && a.equals(c)); + c = (SparseBitSet) d.clone(); + c.and(b); + CUtility.ASSERT(c.size()==0); + System.out.println("Success."); + } +} + +/************************************************************************ + JLEX COPYRIGHT NOTICE, LICENSE AND DISCLAIMER. + + Copyright 1996 by Elliot Joel Berk + + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose and without fee is hereby granted, + provided that the above copyright notice appear in all copies and that + both the copyright notice and this permission notice and warranty + disclaimer appear in supporting documentation, and that the name of + Elliot Joel Berk not be used in advertising or publicity pertaining + to distribution of the software without specific, written prior permission. + + Elliot Joel Berk disclaims all warranties with regard to this software, + including all implied warranties of merchantability and fitness. In no event + shall Elliot Joel Berk be liable for any special, indirect or consequential + damages or any damages whatsoever resulting from loss of use, data or + profits, whether in an action of contract, negligence or other + tortious action, arising out of or in connection with the use or + performance of this software. + ***********************************************************************/ +// set emacs indentation +// Local Variables: +// c-basic-offset:2 +// End: diff --git a/open-nars/com/googlecode/opennars/language/BooleanLiteral.java b/open-nars/com/googlecode/opennars/language/BooleanLiteral.java new file mode 100644 index 0000000000000000000000000000000000000000..b2c6c61db862cdd2e05b35febf29b326dc6b57fe --- /dev/null +++ b/open-nars/com/googlecode/opennars/language/BooleanLiteral.java @@ -0,0 +1,17 @@ +package com.googlecode.opennars.language; + +public class BooleanLiteral extends Literal { + + private boolean truthval; + + public BooleanLiteral(String name) { + super(name); + this.truthval = Boolean.parseBoolean(name); + } + + public BooleanLiteral(boolean tv) { + super(Boolean.toString(tv)); + this.truthval = tv; + } + +} diff --git a/open-nars/com/googlecode/opennars/language/Literal.java b/open-nars/com/googlecode/opennars/language/Literal.java new file mode 100644 index 0000000000000000000000000000000000000000..e9cee1d45cfe33ea3a073caa808550b64132da07 --- /dev/null +++ b/open-nars/com/googlecode/opennars/language/Literal.java @@ -0,0 +1,12 @@ +package com.googlecode.opennars.language; + +public class Literal extends Term { + + public Literal() { + } + + public Literal(String name) { + super(name); + } + +} diff --git a/open-nars/com/googlecode/opennars/language/NumericLiteral.java b/open-nars/com/googlecode/opennars/language/NumericLiteral.java new file mode 100644 index 0000000000000000000000000000000000000000..5fcf5a706637e86e4e7ca9df7b89a7665899bb41 --- /dev/null +++ b/open-nars/com/googlecode/opennars/language/NumericLiteral.java @@ -0,0 +1,34 @@ +package com.googlecode.opennars.language; + +public class NumericLiteral extends Literal { + + public enum TYPE { + INTEGER, + DOUBLE; + }; + + private double num; + private TYPE type; + + public NumericLiteral(String name) { + super(name); + this.num = Double.parseDouble(name); + } + + public NumericLiteral(int num) { + super(Integer.toString(num)); + this.num = num; + this.type = TYPE.INTEGER; + } + + public NumericLiteral(double num) { + super(Double.toString(num)); + this.num = num; + this.type = TYPE.DOUBLE; + } + + public TYPE getType() { + return type; + } + +} diff --git a/open-nars/com/googlecode/opennars/language/StringLiteral.java b/open-nars/com/googlecode/opennars/language/StringLiteral.java new file mode 100644 index 0000000000000000000000000000000000000000..e881f5b6ada4026557ed5c2e3d4f7826d29bf64e --- /dev/null +++ b/open-nars/com/googlecode/opennars/language/StringLiteral.java @@ -0,0 +1,9 @@ +package com.googlecode.opennars.language; + +public class StringLiteral extends Literal { + + public StringLiteral(String string_) { + super(string_); + } + +} diff --git a/open-nars/com/googlecode/opennars/language/Term.java b/open-nars/com/googlecode/opennars/language/Term.java index 41413fee66b784cd49f36e5a928b2c30f66af01a..96e4e33337818c3d18273904d746917d182a16cd 100644 --- a/open-nars/com/googlecode/opennars/language/Term.java +++ b/open-nars/com/googlecode/opennars/language/Term.java @@ -26,6 +26,7 @@ import java.util.*; import com.googlecode.opennars.inference.SyllogisticRules; import com.googlecode.opennars.main.Memory; import com.googlecode.opennars.parser.Symbols; +import com.googlecode.opennars.parser.TermVisitor; /** * Term is the basic component of Narsese, and the object of processing in NARS. @@ -125,5 +126,17 @@ public class Term implements Cloneable, Comparable<Term> { public final boolean containQueryVariable() { // to be revised return (name.indexOf(Symbols.QUERY_VARIABLE_TAG) >= 0); + } + + /** + * Accept a visitor + * @param <R> Return type + * @param <A> Argument type + * @param v Visitor + * @param arg Argument + * @return an instance of the return type + */ + public <R,A> R accept(TermVisitor<R,A> v, A arg) { + return v.visit(this, arg); } } diff --git a/open-nars/com/googlecode/opennars/language/URIRef.java b/open-nars/com/googlecode/opennars/language/URIRef.java new file mode 100644 index 0000000000000000000000000000000000000000..f88b24aaa177705053cbbafca2cbc4a1b5851927 --- /dev/null +++ b/open-nars/com/googlecode/opennars/language/URIRef.java @@ -0,0 +1,39 @@ +package com.googlecode.opennars.language; + +import java.net.URI; + +public class URIRef extends Term { + + private URI uri; + + public URIRef(URI uri2) { + super(uri2.toString().trim()); + uri = uri2; + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.language.Term#getConstantName() + */ + @Override + public String getConstantName() { + return uri.toString().trim(); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.language.Term#getName() + */ + @Override + public String getName() { + return uri.toString().trim(); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.language.Term#clone() + */ + @Override + public Object clone() { + return new URIRef(uri); + } + + +} diff --git a/open-nars/com/googlecode/opennars/main/Reasoner.java b/open-nars/com/googlecode/opennars/main/Reasoner.java index 3bc63dd423675249ff387e9009e6dcca05f2275d..99cda6a075b232d66c2027a8c5861aadffc96ec4 100644 --- a/open-nars/com/googlecode/opennars/main/Reasoner.java +++ b/open-nars/com/googlecode/opennars/main/Reasoner.java @@ -43,7 +43,7 @@ public class Reasoner extends Observable implements Observer, Runnable { * @param parser */ public Reasoner(Parser parser) { - super(); + this(); this.parser = parser; } @@ -109,6 +109,14 @@ public class Reasoner extends Observable implements Observer, Runnable { } } + /** + * Tell the reasoner a task + * @param task the task + */ + public synchronized void tellTask(Task task) { + inputQueue.add(task); + } + /** * Tell the reasoner a sentence with the given budget for working with it * @param sent the sentence diff --git a/open-nars/com/googlecode/opennars/parser/Parser.java b/open-nars/com/googlecode/opennars/parser/Parser.java index 2589a36a62244e1f3c5ba4abcbd555e6e05a84b0..6df85085dee9b9f8008fc969c125dd1f2d7d4abb 100644 --- a/open-nars/com/googlecode/opennars/parser/Parser.java +++ b/open-nars/com/googlecode/opennars/parser/Parser.java @@ -1,12 +1,15 @@ package com.googlecode.opennars.parser; +import java.util.List; + +import com.googlecode.opennars.entity.Sentence; import com.googlecode.opennars.entity.Task; import com.googlecode.opennars.main.Memory; public abstract class Parser extends Symbols { /** - * The only public (static) method of the class, called from Memory.inputTask. + * Parses a given string into a (single) task. * @param buffer the single-line input String * @param memory the memory object doing the parsing * @return an input Task, or null if the input line cannot be parsed into a Task @@ -14,4 +17,22 @@ public abstract class Parser extends Symbols { */ public abstract Task parseTask(String input, Memory memory) throws InvalidInputException; + /** + * Parses a given string into a (list of) tasks. + * @param input + * @param memory + * @return a list of input Tasks, or an empty list if the input line cannot be parsed into a Task + * @throws InvalidInputException + */ + public abstract List<Task> parseTasks(String input, Memory memory) throws InvalidInputException; + + /** + * Serialises the sentence to this parser's format + * @param task + * @param memory + * @return a string containing the serialised task + */ + public abstract String serialiseSentence(Sentence task, Memory memory); + + public abstract String serialiseSentences(List<Sentence> tasks, Memory memory); } \ No newline at end of file diff --git a/open-nars/com/googlecode/opennars/parser/TermVisitor.java b/open-nars/com/googlecode/opennars/parser/TermVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..4ca3a8c80100394a4e4e6d45899cece506515230 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/TermVisitor.java @@ -0,0 +1,49 @@ +package com.googlecode.opennars.parser; + +import com.googlecode.opennars.language.*; + +/** + * A visitor interface for terms in NARS to make it easier to serialise things + * @author jgeldart + * + * @param <R> The return type of this visitor + * @param <A> The argument type + */ +public interface TermVisitor<R, A> { + + R visit(BooleanLiteral p, A arg); + R visit(Conjunction p, A arg); + R visit(ConjunctionParallel p, A arg); + R visit(ConjunctionSequence p, A arg); + R visit(DifferenceExt p, A arg); + R visit(DifferenceInt p, A arg); + R visit(Disjunction p, A arg); + R visit(Equivalence p, A arg); + R visit(EquivalenceAfter p, A arg); + R visit(EquivalenceWhen p, A arg); + R visit(ImageExt p, A arg); + R visit(ImageInt p, A arg); + R visit(Implication p, A arg); + R visit(ImplicationAfter p, A arg); + R visit(ImplicationBefore p, A arg); + R visit(Inheritance p, A arg); + R visit(Instance p, A arg); + R visit(InstanceProperty p, A arg); + R visit(IntersectionExt p, A arg); + R visit(IntersectionInt p, A arg); + R visit(Negation p, A arg); + R visit(NumericLiteral p, A arg); + R visit(Product p, A arg); + R visit(Property p, A arg); + R visit(SetExt p, A arg); + R visit(SetInt p, A arg); + R visit(Similarity p, A arg); + R visit(TenseFuture p, A arg); + R visit(TensePast p, A arg); + R visit(TensePresent p, A arg); + R visit(StringLiteral p, A arg); + R visit(URIRef p, A arg); + R visit(Variable p, A arg); + R visit(Term p, A arg); + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan.cf b/open-nars/com/googlecode/opennars/parser/loan/Loan.cf new file mode 100644 index 0000000000000000000000000000000000000000..97ab2d5f13861ed1e4081abee78fcec639a7360a --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan.cf @@ -0,0 +1,94 @@ +-- LOAN, Non-Axiomatic Ontology Language, grammar +-- Copyright (c) 2008 Joe Geldart + +entrypoints Document, Sentence ; + +DocBR. Document ::= BaseRule [Sentence] ; +Doc. Document ::= [Sentence] ; + +BaseR. BaseRule ::= "@base" URILit "." ; -- The base URI for the document + +[]. [Sentence] ::= ; +(:). [Sentence] ::= Sentence [Sentence] ; + +SentPrefix. Sentence ::= "@prefix" NSPrefix URILit "." ; -- Declares a namespace prefix to be a certain URI +SentImport. Sentence ::= "@import" URILit "." ; -- Imports a given URL +SentDelay. Sentence ::= "@delay" Integer "." ; -- Waits for a given number of cycles before continuing +SentOp. Sentence ::= "@operator" URIRef "." ; -- Declares URI to be an operator (currently unused) + +SentJudge. Sentence ::= Stm TruthValue "." ; -- A judgement with a given truth-value +SentQuest. Sentence ::= Stm "?" ; -- A question +SentGoal. Sentence ::= Stm TruthValue "!" ; -- A goal with a given utility + +StmImpl. Stm ::= Stm "==>" Stm1 ; -- Implication +StmEquiv. Stm ::= Stm "<=>" Stm1 ; -- Equivalence +StmImpPred. Stm ::= Stm "=/>" Stm1 ; -- Predictive implication +StmImpRet. Stm ::= Stm "=\\>" Stm1 ; -- Retrospective implication +StmImpConc. Stm ::= Stm "=|>" Stm1 ; -- Concurrent implication +StmEqvPred. Stm ::= Stm "</>" Stm1 ; -- Predictive equivalence +StmEqvConc. Stm ::= Stm "<|>" Stm1 ; -- Concurrent equivalence +StmConj. Stm1 ::= Stm1 "&&" Stm2 ; -- Conjunction +StmDisj. Stm1 ::= Stm1 "||" Stm2 ; -- Disjunction +StmPar. Stm1 ::= Stm1 ";" Stm2 ; -- Parallel conjunction +StmSeq. Stm1 ::= Stm1 "," Stm2 ; -- Sequential conjunction +StmNot. Stm2 ::= "not" Stm3 ; -- Negation +StmPst. Stm2 ::= "past" Stm3 ; -- Past-tense operator +StmPres. Stm2 ::= "present" Stm3 ; -- Present-tense operator +StmFut. Stm2 ::= "future" Stm3 ; -- Future-tense operator +StmInher. Stm3 ::= Term "-->" Term ; -- Inheritance +StmSim. Stm3 ::= Term "<->" Term ; -- Similarity +StmInst. Stm3 ::= Term "}->" Term ; -- Instance +StmProp. Stm3 ::= Term "--[" Term ; -- Property +StmInPp. Stm3 ::= Term "}-[" Term ; -- Instance-Property +StmOp. Stm3 ::= Term "(" [Term] ")" ; -- Operation +StmTrm. Stm3 ::= Term ; -- Bare term (name) + +coercions Stm 3 ; + +TrmExInt. Term ::= Term "&" Term1 ; -- Extensional intersection +TrmInInt. Term ::= Term "|" Term1 ; -- Intensional intersection +TrmExDif. Term1 ::= Term1 "-" Term2 ; -- Extensional difference +TrmInDif. Term1 ::= Term1 "~" Term2 ; -- Intensional difference +--TrmProd. Term2 ::= Term2 "*" Term3 ; -- Product +--TrmProd. Term2 ::= [Prod] ; +TrmExImg. Term2 ::= Term "extension" "(" [Term] "_|_" [Term] ")" ; -- Extensional image +TrmInImg. Term2 ::= Term "intension" "(" [Term] "_|_" [Term] ")" ; -- Intensional image +TrmExSet. Term3 ::= "{" [Term] "}" ; -- Extensional set +TrmInSet. Term3 ::= "[" [Term] "]" ; -- Intensional set +TrmProd. Term3 ::= "(" [Term] ")" ; +TrmLit. Term3 ::= Literal ; -- Literal +TrmStm. Term3 ::= "(" Stm ")" ; -- Statement + +coercions Term 3 ; + +separator Term "," ; + +-- Literals + +token URILit '<' (char - ["<>\"{}|\\`"])* '>' ; -- A URI literal token + +separator Ident "," ; + +URIFul. URIRef ::= URILit ; -- A full URI reference (possibly relative) +URICur. URIRef ::= NSPrefix Ident ; -- A CURIE + +LitQVar. Literal ::= "?" Ident ; -- A query variable with name +LitQVarAn. Literal ::= "?" ; -- An anonymous query variable +LitSVarD. Literal ::= "#" Ident "(" [Ident] ")" ; -- A dependent statement variable +LitSVarI. Literal ::= "#" Ident ; -- An independent statement variable +LitURI. Literal ::= URIRef ; -- A URI reference literal +LitInt. Literal ::= Integer ; -- An integer literal +LitDbl. Literal ::= Double ; -- A double literal +LitString. Literal ::= String ; -- A string literal +LitTrue. Literal ::= "true" ; -- A true boolean +LitFalse. Literal ::= "false" ; -- A false boolean + +NSPrefix1. NSPrefix ::= Ident ":" ; -- A namespace prefix +NSPrefix2. NSPrefix ::= ":" ; -- The default namespace prefix + +TruthE. TruthValue ::= ; -- The default truth value +TruthF. TruthValue ::= "%" Double "%" ; -- Frequency only +TruthFC. TruthValue ::= "%" Double ";" Double "%" ; -- A full truth value + +comment "/*" "*/" ; -- Comments as in C++ or C# +comment "//" ; diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan.pdf b/open-nars/com/googlecode/opennars/parser/loan/Loan.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4dfc3fd0c8b29e8cb551582ee94e77dbfa17b65b Binary files /dev/null and b/open-nars/com/googlecode/opennars/parser/loan/Loan.pdf differ diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/AbstractVisitor.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/AbstractVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..3c96a362b7fc3f5c20dcbd728865a9235e0ad1fe --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/AbstractVisitor.java @@ -0,0 +1,110 @@ +package com.googlecode.opennars.parser.loan.Loan; +import com.googlecode.opennars.parser.loan.Loan.Absyn.*; +/** BNFC-Generated Abstract Visitor */ +public class AbstractVisitor<R,A> implements AllVisitor<R,A> { +/* Document */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.Doc p, A arg) { return visitDefault(p, arg); } + public R visitDefault(com.googlecode.opennars.parser.loan.Loan.Absyn.Document p, A arg) { + throw new IllegalArgumentException(this.getClass().getName() + ": " + p); + } +/* BaseRule */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR p, A arg) { return visitDefault(p, arg); } + public R visitDefault(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule p, A arg) { + throw new IllegalArgumentException(this.getClass().getName() + ": " + p); + } +/* Sentence */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal p, A arg) { return visitDefault(p, arg); } + public R visitDefault(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence p, A arg) { + throw new IllegalArgumentException(this.getClass().getName() + ": " + p); + } +/* Stm */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc p, A arg) { return visitDefault(p, arg); } + + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq p, A arg) { return visitDefault(p, arg); } + + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut p, A arg) { return visitDefault(p, arg); } + + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm p, A arg) { return visitDefault(p, arg); } + + public R visitDefault(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p, A arg) { + throw new IllegalArgumentException(this.getClass().getName() + ": " + p); + } +/* Term */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt p, A arg) { return visitDefault(p, arg); } + + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif p, A arg) { return visitDefault(p, arg); } + + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg p, A arg) { return visitDefault(p, arg); } + + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm p, A arg) { return visitDefault(p, arg); } + + public R visitDefault(com.googlecode.opennars.parser.loan.Loan.Absyn.Term p, A arg) { + throw new IllegalArgumentException(this.getClass().getName() + ": " + p); + } +/* URIRef */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URICur p, A arg) { return visitDefault(p, arg); } + public R visitDefault(com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef p, A arg) { + throw new IllegalArgumentException(this.getClass().getName() + ": " + p); + } +/* Literal */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitString p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse p, A arg) { return visitDefault(p, arg); } + public R visitDefault(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal p, A arg) { + throw new IllegalArgumentException(this.getClass().getName() + ": " + p); + } +/* NSPrefix */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1 p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2 p, A arg) { return visitDefault(p, arg); } + public R visitDefault(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix p, A arg) { + throw new IllegalArgumentException(this.getClass().getName() + ": " + p); + } +/* TruthValue */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF p, A arg) { return visitDefault(p, arg); } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC p, A arg) { return visitDefault(p, arg); } + public R visitDefault(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue p, A arg) { + throw new IllegalArgumentException(this.getClass().getName() + ": " + p); + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/BaseR.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/BaseR.java new file mode 100644 index 0000000000000000000000000000000000000000..7bca6f48b933cf5237b76ca68f80e59a12111f01 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/BaseR.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class BaseR extends BaseRule { + public final String urilit_; + + public BaseR(String p1) { urilit_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR) { + com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR x = (com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR)o; + return this.urilit_.equals(x.urilit_); + } + return false; + } + + public int hashCode() { + return this.urilit_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/BaseRule.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/BaseRule.java new file mode 100644 index 0000000000000000000000000000000000000000..e6c49b76026e46bceb545aac27d7f7281b835ca6 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/BaseRule.java @@ -0,0 +1,10 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public abstract class BaseRule implements java.io.Serializable { + public abstract <R,A> R accept(BaseRule.Visitor<R,A> v, A arg); + public interface Visitor <R,A> { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR p, A arg); + + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Doc.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Doc.java new file mode 100644 index 0000000000000000000000000000000000000000..c9b22d1dd46bbcd61418a6364481b4171686eebd --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Doc.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class Doc extends Document { + public final ListSentence listsentence_; + + public Doc(ListSentence p1) { listsentence_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Document.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.Doc) { + com.googlecode.opennars.parser.loan.Loan.Absyn.Doc x = (com.googlecode.opennars.parser.loan.Loan.Absyn.Doc)o; + return this.listsentence_.equals(x.listsentence_); + } + return false; + } + + public int hashCode() { + return this.listsentence_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/DocBR.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/DocBR.java new file mode 100644 index 0000000000000000000000000000000000000000..8a135bb93da51c84b19b34d803c51e804669f7c2 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/DocBR.java @@ -0,0 +1,25 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class DocBR extends Document { + public final BaseRule baserule_; + public final ListSentence listsentence_; + + public DocBR(BaseRule p1, ListSentence p2) { baserule_ = p1; listsentence_ = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Document.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR) { + com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR x = (com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR)o; + return this.baserule_.equals(x.baserule_) && this.listsentence_.equals(x.listsentence_); + } + return false; + } + + public int hashCode() { + return 37*(this.baserule_.hashCode())+this.listsentence_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Document.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Document.java new file mode 100644 index 0000000000000000000000000000000000000000..0d84c9e49f47ef14845bec905ee1782ffea7b28b --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Document.java @@ -0,0 +1,11 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public abstract class Document implements java.io.Serializable { + public abstract <R,A> R accept(Document.Visitor<R,A> v, A arg); + public interface Visitor <R,A> { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.Doc p, A arg); + + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/ListIdent.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/ListIdent.java new file mode 100644 index 0000000000000000000000000000000000000000..e0c6d6d74d996b1e20b2506560ee72a96928bb6b --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/ListIdent.java @@ -0,0 +1,4 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class ListIdent extends java.util.LinkedList<String> { +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/ListSentence.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/ListSentence.java new file mode 100644 index 0000000000000000000000000000000000000000..18bff3cad3cc941db8be717da7918edf1a4657fa --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/ListSentence.java @@ -0,0 +1,4 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class ListSentence extends java.util.LinkedList<Sentence> { +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/ListTerm.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/ListTerm.java new file mode 100644 index 0000000000000000000000000000000000000000..78cd90fd5cd0a7bfc95e139e69fd483163fe5ab1 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/ListTerm.java @@ -0,0 +1,4 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class ListTerm extends java.util.LinkedList<Term> { +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitDbl.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitDbl.java new file mode 100644 index 0000000000000000000000000000000000000000..f992d21166b2552f46db60b36391daf3bdd1c9b9 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitDbl.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class LitDbl extends Literal { + public final Double double_; + + public LitDbl(Double p1) { double_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl) { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl x = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl)o; + return this.double_.equals(x.double_); + } + return false; + } + + public int hashCode() { + return this.double_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitFalse.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitFalse.java new file mode 100644 index 0000000000000000000000000000000000000000..3871bbaf0bb57ebaa5bb06de092f8455c067f65c --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitFalse.java @@ -0,0 +1,22 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class LitFalse extends Literal { + + public LitFalse() { } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse) { + return true; + } + return false; + } + + public int hashCode() { + return 37; + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitInt.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitInt.java new file mode 100644 index 0000000000000000000000000000000000000000..155892ad1d00606f8cb3a1ca5d4fb5e9266824a9 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitInt.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class LitInt extends Literal { + public final Integer integer_; + + public LitInt(Integer p1) { integer_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt) { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt x = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt)o; + return this.integer_.equals(x.integer_); + } + return false; + } + + public int hashCode() { + return this.integer_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitQVar.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitQVar.java new file mode 100644 index 0000000000000000000000000000000000000000..162a00a2de68d60653c48bcee35b7c978b15ebf5 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitQVar.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class LitQVar extends Literal { + public final String ident_; + + public LitQVar(String p1) { ident_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar) { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar x = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar)o; + return this.ident_.equals(x.ident_); + } + return false; + } + + public int hashCode() { + return this.ident_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitQVarAn.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitQVarAn.java new file mode 100644 index 0000000000000000000000000000000000000000..80854bb8f71308c611cc78dfd2c84ce5ed571fe0 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitQVarAn.java @@ -0,0 +1,22 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class LitQVarAn extends Literal { + + public LitQVarAn() { } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn) { + return true; + } + return false; + } + + public int hashCode() { + return 37; + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitSVarD.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitSVarD.java new file mode 100644 index 0000000000000000000000000000000000000000..9d561e0889fd7ab64472822acc3b107313b76982 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitSVarD.java @@ -0,0 +1,25 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class LitSVarD extends Literal { + public final String ident_; + public final ListIdent listident_; + + public LitSVarD(String p1, ListIdent p2) { ident_ = p1; listident_ = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD) { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD x = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD)o; + return this.ident_.equals(x.ident_) && this.listident_.equals(x.listident_); + } + return false; + } + + public int hashCode() { + return 37*(this.ident_.hashCode())+this.listident_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitSVarI.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitSVarI.java new file mode 100644 index 0000000000000000000000000000000000000000..6782024edd3b8a3b95c870e77ad086a2e3d88900 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitSVarI.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class LitSVarI extends Literal { + public final String ident_; + + public LitSVarI(String p1) { ident_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI) { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI x = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI)o; + return this.ident_.equals(x.ident_); + } + return false; + } + + public int hashCode() { + return this.ident_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitString.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitString.java new file mode 100644 index 0000000000000000000000000000000000000000..eb30f17720dd0c65fdee92e46d3acc08941f7f9b --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitString.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class LitString extends Literal { + public final String string_; + + public LitString(String p1) { string_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitString) { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitString x = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitString)o; + return this.string_.equals(x.string_); + } + return false; + } + + public int hashCode() { + return this.string_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitTrue.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitTrue.java new file mode 100644 index 0000000000000000000000000000000000000000..5ebbb93c898b5bbb30e102360eb079991c0bb0cb --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitTrue.java @@ -0,0 +1,22 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class LitTrue extends Literal { + + public LitTrue() { } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue) { + return true; + } + return false; + } + + public int hashCode() { + return 37; + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitURI.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitURI.java new file mode 100644 index 0000000000000000000000000000000000000000..c0fa8e94d95c37c82961fdbd7d1e2edc1f3ef48f --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/LitURI.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class LitURI extends Literal { + public final URIRef uriref_; + + public LitURI(URIRef p1) { uriref_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI) { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI x = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI)o; + return this.uriref_.equals(x.uriref_); + } + return false; + } + + public int hashCode() { + return this.uriref_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Literal.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Literal.java new file mode 100644 index 0000000000000000000000000000000000000000..847570134bd7348632ec5c555f5c2b35e31b6332 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Literal.java @@ -0,0 +1,19 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public abstract class Literal implements java.io.Serializable { + public abstract <R,A> R accept(Literal.Visitor<R,A> v, A arg); + public interface Visitor <R,A> { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitString p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse p, A arg); + + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/NSPrefix.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/NSPrefix.java new file mode 100644 index 0000000000000000000000000000000000000000..cf6c96b0cb0f3f1de765e23f0608cf8a1aa88633 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/NSPrefix.java @@ -0,0 +1,11 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public abstract class NSPrefix implements java.io.Serializable { + public abstract <R,A> R accept(NSPrefix.Visitor<R,A> v, A arg); + public interface Visitor <R,A> { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1 p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2 p, A arg); + + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/NSPrefix1.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/NSPrefix1.java new file mode 100644 index 0000000000000000000000000000000000000000..7835025cf168aa5948e7bb292920199d407694ef --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/NSPrefix1.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class NSPrefix1 extends NSPrefix { + public final String ident_; + + public NSPrefix1(String p1) { ident_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1) { + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1 x = (com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1)o; + return this.ident_.equals(x.ident_); + } + return false; + } + + public int hashCode() { + return this.ident_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/NSPrefix2.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/NSPrefix2.java new file mode 100644 index 0000000000000000000000000000000000000000..3ce2a9bd301922b1a4f6a9a59bb76c0c2023141f --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/NSPrefix2.java @@ -0,0 +1,22 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class NSPrefix2 extends NSPrefix { + + public NSPrefix2() { } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2) { + return true; + } + return false; + } + + public int hashCode() { + return 37; + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentDelay.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentDelay.java new file mode 100644 index 0000000000000000000000000000000000000000..9456e9aa4b691f6ac19f9cacb35eba67cfe57aa4 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentDelay.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class SentDelay extends Sentence { + public final Integer integer_; + + public SentDelay(Integer p1) { integer_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay) { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay x = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay)o; + return this.integer_.equals(x.integer_); + } + return false; + } + + public int hashCode() { + return this.integer_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentGoal.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentGoal.java new file mode 100644 index 0000000000000000000000000000000000000000..5e0e24d02dd7b35bc3ee18dae39d57b58a128b46 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentGoal.java @@ -0,0 +1,25 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class SentGoal extends Sentence { + public final Stm stm_; + public final TruthValue truthvalue_; + + public SentGoal(Stm p1, TruthValue p2) { stm_ = p1; truthvalue_ = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal) { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal x = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal)o; + return this.stm_.equals(x.stm_) && this.truthvalue_.equals(x.truthvalue_); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_.hashCode())+this.truthvalue_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentImport.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentImport.java new file mode 100644 index 0000000000000000000000000000000000000000..856658ac99daaadb2caf90265b9ffbf9d2dcaa5d --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentImport.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class SentImport extends Sentence { + public final String urilit_; + + public SentImport(String p1) { urilit_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport) { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport x = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport)o; + return this.urilit_.equals(x.urilit_); + } + return false; + } + + public int hashCode() { + return this.urilit_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentJudge.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentJudge.java new file mode 100644 index 0000000000000000000000000000000000000000..b7f164c84f47611646834a8fd1325a37800c0fcc --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentJudge.java @@ -0,0 +1,25 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class SentJudge extends Sentence { + public final Stm stm_; + public final TruthValue truthvalue_; + + public SentJudge(Stm p1, TruthValue p2) { stm_ = p1; truthvalue_ = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge) { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge x = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge)o; + return this.stm_.equals(x.stm_) && this.truthvalue_.equals(x.truthvalue_); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_.hashCode())+this.truthvalue_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentOp.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentOp.java new file mode 100644 index 0000000000000000000000000000000000000000..6aad34ce2646c50c2d7b68b8675d9e2dc11d104d --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentOp.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class SentOp extends Sentence { + public final URIRef uriref_; + + public SentOp(URIRef p1) { uriref_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp) { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp x = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp)o; + return this.uriref_.equals(x.uriref_); + } + return false; + } + + public int hashCode() { + return this.uriref_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentPrefix.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentPrefix.java new file mode 100644 index 0000000000000000000000000000000000000000..dfd20e86b41dd11bcb17768b724d8fae14bdc604 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentPrefix.java @@ -0,0 +1,25 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class SentPrefix extends Sentence { + public final NSPrefix nsprefix_; + public final String urilit_; + + public SentPrefix(NSPrefix p1, String p2) { nsprefix_ = p1; urilit_ = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix) { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix x = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix)o; + return this.nsprefix_.equals(x.nsprefix_) && this.urilit_.equals(x.urilit_); + } + return false; + } + + public int hashCode() { + return 37*(this.nsprefix_.hashCode())+this.urilit_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentQuest.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentQuest.java new file mode 100644 index 0000000000000000000000000000000000000000..2bc8a8677033583257600eb706c85215189d5c0e --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/SentQuest.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class SentQuest extends Sentence { + public final Stm stm_; + + public SentQuest(Stm p1) { stm_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest) { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest x = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest)o; + return this.stm_.equals(x.stm_); + } + return false; + } + + public int hashCode() { + return this.stm_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Sentence.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Sentence.java new file mode 100644 index 0000000000000000000000000000000000000000..044f903112a42c00b56da1461af75272802a55e8 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Sentence.java @@ -0,0 +1,16 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public abstract class Sentence implements java.io.Serializable { + public abstract <R,A> R accept(Sentence.Visitor<R,A> v, A arg); + public interface Visitor <R,A> { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal p, A arg); + + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Stm.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Stm.java new file mode 100644 index 0000000000000000000000000000000000000000..317da4345321552f5ffa36af95292e63625ce0c4 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Stm.java @@ -0,0 +1,31 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public abstract class Stm implements java.io.Serializable { + public abstract <R,A> R accept(Stm.Visitor<R,A> v, A arg); + public interface Visitor <R,A> { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm p, A arg); + + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmConj.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmConj.java new file mode 100644 index 0000000000000000000000000000000000000000..28f2a2fd3f77b25149ac564836ae94a920200a70 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmConj.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmConj extends Stm { + public final Stm stm_1, stm_2; + + public StmConj(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmDisj.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmDisj.java new file mode 100644 index 0000000000000000000000000000000000000000..b67ef97565c955a9a4bc1a053c13e832987135c0 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmDisj.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmDisj extends Stm { + public final Stm stm_1, stm_2; + + public StmDisj(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmEquiv.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmEquiv.java new file mode 100644 index 0000000000000000000000000000000000000000..c328f67f58358040bb7d6bf5f2791ce437c3ce9c --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmEquiv.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmEquiv extends Stm { + public final Stm stm_1, stm_2; + + public StmEquiv(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmEqvConc.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmEqvConc.java new file mode 100644 index 0000000000000000000000000000000000000000..e15e79d796d308d50b2e2a0d851806a0e21d61de --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmEqvConc.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmEqvConc extends Stm { + public final Stm stm_1, stm_2; + + public StmEqvConc(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmEqvPred.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmEqvPred.java new file mode 100644 index 0000000000000000000000000000000000000000..e2a6582ead451ed662b3917af0f69be76543b2bc --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmEqvPred.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmEqvPred extends Stm { + public final Stm stm_1, stm_2; + + public StmEqvPred(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmFut.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmFut.java new file mode 100644 index 0000000000000000000000000000000000000000..8c024d80e6ceffe492e3588cf29485b9187062c5 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmFut.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmFut extends Stm { + public final Stm stm_; + + public StmFut(Stm p1) { stm_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut)o; + return this.stm_.equals(x.stm_); + } + return false; + } + + public int hashCode() { + return this.stm_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpConc.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpConc.java new file mode 100644 index 0000000000000000000000000000000000000000..1c9d97a3a06502144c4bc55cff9aae18637a35d0 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpConc.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmImpConc extends Stm { + public final Stm stm_1, stm_2; + + public StmImpConc(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpPred.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpPred.java new file mode 100644 index 0000000000000000000000000000000000000000..5d79058a6b8b3edc5fae98ef125f764770e02137 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpPred.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmImpPred extends Stm { + public final Stm stm_1, stm_2; + + public StmImpPred(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpRet.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpRet.java new file mode 100644 index 0000000000000000000000000000000000000000..b073a91da18131e1f39c16da064685c0ccd84380 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpRet.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmImpRet extends Stm { + public final Stm stm_1, stm_2; + + public StmImpRet(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpl.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..b4f8fa1afa70a5203281896631dd7c8892214d2f --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmImpl.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmImpl extends Stm { + public final Stm stm_1, stm_2; + + public StmImpl(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmInPp.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmInPp.java new file mode 100644 index 0000000000000000000000000000000000000000..9f4fea738a5a00314334685dafe089a1caae669d --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmInPp.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmInPp extends Stm { + public final Term term_1, term_2; + + public StmInPp(Term p1, Term p2) { term_1 = p1; term_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp)o; + return this.term_1.equals(x.term_1) && this.term_2.equals(x.term_2); + } + return false; + } + + public int hashCode() { + return 37*(this.term_1.hashCode())+this.term_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmInher.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmInher.java new file mode 100644 index 0000000000000000000000000000000000000000..e31ba046c8749df5deab3f103041ce97f58cb87b --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmInher.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmInher extends Stm { + public final Term term_1, term_2; + + public StmInher(Term p1, Term p2) { term_1 = p1; term_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher)o; + return this.term_1.equals(x.term_1) && this.term_2.equals(x.term_2); + } + return false; + } + + public int hashCode() { + return 37*(this.term_1.hashCode())+this.term_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmInst.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmInst.java new file mode 100644 index 0000000000000000000000000000000000000000..98b1e777b1c4e85a4533a5fb022095d968355c70 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmInst.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmInst extends Stm { + public final Term term_1, term_2; + + public StmInst(Term p1, Term p2) { term_1 = p1; term_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst)o; + return this.term_1.equals(x.term_1) && this.term_2.equals(x.term_2); + } + return false; + } + + public int hashCode() { + return 37*(this.term_1.hashCode())+this.term_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmNot.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmNot.java new file mode 100644 index 0000000000000000000000000000000000000000..319ea6c1982520078f54eb714063ce5f1c16d533 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmNot.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmNot extends Stm { + public final Stm stm_; + + public StmNot(Stm p1) { stm_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot)o; + return this.stm_.equals(x.stm_); + } + return false; + } + + public int hashCode() { + return this.stm_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmOp.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmOp.java new file mode 100644 index 0000000000000000000000000000000000000000..cbaf68a40ecc1304bbf0fbb3973d36d5303fe522 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmOp.java @@ -0,0 +1,25 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmOp extends Stm { + public final Term term_; + public final ListTerm listterm_; + + public StmOp(Term p1, ListTerm p2) { term_ = p1; listterm_ = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp)o; + return this.term_.equals(x.term_) && this.listterm_.equals(x.listterm_); + } + return false; + } + + public int hashCode() { + return 37*(this.term_.hashCode())+this.listterm_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmPar.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmPar.java new file mode 100644 index 0000000000000000000000000000000000000000..1f456403d47c2ef5fd26620c68acda2f2c5e7152 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmPar.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmPar extends Stm { + public final Stm stm_1, stm_2; + + public StmPar(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmPres.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmPres.java new file mode 100644 index 0000000000000000000000000000000000000000..fa5ccb776f0a47f1bc813c8c2804efd699be099d --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmPres.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmPres extends Stm { + public final Stm stm_; + + public StmPres(Stm p1) { stm_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres)o; + return this.stm_.equals(x.stm_); + } + return false; + } + + public int hashCode() { + return this.stm_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmProp.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmProp.java new file mode 100644 index 0000000000000000000000000000000000000000..3e028a3987dcb2adeb2271534463e3d8afcbf5ff --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmProp.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmProp extends Stm { + public final Term term_1, term_2; + + public StmProp(Term p1, Term p2) { term_1 = p1; term_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp)o; + return this.term_1.equals(x.term_1) && this.term_2.equals(x.term_2); + } + return false; + } + + public int hashCode() { + return 37*(this.term_1.hashCode())+this.term_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmPst.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmPst.java new file mode 100644 index 0000000000000000000000000000000000000000..8edb148d00948864b76f33988117524c4195f27d --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmPst.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmPst extends Stm { + public final Stm stm_; + + public StmPst(Stm p1) { stm_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst)o; + return this.stm_.equals(x.stm_); + } + return false; + } + + public int hashCode() { + return this.stm_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmSeq.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmSeq.java new file mode 100644 index 0000000000000000000000000000000000000000..55e1f8fd40abd63c1d299df1594ef81a01c2d35e --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmSeq.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmSeq extends Stm { + public final Stm stm_1, stm_2; + + public StmSeq(Stm p1, Stm p2) { stm_1 = p1; stm_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq)o; + return this.stm_1.equals(x.stm_1) && this.stm_2.equals(x.stm_2); + } + return false; + } + + public int hashCode() { + return 37*(this.stm_1.hashCode())+this.stm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmSim.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmSim.java new file mode 100644 index 0000000000000000000000000000000000000000..38f04c6aff09a1dfdc42706b4363e415b2daf673 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmSim.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmSim extends Stm { + public final Term term_1, term_2; + + public StmSim(Term p1, Term p2) { term_1 = p1; term_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim)o; + return this.term_1.equals(x.term_1) && this.term_2.equals(x.term_2); + } + return false; + } + + public int hashCode() { + return 37*(this.term_1.hashCode())+this.term_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmTrm.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmTrm.java new file mode 100644 index 0000000000000000000000000000000000000000..f0adea0895e9de85fe0cf23e8188bfac9ea40093 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/StmTrm.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class StmTrm extends Stm { + public final Term term_; + + public StmTrm(Term p1) { term_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm) { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm x = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm)o; + return this.term_.equals(x.term_); + } + return false; + } + + public int hashCode() { + return this.term_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Term.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Term.java new file mode 100644 index 0000000000000000000000000000000000000000..2385b09a75558fe6c863ea5d37bcd1d30cff42ac --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/Term.java @@ -0,0 +1,20 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public abstract class Term implements java.io.Serializable { + public abstract <R,A> R accept(Term.Visitor<R,A> v, A arg); + public interface Visitor <R,A> { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm p, A arg); + + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExDif.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExDif.java new file mode 100644 index 0000000000000000000000000000000000000000..baacfce036824cb1dd1e98978183ecf6c1886915 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExDif.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmExDif extends Term { + public final Term term_1, term_2; + + public TrmExDif(Term p1, Term p2) { term_1 = p1; term_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif)o; + return this.term_1.equals(x.term_1) && this.term_2.equals(x.term_2); + } + return false; + } + + public int hashCode() { + return 37*(this.term_1.hashCode())+this.term_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExImg.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExImg.java new file mode 100644 index 0000000000000000000000000000000000000000..18f1049d9b49e4892abb027fd4dd08cc6f923c75 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExImg.java @@ -0,0 +1,25 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmExImg extends Term { + public final Term term_; + public final ListTerm listterm_1, listterm_2; + + public TrmExImg(Term p1, ListTerm p2, ListTerm p3) { term_ = p1; listterm_1 = p2; listterm_2 = p3; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg)o; + return this.term_.equals(x.term_) && this.listterm_1.equals(x.listterm_1) && this.listterm_2.equals(x.listterm_2); + } + return false; + } + + public int hashCode() { + return 37*(37*(this.term_.hashCode())+this.listterm_1.hashCode())+this.listterm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExInt.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExInt.java new file mode 100644 index 0000000000000000000000000000000000000000..b761a7175b7104e0a66afa6bee34066184778240 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExInt.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmExInt extends Term { + public final Term term_1, term_2; + + public TrmExInt(Term p1, Term p2) { term_1 = p1; term_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt)o; + return this.term_1.equals(x.term_1) && this.term_2.equals(x.term_2); + } + return false; + } + + public int hashCode() { + return 37*(this.term_1.hashCode())+this.term_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExSet.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExSet.java new file mode 100644 index 0000000000000000000000000000000000000000..db98430670fb5e53182479edd7696ee307d03b58 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmExSet.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmExSet extends Term { + public final ListTerm listterm_; + + public TrmExSet(ListTerm p1) { listterm_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet)o; + return this.listterm_.equals(x.listterm_); + } + return false; + } + + public int hashCode() { + return this.listterm_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInDif.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInDif.java new file mode 100644 index 0000000000000000000000000000000000000000..21e646d50075aaef739480d561b561bd821f7049 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInDif.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmInDif extends Term { + public final Term term_1, term_2; + + public TrmInDif(Term p1, Term p2) { term_1 = p1; term_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif)o; + return this.term_1.equals(x.term_1) && this.term_2.equals(x.term_2); + } + return false; + } + + public int hashCode() { + return 37*(this.term_1.hashCode())+this.term_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInImg.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInImg.java new file mode 100644 index 0000000000000000000000000000000000000000..5169b6aa549cd68754233cdaf8495a40aab47cc8 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInImg.java @@ -0,0 +1,25 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmInImg extends Term { + public final Term term_; + public final ListTerm listterm_1, listterm_2; + + public TrmInImg(Term p1, ListTerm p2, ListTerm p3) { term_ = p1; listterm_1 = p2; listterm_2 = p3; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg)o; + return this.term_.equals(x.term_) && this.listterm_1.equals(x.listterm_1) && this.listterm_2.equals(x.listterm_2); + } + return false; + } + + public int hashCode() { + return 37*(37*(this.term_.hashCode())+this.listterm_1.hashCode())+this.listterm_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInInt.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInInt.java new file mode 100644 index 0000000000000000000000000000000000000000..e59aa00bbb1d60a5f3b645cd6957a7039521a02b --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInInt.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmInInt extends Term { + public final Term term_1, term_2; + + public TrmInInt(Term p1, Term p2) { term_1 = p1; term_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt)o; + return this.term_1.equals(x.term_1) && this.term_2.equals(x.term_2); + } + return false; + } + + public int hashCode() { + return 37*(this.term_1.hashCode())+this.term_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInSet.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInSet.java new file mode 100644 index 0000000000000000000000000000000000000000..7d44432356af4a9729f5eb21efc6701ab02afb2e --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmInSet.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmInSet extends Term { + public final ListTerm listterm_; + + public TrmInSet(ListTerm p1) { listterm_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet)o; + return this.listterm_.equals(x.listterm_); + } + return false; + } + + public int hashCode() { + return this.listterm_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmLit.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmLit.java new file mode 100644 index 0000000000000000000000000000000000000000..4ba0328e9a9177205b226362f72ccf3108e55c68 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmLit.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmLit extends Term { + public final Literal literal_; + + public TrmLit(Literal p1) { literal_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit)o; + return this.literal_.equals(x.literal_); + } + return false; + } + + public int hashCode() { + return this.literal_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmProd.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmProd.java new file mode 100644 index 0000000000000000000000000000000000000000..963b6fa9454211df208b8cab0fc6871a3e6d9d64 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmProd.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmProd extends Term { + public final ListTerm listterm_; + + public TrmProd(ListTerm p1) { listterm_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd)o; + return this.listterm_.equals(x.listterm_); + } + return false; + } + + public int hashCode() { + return this.listterm_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmStm.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmStm.java new file mode 100644 index 0000000000000000000000000000000000000000..ffbb1976b5a461bdbba8607c1055c27e055c3c06 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TrmStm.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TrmStm extends Term { + public final Stm stm_; + + public TrmStm(Stm p1) { stm_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm)o; + return this.stm_.equals(x.stm_); + } + return false; + } + + public int hashCode() { + return this.stm_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthE.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthE.java new file mode 100644 index 0000000000000000000000000000000000000000..ded9a852ec21b9b6f80b9669345c892c82fd02fb --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthE.java @@ -0,0 +1,22 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TruthE extends TruthValue { + + public TruthE() { } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE) { + return true; + } + return false; + } + + public int hashCode() { + return 37; + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthF.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthF.java new file mode 100644 index 0000000000000000000000000000000000000000..14333d2474c927638aa0a7998b3e6c07f4725d7a --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthF.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TruthF extends TruthValue { + public final Double double_; + + public TruthF(Double p1) { double_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF)o; + return this.double_.equals(x.double_); + } + return false; + } + + public int hashCode() { + return this.double_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthFC.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthFC.java new file mode 100644 index 0000000000000000000000000000000000000000..1af27e51662354cf8073f5b1f4b42a250bc6bf20 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthFC.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class TruthFC extends TruthValue { + public final Double double_1, double_2; + + public TruthFC(Double p1, Double p2) { double_1 = p1; double_2 = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC x = (com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC)o; + return this.double_1.equals(x.double_1) && this.double_2.equals(x.double_2); + } + return false; + } + + public int hashCode() { + return 37*(this.double_1.hashCode())+this.double_2.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthValue.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthValue.java new file mode 100644 index 0000000000000000000000000000000000000000..951454f40648f1d1689fb29b535966e3b00264ce --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/TruthValue.java @@ -0,0 +1,12 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public abstract class TruthValue implements java.io.Serializable { + public abstract <R,A> R accept(TruthValue.Visitor<R,A> v, A arg); + public interface Visitor <R,A> { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC p, A arg); + + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/URICur.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/URICur.java new file mode 100644 index 0000000000000000000000000000000000000000..aa175d25e94ea3282e2a4ed45218bb84ad7cb5c2 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/URICur.java @@ -0,0 +1,25 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class URICur extends URIRef { + public final NSPrefix nsprefix_; + public final String ident_; + + public URICur(NSPrefix p1, String p2) { nsprefix_ = p1; ident_ = p2; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.URICur) { + com.googlecode.opennars.parser.loan.Loan.Absyn.URICur x = (com.googlecode.opennars.parser.loan.Loan.Absyn.URICur)o; + return this.nsprefix_.equals(x.nsprefix_) && this.ident_.equals(x.ident_); + } + return false; + } + + public int hashCode() { + return 37*(this.nsprefix_.hashCode())+this.ident_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/URIFul.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/URIFul.java new file mode 100644 index 0000000000000000000000000000000000000000..21a9e055604c01f87a1f4330037b46fa6504e21f --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/URIFul.java @@ -0,0 +1,24 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public class URIFul extends URIRef { + public final String urilit_; + + public URIFul(String p1) { urilit_ = p1; } + + public <R,A> R accept(com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef.Visitor<R,A> v, A arg) { return v.visit(this, arg); } + + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul) { + com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul x = (com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul)o; + return this.urilit_.equals(x.urilit_); + } + return false; + } + + public int hashCode() { + return this.urilit_.hashCode(); + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/URIRef.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/URIRef.java new file mode 100644 index 0000000000000000000000000000000000000000..4df8f5cb9a8942e2bc84b09fb3e1e5602fad34e6 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Absyn/URIRef.java @@ -0,0 +1,11 @@ +package com.googlecode.opennars.parser.loan.Loan.Absyn; // Java Package generated by the BNF Converter. + +public abstract class URIRef implements java.io.Serializable { + public abstract <R,A> R accept(URIRef.Visitor<R,A> v, A arg); + public interface Visitor <R,A> { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul p, A arg); + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URICur p, A arg); + + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/AllVisitor.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/AllVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..505a1a777ec2964b4451c85b0ed2ff894e175f23 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/AllVisitor.java @@ -0,0 +1,16 @@ +package com.googlecode.opennars.parser.loan.Loan; + +import com.googlecode.opennars.parser.loan.Loan.Absyn.*; + +/** BNFC-Generated All Visitor */ +public interface AllVisitor<R,A> extends + com.googlecode.opennars.parser.loan.Loan.Absyn.Document.Visitor<R,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule.Visitor<R,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence.Visitor<R,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<R,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<R,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef.Visitor<R,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<R,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix.Visitor<R,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue.Visitor<R,A> +{} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/ComposVisitor.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/ComposVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..adce4b93d2a56def6a1fe7562e2d1e98d4b492b0 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/ComposVisitor.java @@ -0,0 +1,452 @@ +package com.googlecode.opennars.parser.loan.Loan; +import com.googlecode.opennars.parser.loan.Loan.Absyn.*; +/** BNFC-Generated Composition Visitor +*/ + +public class ComposVisitor<A> implements + com.googlecode.opennars.parser.loan.Loan.Absyn.Document.Visitor<com.googlecode.opennars.parser.loan.Loan.Absyn.Document,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule.Visitor<com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence.Visitor<com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm.Visitor<com.googlecode.opennars.parser.loan.Loan.Absyn.Stm,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.Term.Visitor<com.googlecode.opennars.parser.loan.Loan.Absyn.Term,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef.Visitor<com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal.Visitor<com.googlecode.opennars.parser.loan.Loan.Absyn.Literal,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix.Visitor<com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix,A>, + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue.Visitor<com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue,A> +{ +/* Document */ + public Document visit(com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR p, A arg) + { + BaseRule baserule_ = p.baserule_.accept(this, arg); + ListSentence listsentence_ = new ListSentence(); + for (Sentence x : p.listsentence_) { + listsentence_.add(x.accept(this,arg)); + } + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR(baserule_, listsentence_); + } + public Document visit(com.googlecode.opennars.parser.loan.Loan.Absyn.Doc p, A arg) + { + ListSentence listsentence_ = new ListSentence(); + for (Sentence x : p.listsentence_) { + listsentence_.add(x.accept(this,arg)); + } + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.Doc(listsentence_); + } + +/* BaseRule */ + public BaseRule visit(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR p, A arg) + { + String urilit_ = p.urilit_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR(urilit_); + } + +/* Sentence */ + public Sentence visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix p, A arg) + { + NSPrefix nsprefix_ = p.nsprefix_.accept(this, arg); + String urilit_ = p.urilit_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix(nsprefix_, urilit_); + } + public Sentence visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport p, A arg) + { + String urilit_ = p.urilit_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport(urilit_); + } + public Sentence visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay p, A arg) + { + Integer integer_ = p.integer_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay(integer_); + } + public Sentence visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp p, A arg) + { + URIRef uriref_ = p.uriref_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp(uriref_); + } + public Sentence visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge p, A arg) + { + Stm stm_ = p.stm_.accept(this, arg); + TruthValue truthvalue_ = p.truthvalue_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge(stm_, truthvalue_); + } + public Sentence visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest p, A arg) + { + Stm stm_ = p.stm_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest(stm_); + } + public Sentence visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal p, A arg) + { + Stm stm_ = p.stm_.accept(this, arg); + TruthValue truthvalue_ = p.truthvalue_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal(stm_, truthvalue_); + } + +/* Stm */ + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq p, A arg) + { + Stm stm_1 = p.stm_1.accept(this, arg); + Stm stm_2 = p.stm_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq(stm_1, stm_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot p, A arg) + { + Stm stm_ = p.stm_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot(stm_); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst p, A arg) + { + Stm stm_ = p.stm_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst(stm_); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres p, A arg) + { + Stm stm_ = p.stm_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres(stm_); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut p, A arg) + { + Stm stm_ = p.stm_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut(stm_); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher p, A arg) + { + Term term_1 = p.term_1.accept(this, arg); + Term term_2 = p.term_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher(term_1, term_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim p, A arg) + { + Term term_1 = p.term_1.accept(this, arg); + Term term_2 = p.term_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim(term_1, term_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst p, A arg) + { + Term term_1 = p.term_1.accept(this, arg); + Term term_2 = p.term_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst(term_1, term_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp p, A arg) + { + Term term_1 = p.term_1.accept(this, arg); + Term term_2 = p.term_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp(term_1, term_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp p, A arg) + { + Term term_1 = p.term_1.accept(this, arg); + Term term_2 = p.term_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp(term_1, term_2); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp p, A arg) + { + Term term_ = p.term_.accept(this, arg); + ListTerm listterm_ = new ListTerm(); + for (Term x : p.listterm_) { + listterm_.add(x.accept(this,arg)); + } + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp(term_, listterm_); + } + public Stm visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm p, A arg) + { + Term term_ = p.term_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm(term_); + } + +/* Term */ + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt p, A arg) + { + Term term_1 = p.term_1.accept(this, arg); + Term term_2 = p.term_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt(term_1, term_2); + } + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt p, A arg) + { + Term term_1 = p.term_1.accept(this, arg); + Term term_2 = p.term_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt(term_1, term_2); + } + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif p, A arg) + { + Term term_1 = p.term_1.accept(this, arg); + Term term_2 = p.term_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif(term_1, term_2); + } + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif p, A arg) + { + Term term_1 = p.term_1.accept(this, arg); + Term term_2 = p.term_2.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif(term_1, term_2); + } + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg p, A arg) + { + Term term_ = p.term_.accept(this, arg); + ListTerm listterm_1 = new ListTerm(); + for (Term x : p.listterm_1) { + listterm_1.add(x.accept(this,arg)); + } + ListTerm listterm_2 = new ListTerm(); + for (Term x : p.listterm_2) { + listterm_2.add(x.accept(this,arg)); + } + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg(term_, listterm_1, listterm_2); + } + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg p, A arg) + { + Term term_ = p.term_.accept(this, arg); + ListTerm listterm_1 = new ListTerm(); + for (Term x : p.listterm_1) { + listterm_1.add(x.accept(this,arg)); + } + ListTerm listterm_2 = new ListTerm(); + for (Term x : p.listterm_2) { + listterm_2.add(x.accept(this,arg)); + } + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg(term_, listterm_1, listterm_2); + } + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet p, A arg) + { + ListTerm listterm_ = new ListTerm(); + for (Term x : p.listterm_) { + listterm_.add(x.accept(this,arg)); + } + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet(listterm_); + } + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet p, A arg) + { + ListTerm listterm_ = new ListTerm(); + for (Term x : p.listterm_) { + listterm_.add(x.accept(this,arg)); + } + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet(listterm_); + } + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd p, A arg) + { + ListTerm listterm_ = new ListTerm(); + for (Term x : p.listterm_) { + listterm_.add(x.accept(this,arg)); + } + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd(listterm_); + } + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit p, A arg) + { + Literal literal_ = p.literal_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit(literal_); + } + public Term visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm p, A arg) + { + Stm stm_ = p.stm_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm(stm_); + } + +/* URIRef */ + public URIRef visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul p, A arg) + { + String urilit_ = p.urilit_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul(urilit_); + } + public URIRef visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URICur p, A arg) + { + NSPrefix nsprefix_ = p.nsprefix_.accept(this, arg); + String ident_ = p.ident_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.URICur(nsprefix_, ident_); + } + +/* Literal */ + public Literal visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar p, A arg) + { + String ident_ = p.ident_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar(ident_); + } + public Literal visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn p, A arg) + { + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn(); + } + public Literal visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD p, A arg) + { + String ident_ = p.ident_; + ListIdent listident_ = p.listident_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD(ident_, listident_); + } + public Literal visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI p, A arg) + { + String ident_ = p.ident_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI(ident_); + } + public Literal visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI p, A arg) + { + URIRef uriref_ = p.uriref_.accept(this, arg); + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI(uriref_); + } + public Literal visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt p, A arg) + { + Integer integer_ = p.integer_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt(integer_); + } + public Literal visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl p, A arg) + { + Double double_ = p.double_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl(double_); + } + public Literal visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitString p, A arg) + { + String string_ = p.string_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.LitString(string_); + } + public Literal visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue p, A arg) + { + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue(); + } + public Literal visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse p, A arg) + { + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse(); + } + +/* NSPrefix */ + public NSPrefix visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1 p, A arg) + { + String ident_ = p.ident_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1(ident_); + } + public NSPrefix visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2 p, A arg) + { + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2(); + } + +/* TruthValue */ + public TruthValue visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE p, A arg) + { + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE(); + } + public TruthValue visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF p, A arg) + { + Double double_ = p.double_; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF(double_); + } + public TruthValue visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC p, A arg) + { + Double double_1 = p.double_1; + Double double_2 = p.double_2; + + return new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC(double_1, double_2); + } + +} \ No newline at end of file diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/FoldVisitor.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/FoldVisitor.java new file mode 100644 index 0000000000000000000000000000000000000000..1ce511699bc20b5f6d33ea42acd388baaad23f96 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/FoldVisitor.java @@ -0,0 +1,362 @@ +package com.googlecode.opennars.parser.loan.Loan; + +import com.googlecode.opennars.parser.loan.Loan.Absyn.*; +import java.util.Collections; +import java.util.List; +import java.util.ArrayList; + +/** BNFC-Generated Fold Visitor */ +public abstract class FoldVisitor<R,A> implements AllVisitor<R,A> { + public abstract R leaf(A arg); + public abstract R combine(R x, R y, A arg); + +/* Document */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR p, A arg) { + R r = leaf(arg); + r = combine(p.baserule_.accept(this, arg), r, arg); + for (Sentence x : p.listsentence_) { + r = combine(x.accept(this,arg), r, arg); + } + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.Doc p, A arg) { + R r = leaf(arg); + for (Sentence x : p.listsentence_) { + r = combine(x.accept(this,arg), r, arg); + } + return r; + } + +/* BaseRule */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR p, A arg) { + R r = leaf(arg); + return r; + } + +/* Sentence */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix p, A arg) { + R r = leaf(arg); + r = combine(p.nsprefix_.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp p, A arg) { + R r = leaf(arg); + r = combine(p.uriref_.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge p, A arg) { + R r = leaf(arg); + r = combine(p.stm_.accept(this, arg), r, arg); + r = combine(p.truthvalue_.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest p, A arg) { + R r = leaf(arg); + r = combine(p.stm_.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal p, A arg) { + R r = leaf(arg); + r = combine(p.stm_.accept(this, arg), r, arg); + r = combine(p.truthvalue_.accept(this, arg), r, arg); + return r; + } + +/* Stm */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq p, A arg) { + R r = leaf(arg); + r = combine(p.stm_1.accept(this, arg), r, arg); + r = combine(p.stm_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot p, A arg) { + R r = leaf(arg); + r = combine(p.stm_.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst p, A arg) { + R r = leaf(arg); + r = combine(p.stm_.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres p, A arg) { + R r = leaf(arg); + r = combine(p.stm_.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut p, A arg) { + R r = leaf(arg); + r = combine(p.stm_.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher p, A arg) { + R r = leaf(arg); + r = combine(p.term_1.accept(this, arg), r, arg); + r = combine(p.term_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim p, A arg) { + R r = leaf(arg); + r = combine(p.term_1.accept(this, arg), r, arg); + r = combine(p.term_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst p, A arg) { + R r = leaf(arg); + r = combine(p.term_1.accept(this, arg), r, arg); + r = combine(p.term_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp p, A arg) { + R r = leaf(arg); + r = combine(p.term_1.accept(this, arg), r, arg); + r = combine(p.term_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp p, A arg) { + R r = leaf(arg); + r = combine(p.term_1.accept(this, arg), r, arg); + r = combine(p.term_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp p, A arg) { + R r = leaf(arg); + r = combine(p.term_.accept(this, arg), r, arg); + for (Term x : p.listterm_) { + r = combine(x.accept(this,arg), r, arg); + } + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm p, A arg) { + R r = leaf(arg); + r = combine(p.term_.accept(this, arg), r, arg); + return r; + } + +/* Term */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt p, A arg) { + R r = leaf(arg); + r = combine(p.term_1.accept(this, arg), r, arg); + r = combine(p.term_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt p, A arg) { + R r = leaf(arg); + r = combine(p.term_1.accept(this, arg), r, arg); + r = combine(p.term_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif p, A arg) { + R r = leaf(arg); + r = combine(p.term_1.accept(this, arg), r, arg); + r = combine(p.term_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif p, A arg) { + R r = leaf(arg); + r = combine(p.term_1.accept(this, arg), r, arg); + r = combine(p.term_2.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg p, A arg) { + R r = leaf(arg); + r = combine(p.term_.accept(this, arg), r, arg); + for (Term x : p.listterm_1) { + r = combine(x.accept(this,arg), r, arg); + } + for (Term x : p.listterm_2) { + r = combine(x.accept(this,arg), r, arg); + } + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg p, A arg) { + R r = leaf(arg); + r = combine(p.term_.accept(this, arg), r, arg); + for (Term x : p.listterm_1) { + r = combine(x.accept(this,arg), r, arg); + } + for (Term x : p.listterm_2) { + r = combine(x.accept(this,arg), r, arg); + } + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet p, A arg) { + R r = leaf(arg); + for (Term x : p.listterm_) { + r = combine(x.accept(this,arg), r, arg); + } + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet p, A arg) { + R r = leaf(arg); + for (Term x : p.listterm_) { + r = combine(x.accept(this,arg), r, arg); + } + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd p, A arg) { + R r = leaf(arg); + for (Term x : p.listterm_) { + r = combine(x.accept(this,arg), r, arg); + } + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit p, A arg) { + R r = leaf(arg); + r = combine(p.literal_.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm p, A arg) { + R r = leaf(arg); + r = combine(p.stm_.accept(this, arg), r, arg); + return r; + } + +/* URIRef */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URICur p, A arg) { + R r = leaf(arg); + r = combine(p.nsprefix_.accept(this, arg), r, arg); + return r; + } + +/* Literal */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI p, A arg) { + R r = leaf(arg); + r = combine(p.uriref_.accept(this, arg), r, arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitString p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse p, A arg) { + R r = leaf(arg); + return r; + } + +/* NSPrefix */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1 p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2 p, A arg) { + R r = leaf(arg); + return r; + } + +/* TruthValue */ + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF p, A arg) { + R r = leaf(arg); + return r; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC p, A arg) { + R r = leaf(arg); + return r; + } + + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Loan.cup b/open-nars/com/googlecode/opennars/parser/loan/Loan/Loan.cup new file mode 100644 index 0000000000000000000000000000000000000000..5a2f44844535bca2e7bde6cd77b318479c34cb4f --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Loan.cup @@ -0,0 +1,197 @@ +// -*- Java -*- This Cup file was machine-generated by BNFC +package com.googlecode.opennars.parser.loan.Loan; + +parser code {: + public com.googlecode.opennars.parser.loan.Loan.Absyn.Document pDocument() throws Exception + { + java_cup.runtime.Symbol res = parse(); + return (com.googlecode.opennars.parser.loan.Loan.Absyn.Document) res.value; + } + +public <B,A extends java.util.LinkedList<? super B>> A cons_(B x, A xs) { xs.addFirst(x); return xs; } + +public void syntax_error(java_cup.runtime.Symbol cur_token) +{ + report_error("Syntax Error, trying to recover and continue parse...", cur_token); +} + +public void unrecovered_syntax_error(java_cup.runtime.Symbol cur_token) throws java.lang.Exception +{ + throw new Exception("Unrecoverable Syntax Error"); +} + +:} + +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Document Document; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule BaseRule; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence ListSentence; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence Sentence; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Stm Stm; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Stm Stm1; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Stm Stm2; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Stm Stm3; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Term Term; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Term Term1; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Term Term2; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Term Term3; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm ListTerm; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent ListIdent; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef URIRef; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.Literal Literal; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix NSPrefix; +nonterminal com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue TruthValue; + +terminal _SYMB_0; // @base +terminal _SYMB_1; // . +terminal _SYMB_2; // @prefix +terminal _SYMB_3; // @import +terminal _SYMB_4; // @delay +terminal _SYMB_5; // @operator +terminal _SYMB_6; // ? +terminal _SYMB_7; // ! +terminal _SYMB_8; // ==> +terminal _SYMB_9; // <=> +terminal _SYMB_10; // =/> +terminal _SYMB_11; // =\> +terminal _SYMB_12; // =|> +terminal _SYMB_13; // </> +terminal _SYMB_14; // <|> +terminal _SYMB_15; // && +terminal _SYMB_16; // || +terminal _SYMB_17; // ; +terminal _SYMB_18; // , +terminal _SYMB_19; // --> +terminal _SYMB_20; // <-> +terminal _SYMB_21; // }-> +terminal _SYMB_22; // --[ +terminal _SYMB_23; // }-[ +terminal _SYMB_24; // ( +terminal _SYMB_25; // ) +terminal _SYMB_26; // & +terminal _SYMB_27; // | +terminal _SYMB_28; // - +terminal _SYMB_29; // ~ +terminal _SYMB_30; // _|_ +terminal _SYMB_31; // { +terminal _SYMB_32; // } +terminal _SYMB_33; // [ +terminal _SYMB_34; // ] +terminal _SYMB_35; // # +terminal _SYMB_36; // : +terminal _SYMB_37; // % +terminal _SYMB_38; // extension +terminal _SYMB_39; // false +terminal _SYMB_40; // future +terminal _SYMB_41; // intension +terminal _SYMB_42; // not +terminal _SYMB_43; // past +terminal _SYMB_44; // present +terminal _SYMB_45; // true + +terminal String _STRING_; + +terminal Integer _INTEGER_; +terminal Double _DOUBLE_; +terminal String _IDENT_; + +terminal String URILit; + + +start with Document; + + +Document ::= BaseRule:p_1 ListSentence:p_2 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR(p_1,p_2); :} + | ListSentence:p_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.Doc(p_1); :} +; +BaseRule ::= _SYMB_0 URILit:p_2 _SYMB_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR(p_2); :} +; +ListSentence ::= /* empty */ {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence(); :} + | ListSentence:p_1 Sentence:p_2 {: RESULT = p_1; p_1.addLast(p_2); :} +; +Sentence ::= _SYMB_2 NSPrefix:p_2 URILit:p_3 _SYMB_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix(p_2,p_3); :} + | _SYMB_3 URILit:p_2 _SYMB_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport(p_2); :} + | _SYMB_4 _INTEGER_:p_2 _SYMB_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay(p_2); :} + | _SYMB_5 URIRef:p_2 _SYMB_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp(p_2); :} + | Stm:p_1 TruthValue:p_2 _SYMB_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge(p_1,p_2); :} + | Stm:p_1 _SYMB_6 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest(p_1); :} + | Stm:p_1 TruthValue:p_2 _SYMB_7 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal(p_1,p_2); :} +; +Stm ::= Stm:p_1 _SYMB_8 Stm1:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl(p_1,p_3); :} + | Stm:p_1 _SYMB_9 Stm1:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv(p_1,p_3); :} + | Stm:p_1 _SYMB_10 Stm1:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred(p_1,p_3); :} + | Stm:p_1 _SYMB_11 Stm1:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet(p_1,p_3); :} + | Stm:p_1 _SYMB_12 Stm1:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc(p_1,p_3); :} + | Stm:p_1 _SYMB_13 Stm1:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred(p_1,p_3); :} + | Stm:p_1 _SYMB_14 Stm1:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc(p_1,p_3); :} + | Stm1:p_1 {: RESULT = p_1; :} +; +Stm1 ::= Stm1:p_1 _SYMB_15 Stm2:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj(p_1,p_3); :} + | Stm1:p_1 _SYMB_16 Stm2:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj(p_1,p_3); :} + | Stm1:p_1 _SYMB_17 Stm2:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar(p_1,p_3); :} + | Stm1:p_1 _SYMB_18 Stm2:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq(p_1,p_3); :} + | Stm2:p_1 {: RESULT = p_1; :} +; +Stm2 ::= _SYMB_42 Stm3:p_2 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot(p_2); :} + | _SYMB_43 Stm3:p_2 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst(p_2); :} + | _SYMB_44 Stm3:p_2 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres(p_2); :} + | _SYMB_40 Stm3:p_2 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut(p_2); :} + | Stm3:p_1 {: RESULT = p_1; :} +; +Stm3 ::= Term:p_1 _SYMB_19 Term:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher(p_1,p_3); :} + | Term:p_1 _SYMB_20 Term:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim(p_1,p_3); :} + | Term:p_1 _SYMB_21 Term:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst(p_1,p_3); :} + | Term:p_1 _SYMB_22 Term:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp(p_1,p_3); :} + | Term:p_1 _SYMB_23 Term:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp(p_1,p_3); :} + | Term:p_1 _SYMB_24 ListTerm:p_3 _SYMB_25 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp(p_1,p_3); :} + | Term:p_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm(p_1); :} + | _SYMB_24 Stm:p_2 _SYMB_25 {: RESULT = p_2; :} +; +Term ::= Term:p_1 _SYMB_26 Term1:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt(p_1,p_3); :} + | Term:p_1 _SYMB_27 Term1:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt(p_1,p_3); :} + | Term1:p_1 {: RESULT = p_1; :} +; +Term1 ::= Term1:p_1 _SYMB_28 Term2:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif(p_1,p_3); :} + | Term1:p_1 _SYMB_29 Term2:p_3 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif(p_1,p_3); :} + | Term2:p_1 {: RESULT = p_1; :} +; +Term2 ::= Term:p_1 _SYMB_38 _SYMB_24 ListTerm:p_4 _SYMB_30 ListTerm:p_6 _SYMB_25 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg(p_1,p_4,p_6); :} + | Term:p_1 _SYMB_41 _SYMB_24 ListTerm:p_4 _SYMB_30 ListTerm:p_6 _SYMB_25 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg(p_1,p_4,p_6); :} + | Term3:p_1 {: RESULT = p_1; :} +; +Term3 ::= _SYMB_31 ListTerm:p_2 _SYMB_32 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet(p_2); :} + | _SYMB_33 ListTerm:p_2 _SYMB_34 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet(p_2); :} + | _SYMB_24 ListTerm:p_2 _SYMB_25 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd(p_2); :} + | Literal:p_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit(p_1); :} + | _SYMB_24 Stm:p_2 _SYMB_25 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm(p_2); :} + | _SYMB_24 Term:p_2 _SYMB_25 {: RESULT = p_2; :} +; +ListTerm ::= /* empty */ {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm(); :} + | Term:p_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm(); RESULT.addLast(p_1); :} + | Term:p_1 _SYMB_18 ListTerm:p_3 {: RESULT = p_3; p_3.addFirst(p_1); :} +; +ListIdent ::= /* empty */ {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent(); :} + | _IDENT_:p_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent(); RESULT.addLast(p_1); :} + | _IDENT_:p_1 _SYMB_18 ListIdent:p_3 {: RESULT = p_3; p_3.addFirst(p_1); :} +; +URIRef ::= URILit:p_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul(p_1); :} + | NSPrefix:p_1 _IDENT_:p_2 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.URICur(p_1,p_2); :} +; +Literal ::= _SYMB_6 _IDENT_:p_2 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar(p_2); :} + | _SYMB_6 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn(); :} + | _SYMB_35 _IDENT_:p_2 _SYMB_24 ListIdent:p_4 _SYMB_25 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD(p_2,p_4); :} + | _SYMB_35 _IDENT_:p_2 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI(p_2); :} + | URIRef:p_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI(p_1); :} + | _INTEGER_:p_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt(p_1); :} + | _DOUBLE_:p_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl(p_1); :} + | _STRING_:p_1 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitString(p_1); :} + | _SYMB_45 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue(); :} + | _SYMB_39 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse(); :} +; +NSPrefix ::= _IDENT_:p_1 _SYMB_36 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1(p_1); :} + | _SYMB_36 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2(); :} +; +TruthValue ::= /* empty */ {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE(); :} + | _SYMB_37 _DOUBLE_:p_2 _SYMB_37 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF(p_2); :} + | _SYMB_37 _DOUBLE_:p_2 _SYMB_17 _DOUBLE_:p_4 _SYMB_37 {: RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC(p_2,p_4); :} +; + diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/PrettyPrinter.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/PrettyPrinter.java new file mode 100644 index 0000000000000000000000000000000000000000..0bb7940ed2f72d0269d9d2a3b0ce613121682a48 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/PrettyPrinter.java @@ -0,0 +1,1458 @@ +package com.googlecode.opennars.parser.loan.Loan; +import com.googlecode.opennars.parser.loan.Loan.Absyn.*; + +public class PrettyPrinter +{ + //For certain applications increasing the initial size of the buffer may improve performance. + private static final int INITIAL_BUFFER_SIZE = 128; + //You may wish to change the parentheses used in precedence. + private static final String _L_PAREN = new String("("); + private static final String _R_PAREN = new String(")"); + //You may wish to change render + private static void render(String s) + { + if (s.equals("{")) + { + buf_.append("\n"); + indent(); + buf_.append(s); + _n_ = _n_ + 2; + buf_.append("\n"); + indent(); + } + else if (s.equals("(") || s.equals("[")) + buf_.append(s); + else if (s.equals(")") || s.equals("]")) + { + backup(); + buf_.append(s); + buf_.append(" "); + } + else if (s.equals("}")) + { + _n_ = _n_ - 2; + backup(); + backup(); + buf_.append(s); + buf_.append("\n"); + indent(); + } + else if (s.equals(",")) + { + backup(); + buf_.append(s); + buf_.append(" "); + } + else if (s.equals(";")) + { + backup(); + buf_.append(s); + buf_.append("\n"); + indent(); + } + else if (s.equals("")) return; + else + { + buf_.append(s); + buf_.append(" "); + } + } + + + // print and show methods are defined for each category. + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.Document foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.Document foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.Term foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.Term foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String print(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue foo) + { + pp(foo, 0); + trim(); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + public static String show(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue foo) + { + sh(foo); + String temp = buf_.toString(); + buf_.delete(0,buf_.length()); + return temp; + } + /*** You shouldn't need to change anything beyond this point. ***/ + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.Document foo, int _i_) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR _docbr = (com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_docbr.baserule_, 0); + pp(_docbr.listsentence_, 0); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.Doc) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Doc _doc = (com.googlecode.opennars.parser.loan.Loan.Absyn.Doc) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_doc.listsentence_, 0); + if (_i_ > 0) render(_R_PAREN); + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule foo, int _i_) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR _baser = (com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR) foo; + if (_i_ > 0) render(_L_PAREN); + render("@base"); + pp(_baser.urilit_, 0); + render("."); + if (_i_ > 0) render(_R_PAREN); + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence foo, int _i_) + { + for (java.util.Iterator<Sentence> it = foo.iterator(); it.hasNext();) + { + pp(it.next(), 0); + if (it.hasNext()) { + render(""); + } else { + render(""); + } + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence foo, int _i_) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix _sentprefix = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix) foo; + if (_i_ > 0) render(_L_PAREN); + render("@prefix"); + pp(_sentprefix.nsprefix_, 0); + pp(_sentprefix.urilit_, 0); + render("."); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport _sentimport = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport) foo; + if (_i_ > 0) render(_L_PAREN); + render("@import"); + pp(_sentimport.urilit_, 0); + render("."); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay _sentdelay = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay) foo; + if (_i_ > 0) render(_L_PAREN); + render("@delay"); + pp(_sentdelay.integer_, 0); + render("."); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp _sentop = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp) foo; + if (_i_ > 0) render(_L_PAREN); + render("@operator"); + pp(_sentop.uriref_, 0); + render("."); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge _sentjudge = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_sentjudge.stm_, 0); + pp(_sentjudge.truthvalue_, 0); + render("."); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest _sentquest = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_sentquest.stm_, 0); + render("?"); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal _sentgoal = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_sentgoal.stm_, 0); + pp(_sentgoal.truthvalue_, 0); + render("!"); + if (_i_ > 0) render(_R_PAREN); + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm foo, int _i_) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl _stmimpl = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_stmimpl.stm_1, 0); + render("==>"); + pp(_stmimpl.stm_2, 1); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv _stmequiv = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_stmequiv.stm_1, 0); + render("<=>"); + pp(_stmequiv.stm_2, 1); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred _stmimppred = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_stmimppred.stm_1, 0); + render("=/>"); + pp(_stmimppred.stm_2, 1); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet _stmimpret = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_stmimpret.stm_1, 0); + render("=\\>"); + pp(_stmimpret.stm_2, 1); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc _stmimpconc = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_stmimpconc.stm_1, 0); + render("=|>"); + pp(_stmimpconc.stm_2, 1); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred _stmeqvpred = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_stmeqvpred.stm_1, 0); + render("</>"); + pp(_stmeqvpred.stm_2, 1); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc _stmeqvconc = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_stmeqvconc.stm_1, 0); + render("<|>"); + pp(_stmeqvconc.stm_2, 1); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj _stmconj = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj) foo; + if (_i_ > 1) render(_L_PAREN); + pp(_stmconj.stm_1, 1); + render("&&"); + pp(_stmconj.stm_2, 2); + if (_i_ > 1) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj _stmdisj = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj) foo; + if (_i_ > 1) render(_L_PAREN); + pp(_stmdisj.stm_1, 1); + render("||"); + pp(_stmdisj.stm_2, 2); + if (_i_ > 1) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar _stmpar = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar) foo; + if (_i_ > 1) render(_L_PAREN); + pp(_stmpar.stm_1, 1); + render(";"); + pp(_stmpar.stm_2, 2); + if (_i_ > 1) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq _stmseq = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq) foo; + if (_i_ > 1) render(_L_PAREN); + pp(_stmseq.stm_1, 1); + render(","); + pp(_stmseq.stm_2, 2); + if (_i_ > 1) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot _stmnot = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot) foo; + if (_i_ > 2) render(_L_PAREN); + render("not"); + pp(_stmnot.stm_, 3); + if (_i_ > 2) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst _stmpst = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst) foo; + if (_i_ > 2) render(_L_PAREN); + render("past"); + pp(_stmpst.stm_, 3); + if (_i_ > 2) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres _stmpres = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres) foo; + if (_i_ > 2) render(_L_PAREN); + render("present"); + pp(_stmpres.stm_, 3); + if (_i_ > 2) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut _stmfut = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut) foo; + if (_i_ > 2) render(_L_PAREN); + render("future"); + pp(_stmfut.stm_, 3); + if (_i_ > 2) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher _stminher = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher) foo; + if (_i_ > 3) render(_L_PAREN); + pp(_stminher.term_1, 0); + render("-->"); + pp(_stminher.term_2, 0); + if (_i_ > 3) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim _stmsim = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim) foo; + if (_i_ > 3) render(_L_PAREN); + pp(_stmsim.term_1, 0); + render("<->"); + pp(_stmsim.term_2, 0); + if (_i_ > 3) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst _stminst = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst) foo; + if (_i_ > 3) render(_L_PAREN); + pp(_stminst.term_1, 0); + render("}->"); + pp(_stminst.term_2, 0); + if (_i_ > 3) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp _stmprop = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp) foo; + if (_i_ > 3) render(_L_PAREN); + pp(_stmprop.term_1, 0); + render("--["); + pp(_stmprop.term_2, 0); + if (_i_ > 3) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp _stminpp = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp) foo; + if (_i_ > 3) render(_L_PAREN); + pp(_stminpp.term_1, 0); + render("}-["); + pp(_stminpp.term_2, 0); + if (_i_ > 3) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp _stmop = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp) foo; + if (_i_ > 3) render(_L_PAREN); + pp(_stmop.term_, 0); + render("("); + pp(_stmop.listterm_, 0); + render(")"); + if (_i_ > 3) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm _stmtrm = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm) foo; + if (_i_ > 3) render(_L_PAREN); + pp(_stmtrm.term_, 0); + if (_i_ > 3) render(_R_PAREN); + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.Term foo, int _i_) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt _trmexint = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_trmexint.term_1, 0); + render("&"); + pp(_trmexint.term_2, 1); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt _trminint = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_trminint.term_1, 0); + render("|"); + pp(_trminint.term_2, 1); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif _trmexdif = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif) foo; + if (_i_ > 1) render(_L_PAREN); + pp(_trmexdif.term_1, 1); + render("-"); + pp(_trmexdif.term_2, 2); + if (_i_ > 1) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif _trmindif = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif) foo; + if (_i_ > 1) render(_L_PAREN); + pp(_trmindif.term_1, 1); + render("~"); + pp(_trmindif.term_2, 2); + if (_i_ > 1) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg _trmeximg = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg) foo; + if (_i_ > 2) render(_L_PAREN); + pp(_trmeximg.term_, 0); + render("extension"); + render("("); + pp(_trmeximg.listterm_1, 0); + render("_|_"); + pp(_trmeximg.listterm_2, 0); + render(")"); + if (_i_ > 2) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg _trminimg = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg) foo; + if (_i_ > 2) render(_L_PAREN); + pp(_trminimg.term_, 0); + render("intension"); + render("("); + pp(_trminimg.listterm_1, 0); + render("_|_"); + pp(_trminimg.listterm_2, 0); + render(")"); + if (_i_ > 2) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet _trmexset = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet) foo; + if (_i_ > 3) render(_L_PAREN); + render("{"); + pp(_trmexset.listterm_, 0); + render("}"); + if (_i_ > 3) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet _trminset = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet) foo; + if (_i_ > 3) render(_L_PAREN); + render("["); + pp(_trminset.listterm_, 0); + render("]"); + if (_i_ > 3) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd _trmprod = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd) foo; + if (_i_ > 3) render(_L_PAREN); + render("("); + pp(_trmprod.listterm_, 0); + render(")"); + if (_i_ > 3) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit _trmlit = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit) foo; + if (_i_ > 3) render(_L_PAREN); + pp(_trmlit.literal_, 0); + if (_i_ > 3) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm _trmstm = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm) foo; + if (_i_ > 3) render(_L_PAREN); + render("("); + pp(_trmstm.stm_, 0); + render(")"); + if (_i_ > 3) render(_R_PAREN); + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm foo, int _i_) + { + for (java.util.Iterator<Term> it = foo.iterator(); it.hasNext();) + { + pp(it.next(), 0); + if (it.hasNext()) { + render(","); + } else { + render(""); + } + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent foo, int _i_) + { + for (java.util.Iterator<String> it = foo.iterator(); it.hasNext();) + { + pp(it.next(), 0); + if (it.hasNext()) { + render(","); + } else { + render(""); + } + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef foo, int _i_) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul _uriful = (com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_uriful.urilit_, 0); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.URICur) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.URICur _uricur = (com.googlecode.opennars.parser.loan.Loan.Absyn.URICur) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_uricur.nsprefix_, 0); + pp(_uricur.ident_, 0); + if (_i_ > 0) render(_R_PAREN); + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal foo, int _i_) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar _litqvar = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar) foo; + if (_i_ > 0) render(_L_PAREN); + render("?"); + pp(_litqvar.ident_, 0); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn _litqvaran = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn) foo; + if (_i_ > 0) render(_L_PAREN); + render("?"); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD _litsvard = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD) foo; + if (_i_ > 0) render(_L_PAREN); + render("#"); + pp(_litsvard.ident_, 0); + render("("); + pp(_litsvard.listident_, 0); + render(")"); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI _litsvari = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI) foo; + if (_i_ > 0) render(_L_PAREN); + render("#"); + pp(_litsvari.ident_, 0); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI _lituri = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_lituri.uriref_, 0); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt _litint = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_litint.integer_, 0); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl _litdbl = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_litdbl.double_, 0); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitString) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitString _litstring = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitString) foo; + if (_i_ > 0) render(_L_PAREN); + printQuoted(_litstring.string_); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue _littrue = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue) foo; + if (_i_ > 0) render(_L_PAREN); + render("true"); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse _litfalse = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse) foo; + if (_i_ > 0) render(_L_PAREN); + render("false"); + if (_i_ > 0) render(_R_PAREN); + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix foo, int _i_) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1 _nsprefix1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1) foo; + if (_i_ > 0) render(_L_PAREN); + pp(_nsprefix1.ident_, 0); + render(":"); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2 _nsprefix2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2) foo; + if (_i_ > 0) render(_L_PAREN); + render(":"); + if (_i_ > 0) render(_R_PAREN); + } + } + + private static void pp(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue foo, int _i_) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE _truthe = (com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE) foo; + if (_i_ > 0) render(_L_PAREN); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF _truthf = (com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF) foo; + if (_i_ > 0) render(_L_PAREN); + render("%"); + pp(_truthf.double_, 0); + render("%"); + if (_i_ > 0) render(_R_PAREN); + } + else if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC _truthfc = (com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC) foo; + if (_i_ > 0) render(_L_PAREN); + render("%"); + pp(_truthfc.double_1, 0); + render(";"); + pp(_truthfc.double_2, 0); + render("%"); + if (_i_ > 0) render(_R_PAREN); + } + } + + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.Document foo) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR _docbr = (com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR) foo; + render("("); + render("DocBR"); + sh(_docbr.baserule_); + render("["); + sh(_docbr.listsentence_); + render("]"); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.Doc) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Doc _doc = (com.googlecode.opennars.parser.loan.Loan.Absyn.Doc) foo; + render("("); + render("Doc"); + render("["); + sh(_doc.listsentence_); + render("]"); + render(")"); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule foo) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR _baser = (com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR) foo; + render("("); + render("BaseR"); + sh(_baser.urilit_); + render(")"); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence foo) + { + for (java.util.Iterator<Sentence> it = foo.iterator(); it.hasNext();) + { + sh(it.next()); + if (it.hasNext()) + render(","); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence foo) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix _sentprefix = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix) foo; + render("("); + render("SentPrefix"); + sh(_sentprefix.nsprefix_); + sh(_sentprefix.urilit_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport _sentimport = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport) foo; + render("("); + render("SentImport"); + sh(_sentimport.urilit_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay _sentdelay = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay) foo; + render("("); + render("SentDelay"); + sh(_sentdelay.integer_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp _sentop = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp) foo; + render("("); + render("SentOp"); + sh(_sentop.uriref_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge _sentjudge = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge) foo; + render("("); + render("SentJudge"); + sh(_sentjudge.stm_); + sh(_sentjudge.truthvalue_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest _sentquest = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest) foo; + render("("); + render("SentQuest"); + sh(_sentquest.stm_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal _sentgoal = (com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal) foo; + render("("); + render("SentGoal"); + sh(_sentgoal.stm_); + sh(_sentgoal.truthvalue_); + render(")"); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.Stm foo) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl _stmimpl = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl) foo; + render("("); + render("StmImpl"); + sh(_stmimpl.stm_1); + sh(_stmimpl.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv _stmequiv = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv) foo; + render("("); + render("StmEquiv"); + sh(_stmequiv.stm_1); + sh(_stmequiv.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred _stmimppred = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred) foo; + render("("); + render("StmImpPred"); + sh(_stmimppred.stm_1); + sh(_stmimppred.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet _stmimpret = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet) foo; + render("("); + render("StmImpRet"); + sh(_stmimpret.stm_1); + sh(_stmimpret.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc _stmimpconc = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc) foo; + render("("); + render("StmImpConc"); + sh(_stmimpconc.stm_1); + sh(_stmimpconc.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred _stmeqvpred = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred) foo; + render("("); + render("StmEqvPred"); + sh(_stmeqvpred.stm_1); + sh(_stmeqvpred.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc _stmeqvconc = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc) foo; + render("("); + render("StmEqvConc"); + sh(_stmeqvconc.stm_1); + sh(_stmeqvconc.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj _stmconj = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj) foo; + render("("); + render("StmConj"); + sh(_stmconj.stm_1); + sh(_stmconj.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj _stmdisj = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj) foo; + render("("); + render("StmDisj"); + sh(_stmdisj.stm_1); + sh(_stmdisj.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar _stmpar = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar) foo; + render("("); + render("StmPar"); + sh(_stmpar.stm_1); + sh(_stmpar.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq _stmseq = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq) foo; + render("("); + render("StmSeq"); + sh(_stmseq.stm_1); + sh(_stmseq.stm_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot _stmnot = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot) foo; + render("("); + render("StmNot"); + sh(_stmnot.stm_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst _stmpst = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst) foo; + render("("); + render("StmPst"); + sh(_stmpst.stm_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres _stmpres = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres) foo; + render("("); + render("StmPres"); + sh(_stmpres.stm_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut _stmfut = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut) foo; + render("("); + render("StmFut"); + sh(_stmfut.stm_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher _stminher = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher) foo; + render("("); + render("StmInher"); + sh(_stminher.term_1); + sh(_stminher.term_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim _stmsim = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim) foo; + render("("); + render("StmSim"); + sh(_stmsim.term_1); + sh(_stmsim.term_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst _stminst = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst) foo; + render("("); + render("StmInst"); + sh(_stminst.term_1); + sh(_stminst.term_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp _stmprop = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp) foo; + render("("); + render("StmProp"); + sh(_stmprop.term_1); + sh(_stmprop.term_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp _stminpp = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp) foo; + render("("); + render("StmInPp"); + sh(_stminpp.term_1); + sh(_stminpp.term_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp _stmop = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp) foo; + render("("); + render("StmOp"); + sh(_stmop.term_); + render("["); + sh(_stmop.listterm_); + render("]"); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm _stmtrm = (com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm) foo; + render("("); + render("StmTrm"); + sh(_stmtrm.term_); + render(")"); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.Term foo) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt _trmexint = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt) foo; + render("("); + render("TrmExInt"); + sh(_trmexint.term_1); + sh(_trmexint.term_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt _trminint = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt) foo; + render("("); + render("TrmInInt"); + sh(_trminint.term_1); + sh(_trminint.term_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif _trmexdif = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif) foo; + render("("); + render("TrmExDif"); + sh(_trmexdif.term_1); + sh(_trmexdif.term_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif _trmindif = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif) foo; + render("("); + render("TrmInDif"); + sh(_trmindif.term_1); + sh(_trmindif.term_2); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg _trmeximg = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg) foo; + render("("); + render("TrmExImg"); + sh(_trmeximg.term_); + render("["); + sh(_trmeximg.listterm_1); + render("]"); + render("["); + sh(_trmeximg.listterm_2); + render("]"); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg _trminimg = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg) foo; + render("("); + render("TrmInImg"); + sh(_trminimg.term_); + render("["); + sh(_trminimg.listterm_1); + render("]"); + render("["); + sh(_trminimg.listterm_2); + render("]"); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet _trmexset = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet) foo; + render("("); + render("TrmExSet"); + render("["); + sh(_trmexset.listterm_); + render("]"); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet _trminset = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet) foo; + render("("); + render("TrmInSet"); + render("["); + sh(_trminset.listterm_); + render("]"); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd _trmprod = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd) foo; + render("("); + render("TrmProd"); + render("["); + sh(_trmprod.listterm_); + render("]"); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit _trmlit = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit) foo; + render("("); + render("TrmLit"); + sh(_trmlit.literal_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm _trmstm = (com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm) foo; + render("("); + render("TrmStm"); + sh(_trmstm.stm_); + render(")"); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm foo) + { + for (java.util.Iterator<Term> it = foo.iterator(); it.hasNext();) + { + sh(it.next()); + if (it.hasNext()) + render(","); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent foo) + { + for (java.util.Iterator<String> it = foo.iterator(); it.hasNext();) + { + sh(it.next()); + if (it.hasNext()) + render(","); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef foo) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul _uriful = (com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul) foo; + render("("); + render("URIFul"); + sh(_uriful.urilit_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.URICur) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.URICur _uricur = (com.googlecode.opennars.parser.loan.Loan.Absyn.URICur) foo; + render("("); + render("URICur"); + sh(_uricur.nsprefix_); + sh(_uricur.ident_); + render(")"); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.Literal foo) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar _litqvar = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar) foo; + render("("); + render("LitQVar"); + sh(_litqvar.ident_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn _litqvaran = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn) foo; + render("LitQVarAn"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD _litsvard = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD) foo; + render("("); + render("LitSVarD"); + sh(_litsvard.ident_); + render("["); + sh(_litsvard.listident_); + render("]"); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI _litsvari = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI) foo; + render("("); + render("LitSVarI"); + sh(_litsvari.ident_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI _lituri = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI) foo; + render("("); + render("LitURI"); + sh(_lituri.uriref_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt _litint = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt) foo; + render("("); + render("LitInt"); + sh(_litint.integer_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl _litdbl = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl) foo; + render("("); + render("LitDbl"); + sh(_litdbl.double_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitString) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitString _litstring = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitString) foo; + render("("); + render("LitString"); + sh(_litstring.string_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue _littrue = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue) foo; + render("LitTrue"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse _litfalse = (com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse) foo; + render("LitFalse"); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix foo) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1 _nsprefix1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1) foo; + render("("); + render("NSPrefix1"); + sh(_nsprefix1.ident_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2 _nsprefix2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2) foo; + render("NSPrefix2"); + } + } + + private static void sh(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue foo) + { + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE _truthe = (com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE) foo; + render("TruthE"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF _truthf = (com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF) foo; + render("("); + render("TruthF"); + sh(_truthf.double_); + render(")"); + } + if (foo instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC) + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC _truthfc = (com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC) foo; + render("("); + render("TruthFC"); + sh(_truthfc.double_1); + sh(_truthfc.double_2); + render(")"); + } + } + + + private static void pp(Integer n, int _i_) { buf_.append(n); buf_.append(" "); } + private static void pp(Double d, int _i_) { buf_.append(d); buf_.append(" "); } + private static void pp(String s, int _i_) { buf_.append(s); buf_.append(" "); } + private static void pp(Character c, int _i_) { buf_.append("'" + c.toString() + "'"); buf_.append(" "); } + private static void sh(Integer n) { render(n.toString()); } + private static void sh(Double d) { render(d.toString()); } + private static void sh(Character c) { render(c.toString()); } + private static void sh(String s) { printQuoted(s); } + private static void printQuoted(String s) { render("\"" + s + "\""); } + private static void indent() + { + int n = _n_; + while (n > 0) + { + buf_.append(" "); + n--; + } + } + private static void backup() + { + if (buf_.charAt(buf_.length() - 1) == ' ') { + buf_.setLength(buf_.length() - 1); + } + } + private static void trim() + { + while (buf_.length() > 0 && buf_.charAt(0) == ' ') + buf_.deleteCharAt(0); + while (buf_.length() > 0 && buf_.charAt(buf_.length()-1) == ' ') + buf_.deleteCharAt(buf_.length()-1); + } + private static int _n_ = 0; + private static StringBuilder buf_ = new StringBuilder(INITIAL_BUFFER_SIZE); +} + diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Test.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Test.java new file mode 100644 index 0000000000000000000000000000000000000000..72587a88bfaebcc738e15e57e009e7c1684aa6fc --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Test.java @@ -0,0 +1,48 @@ +package com.googlecode.opennars.parser.loan.Loan; +import java_cup.runtime.*; +import com.googlecode.opennars.parser.loan.Loan.*; +import com.googlecode.opennars.parser.loan.Loan.Absyn.*; +import java.io.*; + +public class Test +{ + public static void main(String args[]) throws Exception + { + Yylex l = null; + parser p; + try + { + if (args.length == 0) l = new Yylex(System.in); + else l = new Yylex(new FileReader(args[0])); + } + catch(FileNotFoundException e) + { + System.err.println("Error: File not found: " + args[0]); + System.exit(1); + } + p = new parser(l); + /* The default parser is the first-defined entry point. */ + /* You may want to change this. Other options are: */ + /* pSentence */ + try + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Document parse_tree = p.pDocument(); + System.out.println(); + System.out.println("Parse Succesful!"); + System.out.println(); + System.out.println("[Abstract Syntax]"); + System.out.println(); + System.out.println(PrettyPrinter.show(parse_tree)); + System.out.println(); + System.out.println("[Linearized Tree]"); + System.out.println(); + System.out.println(PrettyPrinter.print(parse_tree)); + } + catch(Throwable e) + { + System.err.println("At line " + String.valueOf(l.line_num()) + ", near \"" + l.buff() + "\" :"); + System.err.println(" " + e.getMessage()); + System.exit(1); + } + } +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/VisitSkel.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/VisitSkel.java new file mode 100644 index 0000000000000000000000000000000000000000..9b8392c45f598aa9ec588f15db7d42008d23fbf3 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/VisitSkel.java @@ -0,0 +1,566 @@ +package com.googlecode.opennars.parser.loan.Loan; +import com.googlecode.opennars.parser.loan.Loan.Absyn.*; +/*** BNFC-Generated Visitor Design Pattern Skeleton. ***/ +/* This implements the common visitor design pattern. + Tests show it to be slightly less efficient than the + instanceof method, but easier to use. + Replace the R and A parameters with the desired return + and context types.*/ + +public class VisitSkel +{ + public class DocumentVisitor<R,A> implements Document.Visitor<R,A> + { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR p, A arg) + { + /* Code For DocBR Goes Here */ + + p.baserule_.accept(new BaseRuleVisitor<R,A>(), arg); + for (Sentence x : p.listsentence_) { + } + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.Doc p, A arg) + { + /* Code For Doc Goes Here */ + + for (Sentence x : p.listsentence_) { + } + + return null; + } + + } + public class BaseRuleVisitor<R,A> implements BaseRule.Visitor<R,A> + { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR p, A arg) + { + /* Code For BaseR Goes Here */ + + //p.urilit_; + + return null; + } + + } + public class SentenceVisitor<R,A> implements Sentence.Visitor<R,A> + { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix p, A arg) + { + /* Code For SentPrefix Goes Here */ + + p.nsprefix_.accept(new NSPrefixVisitor<R,A>(), arg); + //p.urilit_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport p, A arg) + { + /* Code For SentImport Goes Here */ + + //p.urilit_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay p, A arg) + { + /* Code For SentDelay Goes Here */ + + //p.integer_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp p, A arg) + { + /* Code For SentOp Goes Here */ + + p.uriref_.accept(new URIRefVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge p, A arg) + { + /* Code For SentJudge Goes Here */ + + p.stm_.accept(new StmVisitor<R,A>(), arg); + p.truthvalue_.accept(new TruthValueVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest p, A arg) + { + /* Code For SentQuest Goes Here */ + + p.stm_.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal p, A arg) + { + /* Code For SentGoal Goes Here */ + + p.stm_.accept(new StmVisitor<R,A>(), arg); + p.truthvalue_.accept(new TruthValueVisitor<R,A>(), arg); + + return null; + } + + } + public class StmVisitor<R,A> implements Stm.Visitor<R,A> + { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl p, A arg) + { + /* Code For StmImpl Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv p, A arg) + { + /* Code For StmEquiv Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred p, A arg) + { + /* Code For StmImpPred Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet p, A arg) + { + /* Code For StmImpRet Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc p, A arg) + { + /* Code For StmImpConc Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred p, A arg) + { + /* Code For StmEqvPred Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc p, A arg) + { + /* Code For StmEqvConc Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj p, A arg) + { + /* Code For StmConj Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj p, A arg) + { + /* Code For StmDisj Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar p, A arg) + { + /* Code For StmPar Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq p, A arg) + { + /* Code For StmSeq Goes Here */ + + p.stm_1.accept(new StmVisitor<R,A>(), arg); + p.stm_2.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot p, A arg) + { + /* Code For StmNot Goes Here */ + + p.stm_.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst p, A arg) + { + /* Code For StmPst Goes Here */ + + p.stm_.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres p, A arg) + { + /* Code For StmPres Goes Here */ + + p.stm_.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut p, A arg) + { + /* Code For StmFut Goes Here */ + + p.stm_.accept(new StmVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher p, A arg) + { + /* Code For StmInher Goes Here */ + + p.term_1.accept(new TermVisitor<R,A>(), arg); + p.term_2.accept(new TermVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim p, A arg) + { + /* Code For StmSim Goes Here */ + + p.term_1.accept(new TermVisitor<R,A>(), arg); + p.term_2.accept(new TermVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst p, A arg) + { + /* Code For StmInst Goes Here */ + + p.term_1.accept(new TermVisitor<R,A>(), arg); + p.term_2.accept(new TermVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp p, A arg) + { + /* Code For StmProp Goes Here */ + + p.term_1.accept(new TermVisitor<R,A>(), arg); + p.term_2.accept(new TermVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp p, A arg) + { + /* Code For StmInPp Goes Here */ + + p.term_1.accept(new TermVisitor<R,A>(), arg); + p.term_2.accept(new TermVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp p, A arg) + { + /* Code For StmOp Goes Here */ + + p.term_.accept(new TermVisitor<R,A>(), arg); + for (Term x : p.listterm_) { + } + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm p, A arg) + { + /* Code For StmTrm Goes Here */ + + p.term_.accept(new TermVisitor<R,A>(), arg); + + return null; + } + + } + public class TermVisitor<R,A> implements Term.Visitor<R,A> + { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt p, A arg) + { + /* Code For TrmExInt Goes Here */ + + p.term_1.accept(new TermVisitor<R,A>(), arg); + p.term_2.accept(new TermVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt p, A arg) + { + /* Code For TrmInInt Goes Here */ + + p.term_1.accept(new TermVisitor<R,A>(), arg); + p.term_2.accept(new TermVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif p, A arg) + { + /* Code For TrmExDif Goes Here */ + + p.term_1.accept(new TermVisitor<R,A>(), arg); + p.term_2.accept(new TermVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif p, A arg) + { + /* Code For TrmInDif Goes Here */ + + p.term_1.accept(new TermVisitor<R,A>(), arg); + p.term_2.accept(new TermVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg p, A arg) + { + /* Code For TrmExImg Goes Here */ + + p.term_.accept(new TermVisitor<R,A>(), arg); + for (Term x : p.listterm_1) { + } + for (Term x : p.listterm_2) { + } + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg p, A arg) + { + /* Code For TrmInImg Goes Here */ + + p.term_.accept(new TermVisitor<R,A>(), arg); + for (Term x : p.listterm_1) { + } + for (Term x : p.listterm_2) { + } + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet p, A arg) + { + /* Code For TrmExSet Goes Here */ + + for (Term x : p.listterm_) { + } + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet p, A arg) + { + /* Code For TrmInSet Goes Here */ + + for (Term x : p.listterm_) { + } + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd p, A arg) + { + /* Code For TrmProd Goes Here */ + + for (Term x : p.listterm_) { + } + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit p, A arg) + { + /* Code For TrmLit Goes Here */ + + p.literal_.accept(new LiteralVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm p, A arg) + { + /* Code For TrmStm Goes Here */ + + p.stm_.accept(new StmVisitor<R,A>(), arg); + + return null; + } + + } + public class URIRefVisitor<R,A> implements URIRef.Visitor<R,A> + { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul p, A arg) + { + /* Code For URIFul Goes Here */ + + //p.urilit_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URICur p, A arg) + { + /* Code For URICur Goes Here */ + + p.nsprefix_.accept(new NSPrefixVisitor<R,A>(), arg); + //p.ident_; + + return null; + } + + } + public class LiteralVisitor<R,A> implements Literal.Visitor<R,A> + { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar p, A arg) + { + /* Code For LitQVar Goes Here */ + + //p.ident_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn p, A arg) + { + /* Code For LitQVarAn Goes Here */ + + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD p, A arg) + { + /* Code For LitSVarD Goes Here */ + + //p.ident_; + for (String x : p.listident_) { + } + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI p, A arg) + { + /* Code For LitSVarI Goes Here */ + + //p.ident_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI p, A arg) + { + /* Code For LitURI Goes Here */ + + p.uriref_.accept(new URIRefVisitor<R,A>(), arg); + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt p, A arg) + { + /* Code For LitInt Goes Here */ + + //p.integer_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl p, A arg) + { + /* Code For LitDbl Goes Here */ + + //p.double_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitString p, A arg) + { + /* Code For LitString Goes Here */ + + //p.string_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue p, A arg) + { + /* Code For LitTrue Goes Here */ + + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse p, A arg) + { + /* Code For LitFalse Goes Here */ + + + return null; + } + + } + public class NSPrefixVisitor<R,A> implements NSPrefix.Visitor<R,A> + { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1 p, A arg) + { + /* Code For NSPrefix1 Goes Here */ + + //p.ident_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2 p, A arg) + { + /* Code For NSPrefix2 Goes Here */ + + + return null; + } + + } + public class TruthValueVisitor<R,A> implements TruthValue.Visitor<R,A> + { + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE p, A arg) + { + /* Code For TruthE Goes Here */ + + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF p, A arg) + { + /* Code For TruthF Goes Here */ + + //p.double_; + + return null; + } + public R visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC p, A arg) + { + /* Code For TruthFC Goes Here */ + + //p.double_1; + //p.double_2; + + return null; + } + + } +} \ No newline at end of file diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Yylex b/open-nars/com/googlecode/opennars/parser/loan/Loan/Yylex new file mode 100644 index 0000000000000000000000000000000000000000..26b5a5b2667623d0c2fa0fc17cbf66f921acafe2 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Yylex @@ -0,0 +1,96 @@ +// This JLex file was machine-generated by the BNF converter +package com.googlecode.opennars.parser.loan.Loan; + +import java_cup.runtime.*; +%% +%cup +%unicode +%line +%public +%{ + String pstring = new String(); + public int line_num() { return (yyline+1); } + public String buff() { return new String(yy_buffer,yy_buffer_index,10).trim(); } +%} +LETTER = ({CAPITAL}|{SMALL}) +CAPITAL = [A-Z\xC0-\xD6\xD8-\xDE] +SMALL = [a-z\xDF-\xF6\xF8-\xFF] +DIGIT = [0-9] +IDENT = ({LETTER}|{DIGIT}|['_]) +%state COMMENT +%state CHAR +%state CHARESC +%state CHAREND +%state STRING +%state ESCAPED +%% +<YYINITIAL>@base { return new Symbol(sym._SYMB_0); } +<YYINITIAL>\. { return new Symbol(sym._SYMB_1); } +<YYINITIAL>@prefix { return new Symbol(sym._SYMB_2); } +<YYINITIAL>@import { return new Symbol(sym._SYMB_3); } +<YYINITIAL>@delay { return new Symbol(sym._SYMB_4); } +<YYINITIAL>@operator { return new Symbol(sym._SYMB_5); } +<YYINITIAL>\? { return new Symbol(sym._SYMB_6); } +<YYINITIAL>! { return new Symbol(sym._SYMB_7); } +<YYINITIAL>==> { return new Symbol(sym._SYMB_8); } +<YYINITIAL><=> { return new Symbol(sym._SYMB_9); } +<YYINITIAL>=/> { return new Symbol(sym._SYMB_10); } +<YYINITIAL>=\\> { return new Symbol(sym._SYMB_11); } +<YYINITIAL>=\|> { return new Symbol(sym._SYMB_12); } +<YYINITIAL></> { return new Symbol(sym._SYMB_13); } +<YYINITIAL><\|> { return new Symbol(sym._SYMB_14); } +<YYINITIAL>&& { return new Symbol(sym._SYMB_15); } +<YYINITIAL>\|\| { return new Symbol(sym._SYMB_16); } +<YYINITIAL>; { return new Symbol(sym._SYMB_17); } +<YYINITIAL>, { return new Symbol(sym._SYMB_18); } +<YYINITIAL>--> { return new Symbol(sym._SYMB_19); } +<YYINITIAL><-> { return new Symbol(sym._SYMB_20); } +<YYINITIAL>\}-> { return new Symbol(sym._SYMB_21); } +<YYINITIAL>--\[ { return new Symbol(sym._SYMB_22); } +<YYINITIAL>\}-\[ { return new Symbol(sym._SYMB_23); } +<YYINITIAL>\( { return new Symbol(sym._SYMB_24); } +<YYINITIAL>\) { return new Symbol(sym._SYMB_25); } +<YYINITIAL>& { return new Symbol(sym._SYMB_26); } +<YYINITIAL>\| { return new Symbol(sym._SYMB_27); } +<YYINITIAL>- { return new Symbol(sym._SYMB_28); } +<YYINITIAL>~ { return new Symbol(sym._SYMB_29); } +<YYINITIAL>_\|_ { return new Symbol(sym._SYMB_30); } +<YYINITIAL>\{ { return new Symbol(sym._SYMB_31); } +<YYINITIAL>\} { return new Symbol(sym._SYMB_32); } +<YYINITIAL>\[ { return new Symbol(sym._SYMB_33); } +<YYINITIAL>\] { return new Symbol(sym._SYMB_34); } +<YYINITIAL># { return new Symbol(sym._SYMB_35); } +<YYINITIAL>: { return new Symbol(sym._SYMB_36); } +<YYINITIAL>% { return new Symbol(sym._SYMB_37); } +<YYINITIAL>extension { return new Symbol(sym._SYMB_38); } +<YYINITIAL>false { return new Symbol(sym._SYMB_39); } +<YYINITIAL>future { return new Symbol(sym._SYMB_40); } +<YYINITIAL>intension { return new Symbol(sym._SYMB_41); } +<YYINITIAL>not { return new Symbol(sym._SYMB_42); } +<YYINITIAL>past { return new Symbol(sym._SYMB_43); } +<YYINITIAL>present { return new Symbol(sym._SYMB_44); } +<YYINITIAL>true { return new Symbol(sym._SYMB_45); } +<YYINITIAL>"//"[^\n]*\n { /* BNFC single-line comment */ } +<YYINITIAL>"/*" { yybegin(COMMENT); } +<COMMENT>"*/" { yybegin(YYINITIAL); } +<COMMENT>. { } +<COMMENT>[\n] { } + + +<YYINITIAL><[^<>\"\{\}\|\\`]*> { return new Symbol(sym.URILit, yytext().intern()); } + +<YYINITIAL>"\"" { yybegin(STRING); } +<STRING>\\ { yybegin(ESCAPED); } +<STRING>\" { String foo = pstring; pstring = new String(); yybegin(YYINITIAL); return new Symbol(sym._STRING_, foo.intern()); } +<STRING>. { pstring += yytext(); } +<ESCAPED>n { pstring += "\n"; yybegin(STRING); } +<ESCAPED>\" { pstring += "\""; yybegin(STRING); } +<ESCAPED>\\ { pstring += "\\"; yybegin(STRING); } +<ESCAPED>t { pstring += "\t"; yybegin(STRING); } +<ESCAPED>. { pstring += yytext(); yybegin(STRING); } + + +<YYINITIAL>{DIGIT}+"."{DIGIT}+("e"(\-)?{DIGIT}+)? { return new Symbol(sym._DOUBLE_, new Double(yytext())); } +<YYINITIAL>{DIGIT}+ { return new Symbol(sym._INTEGER_, new Integer(yytext())); } +<YYINITIAL>{LETTER}{IDENT}* { return new Symbol(sym._IDENT_, yytext().intern()); } +<YYINITIAL>[ \t\r\n\f] { /* ignore white space. */ } diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/Yylex.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/Yylex.java new file mode 100644 index 0000000000000000000000000000000000000000..bc6b050010b8df207afe835d5d8c498c70e9b48e --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/Yylex.java @@ -0,0 +1,915 @@ +// This JLex file was machine-generated by the BNF converter +package com.googlecode.opennars.parser.loan.Loan; +import java_cup.runtime.*; + + +public class Yylex implements java_cup.runtime.Scanner { + private final int YY_BUFFER_SIZE = 512; + private final int YY_F = -1; + private final int YY_NO_STATE = -1; + private final int YY_NOT_ACCEPT = 0; + private final int YY_START = 1; + private final int YY_END = 2; + private final int YY_NO_ANCHOR = 4; + private final int YY_BOL = 65536; + private final int YY_EOF = 65537; + + String pstring = new String(); + public int line_num() { return (yyline+1); } + public String buff() { return new String(yy_buffer,yy_buffer_index,10).trim(); } + private java.io.BufferedReader yy_reader; + private int yy_buffer_index; + private int yy_buffer_read; + private int yy_buffer_start; + private int yy_buffer_end; + private char yy_buffer[]; + private int yyline; + private boolean yy_at_bol; + private int yy_lexical_state; + + public Yylex (java.io.Reader reader) { + this (); + if (null == reader) { + throw (new Error("Error: Bad input stream initializer.")); + } + yy_reader = new java.io.BufferedReader(reader); + } + + public Yylex (java.io.InputStream instream) { + this (); + if (null == instream) { + throw (new Error("Error: Bad input stream initializer.")); + } + yy_reader = new java.io.BufferedReader(new java.io.InputStreamReader(instream)); + } + + private Yylex () { + yy_buffer = new char[YY_BUFFER_SIZE]; + yy_buffer_read = 0; + yy_buffer_index = 0; + yy_buffer_start = 0; + yy_buffer_end = 0; + yyline = 0; + yy_at_bol = true; + yy_lexical_state = YYINITIAL; + } + + private boolean yy_eof_done = false; + private final int STRING = 5; + private final int ESCAPED = 6; + private final int YYINITIAL = 0; + private final int COMMENT = 1; + private final int CHAREND = 4; + private final int CHARESC = 3; + private final int CHAR = 2; + private final int yy_state_dtrans[] = { + 0, + 117, + 118, + 118, + 118, + 119, + 120 + }; + private void yybegin (int state) { + yy_lexical_state = state; + } + private int yy_advance () + throws java.io.IOException { + int next_read; + int i; + int j; + + if (yy_buffer_index < yy_buffer_read) { + return yy_buffer[yy_buffer_index++]; + } + + if (0 != yy_buffer_start) { + i = yy_buffer_start; + j = 0; + while (i < yy_buffer_read) { + yy_buffer[j] = yy_buffer[i]; + ++i; + ++j; + } + yy_buffer_end = yy_buffer_end - yy_buffer_start; + yy_buffer_start = 0; + yy_buffer_read = j; + yy_buffer_index = j; + next_read = yy_reader.read(yy_buffer, + yy_buffer_read, + yy_buffer.length - yy_buffer_read); + if (-1 == next_read) { + return YY_EOF; + } + yy_buffer_read = yy_buffer_read + next_read; + } + + while (yy_buffer_index >= yy_buffer_read) { + if (yy_buffer_index >= yy_buffer.length) { + yy_buffer = yy_double(yy_buffer); + } + next_read = yy_reader.read(yy_buffer, + yy_buffer_read, + yy_buffer.length - yy_buffer_read); + if (-1 == next_read) { + return YY_EOF; + } + yy_buffer_read = yy_buffer_read + next_read; + } + return yy_buffer[yy_buffer_index++]; + } + private void yy_move_end () { + if (yy_buffer_end > yy_buffer_start && + '\n' == yy_buffer[yy_buffer_end-1]) + yy_buffer_end--; + if (yy_buffer_end > yy_buffer_start && + '\r' == yy_buffer[yy_buffer_end-1]) + yy_buffer_end--; + } + private boolean yy_last_was_cr=false; + private void yy_mark_start () { + int i; + for (i = yy_buffer_start; i < yy_buffer_index; ++i) { + if ('\n' == yy_buffer[i] && !yy_last_was_cr) { + ++yyline; + } + if ('\r' == yy_buffer[i]) { + ++yyline; + yy_last_was_cr=true; + } else yy_last_was_cr=false; + } + yy_buffer_start = yy_buffer_index; + } + private void yy_mark_end () { + yy_buffer_end = yy_buffer_index; + } + private void yy_to_mark () { + yy_buffer_index = yy_buffer_end; + yy_at_bol = (yy_buffer_end > yy_buffer_start) && + ('\r' == yy_buffer[yy_buffer_end-1] || + '\n' == yy_buffer[yy_buffer_end-1] || + 2028/*LS*/ == yy_buffer[yy_buffer_end-1] || + 2029/*PS*/ == yy_buffer[yy_buffer_end-1]); + } + private java.lang.String yytext () { + return (new java.lang.String(yy_buffer, + yy_buffer_start, + yy_buffer_end - yy_buffer_start)); + } + private int yylength () { + return yy_buffer_end - yy_buffer_start; + } + private char[] yy_double (char buf[]) { + int i; + char newbuf[]; + newbuf = new char[2*buf.length]; + for (i = 0; i < buf.length; ++i) { + newbuf[i] = buf[i]; + } + return newbuf; + } + private final int YY_E_INTERNAL = 0; + private final int YY_E_MATCH = 1; + private java.lang.String yy_error_string[] = { + "Error: Internal error.\n", + "Error: Unmatched input.\n" + }; + private void yy_error (int code,boolean fatal) { + java.lang.System.out.print(yy_error_string[code]); + java.lang.System.out.flush(); + if (fatal) { + throw new Error("Fatal Error.\n"); + } + } + private int[][] unpackFromString(int size1, int size2, String st) { + int colonIndex = -1; + String lengthString; + int sequenceLength = 0; + int sequenceInteger = 0; + + int commaIndex; + String workString; + + int res[][] = new int[size1][size2]; + for (int i= 0; i < size1; i++) { + for (int j= 0; j < size2; j++) { + if (sequenceLength != 0) { + res[i][j] = sequenceInteger; + sequenceLength--; + continue; + } + commaIndex = st.indexOf(','); + workString = (commaIndex==-1) ? st : + st.substring(0, commaIndex); + st = st.substring(commaIndex+1); + colonIndex = workString.indexOf(':'); + if (colonIndex == -1) { + res[i][j]=Integer.parseInt(workString); + continue; + } + lengthString = + workString.substring(colonIndex+1); + sequenceLength=Integer.parseInt(lengthString); + workString=workString.substring(0,colonIndex); + sequenceInteger=Integer.parseInt(workString); + res[i][j] = sequenceInteger; + sequenceLength--; + } + } + return res; + } + private int yy_acpt[] = { + /* 0 */ YY_NOT_ACCEPT, + /* 1 */ YY_NO_ANCHOR, + /* 2 */ YY_NO_ANCHOR, + /* 3 */ YY_NO_ANCHOR, + /* 4 */ YY_NO_ANCHOR, + /* 5 */ YY_NO_ANCHOR, + /* 6 */ YY_NO_ANCHOR, + /* 7 */ YY_NO_ANCHOR, + /* 8 */ YY_NO_ANCHOR, + /* 9 */ YY_NO_ANCHOR, + /* 10 */ YY_NO_ANCHOR, + /* 11 */ YY_NO_ANCHOR, + /* 12 */ YY_NO_ANCHOR, + /* 13 */ YY_NO_ANCHOR, + /* 14 */ YY_NO_ANCHOR, + /* 15 */ YY_NO_ANCHOR, + /* 16 */ YY_NO_ANCHOR, + /* 17 */ YY_NO_ANCHOR, + /* 18 */ YY_NO_ANCHOR, + /* 19 */ YY_NO_ANCHOR, + /* 20 */ YY_NO_ANCHOR, + /* 21 */ YY_NO_ANCHOR, + /* 22 */ YY_NO_ANCHOR, + /* 23 */ YY_NO_ANCHOR, + /* 24 */ YY_NO_ANCHOR, + /* 25 */ YY_NO_ANCHOR, + /* 26 */ YY_NO_ANCHOR, + /* 27 */ YY_NO_ANCHOR, + /* 28 */ YY_NO_ANCHOR, + /* 29 */ YY_NO_ANCHOR, + /* 30 */ YY_NO_ANCHOR, + /* 31 */ YY_NO_ANCHOR, + /* 32 */ YY_NO_ANCHOR, + /* 33 */ YY_NO_ANCHOR, + /* 34 */ YY_NO_ANCHOR, + /* 35 */ YY_NO_ANCHOR, + /* 36 */ YY_NO_ANCHOR, + /* 37 */ YY_NO_ANCHOR, + /* 38 */ YY_NO_ANCHOR, + /* 39 */ YY_NO_ANCHOR, + /* 40 */ YY_NO_ANCHOR, + /* 41 */ YY_NO_ANCHOR, + /* 42 */ YY_NO_ANCHOR, + /* 43 */ YY_NO_ANCHOR, + /* 44 */ YY_NO_ANCHOR, + /* 45 */ YY_NO_ANCHOR, + /* 46 */ YY_NO_ANCHOR, + /* 47 */ YY_NO_ANCHOR, + /* 48 */ YY_NO_ANCHOR, + /* 49 */ YY_NO_ANCHOR, + /* 50 */ YY_NO_ANCHOR, + /* 51 */ YY_NO_ANCHOR, + /* 52 */ YY_NO_ANCHOR, + /* 53 */ YY_NO_ANCHOR, + /* 54 */ YY_NO_ANCHOR, + /* 55 */ YY_NO_ANCHOR, + /* 56 */ YY_NO_ANCHOR, + /* 57 */ YY_NO_ANCHOR, + /* 58 */ YY_NO_ANCHOR, + /* 59 */ YY_NO_ANCHOR, + /* 60 */ YY_NO_ANCHOR, + /* 61 */ YY_NO_ANCHOR, + /* 62 */ YY_NO_ANCHOR, + /* 63 */ YY_NO_ANCHOR, + /* 64 */ YY_NO_ANCHOR, + /* 65 */ YY_NO_ANCHOR, + /* 66 */ YY_NO_ANCHOR, + /* 67 */ YY_NOT_ACCEPT, + /* 68 */ YY_NO_ANCHOR, + /* 69 */ YY_NO_ANCHOR, + /* 70 */ YY_NO_ANCHOR, + /* 71 */ YY_NOT_ACCEPT, + /* 72 */ YY_NO_ANCHOR, + /* 73 */ YY_NOT_ACCEPT, + /* 74 */ YY_NO_ANCHOR, + /* 75 */ YY_NOT_ACCEPT, + /* 76 */ YY_NO_ANCHOR, + /* 77 */ YY_NOT_ACCEPT, + /* 78 */ YY_NO_ANCHOR, + /* 79 */ YY_NOT_ACCEPT, + /* 80 */ YY_NO_ANCHOR, + /* 81 */ YY_NOT_ACCEPT, + /* 82 */ YY_NO_ANCHOR, + /* 83 */ YY_NOT_ACCEPT, + /* 84 */ YY_NO_ANCHOR, + /* 85 */ YY_NOT_ACCEPT, + /* 86 */ YY_NOT_ACCEPT, + /* 87 */ YY_NOT_ACCEPT, + /* 88 */ YY_NOT_ACCEPT, + /* 89 */ YY_NOT_ACCEPT, + /* 90 */ YY_NOT_ACCEPT, + /* 91 */ YY_NOT_ACCEPT, + /* 92 */ YY_NOT_ACCEPT, + /* 93 */ YY_NOT_ACCEPT, + /* 94 */ YY_NOT_ACCEPT, + /* 95 */ YY_NOT_ACCEPT, + /* 96 */ YY_NOT_ACCEPT, + /* 97 */ YY_NOT_ACCEPT, + /* 98 */ YY_NOT_ACCEPT, + /* 99 */ YY_NOT_ACCEPT, + /* 100 */ YY_NOT_ACCEPT, + /* 101 */ YY_NOT_ACCEPT, + /* 102 */ YY_NOT_ACCEPT, + /* 103 */ YY_NOT_ACCEPT, + /* 104 */ YY_NOT_ACCEPT, + /* 105 */ YY_NOT_ACCEPT, + /* 106 */ YY_NOT_ACCEPT, + /* 107 */ YY_NOT_ACCEPT, + /* 108 */ YY_NOT_ACCEPT, + /* 109 */ YY_NOT_ACCEPT, + /* 110 */ YY_NOT_ACCEPT, + /* 111 */ YY_NOT_ACCEPT, + /* 112 */ YY_NOT_ACCEPT, + /* 113 */ YY_NOT_ACCEPT, + /* 114 */ YY_NOT_ACCEPT, + /* 115 */ YY_NOT_ACCEPT, + /* 116 */ YY_NOT_ACCEPT, + /* 117 */ YY_NOT_ACCEPT, + /* 118 */ YY_NOT_ACCEPT, + /* 119 */ YY_NOT_ACCEPT, + /* 120 */ YY_NOT_ACCEPT, + /* 121 */ YY_NO_ANCHOR, + /* 122 */ YY_NOT_ACCEPT, + /* 123 */ YY_NOT_ACCEPT, + /* 124 */ YY_NOT_ACCEPT, + /* 125 */ YY_NOT_ACCEPT, + /* 126 */ YY_NO_ANCHOR, + /* 127 */ YY_NOT_ACCEPT, + /* 128 */ YY_NO_ANCHOR, + /* 129 */ YY_NO_ANCHOR, + /* 130 */ YY_NO_ANCHOR, + /* 131 */ YY_NO_ANCHOR, + /* 132 */ YY_NO_ANCHOR, + /* 133 */ YY_NO_ANCHOR, + /* 134 */ YY_NO_ANCHOR, + /* 135 */ YY_NO_ANCHOR, + /* 136 */ YY_NO_ANCHOR, + /* 137 */ YY_NO_ANCHOR, + /* 138 */ YY_NO_ANCHOR, + /* 139 */ YY_NO_ANCHOR, + /* 140 */ YY_NO_ANCHOR, + /* 141 */ YY_NO_ANCHOR, + /* 142 */ YY_NO_ANCHOR, + /* 143 */ YY_NO_ANCHOR, + /* 144 */ YY_NO_ANCHOR, + /* 145 */ YY_NO_ANCHOR, + /* 146 */ YY_NO_ANCHOR, + /* 147 */ YY_NO_ANCHOR, + /* 148 */ YY_NO_ANCHOR, + /* 149 */ YY_NO_ANCHOR, + /* 150 */ YY_NO_ANCHOR, + /* 151 */ YY_NO_ANCHOR, + /* 152 */ YY_NO_ANCHOR, + /* 153 */ YY_NO_ANCHOR, + /* 154 */ YY_NO_ANCHOR + }; + private int yy_cmap[] = unpackFromString(1,65538, +"47:9,52,44,47,52,43,47:18,52,19,48,38,47,40,26,51,32,33,45,47,28,29,6,23,49" + +":10,39,27,22,20,21,18,1,50:26,31,24,37,47,35,46,3,2,50,15,5,9,50:2,10,50:2," + +"16,12,41,13,7,50,8,4,14,42,50:2,11,17,50,36,25,30,34,47:65,50:23,47,50:31,4" + +"7,50:8,47:65280,0:2")[0]; + + private int yy_rmap[] = unpackFromString(1,155, +"0,1,2,1:3,3,4,1:2,5,6,1:11,7,1:18,2,8,2:2,1,2,1,2,1:2,2,1,2:2,1:11,9,10,11," + +"12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36," + +"37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,11,53,54,55,56,57,58,59,60," + +"61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85," + +"86,87,88,89,90,91,92,93,94,95")[0]; + + private int yy_nxt[][] = unpackFromString(96,53, +"1,67,2:3,153,3,134,2,141,154,2:3,135,2:3,4,5,71,-1,73,75,-1,6,7,8,9,10,11,1" + +"2,13,14,15,77,16,17,18,19,20,121,2,21:2,-1:3,22,23,2,-1,21,-1:55,2:4,-1,2:1" + +"1,-1:17,2,-1:5,2:2,-1:6,2:3,-1:26,26,-1:53,27,-1:55,97,-1:52,98,-1:29,100,-" + +"1:42,23,-1:8,108,-1:43,43,-1:5,79,-1:4,81,-1:2,83,-1:2,85,-1,86,-1:39,2:4,-" + +"1,2:7,42,2:3,-1:17,2,-1:5,2:2,-1:6,2:3,-1:50,69,-1:26,58,-1:49,87,-1:2,88,8" + +"9,90,-1:29,2:4,-1,2:7,44,2:3,-1:17,2,-1:5,2:2,-1:6,2:3,-1:2,91:19,92,24,-1," + +"93,-1,94,91:3,95,-1,91:5,-1,91:9,-1,91,-1,91:4,-1:2,2:3,45,-1,2:11,-1:17,2," + +"-1:5,2:2,-1:6,2:3,-1:24,96,-1:21,25,-1:9,2:3,47,-1,2:11,-1:17,2,-1:5,2:2,-1" + +":6,2:3,-1:26,99,-1:29,2:3,49,-1,2:11,-1:17,2,-1:5,2:2,-1:6,2:3,-1:4,101,-1:" + +"51,2:4,-1,2:7,52,2:3,-1:17,2,-1:5,2:2,-1:6,2:3,-1:9,123,-1:46,2:4,-1,2:11,-" + +"1:17,2,-1:5,54,2,-1:6,2:3,-1:13,122,-1:42,2:4,-1,2:11,-1:17,2,-1:5,55,2,-1:" + +"6,2:3,-1:8,127,-1:50,102,-1:68,28,-1:52,29,-1:52,30,-1:52,31,-1:32,91:20,24" + +",-1,91,-1:2,91:4,-1,91:5,-1,91:9,-1,91,-1,91:4,-1,91:20,32,-1,91,-1:2,91:4," + +"-1,91:5,-1,91:9,-1,91,-1,91:4,-1,91:20,33,-1,91,-1:2,91:4,-1,91:5,-1,91:9,-" + +"1,91,-1,91:4,-1:21,34,-1:32,91:20,35,-1,91,-1:2,91:4,-1,91:5,-1,91:9,-1,91," + +"-1,91:4,-1,96:43,36,96:8,-1:21,37,-1:9,38,-1:42,39,-1:9,40,-1:56,41,-1:66,4" + +"3,-1:7,103,-1:64,107,-1:41,46,-1:56,109,-1:56,124,-1:47,125,-1:47,110,-1:78" + +",111,-1:19,69,-1:13,112,-1:59,48,-1:46,50,-1:55,51,-1:52,115,-1:51,116,-1:4" + +"7,53,-1:44,1,56:42,-1,57,70,56:7,1,-1:52,1,59:23,60,59:18,-1:2,59:3,61,59:4" + +",1,62:13,63,62:9,64,62:16,65,62,-1:2,62:3,66,62:4,-1:2,2:4,-1,2:6,68,2:4,-1" + +":17,2,-1:5,2:2,-1:6,2:3,-1:8,105,-1:50,104,-1:55,113,-1:47,114,-1:51,2:2,72" + +",2,-1,2:11,-1:17,2,-1:5,2:2,-1:6,2:3,-1:6,106,-1:49,2:4,-1,2:11,-1:17,2,-1:" + +"5,2,74,-1:6,2:3,-1:3,2:2,76,2,-1,2:11,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-1" + +",2,78,2:9,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-1,2:11,-1:17,2,-1:5,80,2,-1:6" + +",2:3,-1:3,2:4,-1,2:6,82,2:4,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-1,2:6,84,2:" + +"4,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2,126,2:2,-1,2,146,2:9,-1:17,2,-1:5,2:2,-1" + +":6,2:3,-1:3,2:4,-1,2,128,2:9,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-1,2:9,129," + +"2,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-1,2:11,-1:17,2,-1:5,2,130,-1:6,2:3,-1" + +":3,2:3,131,-1,2:11,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-1,2:3,132,2:7,-1:17," + +"2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-1,2:3,133,2:7,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3," + +"2,136,2:2,-1,2:11,-1:17,2,-1:5,2,142,-1:6,2:3,-1:3,2:4,-1,2:7,137,2:3,-1:17" + +",2,-1:5,2:2,-1:6,2:3,-1:3,2:2,138,2,-1,2:11,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3," + +"2:2,139,2,-1,2:11,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2:2,140,2,-1,2:11,-1:17,2," + +"-1:5,2:2,-1:6,2:3,-1:3,2:3,143,-1,2:11,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-" + +"1,2:11,-1:17,2,-1:5,144,2,-1:6,2:3,-1:3,2:4,-1,2:11,-1:17,2,-1:5,145,2,-1:6" + +",2:3,-1:3,2:3,147,-1,2:11,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2:3,148,-1,2:11,-1" + +":17,2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-1,2:7,149,2:3,-1:17,2,-1:5,2:2,-1:6,2:3,-" + +"1:3,2:4,-1,2:7,150,2:3,-1:17,2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-1,2:4,151,2:6,-1" + +":17,2,-1:5,2:2,-1:6,2:3,-1:3,2:4,-1,2:11,-1:17,2,-1:5,152,2,-1:6,2:3,-1"); + + public java_cup.runtime.Symbol next_token () + throws java.io.IOException { + int yy_lookahead; + int yy_anchor = YY_NO_ANCHOR; + int yy_state = yy_state_dtrans[yy_lexical_state]; + int yy_next_state = YY_NO_STATE; + int yy_last_accept_state = YY_NO_STATE; + boolean yy_initial = true; + int yy_this_accept; + + yy_mark_start(); + yy_this_accept = yy_acpt[yy_state]; + if (YY_NOT_ACCEPT != yy_this_accept) { + yy_last_accept_state = yy_state; + yy_mark_end(); + } + while (true) { + if (yy_initial && yy_at_bol) yy_lookahead = YY_BOL; + else yy_lookahead = yy_advance(); + yy_next_state = YY_F; + yy_next_state = yy_nxt[yy_rmap[yy_state]][yy_cmap[yy_lookahead]]; + if (YY_EOF == yy_lookahead && true == yy_initial) { + return null; + } + if (YY_F != yy_next_state) { + yy_state = yy_next_state; + yy_initial = false; + yy_this_accept = yy_acpt[yy_state]; + if (YY_NOT_ACCEPT != yy_this_accept) { + yy_last_accept_state = yy_state; + yy_mark_end(); + } + } + else { + if (YY_NO_STATE == yy_last_accept_state) { + throw (new Error("Lexical Error: Unmatched Input.")); + } + else { + yy_anchor = yy_acpt[yy_last_accept_state]; + if (0 != (YY_END & yy_anchor)) { + yy_move_end(); + } + yy_to_mark(); + switch (yy_last_accept_state) { + case 1: + + case -2: + break; + case 2: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -3: + break; + case 3: + { return new Symbol(sym._SYMB_1); } + case -4: + break; + case 4: + { return new Symbol(sym._SYMB_6); } + case -5: + break; + case 5: + { return new Symbol(sym._SYMB_7); } + case -6: + break; + case 6: + { return new Symbol(sym._SYMB_27); } + case -7: + break; + case 7: + { return new Symbol(sym._SYMB_26); } + case -8: + break; + case 8: + { return new Symbol(sym._SYMB_17); } + case -9: + break; + case 9: + { return new Symbol(sym._SYMB_18); } + case -10: + break; + case 10: + { return new Symbol(sym._SYMB_28); } + case -11: + break; + case 11: + { return new Symbol(sym._SYMB_32); } + case -12: + break; + case 12: + { return new Symbol(sym._SYMB_33); } + case -13: + break; + case 13: + { return new Symbol(sym._SYMB_24); } + case -14: + break; + case 14: + { return new Symbol(sym._SYMB_25); } + case -15: + break; + case 15: + { return new Symbol(sym._SYMB_29); } + case -16: + break; + case 16: + { return new Symbol(sym._SYMB_31); } + case -17: + break; + case 17: + { return new Symbol(sym._SYMB_34); } + case -18: + break; + case 18: + { return new Symbol(sym._SYMB_35); } + case -19: + break; + case 19: + { return new Symbol(sym._SYMB_36); } + case -20: + break; + case 20: + { return new Symbol(sym._SYMB_37); } + case -21: + break; + case 21: + { /* ignore white space. */ } + case -22: + break; + case 22: + { yybegin(STRING); } + case -23: + break; + case 23: + { return new Symbol(sym._INTEGER_, new Integer(yytext())); } + case -24: + break; + case 24: + { return new Symbol(sym.URILit, yytext().intern()); } + case -25: + break; + case 25: + { yybegin(COMMENT); } + case -26: + break; + case 26: + { return new Symbol(sym._SYMB_16); } + case -27: + break; + case 27: + { return new Symbol(sym._SYMB_15); } + case -28: + break; + case 28: + { return new Symbol(sym._SYMB_8); } + case -29: + break; + case 29: + { return new Symbol(sym._SYMB_10); } + case -30: + break; + case 30: + { return new Symbol(sym._SYMB_11); } + case -31: + break; + case 31: + { return new Symbol(sym._SYMB_12); } + case -32: + break; + case 32: + { return new Symbol(sym._SYMB_9); } + case -33: + break; + case 33: + { return new Symbol(sym._SYMB_13); } + case -34: + break; + case 34: + { return new Symbol(sym._SYMB_14); } + case -35: + break; + case 35: + { return new Symbol(sym._SYMB_20); } + case -36: + break; + case 36: + { /* BNFC single-line comment */ } + case -37: + break; + case 37: + { return new Symbol(sym._SYMB_19); } + case -38: + break; + case 38: + { return new Symbol(sym._SYMB_22); } + case -39: + break; + case 39: + { return new Symbol(sym._SYMB_21); } + case -40: + break; + case 40: + { return new Symbol(sym._SYMB_23); } + case -41: + break; + case 41: + { return new Symbol(sym._SYMB_30); } + case -42: + break; + case 42: + { return new Symbol(sym._SYMB_42); } + case -43: + break; + case 43: + { return new Symbol(sym._DOUBLE_, new Double(yytext())); } + case -44: + break; + case 44: + { return new Symbol(sym._SYMB_43); } + case -45: + break; + case 45: + { return new Symbol(sym._SYMB_45); } + case -46: + break; + case 46: + { return new Symbol(sym._SYMB_0); } + case -47: + break; + case 47: + { return new Symbol(sym._SYMB_39); } + case -48: + break; + case 48: + { return new Symbol(sym._SYMB_4); } + case -49: + break; + case 49: + { return new Symbol(sym._SYMB_40); } + case -50: + break; + case 50: + { return new Symbol(sym._SYMB_2); } + case -51: + break; + case 51: + { return new Symbol(sym._SYMB_3); } + case -52: + break; + case 52: + { return new Symbol(sym._SYMB_44); } + case -53: + break; + case 53: + { return new Symbol(sym._SYMB_5); } + case -54: + break; + case 54: + { return new Symbol(sym._SYMB_38); } + case -55: + break; + case 55: + { return new Symbol(sym._SYMB_41); } + case -56: + break; + case 56: + { } + case -57: + break; + case 57: + { } + case -58: + break; + case 58: + { yybegin(YYINITIAL); } + case -59: + break; + case 59: + { pstring += yytext(); } + case -60: + break; + case 60: + { yybegin(ESCAPED); } + case -61: + break; + case 61: + { String foo = pstring; pstring = new String(); yybegin(YYINITIAL); return new Symbol(sym._STRING_, foo.intern()); } + case -62: + break; + case 62: + { pstring += yytext(); yybegin(STRING); } + case -63: + break; + case 63: + { pstring += "\t"; yybegin(STRING); } + case -64: + break; + case 64: + { pstring += "\\"; yybegin(STRING); } + case -65: + break; + case 65: + { pstring += "\n"; yybegin(STRING); } + case -66: + break; + case 66: + { pstring += "\""; yybegin(STRING); } + case -67: + break; + case 68: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -68: + break; + case 69: + { return new Symbol(sym._DOUBLE_, new Double(yytext())); } + case -69: + break; + case 70: + { } + case -70: + break; + case 72: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -71: + break; + case 74: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -72: + break; + case 76: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -73: + break; + case 78: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -74: + break; + case 80: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -75: + break; + case 82: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -76: + break; + case 84: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -77: + break; + case 121: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -78: + break; + case 126: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -79: + break; + case 128: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -80: + break; + case 129: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -81: + break; + case 130: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -82: + break; + case 131: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -83: + break; + case 132: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -84: + break; + case 133: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -85: + break; + case 134: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -86: + break; + case 135: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -87: + break; + case 136: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -88: + break; + case 137: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -89: + break; + case 138: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -90: + break; + case 139: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -91: + break; + case 140: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -92: + break; + case 141: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -93: + break; + case 142: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -94: + break; + case 143: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -95: + break; + case 144: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -96: + break; + case 145: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -97: + break; + case 146: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -98: + break; + case 147: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -99: + break; + case 148: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -100: + break; + case 149: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -101: + break; + case 150: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -102: + break; + case 151: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -103: + break; + case 152: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -104: + break; + case 153: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -105: + break; + case 154: + { return new Symbol(sym._IDENT_, yytext().intern()); } + case -106: + break; + default: + yy_error(YY_E_INTERNAL,false); + case -1: + } + yy_initial = true; + yy_state = yy_state_dtrans[yy_lexical_state]; + yy_next_state = YY_NO_STATE; + yy_last_accept_state = YY_NO_STATE; + yy_mark_start(); + yy_this_accept = yy_acpt[yy_state]; + if (YY_NOT_ACCEPT != yy_this_accept) { + yy_last_accept_state = yy_state; + yy_mark_end(); + } + } + } + } + } +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/parser.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/parser.java new file mode 100644 index 0000000000000000000000000000000000000000..961061dcabff6c0b6285b6f87a6ec63f18a3efdc --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/parser.java @@ -0,0 +1,1433 @@ + +//---------------------------------------------------- +// The following code was generated by CUP v0.10k +// Fri Apr 04 05:03:03 BST 2008 +//---------------------------------------------------- + +package com.googlecode.opennars.parser.loan.Loan; + + +/** CUP v0.10k generated parser. + * @version Fri Apr 04 05:03:03 BST 2008 + */ +public class parser extends java_cup.runtime.lr_parser { + + /** Default constructor. */ + public parser() {super();} + + /** Constructor which sets the default scanner. */ + public parser(java_cup.runtime.Scanner s) {super(s);} + + /** Production table. */ + protected static final short _production_table[][] = + unpackFromStrings(new String[] { + "\000\115\000\002\002\004\000\002\003\004\000\002\003" + + "\003\000\002\004\005\000\002\005\002\000\002\005\004" + + "\000\002\006\006\000\002\006\005\000\002\006\005\000" + + "\002\006\005\000\002\006\005\000\002\006\004\000\002" + + "\006\005\000\002\007\005\000\002\007\005\000\002\007" + + "\005\000\002\007\005\000\002\007\005\000\002\007\005" + + "\000\002\007\005\000\002\007\003\000\002\010\005\000" + + "\002\010\005\000\002\010\005\000\002\010\005\000\002" + + "\010\003\000\002\011\004\000\002\011\004\000\002\011" + + "\004\000\002\011\004\000\002\011\003\000\002\012\005" + + "\000\002\012\005\000\002\012\005\000\002\012\005\000" + + "\002\012\005\000\002\012\006\000\002\012\003\000\002" + + "\012\005\000\002\013\005\000\002\013\005\000\002\013" + + "\003\000\002\014\005\000\002\014\005\000\002\014\003" + + "\000\002\015\011\000\002\015\011\000\002\015\003\000" + + "\002\016\005\000\002\016\005\000\002\016\005\000\002" + + "\016\003\000\002\016\005\000\002\016\005\000\002\017" + + "\002\000\002\017\003\000\002\017\005\000\002\020\002" + + "\000\002\020\003\000\002\020\005\000\002\021\003\000" + + "\002\021\004\000\002\022\004\000\002\022\003\000\002" + + "\022\007\000\002\022\004\000\002\022\003\000\002\022" + + "\003\000\002\022\003\000\002\022\003\000\002\022\003" + + "\000\002\022\003\000\002\023\004\000\002\023\003\000" + + "\002\024\002\000\002\024\005\000\002\024\007" }); + + /** Access to production table. */ + public short[][] production_table() {return _production_table;} + + /** Parse-action table. */ + protected static final short[][] _action_table = + unpackFromStrings(new String[] { + "\000\223\000\060\002\ufffd\004\006\006\ufffd\007\ufffd\010" + + "\ufffd\011\ufffd\012\ufffd\034\ufffd\043\ufffd\045\ufffd\047\ufffd" + + "\050\ufffd\053\ufffd\054\ufffd\056\ufffd\057\ufffd\060\ufffd\061" + + "\ufffd\062\ufffd\063\ufffd\064\ufffd\065\ufffd\066\ufffd\001\002" + + "\000\056\002\ufffd\006\ufffd\007\ufffd\010\ufffd\011\ufffd\012" + + "\ufffd\034\ufffd\043\ufffd\045\ufffd\047\ufffd\050\ufffd\053\ufffd" + + "\054\ufffd\056\ufffd\057\ufffd\060\ufffd\061\ufffd\062\ufffd\063" + + "\ufffd\064\ufffd\065\ufffd\066\ufffd\001\002\000\004\002\224" + + "\001\002\000\004\066\222\001\002\000\056\002\uffff\006" + + "\040\007\035\010\033\011\032\012\031\034\041\043\020" + + "\045\014\047\012\050\011\053\045\054\030\056\026\057" + + "\025\060\024\061\023\062\013\063\010\064\022\065\017" + + "\066\016\001\002\000\100\005\uffbe\012\uffbe\013\uffbe\014" + + "\uffbe\015\uffbe\016\uffbe\017\uffbe\020\uffbe\021\uffbe\022\uffbe" + + "\023\uffbe\024\uffbe\025\uffbe\026\uffbe\027\uffbe\030\uffbe\031" + + "\uffbe\032\uffbe\033\uffbe\034\uffbe\035\uffbe\036\uffbe\037\uffbe" + + "\040\uffbe\041\uffbe\042\uffbe\044\uffbe\046\uffbe\051\uffbe\052" + + "\uffbe\055\uffbe\001\002\000\006\065\uffb8\066\uffb8\001\002" + + "\000\004\065\213\001\002\000\100\005\uffbc\012\uffbc\013" + + "\uffbc\014\uffbc\015\uffbc\016\uffbc\017\uffbc\020\uffbc\021\uffbc" + + "\022\uffbc\023\uffbc\024\uffbc\025\uffbc\026\uffbc\027\uffbc\030" + + "\uffbc\031\uffbc\032\uffbc\033\uffbc\034\uffbc\035\uffbc\036\uffbc" + + "\037\uffbc\040\uffbc\041\uffbc\042\uffbc\044\uffbc\046\uffbc\051" + + "\uffbc\052\uffbc\055\uffbc\001\002\000\036\012\031\034\053" + + "\043\020\045\014\046\uffcb\047\012\050\011\053\045\061" + + "\023\062\013\063\010\064\022\065\017\066\016\001\002" + + "\000\030\005\uffb7\012\177\013\uffb7\014\126\015\124\016" + + "\123\017\132\020\131\021\130\022\125\051\201\001\002" + + "\000\100\005\uffc5\012\uffc5\013\uffc5\014\uffc5\015\uffc5\016" + + "\uffc5\017\uffc5\020\uffc5\021\uffc5\022\uffc5\023\uffc5\024\uffc5" + + "\025\uffc5\026\uffc5\027\uffc5\030\uffc5\031\uffc5\032\uffc5\033" + + "\uffc5\034\uffc5\035\uffc5\036\uffc5\037\uffc5\040\uffc5\041\uffc5" + + "\042\uffc5\044\uffc5\046\uffc5\051\uffc5\052\uffc5\055\uffc5\001" + + "\002\000\004\050\176\001\002\000\036\012\031\034\053" + + "\043\020\044\uffcb\045\014\047\012\050\011\053\045\061" + + "\023\062\013\063\010\064\022\065\017\066\016\001\002" + + "\000\100\005\uffbf\012\uffbf\013\uffbf\014\uffbf\015\uffbf\016" + + "\uffbf\017\uffbf\020\uffbf\021\uffbf\022\uffbf\023\uffbf\024\uffbf" + + "\025\uffbf\026\uffbf\027\uffbf\030\uffbf\031\uffbf\032\uffbf\033" + + "\uffbf\034\uffbf\035\uffbf\036\uffbf\037\uffbf\040\uffbf\041\uffbf" + + "\042\uffbf\044\uffbf\046\uffbf\051\uffbf\052\uffbf\055\uffbf\001" + + "\002\000\100\005\uffbd\012\uffbd\013\uffbd\014\uffbd\015\uffbd" + + "\016\uffbd\017\uffbd\020\uffbd\021\uffbd\022\uffbd\023\uffbd\024" + + "\uffbd\025\uffbd\026\uffbd\027\uffbd\030\uffbd\031\uffbd\032\uffbd" + + "\033\uffbd\034\uffbd\035\uffbd\036\uffbd\037\uffbd\040\uffbd\041" + + "\uffbd\042\uffbd\044\uffbd\046\uffbd\051\uffbd\052\uffbd\055\uffbd" + + "\001\002\000\100\005\uffbb\012\uffbb\013\uffbb\014\uffbb\015" + + "\uffbb\016\uffbb\017\uffbb\020\uffbb\021\uffbb\022\uffbb\023\uffbb" + + "\024\uffbb\025\uffbb\026\uffbb\027\uffbb\030\uffbb\031\uffbb\032" + + "\uffbb\033\uffbb\034\uffbb\035\uffbb\036\uffbb\037\uffbb\040\uffbb" + + "\041\uffbb\042\uffbb\044\uffbb\046\uffbb\051\uffbb\052\uffbb\055" + + "\uffbb\001\002\000\034\012\031\034\041\043\020\045\014" + + "\047\012\050\011\053\045\061\023\062\013\063\010\064" + + "\022\065\017\066\016\001\002\000\034\012\031\034\041" + + "\043\020\045\014\047\012\050\011\053\045\061\023\062" + + "\013\063\010\064\022\065\017\066\016\001\002\000\034" + + "\012\031\034\041\043\020\045\014\047\012\050\011\053" + + "\045\061\023\062\013\063\010\064\022\065\017\066\016" + + "\001\002\000\056\002\ufffc\006\ufffc\007\ufffc\010\ufffc\011" + + "\ufffc\012\ufffc\034\ufffc\043\ufffc\045\ufffc\047\ufffc\050\ufffc" + + "\053\ufffc\054\ufffc\056\ufffc\057\ufffc\060\ufffc\061\ufffc\062" + + "\ufffc\063\ufffc\064\ufffc\065\ufffc\066\ufffc\001\002\000\034" + + "\012\031\034\041\043\020\045\014\047\012\050\011\053" + + "\045\061\023\062\013\063\010\064\022\065\017\066\016" + + "\001\002\000\102\005\uffc2\012\uffc2\013\uffc2\014\uffc2\015" + + "\uffc2\016\uffc2\017\uffc2\020\uffc2\021\uffc2\022\uffc2\023\uffc2" + + "\024\uffc2\025\uffc2\026\uffc2\027\uffc2\030\uffc2\031\uffc2\032" + + "\uffc2\033\uffc2\034\uffc2\035\uffc2\036\uffc2\037\uffc2\040\uffc2" + + "\041\uffc2\042\uffc2\044\uffc2\046\uffc2\051\uffc2\052\uffc2\055" + + "\uffc2\065\167\001\002\000\010\050\011\065\017\066\016" + + "\001\002\000\004\063\163\001\002\000\042\005\uffe3\012" + + "\uffe3\013\uffe3\014\uffe3\015\uffe3\016\uffe3\017\uffe3\020\uffe3" + + "\021\uffe3\022\uffe3\023\uffe3\024\uffe3\025\uffe3\026\uffe3\035" + + "\uffe3\051\uffe3\001\002\000\004\066\161\001\002\000\042" + + "\005\uffe8\012\uffe8\013\uffe8\014\uffe8\015\uffe8\016\uffe8\017" + + "\uffe8\020\uffe8\021\uffe8\022\uffe8\023\uffe8\024\uffe8\025\uffe8" + + "\026\uffe8\035\uffe8\051\uffe8\001\002\000\042\005\uffed\012" + + "\uffed\013\uffed\014\uffed\015\uffed\016\uffed\017\uffed\020\uffed" + + "\021\uffed\022\uffed\023\137\024\136\025\135\026\134\035" + + "\uffed\051\uffed\001\002\000\006\050\011\065\017\001\002" + + "\000\046\012\031\034\041\035\uffcb\043\020\045\014\047" + + "\012\050\011\053\045\054\030\056\026\057\025\060\024" + + "\061\023\062\013\063\010\064\022\065\017\066\016\001" + + "\002\000\004\065\153\001\002\000\066\005\uffdc\012\uffdc" + + "\013\uffdc\014\uffdc\015\uffdc\016\uffdc\017\uffdc\020\uffdc\021" + + "\uffdc\022\uffdc\023\uffdc\024\uffdc\025\uffdc\026\uffdc\027\110" + + "\030\112\031\111\032\107\033\106\034\105\035\uffdc\036" + + "\060\037\057\051\uffdc\052\061\055\056\001\002\000\100" + + "\005\uffce\012\uffce\013\uffce\014\uffce\015\uffce\016\uffce\017" + + "\uffce\020\uffce\021\uffce\022\uffce\023\uffce\024\uffce\025\uffce" + + "\026\uffce\027\uffce\030\uffce\031\uffce\032\uffce\033\uffce\034" + + "\uffce\035\uffce\036\uffce\037\uffce\040\uffce\041\uffce\042\uffce" + + "\044\uffce\046\uffce\051\uffce\052\uffce\055\uffce\001\002\000" + + "\100\005\uffba\012\uffba\013\uffba\014\uffba\015\uffba\016\uffba" + + "\017\uffba\020\uffba\021\uffba\022\uffba\023\uffba\024\uffba\025" + + "\uffba\026\uffba\027\uffba\030\uffba\031\uffba\032\uffba\033\uffba" + + "\034\uffba\035\uffba\036\uffba\037\uffba\040\uffba\041\uffba\042" + + "\uffba\044\uffba\046\uffba\051\uffba\052\uffba\055\uffba\001\002" + + "\000\100\005\uffd2\012\uffd2\013\uffd2\014\uffd2\015\uffd2\016" + + "\uffd2\017\uffd2\020\uffd2\021\uffd2\022\uffd2\023\uffd2\024\uffd2" + + "\025\uffd2\026\uffd2\027\uffd2\030\uffd2\031\uffd2\032\uffd2\033" + + "\uffd2\034\uffd2\035\uffd2\036\uffd2\037\uffd2\040\uffd2\041\uffd2" + + "\042\uffd2\044\uffd2\046\uffd2\051\uffd2\052\uffd2\055\uffd2\001" + + "\002\000\100\005\uffd5\012\uffd5\013\uffd5\014\uffd5\015\uffd5" + + "\016\uffd5\017\uffd5\020\uffd5\021\uffd5\022\uffd5\023\uffd5\024" + + "\uffd5\025\uffd5\026\uffd5\027\uffd5\030\uffd5\031\uffd5\032\uffd5" + + "\033\uffd5\034\uffd5\035\uffd5\036\uffd5\037\uffd5\040\uffd5\041" + + "\uffd5\042\uffd5\044\uffd5\046\uffd5\051\uffd5\052\uffd5\055\uffd5" + + "\001\002\000\100\005\uffd8\012\uffd8\013\uffd8\014\uffd8\015" + + "\uffd8\016\uffd8\017\uffd8\020\uffd8\021\uffd8\022\uffd8\023\uffd8" + + "\024\uffd8\025\uffd8\026\uffd8\027\uffd8\030\uffd8\031\uffd8\032" + + "\uffd8\033\uffd8\034\uffd8\035\uffd8\036\uffd8\037\uffd8\040\052" + + "\041\051\042\uffd8\044\uffd8\046\uffd8\051\uffd8\052\uffd8\055" + + "\uffd8\001\002\000\034\012\031\034\053\043\020\045\014" + + "\047\012\050\011\053\045\061\023\062\013\063\010\064" + + "\022\065\017\066\016\001\002\000\034\012\031\034\053" + + "\043\020\045\014\047\012\050\011\053\045\061\023\062" + + "\013\063\010\064\022\065\017\066\016\001\002\000\046" + + "\012\031\034\041\035\uffcb\043\020\045\014\047\012\050" + + "\011\053\045\054\030\056\026\057\025\060\024\061\023" + + "\062\013\063\010\064\022\065\017\066\016\001\002\000" + + "\012\036\060\037\057\052\061\055\056\001\002\000\100" + + "\005\uffd7\012\uffd7\013\uffd7\014\uffd7\015\uffd7\016\uffd7\017" + + "\uffd7\020\uffd7\021\uffd7\022\uffd7\023\uffd7\024\uffd7\025\uffd7" + + "\026\uffd7\027\uffd7\030\uffd7\031\uffd7\032\uffd7\033\uffd7\034" + + "\uffd7\035\uffd7\036\uffd7\037\uffd7\040\uffd7\041\uffd7\042\uffd7" + + "\044\uffd7\046\uffd7\051\uffd7\052\uffd7\055\uffd7\001\002\000" + + "\004\034\074\001\002\000\034\012\031\034\053\043\020" + + "\045\014\047\012\050\011\053\045\061\023\062\013\063" + + "\010\064\022\065\017\066\016\001\002\000\034\012\031" + + "\034\053\043\020\045\014\047\012\050\011\053\045\061" + + "\023\062\013\063\010\064\022\065\017\066\016\001\002" + + "\000\004\034\062\001\002\000\036\012\031\034\053\042" + + "\uffcb\043\020\045\014\047\012\050\011\053\045\061\023" + + "\062\013\063\010\064\022\065\017\066\016\001\002\000" + + "\004\042\067\001\002\000\024\026\065\035\uffca\036\060" + + "\037\057\042\uffca\044\uffca\046\uffca\052\061\055\056\001" + + "\002\000\044\012\031\034\053\035\uffcb\042\uffcb\043\020" + + "\044\uffcb\045\014\046\uffcb\047\012\050\011\053\045\061" + + "\023\062\013\063\010\064\022\065\017\066\016\001\002" + + "\000\012\035\uffc9\042\uffc9\044\uffc9\046\uffc9\001\002\000" + + "\036\012\031\034\053\035\uffcb\043\020\045\014\047\012" + + "\050\011\053\045\061\023\062\013\063\010\064\022\065" + + "\017\066\016\001\002\000\004\035\071\001\002\000\100" + + "\005\uffd4\012\uffd4\013\uffd4\014\uffd4\015\uffd4\016\uffd4\017" + + "\uffd4\020\uffd4\021\uffd4\022\uffd4\023\uffd4\024\uffd4\025\uffd4" + + "\026\uffd4\027\uffd4\030\uffd4\031\uffd4\032\uffd4\033\uffd4\034" + + "\uffd4\035\uffd4\036\uffd4\037\uffd4\040\uffd4\041\uffd4\042\uffd4" + + "\044\uffd4\046\uffd4\051\uffd4\052\uffd4\055\uffd4\001\002\000" + + "\100\005\uffda\012\uffda\013\uffda\014\uffda\015\uffda\016\uffda" + + "\017\uffda\020\uffda\021\uffda\022\uffda\023\uffda\024\uffda\025" + + "\uffda\026\uffda\027\uffda\030\uffda\031\uffda\032\uffda\033\uffda" + + "\034\uffda\035\uffda\036\uffda\037\uffda\040\052\041\051\042" + + "\uffda\044\uffda\046\uffda\051\uffda\052\uffda\055\uffda\001\002" + + "\000\100\005\uffd9\012\uffd9\013\uffd9\014\uffd9\015\uffd9\016" + + "\uffd9\017\uffd9\020\uffd9\021\uffd9\022\uffd9\023\uffd9\024\uffd9" + + "\025\uffd9\026\uffd9\027\uffd9\030\uffd9\031\uffd9\032\uffd9\033" + + "\uffd9\034\uffd9\035\uffd9\036\uffd9\037\uffd9\040\052\041\051" + + "\042\uffd9\044\uffd9\046\uffd9\051\uffd9\052\uffd9\055\uffd9\001" + + "\002\000\036\012\031\034\053\042\uffcb\043\020\045\014" + + "\047\012\050\011\053\045\061\023\062\013\063\010\064" + + "\022\065\017\066\016\001\002\000\004\042\076\001\002" + + "\000\036\012\031\034\053\035\uffcb\043\020\045\014\047" + + "\012\050\011\053\045\061\023\062\013\063\010\064\022" + + "\065\017\066\016\001\002\000\004\035\100\001\002\000" + + "\100\005\uffd3\012\uffd3\013\uffd3\014\uffd3\015\uffd3\016\uffd3" + + "\017\uffd3\020\uffd3\021\uffd3\022\uffd3\023\uffd3\024\uffd3\025" + + "\uffd3\026\uffd3\027\uffd3\030\uffd3\031\uffd3\032\uffd3\033\uffd3" + + "\034\uffd3\035\uffd3\036\uffd3\037\uffd3\040\uffd3\041\uffd3\042" + + "\uffd3\044\uffd3\046\uffd3\051\uffd3\052\uffd3\055\uffd3\001\002" + + "\000\022\014\126\015\124\016\123\017\132\020\131\021" + + "\130\022\125\035\127\001\002\000\004\035\122\001\002" + + "\000\056\014\uffdc\015\uffdc\016\uffdc\017\uffdc\020\uffdc\021" + + "\uffdc\022\uffdc\023\uffdc\024\uffdc\025\uffdc\026\065\027\110" + + "\030\112\031\111\032\107\033\106\034\105\035\104\036" + + "\060\037\057\052\061\055\056\001\002\000\100\005\uffcc" + + "\012\uffcc\013\uffcc\014\uffcc\015\uffcc\016\uffcc\017\uffcc\020" + + "\uffcc\021\uffcc\022\uffcc\023\uffcc\024\uffcc\025\uffcc\026\uffcc" + + "\027\uffcc\030\uffcc\031\uffcc\032\uffcc\033\uffcc\034\uffcc\035" + + "\uffcc\036\uffcc\037\uffcc\040\uffcc\041\uffcc\042\uffcc\044\uffcc" + + "\046\uffcc\051\uffcc\052\uffcc\055\uffcc\001\002\000\036\012" + + "\031\034\053\035\uffcb\043\020\045\014\047\012\050\011" + + "\053\045\061\023\062\013\063\010\064\022\065\017\066" + + "\016\001\002\000\034\012\031\034\053\043\020\045\014" + + "\047\012\050\011\053\045\061\023\062\013\063\010\064" + + "\022\065\017\066\016\001\002\000\034\012\031\034\053" + + "\043\020\045\014\047\012\050\011\053\045\061\023\062" + + "\013\063\010\064\022\065\017\066\016\001\002\000\034" + + "\012\031\034\053\043\020\045\014\047\012\050\011\053" + + "\045\061\023\062\013\063\010\064\022\065\017\066\016" + + "\001\002\000\034\012\031\034\053\043\020\045\014\047" + + "\012\050\011\053\045\061\023\062\013\063\010\064\022" + + "\065\017\066\016\001\002\000\034\012\031\034\053\043" + + "\020\045\014\047\012\050\011\053\045\061\023\062\013" + + "\063\010\064\022\065\017\066\016\001\002\000\052\005" + + "\uffe1\012\uffe1\013\uffe1\014\uffe1\015\uffe1\016\uffe1\017\uffe1" + + "\020\uffe1\021\uffe1\022\uffe1\023\uffe1\024\uffe1\025\uffe1\026" + + "\uffe1\035\uffe1\036\060\037\057\051\uffe1\052\061\055\056" + + "\001\002\000\052\005\uffe0\012\uffe0\013\uffe0\014\uffe0\015" + + "\uffe0\016\uffe0\017\uffe0\020\uffe0\021\uffe0\022\uffe0\023\uffe0" + + "\024\uffe0\025\uffe0\026\uffe0\035\uffe0\036\060\037\057\051" + + "\uffe0\052\061\055\056\001\002\000\052\005\uffe2\012\uffe2" + + "\013\uffe2\014\uffe2\015\uffe2\016\uffe2\017\uffe2\020\uffe2\021" + + "\uffe2\022\uffe2\023\uffe2\024\uffe2\025\uffe2\026\uffe2\035\uffe2" + + "\036\060\037\057\051\uffe2\052\061\055\056\001\002\000" + + "\052\005\uffdf\012\uffdf\013\uffdf\014\uffdf\015\uffdf\016\uffdf" + + "\017\uffdf\020\uffdf\021\uffdf\022\uffdf\023\uffdf\024\uffdf\025" + + "\uffdf\026\uffdf\035\uffdf\036\060\037\057\051\uffdf\052\061" + + "\055\056\001\002\000\052\005\uffde\012\uffde\013\uffde\014" + + "\uffde\015\uffde\016\uffde\017\uffde\020\uffde\021\uffde\022\uffde" + + "\023\uffde\024\uffde\025\uffde\026\uffde\035\uffde\036\060\037" + + "\057\051\uffde\052\061\055\056\001\002\000\004\035\121" + + "\001\002\000\042\005\uffdd\012\uffdd\013\uffdd\014\uffdd\015" + + "\uffdd\016\uffdd\017\uffdd\020\uffdd\021\uffdd\022\uffdd\023\uffdd" + + "\024\uffdd\025\uffdd\026\uffdd\035\uffdd\051\uffdd\001\002\000" + + "\100\005\uffcf\012\uffcf\013\uffcf\014\uffcf\015\uffcf\016\uffcf" + + "\017\uffcf\020\uffcf\021\uffcf\022\uffcf\023\uffcf\024\uffcf\025" + + "\uffcf\026\uffcf\027\uffcf\030\uffcf\031\uffcf\032\uffcf\033\uffcf" + + "\034\uffcf\035\uffcf\036\uffcf\037\uffcf\040\uffcf\041\uffcf\042" + + "\uffcf\044\uffcf\046\uffcf\051\uffcf\052\uffcf\055\uffcf\001\002" + + "\000\044\012\031\034\041\043\020\045\014\047\012\050" + + "\011\053\045\054\030\056\026\057\025\060\024\061\023" + + "\062\013\063\010\064\022\065\017\066\016\001\002\000" + + "\044\012\031\034\041\043\020\045\014\047\012\050\011" + + "\053\045\054\030\056\026\057\025\060\024\061\023\062" + + "\013\063\010\064\022\065\017\066\016\001\002\000\044" + + "\012\031\034\041\043\020\045\014\047\012\050\011\053" + + "\045\054\030\056\026\057\025\060\024\061\023\062\013" + + "\063\010\064\022\065\017\066\016\001\002\000\044\012" + + "\031\034\041\043\020\045\014\047\012\050\011\053\045" + + "\054\030\056\026\057\025\060\024\061\023\062\013\063" + + "\010\064\022\065\017\066\016\001\002\000\100\005\uffcd" + + "\012\uffcd\013\uffcd\014\uffcd\015\uffcd\016\uffcd\017\uffcd\020" + + "\uffcd\021\uffcd\022\uffcd\023\uffcd\024\uffcd\025\uffcd\026\uffcd" + + "\027\uffcd\030\uffcd\031\uffcd\032\uffcd\033\uffcd\034\uffcd\035" + + "\uffcd\036\uffcd\037\uffcd\040\uffcd\041\uffcd\042\uffcd\044\uffcd" + + "\046\uffcd\051\uffcd\052\uffcd\055\uffcd\001\002\000\044\012" + + "\031\034\041\043\020\045\014\047\012\050\011\053\045" + + "\054\030\056\026\057\025\060\024\061\023\062\013\063" + + "\010\064\022\065\017\066\016\001\002\000\044\012\031" + + "\034\041\043\020\045\014\047\012\050\011\053\045\054" + + "\030\056\026\057\025\060\024\061\023\062\013\063\010" + + "\064\022\065\017\066\016\001\002\000\044\012\031\034" + + "\041\043\020\045\014\047\012\050\011\053\045\054\030" + + "\056\026\057\025\060\024\061\023\062\013\063\010\064" + + "\022\065\017\066\016\001\002\000\042\005\ufff1\012\ufff1" + + "\013\ufff1\014\ufff1\015\ufff1\016\ufff1\017\ufff1\020\ufff1\021" + + "\ufff1\022\ufff1\023\137\024\136\025\135\026\134\035\ufff1" + + "\051\ufff1\001\002\000\044\012\031\034\041\043\020\045" + + "\014\047\012\050\011\053\045\054\030\056\026\057\025" + + "\060\024\061\023\062\013\063\010\064\022\065\017\066" + + "\016\001\002\000\044\012\031\034\041\043\020\045\014" + + "\047\012\050\011\053\045\054\030\056\026\057\025\060" + + "\024\061\023\062\013\063\010\064\022\065\017\066\016" + + "\001\002\000\044\012\031\034\041\043\020\045\014\047" + + "\012\050\011\053\045\054\030\056\026\057\025\060\024" + + "\061\023\062\013\063\010\064\022\065\017\066\016\001" + + "\002\000\044\012\031\034\041\043\020\045\014\047\012" + + "\050\011\053\045\054\030\056\026\057\025\060\024\061" + + "\023\062\013\063\010\064\022\065\017\066\016\001\002" + + "\000\042\005\uffec\012\uffec\013\uffec\014\uffec\015\uffec\016" + + "\uffec\017\uffec\020\uffec\021\uffec\022\uffec\023\uffec\024\uffec" + + "\025\uffec\026\uffec\035\uffec\051\uffec\001\002\000\042\005" + + "\uffeb\012\uffeb\013\uffeb\014\uffeb\015\uffeb\016\uffeb\017\uffeb" + + "\020\uffeb\021\uffeb\022\uffeb\023\uffeb\024\uffeb\025\uffeb\026" + + "\uffeb\035\uffeb\051\uffeb\001\002\000\042\005\uffea\012\uffea" + + "\013\uffea\014\uffea\015\uffea\016\uffea\017\uffea\020\uffea\021" + + "\uffea\022\uffea\023\uffea\024\uffea\025\uffea\026\uffea\035\uffea" + + "\051\uffea\001\002\000\042\005\uffe9\012\uffe9\013\uffe9\014" + + "\uffe9\015\uffe9\016\uffe9\017\uffe9\020\uffe9\021\uffe9\022\uffe9" + + "\023\uffe9\024\uffe9\025\uffe9\026\uffe9\035\uffe9\051\uffe9\001" + + "\002\000\042\005\ufff0\012\ufff0\013\ufff0\014\ufff0\015\ufff0" + + "\016\ufff0\017\ufff0\020\ufff0\021\ufff0\022\ufff0\023\137\024" + + "\136\025\135\026\134\035\ufff0\051\ufff0\001\002\000\042" + + "\005\uffef\012\uffef\013\uffef\014\uffef\015\uffef\016\uffef\017" + + "\uffef\020\uffef\021\uffef\022\uffef\023\137\024\136\025\135" + + "\026\134\035\uffef\051\uffef\001\002\000\042\005\ufff4\012" + + "\ufff4\013\ufff4\014\ufff4\015\ufff4\016\ufff4\017\ufff4\020\ufff4" + + "\021\ufff4\022\ufff4\023\137\024\136\025\135\026\134\035" + + "\ufff4\051\ufff4\001\002\000\042\005\uffee\012\uffee\013\uffee" + + "\014\uffee\015\uffee\016\uffee\017\uffee\020\uffee\021\uffee\022" + + "\uffee\023\137\024\136\025\135\026\134\035\uffee\051\uffee" + + "\001\002\000\042\005\ufff3\012\ufff3\013\ufff3\014\ufff3\015" + + "\ufff3\016\ufff3\017\ufff3\020\ufff3\021\ufff3\022\ufff3\023\137" + + "\024\136\025\135\026\134\035\ufff3\051\ufff3\001\002\000" + + "\042\005\ufff2\012\ufff2\013\ufff2\014\ufff2\015\ufff2\016\ufff2" + + "\017\ufff2\020\ufff2\021\ufff2\022\ufff2\023\137\024\136\025" + + "\135\026\134\035\ufff2\051\ufff2\001\002\000\100\005\uffd6" + + "\012\uffd6\013\uffd6\014\uffd6\015\uffd6\016\uffd6\017\uffd6\020" + + "\uffd6\021\uffd6\022\uffd6\023\uffd6\024\uffd6\025\uffd6\026\uffd6" + + "\027\uffd6\030\uffd6\031\uffd6\032\uffd6\033\uffd6\034\uffd6\035" + + "\uffd6\036\uffd6\037\uffd6\040\uffd6\041\uffd6\042\uffd6\044\uffd6" + + "\046\uffd6\051\uffd6\052\uffd6\055\uffd6\001\002\000\100\005" + + "\uffc4\012\uffc4\013\uffc4\014\uffc4\015\uffc4\016\uffc4\017\uffc4" + + "\020\uffc4\021\uffc4\022\uffc4\023\uffc4\024\uffc4\025\uffc4\026" + + "\uffc4\027\uffc4\030\uffc4\031\uffc4\032\uffc4\033\uffc4\034\uffc4" + + "\035\uffc4\036\uffc4\037\uffc4\040\uffc4\041\uffc4\042\uffc4\044" + + "\uffc4\046\uffc4\051\uffc4\052\uffc4\055\uffc4\001\002\000\022" + + "\014\126\015\124\016\123\017\132\020\131\021\130\022" + + "\125\035\155\001\002\000\072\005\uffdb\012\uffdb\013\uffdb" + + "\014\uffdb\015\uffdb\016\uffdb\017\uffdb\020\uffdb\021\uffdb\022" + + "\uffdb\023\uffdb\024\uffdb\025\uffdb\026\uffdb\027\uffcd\030\uffcd" + + "\031\uffcd\032\uffcd\033\uffcd\034\uffcd\035\uffdb\036\uffcd\037" + + "\uffcd\040\uffcd\041\uffcd\051\uffdb\052\uffcd\055\uffcd\001\002" + + "\000\004\066\157\001\002\000\004\005\160\001\002\000" + + "\056\002\ufffb\006\ufffb\007\ufffb\010\ufffb\011\ufffb\012\ufffb" + + "\034\ufffb\043\ufffb\045\ufffb\047\ufffb\050\ufffb\053\ufffb\054" + + "\ufffb\056\ufffb\057\ufffb\060\ufffb\061\ufffb\062\ufffb\063\ufffb" + + "\064\ufffb\065\ufffb\066\ufffb\001\002\000\004\005\162\001" + + "\002\000\056\002\ufffa\006\ufffa\007\ufffa\010\ufffa\011\ufffa" + + "\012\ufffa\034\ufffa\043\ufffa\045\ufffa\047\ufffa\050\ufffa\053" + + "\ufffa\054\ufffa\056\ufffa\057\ufffa\060\ufffa\061\ufffa\062\ufffa" + + "\063\ufffa\064\ufffa\065\ufffa\066\ufffa\001\002\000\004\005" + + "\164\001\002\000\056\002\ufff9\006\ufff9\007\ufff9\010\ufff9" + + "\011\ufff9\012\ufff9\034\ufff9\043\ufff9\045\ufff9\047\ufff9\050" + + "\ufff9\053\ufff9\054\ufff9\056\ufff9\057\ufff9\060\ufff9\061\ufff9" + + "\062\ufff9\063\ufff9\064\ufff9\065\ufff9\066\ufff9\001\002\000" + + "\004\005\166\001\002\000\056\002\ufff8\006\ufff8\007\ufff8" + + "\010\ufff8\011\ufff8\012\ufff8\034\ufff8\043\ufff8\045\ufff8\047" + + "\ufff8\050\ufff8\053\ufff8\054\ufff8\056\ufff8\057\ufff8\060\ufff8" + + "\061\ufff8\062\ufff8\063\ufff8\064\ufff8\065\ufff8\066\ufff8\001" + + "\002\000\100\005\uffc3\012\uffc3\013\uffc3\014\uffc3\015\uffc3" + + "\016\uffc3\017\uffc3\020\uffc3\021\uffc3\022\uffc3\023\uffc3\024" + + "\uffc3\025\uffc3\026\uffc3\027\uffc3\030\uffc3\031\uffc3\032\uffc3" + + "\033\uffc3\034\uffc3\035\uffc3\036\uffc3\037\uffc3\040\uffc3\041" + + "\uffc3\042\uffc3\044\uffc3\046\uffc3\051\uffc3\052\uffc3\055\uffc3" + + "\001\002\000\042\005\uffe4\012\uffe4\013\uffe4\014\uffe4\015" + + "\uffe4\016\uffe4\017\uffe4\020\uffe4\021\uffe4\022\uffe4\023\uffe4" + + "\024\uffe4\025\uffe4\026\uffe4\035\uffe4\051\uffe4\001\002\000" + + "\042\005\uffe7\012\uffe7\013\uffe7\014\uffe7\015\uffe7\016\uffe7" + + "\017\uffe7\020\uffe7\021\uffe7\022\uffe7\023\uffe7\024\uffe7\025" + + "\uffe7\026\uffe7\035\uffe7\051\uffe7\001\002\000\042\005\uffe6" + + "\012\uffe6\013\uffe6\014\uffe6\015\uffe6\016\uffe6\017\uffe6\020" + + "\uffe6\021\uffe6\022\uffe6\023\uffe6\024\uffe6\025\uffe6\026\uffe6" + + "\035\uffe6\051\uffe6\001\002\000\042\005\uffe5\012\uffe5\013" + + "\uffe5\014\uffe5\015\uffe5\016\uffe5\017\uffe5\020\uffe5\021\uffe5" + + "\022\uffe5\023\uffe5\024\uffe5\025\uffe5\026\uffe5\035\uffe5\051" + + "\uffe5\001\002\000\004\044\175\001\002\000\100\005\uffd1" + + "\012\uffd1\013\uffd1\014\uffd1\015\uffd1\016\uffd1\017\uffd1\020" + + "\uffd1\021\uffd1\022\uffd1\023\uffd1\024\uffd1\025\uffd1\026\uffd1" + + "\027\uffd1\030\uffd1\031\uffd1\032\uffd1\033\uffd1\034\uffd1\035" + + "\uffd1\036\uffd1\037\uffd1\040\uffd1\041\uffd1\042\uffd1\044\uffd1" + + "\046\uffd1\051\uffd1\052\uffd1\055\uffd1\001\002\000\006\065" + + "\uffb9\066\uffb9\001\002\000\056\002\ufff6\006\ufff6\007\ufff6" + + "\010\ufff6\011\ufff6\012\ufff6\034\ufff6\043\ufff6\045\ufff6\047" + + "\ufff6\050\ufff6\053\ufff6\054\ufff6\056\ufff6\057\ufff6\060\ufff6" + + "\061\ufff6\062\ufff6\063\ufff6\064\ufff6\065\ufff6\066\ufff6\001" + + "\002\000\006\005\207\013\210\001\002\000\004\064\202" + + "\001\002\000\006\025\203\051\204\001\002\000\004\064" + + "\205\001\002\000\006\005\uffb6\013\uffb6\001\002\000\004" + + "\051\206\001\002\000\006\005\uffb5\013\uffb5\001\002\000" + + "\056\002\ufff7\006\ufff7\007\ufff7\010\ufff7\011\ufff7\012\ufff7" + + "\034\ufff7\043\ufff7\045\ufff7\047\ufff7\050\ufff7\053\ufff7\054" + + "\ufff7\056\ufff7\057\ufff7\060\ufff7\061\ufff7\062\ufff7\063\ufff7" + + "\064\ufff7\065\ufff7\066\ufff7\001\002\000\056\002\ufff5\006" + + "\ufff5\007\ufff5\010\ufff5\011\ufff5\012\ufff5\034\ufff5\043\ufff5" + + "\045\ufff5\047\ufff5\050\ufff5\053\ufff5\054\ufff5\056\ufff5\057" + + "\ufff5\060\ufff5\061\ufff5\062\ufff5\063\ufff5\064\ufff5\065\ufff5" + + "\066\ufff5\001\002\000\004\046\212\001\002\000\100\005" + + "\uffd0\012\uffd0\013\uffd0\014\uffd0\015\uffd0\016\uffd0\017\uffd0" + + "\020\uffd0\021\uffd0\022\uffd0\023\uffd0\024\uffd0\025\uffd0\026" + + "\uffd0\027\uffd0\030\uffd0\031\uffd0\032\uffd0\033\uffd0\034\uffd0" + + "\035\uffd0\036\uffd0\037\uffd0\040\uffd0\041\uffd0\042\uffd0\044" + + "\uffd0\046\uffd0\051\uffd0\052\uffd0\055\uffd0\001\002\000\100" + + "\005\uffc0\012\uffc0\013\uffc0\014\uffc0\015\uffc0\016\uffc0\017" + + "\uffc0\020\uffc0\021\uffc0\022\uffc0\023\uffc0\024\uffc0\025\uffc0" + + "\026\uffc0\027\uffc0\030\uffc0\031\uffc0\032\uffc0\033\uffc0\034" + + "\214\035\uffc0\036\uffc0\037\uffc0\040\uffc0\041\uffc0\042\uffc0" + + "\044\uffc0\046\uffc0\051\uffc0\052\uffc0\055\uffc0\001\002\000" + + "\006\035\uffc8\065\216\001\002\000\004\035\221\001\002" + + "\000\006\026\217\035\uffc7\001\002\000\006\035\uffc8\065" + + "\216\001\002\000\004\035\uffc6\001\002\000\100\005\uffc1" + + "\012\uffc1\013\uffc1\014\uffc1\015\uffc1\016\uffc1\017\uffc1\020" + + "\uffc1\021\uffc1\022\uffc1\023\uffc1\024\uffc1\025\uffc1\026\uffc1" + + "\027\uffc1\030\uffc1\031\uffc1\032\uffc1\033\uffc1\034\uffc1\035" + + "\uffc1\036\uffc1\037\uffc1\040\uffc1\041\uffc1\042\uffc1\044\uffc1" + + "\046\uffc1\051\uffc1\052\uffc1\055\uffc1\001\002\000\004\005" + + "\223\001\002\000\056\002\ufffe\006\ufffe\007\ufffe\010\ufffe" + + "\011\ufffe\012\ufffe\034\ufffe\043\ufffe\045\ufffe\047\ufffe\050" + + "\ufffe\053\ufffe\054\ufffe\056\ufffe\057\ufffe\060\ufffe\061\ufffe" + + "\062\ufffe\063\ufffe\064\ufffe\065\ufffe\066\ufffe\001\002\000" + + "\004\002\001\001\002\000\056\002\000\006\040\007\035" + + "\010\033\011\032\012\031\034\041\043\020\045\014\047" + + "\012\050\011\053\045\054\030\056\026\057\025\060\024" + + "\061\023\062\013\063\010\064\022\065\017\066\016\001" + + "\002" }); + + /** Access to parse-action table. */ + public short[][] action_table() {return _action_table;} + + /** <code>reduce_goto</code> table. */ + protected static final short[][] _reduce_table = + unpackFromStrings(new String[] { + "\000\223\000\010\003\004\004\003\005\006\001\001\000" + + "\004\005\224\001\001\000\002\001\001\000\002\001\001" + + "\000\032\006\026\007\014\010\036\011\035\012\033\013" + + "\042\014\047\015\046\016\045\021\020\022\043\023\041" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\022\013\063\014\047\015\046" + + "\016\045\017\210\021\020\022\043\023\041\001\001\000" + + "\004\024\177\001\001\000\002\001\001\000\002\001\001" + + "\000\022\013\063\014\047\015\046\016\045\017\173\021" + + "\020\022\043\023\041\001\001\000\002\001\001\000\002" + + "\001\001\000\002\001\001\000\022\012\172\013\042\014" + + "\047\015\046\016\045\021\020\022\043\023\041\001\001" + + "\000\022\012\171\013\042\014\047\015\046\016\045\021" + + "\020\022\043\023\041\001\001\000\022\012\170\013\042" + + "\014\047\015\046\016\045\021\020\022\043\023\041\001" + + "\001\000\002\001\001\000\022\012\167\013\042\014\047" + + "\015\046\016\045\021\020\022\043\023\041\001\001\000" + + "\002\001\001\000\006\021\164\023\041\001\001\000\002" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\004\023\155\001\001\000\032" + + "\007\153\010\036\011\035\012\033\013\102\014\047\015" + + "\046\016\045\017\101\021\020\022\043\023\041\001\001" + + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + + "\002\001\001\000\002\001\001\000\002\001\001\000\002" + + "\001\001\000\020\013\053\014\047\015\151\016\045\021" + + "\020\022\043\023\041\001\001\000\020\013\053\014\047" + + "\015\054\016\045\021\020\022\043\023\041\001\001\000" + + "\032\007\100\010\036\011\035\012\033\013\102\014\047" + + "\015\046\016\045\017\101\021\020\022\043\023\041\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\020\013\053\014\072\015\046\016\045\021\020\022" + + "\043\023\041\001\001\000\020\013\053\014\071\015\046" + + "\016\045\021\020\022\043\023\041\001\001\000\002\001" + + "\001\000\022\013\063\014\047\015\046\016\045\017\062" + + "\021\020\022\043\023\041\001\001\000\002\001\001\000" + + "\002\001\001\000\022\013\063\014\047\015\046\016\045" + + "\017\065\021\020\022\043\023\041\001\001\000\002\001" + + "\001\000\022\013\063\014\047\015\046\016\045\017\067" + + "\021\020\022\043\023\041\001\001\000\002\001\001\000" + + "\002\001\001\000\002\001\001\000\002\001\001\000\022" + + "\013\063\014\047\015\046\016\045\017\074\021\020\022" + + "\043\023\041\001\001\000\002\001\001\000\022\013\063" + + "\014\047\015\046\016\045\017\076\021\020\022\043\023" + + "\041\001\001\000\002\001\001\000\002\001\001\000\002" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\022\013\063\014\047\015\046\016\045\017\117" + + "\021\020\022\043\023\041\001\001\000\020\013\116\014" + + "\047\015\046\016\045\021\020\022\043\023\041\001\001" + + "\000\020\013\115\014\047\015\046\016\045\021\020\022" + + "\043\023\041\001\001\000\020\013\114\014\047\015\046" + + "\016\045\021\020\022\043\023\041\001\001\000\020\013" + + "\113\014\047\015\046\016\045\021\020\022\043\023\041" + + "\001\001\000\020\013\112\014\047\015\046\016\045\021" + + "\020\022\043\023\041\001\001\000\002\001\001\000\002" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\026\010\150\011\035\012\033\013\042\014\047\015" + + "\046\016\045\021\020\022\043\023\041\001\001\000\026" + + "\010\147\011\035\012\033\013\042\014\047\015\046\016" + + "\045\021\020\022\043\023\041\001\001\000\026\010\146" + + "\011\035\012\033\013\042\014\047\015\046\016\045\021" + + "\020\022\043\023\041\001\001\000\026\010\145\011\035" + + "\012\033\013\042\014\047\015\046\016\045\021\020\022" + + "\043\023\041\001\001\000\002\001\001\000\026\010\144" + + "\011\035\012\033\013\042\014\047\015\046\016\045\021" + + "\020\022\043\023\041\001\001\000\026\010\143\011\035" + + "\012\033\013\042\014\047\015\046\016\045\021\020\022" + + "\043\023\041\001\001\000\026\010\132\011\035\012\033" + + "\013\042\014\047\015\046\016\045\021\020\022\043\023" + + "\041\001\001\000\002\001\001\000\024\011\142\012\033" + + "\013\042\014\047\015\046\016\045\021\020\022\043\023" + + "\041\001\001\000\024\011\141\012\033\013\042\014\047" + + "\015\046\016\045\021\020\022\043\023\041\001\001\000" + + "\024\011\140\012\033\013\042\014\047\015\046\016\045" + + "\021\020\022\043\023\041\001\001\000\024\011\137\012" + + "\033\013\042\014\047\015\046\016\045\021\020\022\043" + + "\023\041\001\001\000\002\001\001\000\002\001\001\000" + + "\002\001\001\000\002\001\001\000\002\001\001\000\002" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + + "\002\001\001\000\002\001\001\000\002\001\001\000\002" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + + "\002\001\001\000\002\001\001\000\002\001\001\000\002" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + + "\002\001\001\000\002\001\001\000\002\001\001\000\004" + + "\020\214\001\001\000\002\001\001\000\002\001\001\000" + + "\004\020\217\001\001\000\002\001\001\000\002\001\001" + + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + + "\032\006\026\007\014\010\036\011\035\012\033\013\042" + + "\014\047\015\046\016\045\021\020\022\043\023\041\001" + + "\001" }); + + /** Access to <code>reduce_goto</code> table. */ + public short[][] reduce_table() {return _reduce_table;} + + /** Instance of action encapsulation class. */ + protected CUP$parser$actions action_obj; + + /** Action encapsulation object initializer. */ + protected void init_actions() + { + action_obj = new CUP$parser$actions(this); + } + + /** Invoke a user supplied parse action. */ + public java_cup.runtime.Symbol do_action( + int act_num, + java_cup.runtime.lr_parser parser, + java.util.Stack stack, + int top) + throws java.lang.Exception + { + /* call code in generated class */ + return action_obj.CUP$parser$do_action(act_num, parser, stack, top); + } + + /** Indicates start state. */ + public int start_state() {return 0;} + /** Indicates start production. */ + public int start_production() {return 0;} + + /** <code>EOF</code> Symbol index. */ + public int EOF_sym() {return 0;} + + /** <code>error</code> Symbol index. */ + public int error_sym() {return 1;} + + + + public com.googlecode.opennars.parser.loan.Loan.Absyn.Document pDocument() throws Exception + { + java_cup.runtime.Symbol res = parse(); + return (com.googlecode.opennars.parser.loan.Loan.Absyn.Document) res.value; + } + +public <B,A extends java.util.LinkedList<? super B>> A cons_(B x, A xs) { xs.addFirst(x); return xs; } + +public void syntax_error(java_cup.runtime.Symbol cur_token) +{ + report_error("Syntax Error, trying to recover and continue parse...", cur_token); +} + +public void unrecovered_syntax_error(java_cup.runtime.Symbol cur_token) throws java.lang.Exception +{ + throw new Exception("Unrecoverable Syntax Error"); +} + + +} + +/** Cup generated class to encapsulate user supplied action code.*/ +class CUP$parser$actions { + private final parser parser; + + /** Constructor */ + CUP$parser$actions(parser parser) { + this.parser = parser; + } + + /** Method with the actual generated action code. */ + public final java_cup.runtime.Symbol CUP$parser$do_action( + int CUP$parser$act_num, + java_cup.runtime.lr_parser CUP$parser$parser, + java.util.Stack CUP$parser$stack, + int CUP$parser$top) + throws java.lang.Exception + { + /* Symbol object for return from actions */ + java_cup.runtime.Symbol CUP$parser$result; + + /* select the action based on the action number */ + switch (CUP$parser$act_num) + { + /*. . . . . . . . . . . . . . . . . . . .*/ + case 76: // TruthValue ::= _SYMB_37 _DOUBLE_ _SYMB_17 _DOUBLE_ _SYMB_37 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue RESULT = null; + Double p_2 = (Double)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-3)).value; + Double p_4 = (Double)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC(p_2,p_4); + CUP$parser$result = new java_cup.runtime.Symbol(18/*TruthValue*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 75: // TruthValue ::= _SYMB_37 _DOUBLE_ _SYMB_37 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue RESULT = null; + Double p_2 = (Double)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(18/*TruthValue*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 74: // TruthValue ::= + { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue RESULT = null; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE(); + CUP$parser$result = new java_cup.runtime.Symbol(18/*TruthValue*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 73: // NSPrefix ::= _SYMB_36 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix RESULT = null; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2(); + CUP$parser$result = new java_cup.runtime.Symbol(17/*NSPrefix*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 72: // NSPrefix ::= _IDENT_ _SYMB_36 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix RESULT = null; + String p_1 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(17/*NSPrefix*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 71: // Literal ::= _SYMB_39 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal RESULT = null; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse(); + CUP$parser$result = new java_cup.runtime.Symbol(16/*Literal*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 70: // Literal ::= _SYMB_45 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal RESULT = null; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue(); + CUP$parser$result = new java_cup.runtime.Symbol(16/*Literal*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 69: // Literal ::= _STRING_ + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal RESULT = null; + String p_1 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitString(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(16/*Literal*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 68: // Literal ::= _DOUBLE_ + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal RESULT = null; + Double p_1 = (Double)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(16/*Literal*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 67: // Literal ::= _INTEGER_ + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal RESULT = null; + Integer p_1 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(16/*Literal*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 66: // Literal ::= URIRef + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(16/*Literal*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 65: // Literal ::= _SYMB_35 _IDENT_ + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal RESULT = null; + String p_2 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(16/*Literal*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 64: // Literal ::= _SYMB_35 _IDENT_ _SYMB_24 ListIdent _SYMB_25 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal RESULT = null; + String p_2 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-3)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent p_4 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD(p_2,p_4); + CUP$parser$result = new java_cup.runtime.Symbol(16/*Literal*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 63: // Literal ::= _SYMB_6 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal RESULT = null; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn(); + CUP$parser$result = new java_cup.runtime.Symbol(16/*Literal*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 62: // Literal ::= _SYMB_6 _IDENT_ + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal RESULT = null; + String p_2 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(16/*Literal*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 61: // URIRef ::= NSPrefix _IDENT_ + { + com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + String p_2 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.URICur(p_1,p_2); + CUP$parser$result = new java_cup.runtime.Symbol(15/*URIRef*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 60: // URIRef ::= URILit + { + com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef RESULT = null; + String p_1 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(15/*URIRef*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 59: // ListIdent ::= _IDENT_ _SYMB_18 ListIdent + { + com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent RESULT = null; + String p_1 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = p_3; p_3.addFirst(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(14/*ListIdent*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 58: // ListIdent ::= _IDENT_ + { + com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent RESULT = null; + String p_1 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent(); RESULT.addLast(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(14/*ListIdent*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 57: // ListIdent ::= + { + com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent RESULT = null; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent(); + CUP$parser$result = new java_cup.runtime.Symbol(14/*ListIdent*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 56: // ListTerm ::= Term _SYMB_18 ListTerm + { + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = p_3; p_3.addFirst(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(13/*ListTerm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 55: // ListTerm ::= Term + { + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm(); RESULT.addLast(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(13/*ListTerm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 54: // ListTerm ::= + { + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm RESULT = null; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm(); + CUP$parser$result = new java_cup.runtime.Symbol(13/*ListTerm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 53: // Term3 ::= _SYMB_24 Term _SYMB_25 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = p_2; + CUP$parser$result = new java_cup.runtime.Symbol(12/*Term3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 52: // Term3 ::= _SYMB_24 Stm _SYMB_25 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(12/*Term3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 51: // Term3 ::= Literal + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Literal p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Literal)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(12/*Term3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 50: // Term3 ::= _SYMB_24 ListTerm _SYMB_25 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(12/*Term3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 49: // Term3 ::= _SYMB_33 ListTerm _SYMB_34 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(12/*Term3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 48: // Term3 ::= _SYMB_31 ListTerm _SYMB_32 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(12/*Term3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 47: // Term2 ::= Term3 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = p_1; + CUP$parser$result = new java_cup.runtime.Symbol(11/*Term2*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 46: // Term2 ::= Term _SYMB_41 _SYMB_24 ListTerm _SYMB_30 ListTerm _SYMB_25 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-6)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm p_4 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-3)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm p_6 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg(p_1,p_4,p_6); + CUP$parser$result = new java_cup.runtime.Symbol(11/*Term2*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 45: // Term2 ::= Term _SYMB_38 _SYMB_24 ListTerm _SYMB_30 ListTerm _SYMB_25 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-6)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm p_4 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-3)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm p_6 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg(p_1,p_4,p_6); + CUP$parser$result = new java_cup.runtime.Symbol(11/*Term2*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 44: // Term1 ::= Term2 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = p_1; + CUP$parser$result = new java_cup.runtime.Symbol(10/*Term1*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 43: // Term1 ::= Term1 _SYMB_29 Term2 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(10/*Term1*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 42: // Term1 ::= Term1 _SYMB_28 Term2 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(10/*Term1*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 41: // Term ::= Term1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = p_1; + CUP$parser$result = new java_cup.runtime.Symbol(9/*Term*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 40: // Term ::= Term _SYMB_27 Term1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(9/*Term*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 39: // Term ::= Term _SYMB_26 Term1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(9/*Term*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 38: // Stm3 ::= _SYMB_24 Stm _SYMB_25 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = p_2; + CUP$parser$result = new java_cup.runtime.Symbol(8/*Stm3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 37: // Stm3 ::= Term + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(8/*Stm3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 36: // Stm3 ::= Term _SYMB_24 ListTerm _SYMB_25 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-3)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(8/*Stm3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 35: // Stm3 ::= Term _SYMB_23 Term + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(8/*Stm3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 34: // Stm3 ::= Term _SYMB_22 Term + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(8/*Stm3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 33: // Stm3 ::= Term _SYMB_21 Term + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(8/*Stm3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 32: // Stm3 ::= Term _SYMB_20 Term + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(8/*Stm3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 31: // Stm3 ::= Term _SYMB_19 Term + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Term p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Term)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(8/*Stm3*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 30: // Stm2 ::= Stm3 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = p_1; + CUP$parser$result = new java_cup.runtime.Symbol(7/*Stm2*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 29: // Stm2 ::= _SYMB_40 Stm3 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(7/*Stm2*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 28: // Stm2 ::= _SYMB_44 Stm3 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(7/*Stm2*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 27: // Stm2 ::= _SYMB_43 Stm3 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(7/*Stm2*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 26: // Stm2 ::= _SYMB_42 Stm3 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(7/*Stm2*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 25: // Stm1 ::= Stm2 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = p_1; + CUP$parser$result = new java_cup.runtime.Symbol(6/*Stm1*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 24: // Stm1 ::= Stm1 _SYMB_18 Stm2 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(6/*Stm1*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 23: // Stm1 ::= Stm1 _SYMB_17 Stm2 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(6/*Stm1*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 22: // Stm1 ::= Stm1 _SYMB_16 Stm2 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(6/*Stm1*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 21: // Stm1 ::= Stm1 _SYMB_15 Stm2 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(6/*Stm1*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 20: // Stm ::= Stm1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = p_1; + CUP$parser$result = new java_cup.runtime.Symbol(5/*Stm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 19: // Stm ::= Stm _SYMB_14 Stm1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(5/*Stm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 18: // Stm ::= Stm _SYMB_13 Stm1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(5/*Stm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 17: // Stm ::= Stm _SYMB_12 Stm1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(5/*Stm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 16: // Stm ::= Stm _SYMB_11 Stm1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(5/*Stm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 15: // Stm ::= Stm _SYMB_10 Stm1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(5/*Stm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 14: // Stm ::= Stm _SYMB_9 Stm1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(5/*Stm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 13: // Stm ::= Stm _SYMB_8 Stm1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_3 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl(p_1,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(5/*Stm*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 12: // Sentence ::= Stm TruthValue _SYMB_7 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal(p_1,p_2); + CUP$parser$result = new java_cup.runtime.Symbol(4/*Sentence*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 11: // Sentence ::= Stm _SYMB_6 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(4/*Sentence*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 10: // Sentence ::= Stm TruthValue _SYMB_1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Stm)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge(p_1,p_2); + CUP$parser$result = new java_cup.runtime.Symbol(4/*Sentence*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 9: // Sentence ::= _SYMB_5 URIRef _SYMB_1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.URIRef)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(4/*Sentence*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 8: // Sentence ::= _SYMB_4 _INTEGER_ _SYMB_1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence RESULT = null; + Integer p_2 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(4/*Sentence*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 7: // Sentence ::= _SYMB_3 URILit _SYMB_1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence RESULT = null; + String p_2 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(4/*Sentence*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 6: // Sentence ::= _SYMB_2 NSPrefix URILit _SYMB_1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + String p_3 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix(p_2,p_3); + CUP$parser$result = new java_cup.runtime.Symbol(4/*Sentence*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 5: // ListSentence ::= ListSentence Sentence + { + com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = p_1; p_1.addLast(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(3/*ListSentence*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 4: // ListSentence ::= + { + com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence RESULT = null; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence(); + CUP$parser$result = new java_cup.runtime.Symbol(3/*ListSentence*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 3: // BaseRule ::= _SYMB_0 URILit _SYMB_1 + { + com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule RESULT = null; + String p_2 = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR(p_2); + CUP$parser$result = new java_cup.runtime.Symbol(2/*BaseRule*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 2: // Document ::= ListSentence + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Document RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.Doc(p_1); + CUP$parser$result = new java_cup.runtime.Symbol(1/*Document*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 1: // Document ::= BaseRule ListSentence + { + com.googlecode.opennars.parser.loan.Loan.Absyn.Document RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule p_1 = (com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence p_2 = (com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR(p_1,p_2); + CUP$parser$result = new java_cup.runtime.Symbol(1/*Document*/, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 0: // $START ::= Document EOF + { + Object RESULT = null; + com.googlecode.opennars.parser.loan.Loan.Absyn.Document start_val = (com.googlecode.opennars.parser.loan.Loan.Absyn.Document)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = start_val; + CUP$parser$result = new java_cup.runtime.Symbol(0/*$START*/, RESULT); + } + /* ACCEPT */ + CUP$parser$parser.done_parsing(); + return CUP$parser$result; + + /* . . . . . .*/ + default: + throw new Exception( + "Invalid action number found in internal parse table"); + + } + } +} + diff --git a/open-nars/com/googlecode/opennars/parser/loan/Loan/sym.java b/open-nars/com/googlecode/opennars/parser/loan/Loan/sym.java new file mode 100644 index 0000000000000000000000000000000000000000..db86f2a21b7c83caf68a8596190633615a6112f1 --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/Loan/sym.java @@ -0,0 +1,66 @@ + +//---------------------------------------------------- +// The following code was generated by CUP v0.10k +// Fri Apr 04 05:03:03 BST 2008 +//---------------------------------------------------- + +package com.googlecode.opennars.parser.loan.Loan; + +/** CUP generated class containing symbol constants. */ +public class sym { + /* terminals */ + public static final int _SYMB_18 = 20; + public static final int _SYMB_17 = 19; + public static final int _SYMB_16 = 18; + public static final int _SYMB_15 = 17; + public static final int _SYMB_14 = 16; + public static final int _SYMB_45 = 47; + public static final int _SYMB_13 = 15; + public static final int _SYMB_44 = 46; + public static final int _SYMB_12 = 14; + public static final int _SYMB_43 = 45; + public static final int _SYMB_11 = 13; + public static final int _SYMB_9 = 11; + public static final int _SYMB_42 = 44; + public static final int _SYMB_8 = 10; + public static final int _SYMB_10 = 12; + public static final int _SYMB_41 = 43; + public static final int _SYMB_7 = 9; + public static final int URILit = 52; + public static final int _SYMB_40 = 42; + public static final int _SYMB_6 = 8; + public static final int _SYMB_5 = 7; + public static final int _SYMB_4 = 6; + public static final int _SYMB_3 = 5; + public static final int _SYMB_2 = 4; + public static final int _SYMB_1 = 3; + public static final int _SYMB_0 = 2; + public static final int _IDENT_ = 51; + public static final int _INTEGER_ = 49; + public static final int _STRING_ = 48; + public static final int _SYMB_39 = 41; + public static final int _SYMB_38 = 40; + public static final int _SYMB_37 = 39; + public static final int _SYMB_36 = 38; + public static final int _SYMB_35 = 37; + public static final int _SYMB_34 = 36; + public static final int _SYMB_33 = 35; + public static final int _SYMB_32 = 34; + public static final int _SYMB_31 = 33; + public static final int _SYMB_30 = 32; + public static final int EOF = 0; + public static final int error = 1; + public static final int _SYMB_29 = 31; + public static final int _SYMB_28 = 30; + public static final int _SYMB_27 = 29; + public static final int _SYMB_26 = 28; + public static final int _SYMB_25 = 27; + public static final int _SYMB_24 = 26; + public static final int _SYMB_23 = 25; + public static final int _SYMB_22 = 24; + public static final int _SYMB_21 = 23; + public static final int _SYMB_20 = 22; + public static final int _DOUBLE_ = 50; + public static final int _SYMB_19 = 21; +} + diff --git a/open-nars/com/googlecode/opennars/parser/loan/LoanParser.java b/open-nars/com/googlecode/opennars/parser/loan/LoanParser.java new file mode 100644 index 0000000000000000000000000000000000000000..c663d962ccb4a005664e30291d925759f8cd267c --- /dev/null +++ b/open-nars/com/googlecode/opennars/parser/loan/LoanParser.java @@ -0,0 +1,1449 @@ +package com.googlecode.opennars.parser.loan; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import com.googlecode.opennars.entity.Base; +import com.googlecode.opennars.entity.BudgetValue; +import com.googlecode.opennars.entity.Sentence; +import com.googlecode.opennars.entity.Task; +import com.googlecode.opennars.entity.TruthValue; +import com.googlecode.opennars.language.BooleanLiteral; +import com.googlecode.opennars.language.CompoundTerm; +import com.googlecode.opennars.language.Conjunction; +import com.googlecode.opennars.language.ConjunctionParallel; +import com.googlecode.opennars.language.ConjunctionSequence; +import com.googlecode.opennars.language.DifferenceExt; +import com.googlecode.opennars.language.DifferenceInt; +import com.googlecode.opennars.language.Disjunction; +import com.googlecode.opennars.language.Equivalence; +import com.googlecode.opennars.language.EquivalenceAfter; +import com.googlecode.opennars.language.EquivalenceWhen; +import com.googlecode.opennars.language.ImageExt; +import com.googlecode.opennars.language.ImageInt; +import com.googlecode.opennars.language.Implication; +import com.googlecode.opennars.language.ImplicationAfter; +import com.googlecode.opennars.language.ImplicationBefore; +import com.googlecode.opennars.language.ImplicationWhen; +import com.googlecode.opennars.language.Inheritance; +import com.googlecode.opennars.language.Instance; +import com.googlecode.opennars.language.InstanceProperty; +import com.googlecode.opennars.language.IntersectionExt; +import com.googlecode.opennars.language.IntersectionInt; +import com.googlecode.opennars.language.Literal; +import com.googlecode.opennars.language.Negation; +import com.googlecode.opennars.language.NumericLiteral; +import com.googlecode.opennars.language.Product; +import com.googlecode.opennars.language.Property; +import com.googlecode.opennars.language.SetExt; +import com.googlecode.opennars.language.SetInt; +import com.googlecode.opennars.language.Similarity; +import com.googlecode.opennars.language.Statement; +import com.googlecode.opennars.language.StringLiteral; +import com.googlecode.opennars.language.TenseFuture; +import com.googlecode.opennars.language.TensePast; +import com.googlecode.opennars.language.TensePresent; +import com.googlecode.opennars.language.Term; +import com.googlecode.opennars.language.URIRef; +import com.googlecode.opennars.language.Variable; +import com.googlecode.opennars.main.Memory; +import com.googlecode.opennars.parser.InvalidInputException; +import com.googlecode.opennars.parser.Parser; +import com.googlecode.opennars.parser.Symbols; +import com.googlecode.opennars.parser.TermVisitor; +import com.googlecode.opennars.parser.loan.Loan.AbstractVisitor; +import com.googlecode.opennars.parser.loan.Loan.PrettyPrinter; +import com.googlecode.opennars.parser.loan.Loan.Yylex; +import com.googlecode.opennars.parser.loan.Loan.parser; +import com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR; +import com.googlecode.opennars.parser.loan.Loan.Absyn.Doc; +import com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR; +import com.googlecode.opennars.parser.loan.Loan.Absyn.Document; +import com.googlecode.opennars.parser.loan.Loan.Absyn.ListIdent; +import com.googlecode.opennars.parser.loan.Loan.Absyn.ListTerm; +import com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl; +import com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse; +import com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt; +import com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar; +import com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn; +import com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD; +import com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI; +import com.googlecode.opennars.parser.loan.Loan.Absyn.LitString; +import com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue; +import com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI; +import com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1; +import com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2; +import com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay; +import com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal; +import com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport; +import com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge; +import com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp; +import com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix; +import com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest; +import com.googlecode.opennars.parser.loan.Loan.Absyn.Stm; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim; +import com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF; +import com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC; +import com.googlecode.opennars.parser.loan.Loan.Absyn.URICur; +import com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul; + +public class LoanParser extends Parser { + + public class SerialiseVisitor implements TermVisitor<Object,LoanParser> { + + /** + * If the provided object is a term, wrap it in a StmTrm object + * @param o the object to (potentially) wrap + * @return the wrapped object + */ + private Stm wrapTerm(Object o) { + if(o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.Term) { + return new StmTrm((com.googlecode.opennars.parser.loan.Loan.Absyn.Term) o); + } + else + return (Stm) o; + } + + /** + * If the provided object is a statement, wrap it in a TrmStm object + * @param o the object to (potentially) wrap + * @return the wrapped object + */ + private com.googlecode.opennars.parser.loan.Loan.Absyn.Term wrapStatement(Object o) { + if(o instanceof com.googlecode.opennars.parser.loan.Loan.Absyn.Stm) { + return new TrmStm((com.googlecode.opennars.parser.loan.Loan.Absyn.Stm) o); + } + else + return (com.googlecode.opennars.parser.loan.Loan.Absyn.Term) o; + } + + public Object visit(Term p, LoanParser arg) { + // TODO: Fix this awful ladder. I wish Java had a more dynamic invocation procedure like Smalltalk or Objective-C + if(p instanceof BooleanLiteral) + return visit((BooleanLiteral) p, arg); + if(p instanceof Conjunction) + return visit((Conjunction) p, arg); + if(p instanceof ConjunctionParallel) + return visit((ConjunctionParallel) p, arg); + if(p instanceof ConjunctionSequence) + return visit((ConjunctionSequence) p, arg); + if(p instanceof DifferenceExt) + return visit((DifferenceExt) p, arg); + if(p instanceof DifferenceInt) + return visit((DifferenceInt) p, arg); + if(p instanceof Disjunction) + return visit((Disjunction) p, arg); + if(p instanceof Equivalence) + return visit((Equivalence) p, arg); + if(p instanceof EquivalenceAfter) + return visit((EquivalenceAfter) p, arg); + if(p instanceof EquivalenceWhen) + return visit((EquivalenceWhen) p, arg); + if(p instanceof ImageExt) + return visit((ImageExt) p, arg); + if(p instanceof ImageInt) + return visit((ImageInt) p, arg); + if(p instanceof Implication) + return visit((Implication) p, arg); + if(p instanceof ImplicationAfter) + return visit((ImplicationAfter) p, arg); + if(p instanceof ImplicationBefore) + return visit((ImplicationBefore) p, arg); + if(p instanceof ImplicationWhen) + return visit((ImplicationWhen) p, arg); + if(p instanceof Inheritance) + return visit((Inheritance) p, arg); + if(p instanceof Instance) + return visit((Instance) p, arg); + if(p instanceof InstanceProperty) + return visit((InstanceProperty) p, arg); + if(p instanceof IntersectionExt) + return visit((IntersectionExt) p, arg); + if(p instanceof IntersectionInt) + return visit((IntersectionInt) p, arg); + if(p instanceof Negation) + return visit((Negation) p, arg); + if(p instanceof NumericLiteral) + return visit((NumericLiteral) p, arg); + if(p instanceof Product) + return visit((Product) p, arg); + if(p instanceof Property) + return visit((Property) p, arg); + if(p instanceof SetExt) + return visit((SetExt) p, arg); + if(p instanceof SetInt) + return visit((SetInt) p, arg); + if(p instanceof Similarity) + return visit((Similarity) p, arg); + if(p instanceof TenseFuture) + return visit((TenseFuture) p, arg); + if(p instanceof TensePast) + return visit((TensePast) p, arg); + if(p instanceof TensePresent) + return visit((TensePresent) p, arg); + if(p instanceof URIRef) + return visit((URIRef) p, arg); + if(p instanceof Variable) + return visit((Variable) p, arg); + + return new TrmLit(new LitString(p.getName())); + } + + public Object visit(BooleanLiteral p, LoanParser arg) { + if(p.getName().equals("true")) + return new TrmLit(new LitTrue()); + else + return new TrmLit(new LitFalse()); + } + + public Object visit(Conjunction p, LoanParser arg) { + ArrayList<Term> components = p.getComponents(); + Iterator<Term> iter = components.iterator(); + Term t = iter.next(); + Stm s = wrapTerm(t.accept(this, arg)); + while(iter.hasNext()) { + s = new StmConj(s, wrapTerm(iter.next().accept(this, arg))); + } + return s; + } + + public Object visit(ConjunctionParallel p, LoanParser arg) { + ArrayList<Term> components = p.getComponents(); + Iterator<Term> iter = components.iterator(); + Term t = iter.next(); + Stm s = wrapTerm(t.accept(this, arg)); + while(iter.hasNext()) { + s = new StmPar(s, wrapTerm(iter.next().accept(this, arg))); + } + return s; + } + + public Object visit(ConjunctionSequence p, LoanParser arg) { + ArrayList<Term> components = p.getComponents(); + Iterator<Term> iter = components.iterator(); + Term t = iter.next(); + Stm s = wrapTerm(t.accept(this, arg)); + while(iter.hasNext()) { + s = new StmSeq(s, wrapTerm(iter.next().accept(this, arg))); + } + return s; + } + + public Object visit(DifferenceExt p, LoanParser arg) { + ArrayList<Term> components = p.getComponents(); + Term t1 = components.get(0); + Term t2 = components.get(1); + return new TrmExDif(wrapStatement(t1.accept(this, arg)), wrapStatement(t2.accept(this, arg))); + } + + public Object visit(DifferenceInt p, LoanParser arg) { + ArrayList<Term> components = p.getComponents(); + Term t1 = components.get(0); + Term t2 = components.get(1); + return new TrmInDif(wrapStatement(t1.accept(this, arg)), wrapStatement(t2.accept(this, arg))); + } + + public Object visit(Disjunction p, LoanParser arg) { + ArrayList<Term> components = p.getComponents(); + Iterator<Term> iter = components.iterator(); + Term t = iter.next(); + Stm s = wrapTerm(t.accept(this, arg)); + while(iter.hasNext()) { + s = new StmDisj(s, wrapTerm(iter.next().accept(this, arg))); + } + return s; + } + + public Object visit(Equivalence p, LoanParser arg) { + Stm subj = wrapTerm(p.getSubject().accept(this, arg)); + Stm pred = wrapTerm(p.getPredicate().accept(this, arg)); + return new StmEquiv(subj,pred); + } + + public Object visit(EquivalenceAfter p, LoanParser arg) { + Stm subj = wrapTerm(p.getSubject().accept(this, arg)); + Stm pred = wrapTerm(p.getPredicate().accept(this, arg)); + return new StmEqvPred(subj,pred); + } + + public Object visit(EquivalenceWhen p, LoanParser arg) { + Stm subj = wrapTerm(p.getSubject().accept(this, arg)); + Stm pred = wrapTerm(p.getPredicate().accept(this, arg)); + return new StmEqvConc(subj,pred); + } + + public Object visit(ImageExt p, LoanParser arg) { + List<Term> pre = p.getComponents().subList(0, p.getRelationIndex()); + Term reln = p.getComponents().get(p.getRelationIndex()); + List<Term> post = p.getComponents().subList(p.getRelationIndex() + 1, p.size()); + + com.googlecode.opennars.parser.loan.Loan.Absyn.Term relnT = wrapStatement(reln.accept(this, arg)); + + ListTerm preList = new ListTerm(); + Iterator<Term> iter = pre.iterator(); + while(iter.hasNext()) { + preList.add(wrapStatement(iter.next().accept(this, arg))); + } + + ListTerm postList = new ListTerm(); + iter = post.iterator(); + while(iter.hasNext()) { + postList.add(wrapStatement(iter.next().accept(this, arg))); + } + + return new TrmExImg(relnT, preList, postList); + } + + public Object visit(ImageInt p, LoanParser arg) { + List<Term> pre = p.getComponents().subList(0, p.getRelationIndex()); + Term reln = p.getComponents().get(p.getRelationIndex()); + List<Term> post = p.getComponents().subList(p.getRelationIndex() + 1, p.size()); + + com.googlecode.opennars.parser.loan.Loan.Absyn.Term relnT = wrapStatement(reln.accept(this, arg)); + + ListTerm preList = new ListTerm(); + Iterator<Term> iter = pre.iterator(); + while(iter.hasNext()) { + preList.add(wrapStatement(iter.next().accept(this, arg))); + } + + ListTerm postList = new ListTerm(); + iter = post.iterator(); + while(iter.hasNext()) { + postList.add(wrapStatement(iter.next().accept(this, arg))); + } + + return new TrmInImg(relnT, preList, postList); + } + + public Object visit(Implication p, LoanParser arg) { + Stm subj = wrapTerm(p.getSubject().accept(this, arg)); + Stm pred = wrapTerm(p.getPredicate().accept(this, arg)); + return new StmImpl(subj,pred); + } + + public Object visit(ImplicationAfter p, LoanParser arg) { + Stm subj = wrapTerm(p.getSubject().accept(this, arg)); + Stm pred = wrapTerm(p.getPredicate().accept(this, arg)); + return new StmImpPred(subj,pred); + } + + public Object visit(ImplicationBefore p, LoanParser arg) { + Stm subj = wrapTerm(p.getSubject().accept(this, arg)); + Stm pred = wrapTerm(p.getPredicate().accept(this, arg)); + return new StmImpRet(subj,pred); + } + + public Object visit(ImplicationWhen p, LoanParser arg) { + Stm subj = wrapTerm(p.getSubject().accept(this, arg)); + Stm pred = wrapTerm(p.getPredicate().accept(this, arg)); + return new StmImpConc(subj,pred); + } + + public Object visit(Inheritance p, LoanParser arg) { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term subj = wrapStatement(p.getSubject().accept(this, arg)); + com.googlecode.opennars.parser.loan.Loan.Absyn.Term pred = wrapStatement(p.getPredicate().accept(this, arg)); + return new StmInher(subj,pred); + } + + public Object visit(Instance p, LoanParser arg) { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term subj = wrapStatement(p.getSubject().accept(this, arg)); + com.googlecode.opennars.parser.loan.Loan.Absyn.Term pred = wrapStatement(p.getPredicate().accept(this, arg)); + return new StmInst(subj,pred); + } + + public Object visit(InstanceProperty p, LoanParser arg) { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term subj = wrapStatement(p.getSubject().accept(this, arg)); + com.googlecode.opennars.parser.loan.Loan.Absyn.Term pred = wrapStatement(p.getPredicate().accept(this, arg)); + return new StmInPp(subj,pred); + } + + public Object visit(IntersectionExt p, LoanParser arg) { + ArrayList<Term> components = p.getComponents(); + Iterator<Term> iter = components.iterator(); + Term t = iter.next(); + com.googlecode.opennars.parser.loan.Loan.Absyn.Term s = wrapStatement(t.accept(this, arg)); + while(iter.hasNext()) { + s = new TrmExInt(s, wrapStatement(iter.next().accept(this, arg))); + } + return s; + } + + public Object visit(IntersectionInt p, LoanParser arg) { + ArrayList<Term> components = p.getComponents(); + Iterator<Term> iter = components.iterator(); + Term t = iter.next(); + com.googlecode.opennars.parser.loan.Loan.Absyn.Term s = wrapStatement(t.accept(this, arg)); + while(iter.hasNext()) { + s = new TrmInInt(s, wrapStatement(iter.next().accept(this, arg))); + } + return s; + } + + public Object visit(Negation p, LoanParser arg) { + Stm s = wrapTerm(p.getComponents().get(0).accept(this, arg)); + return new StmNot(s); + } + + public Object visit(NumericLiteral p, LoanParser arg) { + if(p.getType() == NumericLiteral.TYPE.INTEGER) + return new TrmLit(new LitInt(Integer.parseInt(p.getName()))); + else if(p.getType() == NumericLiteral.TYPE.DOUBLE) + return new TrmLit(new LitDbl(Double.parseDouble(p.getName()))); + else + return null; + } + + public Object visit(Product p, LoanParser arg) { + Iterator<Term> iter = p.getComponents().iterator(); + ListTerm ts = new ListTerm(); + while(iter.hasNext()) { + ts.add(wrapStatement(iter.next().accept(this, arg))); + } + return new TrmProd(ts); + } + + public Object visit(Property p, LoanParser arg) { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term subj = wrapStatement(p.getSubject().accept(this, arg)); + com.googlecode.opennars.parser.loan.Loan.Absyn.Term pred = wrapStatement(p.getPredicate().accept(this, arg)); + return new StmProp(subj,pred); + } + + public Object visit(SetExt p, LoanParser arg) { + Iterator<Term> iter = p.getComponents().iterator(); + ListTerm ts = new ListTerm(); + while(iter.hasNext()) { + ts.add(wrapStatement(iter.next().accept(this, arg))); + } + return new TrmExSet(ts); + } + + public Object visit(SetInt p, LoanParser arg) { + Iterator<Term> iter = p.getComponents().iterator(); + ListTerm ts = new ListTerm(); + while(iter.hasNext()) { + ts.add(wrapStatement(iter.next().accept(this, arg))); + } + return new TrmInSet(ts); + } + + public Object visit(Similarity p, LoanParser arg) { + com.googlecode.opennars.parser.loan.Loan.Absyn.Term subj = wrapStatement(p.getSubject().accept(this, arg)); + com.googlecode.opennars.parser.loan.Loan.Absyn.Term pred = wrapStatement(p.getPredicate().accept(this, arg)); + return new StmSim(subj,pred); + } + + public Object visit(TenseFuture p, LoanParser arg) { + Stm s = wrapTerm(p.getComponents().get(0).accept(this, arg)); + return new StmFut(s); + } + + public Object visit(TensePast p, LoanParser arg) { + Stm s = wrapTerm(p.getComponents().get(0).accept(this, arg)); + return new StmPst(s); + } + + public Object visit(TensePresent p, LoanParser arg) { + Stm s = wrapTerm(p.getComponents().get(0).accept(this, arg)); + return new StmPres(s); + } + + public Object visit(StringLiteral p, LoanParser arg) { + return new TrmLit(new LitString(p.getName())); + } + + public Object visit(URIRef p, LoanParser arg) { + String uriref = p.getName(); + // Try namespaces first + Iterator<String> iter = arg.getNamespaces().keySet().iterator(); + while(iter.hasNext()) { + String pre = iter.next(); + URI u = arg.getNamespaces().get(pre); + // Can we match the start of the URI to any known sequence? + if(uriref.startsWith(u.toString())) { + // Blank prefix is dealt with separately in the abstract syntax for parsing reasons + if(u.equals("")) + return new TrmLit(new LitURI(new URICur(new NSPrefix2(), uriref.substring(u.toString().length())))); + else + return new TrmLit(new LitURI(new URICur(new NSPrefix1(pre), uriref.substring(u.toString().length())))); + } + } + + try { + // Try resolving against the base + URI b = arg.getBaseURI(); + URI r = b.relativize(new URI(uriref)); + return new TrmLit(new LitURI(new URIFul("<" + r.toString() + ">"))); + } + catch (URISyntaxException e) { + e.printStackTrace(); + } + return new TrmLit(new LitURI(new URIFul("<" + p.getName() + ">"))); + } + + public Object visit(Variable p, LoanParser arg) { + if(p.getType() == Variable.VarType.QUERY) + return new TrmLit(new LitQVar(p.getName().substring(1))); + else if(p.getType() == Variable.VarType.INDEPENDENT) + return new TrmLit(new LitSVarI(p.getName().substring(1))); + else if(p.getType() == Variable.VarType.DEPENDENT) + return new TrmLit(new LitSVarD(p.getName().substring(1), new ListIdent())); + else if(p.getType() == Variable.VarType.ANONYMOUS) + return new TrmLit(new LitQVarAn()); + else + return null; + } + + } + + public class ParserVisitor extends AbstractVisitor<Object, LoanParser> { + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR, java.lang.Object) + */ + @Override + public Object visit(BaseR p, LoanParser arg) { + try { + arg.setBaseURI(new URI(p.urilit_.substring(1, p.urilit_.length()-1))); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return null; + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.Doc, java.lang.Object) + */ + @Override + public Object visit(Doc p, LoanParser arg) { + List<Task> tasks = new ArrayList<Task>(); + Iterator<com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence> iter = p.listsentence_.iterator(); + while(iter.hasNext()) { + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence s = iter.next(); + Object t = s.accept(this, arg); + if(t != null) { + if(t instanceof List) // Should only happen with an @import + tasks.addAll((Collection<? extends Task>) t); + else + tasks.add((Task) t); + } + } + return tasks; + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.DocBR, java.lang.Object) + */ + @Override + public Object visit(DocBR p, LoanParser arg) { + p.baserule_.accept(this, arg); + List<Task> tasks = new ArrayList<Task>(); + Iterator<com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence> iter = p.listsentence_.iterator(); + while(iter.hasNext()) { + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence s = iter.next(); + Task t = (Task) s.accept(this, arg); + if(t != null) + tasks.add(t); + } + return tasks; + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitDbl, java.lang.Object) + */ + @Override + public Object visit(LitDbl p, LoanParser arg) { + return new NumericLiteral(p.double_.doubleValue()); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitFalse, java.lang.Object) + */ + @Override + public Object visit(LitFalse p, LoanParser arg) { + return new BooleanLiteral(false); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitInt, java.lang.Object) + */ + @Override + public Object visit(LitInt p, LoanParser arg) { + return new NumericLiteral(p.integer_.intValue()); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVar, java.lang.Object) + */ + @Override + public Object visit(LitQVar p, LoanParser arg) { + return new Variable("" + Symbols.QUERY_VARIABLE_TAG + p.ident_); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitQVarAn, java.lang.Object) + */ + @Override + public Object visit(LitQVarAn p, LoanParser arg) { + return new Variable("" + Symbols.QUERY_VARIABLE_TAG); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitString, java.lang.Object) + */ + @Override + public Object visit(LitString p, LoanParser arg) { + // TODO Auto-generated method stub + return new StringLiteral(p.string_); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarD, java.lang.Object) + */ + @Override + public Object visit(LitSVarD p, LoanParser arg) { + StringBuilder builder = new StringBuilder(); + builder.append(Symbols.VARIABLE_TAG); + builder.append(p.ident_); + builder.append(Symbols.COMPOUND_TERM_OPENER); + Iterator<String> iter = p.listident_.iterator(); + while(iter.hasNext()) { + builder.append(iter.next()); + if(iter.hasNext()) + builder.append(","); + } + builder.append(Symbols.COMPOUND_TERM_CLOSER); + return new Variable(builder.toString()); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitSVarI, java.lang.Object) + */ + @Override + public Object visit(LitSVarI p, LoanParser arg) { + return new Variable("" + Symbols.VARIABLE_TAG + p.ident_); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitTrue, java.lang.Object) + */ + @Override + public Object visit(LitTrue p, LoanParser arg) { + return new BooleanLiteral(true); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.LitURI, java.lang.Object) + */ + @Override + public Object visit(LitURI p, LoanParser arg) { + URI u = (URI) p.uriref_.accept(this, arg); + return new URIRef(u); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix1, java.lang.Object) + */ + @Override + public Object visit(NSPrefix1 p, LoanParser arg) { + // TODO Auto-generated method stub + return p.ident_; + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.NSPrefix2, java.lang.Object) + */ + @Override + public Object visit(NSPrefix2 p, LoanParser arg) { + // TODO Auto-generated method stub + return ""; + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentDelay, java.lang.Object) + */ + @Override + public Object visit(SentDelay p, LoanParser arg) { + int delay = p.integer_.intValue(); + for(int i = 0; i < delay; i++) + arg.getMemory().cycle(); + return null; + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal, java.lang.Object) + */ + @Override + public Object visit(SentGoal p, LoanParser arg) { + // Get the truth + TruthValue truth = (TruthValue) p.truthvalue_.accept(this, arg); + + // We don't actually do budget values (yet) in LOAN + float priority = memory.getParameters().DEFAULT_GOAL_PRIORITY; + float durability = memory.getParameters().DEFAULT_GOAL_DURABILITY; + float quality = memory.budgetfunctions.truthToQuality(truth); + BudgetValue budget = new BudgetValue(priority, durability, quality, memory); + + // Process the sentence itself + Term content = (Term) p.stm_.accept(this, arg); + Base base = new Base(); + Sentence sentence = Sentence.make(content, Symbols.GOAL_MARK, truth, base, memory); + sentence.setInput(); + + return new Task(sentence, budget, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentImport, java.lang.Object) + */ + @Override + public Object visit(SentImport p, LoanParser arg) { + try { + URL u = new URL(p.urilit_.substring(1, p.urilit_.length()-1)); + BufferedReader reader = new BufferedReader(new InputStreamReader(u.openStream())); + StringBuilder builder = new StringBuilder(); + String line = ""; + while(line != null) { + builder.append(line); + builder.append("\n"); + line = reader.readLine(); + } + + LoanParser parser = new LoanParser(); + parser.setBaseURI(u.toURI()); + List<Task> ts = parser.parseTasks(builder.toString(), memory); + return ts; + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } catch (InvalidInputException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge, java.lang.Object) + */ + @Override + public Object visit(SentJudge p, LoanParser arg) { + // Get the truth + TruthValue truth = (TruthValue) p.truthvalue_.accept(this, arg); + + // We don't actually do budget values (yet) in LOAN + float priority = memory.getParameters().DEFAULT_JUDGMENT_PRIORITY; + float durability = memory.getParameters().DEFAULT_JUDGMENT_DURABILITY; + float quality = memory.budgetfunctions.truthToQuality(truth); + BudgetValue budget = new BudgetValue(priority, durability, quality, memory); + + // Process the sentence itself + Term content = (Term) p.stm_.accept(this, arg); + Base base = new Base(); + Sentence sentence = Sentence.make(content, Symbols.JUDGMENT_MARK, truth, base, memory); + sentence.setInput(); + + return new Task(sentence, budget, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentOp, java.lang.Object) + */ + @Override + public Object visit(SentOp p, LoanParser arg) { + // TODO Handle the adding of operators once we can do something with them + return null; + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentPrefix, java.lang.Object) + */ + @Override + public Object visit(SentPrefix p, LoanParser arg) { + String pre = (String) p.nsprefix_.accept(this, arg); + try { + URI u = new URI(p.urilit_.substring(1, p.urilit_.length()-1)); + arg.getNamespaces().put(pre, u); + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest, java.lang.Object) + */ + @Override + public Object visit(SentQuest p, LoanParser arg) { + // Questions don't have truth + TruthValue truth = null; + + // We don't actually do budget values (yet) in LOAN + float priority = memory.getParameters().DEFAULT_QUESTION_PRIORITY; + float durability = memory.getParameters().DEFAULT_QUESTION_DURABILITY; + float quality = 1; + BudgetValue budget = new BudgetValue(priority, durability, quality, memory); + + // Process the sentence itself + Term content = (Term) p.stm_.accept(this, arg); + Base base = null; + Sentence sentence = Sentence.make(content, Symbols.QUESTION_MARK, truth, base, memory); + sentence.setInput(); + + // ++DEBUG + System.out.println(sentence.toString2()); + // --DEBUG + + return new Task(sentence, budget, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmConj, java.lang.Object) + */ + @Override + public Object visit(StmConj p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + ts.add(t2); + + return CompoundTerm.make(Symbols.CONJUNCTION_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmDisj, java.lang.Object) + */ + @Override + public Object visit(StmDisj p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + ts.add(t2); + + return CompoundTerm.make(Symbols.DISJUNCTION_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEquiv, java.lang.Object) + */ + @Override + public Object visit(StmEquiv p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + ts.add(t2); + + return Statement.make(Symbols.EQUIVALENCE_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvConc, java.lang.Object) + */ + @Override + public Object visit(StmEqvConc p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + ts.add(t2); + + return Statement.make(Symbols.EQUIVALENCE_WHEN_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmEqvPred, java.lang.Object) + */ + @Override + public Object visit(StmEqvPred p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + + return Statement.make(Symbols.EQUIVALENCE_AFTER_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmFut, java.lang.Object) + */ + @Override + public Object visit(StmFut p, LoanParser arg) { + Term t1 = (Term) p.stm_.accept(this, arg); + + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + + return CompoundTerm.make(Symbols.FUTURE_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpConc, java.lang.Object) + */ + @Override + public Object visit(StmImpConc p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + + return Statement.make(Symbols.IMPLICATION_WHEN_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpl, java.lang.Object) + */ + @Override + public Object visit(StmImpl p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + + return Statement.make(Symbols.IMPLICATION_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpPred, java.lang.Object) + */ + @Override + public Object visit(StmImpPred p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + + return Statement.make(Symbols.IMPLICATION_AFTER_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmImpRet, java.lang.Object) + */ + @Override + public Object visit(StmImpRet p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + + return Statement.make(Symbols.IMPLICATION_BEFORE_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInher, java.lang.Object) + */ + @Override + public Object visit(StmInher p, LoanParser arg) { + Term t1 = (Term) p.term_1.accept(this, arg); + Term t2 = (Term) p.term_2.accept(this, arg); + + return Statement.make(Symbols.INHERITANCE_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInPp, java.lang.Object) + */ + @Override + public Object visit(StmInPp p, LoanParser arg) { + Term t1 = (Term) p.term_1.accept(this, arg); + Term t2 = (Term) p.term_2.accept(this, arg); + + return Statement.make(Symbols.INSTANCE_PROPERTY_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmInst, java.lang.Object) + */ + @Override + public Object visit(StmInst p, LoanParser arg) { + Term t1 = (Term) p.term_1.accept(this, arg); + Term t2 = (Term) p.term_2.accept(this, arg); + + return Statement.make(Symbols.INSTANCE_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmNot, java.lang.Object) + */ + @Override + public Object visit(StmNot p, LoanParser arg) { + Term t1 = (Term) p.stm_.accept(this, arg); + + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + + return CompoundTerm.make(Symbols.NEGATION_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmOp, java.lang.Object) + */ + @Override + public Object visit(StmOp p, LoanParser arg) { + // Get the functor + Term t1 = (Term) p.term_.accept(this, arg); + + // Get the arguments + ArrayList<Term> opargs = new ArrayList<Term>(); + Iterator<com.googlecode.opennars.parser.loan.Loan.Absyn.Term> iter = p.listterm_.iterator(); + while(iter.hasNext()) { + Term t = (Term) iter.next().accept(this, arg); + opargs.add(t); + } + + // Make arguments into a product + Term prod = CompoundTerm.make(Symbols.PRODUCT_OPERATOR, opargs, memory); + + return Statement.make(Symbols.INHERITANCE_RELATION, prod, t1, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPar, java.lang.Object) + */ + @Override + public Object visit(StmPar p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + ts.add(t2); + + return CompoundTerm.make(Symbols.PARALLEL_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPres, java.lang.Object) + */ + @Override + public Object visit(StmPres p, LoanParser arg) { + Term t1 = (Term) p.stm_.accept(this, arg); + + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + + return CompoundTerm.make(Symbols.PRESENT_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmProp, java.lang.Object) + */ + @Override + public Object visit(StmProp p, LoanParser arg) { + Term t1 = (Term) p.term_1.accept(this, arg); + Term t2 = (Term) p.term_2.accept(this, arg); + + return Statement.make(Symbols.PROPERTY_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmPst, java.lang.Object) + */ + @Override + public Object visit(StmPst p, LoanParser arg) { + Term t1 = (Term) p.stm_.accept(this, arg); + + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + + return CompoundTerm.make(Symbols.PAST_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSeq, java.lang.Object) + */ + @Override + public Object visit(StmSeq p, LoanParser arg) { + Term t1 = (Term) p.stm_1.accept(this, arg); + Term t2 = (Term) p.stm_2.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + ts.add(t2); + + return CompoundTerm.make(Symbols.SEQUENCE_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmSim, java.lang.Object) + */ + @Override + public Object visit(StmSim p, LoanParser arg) { + Term t1 = (Term) p.term_1.accept(this, arg); + Term t2 = (Term) p.term_2.accept(this, arg); + + return Statement.make(Symbols.SIMILARITY_RELATION, t1, t2, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.StmTrm, java.lang.Object) + */ + @Override + public Object visit(StmTrm p, LoanParser arg) { + return p.term_.accept(this, arg); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExDif, java.lang.Object) + */ + @Override + public Object visit(TrmExDif p, LoanParser arg) { + Term t1 = (Term) p.term_1.accept(this, arg); + Term t2 = (Term) p.term_2.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + ts.add(t2); + + return CompoundTerm.make(Symbols.DIFFERENCE_EXT_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExImg, java.lang.Object) + */ + @Override + public Object visit(TrmExImg p, LoanParser arg) { + Term reln = (Term) p.term_.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(reln); + + Iterator<com.googlecode.opennars.parser.loan.Loan.Absyn.Term> iter = p.listterm_1.iterator(); + while(iter.hasNext()) + ts.add((Term) iter.next().accept(this, arg)); + ts.add(new Term("" + Symbols.IMAGE_PLACE_HOLDER)); + iter = p.listterm_2.iterator(); + while(iter.hasNext()) + ts.add((Term) iter.next().accept(this, arg)); + + return CompoundTerm.make(Symbols.IMAGE_EXT_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExInt, java.lang.Object) + */ + @Override + public Object visit(TrmExInt p, LoanParser arg) { + Term t1 = (Term) p.term_1.accept(this, arg); + Term t2 = (Term) p.term_2.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + ts.add(t2); + + return CompoundTerm.make(Symbols.INTERSECTION_EXT_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmExSet, java.lang.Object) + */ + @Override + public Object visit(TrmExSet p, LoanParser arg) { + ArrayList<Term> ts = new ArrayList<Term>(); + Iterator<com.googlecode.opennars.parser.loan.Loan.Absyn.Term> iter = p.listterm_.iterator(); + while(iter.hasNext()) { + Term t = (Term) iter.next().accept(this, arg); + ts.add(t); + } + + return SetExt.make(ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInDif, java.lang.Object) + */ + @Override + public Object visit(TrmInDif p, LoanParser arg) { + Term t1 = (Term) p.term_1.accept(this, arg); + Term t2 = (Term) p.term_2.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + ts.add(t2); + + return CompoundTerm.make(Symbols.DIFFERENCE_INT_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInImg, java.lang.Object) + */ + @Override + public Object visit(TrmInImg p, LoanParser arg) { + Term reln = (Term) p.term_.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(reln); + + Iterator<com.googlecode.opennars.parser.loan.Loan.Absyn.Term> iter = p.listterm_1.iterator(); + while(iter.hasNext()) + ts.add((Term) iter.next().accept(this, arg)); + ts.add(new Term("" + Symbols.IMAGE_PLACE_HOLDER)); + iter = p.listterm_2.iterator(); + while(iter.hasNext()) + ts.add((Term) iter.next().accept(this, arg)); + + return CompoundTerm.make(Symbols.IMAGE_INT_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInInt, java.lang.Object) + */ + @Override + public Object visit(TrmInInt p, LoanParser arg) { + Term t1 = (Term) p.term_1.accept(this, arg); + Term t2 = (Term) p.term_2.accept(this, arg); + ArrayList<Term> ts = new ArrayList<Term>(); + ts.add(t1); + ts.add(t2); + + return CompoundTerm.make(Symbols.INTERSECTION_INT_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmInSet, java.lang.Object) + */ + @Override + public Object visit(TrmInSet p, LoanParser arg) { + ArrayList<Term> ts = new ArrayList<Term>(); + Iterator<com.googlecode.opennars.parser.loan.Loan.Absyn.Term> iter = p.listterm_.iterator(); + while(iter.hasNext()) { + Term t = (Term) iter.next().accept(this, arg); + ts.add(t); + } + + return SetInt.make(ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmLit, java.lang.Object) + */ + @Override + public Object visit(TrmLit p, LoanParser arg) { + return p.literal_.accept(this, arg); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmProd, java.lang.Object) + */ + @Override + public Object visit(TrmProd p, LoanParser arg) { + ArrayList<Term> ts = new ArrayList<Term>(); + Iterator<com.googlecode.opennars.parser.loan.Loan.Absyn.Term> iter = p.listterm_.iterator(); + while(iter.hasNext()) { + Term t = (Term) iter.next().accept(this, arg); + ts.add(t); + } + + return CompoundTerm.make(Symbols.PRODUCT_OPERATOR, ts, memory); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TrmStm, java.lang.Object) + */ + @Override + public Object visit(TrmStm p, LoanParser arg) { + return p.stm_.accept(this, arg); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthE, java.lang.Object) + */ + @Override + public Object visit(TruthE p, LoanParser arg) { + return new TruthValue(1, memory.getParameters().DEFAULT_JUDGMENT_CONFIDENCE); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthF, java.lang.Object) + */ + @Override + public Object visit(TruthF p, LoanParser arg) { + return new TruthValue(p.double_.floatValue(), memory.getParameters().DEFAULT_JUDGMENT_CONFIDENCE); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC, java.lang.Object) + */ + @Override + public Object visit(TruthFC p, LoanParser arg) { + return new TruthValue(p.double_1.floatValue(),p.double_2.floatValue()); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URICur, java.lang.Object) + */ + @Override + public Object visit(URICur p, LoanParser arg) { + String pre = (String) p.nsprefix_.accept(this, arg); + URI u = arg.getNamespaces().get(pre); + return u.resolve(p.ident_); + } + + /* (non-Javadoc) + * @see com.googlecode.opennars.parser.loan.Loan.AbstractVisitor#visit(com.googlecode.opennars.parser.loan.Loan.Absyn.URIFul, java.lang.Object) + */ + @Override + public Object visit(URIFul p, LoanParser arg) { + URI base = arg.getBaseURI(); + String u = p.urilit_.substring(1, p.urilit_.length()-1); + return base.resolve(u); + } + + } + + private Map<String,URI> namespaces = new HashMap<String,URI>(); + private URI baseURI = null; + private Memory memory = null; + + @Override + public Task parseTask(String input, Memory memory) + throws InvalidInputException { + this.memory = memory; + List<Task> tasks = null; + Yylex l = new Yylex(new StringReader(input)); + parser p = new parser(l); + try { + Document parse_tree = p.pDocument(); + tasks = (List<Task>) parse_tree.accept(new ParserVisitor(), this); + } catch (Exception e) { + e.printStackTrace(); + throw new InvalidInputException(); + } + if(tasks.size() > 0) + return tasks.get(0); + else + return null; + } + + @Override + public List<Task> parseTasks(String input, Memory memory) + throws InvalidInputException { + this.memory = memory; + List<Task> tasks = null; + Yylex l = new Yylex(new StringReader(input)); + parser p = new parser(l); + try { + Document parse_tree = p.pDocument(); + tasks = (List<Task>) parse_tree.accept(new ParserVisitor(), this); + } catch (Exception e) { + e.printStackTrace(); + throw new InvalidInputException(); + } + + return tasks; + } + + @Override + public String serialiseSentence(Sentence task, Memory memory) { + com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence ss = new com.googlecode.opennars.parser.loan.Loan.Absyn.ListSentence(); + com.googlecode.opennars.parser.loan.Loan.Absyn.Sentence s; + com.googlecode.opennars.parser.loan.Loan.Absyn.Stm stm = (Stm) ((CompoundTerm) task.getContent()).accept(new SerialiseVisitor(), this); + if(task.isJudgment()) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue tv = new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC(Double.valueOf(task.getTruth().getFrequency()), Double.valueOf(task.getTruth().getConfidence())); + s = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentJudge(stm, tv); + ss.add(s); + } + else if(task.isQuestion()) { + s = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentQuest(stm); + ss.add(s); + } + else if(task.isGoal()) { + com.googlecode.opennars.parser.loan.Loan.Absyn.TruthValue tv = new com.googlecode.opennars.parser.loan.Loan.Absyn.TruthFC(Double.valueOf(task.getTruth().getFrequency()), Double.valueOf(task.getTruth().getConfidence())); + s = new com.googlecode.opennars.parser.loan.Loan.Absyn.SentGoal(stm, tv); + ss.add(s); + } + + com.googlecode.opennars.parser.loan.Loan.Absyn.Doc doc = new Doc(ss); + return PrettyPrinter.print(doc).replace('\n', ' '); + } + + @Override + public String serialiseSentences(List<Sentence> tasks, Memory memory) { + // TODO: Write this method + com.googlecode.opennars.parser.loan.Loan.Absyn.BaseRule br = new com.googlecode.opennars.parser.loan.Loan.Absyn.BaseR(this.getBaseURI().toString()); + return null; + } + + /** + * @return the memory + */ + public Memory getMemory() { + return memory; + } + + /** + * @param memory the memory to set + */ + public void setMemory(Memory memory) { + this.memory = memory; + } + + /** + * @return the namespaces + */ + public Map<String, URI> getNamespaces() { + return namespaces; + } + + /** + * @param namespaces the namespaces to set + */ + public void setNamespaces(Map<String, URI> namespaces) { + this.namespaces = namespaces; + } + + /** + * @return the base URI + */ + public URI getBaseURI() { + return baseURI; + } + + /** + * @param baseURI the base URI to set + */ + public void setBaseURI(URI baseURI) { + this.baseURI = baseURI; + } + +} diff --git a/open-nars/com/googlecode/opennars/parser/loan/loan.g b/open-nars/com/googlecode/opennars/parser/loan/loan.g index e76fa96af9beb65a0d3da0deeccb6e5206963036..604a9a87e10d2aaee4a351e17180e5c70dda7689 100644 --- a/open-nars/com/googlecode/opennars/parser/loan/loan.g +++ b/open-nars/com/googlecode/opennars/parser/loan/loan.g @@ -4,6 +4,17 @@ options { output = AST; } +tokens { + NUM_LIT = 'numeric'; + BOOL_LIT = 'boolean'; + STRING_LIT = 'string'; + URI = 'uri'; + CURIE = 'curie'; + PRODUCT = 'product'; + JUDGEMENT = 'judgement'; + GOAL = 'goal'; +} + // $<Parser document @@ -19,7 +30,10 @@ at_rule : AT_IMPORT^ IRI_REF DOT! ; sentence - : statement (judgement^|question^|goal^) + : statement ( judgement + | question + | goal + ) ; judgement @@ -34,7 +48,7 @@ question ; truthvalue - : PERCENT! (DECIMAL | INTEGER) (SEMICOLON DECIMAL)? PERCENT!; + : PERCENT^ (DECIMAL | INTEGER) (SEMICOLON! DECIMAL)? PERCENT!; statement : unary_statement ((CONJ^ | SEMICOLON^ | COMMA^ | DISJ^) unary_statement)* @@ -62,16 +76,31 @@ ext_set : OPEN_BRACE^ (term (COMMA! term)*)? CLOSE_BRACE! int_set : LBRACKET^ (term (COMMA! term)*)? RBRACKET! ; +ext_image + : EXT_IMG^ LPAREN! term COMMA! term_or_wild (COMMA! term_or_wild)* RPAREN! + ; + +int_image + : INT_IMG^ LPAREN! term COMMA! term_or_wild (COMMA! term_or_wild)* RPAREN! + ; + +term_or_wild + : WILDCARD + | term + ; + difference : product ((MINUS^ | TILDE^) product)* ; -product : atomic_term (STAR^ atomic_term)* +product : atomic_term (STAR atomic_term)* -> ^(PRODUCT atomic_term*) ; atomic_term : ext_set | int_set + | ext_image + | int_image | LPAREN! statement RPAREN! | variable | iriRef @@ -94,9 +123,9 @@ statement_variable literal - : numericLiteral - | booleanLiteral - | string + : numericLiteral -> ^(NUM_LIT numericLiteral) + | booleanLiteral -> ^(BOOL_LIT booleanLiteral) + | string -> ^(STRING_LIT string) ; numericLiteral @@ -134,8 +163,8 @@ string ; iriRef - : IRI_REF - | prefixedName + : IRI_REF -> ^(URI IRI_REF) + | prefixedName -> ^(CURIE prefixedName) ; prefixedName @@ -225,6 +254,17 @@ EQUIVALENCE_CONC : '<|>' ; +EXT_IMG : 'ext' + ; + +INT_IMG : 'int' + ; + +WILDCARD + : '_' + ; + + NOT : '!!' ; diff --git a/open-nars/com/googlecode/opennars/parser/loan/loan.tokens b/open-nars/com/googlecode/opennars/parser/loan/loan.tokens deleted file mode 100644 index 61763b197e8c714eb0a221aa3e9eb5ce02434fee..0000000000000000000000000000000000000000 --- a/open-nars/com/googlecode/opennars/parser/loan/loan.tokens +++ /dev/null @@ -1,76 +0,0 @@ -COMMA=20 -PN_CHARS_U=75 -MINUS=44 -PERCENT=16 -AT_PREFIX=8 -OPEN_BRACE=40 -DOUBLE=49 -AT_BASE=4 -EQUIVALENCE=35 -FALSE=57 -PN_CHARS_BASE=69 -EQUIVALENCE_CONC=37 -QUERY_VAR=47 -AT_DELAY=10 -LBRACKET=42 -INHERITANCE=26 -INSTANCE=28 -TILDE=45 -DECIMAL=17 -QUESTION=15 -CONJ=19 -DISJ=21 -IMPLICATION=31 -DOT=6 -STM_VAR=48 -RANGLE=68 -INTEGER=12 -IMPLICATION_RETRO=33 -FUTURE=25 -RBRACKET=43 -RPAREN=13 -PN_PREFIX=65 -EQUIVALENCE_PRED=36 -LANGLE=67 -LPAREN=11 -INSTANCE_PROPERTY=30 -ECHAR=74 -PLUS=73 -DIGIT=70 -AMPERSAND=38 -INTEGER_NEGATIVE=53 -PNAME_NS=9 -PAST=23 -SIMILARITY=27 -PROPERTY=29 -DECIMAL_POSITIVE=51 -STRING_LITERAL_LONG1=60 -IMPLICATION_PRED=32 -WS=64 -PNAME_LN=62 -LANGTAG=71 -EXCLAMATION=14 -PN_LOCAL=66 -VARNAME=76 -CLOSE_BRACE=41 -COMMENT=78 -PN_CHARS=77 -PRESENT=24 -AT_IMPORT=7 -STRING_LITERAL_LONG2=61 -DOUBLE_NEGATIVE=55 -EXPONENT=72 -SEMICOLON=18 -BAR=39 -DECIMAL_NEGATIVE=54 -IRI_REF=5 -DOUBLE_POSITIVE=52 -REFERENCE=79 -EOL=63 -INTEGER_POSITIVE=50 -STAR=46 -NOT=22 -STRING_LITERAL2=59 -TRUE=56 -STRING_LITERAL1=58 -IMPLICATION_CONC=34 diff --git a/open-nars/com/googlecode/opennars/parser/loan/loanLexer.java b/open-nars/com/googlecode/opennars/parser/loan/loanLexer.java deleted file mode 100644 index 865e1e24877e240d7626b4e53881b04889d17cdf..0000000000000000000000000000000000000000 --- a/open-nars/com/googlecode/opennars/parser/loan/loanLexer.java +++ /dev/null @@ -1,3574 +0,0 @@ -package com.googlecode.opennars.parser.loan; - -import org.antlr.runtime.*; -import java.util.Stack; -import java.util.List; -import java.util.ArrayList; - -public class loanLexer extends Lexer { - public static final int COMMA=20; - public static final int PN_CHARS_U=75; - public static final int MINUS=44; - public static final int AT_PREFIX=8; - public static final int PERCENT=16; - public static final int OPEN_BRACE=40; - public static final int DOUBLE=49; - public static final int EQUIVALENCE=35; - public static final int AT_BASE=4; - public static final int FALSE=57; - public static final int EQUIVALENCE_CONC=37; - public static final int PN_CHARS_BASE=69; - public static final int QUERY_VAR=47; - public static final int AT_DELAY=10; - public static final int LBRACKET=42; - public static final int INHERITANCE=26; - public static final int INSTANCE=28; - public static final int TILDE=45; - public static final int DECIMAL=17; - public static final int QUESTION=15; - public static final int CONJ=19; - public static final int DISJ=21; - public static final int IMPLICATION=31; - public static final int DOT=6; - public static final int STM_VAR=48; - public static final int RANGLE=68; - public static final int INTEGER=12; - public static final int IMPLICATION_RETRO=33; - public static final int FUTURE=25; - public static final int RBRACKET=43; - public static final int RPAREN=13; - public static final int PN_PREFIX=65; - public static final int EQUIVALENCE_PRED=36; - public static final int LANGLE=67; - public static final int LPAREN=11; - public static final int INSTANCE_PROPERTY=30; - public static final int ECHAR=74; - public static final int PLUS=73; - public static final int DIGIT=70; - public static final int AMPERSAND=38; - public static final int PAST=23; - public static final int PNAME_NS=9; - public static final int INTEGER_NEGATIVE=53; - public static final int SIMILARITY=27; - public static final int PROPERTY=29; - public static final int DECIMAL_POSITIVE=51; - public static final int STRING_LITERAL_LONG1=60; - public static final int IMPLICATION_PRED=32; - public static final int WS=64; - public static final int PNAME_LN=62; - public static final int EXCLAMATION=14; - public static final int LANGTAG=71; - public static final int PN_LOCAL=66; - public static final int CLOSE_BRACE=41; - public static final int VARNAME=76; - public static final int COMMENT=78; - public static final int PN_CHARS=77; - public static final int PRESENT=24; - public static final int AT_IMPORT=7; - public static final int DOUBLE_NEGATIVE=55; - public static final int STRING_LITERAL_LONG2=61; - public static final int SEMICOLON=18; - public static final int EXPONENT=72; - public static final int BAR=39; - public static final int DECIMAL_NEGATIVE=54; - public static final int IRI_REF=5; - public static final int EOF=-1; - public static final int DOUBLE_POSITIVE=52; - public static final int EOL=63; - public static final int REFERENCE=79; - public static final int Tokens=80; - public static final int INTEGER_POSITIVE=50; - public static final int STAR=46; - public static final int NOT=22; - public static final int TRUE=56; - public static final int STRING_LITERAL2=59; - public static final int STRING_LITERAL1=58; - public static final int IMPLICATION_CONC=34; - public loanLexer() {;} - public loanLexer(CharStream input) { - super(input); - } - public String getGrammarFileName() { return "/Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g"; } - - // $ANTLR start WS - public final void mWS() throws RecognitionException { - try { - int _type = WS; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:152:5: ( ( ' ' | '\\t' | EOL )+ ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:152:7: ( ' ' | '\\t' | EOL )+ - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:152:7: ( ' ' | '\\t' | EOL )+ - int cnt1=0; - loop1: - do { - int alt1=2; - int LA1_0 = input.LA(1); - - if ( ((LA1_0>='\t' && LA1_0<='\n')||LA1_0=='\r'||LA1_0==' ') ) { - alt1=1; - } - - - switch (alt1) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - if ( (input.LA(1)>='\t' && input.LA(1)<='\n')||input.LA(1)=='\r'||input.LA(1)==' ' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - break; - - default : - if ( cnt1 >= 1 ) break loop1; - EarlyExitException eee = - new EarlyExitException(1, input); - throw eee; - } - cnt1++; - } while (true); - - channel=HIDDEN; - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end WS - - // $ANTLR start AT_IMPORT - public final void mAT_IMPORT() throws RecognitionException { - try { - int _type = AT_IMPORT; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:156:2: ( '@import' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:156:4: '@import' - { - match("@import"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end AT_IMPORT - - // $ANTLR start AT_PREFIX - public final void mAT_PREFIX() throws RecognitionException { - try { - int _type = AT_PREFIX; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:160:2: ( '@prefix' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:160:4: '@prefix' - { - match("@prefix"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end AT_PREFIX - - // $ANTLR start AT_BASE - public final void mAT_BASE() throws RecognitionException { - try { - int _type = AT_BASE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:163:9: ( '@base' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:163:11: '@base' - { - match("@base"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end AT_BASE - - // $ANTLR start AT_DELAY - public final void mAT_DELAY() throws RecognitionException { - try { - int _type = AT_DELAY; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:167:2: ( '@delay' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:167:4: '@delay' - { - match("@delay"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end AT_DELAY - - // $ANTLR start INHERITANCE - public final void mINHERITANCE() throws RecognitionException { - try { - int _type = INHERITANCE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:172:2: ( '-->' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:172:4: '-->' - { - match("-->"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end INHERITANCE - - // $ANTLR start SIMILARITY - public final void mSIMILARITY() throws RecognitionException { - try { - int _type = SIMILARITY; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:176:2: ( '<->' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:176:4: '<->' - { - match("<->"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end SIMILARITY - - // $ANTLR start INSTANCE - public final void mINSTANCE() throws RecognitionException { - try { - int _type = INSTANCE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:180:2: ( '}->' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:180:4: '}->' - { - match("}->"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end INSTANCE - - // $ANTLR start PROPERTY - public final void mPROPERTY() throws RecognitionException { - try { - int _type = PROPERTY; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:185:2: ( '--[' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:185:4: '--[' - { - match("--["); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end PROPERTY - - // $ANTLR start INSTANCE_PROPERTY - public final void mINSTANCE_PROPERTY() throws RecognitionException { - try { - int _type = INSTANCE_PROPERTY; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:190:2: ( '}-[' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:190:4: '}-[' - { - match("}-["); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end INSTANCE_PROPERTY - - // $ANTLR start IMPLICATION - public final void mIMPLICATION() throws RecognitionException { - try { - int _type = IMPLICATION; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:195:2: ( '==>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:195:4: '==>' - { - match("==>"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end IMPLICATION - - // $ANTLR start IMPLICATION_PRED - public final void mIMPLICATION_PRED() throws RecognitionException { - try { - int _type = IMPLICATION_PRED; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:200:2: ( '=/>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:200:4: '=/>' - { - match("=/>"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end IMPLICATION_PRED - - // $ANTLR start IMPLICATION_RETRO - public final void mIMPLICATION_RETRO() throws RecognitionException { - try { - int _type = IMPLICATION_RETRO; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:205:2: ( '=\\\\>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:205:4: '=\\\\>' - { - match("=\\>"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end IMPLICATION_RETRO - - // $ANTLR start IMPLICATION_CONC - public final void mIMPLICATION_CONC() throws RecognitionException { - try { - int _type = IMPLICATION_CONC; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:210:2: ( '=|>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:210:4: '=|>' - { - match("=|>"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end IMPLICATION_CONC - - // $ANTLR start EQUIVALENCE - public final void mEQUIVALENCE() throws RecognitionException { - try { - int _type = EQUIVALENCE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:215:2: ( '<=>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:215:4: '<=>' - { - match("<=>"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end EQUIVALENCE - - // $ANTLR start EQUIVALENCE_PRED - public final void mEQUIVALENCE_PRED() throws RecognitionException { - try { - int _type = EQUIVALENCE_PRED; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:220:2: ( '</>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:220:4: '</>' - { - match("</>"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end EQUIVALENCE_PRED - - // $ANTLR start EQUIVALENCE_CONC - public final void mEQUIVALENCE_CONC() throws RecognitionException { - try { - int _type = EQUIVALENCE_CONC; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:225:2: ( '<|>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:225:4: '<|>' - { - match("<|>"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end EQUIVALENCE_CONC - - // $ANTLR start NOT - public final void mNOT() throws RecognitionException { - try { - int _type = NOT; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:228:5: ( '!!' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:228:7: '!!' - { - match("!!"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end NOT - - // $ANTLR start PAST - public final void mPAST() throws RecognitionException { - try { - int _type = PAST; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:231:6: ( '\\\\>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:231:8: '\\\\>' - { - match("\\>"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end PAST - - // $ANTLR start PRESENT - public final void mPRESENT() throws RecognitionException { - try { - int _type = PRESENT; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:234:9: ( '|>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:234:11: '|>' - { - match("|>"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end PRESENT - - // $ANTLR start FUTURE - public final void mFUTURE() throws RecognitionException { - try { - int _type = FUTURE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:237:9: ( '/>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:237:11: '/>' - { - match("/>"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end FUTURE - - // $ANTLR start CONJ - public final void mCONJ() throws RecognitionException { - try { - int _type = CONJ; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:240:6: ( '&&' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:240:8: '&&' - { - match("&&"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end CONJ - - // $ANTLR start DISJ - public final void mDISJ() throws RecognitionException { - try { - int _type = DISJ; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:243:6: ( '||' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:243:8: '||' - { - match("||"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end DISJ - - // $ANTLR start OPEN_BRACE - public final void mOPEN_BRACE() throws RecognitionException { - try { - int _type = OPEN_BRACE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:247:2: ( '{' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:247:4: '{' - { - match('{'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end OPEN_BRACE - - // $ANTLR start CLOSE_BRACE - public final void mCLOSE_BRACE() throws RecognitionException { - try { - int _type = CLOSE_BRACE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:251:2: ( '}' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:251:4: '}' - { - match('}'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end CLOSE_BRACE - - // $ANTLR start LPAREN - public final void mLPAREN() throws RecognitionException { - try { - int _type = LPAREN; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:254:8: ( '(' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:254:10: '(' - { - match('('); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end LPAREN - - // $ANTLR start RPAREN - public final void mRPAREN() throws RecognitionException { - try { - int _type = RPAREN; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:257:8: ( ')' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:257:10: ')' - { - match(')'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end RPAREN - - // $ANTLR start LBRACKET - public final void mLBRACKET() throws RecognitionException { - try { - int _type = LBRACKET; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:261:2: ( '[' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:261:4: '[' - { - match('['); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end LBRACKET - - // $ANTLR start RBRACKET - public final void mRBRACKET() throws RecognitionException { - try { - int _type = RBRACKET; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:265:2: ( ']' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:265:4: ']' - { - match(']'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end RBRACKET - - // $ANTLR start PNAME_NS - public final void mPNAME_NS() throws RecognitionException { - try { - int _type = PNAME_NS; - Token p=null; - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:271:5: ( (p= PN_PREFIX )? ':' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:271:7: (p= PN_PREFIX )? ':' - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:271:8: (p= PN_PREFIX )? - int alt2=2; - int LA2_0 = input.LA(1); - - if ( ((LA2_0>='A' && LA2_0<='Z')||(LA2_0>='a' && LA2_0<='z')||(LA2_0>='\u00C0' && LA2_0<='\u00D6')||(LA2_0>='\u00D8' && LA2_0<='\u00F6')||(LA2_0>='\u00F8' && LA2_0<='\u02FF')||(LA2_0>='\u0370' && LA2_0<='\u037D')||(LA2_0>='\u037F' && LA2_0<='\u1FFF')||(LA2_0>='\u200C' && LA2_0<='\u200D')||(LA2_0>='\u2070' && LA2_0<='\u218F')||(LA2_0>='\u2C00' && LA2_0<='\u2FEF')||(LA2_0>='\u3001' && LA2_0<='\uD7FF')||(LA2_0>='\uF900' && LA2_0<='\uFDCF')||(LA2_0>='\uFDF0' && LA2_0<='\uFFFD')) ) { - alt2=1; - } - switch (alt2) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:271:8: p= PN_PREFIX - { - int pStart439 = getCharIndex(); - mPN_PREFIX(); - p = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, pStart439, getCharIndex()-1); - - } - break; - - } - - match(':'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end PNAME_NS - - // $ANTLR start PNAME_LN - public final void mPNAME_LN() throws RecognitionException { - try { - int _type = PNAME_LN; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:275:5: ( PNAME_NS PN_LOCAL ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:275:7: PNAME_NS PN_LOCAL - { - mPNAME_NS(); - mPN_LOCAL(); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end PNAME_LN - - // $ANTLR start TRUE - public final void mTRUE() throws RecognitionException { - try { - int _type = TRUE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:279:5: ( ( 'T' | 't' ) ( 'R' | 'r' ) ( 'U' | 'u' ) ( 'E' | 'e' ) ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:279:7: ( 'T' | 't' ) ( 'R' | 'r' ) ( 'U' | 'u' ) ( 'E' | 'e' ) - { - if ( input.LA(1)=='T'||input.LA(1)=='t' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - if ( input.LA(1)=='R'||input.LA(1)=='r' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - if ( input.LA(1)=='U'||input.LA(1)=='u' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - if ( input.LA(1)=='E'||input.LA(1)=='e' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end TRUE - - // $ANTLR start FALSE - public final void mFALSE() throws RecognitionException { - try { - int _type = FALSE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:283:5: ( ( 'F' | 'f' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'S' | 's' ) ( 'E' | 'e' ) ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:283:7: ( 'F' | 'f' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'S' | 's' ) ( 'E' | 'e' ) - { - if ( input.LA(1)=='F'||input.LA(1)=='f' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - if ( input.LA(1)=='A'||input.LA(1)=='a' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - if ( input.LA(1)=='L'||input.LA(1)=='l' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - if ( input.LA(1)=='S'||input.LA(1)=='s' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - if ( input.LA(1)=='E'||input.LA(1)=='e' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end FALSE - - // $ANTLR start IRI_REF - public final void mIRI_REF() throws RecognitionException { - try { - int _type = IRI_REF; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:287:5: ( LANGLE ( options {greedy=false; } : ~ ( LANGLE | RANGLE | '\"' | OPEN_BRACE | CLOSE_BRACE | '|' | '^' | '\\\\' | '`' | ( '\\u0000' .. '\\u0020' ) ) )* RANGLE ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:287:7: LANGLE ( options {greedy=false; } : ~ ( LANGLE | RANGLE | '\"' | OPEN_BRACE | CLOSE_BRACE | '|' | '^' | '\\\\' | '`' | ( '\\u0000' .. '\\u0020' ) ) )* RANGLE - { - mLANGLE(); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:287:14: ( options {greedy=false; } : ~ ( LANGLE | RANGLE | '\"' | OPEN_BRACE | CLOSE_BRACE | '|' | '^' | '\\\\' | '`' | ( '\\u0000' .. '\\u0020' ) ) )* - loop3: - do { - int alt3=2; - int LA3_0 = input.LA(1); - - if ( (LA3_0=='>') ) { - alt3=2; - } - else if ( (LA3_0=='!'||(LA3_0>='#' && LA3_0<=';')||LA3_0=='='||(LA3_0>='?' && LA3_0<='[')||LA3_0==']'||LA3_0=='_'||(LA3_0>='a' && LA3_0<='z')||(LA3_0>='~' && LA3_0<='\uFFFE')) ) { - alt3=1; - } - - - switch (alt3) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:287:42: ~ ( LANGLE | RANGLE | '\"' | OPEN_BRACE | CLOSE_BRACE | '|' | '^' | '\\\\' | '`' | ( '\\u0000' .. '\\u0020' ) ) - { - if ( input.LA(1)=='!'||(input.LA(1)>='#' && input.LA(1)<=';')||input.LA(1)=='='||(input.LA(1)>='?' && input.LA(1)<='[')||input.LA(1)==']'||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z')||(input.LA(1)>='~' && input.LA(1)<='\uFFFE') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - break; - - default : - break loop3; - } - } while (true); - - mRANGLE(); - setText(getText().substring(1, getText().length() - 1)); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end IRI_REF - - // $ANTLR start LANGTAG - public final void mLANGTAG() throws RecognitionException { - try { - int _type = LANGTAG; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:291:5: ( '@' ( PN_CHARS_BASE )+ ( MINUS ( PN_CHARS_BASE DIGIT )+ )* ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:291:7: '@' ( PN_CHARS_BASE )+ ( MINUS ( PN_CHARS_BASE DIGIT )+ )* - { - match('@'); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:291:11: ( PN_CHARS_BASE )+ - int cnt4=0; - loop4: - do { - int alt4=2; - int LA4_0 = input.LA(1); - - if ( ((LA4_0>='A' && LA4_0<='Z')||(LA4_0>='a' && LA4_0<='z')||(LA4_0>='\u00C0' && LA4_0<='\u00D6')||(LA4_0>='\u00D8' && LA4_0<='\u00F6')||(LA4_0>='\u00F8' && LA4_0<='\u02FF')||(LA4_0>='\u0370' && LA4_0<='\u037D')||(LA4_0>='\u037F' && LA4_0<='\u1FFF')||(LA4_0>='\u200C' && LA4_0<='\u200D')||(LA4_0>='\u2070' && LA4_0<='\u218F')||(LA4_0>='\u2C00' && LA4_0<='\u2FEF')||(LA4_0>='\u3001' && LA4_0<='\uD7FF')||(LA4_0>='\uF900' && LA4_0<='\uFDCF')||(LA4_0>='\uFDF0' && LA4_0<='\uFFFD')) ) { - alt4=1; - } - - - switch (alt4) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:291:11: PN_CHARS_BASE - { - mPN_CHARS_BASE(); - - } - break; - - default : - if ( cnt4 >= 1 ) break loop4; - EarlyExitException eee = - new EarlyExitException(4, input); - throw eee; - } - cnt4++; - } while (true); - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:291:26: ( MINUS ( PN_CHARS_BASE DIGIT )+ )* - loop6: - do { - int alt6=2; - int LA6_0 = input.LA(1); - - if ( (LA6_0=='-') ) { - alt6=1; - } - - - switch (alt6) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:291:27: MINUS ( PN_CHARS_BASE DIGIT )+ - { - mMINUS(); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:291:33: ( PN_CHARS_BASE DIGIT )+ - int cnt5=0; - loop5: - do { - int alt5=2; - int LA5_0 = input.LA(1); - - if ( ((LA5_0>='A' && LA5_0<='Z')||(LA5_0>='a' && LA5_0<='z')||(LA5_0>='\u00C0' && LA5_0<='\u00D6')||(LA5_0>='\u00D8' && LA5_0<='\u00F6')||(LA5_0>='\u00F8' && LA5_0<='\u02FF')||(LA5_0>='\u0370' && LA5_0<='\u037D')||(LA5_0>='\u037F' && LA5_0<='\u1FFF')||(LA5_0>='\u200C' && LA5_0<='\u200D')||(LA5_0>='\u2070' && LA5_0<='\u218F')||(LA5_0>='\u2C00' && LA5_0<='\u2FEF')||(LA5_0>='\u3001' && LA5_0<='\uD7FF')||(LA5_0>='\uF900' && LA5_0<='\uFDCF')||(LA5_0>='\uFDF0' && LA5_0<='\uFFFD')) ) { - alt5=1; - } - - - switch (alt5) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:291:34: PN_CHARS_BASE DIGIT - { - mPN_CHARS_BASE(); - mDIGIT(); - - } - break; - - default : - if ( cnt5 >= 1 ) break loop5; - EarlyExitException eee = - new EarlyExitException(5, input); - throw eee; - } - cnt5++; - } while (true); - - - } - break; - - default : - break loop6; - } - } while (true); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end LANGTAG - - // $ANTLR start QUERY_VAR - public final void mQUERY_VAR() throws RecognitionException { - try { - int _type = QUERY_VAR; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:295:2: ( '?' PN_LOCAL ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:295:4: '?' PN_LOCAL - { - match('?'); - mPN_LOCAL(); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end QUERY_VAR - - // $ANTLR start STM_VAR - public final void mSTM_VAR() throws RecognitionException { - try { - int _type = STM_VAR; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:298:9: ( '#' PN_LOCAL ( '(' ( PN_LOCAL ( ',' PN_LOCAL )* )? ')' )? ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:298:11: '#' PN_LOCAL ( '(' ( PN_LOCAL ( ',' PN_LOCAL )* )? ')' )? - { - match('#'); - mPN_LOCAL(); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:298:24: ( '(' ( PN_LOCAL ( ',' PN_LOCAL )* )? ')' )? - int alt9=2; - int LA9_0 = input.LA(1); - - if ( (LA9_0=='(') ) { - alt9=1; - } - switch (alt9) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:298:25: '(' ( PN_LOCAL ( ',' PN_LOCAL )* )? ')' - { - match('('); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:298:29: ( PN_LOCAL ( ',' PN_LOCAL )* )? - int alt8=2; - int LA8_0 = input.LA(1); - - if ( ((LA8_0>='0' && LA8_0<='9')||(LA8_0>='A' && LA8_0<='Z')||LA8_0=='_'||(LA8_0>='a' && LA8_0<='z')||(LA8_0>='\u00C0' && LA8_0<='\u00D6')||(LA8_0>='\u00D8' && LA8_0<='\u00F6')||(LA8_0>='\u00F8' && LA8_0<='\u02FF')||(LA8_0>='\u0370' && LA8_0<='\u037D')||(LA8_0>='\u037F' && LA8_0<='\u1FFF')||(LA8_0>='\u200C' && LA8_0<='\u200D')||(LA8_0>='\u2070' && LA8_0<='\u218F')||(LA8_0>='\u2C00' && LA8_0<='\u2FEF')||(LA8_0>='\u3001' && LA8_0<='\uD7FF')||(LA8_0>='\uF900' && LA8_0<='\uFDCF')||(LA8_0>='\uFDF0' && LA8_0<='\uFFFD')) ) { - alt8=1; - } - switch (alt8) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:298:30: PN_LOCAL ( ',' PN_LOCAL )* - { - mPN_LOCAL(); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:298:39: ( ',' PN_LOCAL )* - loop7: - do { - int alt7=2; - int LA7_0 = input.LA(1); - - if ( (LA7_0==',') ) { - alt7=1; - } - - - switch (alt7) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:298:40: ',' PN_LOCAL - { - match(','); - mPN_LOCAL(); - - } - break; - - default : - break loop7; - } - } while (true); - - - } - break; - - } - - match(')'); - - } - break; - - } - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end STM_VAR - - // $ANTLR start INTEGER - public final void mINTEGER() throws RecognitionException { - try { - int _type = INTEGER; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:302:5: ( ( DIGIT )+ ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:302:7: ( DIGIT )+ - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:302:7: ( DIGIT )+ - int cnt10=0; - loop10: - do { - int alt10=2; - int LA10_0 = input.LA(1); - - if ( ((LA10_0>='0' && LA10_0<='9')) ) { - alt10=1; - } - - - switch (alt10) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:302:7: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt10 >= 1 ) break loop10; - EarlyExitException eee = - new EarlyExitException(10, input); - throw eee; - } - cnt10++; - } while (true); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end INTEGER - - // $ANTLR start DECIMAL - public final void mDECIMAL() throws RecognitionException { - try { - int _type = DECIMAL; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:306:5: ( ( DIGIT )+ DOT ( DIGIT )* | DOT ( DIGIT )+ ) - int alt14=2; - int LA14_0 = input.LA(1); - - if ( ((LA14_0>='0' && LA14_0<='9')) ) { - alt14=1; - } - else if ( (LA14_0=='.') ) { - alt14=2; - } - else { - NoViableAltException nvae = - new NoViableAltException("305:1: DECIMAL : ( ( DIGIT )+ DOT ( DIGIT )* | DOT ( DIGIT )+ );", 14, 0, input); - - throw nvae; - } - switch (alt14) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:306:7: ( DIGIT )+ DOT ( DIGIT )* - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:306:7: ( DIGIT )+ - int cnt11=0; - loop11: - do { - int alt11=2; - int LA11_0 = input.LA(1); - - if ( ((LA11_0>='0' && LA11_0<='9')) ) { - alt11=1; - } - - - switch (alt11) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:306:7: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt11 >= 1 ) break loop11; - EarlyExitException eee = - new EarlyExitException(11, input); - throw eee; - } - cnt11++; - } while (true); - - mDOT(); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:306:18: ( DIGIT )* - loop12: - do { - int alt12=2; - int LA12_0 = input.LA(1); - - if ( ((LA12_0>='0' && LA12_0<='9')) ) { - alt12=1; - } - - - switch (alt12) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:306:18: DIGIT - { - mDIGIT(); - - } - break; - - default : - break loop12; - } - } while (true); - - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:307:7: DOT ( DIGIT )+ - { - mDOT(); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:307:11: ( DIGIT )+ - int cnt13=0; - loop13: - do { - int alt13=2; - int LA13_0 = input.LA(1); - - if ( ((LA13_0>='0' && LA13_0<='9')) ) { - alt13=1; - } - - - switch (alt13) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:307:11: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt13 >= 1 ) break loop13; - EarlyExitException eee = - new EarlyExitException(13, input); - throw eee; - } - cnt13++; - } while (true); - - - } - break; - - } - this.type = _type; - } - finally { - } - } - // $ANTLR end DECIMAL - - // $ANTLR start DOUBLE - public final void mDOUBLE() throws RecognitionException { - try { - int _type = DOUBLE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:311:5: ( ( DIGIT )+ DOT ( DIGIT )* EXPONENT | DOT ( DIGIT )+ EXPONENT | ( DIGIT )+ EXPONENT ) - int alt19=3; - alt19 = dfa19.predict(input); - switch (alt19) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:311:7: ( DIGIT )+ DOT ( DIGIT )* EXPONENT - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:311:7: ( DIGIT )+ - int cnt15=0; - loop15: - do { - int alt15=2; - int LA15_0 = input.LA(1); - - if ( ((LA15_0>='0' && LA15_0<='9')) ) { - alt15=1; - } - - - switch (alt15) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:311:7: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt15 >= 1 ) break loop15; - EarlyExitException eee = - new EarlyExitException(15, input); - throw eee; - } - cnt15++; - } while (true); - - mDOT(); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:311:18: ( DIGIT )* - loop16: - do { - int alt16=2; - int LA16_0 = input.LA(1); - - if ( ((LA16_0>='0' && LA16_0<='9')) ) { - alt16=1; - } - - - switch (alt16) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:311:18: DIGIT - { - mDIGIT(); - - } - break; - - default : - break loop16; - } - } while (true); - - mEXPONENT(); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:312:7: DOT ( DIGIT )+ EXPONENT - { - mDOT(); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:312:11: ( DIGIT )+ - int cnt17=0; - loop17: - do { - int alt17=2; - int LA17_0 = input.LA(1); - - if ( ((LA17_0>='0' && LA17_0<='9')) ) { - alt17=1; - } - - - switch (alt17) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:312:11: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt17 >= 1 ) break loop17; - EarlyExitException eee = - new EarlyExitException(17, input); - throw eee; - } - cnt17++; - } while (true); - - mEXPONENT(); - - } - break; - case 3 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:313:7: ( DIGIT )+ EXPONENT - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:313:7: ( DIGIT )+ - int cnt18=0; - loop18: - do { - int alt18=2; - int LA18_0 = input.LA(1); - - if ( ((LA18_0>='0' && LA18_0<='9')) ) { - alt18=1; - } - - - switch (alt18) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:313:7: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt18 >= 1 ) break loop18; - EarlyExitException eee = - new EarlyExitException(18, input); - throw eee; - } - cnt18++; - } while (true); - - mEXPONENT(); - - } - break; - - } - this.type = _type; - } - finally { - } - } - // $ANTLR end DOUBLE - - // $ANTLR start INTEGER_POSITIVE - public final void mINTEGER_POSITIVE() throws RecognitionException { - try { - int _type = INTEGER_POSITIVE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:317:5: ( PLUS INTEGER ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:317:7: PLUS INTEGER - { - mPLUS(); - mINTEGER(); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end INTEGER_POSITIVE - - // $ANTLR start DECIMAL_POSITIVE - public final void mDECIMAL_POSITIVE() throws RecognitionException { - try { - int _type = DECIMAL_POSITIVE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:321:5: ( PLUS DECIMAL ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:321:7: PLUS DECIMAL - { - mPLUS(); - mDECIMAL(); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end DECIMAL_POSITIVE - - // $ANTLR start DOUBLE_POSITIVE - public final void mDOUBLE_POSITIVE() throws RecognitionException { - try { - int _type = DOUBLE_POSITIVE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:325:5: ( PLUS DOUBLE ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:325:7: PLUS DOUBLE - { - mPLUS(); - mDOUBLE(); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end DOUBLE_POSITIVE - - // $ANTLR start INTEGER_NEGATIVE - public final void mINTEGER_NEGATIVE() throws RecognitionException { - try { - int _type = INTEGER_NEGATIVE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:329:5: ( MINUS INTEGER ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:329:7: MINUS INTEGER - { - mMINUS(); - mINTEGER(); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end INTEGER_NEGATIVE - - // $ANTLR start DECIMAL_NEGATIVE - public final void mDECIMAL_NEGATIVE() throws RecognitionException { - try { - int _type = DECIMAL_NEGATIVE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:333:5: ( MINUS DECIMAL ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:333:7: MINUS DECIMAL - { - mMINUS(); - mDECIMAL(); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end DECIMAL_NEGATIVE - - // $ANTLR start DOUBLE_NEGATIVE - public final void mDOUBLE_NEGATIVE() throws RecognitionException { - try { - int _type = DOUBLE_NEGATIVE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:337:5: ( MINUS DOUBLE ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:337:7: MINUS DOUBLE - { - mMINUS(); - mDOUBLE(); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end DOUBLE_NEGATIVE - - // $ANTLR start EXPONENT - public final void mEXPONENT() throws RecognitionException { - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:342:5: ( ( 'e' | 'E' ) ( PLUS | MINUS )? ( DIGIT )+ ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:342:7: ( 'e' | 'E' ) ( PLUS | MINUS )? ( DIGIT )+ - { - if ( input.LA(1)=='E'||input.LA(1)=='e' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:342:17: ( PLUS | MINUS )? - int alt20=2; - int LA20_0 = input.LA(1); - - if ( (LA20_0=='+'||LA20_0=='-') ) { - alt20=1; - } - switch (alt20) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - if ( input.LA(1)=='+'||input.LA(1)=='-' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - break; - - } - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:342:31: ( DIGIT )+ - int cnt21=0; - loop21: - do { - int alt21=2; - int LA21_0 = input.LA(1); - - if ( ((LA21_0>='0' && LA21_0<='9')) ) { - alt21=1; - } - - - switch (alt21) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:342:31: DIGIT - { - mDIGIT(); - - } - break; - - default : - if ( cnt21 >= 1 ) break loop21; - EarlyExitException eee = - new EarlyExitException(21, input); - throw eee; - } - cnt21++; - } while (true); - - - } - - } - finally { - } - } - // $ANTLR end EXPONENT - - // $ANTLR start STRING_LITERAL1 - public final void mSTRING_LITERAL1() throws RecognitionException { - try { - int _type = STRING_LITERAL1; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:346:5: ( '\\'' ( options {greedy=false; } : ~ ( '\\u0027' | '\\u005C' | '\\u000A' | '\\u000D' ) | ECHAR )* '\\'' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:346:7: '\\'' ( options {greedy=false; } : ~ ( '\\u0027' | '\\u005C' | '\\u000A' | '\\u000D' ) | ECHAR )* '\\'' - { - match('\''); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:346:12: ( options {greedy=false; } : ~ ( '\\u0027' | '\\u005C' | '\\u000A' | '\\u000D' ) | ECHAR )* - loop22: - do { - int alt22=3; - int LA22_0 = input.LA(1); - - if ( (LA22_0=='\'') ) { - alt22=3; - } - else if ( ((LA22_0>='\u0000' && LA22_0<='\t')||(LA22_0>='\u000B' && LA22_0<='\f')||(LA22_0>='\u000E' && LA22_0<='&')||(LA22_0>='(' && LA22_0<='[')||(LA22_0>=']' && LA22_0<='\uFFFE')) ) { - alt22=1; - } - else if ( (LA22_0=='\\') ) { - alt22=2; - } - - - switch (alt22) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:346:40: ~ ( '\\u0027' | '\\u005C' | '\\u000A' | '\\u000D' ) - { - if ( (input.LA(1)>='\u0000' && input.LA(1)<='\t')||(input.LA(1)>='\u000B' && input.LA(1)<='\f')||(input.LA(1)>='\u000E' && input.LA(1)<='&')||(input.LA(1)>='(' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFE') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:346:87: ECHAR - { - mECHAR(); - - } - break; - - default : - break loop22; - } - } while (true); - - match('\''); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end STRING_LITERAL1 - - // $ANTLR start STRING_LITERAL2 - public final void mSTRING_LITERAL2() throws RecognitionException { - try { - int _type = STRING_LITERAL2; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:350:5: ( '\"' ( options {greedy=false; } : ~ ( '\\u0022' | '\\u005C' | '\\u000A' | '\\u000D' ) | ECHAR )* '\"' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:350:7: '\"' ( options {greedy=false; } : ~ ( '\\u0022' | '\\u005C' | '\\u000A' | '\\u000D' ) | ECHAR )* '\"' - { - match('\"'); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:350:12: ( options {greedy=false; } : ~ ( '\\u0022' | '\\u005C' | '\\u000A' | '\\u000D' ) | ECHAR )* - loop23: - do { - int alt23=3; - int LA23_0 = input.LA(1); - - if ( (LA23_0=='\"') ) { - alt23=3; - } - else if ( ((LA23_0>='\u0000' && LA23_0<='\t')||(LA23_0>='\u000B' && LA23_0<='\f')||(LA23_0>='\u000E' && LA23_0<='!')||(LA23_0>='#' && LA23_0<='[')||(LA23_0>=']' && LA23_0<='\uFFFE')) ) { - alt23=1; - } - else if ( (LA23_0=='\\') ) { - alt23=2; - } - - - switch (alt23) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:350:40: ~ ( '\\u0022' | '\\u005C' | '\\u000A' | '\\u000D' ) - { - if ( (input.LA(1)>='\u0000' && input.LA(1)<='\t')||(input.LA(1)>='\u000B' && input.LA(1)<='\f')||(input.LA(1)>='\u000E' && input.LA(1)<='!')||(input.LA(1)>='#' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFE') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:350:87: ECHAR - { - mECHAR(); - - } - break; - - default : - break loop23; - } - } while (true); - - match('\"'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end STRING_LITERAL2 - - // $ANTLR start STRING_LITERAL_LONG1 - public final void mSTRING_LITERAL_LONG1() throws RecognitionException { - try { - int _type = STRING_LITERAL_LONG1; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:354:5: ( '\\'\\'\\'' ( options {greedy=false; } : ( '\\'' | '\\'\\'' )? (~ ( '\\'' | '\\\\' ) | ECHAR ) )* '\\'\\'\\'' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:354:9: '\\'\\'\\'' ( options {greedy=false; } : ( '\\'' | '\\'\\'' )? (~ ( '\\'' | '\\\\' ) | ECHAR ) )* '\\'\\'\\'' - { - match("\'\'\'"); - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:354:18: ( options {greedy=false; } : ( '\\'' | '\\'\\'' )? (~ ( '\\'' | '\\\\' ) | ECHAR ) )* - loop26: - do { - int alt26=2; - int LA26_0 = input.LA(1); - - if ( (LA26_0=='\'') ) { - int LA26_1 = input.LA(2); - - if ( (LA26_1=='\'') ) { - int LA26_3 = input.LA(3); - - if ( (LA26_3=='\'') ) { - alt26=2; - } - else if ( ((LA26_3>='\u0000' && LA26_3<='&')||(LA26_3>='(' && LA26_3<='\uFFFE')) ) { - alt26=1; - } - - - } - else if ( ((LA26_1>='\u0000' && LA26_1<='&')||(LA26_1>='(' && LA26_1<='\uFFFE')) ) { - alt26=1; - } - - - } - else if ( ((LA26_0>='\u0000' && LA26_0<='&')||(LA26_0>='(' && LA26_0<='\uFFFE')) ) { - alt26=1; - } - - - switch (alt26) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:354:46: ( '\\'' | '\\'\\'' )? (~ ( '\\'' | '\\\\' ) | ECHAR ) - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:354:46: ( '\\'' | '\\'\\'' )? - int alt24=3; - int LA24_0 = input.LA(1); - - if ( (LA24_0=='\'') ) { - int LA24_1 = input.LA(2); - - if ( (LA24_1=='\'') ) { - alt24=2; - } - else if ( ((LA24_1>='\u0000' && LA24_1<='&')||(LA24_1>='(' && LA24_1<='\uFFFE')) ) { - alt24=1; - } - } - switch (alt24) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:354:48: '\\'' - { - match('\''); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:354:55: '\\'\\'' - { - match("\'\'"); - - - } - break; - - } - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:354:65: (~ ( '\\'' | '\\\\' ) | ECHAR ) - int alt25=2; - int LA25_0 = input.LA(1); - - if ( ((LA25_0>='\u0000' && LA25_0<='&')||(LA25_0>='(' && LA25_0<='[')||(LA25_0>=']' && LA25_0<='\uFFFE')) ) { - alt25=1; - } - else if ( (LA25_0=='\\') ) { - alt25=2; - } - else { - NoViableAltException nvae = - new NoViableAltException("354:65: (~ ( '\\'' | '\\\\' ) | ECHAR )", 25, 0, input); - - throw nvae; - } - switch (alt25) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:354:67: ~ ( '\\'' | '\\\\' ) - { - if ( (input.LA(1)>='\u0000' && input.LA(1)<='&')||(input.LA(1)>='(' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFE') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:354:82: ECHAR - { - mECHAR(); - - } - break; - - } - - - } - break; - - default : - break loop26; - } - } while (true); - - match("\'\'\'"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end STRING_LITERAL_LONG1 - - // $ANTLR start STRING_LITERAL_LONG2 - public final void mSTRING_LITERAL_LONG2() throws RecognitionException { - try { - int _type = STRING_LITERAL_LONG2; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:358:5: ( '\"\"\"' ( options {greedy=false; } : ( '\"' | '\"\"' )? (~ ( '\"' | '\\\\' ) | ECHAR ) )* '\"\"\"' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:358:9: '\"\"\"' ( options {greedy=false; } : ( '\"' | '\"\"' )? (~ ( '\"' | '\\\\' ) | ECHAR ) )* '\"\"\"' - { - match("\"\"\""); - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:358:15: ( options {greedy=false; } : ( '\"' | '\"\"' )? (~ ( '\"' | '\\\\' ) | ECHAR ) )* - loop29: - do { - int alt29=2; - int LA29_0 = input.LA(1); - - if ( (LA29_0=='\"') ) { - int LA29_1 = input.LA(2); - - if ( (LA29_1=='\"') ) { - int LA29_3 = input.LA(3); - - if ( (LA29_3=='\"') ) { - alt29=2; - } - else if ( ((LA29_3>='\u0000' && LA29_3<='!')||(LA29_3>='#' && LA29_3<='\uFFFE')) ) { - alt29=1; - } - - - } - else if ( ((LA29_1>='\u0000' && LA29_1<='!')||(LA29_1>='#' && LA29_1<='\uFFFE')) ) { - alt29=1; - } - - - } - else if ( ((LA29_0>='\u0000' && LA29_0<='!')||(LA29_0>='#' && LA29_0<='\uFFFE')) ) { - alt29=1; - } - - - switch (alt29) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:358:43: ( '\"' | '\"\"' )? (~ ( '\"' | '\\\\' ) | ECHAR ) - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:358:43: ( '\"' | '\"\"' )? - int alt27=3; - int LA27_0 = input.LA(1); - - if ( (LA27_0=='\"') ) { - int LA27_1 = input.LA(2); - - if ( (LA27_1=='\"') ) { - alt27=2; - } - else if ( ((LA27_1>='\u0000' && LA27_1<='!')||(LA27_1>='#' && LA27_1<='\uFFFE')) ) { - alt27=1; - } - } - switch (alt27) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:358:45: '\"' - { - match('\"'); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:358:51: '\"\"' - { - match("\"\""); - - - } - break; - - } - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:358:59: (~ ( '\"' | '\\\\' ) | ECHAR ) - int alt28=2; - int LA28_0 = input.LA(1); - - if ( ((LA28_0>='\u0000' && LA28_0<='!')||(LA28_0>='#' && LA28_0<='[')||(LA28_0>=']' && LA28_0<='\uFFFE')) ) { - alt28=1; - } - else if ( (LA28_0=='\\') ) { - alt28=2; - } - else { - NoViableAltException nvae = - new NoViableAltException("358:59: (~ ( '\"' | '\\\\' ) | ECHAR )", 28, 0, input); - - throw nvae; - } - switch (alt28) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:358:61: ~ ( '\"' | '\\\\' ) - { - if ( (input.LA(1)>='\u0000' && input.LA(1)<='!')||(input.LA(1)>='#' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFE') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:358:75: ECHAR - { - mECHAR(); - - } - break; - - } - - - } - break; - - default : - break loop29; - } - } while (true); - - match("\"\"\""); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end STRING_LITERAL_LONG2 - - // $ANTLR start ECHAR - public final void mECHAR() throws RecognitionException { - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:363:5: ( '\\\\' ( 't' | 'b' | 'n' | 'r' | 'f' | '\\\\' | '\"' | '\\'' ) ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:363:7: '\\\\' ( 't' | 'b' | 'n' | 'r' | 'f' | '\\\\' | '\"' | '\\'' ) - { - match('\\'); - if ( input.LA(1)=='\"'||input.LA(1)=='\''||input.LA(1)=='\\'||input.LA(1)=='b'||input.LA(1)=='f'||input.LA(1)=='n'||input.LA(1)=='r'||input.LA(1)=='t' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - - } - finally { - } - } - // $ANTLR end ECHAR - - // $ANTLR start PN_CHARS_U - public final void mPN_CHARS_U() throws RecognitionException { - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:368:5: ( PN_CHARS_BASE | '_' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - if ( (input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z')||(input.LA(1)>='\u00C0' && input.LA(1)<='\u00D6')||(input.LA(1)>='\u00D8' && input.LA(1)<='\u00F6')||(input.LA(1)>='\u00F8' && input.LA(1)<='\u02FF')||(input.LA(1)>='\u0370' && input.LA(1)<='\u037D')||(input.LA(1)>='\u037F' && input.LA(1)<='\u1FFF')||(input.LA(1)>='\u200C' && input.LA(1)<='\u200D')||(input.LA(1)>='\u2070' && input.LA(1)<='\u218F')||(input.LA(1)>='\u2C00' && input.LA(1)<='\u2FEF')||(input.LA(1)>='\u3001' && input.LA(1)<='\uD7FF')||(input.LA(1)>='\uF900' && input.LA(1)<='\uFDCF')||(input.LA(1)>='\uFDF0' && input.LA(1)<='\uFFFD') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - - } - finally { - } - } - // $ANTLR end PN_CHARS_U - - // $ANTLR start VARNAME - public final void mVARNAME() throws RecognitionException { - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:373:5: ( ( PN_CHARS_U | DIGIT ) ( PN_CHARS_U | DIGIT | '\\u00B7' | '\\u0300' .. '\\u036F' | '\\u203F' .. '\\u2040' )* ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:373:7: ( PN_CHARS_U | DIGIT ) ( PN_CHARS_U | DIGIT | '\\u00B7' | '\\u0300' .. '\\u036F' | '\\u203F' .. '\\u2040' )* - { - if ( (input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z')||(input.LA(1)>='\u00C0' && input.LA(1)<='\u00D6')||(input.LA(1)>='\u00D8' && input.LA(1)<='\u00F6')||(input.LA(1)>='\u00F8' && input.LA(1)<='\u02FF')||(input.LA(1)>='\u0370' && input.LA(1)<='\u037D')||(input.LA(1)>='\u037F' && input.LA(1)<='\u1FFF')||(input.LA(1)>='\u200C' && input.LA(1)<='\u200D')||(input.LA(1)>='\u2070' && input.LA(1)<='\u218F')||(input.LA(1)>='\u2C00' && input.LA(1)<='\u2FEF')||(input.LA(1)>='\u3001' && input.LA(1)<='\uD7FF')||(input.LA(1)>='\uF900' && input.LA(1)<='\uFDCF')||(input.LA(1)>='\uFDF0' && input.LA(1)<='\uFFFD') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:373:30: ( PN_CHARS_U | DIGIT | '\\u00B7' | '\\u0300' .. '\\u036F' | '\\u203F' .. '\\u2040' )* - loop30: - do { - int alt30=2; - int LA30_0 = input.LA(1); - - if ( ((LA30_0>='0' && LA30_0<='9')||(LA30_0>='A' && LA30_0<='Z')||LA30_0=='_'||(LA30_0>='a' && LA30_0<='z')||LA30_0=='\u00B7'||(LA30_0>='\u00C0' && LA30_0<='\u00D6')||(LA30_0>='\u00D8' && LA30_0<='\u00F6')||(LA30_0>='\u00F8' && LA30_0<='\u037D')||(LA30_0>='\u037F' && LA30_0<='\u1FFF')||(LA30_0>='\u200C' && LA30_0<='\u200D')||(LA30_0>='\u203F' && LA30_0<='\u2040')||(LA30_0>='\u2070' && LA30_0<='\u218F')||(LA30_0>='\u2C00' && LA30_0<='\u2FEF')||(LA30_0>='\u3001' && LA30_0<='\uD7FF')||(LA30_0>='\uF900' && LA30_0<='\uFDCF')||(LA30_0>='\uFDF0' && LA30_0<='\uFFFD')) ) { - alt30=1; - } - - - switch (alt30) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - if ( (input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z')||input.LA(1)=='\u00B7'||(input.LA(1)>='\u00C0' && input.LA(1)<='\u00D6')||(input.LA(1)>='\u00D8' && input.LA(1)<='\u00F6')||(input.LA(1)>='\u00F8' && input.LA(1)<='\u037D')||(input.LA(1)>='\u037F' && input.LA(1)<='\u1FFF')||(input.LA(1)>='\u200C' && input.LA(1)<='\u200D')||(input.LA(1)>='\u203F' && input.LA(1)<='\u2040')||(input.LA(1)>='\u2070' && input.LA(1)<='\u218F')||(input.LA(1)>='\u2C00' && input.LA(1)<='\u2FEF')||(input.LA(1)>='\u3001' && input.LA(1)<='\uD7FF')||(input.LA(1)>='\uF900' && input.LA(1)<='\uFDCF')||(input.LA(1)>='\uFDF0' && input.LA(1)<='\uFFFD') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - break; - - default : - break loop30; - } - } while (true); - - - } - - } - finally { - } - } - // $ANTLR end VARNAME - - // $ANTLR start PN_CHARS - public final void mPN_CHARS() throws RecognitionException { - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:378:5: ( PN_CHARS_U | MINUS | DIGIT | '\\u00B7' | '\\u0300' .. '\\u036F' | '\\u203F' .. '\\u2040' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - if ( input.LA(1)=='-'||(input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z')||input.LA(1)=='\u00B7'||(input.LA(1)>='\u00C0' && input.LA(1)<='\u00D6')||(input.LA(1)>='\u00D8' && input.LA(1)<='\u00F6')||(input.LA(1)>='\u00F8' && input.LA(1)<='\u037D')||(input.LA(1)>='\u037F' && input.LA(1)<='\u1FFF')||(input.LA(1)>='\u200C' && input.LA(1)<='\u200D')||(input.LA(1)>='\u203F' && input.LA(1)<='\u2040')||(input.LA(1)>='\u2070' && input.LA(1)<='\u218F')||(input.LA(1)>='\u2C00' && input.LA(1)<='\u2FEF')||(input.LA(1)>='\u3001' && input.LA(1)<='\uD7FF')||(input.LA(1)>='\uF900' && input.LA(1)<='\uFDCF')||(input.LA(1)>='\uFDF0' && input.LA(1)<='\uFFFD') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - - } - finally { - } - } - // $ANTLR end PN_CHARS - - // $ANTLR start PN_PREFIX - public final void mPN_PREFIX() throws RecognitionException { - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:388:5: ( PN_CHARS_BASE ( ( PN_CHARS | DOT )* PN_CHARS )? ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:388:7: PN_CHARS_BASE ( ( PN_CHARS | DOT )* PN_CHARS )? - { - mPN_CHARS_BASE(); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:388:21: ( ( PN_CHARS | DOT )* PN_CHARS )? - int alt32=2; - int LA32_0 = input.LA(1); - - if ( ((LA32_0>='-' && LA32_0<='.')||(LA32_0>='0' && LA32_0<='9')||(LA32_0>='A' && LA32_0<='Z')||LA32_0=='_'||(LA32_0>='a' && LA32_0<='z')||LA32_0=='\u00B7'||(LA32_0>='\u00C0' && LA32_0<='\u00D6')||(LA32_0>='\u00D8' && LA32_0<='\u00F6')||(LA32_0>='\u00F8' && LA32_0<='\u037D')||(LA32_0>='\u037F' && LA32_0<='\u1FFF')||(LA32_0>='\u200C' && LA32_0<='\u200D')||(LA32_0>='\u203F' && LA32_0<='\u2040')||(LA32_0>='\u2070' && LA32_0<='\u218F')||(LA32_0>='\u2C00' && LA32_0<='\u2FEF')||(LA32_0>='\u3001' && LA32_0<='\uD7FF')||(LA32_0>='\uF900' && LA32_0<='\uFDCF')||(LA32_0>='\uFDF0' && LA32_0<='\uFFFD')) ) { - alt32=1; - } - switch (alt32) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:388:22: ( PN_CHARS | DOT )* PN_CHARS - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:388:22: ( PN_CHARS | DOT )* - loop31: - do { - int alt31=2; - int LA31_0 = input.LA(1); - - if ( (LA31_0=='-'||(LA31_0>='0' && LA31_0<='9')||(LA31_0>='A' && LA31_0<='Z')||LA31_0=='_'||(LA31_0>='a' && LA31_0<='z')||LA31_0=='\u00B7'||(LA31_0>='\u00C0' && LA31_0<='\u00D6')||(LA31_0>='\u00D8' && LA31_0<='\u00F6')||(LA31_0>='\u00F8' && LA31_0<='\u037D')||(LA31_0>='\u037F' && LA31_0<='\u1FFF')||(LA31_0>='\u200C' && LA31_0<='\u200D')||(LA31_0>='\u203F' && LA31_0<='\u2040')||(LA31_0>='\u2070' && LA31_0<='\u218F')||(LA31_0>='\u2C00' && LA31_0<='\u2FEF')||(LA31_0>='\u3001' && LA31_0<='\uD7FF')||(LA31_0>='\uF900' && LA31_0<='\uFDCF')||(LA31_0>='\uFDF0' && LA31_0<='\uFFFD')) ) { - int LA31_1 = input.LA(2); - - if ( ((LA31_1>='-' && LA31_1<='.')||(LA31_1>='0' && LA31_1<='9')||(LA31_1>='A' && LA31_1<='Z')||LA31_1=='_'||(LA31_1>='a' && LA31_1<='z')||LA31_1=='\u00B7'||(LA31_1>='\u00C0' && LA31_1<='\u00D6')||(LA31_1>='\u00D8' && LA31_1<='\u00F6')||(LA31_1>='\u00F8' && LA31_1<='\u037D')||(LA31_1>='\u037F' && LA31_1<='\u1FFF')||(LA31_1>='\u200C' && LA31_1<='\u200D')||(LA31_1>='\u203F' && LA31_1<='\u2040')||(LA31_1>='\u2070' && LA31_1<='\u218F')||(LA31_1>='\u2C00' && LA31_1<='\u2FEF')||(LA31_1>='\u3001' && LA31_1<='\uD7FF')||(LA31_1>='\uF900' && LA31_1<='\uFDCF')||(LA31_1>='\uFDF0' && LA31_1<='\uFFFD')) ) { - alt31=1; - } - - - } - else if ( (LA31_0=='.') ) { - alt31=1; - } - - - switch (alt31) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - if ( (input.LA(1)>='-' && input.LA(1)<='.')||(input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z')||input.LA(1)=='\u00B7'||(input.LA(1)>='\u00C0' && input.LA(1)<='\u00D6')||(input.LA(1)>='\u00D8' && input.LA(1)<='\u00F6')||(input.LA(1)>='\u00F8' && input.LA(1)<='\u037D')||(input.LA(1)>='\u037F' && input.LA(1)<='\u1FFF')||(input.LA(1)>='\u200C' && input.LA(1)<='\u200D')||(input.LA(1)>='\u203F' && input.LA(1)<='\u2040')||(input.LA(1)>='\u2070' && input.LA(1)<='\u218F')||(input.LA(1)>='\u2C00' && input.LA(1)<='\u2FEF')||(input.LA(1)>='\u3001' && input.LA(1)<='\uD7FF')||(input.LA(1)>='\uF900' && input.LA(1)<='\uFDCF')||(input.LA(1)>='\uFDF0' && input.LA(1)<='\uFFFD') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - break; - - default : - break loop31; - } - } while (true); - - mPN_CHARS(); - - } - break; - - } - - - } - - } - finally { - } - } - // $ANTLR end PN_PREFIX - - // $ANTLR start PN_LOCAL - public final void mPN_LOCAL() throws RecognitionException { - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:393:5: ( ( PN_CHARS_U | DIGIT ) ( ( PN_CHARS )* PN_CHARS )? ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:393:7: ( PN_CHARS_U | DIGIT ) ( ( PN_CHARS )* PN_CHARS )? - { - if ( (input.LA(1)>='0' && input.LA(1)<='9')||(input.LA(1)>='A' && input.LA(1)<='Z')||input.LA(1)=='_'||(input.LA(1)>='a' && input.LA(1)<='z')||(input.LA(1)>='\u00C0' && input.LA(1)<='\u00D6')||(input.LA(1)>='\u00D8' && input.LA(1)<='\u00F6')||(input.LA(1)>='\u00F8' && input.LA(1)<='\u02FF')||(input.LA(1)>='\u0370' && input.LA(1)<='\u037D')||(input.LA(1)>='\u037F' && input.LA(1)<='\u1FFF')||(input.LA(1)>='\u200C' && input.LA(1)<='\u200D')||(input.LA(1)>='\u2070' && input.LA(1)<='\u218F')||(input.LA(1)>='\u2C00' && input.LA(1)<='\u2FEF')||(input.LA(1)>='\u3001' && input.LA(1)<='\uD7FF')||(input.LA(1)>='\uF900' && input.LA(1)<='\uFDCF')||(input.LA(1)>='\uFDF0' && input.LA(1)<='\uFFFD') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:393:30: ( ( PN_CHARS )* PN_CHARS )? - int alt34=2; - int LA34_0 = input.LA(1); - - if ( (LA34_0=='-'||(LA34_0>='0' && LA34_0<='9')||(LA34_0>='A' && LA34_0<='Z')||LA34_0=='_'||(LA34_0>='a' && LA34_0<='z')||LA34_0=='\u00B7'||(LA34_0>='\u00C0' && LA34_0<='\u00D6')||(LA34_0>='\u00D8' && LA34_0<='\u00F6')||(LA34_0>='\u00F8' && LA34_0<='\u037D')||(LA34_0>='\u037F' && LA34_0<='\u1FFF')||(LA34_0>='\u200C' && LA34_0<='\u200D')||(LA34_0>='\u203F' && LA34_0<='\u2040')||(LA34_0>='\u2070' && LA34_0<='\u218F')||(LA34_0>='\u2C00' && LA34_0<='\u2FEF')||(LA34_0>='\u3001' && LA34_0<='\uD7FF')||(LA34_0>='\uF900' && LA34_0<='\uFDCF')||(LA34_0>='\uFDF0' && LA34_0<='\uFFFD')) ) { - alt34=1; - } - switch (alt34) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:393:31: ( PN_CHARS )* PN_CHARS - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:393:31: ( PN_CHARS )* - loop33: - do { - int alt33=2; - int LA33_0 = input.LA(1); - - if ( (LA33_0=='-'||(LA33_0>='0' && LA33_0<='9')||(LA33_0>='A' && LA33_0<='Z')||LA33_0=='_'||(LA33_0>='a' && LA33_0<='z')||LA33_0=='\u00B7'||(LA33_0>='\u00C0' && LA33_0<='\u00D6')||(LA33_0>='\u00D8' && LA33_0<='\u00F6')||(LA33_0>='\u00F8' && LA33_0<='\u037D')||(LA33_0>='\u037F' && LA33_0<='\u1FFF')||(LA33_0>='\u200C' && LA33_0<='\u200D')||(LA33_0>='\u203F' && LA33_0<='\u2040')||(LA33_0>='\u2070' && LA33_0<='\u218F')||(LA33_0>='\u2C00' && LA33_0<='\u2FEF')||(LA33_0>='\u3001' && LA33_0<='\uD7FF')||(LA33_0>='\uF900' && LA33_0<='\uFDCF')||(LA33_0>='\uFDF0' && LA33_0<='\uFFFD')) ) { - int LA33_1 = input.LA(2); - - if ( (LA33_1=='-'||(LA33_1>='0' && LA33_1<='9')||(LA33_1>='A' && LA33_1<='Z')||LA33_1=='_'||(LA33_1>='a' && LA33_1<='z')||LA33_1=='\u00B7'||(LA33_1>='\u00C0' && LA33_1<='\u00D6')||(LA33_1>='\u00D8' && LA33_1<='\u00F6')||(LA33_1>='\u00F8' && LA33_1<='\u037D')||(LA33_1>='\u037F' && LA33_1<='\u1FFF')||(LA33_1>='\u200C' && LA33_1<='\u200D')||(LA33_1>='\u203F' && LA33_1<='\u2040')||(LA33_1>='\u2070' && LA33_1<='\u218F')||(LA33_1>='\u2C00' && LA33_1<='\u2FEF')||(LA33_1>='\u3001' && LA33_1<='\uD7FF')||(LA33_1>='\uF900' && LA33_1<='\uFDCF')||(LA33_1>='\uFDF0' && LA33_1<='\uFFFD')) ) { - alt33=1; - } - - - } - - - switch (alt33) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:393:32: PN_CHARS - { - mPN_CHARS(); - - } - break; - - default : - break loop33; - } - } while (true); - - mPN_CHARS(); - - } - break; - - } - - - } - - } - finally { - } - } - // $ANTLR end PN_LOCAL - - // $ANTLR start PN_CHARS_BASE - public final void mPN_CHARS_BASE() throws RecognitionException { - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:398:5: ( 'A' .. 'Z' | 'a' .. 'z' | '\\u00C0' .. '\\u00D6' | '\\u00D8' .. '\\u00F6' | '\\u00F8' .. '\\u02FF' | '\\u0370' .. '\\u037D' | '\\u037F' .. '\\u1FFF' | '\\u200C' .. '\\u200D' | '\\u2070' .. '\\u218F' | '\\u2C00' .. '\\u2FEF' | '\\u3001' .. '\\uD7FF' | '\\uF900' .. '\\uFDCF' | '\\uFDF0' .. '\\uFFFD' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - if ( (input.LA(1)>='A' && input.LA(1)<='Z')||(input.LA(1)>='a' && input.LA(1)<='z')||(input.LA(1)>='\u00C0' && input.LA(1)<='\u00D6')||(input.LA(1)>='\u00D8' && input.LA(1)<='\u00F6')||(input.LA(1)>='\u00F8' && input.LA(1)<='\u02FF')||(input.LA(1)>='\u0370' && input.LA(1)<='\u037D')||(input.LA(1)>='\u037F' && input.LA(1)<='\u1FFF')||(input.LA(1)>='\u200C' && input.LA(1)<='\u200D')||(input.LA(1)>='\u2070' && input.LA(1)<='\u218F')||(input.LA(1)>='\u2C00' && input.LA(1)<='\u2FEF')||(input.LA(1)>='\u3001' && input.LA(1)<='\uD7FF')||(input.LA(1)>='\uF900' && input.LA(1)<='\uFDCF')||(input.LA(1)>='\uFDF0' && input.LA(1)<='\uFFFD') ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - - } - finally { - } - } - // $ANTLR end PN_CHARS_BASE - - // $ANTLR start DIGIT - public final void mDIGIT() throws RecognitionException { - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:415:5: ( '0' .. '9' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:415:7: '0' .. '9' - { - matchRange('0','9'); - - } - - } - finally { - } - } - // $ANTLR end DIGIT - - // $ANTLR start COMMENT - public final void mCOMMENT() throws RecognitionException { - try { - int _type = COMMENT; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:419:5: ( '//' ( options {greedy=false; } : . )* EOL ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:419:7: '//' ( options {greedy=false; } : . )* EOL - { - match("//"); - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:419:12: ( options {greedy=false; } : . )* - loop35: - do { - int alt35=2; - int LA35_0 = input.LA(1); - - if ( (LA35_0=='\n'||LA35_0=='\r') ) { - alt35=2; - } - else if ( ((LA35_0>='\u0000' && LA35_0<='\t')||(LA35_0>='\u000B' && LA35_0<='\f')||(LA35_0>='\u000E' && LA35_0<='\uFFFE')) ) { - alt35=1; - } - - - switch (alt35) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:419:39: . - { - matchAny(); - - } - break; - - default : - break loop35; - } - } while (true); - - mEOL(); - channel=HIDDEN; - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end COMMENT - - // $ANTLR start EOL - public final void mEOL() throws RecognitionException { - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:424:5: ( '\\n' | '\\r' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - if ( input.LA(1)=='\n'||input.LA(1)=='\r' ) { - input.consume(); - - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recover(mse); throw mse; - } - - - } - - } - finally { - } - } - // $ANTLR end EOL - - // $ANTLR start REFERENCE - public final void mREFERENCE() throws RecognitionException { - try { - int _type = REFERENCE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:428:5: ( '^^' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:428:7: '^^' - { - match("^^"); - - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end REFERENCE - - // $ANTLR start EXCLAMATION - public final void mEXCLAMATION() throws RecognitionException { - try { - int _type = EXCLAMATION; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:431:2: ( '!' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:431:4: '!' - { - match('!'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end EXCLAMATION - - // $ANTLR start QUESTION - public final void mQUESTION() throws RecognitionException { - try { - int _type = QUESTION; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:434:2: ( '?' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:434:4: '?' - { - match('?'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end QUESTION - - // $ANTLR start DOT - public final void mDOT() throws RecognitionException { - try { - int _type = DOT; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:436:5: ( '.' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:436:7: '.' - { - match('.'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end DOT - - // $ANTLR start COMMA - public final void mCOMMA() throws RecognitionException { - try { - int _type = COMMA; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:439:7: ( ',' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:439:9: ',' - { - match(','); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end COMMA - - // $ANTLR start SEMICOLON - public final void mSEMICOLON() throws RecognitionException { - try { - int _type = SEMICOLON; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:446:2: ( ';' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:446:4: ';' - { - match(';'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end SEMICOLON - - // $ANTLR start AMPERSAND - public final void mAMPERSAND() throws RecognitionException { - try { - int _type = AMPERSAND; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:450:2: ( '&' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:450:4: '&' - { - match('&'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end AMPERSAND - - // $ANTLR start BAR - public final void mBAR() throws RecognitionException { - try { - int _type = BAR; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:452:5: ( '|' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:452:7: '|' - { - match('|'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end BAR - - // $ANTLR start LANGLE - public final void mLANGLE() throws RecognitionException { - try { - int _type = LANGLE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:455:8: ( '<' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:455:10: '<' - { - match('<'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end LANGLE - - // $ANTLR start RANGLE - public final void mRANGLE() throws RecognitionException { - try { - int _type = RANGLE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:458:9: ( '>' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:458:11: '>' - { - match('>'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end RANGLE - - // $ANTLR start PERCENT - public final void mPERCENT() throws RecognitionException { - try { - int _type = PERCENT; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:461:9: ( '%' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:461:11: '%' - { - match('%'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end PERCENT - - // $ANTLR start PLUS - public final void mPLUS() throws RecognitionException { - try { - int _type = PLUS; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:464:6: ( '+' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:464:8: '+' - { - match('+'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end PLUS - - // $ANTLR start MINUS - public final void mMINUS() throws RecognitionException { - try { - int _type = MINUS; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:467:7: ( '-' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:467:9: '-' - { - match('-'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end MINUS - - // $ANTLR start STAR - public final void mSTAR() throws RecognitionException { - try { - int _type = STAR; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:470:6: ( '*' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:470:8: '*' - { - match('*'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end STAR - - // $ANTLR start TILDE - public final void mTILDE() throws RecognitionException { - try { - int _type = TILDE; - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:473:8: ( '~' ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:473:10: '~' - { - match('~'); - - } - - this.type = _type; - } - finally { - } - } - // $ANTLR end TILDE - - public void mTokens() throws RecognitionException { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:8: ( WS | AT_IMPORT | AT_PREFIX | AT_BASE | AT_DELAY | INHERITANCE | SIMILARITY | INSTANCE | PROPERTY | INSTANCE_PROPERTY | IMPLICATION | IMPLICATION_PRED | IMPLICATION_RETRO | IMPLICATION_CONC | EQUIVALENCE | EQUIVALENCE_PRED | EQUIVALENCE_CONC | NOT | PAST | PRESENT | FUTURE | CONJ | DISJ | OPEN_BRACE | CLOSE_BRACE | LPAREN | RPAREN | LBRACKET | RBRACKET | PNAME_NS | PNAME_LN | TRUE | FALSE | IRI_REF | LANGTAG | QUERY_VAR | STM_VAR | INTEGER | DECIMAL | DOUBLE | INTEGER_POSITIVE | DECIMAL_POSITIVE | DOUBLE_POSITIVE | INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE | STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2 | COMMENT | REFERENCE | EXCLAMATION | QUESTION | DOT | COMMA | SEMICOLON | AMPERSAND | BAR | LANGLE | RANGLE | PERCENT | PLUS | MINUS | STAR | TILDE ) - int alt36=66; - alt36 = dfa36.predict(input); - switch (alt36) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:10: WS - { - mWS(); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:13: AT_IMPORT - { - mAT_IMPORT(); - - } - break; - case 3 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:23: AT_PREFIX - { - mAT_PREFIX(); - - } - break; - case 4 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:33: AT_BASE - { - mAT_BASE(); - - } - break; - case 5 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:41: AT_DELAY - { - mAT_DELAY(); - - } - break; - case 6 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:50: INHERITANCE - { - mINHERITANCE(); - - } - break; - case 7 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:62: SIMILARITY - { - mSIMILARITY(); - - } - break; - case 8 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:73: INSTANCE - { - mINSTANCE(); - - } - break; - case 9 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:82: PROPERTY - { - mPROPERTY(); - - } - break; - case 10 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:91: INSTANCE_PROPERTY - { - mINSTANCE_PROPERTY(); - - } - break; - case 11 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:109: IMPLICATION - { - mIMPLICATION(); - - } - break; - case 12 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:121: IMPLICATION_PRED - { - mIMPLICATION_PRED(); - - } - break; - case 13 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:138: IMPLICATION_RETRO - { - mIMPLICATION_RETRO(); - - } - break; - case 14 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:156: IMPLICATION_CONC - { - mIMPLICATION_CONC(); - - } - break; - case 15 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:173: EQUIVALENCE - { - mEQUIVALENCE(); - - } - break; - case 16 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:185: EQUIVALENCE_PRED - { - mEQUIVALENCE_PRED(); - - } - break; - case 17 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:202: EQUIVALENCE_CONC - { - mEQUIVALENCE_CONC(); - - } - break; - case 18 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:219: NOT - { - mNOT(); - - } - break; - case 19 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:223: PAST - { - mPAST(); - - } - break; - case 20 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:228: PRESENT - { - mPRESENT(); - - } - break; - case 21 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:236: FUTURE - { - mFUTURE(); - - } - break; - case 22 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:243: CONJ - { - mCONJ(); - - } - break; - case 23 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:248: DISJ - { - mDISJ(); - - } - break; - case 24 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:253: OPEN_BRACE - { - mOPEN_BRACE(); - - } - break; - case 25 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:264: CLOSE_BRACE - { - mCLOSE_BRACE(); - - } - break; - case 26 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:276: LPAREN - { - mLPAREN(); - - } - break; - case 27 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:283: RPAREN - { - mRPAREN(); - - } - break; - case 28 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:290: LBRACKET - { - mLBRACKET(); - - } - break; - case 29 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:299: RBRACKET - { - mRBRACKET(); - - } - break; - case 30 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:308: PNAME_NS - { - mPNAME_NS(); - - } - break; - case 31 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:317: PNAME_LN - { - mPNAME_LN(); - - } - break; - case 32 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:326: TRUE - { - mTRUE(); - - } - break; - case 33 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:331: FALSE - { - mFALSE(); - - } - break; - case 34 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:337: IRI_REF - { - mIRI_REF(); - - } - break; - case 35 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:345: LANGTAG - { - mLANGTAG(); - - } - break; - case 36 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:353: QUERY_VAR - { - mQUERY_VAR(); - - } - break; - case 37 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:363: STM_VAR - { - mSTM_VAR(); - - } - break; - case 38 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:371: INTEGER - { - mINTEGER(); - - } - break; - case 39 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:379: DECIMAL - { - mDECIMAL(); - - } - break; - case 40 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:387: DOUBLE - { - mDOUBLE(); - - } - break; - case 41 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:394: INTEGER_POSITIVE - { - mINTEGER_POSITIVE(); - - } - break; - case 42 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:411: DECIMAL_POSITIVE - { - mDECIMAL_POSITIVE(); - - } - break; - case 43 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:428: DOUBLE_POSITIVE - { - mDOUBLE_POSITIVE(); - - } - break; - case 44 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:444: INTEGER_NEGATIVE - { - mINTEGER_NEGATIVE(); - - } - break; - case 45 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:461: DECIMAL_NEGATIVE - { - mDECIMAL_NEGATIVE(); - - } - break; - case 46 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:478: DOUBLE_NEGATIVE - { - mDOUBLE_NEGATIVE(); - - } - break; - case 47 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:494: STRING_LITERAL1 - { - mSTRING_LITERAL1(); - - } - break; - case 48 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:510: STRING_LITERAL2 - { - mSTRING_LITERAL2(); - - } - break; - case 49 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:526: STRING_LITERAL_LONG1 - { - mSTRING_LITERAL_LONG1(); - - } - break; - case 50 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:547: STRING_LITERAL_LONG2 - { - mSTRING_LITERAL_LONG2(); - - } - break; - case 51 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:568: COMMENT - { - mCOMMENT(); - - } - break; - case 52 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:576: REFERENCE - { - mREFERENCE(); - - } - break; - case 53 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:586: EXCLAMATION - { - mEXCLAMATION(); - - } - break; - case 54 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:598: QUESTION - { - mQUESTION(); - - } - break; - case 55 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:607: DOT - { - mDOT(); - - } - break; - case 56 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:611: COMMA - { - mCOMMA(); - - } - break; - case 57 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:617: SEMICOLON - { - mSEMICOLON(); - - } - break; - case 58 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:627: AMPERSAND - { - mAMPERSAND(); - - } - break; - case 59 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:637: BAR - { - mBAR(); - - } - break; - case 60 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:641: LANGLE - { - mLANGLE(); - - } - break; - case 61 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:648: RANGLE - { - mRANGLE(); - - } - break; - case 62 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:655: PERCENT - { - mPERCENT(); - - } - break; - case 63 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:663: PLUS - { - mPLUS(); - - } - break; - case 64 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:668: MINUS - { - mMINUS(); - - } - break; - case 65 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:674: STAR - { - mSTAR(); - - } - break; - case 66 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:1:679: TILDE - { - mTILDE(); - - } - break; - - } - - } - - - protected DFA19 dfa19 = new DFA19(this); - protected DFA36 dfa36 = new DFA36(this); - static final String DFA19_eotS = - "\5\uffff"; - static final String DFA19_eofS = - "\5\uffff"; - static final String DFA19_minS = - "\2\56\3\uffff"; - static final String DFA19_maxS = - "\1\71\1\145\3\uffff"; - static final String DFA19_acceptS = - "\2\uffff\1\2\1\1\1\3"; - static final String DFA19_specialS = - "\5\uffff}>"; - static final String[] DFA19_transitionS = { - "\1\2\1\uffff\12\1", - "\1\3\1\uffff\12\1\13\uffff\1\4\37\uffff\1\4", - "", - "", - "" - }; - - static final short[] DFA19_eot = DFA.unpackEncodedString(DFA19_eotS); - static final short[] DFA19_eof = DFA.unpackEncodedString(DFA19_eofS); - static final char[] DFA19_min = DFA.unpackEncodedStringToUnsignedChars(DFA19_minS); - static final char[] DFA19_max = DFA.unpackEncodedStringToUnsignedChars(DFA19_maxS); - static final short[] DFA19_accept = DFA.unpackEncodedString(DFA19_acceptS); - static final short[] DFA19_special = DFA.unpackEncodedString(DFA19_specialS); - static final short[][] DFA19_transition; - - static { - int numStates = DFA19_transitionS.length; - DFA19_transition = new short[numStates][]; - for (int i=0; i<numStates; i++) { - DFA19_transition[i] = DFA.unpackEncodedString(DFA19_transitionS[i]); - } - } - - class DFA19 extends DFA { - - public DFA19(BaseRecognizer recognizer) { - this.recognizer = recognizer; - this.decisionNumber = 19; - this.eot = DFA19_eot; - this.eof = DFA19_eof; - this.min = DFA19_min; - this.max = DFA19_max; - this.accept = DFA19_accept; - this.special = DFA19_special; - this.transition = DFA19_transition; - } - public String getDescription() { - return "310:1: DOUBLE : ( ( DIGIT )+ DOT ( DIGIT )* EXPONENT | DOT ( DIGIT )+ EXPONENT | ( DIGIT )+ EXPONENT );"; - } - } - static final String DFA36_eotS = - "\3\uffff\1\51\1\60\1\63\1\uffff\1\71\1\uffff\1\74\1\uffff\1\100"+ - "\6\uffff\1\104\2\uffff\1\107\1\uffff\1\111\1\114\1\116\11\uffff"+ - "\4\47\3\uffff\1\133\37\uffff\1\146\2\uffff\1\146\1\uffff\1\150\1"+ - "\uffff\1\122\1\uffff\1\124\1\uffff\4\47\3\uffff\1\162\1\uffff\1"+ - "\162\10\uffff\1\146\1\uffff\1\171\1\uffff\1\171\2\uffff\4\47\1\uffff"+ - "\1\162\3\uffff\1\177\2\uffff\1\171\3\47\1\u0084\1\uffff\1\u0085"+ - "\2\47\1\u0088\2\uffff\1\u0089\1\u008a\3\uffff"; - static final String DFA36_eofS = - "\u008b\uffff"; - static final String DFA36_minS = - "\1\11\1\uffff\1\101\1\55\1\41\1\55\1\57\1\41\1\uffff\1\76\1\57\1"+ - "\46\5\uffff\1\55\1\60\2\55\1\60\1\uffff\1\56\1\60\1\56\2\0\7\uffff"+ - "\1\155\1\162\1\145\1\141\1\uffff\1\76\1\uffff\1\56\1\60\2\41\1\uffff"+ - "\1\41\2\uffff\1\76\16\uffff\3\55\2\uffff\1\55\3\uffff\1\60\2\uffff"+ - "\1\60\1\uffff\1\56\1\60\1\47\1\uffff\1\42\1\uffff\1\160\1\145\1"+ - "\154\1\163\3\uffff\1\60\1\uffff\1\60\5\uffff\2\55\1\uffff\1\60\1"+ - "\uffff\1\60\1\uffff\1\60\2\uffff\1\157\1\146\1\141\1\145\1\uffff"+ - "\1\60\3\uffff\2\55\1\uffff\1\60\1\162\1\151\1\171\1\55\1\uffff\1"+ - "\55\1\164\1\170\1\55\2\uffff\2\55\3\uffff"; - static final String DFA36_maxS = - "\1\ufffd\1\uffff\1\ufffd\1\71\1\ufffe\1\55\1\174\1\41\1\uffff\1"+ - "\174\1\76\1\46\5\uffff\5\ufffd\1\uffff\1\145\2\71\2\ufffe\7\uffff"+ - "\1\155\1\162\1\145\1\141\1\uffff\1\133\1\uffff\1\145\1\71\2\ufffe"+ - "\1\uffff\1\ufffe\2\uffff\1\133\16\uffff\3\ufffd\2\uffff\1\ufffd"+ - "\3\uffff\1\145\2\uffff\1\145\1\uffff\1\145\1\71\1\47\1\uffff\1\42"+ - "\1\uffff\1\160\1\145\1\154\1\163\3\uffff\1\145\1\uffff\1\145\5\uffff"+ - "\2\ufffd\1\uffff\1\145\1\uffff\1\145\1\uffff\1\145\2\uffff\1\157"+ - "\1\146\1\141\1\145\1\uffff\1\145\3\uffff\2\ufffd\1\uffff\1\145\1"+ - "\162\1\151\1\171\1\ufffd\1\uffff\1\ufffd\1\164\1\170\1\ufffd\2\uffff"+ - "\2\ufffd\3\uffff"; - static final String DFA36_acceptS = - "\1\uffff\1\1\6\uffff\1\23\3\uffff\1\30\1\32\1\33\1\34\1\35\5\uffff"+ - "\1\45\5\uffff\1\64\1\70\1\71\1\75\1\76\1\101\1\102\4\uffff\1\43"+ - "\1\uffff\1\100\4\uffff\1\21\1\uffff\1\74\1\42\1\uffff\1\31\1\14"+ - "\1\13\1\15\1\16\1\22\1\65\1\24\1\27\1\73\1\25\1\63\1\26\1\72\3\uffff"+ - "\1\36\1\37\1\uffff\1\66\1\44\1\46\1\uffff\1\50\1\67\1\uffff\1\77"+ - "\3\uffff\1\57\1\uffff\1\60\4\uffff\1\11\1\6\1\54\1\uffff\1\56\1"+ - "\uffff\1\17\1\7\1\20\1\12\1\10\2\uffff\1\47\1\uffff\1\51\1\uffff"+ - "\1\53\1\uffff\1\61\1\62\4\uffff\1\55\1\uffff\1\17\1\7\1\20\2\uffff"+ - "\1\52\5\uffff\1\40\4\uffff\1\4\1\41\2\uffff\1\5\1\2\1\3"; - static final String DFA36_specialS = - "\u008b\uffff}>"; - static final String[] DFA36_transitionS = { - "\2\1\2\uffff\1\1\22\uffff\1\1\1\7\1\33\1\26\1\uffff\1\40\1\13"+ - "\1\32\1\15\1\16\1\41\1\31\1\35\1\3\1\30\1\12\12\27\1\22\1\36"+ - "\1\4\1\6\1\37\1\25\1\2\5\24\1\23\15\24\1\21\6\24\1\17\1\10\1"+ - "\20\1\34\2\uffff\5\24\1\23\15\24\1\21\6\24\1\14\1\11\1\5\1\42"+ - "\101\uffff\27\24\1\uffff\37\24\1\uffff\u0208\24\160\uffff\16"+ - "\24\1\uffff\u1c81\24\14\uffff\2\24\142\uffff\u0120\24\u0a70"+ - "\uffff\u03f0\24\21\uffff\ua7ff\24\u2100\uffff\u04d0\24\40\uffff"+ - "\u020e\24", - "", - "\32\47\6\uffff\1\47\1\46\1\47\1\45\4\47\1\43\6\47\1\44\12\47"+ - "\105\uffff\27\47\1\uffff\37\47\1\uffff\u0208\47\160\uffff\16"+ - "\47\1\uffff\u1c81\47\14\uffff\2\47\142\uffff\u0120\47\u0a70"+ - "\uffff\u03f0\47\21\uffff\ua7ff\47\u2100\uffff\u04d0\47\40\uffff"+ - "\u020e\47", - "\1\50\1\53\1\uffff\12\52", - "\1\61\1\uffff\12\61\1\55\1\61\1\57\14\61\1\uffff\1\54\36\61"+ - "\1\uffff\1\61\1\uffff\1\61\1\uffff\32\61\1\uffff\1\56\1\uffff"+ - "\uff81\61", - "\1\62", - "\1\64\15\uffff\1\65\36\uffff\1\66\37\uffff\1\67", - "\1\70", - "", - "\1\72\75\uffff\1\73", - "\1\76\16\uffff\1\75", - "\1\77", - "", - "", - "", - "", - "", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\21\102\1\101\10\102"+ - "\4\uffff\1\102\1\uffff\21\102\1\101\10\102\74\uffff\1\102\10"+ - "\uffff\27\102\1\uffff\37\102\1\uffff\u0286\102\1\uffff\u1c81"+ - "\102\14\uffff\2\102\61\uffff\2\102\57\uffff\u0120\102\u0a70"+ - "\uffff\u03f0\102\21\uffff\ua7ff\102\u2100\uffff\u04d0\102\40"+ - "\uffff\u020e\102", - "\12\105\7\uffff\32\105\4\uffff\1\105\1\uffff\32\105\105\uffff"+ - "\27\105\1\uffff\37\105\1\uffff\u0208\105\160\uffff\16\105\1"+ - "\uffff\u1c81\105\14\uffff\2\105\142\uffff\u0120\105\u0a70\uffff"+ - "\u03f0\105\21\uffff\ua7ff\105\u2100\uffff\u04d0\105\40\uffff"+ - "\u020e\105", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\1\106\31\102\4\uffff"+ - "\1\102\1\uffff\1\106\31\102\74\uffff\1\102\10\uffff\27\102\1"+ - "\uffff\37\102\1\uffff\u0286\102\1\uffff\u1c81\102\14\uffff\2"+ - "\102\61\uffff\2\102\57\uffff\u0120\102\u0a70\uffff\u03f0\102"+ - "\21\uffff\ua7ff\102\u2100\uffff\u04d0\102\40\uffff\u020e\102", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\32\102\4\uffff\1\102"+ - "\1\uffff\32\102\74\uffff\1\102\10\uffff\27\102\1\uffff\37\102"+ - "\1\uffff\u0286\102\1\uffff\u1c81\102\14\uffff\2\102\61\uffff"+ - "\2\102\57\uffff\u0120\102\u0a70\uffff\u03f0\102\21\uffff\ua7ff"+ - "\102\u2100\uffff\u04d0\102\40\uffff\u020e\102", - "\12\110\7\uffff\32\110\4\uffff\1\110\1\uffff\32\110\105\uffff"+ - "\27\110\1\uffff\37\110\1\uffff\u0208\110\160\uffff\16\110\1"+ - "\uffff\u1c81\110\14\uffff\2\110\142\uffff\u0120\110\u0a70\uffff"+ - "\u03f0\110\21\uffff\ua7ff\110\u2100\uffff\u04d0\110\40\uffff"+ - "\u020e\110", - "", - "\1\112\1\uffff\12\27\13\uffff\1\113\37\uffff\1\113", - "\12\115", - "\1\120\1\uffff\12\117", - "\12\122\1\uffff\2\122\1\uffff\31\122\1\121\uffd7\122", - "\12\124\1\uffff\2\124\1\uffff\24\124\1\123\uffdc\124", - "", - "", - "", - "", - "", - "", - "", - "\1\125", - "\1\126", - "\1\127", - "\1\130", - "", - "\1\132\34\uffff\1\131", - "", - "\1\134\1\uffff\12\52\13\uffff\1\135\37\uffff\1\135", - "\12\136", - "\1\61\1\uffff\31\61\1\uffff\1\61\1\137\35\61\1\uffff\1\61\1"+ - "\uffff\1\61\1\uffff\32\61\3\uffff\uff81\61", - "\1\61\1\uffff\31\61\1\uffff\1\61\1\140\35\61\1\uffff\1\61\1"+ - "\uffff\1\61\1\uffff\32\61\3\uffff\uff81\61", - "", - "\1\61\1\uffff\31\61\1\uffff\1\61\1\141\35\61\1\uffff\1\61\1"+ - "\uffff\1\61\1\uffff\32\61\3\uffff\uff81\61", - "", - "", - "\1\143\34\uffff\1\142", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\24\102\1\144\5\102"+ - "\4\uffff\1\102\1\uffff\24\102\1\144\5\102\74\uffff\1\102\10"+ - "\uffff\27\102\1\uffff\37\102\1\uffff\u0286\102\1\uffff\u1c81"+ - "\102\14\uffff\2\102\61\uffff\2\102\57\uffff\u0120\102\u0a70"+ - "\uffff\u03f0\102\21\uffff\ua7ff\102\u2100\uffff\u04d0\102\40"+ - "\uffff\u020e\102", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\32\102\4\uffff\1\102"+ - "\1\uffff\32\102\74\uffff\1\102\10\uffff\27\102\1\uffff\37\102"+ - "\1\uffff\u0286\102\1\uffff\u1c81\102\14\uffff\2\102\61\uffff"+ - "\2\102\57\uffff\u0120\102\u0a70\uffff\u03f0\102\21\uffff\ua7ff"+ - "\102\u2100\uffff\u04d0\102\40\uffff\u020e\102", - "\1\102\1\103\1\uffff\12\102\7\uffff\32\102\4\uffff\1\102\1\uffff"+ - "\32\102\74\uffff\1\102\10\uffff\27\102\1\uffff\37\102\1\uffff"+ - "\u0286\102\1\uffff\u1c81\102\14\uffff\2\102\61\uffff\2\102\57"+ - "\uffff\u0120\102\u0a70\uffff\u03f0\102\21\uffff\ua7ff\102\u2100"+ - "\uffff\u04d0\102\40\uffff\u020e\102", - "", - "", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\13\102\1\145\16\102"+ - "\4\uffff\1\102\1\uffff\13\102\1\145\16\102\74\uffff\1\102\10"+ - "\uffff\27\102\1\uffff\37\102\1\uffff\u0286\102\1\uffff\u1c81"+ - "\102\14\uffff\2\102\61\uffff\2\102\57\uffff\u0120\102\u0a70"+ - "\uffff\u03f0\102\21\uffff\ua7ff\102\u2100\uffff\u04d0\102\40"+ - "\uffff\u020e\102", - "", - "", - "", - "\12\147\13\uffff\1\113\37\uffff\1\113", - "", - "", - "\12\115\13\uffff\1\113\37\uffff\1\113", - "", - "\1\151\1\uffff\12\117\13\uffff\1\152\37\uffff\1\152", - "\12\153", - "\1\154", - "", - "\1\155", - "", - "\1\156", - "\1\157", - "\1\160", - "\1\161", - "", - "", - "", - "\12\163\13\uffff\1\135\37\uffff\1\135", - "", - "\12\136\13\uffff\1\135\37\uffff\1\135", - "", - "", - "", - "", - "", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\4\102\1\167\25\102"+ - "\4\uffff\1\102\1\uffff\4\102\1\167\25\102\74\uffff\1\102\10"+ - "\uffff\27\102\1\uffff\37\102\1\uffff\u0286\102\1\uffff\u1c81"+ - "\102\14\uffff\2\102\61\uffff\2\102\57\uffff\u0120\102\u0a70"+ - "\uffff\u03f0\102\21\uffff\ua7ff\102\u2100\uffff\u04d0\102\40"+ - "\uffff\u020e\102", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\22\102\1\170\7\102"+ - "\4\uffff\1\102\1\uffff\22\102\1\170\7\102\74\uffff\1\102\10"+ - "\uffff\27\102\1\uffff\37\102\1\uffff\u0286\102\1\uffff\u1c81"+ - "\102\14\uffff\2\102\61\uffff\2\102\57\uffff\u0120\102\u0a70"+ - "\uffff\u03f0\102\21\uffff\ua7ff\102\u2100\uffff\u04d0\102\40"+ - "\uffff\u020e\102", - "", - "\12\147\13\uffff\1\113\37\uffff\1\113", - "", - "\12\172\13\uffff\1\152\37\uffff\1\152", - "", - "\12\153\13\uffff\1\152\37\uffff\1\152", - "", - "", - "\1\173", - "\1\174", - "\1\175", - "\1\176", - "", - "\12\163\13\uffff\1\135\37\uffff\1\135", - "", - "", - "", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\32\102\4\uffff\1\102"+ - "\1\uffff\32\102\74\uffff\1\102\10\uffff\27\102\1\uffff\37\102"+ - "\1\uffff\u0286\102\1\uffff\u1c81\102\14\uffff\2\102\61\uffff"+ - "\2\102\57\uffff\u0120\102\u0a70\uffff\u03f0\102\21\uffff\ua7ff"+ - "\102\u2100\uffff\u04d0\102\40\uffff\u020e\102", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\4\102\1\u0080\25\102"+ - "\4\uffff\1\102\1\uffff\4\102\1\u0080\25\102\74\uffff\1\102\10"+ - "\uffff\27\102\1\uffff\37\102\1\uffff\u0286\102\1\uffff\u1c81"+ - "\102\14\uffff\2\102\61\uffff\2\102\57\uffff\u0120\102\u0a70"+ - "\uffff\u03f0\102\21\uffff\ua7ff\102\u2100\uffff\u04d0\102\40"+ - "\uffff\u020e\102", - "", - "\12\172\13\uffff\1\152\37\uffff\1\152", - "\1\u0081", - "\1\u0082", - "\1\u0083", - "\1\47\23\uffff\32\47\6\uffff\32\47\105\uffff\27\47\1\uffff\37"+ - "\47\1\uffff\u0208\47\160\uffff\16\47\1\uffff\u1c81\47\14\uffff"+ - "\2\47\142\uffff\u0120\47\u0a70\uffff\u03f0\47\21\uffff\ua7ff"+ - "\47\u2100\uffff\u04d0\47\40\uffff\u020e\47", - "", - "\1\102\1\103\1\uffff\12\102\1\22\6\uffff\32\102\4\uffff\1\102"+ - "\1\uffff\32\102\74\uffff\1\102\10\uffff\27\102\1\uffff\37\102"+ - "\1\uffff\u0286\102\1\uffff\u1c81\102\14\uffff\2\102\61\uffff"+ - "\2\102\57\uffff\u0120\102\u0a70\uffff\u03f0\102\21\uffff\ua7ff"+ - "\102\u2100\uffff\u04d0\102\40\uffff\u020e\102", - "\1\u0086", - "\1\u0087", - "\1\47\23\uffff\32\47\6\uffff\32\47\105\uffff\27\47\1\uffff\37"+ - "\47\1\uffff\u0208\47\160\uffff\16\47\1\uffff\u1c81\47\14\uffff"+ - "\2\47\142\uffff\u0120\47\u0a70\uffff\u03f0\47\21\uffff\ua7ff"+ - "\47\u2100\uffff\u04d0\47\40\uffff\u020e\47", - "", - "", - "\1\47\23\uffff\32\47\6\uffff\32\47\105\uffff\27\47\1\uffff\37"+ - "\47\1\uffff\u0208\47\160\uffff\16\47\1\uffff\u1c81\47\14\uffff"+ - "\2\47\142\uffff\u0120\47\u0a70\uffff\u03f0\47\21\uffff\ua7ff"+ - "\47\u2100\uffff\u04d0\47\40\uffff\u020e\47", - "\1\47\23\uffff\32\47\6\uffff\32\47\105\uffff\27\47\1\uffff\37"+ - "\47\1\uffff\u0208\47\160\uffff\16\47\1\uffff\u1c81\47\14\uffff"+ - "\2\47\142\uffff\u0120\47\u0a70\uffff\u03f0\47\21\uffff\ua7ff"+ - "\47\u2100\uffff\u04d0\47\40\uffff\u020e\47", - "", - "", - "" - }; - - static final short[] DFA36_eot = DFA.unpackEncodedString(DFA36_eotS); - static final short[] DFA36_eof = DFA.unpackEncodedString(DFA36_eofS); - static final char[] DFA36_min = DFA.unpackEncodedStringToUnsignedChars(DFA36_minS); - static final char[] DFA36_max = DFA.unpackEncodedStringToUnsignedChars(DFA36_maxS); - static final short[] DFA36_accept = DFA.unpackEncodedString(DFA36_acceptS); - static final short[] DFA36_special = DFA.unpackEncodedString(DFA36_specialS); - static final short[][] DFA36_transition; - - static { - int numStates = DFA36_transitionS.length; - DFA36_transition = new short[numStates][]; - for (int i=0; i<numStates; i++) { - DFA36_transition[i] = DFA.unpackEncodedString(DFA36_transitionS[i]); - } - } - - class DFA36 extends DFA { - - public DFA36(BaseRecognizer recognizer) { - this.recognizer = recognizer; - this.decisionNumber = 36; - this.eot = DFA36_eot; - this.eof = DFA36_eof; - this.min = DFA36_min; - this.max = DFA36_max; - this.accept = DFA36_accept; - this.special = DFA36_special; - this.transition = DFA36_transition; - } - public String getDescription() { - return "1:1: Tokens : ( WS | AT_IMPORT | AT_PREFIX | AT_BASE | AT_DELAY | INHERITANCE | SIMILARITY | INSTANCE | PROPERTY | INSTANCE_PROPERTY | IMPLICATION | IMPLICATION_PRED | IMPLICATION_RETRO | IMPLICATION_CONC | EQUIVALENCE | EQUIVALENCE_PRED | EQUIVALENCE_CONC | NOT | PAST | PRESENT | FUTURE | CONJ | DISJ | OPEN_BRACE | CLOSE_BRACE | LPAREN | RPAREN | LBRACKET | RBRACKET | PNAME_NS | PNAME_LN | TRUE | FALSE | IRI_REF | LANGTAG | QUERY_VAR | STM_VAR | INTEGER | DECIMAL | DOUBLE | INTEGER_POSITIVE | DECIMAL_POSITIVE | DOUBLE_POSITIVE | INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE | STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2 | COMMENT | REFERENCE | EXCLAMATION | QUESTION | DOT | COMMA | SEMICOLON | AMPERSAND | BAR | LANGLE | RANGLE | PERCENT | PLUS | MINUS | STAR | TILDE );"; - } - } - - -} \ No newline at end of file diff --git a/open-nars/com/googlecode/opennars/parser/loan/loanParser.java b/open-nars/com/googlecode/opennars/parser/loan/loanParser.java deleted file mode 100644 index b70c73316a1141e30a0fec94c0723a9299a73c29..0000000000000000000000000000000000000000 --- a/open-nars/com/googlecode/opennars/parser/loan/loanParser.java +++ /dev/null @@ -1,3160 +0,0 @@ -package com.googlecode.opennars.parser.loan; - -import org.antlr.runtime.*; -import java.util.Stack; -import java.util.List; -import java.util.ArrayList; - - -import org.antlr.runtime.tree.*; - -public class loanParser extends Parser { - public static final String[] tokenNames = new String[] { - "<invalid>", "<EOR>", "<DOWN>", "<UP>", "AT_BASE", "IRI_REF", "DOT", "AT_IMPORT", "AT_PREFIX", "PNAME_NS", "AT_DELAY", "LPAREN", "INTEGER", "RPAREN", "EXCLAMATION", "QUESTION", "PERCENT", "DECIMAL", "SEMICOLON", "CONJ", "COMMA", "DISJ", "NOT", "PAST", "PRESENT", "FUTURE", "INHERITANCE", "SIMILARITY", "INSTANCE", "PROPERTY", "INSTANCE_PROPERTY", "IMPLICATION", "IMPLICATION_PRED", "IMPLICATION_RETRO", "IMPLICATION_CONC", "EQUIVALENCE", "EQUIVALENCE_PRED", "EQUIVALENCE_CONC", "AMPERSAND", "BAR", "OPEN_BRACE", "CLOSE_BRACE", "LBRACKET", "RBRACKET", "MINUS", "TILDE", "STAR", "QUERY_VAR", "STM_VAR", "DOUBLE", "INTEGER_POSITIVE", "DECIMAL_POSITIVE", "DOUBLE_POSITIVE", "INTEGER_NEGATIVE", "DECIMAL_NEGATIVE", "DOUBLE_NEGATIVE", "TRUE", "FALSE", "STRING_LITERAL1", "STRING_LITERAL2", "STRING_LITERAL_LONG1", "STRING_LITERAL_LONG2", "PNAME_LN", "EOL", "WS", "PN_PREFIX", "PN_LOCAL", "LANGLE", "RANGLE", "PN_CHARS_BASE", "DIGIT", "LANGTAG", "EXPONENT", "PLUS", "ECHAR", "PN_CHARS_U", "VARNAME", "PN_CHARS", "COMMENT", "REFERENCE" - }; - public static final int COMMA=20; - public static final int PN_CHARS_U=75; - public static final int MINUS=44; - public static final int PERCENT=16; - public static final int AT_PREFIX=8; - public static final int OPEN_BRACE=40; - public static final int DOUBLE=49; - public static final int AT_BASE=4; - public static final int EQUIVALENCE=35; - public static final int FALSE=57; - public static final int PN_CHARS_BASE=69; - public static final int EQUIVALENCE_CONC=37; - public static final int QUERY_VAR=47; - public static final int AT_DELAY=10; - public static final int LBRACKET=42; - public static final int INHERITANCE=26; - public static final int INSTANCE=28; - public static final int TILDE=45; - public static final int DECIMAL=17; - public static final int QUESTION=15; - public static final int CONJ=19; - public static final int DISJ=21; - public static final int IMPLICATION=31; - public static final int DOT=6; - public static final int STM_VAR=48; - public static final int RANGLE=68; - public static final int INTEGER=12; - public static final int IMPLICATION_RETRO=33; - public static final int FUTURE=25; - public static final int RBRACKET=43; - public static final int RPAREN=13; - public static final int PN_PREFIX=65; - public static final int EQUIVALENCE_PRED=36; - public static final int LANGLE=67; - public static final int LPAREN=11; - public static final int INSTANCE_PROPERTY=30; - public static final int ECHAR=74; - public static final int PLUS=73; - public static final int DIGIT=70; - public static final int AMPERSAND=38; - public static final int INTEGER_NEGATIVE=53; - public static final int PNAME_NS=9; - public static final int PAST=23; - public static final int SIMILARITY=27; - public static final int PROPERTY=29; - public static final int DECIMAL_POSITIVE=51; - public static final int STRING_LITERAL_LONG1=60; - public static final int IMPLICATION_PRED=32; - public static final int WS=64; - public static final int PNAME_LN=62; - public static final int LANGTAG=71; - public static final int EXCLAMATION=14; - public static final int PN_LOCAL=66; - public static final int VARNAME=76; - public static final int CLOSE_BRACE=41; - public static final int COMMENT=78; - public static final int PN_CHARS=77; - public static final int PRESENT=24; - public static final int AT_IMPORT=7; - public static final int STRING_LITERAL_LONG2=61; - public static final int DOUBLE_NEGATIVE=55; - public static final int EXPONENT=72; - public static final int SEMICOLON=18; - public static final int BAR=39; - public static final int DECIMAL_NEGATIVE=54; - public static final int EOF=-1; - public static final int IRI_REF=5; - public static final int DOUBLE_POSITIVE=52; - public static final int REFERENCE=79; - public static final int EOL=63; - public static final int INTEGER_POSITIVE=50; - public static final int STAR=46; - public static final int NOT=22; - public static final int STRING_LITERAL2=59; - public static final int TRUE=56; - public static final int STRING_LITERAL1=58; - public static final int IMPLICATION_CONC=34; - - public loanParser(TokenStream input) { - super(input); - } - - protected TreeAdaptor adaptor = new CommonTreeAdaptor(); - - public void setTreeAdaptor(TreeAdaptor adaptor) { - this.adaptor = adaptor; - } - public TreeAdaptor getTreeAdaptor() { - return adaptor; - } - - public String[] getTokenNames() { return tokenNames; } - public String getGrammarFileName() { return "/Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g"; } - - - public static class document_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start document - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:9:1: document : ( base_rule )? ( at_rule | sentence )* EOF ; - public final document_return document() throws RecognitionException { - document_return retval = new document_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token EOF4=null; - base_rule_return base_rule1 = null; - - at_rule_return at_rule2 = null; - - sentence_return sentence3 = null; - - - Object EOF4_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:10:2: ( ( base_rule )? ( at_rule | sentence )* EOF ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:10:4: ( base_rule )? ( at_rule | sentence )* EOF - { - root_0 = (Object)adaptor.nil(); - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:10:4: ( base_rule )? - int alt1=2; - int LA1_0 = input.LA(1); - - if ( (LA1_0==AT_BASE) ) { - alt1=1; - } - switch (alt1) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:10:4: base_rule - { - pushFollow(FOLLOW_base_rule_in_document27); - base_rule1=base_rule(); - _fsp--; - - adaptor.addChild(root_0, base_rule1.getTree()); - - } - break; - - } - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:10:15: ( at_rule | sentence )* - loop2: - do { - int alt2=3; - int LA2_0 = input.LA(1); - - if ( ((LA2_0>=AT_IMPORT && LA2_0<=AT_PREFIX)||LA2_0==AT_DELAY) ) { - alt2=1; - } - else if ( (LA2_0==IRI_REF||LA2_0==PNAME_NS||(LA2_0>=LPAREN && LA2_0<=INTEGER)||LA2_0==DECIMAL||(LA2_0>=NOT && LA2_0<=FUTURE)||LA2_0==OPEN_BRACE||LA2_0==LBRACKET||(LA2_0>=QUERY_VAR && LA2_0<=PNAME_LN)) ) { - alt2=2; - } - - - switch (alt2) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:10:16: at_rule - { - pushFollow(FOLLOW_at_rule_in_document31); - at_rule2=at_rule(); - _fsp--; - - adaptor.addChild(root_0, at_rule2.getTree()); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:10:26: sentence - { - pushFollow(FOLLOW_sentence_in_document35); - sentence3=sentence(); - _fsp--; - - adaptor.addChild(root_0, sentence3.getTree()); - - } - break; - - default : - break loop2; - } - } while (true); - - EOF4=(Token)input.LT(1); - match(input,EOF,FOLLOW_EOF_in_document39); - EOF4_tree = (Object)adaptor.create(EOF4); - adaptor.addChild(root_0, EOF4_tree); - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end document - - public static class base_rule_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start base_rule - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:12:1: base_rule : AT_BASE IRI_REF DOT ; - public final base_rule_return base_rule() throws RecognitionException { - base_rule_return retval = new base_rule_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token AT_BASE5=null; - Token IRI_REF6=null; - Token DOT7=null; - - Object AT_BASE5_tree=null; - Object IRI_REF6_tree=null; - Object DOT7_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:13:2: ( AT_BASE IRI_REF DOT ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:13:4: AT_BASE IRI_REF DOT - { - root_0 = (Object)adaptor.nil(); - - AT_BASE5=(Token)input.LT(1); - match(input,AT_BASE,FOLLOW_AT_BASE_in_base_rule50); - AT_BASE5_tree = (Object)adaptor.create(AT_BASE5); - root_0 = (Object)adaptor.becomeRoot(AT_BASE5_tree, root_0); - - IRI_REF6=(Token)input.LT(1); - match(input,IRI_REF,FOLLOW_IRI_REF_in_base_rule53); - IRI_REF6_tree = (Object)adaptor.create(IRI_REF6); - adaptor.addChild(root_0, IRI_REF6_tree); - - DOT7=(Token)input.LT(1); - match(input,DOT,FOLLOW_DOT_in_base_rule55); - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end base_rule - - public static class at_rule_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start at_rule - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:16:1: at_rule : ( AT_IMPORT IRI_REF DOT | AT_PREFIX PNAME_NS IRI_REF DOT | AT_DELAY LPAREN INTEGER RPAREN DOT ); - public final at_rule_return at_rule() throws RecognitionException { - at_rule_return retval = new at_rule_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token AT_IMPORT8=null; - Token IRI_REF9=null; - Token DOT10=null; - Token AT_PREFIX11=null; - Token PNAME_NS12=null; - Token IRI_REF13=null; - Token DOT14=null; - Token AT_DELAY15=null; - Token LPAREN16=null; - Token INTEGER17=null; - Token RPAREN18=null; - Token DOT19=null; - - Object AT_IMPORT8_tree=null; - Object IRI_REF9_tree=null; - Object DOT10_tree=null; - Object AT_PREFIX11_tree=null; - Object PNAME_NS12_tree=null; - Object IRI_REF13_tree=null; - Object DOT14_tree=null; - Object AT_DELAY15_tree=null; - Object LPAREN16_tree=null; - Object INTEGER17_tree=null; - Object RPAREN18_tree=null; - Object DOT19_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:16:9: ( AT_IMPORT IRI_REF DOT | AT_PREFIX PNAME_NS IRI_REF DOT | AT_DELAY LPAREN INTEGER RPAREN DOT ) - int alt3=3; - switch ( input.LA(1) ) { - case AT_IMPORT: - { - alt3=1; - } - break; - case AT_PREFIX: - { - alt3=2; - } - break; - case AT_DELAY: - { - alt3=3; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("16:1: at_rule : ( AT_IMPORT IRI_REF DOT | AT_PREFIX PNAME_NS IRI_REF DOT | AT_DELAY LPAREN INTEGER RPAREN DOT );", 3, 0, input); - - throw nvae; - } - - switch (alt3) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:16:11: AT_IMPORT IRI_REF DOT - { - root_0 = (Object)adaptor.nil(); - - AT_IMPORT8=(Token)input.LT(1); - match(input,AT_IMPORT,FOLLOW_AT_IMPORT_in_at_rule66); - AT_IMPORT8_tree = (Object)adaptor.create(AT_IMPORT8); - root_0 = (Object)adaptor.becomeRoot(AT_IMPORT8_tree, root_0); - - IRI_REF9=(Token)input.LT(1); - match(input,IRI_REF,FOLLOW_IRI_REF_in_at_rule69); - IRI_REF9_tree = (Object)adaptor.create(IRI_REF9); - adaptor.addChild(root_0, IRI_REF9_tree); - - DOT10=(Token)input.LT(1); - match(input,DOT,FOLLOW_DOT_in_at_rule71); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:17:4: AT_PREFIX PNAME_NS IRI_REF DOT - { - root_0 = (Object)adaptor.nil(); - - AT_PREFIX11=(Token)input.LT(1); - match(input,AT_PREFIX,FOLLOW_AT_PREFIX_in_at_rule77); - AT_PREFIX11_tree = (Object)adaptor.create(AT_PREFIX11); - root_0 = (Object)adaptor.becomeRoot(AT_PREFIX11_tree, root_0); - - PNAME_NS12=(Token)input.LT(1); - match(input,PNAME_NS,FOLLOW_PNAME_NS_in_at_rule80); - PNAME_NS12_tree = (Object)adaptor.create(PNAME_NS12); - adaptor.addChild(root_0, PNAME_NS12_tree); - - IRI_REF13=(Token)input.LT(1); - match(input,IRI_REF,FOLLOW_IRI_REF_in_at_rule82); - IRI_REF13_tree = (Object)adaptor.create(IRI_REF13); - adaptor.addChild(root_0, IRI_REF13_tree); - - DOT14=(Token)input.LT(1); - match(input,DOT,FOLLOW_DOT_in_at_rule84); - - } - break; - case 3 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:18:4: AT_DELAY LPAREN INTEGER RPAREN DOT - { - root_0 = (Object)adaptor.nil(); - - AT_DELAY15=(Token)input.LT(1); - match(input,AT_DELAY,FOLLOW_AT_DELAY_in_at_rule90); - AT_DELAY15_tree = (Object)adaptor.create(AT_DELAY15); - root_0 = (Object)adaptor.becomeRoot(AT_DELAY15_tree, root_0); - - LPAREN16=(Token)input.LT(1); - match(input,LPAREN,FOLLOW_LPAREN_in_at_rule93); - INTEGER17=(Token)input.LT(1); - match(input,INTEGER,FOLLOW_INTEGER_in_at_rule96); - INTEGER17_tree = (Object)adaptor.create(INTEGER17); - adaptor.addChild(root_0, INTEGER17_tree); - - RPAREN18=(Token)input.LT(1); - match(input,RPAREN,FOLLOW_RPAREN_in_at_rule98); - DOT19=(Token)input.LT(1); - match(input,DOT,FOLLOW_DOT_in_at_rule101); - - } - break; - - } - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end at_rule - - public static class sentence_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start sentence - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:21:1: sentence : statement ( judgement | question | goal ) ; - public final sentence_return sentence() throws RecognitionException { - sentence_return retval = new sentence_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - statement_return statement20 = null; - - judgement_return judgement21 = null; - - question_return question22 = null; - - goal_return goal23 = null; - - - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:22:2: ( statement ( judgement | question | goal ) ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:22:4: statement ( judgement | question | goal ) - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_statement_in_sentence114); - statement20=statement(); - _fsp--; - - adaptor.addChild(root_0, statement20.getTree()); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:22:14: ( judgement | question | goal ) - int alt4=3; - switch ( input.LA(1) ) { - case DOT: - { - alt4=1; - } - break; - case QUESTION: - { - alt4=2; - } - break; - case EXCLAMATION: - { - alt4=3; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("22:14: ( judgement | question | goal )", 4, 0, input); - - throw nvae; - } - - switch (alt4) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:22:15: judgement - { - pushFollow(FOLLOW_judgement_in_sentence117); - judgement21=judgement(); - _fsp--; - - root_0 = (Object)adaptor.becomeRoot(judgement21.getTree(), root_0); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:22:26: question - { - pushFollow(FOLLOW_question_in_sentence120); - question22=question(); - _fsp--; - - root_0 = (Object)adaptor.becomeRoot(question22.getTree(), root_0); - - } - break; - case 3 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:22:36: goal - { - pushFollow(FOLLOW_goal_in_sentence123); - goal23=goal(); - _fsp--; - - root_0 = (Object)adaptor.becomeRoot(goal23.getTree(), root_0); - - } - break; - - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end sentence - - public static class judgement_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start judgement - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:25:1: judgement : DOT ( truthvalue )? ; - public final judgement_return judgement() throws RecognitionException { - judgement_return retval = new judgement_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token DOT24=null; - truthvalue_return truthvalue25 = null; - - - Object DOT24_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:26:2: ( DOT ( truthvalue )? ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:26:4: DOT ( truthvalue )? - { - root_0 = (Object)adaptor.nil(); - - DOT24=(Token)input.LT(1); - match(input,DOT,FOLLOW_DOT_in_judgement138); - DOT24_tree = (Object)adaptor.create(DOT24); - root_0 = (Object)adaptor.becomeRoot(DOT24_tree, root_0); - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:26:9: ( truthvalue )? - int alt5=2; - int LA5_0 = input.LA(1); - - if ( (LA5_0==PERCENT) ) { - alt5=1; - } - switch (alt5) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:26:9: truthvalue - { - pushFollow(FOLLOW_truthvalue_in_judgement141); - truthvalue25=truthvalue(); - _fsp--; - - adaptor.addChild(root_0, truthvalue25.getTree()); - - } - break; - - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end judgement - - public static class goal_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start goal - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:29:1: goal : EXCLAMATION ( truthvalue )? ; - public final goal_return goal() throws RecognitionException { - goal_return retval = new goal_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token EXCLAMATION26=null; - truthvalue_return truthvalue27 = null; - - - Object EXCLAMATION26_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:29:6: ( EXCLAMATION ( truthvalue )? ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:29:8: EXCLAMATION ( truthvalue )? - { - root_0 = (Object)adaptor.nil(); - - EXCLAMATION26=(Token)input.LT(1); - match(input,EXCLAMATION,FOLLOW_EXCLAMATION_in_goal153); - EXCLAMATION26_tree = (Object)adaptor.create(EXCLAMATION26); - root_0 = (Object)adaptor.becomeRoot(EXCLAMATION26_tree, root_0); - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:29:21: ( truthvalue )? - int alt6=2; - int LA6_0 = input.LA(1); - - if ( (LA6_0==PERCENT) ) { - alt6=1; - } - switch (alt6) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:29:21: truthvalue - { - pushFollow(FOLLOW_truthvalue_in_goal156); - truthvalue27=truthvalue(); - _fsp--; - - adaptor.addChild(root_0, truthvalue27.getTree()); - - } - break; - - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end goal - - public static class question_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start question - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:32:1: question : QUESTION ; - public final question_return question() throws RecognitionException { - question_return retval = new question_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token QUESTION28=null; - - Object QUESTION28_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:33:2: ( QUESTION ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:33:4: QUESTION - { - root_0 = (Object)adaptor.nil(); - - QUESTION28=(Token)input.LT(1); - match(input,QUESTION,FOLLOW_QUESTION_in_question170); - QUESTION28_tree = (Object)adaptor.create(QUESTION28); - root_0 = (Object)adaptor.becomeRoot(QUESTION28_tree, root_0); - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end question - - public static class truthvalue_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start truthvalue - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:36:1: truthvalue : PERCENT ( DECIMAL | INTEGER ) ( SEMICOLON DECIMAL )? PERCENT ; - public final truthvalue_return truthvalue() throws RecognitionException { - truthvalue_return retval = new truthvalue_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token PERCENT29=null; - Token set30=null; - Token SEMICOLON31=null; - Token DECIMAL32=null; - Token PERCENT33=null; - - Object PERCENT29_tree=null; - Object set30_tree=null; - Object SEMICOLON31_tree=null; - Object DECIMAL32_tree=null; - Object PERCENT33_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:37:2: ( PERCENT ( DECIMAL | INTEGER ) ( SEMICOLON DECIMAL )? PERCENT ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:37:4: PERCENT ( DECIMAL | INTEGER ) ( SEMICOLON DECIMAL )? PERCENT - { - root_0 = (Object)adaptor.nil(); - - PERCENT29=(Token)input.LT(1); - match(input,PERCENT,FOLLOW_PERCENT_in_truthvalue184); - set30=(Token)input.LT(1); - if ( input.LA(1)==INTEGER||input.LA(1)==DECIMAL ) { - input.consume(); - adaptor.addChild(root_0, adaptor.create(set30)); - errorRecovery=false; - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recoverFromMismatchedSet(input,mse,FOLLOW_set_in_truthvalue187); throw mse; - } - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:37:33: ( SEMICOLON DECIMAL )? - int alt7=2; - int LA7_0 = input.LA(1); - - if ( (LA7_0==SEMICOLON) ) { - alt7=1; - } - switch (alt7) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:37:34: SEMICOLON DECIMAL - { - SEMICOLON31=(Token)input.LT(1); - match(input,SEMICOLON,FOLLOW_SEMICOLON_in_truthvalue196); - SEMICOLON31_tree = (Object)adaptor.create(SEMICOLON31); - adaptor.addChild(root_0, SEMICOLON31_tree); - - DECIMAL32=(Token)input.LT(1); - match(input,DECIMAL,FOLLOW_DECIMAL_in_truthvalue198); - DECIMAL32_tree = (Object)adaptor.create(DECIMAL32); - adaptor.addChild(root_0, DECIMAL32_tree); - - - } - break; - - } - - PERCENT33=(Token)input.LT(1); - match(input,PERCENT,FOLLOW_PERCENT_in_truthvalue202); - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end truthvalue - - public static class statement_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start statement - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:39:1: statement : unary_statement ( ( CONJ | SEMICOLON | COMMA | DISJ ) unary_statement )* ; - public final statement_return statement() throws RecognitionException { - statement_return retval = new statement_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token CONJ35=null; - Token SEMICOLON36=null; - Token COMMA37=null; - Token DISJ38=null; - unary_statement_return unary_statement34 = null; - - unary_statement_return unary_statement39 = null; - - - Object CONJ35_tree=null; - Object SEMICOLON36_tree=null; - Object COMMA37_tree=null; - Object DISJ38_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:40:2: ( unary_statement ( ( CONJ | SEMICOLON | COMMA | DISJ ) unary_statement )* ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:40:4: unary_statement ( ( CONJ | SEMICOLON | COMMA | DISJ ) unary_statement )* - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_unary_statement_in_statement213); - unary_statement34=unary_statement(); - _fsp--; - - adaptor.addChild(root_0, unary_statement34.getTree()); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:40:20: ( ( CONJ | SEMICOLON | COMMA | DISJ ) unary_statement )* - loop9: - do { - int alt9=2; - int LA9_0 = input.LA(1); - - if ( ((LA9_0>=SEMICOLON && LA9_0<=DISJ)) ) { - alt9=1; - } - - - switch (alt9) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:40:21: ( CONJ | SEMICOLON | COMMA | DISJ ) unary_statement - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:40:21: ( CONJ | SEMICOLON | COMMA | DISJ ) - int alt8=4; - switch ( input.LA(1) ) { - case CONJ: - { - alt8=1; - } - break; - case SEMICOLON: - { - alt8=2; - } - break; - case COMMA: - { - alt8=3; - } - break; - case DISJ: - { - alt8=4; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("40:21: ( CONJ | SEMICOLON | COMMA | DISJ )", 8, 0, input); - - throw nvae; - } - - switch (alt8) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:40:22: CONJ - { - CONJ35=(Token)input.LT(1); - match(input,CONJ,FOLLOW_CONJ_in_statement217); - CONJ35_tree = (Object)adaptor.create(CONJ35); - root_0 = (Object)adaptor.becomeRoot(CONJ35_tree, root_0); - - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:40:30: SEMICOLON - { - SEMICOLON36=(Token)input.LT(1); - match(input,SEMICOLON,FOLLOW_SEMICOLON_in_statement222); - SEMICOLON36_tree = (Object)adaptor.create(SEMICOLON36); - root_0 = (Object)adaptor.becomeRoot(SEMICOLON36_tree, root_0); - - - } - break; - case 3 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:40:43: COMMA - { - COMMA37=(Token)input.LT(1); - match(input,COMMA,FOLLOW_COMMA_in_statement227); - COMMA37_tree = (Object)adaptor.create(COMMA37); - root_0 = (Object)adaptor.becomeRoot(COMMA37_tree, root_0); - - - } - break; - case 4 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:40:52: DISJ - { - DISJ38=(Token)input.LT(1); - match(input,DISJ,FOLLOW_DISJ_in_statement232); - DISJ38_tree = (Object)adaptor.create(DISJ38); - root_0 = (Object)adaptor.becomeRoot(DISJ38_tree, root_0); - - - } - break; - - } - - pushFollow(FOLLOW_unary_statement_in_statement236); - unary_statement39=unary_statement(); - _fsp--; - - adaptor.addChild(root_0, unary_statement39.getTree()); - - } - break; - - default : - break loop9; - } - } while (true); - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end statement - - public static class unary_statement_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start unary_statement - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:43:1: unary_statement : ( NOT simple_statement | PAST simple_statement | PRESENT simple_statement | FUTURE simple_statement | simple_statement ); - public final unary_statement_return unary_statement() throws RecognitionException { - unary_statement_return retval = new unary_statement_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token NOT40=null; - Token PAST42=null; - Token PRESENT44=null; - Token FUTURE46=null; - simple_statement_return simple_statement41 = null; - - simple_statement_return simple_statement43 = null; - - simple_statement_return simple_statement45 = null; - - simple_statement_return simple_statement47 = null; - - simple_statement_return simple_statement48 = null; - - - Object NOT40_tree=null; - Object PAST42_tree=null; - Object PRESENT44_tree=null; - Object FUTURE46_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:44:2: ( NOT simple_statement | PAST simple_statement | PRESENT simple_statement | FUTURE simple_statement | simple_statement ) - int alt10=5; - switch ( input.LA(1) ) { - case NOT: - { - alt10=1; - } - break; - case PAST: - { - alt10=2; - } - break; - case PRESENT: - { - alt10=3; - } - break; - case FUTURE: - { - alt10=4; - } - break; - case IRI_REF: - case PNAME_NS: - case LPAREN: - case INTEGER: - case DECIMAL: - case OPEN_BRACE: - case LBRACKET: - case QUERY_VAR: - case STM_VAR: - case DOUBLE: - case INTEGER_POSITIVE: - case DECIMAL_POSITIVE: - case DOUBLE_POSITIVE: - case INTEGER_NEGATIVE: - case DECIMAL_NEGATIVE: - case DOUBLE_NEGATIVE: - case TRUE: - case FALSE: - case STRING_LITERAL1: - case STRING_LITERAL2: - case STRING_LITERAL_LONG1: - case STRING_LITERAL_LONG2: - case PNAME_LN: - { - alt10=5; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("43:1: unary_statement : ( NOT simple_statement | PAST simple_statement | PRESENT simple_statement | FUTURE simple_statement | simple_statement );", 10, 0, input); - - throw nvae; - } - - switch (alt10) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:44:4: NOT simple_statement - { - root_0 = (Object)adaptor.nil(); - - NOT40=(Token)input.LT(1); - match(input,NOT,FOLLOW_NOT_in_unary_statement251); - NOT40_tree = (Object)adaptor.create(NOT40); - adaptor.addChild(root_0, NOT40_tree); - - pushFollow(FOLLOW_simple_statement_in_unary_statement253); - simple_statement41=simple_statement(); - _fsp--; - - adaptor.addChild(root_0, simple_statement41.getTree()); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:45:4: PAST simple_statement - { - root_0 = (Object)adaptor.nil(); - - PAST42=(Token)input.LT(1); - match(input,PAST,FOLLOW_PAST_in_unary_statement258); - PAST42_tree = (Object)adaptor.create(PAST42); - adaptor.addChild(root_0, PAST42_tree); - - pushFollow(FOLLOW_simple_statement_in_unary_statement260); - simple_statement43=simple_statement(); - _fsp--; - - adaptor.addChild(root_0, simple_statement43.getTree()); - - } - break; - case 3 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:46:4: PRESENT simple_statement - { - root_0 = (Object)adaptor.nil(); - - PRESENT44=(Token)input.LT(1); - match(input,PRESENT,FOLLOW_PRESENT_in_unary_statement265); - PRESENT44_tree = (Object)adaptor.create(PRESENT44); - adaptor.addChild(root_0, PRESENT44_tree); - - pushFollow(FOLLOW_simple_statement_in_unary_statement267); - simple_statement45=simple_statement(); - _fsp--; - - adaptor.addChild(root_0, simple_statement45.getTree()); - - } - break; - case 4 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:47:4: FUTURE simple_statement - { - root_0 = (Object)adaptor.nil(); - - FUTURE46=(Token)input.LT(1); - match(input,FUTURE,FOLLOW_FUTURE_in_unary_statement272); - FUTURE46_tree = (Object)adaptor.create(FUTURE46); - adaptor.addChild(root_0, FUTURE46_tree); - - pushFollow(FOLLOW_simple_statement_in_unary_statement274); - simple_statement47=simple_statement(); - _fsp--; - - adaptor.addChild(root_0, simple_statement47.getTree()); - - } - break; - case 5 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:48:4: simple_statement - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_simple_statement_in_unary_statement279); - simple_statement48=simple_statement(); - _fsp--; - - adaptor.addChild(root_0, simple_statement48.getTree()); - - } - break; - - } - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end unary_statement - - public static class simple_statement_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start simple_statement - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:51:1: simple_statement : term ( ( INHERITANCE | SIMILARITY | INSTANCE | PROPERTY | INSTANCE_PROPERTY | IMPLICATION | IMPLICATION_PRED | IMPLICATION_RETRO | IMPLICATION_CONC | EQUIVALENCE | EQUIVALENCE_PRED | EQUIVALENCE_CONC ) term )? ; - public final simple_statement_return simple_statement() throws RecognitionException { - simple_statement_return retval = new simple_statement_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token INHERITANCE50=null; - Token SIMILARITY51=null; - Token INSTANCE52=null; - Token PROPERTY53=null; - Token INSTANCE_PROPERTY54=null; - Token IMPLICATION55=null; - Token IMPLICATION_PRED56=null; - Token IMPLICATION_RETRO57=null; - Token IMPLICATION_CONC58=null; - Token EQUIVALENCE59=null; - Token EQUIVALENCE_PRED60=null; - Token EQUIVALENCE_CONC61=null; - term_return term49 = null; - - term_return term62 = null; - - - Object INHERITANCE50_tree=null; - Object SIMILARITY51_tree=null; - Object INSTANCE52_tree=null; - Object PROPERTY53_tree=null; - Object INSTANCE_PROPERTY54_tree=null; - Object IMPLICATION55_tree=null; - Object IMPLICATION_PRED56_tree=null; - Object IMPLICATION_RETRO57_tree=null; - Object IMPLICATION_CONC58_tree=null; - Object EQUIVALENCE59_tree=null; - Object EQUIVALENCE_PRED60_tree=null; - Object EQUIVALENCE_CONC61_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:2: ( term ( ( INHERITANCE | SIMILARITY | INSTANCE | PROPERTY | INSTANCE_PROPERTY | IMPLICATION | IMPLICATION_PRED | IMPLICATION_RETRO | IMPLICATION_CONC | EQUIVALENCE | EQUIVALENCE_PRED | EQUIVALENCE_CONC ) term )? ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:4: term ( ( INHERITANCE | SIMILARITY | INSTANCE | PROPERTY | INSTANCE_PROPERTY | IMPLICATION | IMPLICATION_PRED | IMPLICATION_RETRO | IMPLICATION_CONC | EQUIVALENCE | EQUIVALENCE_PRED | EQUIVALENCE_CONC ) term )? - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_term_in_simple_statement292); - term49=term(); - _fsp--; - - adaptor.addChild(root_0, term49.getTree()); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:9: ( ( INHERITANCE | SIMILARITY | INSTANCE | PROPERTY | INSTANCE_PROPERTY | IMPLICATION | IMPLICATION_PRED | IMPLICATION_RETRO | IMPLICATION_CONC | EQUIVALENCE | EQUIVALENCE_PRED | EQUIVALENCE_CONC ) term )? - int alt12=2; - int LA12_0 = input.LA(1); - - if ( ((LA12_0>=INHERITANCE && LA12_0<=EQUIVALENCE_CONC)) ) { - alt12=1; - } - switch (alt12) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:10: ( INHERITANCE | SIMILARITY | INSTANCE | PROPERTY | INSTANCE_PROPERTY | IMPLICATION | IMPLICATION_PRED | IMPLICATION_RETRO | IMPLICATION_CONC | EQUIVALENCE | EQUIVALENCE_PRED | EQUIVALENCE_CONC ) term - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:10: ( INHERITANCE | SIMILARITY | INSTANCE | PROPERTY | INSTANCE_PROPERTY | IMPLICATION | IMPLICATION_PRED | IMPLICATION_RETRO | IMPLICATION_CONC | EQUIVALENCE | EQUIVALENCE_PRED | EQUIVALENCE_CONC ) - int alt11=12; - switch ( input.LA(1) ) { - case INHERITANCE: - { - alt11=1; - } - break; - case SIMILARITY: - { - alt11=2; - } - break; - case INSTANCE: - { - alt11=3; - } - break; - case PROPERTY: - { - alt11=4; - } - break; - case INSTANCE_PROPERTY: - { - alt11=5; - } - break; - case IMPLICATION: - { - alt11=6; - } - break; - case IMPLICATION_PRED: - { - alt11=7; - } - break; - case IMPLICATION_RETRO: - { - alt11=8; - } - break; - case IMPLICATION_CONC: - { - alt11=9; - } - break; - case EQUIVALENCE: - { - alt11=10; - } - break; - case EQUIVALENCE_PRED: - { - alt11=11; - } - break; - case EQUIVALENCE_CONC: - { - alt11=12; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("52:10: ( INHERITANCE | SIMILARITY | INSTANCE | PROPERTY | INSTANCE_PROPERTY | IMPLICATION | IMPLICATION_PRED | IMPLICATION_RETRO | IMPLICATION_CONC | EQUIVALENCE | EQUIVALENCE_PRED | EQUIVALENCE_CONC )", 11, 0, input); - - throw nvae; - } - - switch (alt11) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:11: INHERITANCE - { - INHERITANCE50=(Token)input.LT(1); - match(input,INHERITANCE,FOLLOW_INHERITANCE_in_simple_statement296); - INHERITANCE50_tree = (Object)adaptor.create(INHERITANCE50); - root_0 = (Object)adaptor.becomeRoot(INHERITANCE50_tree, root_0); - - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:26: SIMILARITY - { - SIMILARITY51=(Token)input.LT(1); - match(input,SIMILARITY,FOLLOW_SIMILARITY_in_simple_statement301); - SIMILARITY51_tree = (Object)adaptor.create(SIMILARITY51); - root_0 = (Object)adaptor.becomeRoot(SIMILARITY51_tree, root_0); - - - } - break; - case 3 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:40: INSTANCE - { - INSTANCE52=(Token)input.LT(1); - match(input,INSTANCE,FOLLOW_INSTANCE_in_simple_statement306); - INSTANCE52_tree = (Object)adaptor.create(INSTANCE52); - root_0 = (Object)adaptor.becomeRoot(INSTANCE52_tree, root_0); - - - } - break; - case 4 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:52: PROPERTY - { - PROPERTY53=(Token)input.LT(1); - match(input,PROPERTY,FOLLOW_PROPERTY_in_simple_statement311); - PROPERTY53_tree = (Object)adaptor.create(PROPERTY53); - root_0 = (Object)adaptor.becomeRoot(PROPERTY53_tree, root_0); - - - } - break; - case 5 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:64: INSTANCE_PROPERTY - { - INSTANCE_PROPERTY54=(Token)input.LT(1); - match(input,INSTANCE_PROPERTY,FOLLOW_INSTANCE_PROPERTY_in_simple_statement316); - INSTANCE_PROPERTY54_tree = (Object)adaptor.create(INSTANCE_PROPERTY54); - root_0 = (Object)adaptor.becomeRoot(INSTANCE_PROPERTY54_tree, root_0); - - - } - break; - case 6 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:85: IMPLICATION - { - IMPLICATION55=(Token)input.LT(1); - match(input,IMPLICATION,FOLLOW_IMPLICATION_in_simple_statement321); - IMPLICATION55_tree = (Object)adaptor.create(IMPLICATION55); - root_0 = (Object)adaptor.becomeRoot(IMPLICATION55_tree, root_0); - - - } - break; - case 7 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:100: IMPLICATION_PRED - { - IMPLICATION_PRED56=(Token)input.LT(1); - match(input,IMPLICATION_PRED,FOLLOW_IMPLICATION_PRED_in_simple_statement326); - IMPLICATION_PRED56_tree = (Object)adaptor.create(IMPLICATION_PRED56); - root_0 = (Object)adaptor.becomeRoot(IMPLICATION_PRED56_tree, root_0); - - - } - break; - case 8 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:120: IMPLICATION_RETRO - { - IMPLICATION_RETRO57=(Token)input.LT(1); - match(input,IMPLICATION_RETRO,FOLLOW_IMPLICATION_RETRO_in_simple_statement331); - IMPLICATION_RETRO57_tree = (Object)adaptor.create(IMPLICATION_RETRO57); - root_0 = (Object)adaptor.becomeRoot(IMPLICATION_RETRO57_tree, root_0); - - - } - break; - case 9 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:141: IMPLICATION_CONC - { - IMPLICATION_CONC58=(Token)input.LT(1); - match(input,IMPLICATION_CONC,FOLLOW_IMPLICATION_CONC_in_simple_statement336); - IMPLICATION_CONC58_tree = (Object)adaptor.create(IMPLICATION_CONC58); - root_0 = (Object)adaptor.becomeRoot(IMPLICATION_CONC58_tree, root_0); - - - } - break; - case 10 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:161: EQUIVALENCE - { - EQUIVALENCE59=(Token)input.LT(1); - match(input,EQUIVALENCE,FOLLOW_EQUIVALENCE_in_simple_statement341); - EQUIVALENCE59_tree = (Object)adaptor.create(EQUIVALENCE59); - root_0 = (Object)adaptor.becomeRoot(EQUIVALENCE59_tree, root_0); - - - } - break; - case 11 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:176: EQUIVALENCE_PRED - { - EQUIVALENCE_PRED60=(Token)input.LT(1); - match(input,EQUIVALENCE_PRED,FOLLOW_EQUIVALENCE_PRED_in_simple_statement346); - EQUIVALENCE_PRED60_tree = (Object)adaptor.create(EQUIVALENCE_PRED60); - root_0 = (Object)adaptor.becomeRoot(EQUIVALENCE_PRED60_tree, root_0); - - - } - break; - case 12 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:52:196: EQUIVALENCE_CONC - { - EQUIVALENCE_CONC61=(Token)input.LT(1); - match(input,EQUIVALENCE_CONC,FOLLOW_EQUIVALENCE_CONC_in_simple_statement351); - EQUIVALENCE_CONC61_tree = (Object)adaptor.create(EQUIVALENCE_CONC61); - root_0 = (Object)adaptor.becomeRoot(EQUIVALENCE_CONC61_tree, root_0); - - - } - break; - - } - - pushFollow(FOLLOW_term_in_simple_statement355); - term62=term(); - _fsp--; - - adaptor.addChild(root_0, term62.getTree()); - - } - break; - - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end simple_statement - - public static class term_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start term - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:56:1: term : difference ( ( AMPERSAND | BAR ) difference )* ; - public final term_return term() throws RecognitionException { - term_return retval = new term_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token AMPERSAND64=null; - Token BAR65=null; - difference_return difference63 = null; - - difference_return difference66 = null; - - - Object AMPERSAND64_tree=null; - Object BAR65_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:56:7: ( difference ( ( AMPERSAND | BAR ) difference )* ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:56:9: difference ( ( AMPERSAND | BAR ) difference )* - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_difference_in_term371); - difference63=difference(); - _fsp--; - - adaptor.addChild(root_0, difference63.getTree()); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:56:20: ( ( AMPERSAND | BAR ) difference )* - loop14: - do { - int alt14=2; - int LA14_0 = input.LA(1); - - if ( ((LA14_0>=AMPERSAND && LA14_0<=BAR)) ) { - alt14=1; - } - - - switch (alt14) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:56:21: ( AMPERSAND | BAR ) difference - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:56:21: ( AMPERSAND | BAR ) - int alt13=2; - int LA13_0 = input.LA(1); - - if ( (LA13_0==AMPERSAND) ) { - alt13=1; - } - else if ( (LA13_0==BAR) ) { - alt13=2; - } - else { - NoViableAltException nvae = - new NoViableAltException("56:21: ( AMPERSAND | BAR )", 13, 0, input); - - throw nvae; - } - switch (alt13) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:56:22: AMPERSAND - { - AMPERSAND64=(Token)input.LT(1); - match(input,AMPERSAND,FOLLOW_AMPERSAND_in_term375); - AMPERSAND64_tree = (Object)adaptor.create(AMPERSAND64); - root_0 = (Object)adaptor.becomeRoot(AMPERSAND64_tree, root_0); - - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:56:35: BAR - { - BAR65=(Token)input.LT(1); - match(input,BAR,FOLLOW_BAR_in_term380); - BAR65_tree = (Object)adaptor.create(BAR65); - root_0 = (Object)adaptor.becomeRoot(BAR65_tree, root_0); - - - } - break; - - } - - pushFollow(FOLLOW_difference_in_term384); - difference66=difference(); - _fsp--; - - adaptor.addChild(root_0, difference66.getTree()); - - } - break; - - default : - break loop14; - } - } while (true); - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end term - - public static class ext_set_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start ext_set - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:59:1: ext_set : OPEN_BRACE ( term ( COMMA term )* )? CLOSE_BRACE ; - public final ext_set_return ext_set() throws RecognitionException { - ext_set_return retval = new ext_set_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token OPEN_BRACE67=null; - Token COMMA69=null; - Token CLOSE_BRACE71=null; - term_return term68 = null; - - term_return term70 = null; - - - Object OPEN_BRACE67_tree=null; - Object COMMA69_tree=null; - Object CLOSE_BRACE71_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:59:9: ( OPEN_BRACE ( term ( COMMA term )* )? CLOSE_BRACE ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:59:11: OPEN_BRACE ( term ( COMMA term )* )? CLOSE_BRACE - { - root_0 = (Object)adaptor.nil(); - - OPEN_BRACE67=(Token)input.LT(1); - match(input,OPEN_BRACE,FOLLOW_OPEN_BRACE_in_ext_set396); - OPEN_BRACE67_tree = (Object)adaptor.create(OPEN_BRACE67); - root_0 = (Object)adaptor.becomeRoot(OPEN_BRACE67_tree, root_0); - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:59:23: ( term ( COMMA term )* )? - int alt16=2; - int LA16_0 = input.LA(1); - - if ( (LA16_0==IRI_REF||LA16_0==PNAME_NS||(LA16_0>=LPAREN && LA16_0<=INTEGER)||LA16_0==DECIMAL||LA16_0==OPEN_BRACE||LA16_0==LBRACKET||(LA16_0>=QUERY_VAR && LA16_0<=PNAME_LN)) ) { - alt16=1; - } - switch (alt16) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:59:24: term ( COMMA term )* - { - pushFollow(FOLLOW_term_in_ext_set400); - term68=term(); - _fsp--; - - adaptor.addChild(root_0, term68.getTree()); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:59:29: ( COMMA term )* - loop15: - do { - int alt15=2; - int LA15_0 = input.LA(1); - - if ( (LA15_0==COMMA) ) { - alt15=1; - } - - - switch (alt15) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:59:30: COMMA term - { - COMMA69=(Token)input.LT(1); - match(input,COMMA,FOLLOW_COMMA_in_ext_set403); - pushFollow(FOLLOW_term_in_ext_set406); - term70=term(); - _fsp--; - - adaptor.addChild(root_0, term70.getTree()); - - } - break; - - default : - break loop15; - } - } while (true); - - - } - break; - - } - - CLOSE_BRACE71=(Token)input.LT(1); - match(input,CLOSE_BRACE,FOLLOW_CLOSE_BRACE_in_ext_set412); - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end ext_set - - public static class int_set_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start int_set - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:62:1: int_set : LBRACKET ( term ( COMMA term )* )? RBRACKET ; - public final int_set_return int_set() throws RecognitionException { - int_set_return retval = new int_set_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token LBRACKET72=null; - Token COMMA74=null; - Token RBRACKET76=null; - term_return term73 = null; - - term_return term75 = null; - - - Object LBRACKET72_tree=null; - Object COMMA74_tree=null; - Object RBRACKET76_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:62:9: ( LBRACKET ( term ( COMMA term )* )? RBRACKET ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:62:11: LBRACKET ( term ( COMMA term )* )? RBRACKET - { - root_0 = (Object)adaptor.nil(); - - LBRACKET72=(Token)input.LT(1); - match(input,LBRACKET,FOLLOW_LBRACKET_in_int_set424); - LBRACKET72_tree = (Object)adaptor.create(LBRACKET72); - root_0 = (Object)adaptor.becomeRoot(LBRACKET72_tree, root_0); - - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:62:21: ( term ( COMMA term )* )? - int alt18=2; - int LA18_0 = input.LA(1); - - if ( (LA18_0==IRI_REF||LA18_0==PNAME_NS||(LA18_0>=LPAREN && LA18_0<=INTEGER)||LA18_0==DECIMAL||LA18_0==OPEN_BRACE||LA18_0==LBRACKET||(LA18_0>=QUERY_VAR && LA18_0<=PNAME_LN)) ) { - alt18=1; - } - switch (alt18) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:62:22: term ( COMMA term )* - { - pushFollow(FOLLOW_term_in_int_set428); - term73=term(); - _fsp--; - - adaptor.addChild(root_0, term73.getTree()); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:62:27: ( COMMA term )* - loop17: - do { - int alt17=2; - int LA17_0 = input.LA(1); - - if ( (LA17_0==COMMA) ) { - alt17=1; - } - - - switch (alt17) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:62:28: COMMA term - { - COMMA74=(Token)input.LT(1); - match(input,COMMA,FOLLOW_COMMA_in_int_set431); - pushFollow(FOLLOW_term_in_int_set434); - term75=term(); - _fsp--; - - adaptor.addChild(root_0, term75.getTree()); - - } - break; - - default : - break loop17; - } - } while (true); - - - } - break; - - } - - RBRACKET76=(Token)input.LT(1); - match(input,RBRACKET,FOLLOW_RBRACKET_in_int_set440); - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end int_set - - public static class difference_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start difference - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:65:1: difference : product ( ( MINUS | TILDE ) product )* ; - public final difference_return difference() throws RecognitionException { - difference_return retval = new difference_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token MINUS78=null; - Token TILDE79=null; - product_return product77 = null; - - product_return product80 = null; - - - Object MINUS78_tree=null; - Object TILDE79_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:66:2: ( product ( ( MINUS | TILDE ) product )* ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:66:4: product ( ( MINUS | TILDE ) product )* - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_product_in_difference454); - product77=product(); - _fsp--; - - adaptor.addChild(root_0, product77.getTree()); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:66:12: ( ( MINUS | TILDE ) product )* - loop20: - do { - int alt20=2; - int LA20_0 = input.LA(1); - - if ( ((LA20_0>=MINUS && LA20_0<=TILDE)) ) { - alt20=1; - } - - - switch (alt20) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:66:13: ( MINUS | TILDE ) product - { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:66:13: ( MINUS | TILDE ) - int alt19=2; - int LA19_0 = input.LA(1); - - if ( (LA19_0==MINUS) ) { - alt19=1; - } - else if ( (LA19_0==TILDE) ) { - alt19=2; - } - else { - NoViableAltException nvae = - new NoViableAltException("66:13: ( MINUS | TILDE )", 19, 0, input); - - throw nvae; - } - switch (alt19) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:66:14: MINUS - { - MINUS78=(Token)input.LT(1); - match(input,MINUS,FOLLOW_MINUS_in_difference458); - MINUS78_tree = (Object)adaptor.create(MINUS78); - root_0 = (Object)adaptor.becomeRoot(MINUS78_tree, root_0); - - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:66:23: TILDE - { - TILDE79=(Token)input.LT(1); - match(input,TILDE,FOLLOW_TILDE_in_difference463); - TILDE79_tree = (Object)adaptor.create(TILDE79); - root_0 = (Object)adaptor.becomeRoot(TILDE79_tree, root_0); - - - } - break; - - } - - pushFollow(FOLLOW_product_in_difference467); - product80=product(); - _fsp--; - - adaptor.addChild(root_0, product80.getTree()); - - } - break; - - default : - break loop20; - } - } while (true); - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end difference - - public static class product_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start product - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:69:1: product : atomic_term ( STAR atomic_term )* ; - public final product_return product() throws RecognitionException { - product_return retval = new product_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token STAR82=null; - atomic_term_return atomic_term81 = null; - - atomic_term_return atomic_term83 = null; - - - Object STAR82_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:69:9: ( atomic_term ( STAR atomic_term )* ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:69:11: atomic_term ( STAR atomic_term )* - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_atomic_term_in_product480); - atomic_term81=atomic_term(); - _fsp--; - - adaptor.addChild(root_0, atomic_term81.getTree()); - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:69:23: ( STAR atomic_term )* - loop21: - do { - int alt21=2; - int LA21_0 = input.LA(1); - - if ( (LA21_0==STAR) ) { - alt21=1; - } - - - switch (alt21) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:69:24: STAR atomic_term - { - STAR82=(Token)input.LT(1); - match(input,STAR,FOLLOW_STAR_in_product483); - STAR82_tree = (Object)adaptor.create(STAR82); - root_0 = (Object)adaptor.becomeRoot(STAR82_tree, root_0); - - pushFollow(FOLLOW_atomic_term_in_product486); - atomic_term83=atomic_term(); - _fsp--; - - adaptor.addChild(root_0, atomic_term83.getTree()); - - } - break; - - default : - break loop21; - } - } while (true); - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end product - - public static class atomic_term_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start atomic_term - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:72:1: atomic_term : ( ext_set | int_set | LPAREN statement RPAREN | variable | iriRef | literal ); - public final atomic_term_return atomic_term() throws RecognitionException { - atomic_term_return retval = new atomic_term_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token LPAREN86=null; - Token RPAREN88=null; - ext_set_return ext_set84 = null; - - int_set_return int_set85 = null; - - statement_return statement87 = null; - - variable_return variable89 = null; - - iriRef_return iriRef90 = null; - - literal_return literal91 = null; - - - Object LPAREN86_tree=null; - Object RPAREN88_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:73:2: ( ext_set | int_set | LPAREN statement RPAREN | variable | iriRef | literal ) - int alt22=6; - switch ( input.LA(1) ) { - case OPEN_BRACE: - { - alt22=1; - } - break; - case LBRACKET: - { - alt22=2; - } - break; - case LPAREN: - { - alt22=3; - } - break; - case QUERY_VAR: - case STM_VAR: - { - alt22=4; - } - break; - case IRI_REF: - case PNAME_NS: - case PNAME_LN: - { - alt22=5; - } - break; - case INTEGER: - case DECIMAL: - case DOUBLE: - case INTEGER_POSITIVE: - case DECIMAL_POSITIVE: - case DOUBLE_POSITIVE: - case INTEGER_NEGATIVE: - case DECIMAL_NEGATIVE: - case DOUBLE_NEGATIVE: - case TRUE: - case FALSE: - case STRING_LITERAL1: - case STRING_LITERAL2: - case STRING_LITERAL_LONG1: - case STRING_LITERAL_LONG2: - { - alt22=6; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("72:1: atomic_term : ( ext_set | int_set | LPAREN statement RPAREN | variable | iriRef | literal );", 22, 0, input); - - throw nvae; - } - - switch (alt22) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:73:4: ext_set - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_ext_set_in_atomic_term500); - ext_set84=ext_set(); - _fsp--; - - adaptor.addChild(root_0, ext_set84.getTree()); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:74:4: int_set - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_int_set_in_atomic_term505); - int_set85=int_set(); - _fsp--; - - adaptor.addChild(root_0, int_set85.getTree()); - - } - break; - case 3 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:75:4: LPAREN statement RPAREN - { - root_0 = (Object)adaptor.nil(); - - LPAREN86=(Token)input.LT(1); - match(input,LPAREN,FOLLOW_LPAREN_in_atomic_term510); - pushFollow(FOLLOW_statement_in_atomic_term513); - statement87=statement(); - _fsp--; - - adaptor.addChild(root_0, statement87.getTree()); - RPAREN88=(Token)input.LT(1); - match(input,RPAREN,FOLLOW_RPAREN_in_atomic_term515); - - } - break; - case 4 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:76:4: variable - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_variable_in_atomic_term521); - variable89=variable(); - _fsp--; - - adaptor.addChild(root_0, variable89.getTree()); - - } - break; - case 5 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:77:4: iriRef - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_iriRef_in_atomic_term526); - iriRef90=iriRef(); - _fsp--; - - adaptor.addChild(root_0, iriRef90.getTree()); - - } - break; - case 6 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:78:4: literal - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_literal_in_atomic_term531); - literal91=literal(); - _fsp--; - - adaptor.addChild(root_0, literal91.getTree()); - - } - break; - - } - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end atomic_term - - public static class variable_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start variable - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:81:1: variable : ( query_variable | statement_variable ); - public final variable_return variable() throws RecognitionException { - variable_return retval = new variable_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - query_variable_return query_variable92 = null; - - statement_variable_return statement_variable93 = null; - - - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:82:2: ( query_variable | statement_variable ) - int alt23=2; - int LA23_0 = input.LA(1); - - if ( (LA23_0==QUERY_VAR) ) { - alt23=1; - } - else if ( (LA23_0==STM_VAR) ) { - alt23=2; - } - else { - NoViableAltException nvae = - new NoViableAltException("81:1: variable : ( query_variable | statement_variable );", 23, 0, input); - - throw nvae; - } - switch (alt23) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:82:4: query_variable - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_query_variable_in_variable544); - query_variable92=query_variable(); - _fsp--; - - adaptor.addChild(root_0, query_variable92.getTree()); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:83:4: statement_variable - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_statement_variable_in_variable549); - statement_variable93=statement_variable(); - _fsp--; - - adaptor.addChild(root_0, statement_variable93.getTree()); - - } - break; - - } - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end variable - - public static class query_variable_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start query_variable - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:86:1: query_variable : QUERY_VAR ; - public final query_variable_return query_variable() throws RecognitionException { - query_variable_return retval = new query_variable_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token QUERY_VAR94=null; - - Object QUERY_VAR94_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:87:2: ( QUERY_VAR ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:87:4: QUERY_VAR - { - root_0 = (Object)adaptor.nil(); - - QUERY_VAR94=(Token)input.LT(1); - match(input,QUERY_VAR,FOLLOW_QUERY_VAR_in_query_variable562); - QUERY_VAR94_tree = (Object)adaptor.create(QUERY_VAR94); - adaptor.addChild(root_0, QUERY_VAR94_tree); - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end query_variable - - public static class statement_variable_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start statement_variable - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:90:1: statement_variable : STM_VAR ; - public final statement_variable_return statement_variable() throws RecognitionException { - statement_variable_return retval = new statement_variable_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token STM_VAR95=null; - - Object STM_VAR95_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:91:2: ( STM_VAR ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:91:4: STM_VAR - { - root_0 = (Object)adaptor.nil(); - - STM_VAR95=(Token)input.LT(1); - match(input,STM_VAR,FOLLOW_STM_VAR_in_statement_variable575); - STM_VAR95_tree = (Object)adaptor.create(STM_VAR95); - adaptor.addChild(root_0, STM_VAR95_tree); - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end statement_variable - - public static class literal_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start literal - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:96:1: literal : ( numericLiteral | booleanLiteral | string ); - public final literal_return literal() throws RecognitionException { - literal_return retval = new literal_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - numericLiteral_return numericLiteral96 = null; - - booleanLiteral_return booleanLiteral97 = null; - - string_return string98 = null; - - - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:97:2: ( numericLiteral | booleanLiteral | string ) - int alt24=3; - switch ( input.LA(1) ) { - case INTEGER: - case DECIMAL: - case DOUBLE: - case INTEGER_POSITIVE: - case DECIMAL_POSITIVE: - case DOUBLE_POSITIVE: - case INTEGER_NEGATIVE: - case DECIMAL_NEGATIVE: - case DOUBLE_NEGATIVE: - { - alt24=1; - } - break; - case TRUE: - case FALSE: - { - alt24=2; - } - break; - case STRING_LITERAL1: - case STRING_LITERAL2: - case STRING_LITERAL_LONG1: - case STRING_LITERAL_LONG2: - { - alt24=3; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("96:1: literal : ( numericLiteral | booleanLiteral | string );", 24, 0, input); - - throw nvae; - } - - switch (alt24) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:97:4: numericLiteral - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_numericLiteral_in_literal591); - numericLiteral96=numericLiteral(); - _fsp--; - - adaptor.addChild(root_0, numericLiteral96.getTree()); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:98:4: booleanLiteral - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_booleanLiteral_in_literal596); - booleanLiteral97=booleanLiteral(); - _fsp--; - - adaptor.addChild(root_0, booleanLiteral97.getTree()); - - } - break; - case 3 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:99:4: string - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_string_in_literal601); - string98=string(); - _fsp--; - - adaptor.addChild(root_0, string98.getTree()); - - } - break; - - } - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end literal - - public static class numericLiteral_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start numericLiteral - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:102:1: numericLiteral : ( numericLiteralUnsigned | numericLiteralPositive | numericLiteralNegative ); - public final numericLiteral_return numericLiteral() throws RecognitionException { - numericLiteral_return retval = new numericLiteral_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - numericLiteralUnsigned_return numericLiteralUnsigned99 = null; - - numericLiteralPositive_return numericLiteralPositive100 = null; - - numericLiteralNegative_return numericLiteralNegative101 = null; - - - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:103:5: ( numericLiteralUnsigned | numericLiteralPositive | numericLiteralNegative ) - int alt25=3; - switch ( input.LA(1) ) { - case INTEGER: - case DECIMAL: - case DOUBLE: - { - alt25=1; - } - break; - case INTEGER_POSITIVE: - case DECIMAL_POSITIVE: - case DOUBLE_POSITIVE: - { - alt25=2; - } - break; - case INTEGER_NEGATIVE: - case DECIMAL_NEGATIVE: - case DOUBLE_NEGATIVE: - { - alt25=3; - } - break; - default: - NoViableAltException nvae = - new NoViableAltException("102:1: numericLiteral : ( numericLiteralUnsigned | numericLiteralPositive | numericLiteralNegative );", 25, 0, input); - - throw nvae; - } - - switch (alt25) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:103:7: numericLiteralUnsigned - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_numericLiteralUnsigned_in_numericLiteral616); - numericLiteralUnsigned99=numericLiteralUnsigned(); - _fsp--; - - adaptor.addChild(root_0, numericLiteralUnsigned99.getTree()); - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:103:32: numericLiteralPositive - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_numericLiteralPositive_in_numericLiteral620); - numericLiteralPositive100=numericLiteralPositive(); - _fsp--; - - adaptor.addChild(root_0, numericLiteralPositive100.getTree()); - - } - break; - case 3 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:103:57: numericLiteralNegative - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_numericLiteralNegative_in_numericLiteral624); - numericLiteralNegative101=numericLiteralNegative(); - _fsp--; - - adaptor.addChild(root_0, numericLiteralNegative101.getTree()); - - } - break; - - } - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end numericLiteral - - public static class numericLiteralUnsigned_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start numericLiteralUnsigned - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:106:1: numericLiteralUnsigned : ( INTEGER | DECIMAL | DOUBLE ); - public final numericLiteralUnsigned_return numericLiteralUnsigned() throws RecognitionException { - numericLiteralUnsigned_return retval = new numericLiteralUnsigned_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token set102=null; - - Object set102_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:107:5: ( INTEGER | DECIMAL | DOUBLE ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - root_0 = (Object)adaptor.nil(); - - set102=(Token)input.LT(1); - if ( input.LA(1)==INTEGER||input.LA(1)==DECIMAL||input.LA(1)==DOUBLE ) { - input.consume(); - adaptor.addChild(root_0, adaptor.create(set102)); - errorRecovery=false; - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recoverFromMismatchedSet(input,mse,FOLLOW_set_in_numericLiteralUnsigned0); throw mse; - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end numericLiteralUnsigned - - public static class numericLiteralPositive_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start numericLiteralPositive - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:112:1: numericLiteralPositive : ( INTEGER_POSITIVE | DECIMAL_POSITIVE | DOUBLE_POSITIVE ); - public final numericLiteralPositive_return numericLiteralPositive() throws RecognitionException { - numericLiteralPositive_return retval = new numericLiteralPositive_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token set103=null; - - Object set103_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:113:5: ( INTEGER_POSITIVE | DECIMAL_POSITIVE | DOUBLE_POSITIVE ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - root_0 = (Object)adaptor.nil(); - - set103=(Token)input.LT(1); - if ( (input.LA(1)>=INTEGER_POSITIVE && input.LA(1)<=DOUBLE_POSITIVE) ) { - input.consume(); - adaptor.addChild(root_0, adaptor.create(set103)); - errorRecovery=false; - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recoverFromMismatchedSet(input,mse,FOLLOW_set_in_numericLiteralPositive0); throw mse; - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end numericLiteralPositive - - public static class numericLiteralNegative_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start numericLiteralNegative - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:118:1: numericLiteralNegative : ( INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE ); - public final numericLiteralNegative_return numericLiteralNegative() throws RecognitionException { - numericLiteralNegative_return retval = new numericLiteralNegative_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token set104=null; - - Object set104_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:119:5: ( INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - root_0 = (Object)adaptor.nil(); - - set104=(Token)input.LT(1); - if ( (input.LA(1)>=INTEGER_NEGATIVE && input.LA(1)<=DOUBLE_NEGATIVE) ) { - input.consume(); - adaptor.addChild(root_0, adaptor.create(set104)); - errorRecovery=false; - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recoverFromMismatchedSet(input,mse,FOLLOW_set_in_numericLiteralNegative0); throw mse; - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end numericLiteralNegative - - public static class booleanLiteral_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start booleanLiteral - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:124:1: booleanLiteral : ( TRUE | FALSE ); - public final booleanLiteral_return booleanLiteral() throws RecognitionException { - booleanLiteral_return retval = new booleanLiteral_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token set105=null; - - Object set105_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:125:5: ( TRUE | FALSE ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - root_0 = (Object)adaptor.nil(); - - set105=(Token)input.LT(1); - if ( (input.LA(1)>=TRUE && input.LA(1)<=FALSE) ) { - input.consume(); - adaptor.addChild(root_0, adaptor.create(set105)); - errorRecovery=false; - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recoverFromMismatchedSet(input,mse,FOLLOW_set_in_booleanLiteral0); throw mse; - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end booleanLiteral - - public static class string_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start string - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:129:1: string : ( STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2 ); - public final string_return string() throws RecognitionException { - string_return retval = new string_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token set106=null; - - Object set106_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:130:5: ( STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2 ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - root_0 = (Object)adaptor.nil(); - - set106=(Token)input.LT(1); - if ( (input.LA(1)>=STRING_LITERAL1 && input.LA(1)<=STRING_LITERAL_LONG2) ) { - input.consume(); - adaptor.addChild(root_0, adaptor.create(set106)); - errorRecovery=false; - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recoverFromMismatchedSet(input,mse,FOLLOW_set_in_string0); throw mse; - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end string - - public static class iriRef_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start iriRef - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:136:1: iriRef : ( IRI_REF | prefixedName ); - public final iriRef_return iriRef() throws RecognitionException { - iriRef_return retval = new iriRef_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token IRI_REF107=null; - prefixedName_return prefixedName108 = null; - - - Object IRI_REF107_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:137:5: ( IRI_REF | prefixedName ) - int alt26=2; - int LA26_0 = input.LA(1); - - if ( (LA26_0==IRI_REF) ) { - alt26=1; - } - else if ( (LA26_0==PNAME_NS||LA26_0==PNAME_LN) ) { - alt26=2; - } - else { - NoViableAltException nvae = - new NoViableAltException("136:1: iriRef : ( IRI_REF | prefixedName );", 26, 0, input); - - throw nvae; - } - switch (alt26) { - case 1 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:137:7: IRI_REF - { - root_0 = (Object)adaptor.nil(); - - IRI_REF107=(Token)input.LT(1); - match(input,IRI_REF,FOLLOW_IRI_REF_in_iriRef806); - IRI_REF107_tree = (Object)adaptor.create(IRI_REF107); - adaptor.addChild(root_0, IRI_REF107_tree); - - - } - break; - case 2 : - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:138:7: prefixedName - { - root_0 = (Object)adaptor.nil(); - - pushFollow(FOLLOW_prefixedName_in_iriRef814); - prefixedName108=prefixedName(); - _fsp--; - - adaptor.addChild(root_0, prefixedName108.getTree()); - - } - break; - - } - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end iriRef - - public static class prefixedName_return extends ParserRuleReturnScope { - Object tree; - public Object getTree() { return tree; } - }; - - // $ANTLR start prefixedName - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:141:1: prefixedName : ( PNAME_LN | PNAME_NS ); - public final prefixedName_return prefixedName() throws RecognitionException { - prefixedName_return retval = new prefixedName_return(); - retval.start = input.LT(1); - - Object root_0 = null; - - Token set109=null; - - Object set109_tree=null; - - try { - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g:142:5: ( PNAME_LN | PNAME_NS ) - // /Users/jgeldart/Documents/Eclipse/open-nars/com/googlecode/opennars/parser/loan/loan.g: - { - root_0 = (Object)adaptor.nil(); - - set109=(Token)input.LT(1); - if ( input.LA(1)==PNAME_NS||input.LA(1)==PNAME_LN ) { - input.consume(); - adaptor.addChild(root_0, adaptor.create(set109)); - errorRecovery=false; - } - else { - MismatchedSetException mse = - new MismatchedSetException(null,input); - recoverFromMismatchedSet(input,mse,FOLLOW_set_in_prefixedName0); throw mse; - } - - - } - - retval.stop = input.LT(-1); - - retval.tree = (Object)adaptor.rulePostProcessing(root_0); - adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop); - - } - catch (RecognitionException re) { - reportError(re); - recover(input,re); - } - finally { - } - return retval; - } - // $ANTLR end prefixedName - - - - - public static final BitSet FOLLOW_base_rule_in_document27 = new BitSet(new long[]{0x7FFF850003C21FA0L}); - public static final BitSet FOLLOW_at_rule_in_document31 = new BitSet(new long[]{0x7FFF850003C21FA0L}); - public static final BitSet FOLLOW_sentence_in_document35 = new BitSet(new long[]{0x7FFF850003C21FA0L}); - public static final BitSet FOLLOW_EOF_in_document39 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_AT_BASE_in_base_rule50 = new BitSet(new long[]{0x0000000000000020L}); - public static final BitSet FOLLOW_IRI_REF_in_base_rule53 = new BitSet(new long[]{0x0000000000000040L}); - public static final BitSet FOLLOW_DOT_in_base_rule55 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_AT_IMPORT_in_at_rule66 = new BitSet(new long[]{0x0000000000000020L}); - public static final BitSet FOLLOW_IRI_REF_in_at_rule69 = new BitSet(new long[]{0x0000000000000040L}); - public static final BitSet FOLLOW_DOT_in_at_rule71 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_AT_PREFIX_in_at_rule77 = new BitSet(new long[]{0x0000000000000200L}); - public static final BitSet FOLLOW_PNAME_NS_in_at_rule80 = new BitSet(new long[]{0x0000000000000020L}); - public static final BitSet FOLLOW_IRI_REF_in_at_rule82 = new BitSet(new long[]{0x0000000000000040L}); - public static final BitSet FOLLOW_DOT_in_at_rule84 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_AT_DELAY_in_at_rule90 = new BitSet(new long[]{0x0000000000000800L}); - public static final BitSet FOLLOW_LPAREN_in_at_rule93 = new BitSet(new long[]{0x0000000000001000L}); - public static final BitSet FOLLOW_INTEGER_in_at_rule96 = new BitSet(new long[]{0x0000000000002000L}); - public static final BitSet FOLLOW_RPAREN_in_at_rule98 = new BitSet(new long[]{0x0000000000000040L}); - public static final BitSet FOLLOW_DOT_in_at_rule101 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_statement_in_sentence114 = new BitSet(new long[]{0x000000000000C040L}); - public static final BitSet FOLLOW_judgement_in_sentence117 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_question_in_sentence120 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_goal_in_sentence123 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_DOT_in_judgement138 = new BitSet(new long[]{0x0000000000010002L}); - public static final BitSet FOLLOW_truthvalue_in_judgement141 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_EXCLAMATION_in_goal153 = new BitSet(new long[]{0x0000000000010002L}); - public static final BitSet FOLLOW_truthvalue_in_goal156 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_QUESTION_in_question170 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_PERCENT_in_truthvalue184 = new BitSet(new long[]{0x0000000000021000L}); - public static final BitSet FOLLOW_set_in_truthvalue187 = new BitSet(new long[]{0x0000000000050000L}); - public static final BitSet FOLLOW_SEMICOLON_in_truthvalue196 = new BitSet(new long[]{0x0000000000020000L}); - public static final BitSet FOLLOW_DECIMAL_in_truthvalue198 = new BitSet(new long[]{0x0000000000010000L}); - public static final BitSet FOLLOW_PERCENT_in_truthvalue202 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_unary_statement_in_statement213 = new BitSet(new long[]{0x00000000003C0002L}); - public static final BitSet FOLLOW_CONJ_in_statement217 = new BitSet(new long[]{0x7FFF850003C21A20L}); - public static final BitSet FOLLOW_SEMICOLON_in_statement222 = new BitSet(new long[]{0x7FFF850003C21A20L}); - public static final BitSet FOLLOW_COMMA_in_statement227 = new BitSet(new long[]{0x7FFF850003C21A20L}); - public static final BitSet FOLLOW_DISJ_in_statement232 = new BitSet(new long[]{0x7FFF850003C21A20L}); - public static final BitSet FOLLOW_unary_statement_in_statement236 = new BitSet(new long[]{0x00000000003C0002L}); - public static final BitSet FOLLOW_NOT_in_unary_statement251 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_simple_statement_in_unary_statement253 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_PAST_in_unary_statement258 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_simple_statement_in_unary_statement260 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_PRESENT_in_unary_statement265 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_simple_statement_in_unary_statement267 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_FUTURE_in_unary_statement272 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_simple_statement_in_unary_statement274 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_simple_statement_in_unary_statement279 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_term_in_simple_statement292 = new BitSet(new long[]{0x0000003FFC000002L}); - public static final BitSet FOLLOW_INHERITANCE_in_simple_statement296 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_SIMILARITY_in_simple_statement301 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_INSTANCE_in_simple_statement306 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_PROPERTY_in_simple_statement311 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_INSTANCE_PROPERTY_in_simple_statement316 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_IMPLICATION_in_simple_statement321 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_IMPLICATION_PRED_in_simple_statement326 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_IMPLICATION_RETRO_in_simple_statement331 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_IMPLICATION_CONC_in_simple_statement336 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_EQUIVALENCE_in_simple_statement341 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_EQUIVALENCE_PRED_in_simple_statement346 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_EQUIVALENCE_CONC_in_simple_statement351 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_term_in_simple_statement355 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_difference_in_term371 = new BitSet(new long[]{0x000000C000000002L}); - public static final BitSet FOLLOW_AMPERSAND_in_term375 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_BAR_in_term380 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_difference_in_term384 = new BitSet(new long[]{0x000000C000000002L}); - public static final BitSet FOLLOW_OPEN_BRACE_in_ext_set396 = new BitSet(new long[]{0x7FFF870000021A20L}); - public static final BitSet FOLLOW_term_in_ext_set400 = new BitSet(new long[]{0x0000020000100000L}); - public static final BitSet FOLLOW_COMMA_in_ext_set403 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_term_in_ext_set406 = new BitSet(new long[]{0x0000020000100000L}); - public static final BitSet FOLLOW_CLOSE_BRACE_in_ext_set412 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_LBRACKET_in_int_set424 = new BitSet(new long[]{0x7FFF8D0000021A20L}); - public static final BitSet FOLLOW_term_in_int_set428 = new BitSet(new long[]{0x0000080000100000L}); - public static final BitSet FOLLOW_COMMA_in_int_set431 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_term_in_int_set434 = new BitSet(new long[]{0x0000080000100000L}); - public static final BitSet FOLLOW_RBRACKET_in_int_set440 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_product_in_difference454 = new BitSet(new long[]{0x0000300000000002L}); - public static final BitSet FOLLOW_MINUS_in_difference458 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_TILDE_in_difference463 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_product_in_difference467 = new BitSet(new long[]{0x0000300000000002L}); - public static final BitSet FOLLOW_atomic_term_in_product480 = new BitSet(new long[]{0x0000400000000002L}); - public static final BitSet FOLLOW_STAR_in_product483 = new BitSet(new long[]{0x7FFF850000021A20L}); - public static final BitSet FOLLOW_atomic_term_in_product486 = new BitSet(new long[]{0x0000400000000002L}); - public static final BitSet FOLLOW_ext_set_in_atomic_term500 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_int_set_in_atomic_term505 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_LPAREN_in_atomic_term510 = new BitSet(new long[]{0x7FFF850003C21A20L}); - public static final BitSet FOLLOW_statement_in_atomic_term513 = new BitSet(new long[]{0x0000000000002000L}); - public static final BitSet FOLLOW_RPAREN_in_atomic_term515 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_variable_in_atomic_term521 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_iriRef_in_atomic_term526 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_literal_in_atomic_term531 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_query_variable_in_variable544 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_statement_variable_in_variable549 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_QUERY_VAR_in_query_variable562 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_STM_VAR_in_statement_variable575 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_numericLiteral_in_literal591 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_booleanLiteral_in_literal596 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_string_in_literal601 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_numericLiteralUnsigned_in_numericLiteral616 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_numericLiteralPositive_in_numericLiteral620 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_numericLiteralNegative_in_numericLiteral624 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_set_in_numericLiteralUnsigned0 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_set_in_numericLiteralPositive0 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_set_in_numericLiteralNegative0 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_set_in_booleanLiteral0 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_set_in_string0 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_IRI_REF_in_iriRef806 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_prefixedName_in_iriRef814 = new BitSet(new long[]{0x0000000000000002L}); - public static final BitSet FOLLOW_set_in_prefixedName0 = new BitSet(new long[]{0x0000000000000002L}); - -} \ No newline at end of file diff --git a/open-nars/com/googlecode/opennars/parser/narsese/NarseseParser.java b/open-nars/com/googlecode/opennars/parser/narsese/NarseseParser.java index 20c9f1fb46645c2bc5726c8dd724116cb1c24ea8..d94256ae23cc336baa3c658099cc0063bc80e498 100644 --- a/open-nars/com/googlecode/opennars/parser/narsese/NarseseParser.java +++ b/open-nars/com/googlecode/opennars/parser/narsese/NarseseParser.java @@ -381,5 +381,24 @@ public class NarseseParser extends Parser { sentence.setInput(); Task task = new Task(sentence, budget, memory); return task; + } + + @Override + public List<Task> parseTasks(String input, Memory memory) + throws InvalidInputException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String serialiseSentence(Sentence task, Memory memory) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String serialiseSentences(List<Sentence> tasks, Memory memory) { + // TODO Auto-generated method stub + return null; } } diff --git a/open-nars/java_cup/Main.java b/open-nars/java_cup/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..50811b536538e827f1f851698ff3c7201dcc0668 --- /dev/null +++ b/open-nars/java_cup/Main.java @@ -0,0 +1,854 @@ + +package java_cup; + +import java.util.Enumeration; +import java.io.*; + +/** This class serves as the main driver for the JavaCup system. + * It accepts user options and coordinates overall control flow. + * The main flow of control includes the following activities: + * <ul> + * <li> Parse user supplied arguments and options. + * <li> Open output files. + * <li> Parse the specification from standard input. + * <li> Check for unused terminals, non-terminals, and productions. + * <li> Build the state machine, tables, etc. + * <li> Output the generated code. + * <li> Close output files. + * <li> Print a summary if requested. + * </ul> + * + * Options to the main program include: <dl> + * <dt> -package name + * <dd> specify package generated classes go in [default none] + * <dt> -parser name + * <dd> specify parser class name [default "parser"] + * <dt> -symbols name + * <dd> specify name for symbol constant class [default "sym"] + * <dt> -interface + * <dd> emit symbol constant <i>interface</i>, rather than class + * <dt> -nonterms + * <dd> put non terminals in symbol constant class + * <dt> -expect # + * <dd> number of conflicts expected/allowed [default 0] + * <dt> -compact_red + * <dd> compact tables by defaulting to most frequent reduce + * <dt> -nowarn + * <dd> don't warn about useless productions, etc. + * <dt> -nosummary + * <dd> don't print the usual summary of parse states, etc. + * <dt> -progress + * <dd> print messages to indicate progress of the system + * <dt> -time + * <dd> print time usage summary + * <dt> -dump_grammar + * <dd> produce a dump of the symbols and grammar + * <dt> -dump_states + * <dd> produce a dump of parse state machine + * <dt> -dump_tables + * <dd> produce a dump of the parse tables + * <dt> -dump + * <dd> produce a dump of all of the above + * <dt> -debug + * <dd> turn on debugging messages within JavaCup + * <dt> -nopositions + * <dd> don't generate the positions code + * <dt> -noscanner + * <dd> don't refer to java_cup.runtime.Scanner in the parser + * (for compatibility with old runtimes) + * <dt> -version + * <dd> print version information for JavaCUP and halt. + * </dl> + * + * @version last updated: 7/3/96 + * @author Frank Flannery + */ + +public class Main { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + /** Only constructor is private, so we do not allocate any instances of this + class. */ + private Main() { } + + /*-------------------------*/ + /* Options set by the user */ + /*-------------------------*/ + /** User option -- do we print progress messages. */ + protected static boolean print_progress = true; + /** User option -- do we produce a dump of the state machine */ + protected static boolean opt_dump_states = false; + /** User option -- do we produce a dump of the parse tables */ + protected static boolean opt_dump_tables = false; + /** User option -- do we produce a dump of the grammar */ + protected static boolean opt_dump_grammar = false; + /** User option -- do we show timing information as a part of the summary */ + protected static boolean opt_show_timing = false; + /** User option -- do we run produce extra debugging messages */ + protected static boolean opt_do_debug = false; + /** User option -- do we compact tables by making most common reduce the + default action */ + protected static boolean opt_compact_red = false; + /** User option -- should we include non terminal symbol numbers in the + symbol constant class. */ + protected static boolean include_non_terms = false; + /** User option -- do not print a summary. */ + protected static boolean no_summary = false; + /** User option -- number of conflicts to expect */ + protected static int expect_conflicts = 0; + + /* frankf added this 6/18/96 */ + /** User option -- should generator generate code for left/right values? */ + protected static boolean lr_values = true; + + /** User option -- should symbols be put in a class or an interface? [CSA]*/ + protected static boolean sym_interface = false; + + /** User option -- should generator suppress references to + * java_cup.runtime.Scanner for compatibility with old runtimes? */ + protected static boolean suppress_scanner = false; + + /*----------------------------------------------------------------------*/ + /* Timing data (not all of these time intervals are mutually exclusive) */ + /*----------------------------------------------------------------------*/ + /** Timing data -- when did we start */ + protected static long start_time = 0; + /** Timing data -- when did we end preliminaries */ + protected static long prelim_end = 0; + /** Timing data -- when did we end parsing */ + protected static long parse_end = 0; + /** Timing data -- when did we end checking */ + protected static long check_end = 0; + /** Timing data -- when did we end dumping */ + protected static long dump_end = 0; + /** Timing data -- when did we end state and table building */ + protected static long build_end = 0; + /** Timing data -- when did we end nullability calculation */ + protected static long nullability_end = 0; + /** Timing data -- when did we end first set calculation */ + protected static long first_end = 0; + /** Timing data -- when did we end state machine construction */ + protected static long machine_end = 0; + /** Timing data -- when did we end table construction */ + protected static long table_end = 0; + /** Timing data -- when did we end checking for non-reduced productions */ + protected static long reduce_check_end = 0; + /** Timing data -- when did we finish emitting code */ + protected static long emit_end = 0; + /** Timing data -- when were we completely done */ + protected static long final_time = 0; + + /* Additional timing information is also collected in emit */ + + /*-----------------------------------------------------------*/ + /*--- Main Program ------------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** The main driver for the system. + * @param argv an array of strings containing command line arguments. + */ + public static void main(String argv[]) + throws internal_error, java.io.IOException, java.lang.Exception + { + boolean did_output = false; + + start_time = System.currentTimeMillis(); + + /* process user options and arguments */ + parse_args(argv); + + /* frankf 6/18/96 + hackish, yes, but works */ + emit.set_lr_values(lr_values); + /* open output files */ + if (print_progress) System.err.println("Opening files..."); + /* use a buffered version of standard input */ + input_file = new BufferedInputStream(System.in); + + prelim_end = System.currentTimeMillis(); + + /* parse spec into internal data structures */ + if (print_progress) + System.err.println("Parsing specification from standard input..."); + parse_grammar_spec(); + + parse_end = System.currentTimeMillis(); + + /* don't proceed unless we are error free */ + if (lexer.error_count == 0) + { + /* check for unused bits */ + if (print_progress) System.err.println("Checking specification..."); + check_unused(); + + check_end = System.currentTimeMillis(); + + /* build the state machine and parse tables */ + if (print_progress) System.err.println("Building parse tables..."); + build_parser(); + + build_end = System.currentTimeMillis(); + + /* output the generated code, if # of conflicts permits */ + if (lexer.error_count != 0) { + // conflicts! don't emit code, don't dump tables. + opt_dump_tables = false; + } else { // everything's okay, emit parser. + if (print_progress) System.err.println("Writing parser..."); + open_files(); + emit_parser(); + did_output = true; + } + } + /* fix up the times to make the summary easier */ + emit_end = System.currentTimeMillis(); + + /* do requested dumps */ + if (opt_dump_grammar) dump_grammar(); + if (opt_dump_states) dump_machine(); + if (opt_dump_tables) dump_tables(); + + dump_end = System.currentTimeMillis(); + + /* close input/output files */ + if (print_progress) System.err.println("Closing files..."); + close_files(); + + /* produce a summary if desired */ + if (!no_summary) emit_summary(did_output); + + /* If there were errors during the run, + * exit with non-zero status (makefile-friendliness). --CSA */ + if (lexer.error_count != 0) + System.exit(100); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Print a "usage message" that described possible command line options, + * then exit. + * @param message a specific error message to preface the usage message by. + */ + protected static void usage(String message) + { + System.err.println(); + System.err.println(message); + System.err.println(); + System.err.println( +"Usage: " + version.program_name + " [options] [filename]\n" + +" and expects a specification file on standard input if no filename is given.\n" + +" Legal options include:\n" + +" -package name specify package generated classes go in [default none]\n" + +" -parser name specify parser class name [default \"parser\"]\n" + +" -symbols name specify name for symbol constant class [default \"sym\"]\n"+ +" -interface put symbols in an interface, rather than a class\n" + +" -nonterms put non terminals in symbol constant class\n" + +" -expect # number of conflicts expected/allowed [default 0]\n" + +" -compact_red compact tables by defaulting to most frequent reduce\n" + +" -nowarn don't warn about useless productions, etc.\n" + +" -nosummary don't print the usual summary of parse states, etc.\n" + +" -nopositions don't propagate the left and right token position values\n" + +" -noscanner don't refer to java_cup.runtime.Scanner\n" + +" -progress print messages to indicate progress of the system\n" + +" -time print time usage summary\n" + +" -dump_grammar produce a human readable dump of the symbols and grammar\n"+ +" -dump_states produce a dump of parse state machine\n"+ +" -dump_tables produce a dump of the parse tables\n"+ +" -dump produce a dump of all of the above\n"+ +" -version print the version information for CUP and exit\n" + ); + System.exit(1); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Parse command line options and arguments to set various user-option + * flags and variables. + * @param argv the command line arguments to be parsed. + */ + protected static void parse_args(String argv[]) + { + int len = argv.length; + int i; + + /* parse the options */ + for (i=0; i<len; i++) + { + /* try to get the various options */ + if (argv[i].equals("-package")) + { + /* must have an arg */ + if (++i >= len || argv[i].startsWith("-") || + argv[i].endsWith(".cup")) + usage("-package must have a name argument"); + + /* record the name */ + emit.package_name = argv[i]; + } + else if (argv[i].equals("-parser")) + { + /* must have an arg */ + if (++i >= len || argv[i].startsWith("-") || + argv[i].endsWith(".cup")) + usage("-parser must have a name argument"); + + /* record the name */ + emit.parser_class_name = argv[i]; + } + else if (argv[i].equals("-symbols")) + { + /* must have an arg */ + if (++i >= len || argv[i].startsWith("-") || + argv[i].endsWith(".cup")) + usage("-symbols must have a name argument"); + + /* record the name */ + emit.symbol_const_class_name = argv[i]; + } + else if (argv[i].equals("-nonterms")) + { + include_non_terms = true; + } + else if (argv[i].equals("-expect")) + { + /* must have an arg */ + if (++i >= len || argv[i].startsWith("-") || + argv[i].endsWith(".cup")) + usage("-expect must have a name argument"); + + /* record the number */ + try { + expect_conflicts = Integer.parseInt(argv[i]); + } catch (NumberFormatException e) { + usage("-expect must be followed by a decimal integer"); + } + } + else if (argv[i].equals("-compact_red")) opt_compact_red = true; + else if (argv[i].equals("-nosummary")) no_summary = true; + else if (argv[i].equals("-nowarn")) emit.nowarn = true; + else if (argv[i].equals("-dump_states")) opt_dump_states = true; + else if (argv[i].equals("-dump_tables")) opt_dump_tables = true; + else if (argv[i].equals("-progress")) print_progress = true; + else if (argv[i].equals("-dump_grammar")) opt_dump_grammar = true; + else if (argv[i].equals("-dump")) + opt_dump_states = opt_dump_tables = opt_dump_grammar = true; + else if (argv[i].equals("-time")) opt_show_timing = true; + else if (argv[i].equals("-debug")) opt_do_debug = true; + /* frankf 6/18/96 */ + else if (argv[i].equals("-nopositions")) lr_values = false; + /* CSA 12/21/97 */ + else if (argv[i].equals("-interface")) sym_interface = true; + /* CSA 23-Jul-1999 */ + else if (argv[i].equals("-noscanner")) suppress_scanner = true; + /* CSA 23-Jul-1999 */ + else if (argv[i].equals("-version")) { + System.out.println(version.title_str); + System.exit(1); + } + /* CSA 24-Jul-1999; suggestion by Jean Vaucher */ + else if (!argv[i].startsWith("-") && i==len-1) { + /* use input from file. */ + try { + System.setIn(new FileInputStream(argv[i])); + } catch (java.io.FileNotFoundException e) { + usage("Unable to open \"" + argv[i] +"\" for input"); + } + } + else + { + usage("Unrecognized option \"" + argv[i] + "\""); + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /*-------*/ + /* Files */ + /*-------*/ + + /** Input file. This is a buffered version of System.in. */ + protected static BufferedInputStream input_file; + + /** Output file for the parser class. */ + protected static PrintWriter parser_class_file; + + /** Output file for the symbol constant class. */ + protected static PrintWriter symbol_class_file; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Open various files used by the system. */ + protected static void open_files() + { + File fil; + String out_name; + + /* open each of the output files */ + + /* parser class */ + out_name = emit.parser_class_name + ".java"; + fil = new File(out_name); + try { + parser_class_file = new PrintWriter( + new BufferedOutputStream(new FileOutputStream(fil), 4096)); + } catch(Exception e) { + System.err.println("Can't open \"" + out_name + "\" for output"); + System.exit(3); + } + + /* symbol constants class */ + out_name = emit.symbol_const_class_name + ".java"; + fil = new File(out_name); + try { + symbol_class_file = new PrintWriter( + new BufferedOutputStream(new FileOutputStream(fil), 4096)); + } catch(Exception e) { + System.err.println("Can't open \"" + out_name + "\" for output"); + System.exit(4); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Close various files used by the system. */ + protected static void close_files() throws java.io.IOException + { + if (input_file != null) input_file.close(); + if (parser_class_file != null) parser_class_file.close(); + if (symbol_class_file != null) symbol_class_file.close(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Parse the grammar specification from standard input. This produces + * sets of terminal, non-terminals, and productions which can be accessed + * via static variables of the respective classes, as well as the setting + * of various variables (mostly in the emit class) for small user supplied + * items such as the code to scan with. + */ + protected static void parse_grammar_spec() throws java.lang.Exception + { + parser parser_obj; + + /* create a parser and parse with it */ + parser_obj = new parser(); + try { + if (opt_do_debug) + parser_obj.debug_parse(); + else + parser_obj.parse(); + } catch (Exception e) + { + /* something threw an exception. catch it and emit a message so we + have a line number to work with, then re-throw it */ + lexer.emit_error("Internal error: Unexpected exception"); + throw e; + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Check for unused symbols. Unreduced productions get checked when + * tables are created. + */ + protected static void check_unused() + { + terminal term; + non_terminal nt; + + /* check for unused terminals */ + for (Enumeration t = terminal.all(); t.hasMoreElements(); ) + { + term = (terminal)t.nextElement(); + + /* don't issue a message for EOF */ + if (term == terminal.EOF) continue; + + /* or error */ + if (term == terminal.error) continue; + + /* is this one unused */ + if (term.use_count() == 0) + { + /* count it and warn if we are doing warnings */ + emit.unused_term++; + if (!emit.nowarn) + { + System.err.println("Warning: Terminal \"" + term.name() + + "\" was declared but never used"); + lexer.warning_count++; + } + } + } + + /* check for unused non terminals */ + for (Enumeration n = non_terminal.all(); n.hasMoreElements(); ) + { + nt = (non_terminal)n.nextElement(); + + /* is this one unused */ + if (nt.use_count() == 0) + { + /* count and warn if we are doing warnings */ + emit.unused_term++; + if (!emit.nowarn) + { + System.err.println("Warning: Non terminal \"" + nt.name() + + "\" was declared but never used"); + lexer.warning_count++; + } + } + } + + } + + /* . . . . . . . . . . . . . . . . . . . . . . . . .*/ + /* . . Internal Results of Generating the Parser . .*/ + /* . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Start state in the overall state machine. */ + protected static lalr_state start_state; + + /** Resulting parse action table. */ + protected static parse_action_table action_table; + + /** Resulting reduce-goto table. */ + protected static parse_reduce_table reduce_table; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Build the (internal) parser from the previously parsed specification. + * This includes:<ul> + * <li> Computing nullability of non-terminals. + * <li> Computing first sets of non-terminals and productions. + * <li> Building the viable prefix recognizer machine. + * <li> Filling in the (internal) parse tables. + * <li> Checking for unreduced productions. + * </ul> + */ + protected static void build_parser() throws internal_error + { + /* compute nullability of all non terminals */ + if (opt_do_debug || print_progress) + System.err.println(" Computing non-terminal nullability..."); + non_terminal.compute_nullability(); + + nullability_end = System.currentTimeMillis(); + + /* compute first sets of all non terminals */ + if (opt_do_debug || print_progress) + System.err.println(" Computing first sets..."); + non_terminal.compute_first_sets(); + + first_end = System.currentTimeMillis(); + + /* build the LR viable prefix recognition machine */ + if (opt_do_debug || print_progress) + System.err.println(" Building state machine..."); + start_state = lalr_state.build_machine(emit.start_production); + + machine_end = System.currentTimeMillis(); + + /* build the LR parser action and reduce-goto tables */ + if (opt_do_debug || print_progress) + System.err.println(" Filling in tables..."); + action_table = new parse_action_table(); + reduce_table = new parse_reduce_table(); + for (Enumeration st = lalr_state.all(); st.hasMoreElements(); ) + { + lalr_state lst = (lalr_state)st.nextElement(); + lst.build_table_entries( + action_table, reduce_table); + } + + table_end = System.currentTimeMillis(); + + /* check and warn for non-reduced productions */ + if (opt_do_debug || print_progress) + System.err.println(" Checking for non-reduced productions..."); + action_table.check_reductions(); + + reduce_check_end = System.currentTimeMillis(); + + /* if we have more conflicts than we expected issue a message and die */ + if (emit.num_conflicts > expect_conflicts) + { + System.err.println("*** More conflicts encountered than expected " + + "-- parser generation aborted"); + lexer.error_count++; // indicate the problem. + // we'll die on return, after clean up. + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Call the emit routines necessary to write out the generated parser. */ + protected static void emit_parser() throws internal_error + { + emit.symbols(symbol_class_file, include_non_terms, sym_interface); + emit.parser(parser_class_file, action_table, reduce_table, + start_state.index(), emit.start_production, opt_compact_red, + suppress_scanner); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Helper routine to optionally return a plural or non-plural ending. + * @param val the numerical value determining plurality. + */ + protected static String plural(int val) + { + if (val == 1) + return ""; + else + return "s"; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit a long summary message to standard error (System.err) which + * summarizes what was found in the specification, how many states were + * produced, how many conflicts were found, etc. A detailed timing + * summary is also produced if it was requested by the user. + * @param output_produced did the system get far enough to generate code. + */ + protected static void emit_summary(boolean output_produced) + { + final_time = System.currentTimeMillis(); + + if (no_summary) return; + + System.err.println("------- " + version.title_str + + " Parser Generation Summary -------"); + + /* error and warning count */ + System.err.println(" " + lexer.error_count + " error" + + plural(lexer.error_count) + " and " + lexer.warning_count + + " warning" + plural(lexer.warning_count)); + + /* basic stats */ + System.err.print(" " + terminal.number() + " terminal" + + plural(terminal.number()) + ", "); + System.err.print(non_terminal.number() + " non-terminal" + + plural(non_terminal.number()) + ", and "); + System.err.println(production.number() + " production" + + plural(production.number()) + " declared, "); + System.err.println(" producing " + lalr_state.number() + + " unique parse states."); + + /* unused symbols */ + System.err.println(" " + emit.unused_term + " terminal" + + plural(emit.unused_term) + " declared but not used."); + System.err.println(" " + emit.unused_non_term + " non-terminal" + + plural(emit.unused_term) + " declared but not used."); + + /* productions that didn't reduce */ + System.err.println(" " + emit.not_reduced + " production" + + plural(emit.not_reduced) + " never reduced."); + + /* conflicts */ + System.err.println(" " + emit.num_conflicts + " conflict" + + plural(emit.num_conflicts) + " detected" + + " (" + expect_conflicts + " expected)."); + + /* code location */ + if (output_produced) + System.err.println(" Code written to \"" + emit.parser_class_name + + ".java\", and \"" + emit.symbol_const_class_name + ".java\"."); + else + System.err.println(" No code produced."); + + if (opt_show_timing) show_times(); + + System.err.println( + "---------------------------------------------------- (" + + version.version_str + ")"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce the optional timing summary as part of an overall summary. */ + protected static void show_times() + { + long total_time = final_time - start_time; + + System.err.println(". . . . . . . . . . . . . . . . . . . . . . . . . "); + System.err.println(" Timing Summary"); + System.err.println(" Total time " + + timestr(final_time-start_time, total_time)); + System.err.println(" Startup " + + timestr(prelim_end-start_time, total_time)); + System.err.println(" Parse " + + timestr(parse_end-prelim_end, total_time) ); + if (check_end != 0) + System.err.println(" Checking " + + timestr(check_end-parse_end, total_time)); + if (check_end != 0 && build_end != 0) + System.err.println(" Parser Build " + + timestr(build_end-check_end, total_time)); + if (nullability_end != 0 && check_end != 0) + System.err.println(" Nullability " + + timestr(nullability_end-check_end, total_time)); + if (first_end != 0 && nullability_end != 0) + System.err.println(" First sets " + + timestr(first_end-nullability_end, total_time)); + if (machine_end != 0 && first_end != 0) + System.err.println(" State build " + + timestr(machine_end-first_end, total_time)); + if (table_end != 0 && machine_end != 0) + System.err.println(" Table build " + + timestr(table_end-machine_end, total_time)); + if (reduce_check_end != 0 && table_end != 0) + System.err.println(" Checking " + + timestr(reduce_check_end-table_end, total_time)); + if (emit_end != 0 && build_end != 0) + System.err.println(" Code Output " + + timestr(emit_end-build_end, total_time)); + if (emit.symbols_time != 0) + System.err.println(" Symbols " + + timestr(emit.symbols_time, total_time)); + if (emit.parser_time != 0) + System.err.println(" Parser class " + + timestr(emit.parser_time, total_time)); + if (emit.action_code_time != 0) + System.err.println(" Actions " + + timestr(emit.action_code_time, total_time)); + if (emit.production_table_time != 0) + System.err.println(" Prod table " + + timestr(emit.production_table_time, total_time)); + if (emit.action_table_time != 0) + System.err.println(" Action tab " + + timestr(emit.action_table_time, total_time)); + if (emit.goto_table_time != 0) + System.err.println(" Reduce tab " + + timestr(emit.goto_table_time, total_time)); + + System.err.println(" Dump Output " + + timestr(dump_end-emit_end, total_time)); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Helper routine to format a decimal based display of seconds and + * percentage of total time given counts of milliseconds. Note: this + * is broken for use with some instances of negative time (since we don't + * use any negative time here, we let if be for now). + * @param time_val the value being formatted (in ms). + * @param total_time total time percentages are calculated against (in ms). + */ + protected static String timestr(long time_val, long total_time) + { + boolean neg; + long ms = 0; + long sec = 0; + long percent10; + String pad; + + /* work with positives only */ + neg = time_val < 0; + if (neg) time_val = -time_val; + + /* pull out seconds and ms */ + ms = time_val % 1000; + sec = time_val / 1000; + + /* construct a pad to blank fill seconds out to 4 places */ + if (sec < 10) + pad = " "; + else if (sec < 100) + pad = " "; + else if (sec < 1000) + pad = " "; + else + pad = ""; + + /* calculate 10 times the percentage of total */ + percent10 = (time_val*1000)/total_time; + + /* build and return the output string */ + return (neg ? "-" : "") + pad + sec + "." + + ((ms%1000)/100) + ((ms%100)/10) + (ms%10) + "sec" + + " (" + percent10/10 + "." + percent10%10 + "%)"; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a human readable dump of the grammar. */ + public static void dump_grammar() throws internal_error + { + System.err.println("===== Terminals ====="); + for (int tidx=0, cnt=0; tidx < terminal.number(); tidx++, cnt++) + { + System.err.print("["+tidx+"]"+terminal.find(tidx).name()+" "); + if ((cnt+1) % 5 == 0) System.err.println(); + } + System.err.println(); + System.err.println(); + + System.err.println("===== Non terminals ====="); + for (int nidx=0, cnt=0; nidx < non_terminal.number(); nidx++, cnt++) + { + System.err.print("["+nidx+"]"+non_terminal.find(nidx).name()+" "); + if ((cnt+1) % 5 == 0) System.err.println(); + } + System.err.println(); + System.err.println(); + + + System.err.println("===== Productions ====="); + for (int pidx=0; pidx < production.number(); pidx++) + { + production prod = production.find(pidx); + System.err.print("["+pidx+"] "+prod.lhs().the_symbol().name() + " ::= "); + for (int i=0; i<prod.rhs_length(); i++) + if (prod.rhs(i).is_action()) + System.err.print("{action} "); + else + System.err.print( + ((symbol_part)prod.rhs(i)).the_symbol().name() + " "); + System.err.println(); + } + System.err.println(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a (semi-) human readable dump of the complete viable prefix + * recognition state machine. + */ + public static void dump_machine() + { + lalr_state ordered[] = new lalr_state[lalr_state.number()]; + + /* put the states in sorted order for a nicer display */ + for (Enumeration s = lalr_state.all(); s.hasMoreElements(); ) + { + lalr_state st = (lalr_state)s.nextElement(); + ordered[st.index()] = st; + } + + System.err.println("===== Viable Prefix Recognizer ====="); + for (int i = 0; i<lalr_state.number(); i++) + { + if (ordered[i] == start_state) System.err.print("START "); + System.err.println(ordered[i]); + System.err.println("-------------------"); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a (semi-) human readable dumps of the parse tables */ + public static void dump_tables() + { + System.err.println(action_table); + System.err.println(reduce_table); + } + + /*-----------------------------------------------------------*/ + +} + diff --git a/open-nars/java_cup/action_part.java b/open-nars/java_cup/action_part.java new file mode 100644 index 0000000000000000000000000000000000000000..69e98f59ac10d8d0928e6d83dc47b043b05de42a --- /dev/null +++ b/open-nars/java_cup/action_part.java @@ -0,0 +1,93 @@ + +package java_cup; + +/** + * This class represents a part of a production which contains an + * action. These are eventually eliminated from productions and converted + * to trailing actions by factoring out with a production that derives the + * empty string (and ends with this action). + * + * @see java_cup.production + * @version last update: 11/25/95 + * @author Scott Hudson + */ + +public class action_part extends production_part { + + /*-----------------------------------------------------------*/ + /*--- Constructors ------------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. + * @param code_str string containing the actual user code. + */ + public action_part(String code_str) + { + super(/* never have a label on code */null); + _code_string = code_str; + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** String containing code for the action in question. */ + protected String _code_string; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** String containing code for the action in question. */ + public String code_string() {return _code_string;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Set the code string. */ + public void set_code_string(String new_str) {_code_string = new_str;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Override to report this object as an action. */ + public boolean is_action() { return true; } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison for properly typed object. */ + public boolean equals(action_part other) + { + /* compare the strings */ + return other != null && super.equals(other) && + other.code_string().equals(code_string()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof action_part)) + return false; + else + return equals((action_part)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a hash code. */ + public int hashCode() + { + return super.hashCode() ^ + (code_string()==null ? 0 : code_string().hashCode()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + return super.toString() + "{" + code_string() + "}"; + } + + /*-----------------------------------------------------------*/ +} diff --git a/open-nars/java_cup/action_production.java b/open-nars/java_cup/action_production.java new file mode 100644 index 0000000000000000000000000000000000000000..3c0845f265f71272b43f83a495305273c69c7513 --- /dev/null +++ b/open-nars/java_cup/action_production.java @@ -0,0 +1,39 @@ + +package java_cup; + +/** A specialized version of a production used when we split an existing + * production in order to remove an embedded action. Here we keep a bit + * of extra bookkeeping so that we know where we came from. + * @version last updated: 11/25/95 + * @author Scott Hudson + */ + +public class action_production extends production { + + /** Constructor. + * @param base the production we are being factored out of. + * @param lhs_sym the LHS symbol for this production. + * @param rhs_parts array of production parts for the RHS. + * @param rhs_len how much of the rhs_parts array is valid. + * @param action_str the trailing reduce action for this production. + */ + public action_production( + production base, + non_terminal lhs_sym, + production_part rhs_parts[], + int rhs_len, + String action_str) + throws internal_error + { + super(lhs_sym, rhs_parts, rhs_len, action_str); + _base_production = base; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The production we were taken out of. */ + protected production _base_production; + + /** The production we were taken out of. */ + public production base_production() {return _base_production;} +} diff --git a/open-nars/java_cup/assoc.java b/open-nars/java_cup/assoc.java new file mode 100644 index 0000000000000000000000000000000000000000..8d0b50e9178aff4115564ed74fa3b6a2295d1166 --- /dev/null +++ b/open-nars/java_cup/assoc.java @@ -0,0 +1,16 @@ +package java_cup; + +/* Defines integers that represent the associativity of terminals + * @version last updated: 7/3/96 + * @author Frank Flannery + */ + +public class assoc { + + /* various associativities, no_prec being the default value */ + public final static int left = 0; + public final static int right = 1; + public final static int nonassoc = 2; + public final static int no_prec = -1; + +} \ No newline at end of file diff --git a/open-nars/java_cup/emit.java b/open-nars/java_cup/emit.java new file mode 100644 index 0000000000000000000000000000000000000000..9db9014ab4cb9513dc93978f7a89dc6b1233105d --- /dev/null +++ b/open-nars/java_cup/emit.java @@ -0,0 +1,897 @@ +package java_cup; + +import java.io.PrintWriter; +import java.util.Stack; +import java.util.Enumeration; +import java.util.Date; + +/** + * This class handles emitting generated code for the resulting parser. + * The various parse tables must be constructed, etc. before calling any + * routines in this class.<p> + * + * Three classes are produced by this code: + * <dl> + * <dt> symbol constant class + * <dd> this contains constant declarations for each terminal (and + * optionally each non-terminal). + * <dt> action class + * <dd> this non-public class contains code to invoke all the user actions + * that were embedded in the parser specification. + * <dt> parser class + * <dd> the specialized parser class consisting primarily of some user + * supplied general and initialization code, and the parse tables. + * </dl><p> + * + * Three parse tables are created as part of the parser class: + * <dl> + * <dt> production table + * <dd> lists the LHS non terminal number, and the length of the RHS of + * each production. + * <dt> action table + * <dd> for each state of the parse machine, gives the action to be taken + * (shift, reduce, or error) under each lookahead symbol.<br> + * <dt> reduce-goto table + * <dd> when a reduce on a given production is taken, the parse stack is + * popped back a number of elements corresponding to the RHS of the + * production. This reveals a prior state, which we transition out + * of under the LHS non terminal symbol for the production (as if we + * had seen the LHS symbol rather than all the symbols matching the + * RHS). This table is indexed by non terminal numbers and indicates + * how to make these transitions. + * </dl><p> + * + * In addition to the method interface, this class maintains a series of + * public global variables and flags indicating how misc. parts of the code + * and other output is to be produced, and counting things such as number of + * conflicts detected (see the source code and public variables below for + * more details).<p> + * + * This class is "static" (contains only static data and methods).<p> + * + * @see java_cup.main + * @version last update: 11/25/95 + * @author Scott Hudson + */ + +/* Major externally callable routines here include: + symbols - emit the symbol constant class + parser - emit the parser class + + In addition the following major internal routines are provided: + emit_package - emit a package declaration + emit_action_code - emit the class containing the user's actions + emit_production_table - emit declaration and init for the production table + do_action_table - emit declaration and init for the action table + do_reduce_table - emit declaration and init for the reduce-goto table + + Finally, this class uses a number of public instance variables to communicate + optional parameters and flags used to control how code is generated, + as well as to report counts of various things (such as number of conflicts + detected). These include: + + prefix - a prefix string used to prefix names that would + otherwise "pollute" someone else's name space. + package_name - name of the package emitted code is placed in + (or null for an unnamed package. + symbol_const_class_name - name of the class containing symbol constants. + parser_class_name - name of the class for the resulting parser. + action_code - user supplied declarations and other code to be + placed in action class. + parser_code - user supplied declarations and other code to be + placed in parser class. + init_code - user supplied code to be executed as the parser + is being initialized. + scan_code - user supplied code to get the next Symbol. + start_production - the start production for the grammar. + import_list - list of imports for use with action class. + num_conflicts - number of conflicts detected. + nowarn - true if we are not to issue warning messages. + not_reduced - count of number of productions that never reduce. + unused_term - count of unused terminal symbols. + unused_non_term - count of unused non terminal symbols. + *_time - a series of symbols indicating how long various + sub-parts of code generation took (used to produce + optional time reports in main). +*/ + +public class emit { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Only constructor is private so no instances can be created. */ + private emit() { } + + /*-----------------------------------------------------------*/ + /*--- Static (Class) Variables ------------------------------*/ + /*-----------------------------------------------------------*/ + + /** The prefix placed on names that pollute someone else's name space. */ + public static String prefix = "CUP$"; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Package that the resulting code goes into (null is used for unnamed). */ + public static String package_name = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Name of the generated class for symbol constants. */ + public static String symbol_const_class_name = "sym"; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Name of the generated parser class. */ + public static String parser_class_name = "parser"; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** User declarations for direct inclusion in user action class. */ + public static String action_code = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** User declarations for direct inclusion in parser class. */ + public static String parser_code = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** User code for user_init() which is called during parser initialization. */ + public static String init_code = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** User code for scan() which is called to get the next Symbol. */ + public static String scan_code = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The start production of the grammar. */ + public static production start_production = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** List of imports (Strings containing class names) to go with actions. */ + public static Stack import_list = new Stack(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Number of conflict found while building tables. */ + public static int num_conflicts = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Do we skip warnings? */ + public static boolean nowarn = false; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of the number on non-reduced productions found. */ + public static int not_reduced = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of unused terminals. */ + public static int unused_term = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of unused non terminals. */ + public static int unused_non_term = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /* Timing values used to produce timing report in main.*/ + + /** Time to produce symbol constant class. */ + public static long symbols_time = 0; + + /** Time to produce parser class. */ + public static long parser_time = 0; + + /** Time to produce action code class. */ + public static long action_code_time = 0; + + /** Time to produce the production table. */ + public static long production_table_time = 0; + + /** Time to produce the action table. */ + public static long action_table_time = 0; + + /** Time to produce the reduce-goto table. */ + public static long goto_table_time = 0; + + /* frankf 6/18/96 */ + protected static boolean _lr_values; + + /** whether or not to emit code for left and right values */ + public static boolean lr_values() {return _lr_values;} + protected static void set_lr_values(boolean b) { _lr_values = b;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Build a string with the standard prefix. + * @param str string to prefix. + */ + protected static String pre(String str) { + return prefix + parser_class_name + "$" + str; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit a package spec if the user wants one. + * @param out stream to produce output on. + */ + protected static void emit_package(PrintWriter out) + { + /* generate a package spec if we have a name for one */ + if (package_name != null) { + out.println("package " + package_name + ";"); out.println(); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit code for the symbol constant class, optionally including non terms, + * if they have been requested. + * @param out stream to produce output on. + * @param emit_non_terms do we emit constants for non terminals? + * @param sym_interface should we emit an interface, rather than a class? + */ + public static void symbols(PrintWriter out, + boolean emit_non_terms, boolean sym_interface) + { + terminal term; + non_terminal nt; + String class_or_interface = (sym_interface)?"interface":"class"; + + long start_time = System.currentTimeMillis(); + + /* top of file */ + out.println(); + out.println("//----------------------------------------------------"); + out.println("// The following code was generated by " + + version.title_str); + out.println("// " + new Date()); + out.println("//----------------------------------------------------"); + out.println(); + emit_package(out); + + /* class header */ + out.println("/** CUP generated " + class_or_interface + + " containing symbol constants. */"); + out.println("public " + class_or_interface + " " + + symbol_const_class_name + " {"); + + out.println(" /* terminals */"); + + /* walk over the terminals */ /* later might sort these */ + for (Enumeration e = terminal.all(); e.hasMoreElements(); ) + { + term = (terminal)e.nextElement(); + + /* output a constant decl for the terminal */ + out.println(" public static final int " + term.name() + " = " + + term.index() + ";"); + } + + /* do the non terminals if they want them (parser doesn't need them) */ + if (emit_non_terms) + { + out.println(); + out.println(" /* non terminals */"); + + /* walk over the non terminals */ /* later might sort these */ + for (Enumeration e = non_terminal.all(); e.hasMoreElements(); ) + { + nt = (non_terminal)e.nextElement(); + + /* output a constant decl for the terminal */ + out.println(" static final int " + nt.name() + " = " + + nt.index() + ";"); + } + } + + /* end of class */ + out.println("}"); + out.println(); + + symbols_time = System.currentTimeMillis() - start_time; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit code for the non-public class holding the actual action code. + * @param out stream to produce output on. + * @param start_prod the start production of the grammar. + */ + protected static void emit_action_code(PrintWriter out, production start_prod) + throws internal_error + { + production prod; + + long start_time = System.currentTimeMillis(); + + /* class header */ + out.println(); + out.println( + "/** Cup generated class to encapsulate user supplied action code.*/" + ); + out.println("class " + pre("actions") + " {"); + + /* user supplied code */ + if (action_code != null) + { + out.println(); + out.println(action_code); + } + + /* field for parser object */ + out.println(" private final "+parser_class_name+" parser;"); + + /* constructor */ + out.println(); + out.println(" /** Constructor */"); + out.println(" " + pre("actions") + "("+parser_class_name+" parser) {"); + out.println(" this.parser = parser;"); + out.println(" }"); + + /* action method head */ + out.println(); + out.println(" /** Method with the actual generated action code. */"); + out.println(" public final java_cup.runtime.Symbol " + + pre("do_action") + "("); + out.println(" int " + pre("act_num,")); + out.println(" java_cup.runtime.lr_parser " + pre("parser,")); + out.println(" java.util.Stack " + pre("stack,")); + out.println(" int " + pre("top)")); + out.println(" throws java.lang.Exception"); + out.println(" {"); + + /* declaration of result symbol */ + /* New declaration!! now return Symbol + 6/13/96 frankf */ + out.println(" /* Symbol object for return from actions */"); + out.println(" java_cup.runtime.Symbol " + pre("result") + ";"); + out.println(); + + /* switch top */ + out.println(" /* select the action based on the action number */"); + out.println(" switch (" + pre("act_num") + ")"); + out.println(" {"); + + /* emit action code for each production as a separate case */ + for (Enumeration p = production.all(); p.hasMoreElements(); ) + { + prod = (production)p.nextElement(); + + /* case label */ + out.println(" /*. . . . . . . . . . . . . . . . . . . .*/"); + out.println(" case " + prod.index() + ": // " + + prod.to_simple_string()); + + /* give them their own block to work in */ + out.println(" {"); + + /* create the result symbol */ + /*make the variable RESULT which will point to the new Symbol (see below) + and be changed by action code + 6/13/96 frankf */ + out.println(" " + prod.lhs().the_symbol().stack_type() + + " RESULT = null;"); + + /* Add code to propagate RESULT assignments that occur in + * action code embedded in a production (ie, non-rightmost + * action code). 24-Mar-1998 CSA + */ + for (int i=0; i<prod.rhs_length(); i++) { + // only interested in non-terminal symbols. + if (!(prod.rhs(i) instanceof symbol_part)) continue; + symbol s = ((symbol_part)prod.rhs(i)).the_symbol(); + if (!(s instanceof non_terminal)) continue; + // skip this non-terminal unless it corresponds to + // an embedded action production. + if (((non_terminal)s).is_embedded_action == false) continue; + // OK, it fits. Make a conditional assignment to RESULT. + int index = prod.rhs_length() - i - 1; // last rhs is on top. + out.println(" " + "// propagate RESULT from " + + s.name()); + out.println(" " + "if ( " + + "((java_cup.runtime.Symbol) " + emit.pre("stack") + ".elementAt(" + + emit.pre("top") + "-" + index + ")).value != null )"); + out.println(" " + "RESULT = " + + "(" + prod.lhs().the_symbol().stack_type() + ") " + + "((java_cup.runtime.Symbol) " + emit.pre("stack") + ".elementAt(" + + emit.pre("top") + "-" + index + ")).value;"); + } + + /* if there is an action string, emit it */ + if (prod.action() != null && prod.action().code_string() != null && + !prod.action().equals("")) + out.println(prod.action().code_string()); + + /* here we have the left and right values being propagated. + must make this a command line option. + frankf 6/18/96 */ + + /* Create the code that assigns the left and right values of + the new Symbol that the production is reducing to */ + if (emit.lr_values()) { + int loffset; + String leftstring, rightstring; + int roffset = 0; + rightstring = "((java_cup.runtime.Symbol)" + emit.pre("stack") + ".elementAt(" + + emit.pre("top") + "-" + roffset + ")).right"; + if (prod.rhs_length() == 0) + leftstring = rightstring; + else { + loffset = prod.rhs_length() - 1; + leftstring = "((java_cup.runtime.Symbol)" + emit.pre("stack") + ".elementAt(" + + emit.pre("top") + "-" + loffset + ")).left"; + } + out.println(" " + pre("result") + " = new java_cup.runtime.Symbol(" + + prod.lhs().the_symbol().index() + "/*" + + prod.lhs().the_symbol().name() + "*/" + + ", " + leftstring + ", " + rightstring + ", RESULT);"); + } else { + out.println(" " + pre("result") + " = new java_cup.runtime.Symbol(" + + prod.lhs().the_symbol().index() + "/*" + + prod.lhs().the_symbol().name() + "*/" + + ", RESULT);"); + } + + /* end of their block */ + out.println(" }"); + + /* if this was the start production, do action for accept */ + if (prod == start_prod) + { + out.println(" /* ACCEPT */"); + out.println(" " + pre("parser") + ".done_parsing();"); + } + + /* code to return lhs symbol */ + out.println(" return " + pre("result") + ";"); + out.println(); + } + + /* end of switch */ + out.println(" /* . . . . . .*/"); + out.println(" default:"); + out.println(" throw new Exception("); + out.println(" \"Invalid action number found in " + + "internal parse table\");"); + out.println(); + out.println(" }"); + + /* end of method */ + out.println(" }"); + + /* end of class */ + out.println("}"); + out.println(); + + action_code_time = System.currentTimeMillis() - start_time; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit the production table. + * @param out stream to produce output on. + */ + protected static void emit_production_table(PrintWriter out) + { + production all_prods[]; + production prod; + + long start_time = System.currentTimeMillis(); + + /* collect up the productions in order */ + all_prods = new production[production.number()]; + for (Enumeration p = production.all(); p.hasMoreElements(); ) + { + prod = (production)p.nextElement(); + all_prods[prod.index()] = prod; + } + + // make short[][] + short[][] prod_table = new short[production.number()][2]; + for (int i = 0; i<production.number(); i++) + { + prod = all_prods[i]; + // { lhs symbol , rhs size } + prod_table[i][0] = (short) prod.lhs().the_symbol().index(); + prod_table[i][1] = (short) prod.rhs_length(); + } + /* do the top of the table */ + out.println(); + out.println(" /** Production table. */"); + out.println(" protected static final short _production_table[][] = "); + out.print (" unpackFromStrings("); + do_table_as_string(out, prod_table); + out.println(");"); + + /* do the public accessor method */ + out.println(); + out.println(" /** Access to production table. */"); + out.println(" public short[][] production_table() " + + "{return _production_table;}"); + + production_table_time = System.currentTimeMillis() - start_time; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit the action table. + * @param out stream to produce output on. + * @param act_tab the internal representation of the action table. + * @param compact_reduces do we use the most frequent reduce as default? + */ + protected static void do_action_table( + PrintWriter out, + parse_action_table act_tab, + boolean compact_reduces) + throws internal_error + { + parse_action_row row; + parse_action act; + int red; + + long start_time = System.currentTimeMillis(); + + /* collect values for the action table */ + short[][] action_table = new short[act_tab.num_states()][]; + /* do each state (row) of the action table */ + for (int i = 0; i < act_tab.num_states(); i++) + { + /* get the row */ + row = act_tab.under_state[i]; + + /* determine the default for the row */ + if (compact_reduces) + row.compute_default(); + else + row.default_reduce = -1; + + /* make temporary table for the row. */ + short[] temp_table = new short[2*row.size()]; + int nentries = 0; + + /* do each column */ + for (int j = 0; j < row.size(); j++) + { + /* extract the action from the table */ + act = row.under_term[j]; + + /* skip error entries these are all defaulted out */ + if (act.kind() != parse_action.ERROR) + { + /* first put in the symbol index, then the actual entry */ + + /* shifts get positive entries of state number + 1 */ + if (act.kind() == parse_action.SHIFT) + { + /* make entry */ + temp_table[nentries++] = (short) j; + temp_table[nentries++] = (short) + (((shift_action)act).shift_to().index() + 1); + } + + /* reduce actions get negated entries of production# + 1 */ + else if (act.kind() == parse_action.REDUCE) + { + /* if its the default entry let it get defaulted out */ + red = ((reduce_action)act).reduce_with().index(); + if (red != row.default_reduce) { + /* make entry */ + temp_table[nentries++] = (short) j; + temp_table[nentries++] = (short) (-(red+1)); + } + } else if (act.kind() == parse_action.NONASSOC) + { + /* do nothing, since we just want a syntax error */ + } + /* shouldn't be anything else */ + else + throw new internal_error("Unrecognized action code " + + act.kind() + " found in parse table"); + } + } + + /* now we know how big to make the row */ + action_table[i] = new short[nentries + 2]; + System.arraycopy(temp_table, 0, action_table[i], 0, nentries); + + /* finish off the row with a default entry */ + action_table[i][nentries++] = -1; + if (row.default_reduce != -1) + action_table[i][nentries++] = (short) (-(row.default_reduce+1)); + else + action_table[i][nentries++] = 0; + } + + /* finish off the init of the table */ + out.println(); + out.println(" /** Parse-action table. */"); + out.println(" protected static final short[][] _action_table = "); + out.print (" unpackFromStrings("); + do_table_as_string(out, action_table); + out.println(");"); + + /* do the public accessor method */ + out.println(); + out.println(" /** Access to parse-action table. */"); + out.println(" public short[][] action_table() {return _action_table;}"); + + action_table_time = System.currentTimeMillis() - start_time; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit the reduce-goto table. + * @param out stream to produce output on. + * @param red_tab the internal representation of the reduce-goto table. + */ + protected static void do_reduce_table( + PrintWriter out, + parse_reduce_table red_tab) + { + lalr_state goto_st; + parse_action act; + + long start_time = System.currentTimeMillis(); + + /* collect values for reduce-goto table */ + short[][] reduce_goto_table = new short[red_tab.num_states()][]; + /* do each row of the reduce-goto table */ + for (int i=0; i<red_tab.num_states(); i++) + { + /* make temporary table for the row. */ + short[] temp_table = new short[2*red_tab.under_state[i].size()]; + int nentries = 0; + /* do each entry in the row */ + for (int j=0; j<red_tab.under_state[i].size(); j++) + { + /* get the entry */ + goto_st = red_tab.under_state[i].under_non_term[j]; + + /* if we have none, skip it */ + if (goto_st != null) + { + /* make entries for the index and the value */ + temp_table[nentries++] = (short) j; + temp_table[nentries++] = (short) goto_st.index(); + } + } + /* now we know how big to make the row. */ + reduce_goto_table[i] = new short[nentries+2]; + System.arraycopy(temp_table, 0, reduce_goto_table[i], 0, nentries); + + /* end row with default value */ + reduce_goto_table[i][nentries++] = -1; + reduce_goto_table[i][nentries++] = -1; + } + + /* emit the table. */ + out.println(); + out.println(" /** <code>reduce_goto</code> table. */"); + out.println(" protected static final short[][] _reduce_table = "); + out.print (" unpackFromStrings("); + do_table_as_string(out, reduce_goto_table); + out.println(");"); + + /* do the public accessor method */ + out.println(); + out.println(" /** Access to <code>reduce_goto</code> table. */"); + out.println(" public short[][] reduce_table() {return _reduce_table;}"); + out.println(); + + goto_table_time = System.currentTimeMillis() - start_time; + } + + // print a string array encoding the given short[][] array. + protected static void do_table_as_string(PrintWriter out, short[][] sa) { + out.println("new String[] {"); + out.print(" \""); + int nchar=0, nbytes=0; + nbytes+=do_escaped(out, (char)(sa.length>>16)); + nchar =do_newline(out, nchar, nbytes); + nbytes+=do_escaped(out, (char)(sa.length&0xFFFF)); + nchar =do_newline(out, nchar, nbytes); + for (int i=0; i<sa.length; i++) { + nbytes+=do_escaped(out, (char)(sa[i].length>>16)); + nchar =do_newline(out, nchar, nbytes); + nbytes+=do_escaped(out, (char)(sa[i].length&0xFFFF)); + nchar =do_newline(out, nchar, nbytes); + for (int j=0; j<sa[i].length; j++) { + // contents of string are (value+2) to allow for common -1, 0 cases + // (UTF-8 encoding is most efficient for 0<c<0x80) + nbytes+=do_escaped(out, (char)(2+sa[i][j])); + nchar =do_newline(out, nchar, nbytes); + } + } + out.print("\" }"); + } + // split string if it is very long; start new line occasionally for neatness + protected static int do_newline(PrintWriter out, int nchar, int nbytes) { + if (nbytes > 65500) { out.println("\", "); out.print(" \""); } + else if (nchar > 11) { out.println("\" +"); out.print(" \""); } + else return nchar+1; + return 0; + } + // output an escape sequence for the given character code. + protected static int do_escaped(PrintWriter out, char c) { + StringBuffer escape = new StringBuffer(); + if (c <= 0xFF) { + escape.append(Integer.toOctalString(c)); + while(escape.length() < 3) escape.insert(0, '0'); + } else { + escape.append(Integer.toHexString(c)); + while(escape.length() < 4) escape.insert(0, '0'); + escape.insert(0, 'u'); + } + escape.insert(0, '\\'); + out.print(escape.toString()); + + // return number of bytes this takes up in UTF-8 encoding. + if (c == 0) return 2; + if (c >= 0x01 && c <= 0x7F) return 1; + if (c >= 0x80 && c <= 0x7FF) return 2; + return 3; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit the parser subclass with embedded tables. + * @param out stream to produce output on. + * @param action_table internal representation of the action table. + * @param reduce_table internal representation of the reduce-goto table. + * @param start_st start state of the parse machine. + * @param start_prod start production of the grammar. + * @param compact_reduces do we use most frequent reduce as default? + * @param suppress_scanner should scanner be suppressed for compatibility? + */ + public static void parser( + PrintWriter out, + parse_action_table action_table, + parse_reduce_table reduce_table, + int start_st, + production start_prod, + boolean compact_reduces, + boolean suppress_scanner) + throws internal_error + { + long start_time = System.currentTimeMillis(); + + /* top of file */ + out.println(); + out.println("//----------------------------------------------------"); + out.println("// The following code was generated by " + + version.title_str); + out.println("// " + new Date()); + out.println("//----------------------------------------------------"); + out.println(); + emit_package(out); + + /* user supplied imports */ + for (int i = 0; i < import_list.size(); i++) + out.println("import " + import_list.elementAt(i) + ";"); + + /* class header */ + out.println(); + out.println("/** "+version.title_str+" generated parser."); + out.println(" * @version " + new Date()); + out.println(" */"); + out.println("public class " + parser_class_name + + " extends java_cup.runtime.lr_parser {"); + + /* constructors [CSA/davidm, 24-jul-99] */ + out.println(); + out.println(" /** Default constructor. */"); + out.println(" public " + parser_class_name + "() {super();}"); + if (!suppress_scanner) { + out.println(); + out.println(" /** Constructor which sets the default scanner. */"); + out.println(" public " + parser_class_name + + "(java_cup.runtime.Scanner s) {super(s);}"); + } + + /* emit the various tables */ + emit_production_table(out); + do_action_table(out, action_table, compact_reduces); + do_reduce_table(out, reduce_table); + + /* instance of the action encapsulation class */ + out.println(" /** Instance of action encapsulation class. */"); + out.println(" protected " + pre("actions") + " action_obj;"); + out.println(); + + /* action object initializer */ + out.println(" /** Action encapsulation object initializer. */"); + out.println(" protected void init_actions()"); + out.println(" {"); + out.println(" action_obj = new " + pre("actions") + "(this);"); + out.println(" }"); + out.println(); + + /* access to action code */ + out.println(" /** Invoke a user supplied parse action. */"); + out.println(" public java_cup.runtime.Symbol do_action("); + out.println(" int act_num,"); + out.println(" java_cup.runtime.lr_parser parser,"); + out.println(" java.util.Stack stack,"); + out.println(" int top)"); + out.println(" throws java.lang.Exception"); + out.println(" {"); + out.println(" /* call code in generated class */"); + out.println(" return action_obj." + pre("do_action(") + + "act_num, parser, stack, top);"); + out.println(" }"); + out.println(""); + + + /* method to tell the parser about the start state */ + out.println(" /** Indicates start state. */"); + out.println(" public int start_state() {return " + start_st + ";}"); + + /* method to indicate start production */ + out.println(" /** Indicates start production. */"); + out.println(" public int start_production() {return " + + start_production.index() + ";}"); + out.println(); + + /* methods to indicate EOF and error symbol indexes */ + out.println(" /** <code>EOF</code> Symbol index. */"); + out.println(" public int EOF_sym() {return " + terminal.EOF.index() + + ";}"); + out.println(); + out.println(" /** <code>error</code> Symbol index. */"); + out.println(" public int error_sym() {return " + terminal.error.index() + + ";}"); + out.println(); + + /* user supplied code for user_init() */ + if (init_code != null) + { + out.println(); + out.println(" /** User initialization code. */"); + out.println(" public void user_init() throws java.lang.Exception"); + out.println(" {"); + out.println(init_code); + out.println(" }"); + } + + /* user supplied code for scan */ + if (scan_code != null) + { + out.println(); + out.println(" /** Scan to get the next Symbol. */"); + out.println(" public java_cup.runtime.Symbol scan()"); + out.println(" throws java.lang.Exception"); + out.println(" {"); + out.println(scan_code); + out.println(" }"); + } + + /* user supplied code */ + if (parser_code != null) + { + out.println(); + out.println(parser_code); + } + + /* end of class */ + out.println("}"); + + /* put out the action code class */ + emit_action_code(out, start_prod); + + parser_time = System.currentTimeMillis() - start_time; + } + + /*-----------------------------------------------------------*/ +} diff --git a/open-nars/java_cup/internal_error.java b/open-nars/java_cup/internal_error.java new file mode 100644 index 0000000000000000000000000000000000000000..4d3e7c2c7615b577c36d03e6e90cd13d960ac5ec --- /dev/null +++ b/open-nars/java_cup/internal_error.java @@ -0,0 +1,22 @@ + +package java_cup; + +/** Exception subclass for reporting internal errors in JavaCup. */ +public class internal_error extends Exception + { + /** Constructor with a message */ + public internal_error(String msg) + { + super(msg); + } + + /** Method called to do a forced error exit on an internal error + for cases when we can't actually throw the exception. */ + public void crash() + { + System.err.println("JavaCUP Fatal Internal Error Detected"); + System.err.println(getMessage()); + printStackTrace(); + System.exit(-1); + } + } diff --git a/open-nars/java_cup/lalr_item.java b/open-nars/java_cup/lalr_item.java new file mode 100644 index 0000000000000000000000000000000000000000..fe920544cb6e9f8b6a4eba7149262103cf525088 --- /dev/null +++ b/open-nars/java_cup/lalr_item.java @@ -0,0 +1,330 @@ +package java_cup; + +import java.util.Stack; +import java.util.Enumeration; + +/** This class represents an LALR item. Each LALR item consists of + * a production, a "dot" at a position within that production, and + * a set of lookahead symbols (terminal). (The first two of these parts + * are provide by the super class). An item is designed to represent a + * configuration that the parser may be in. For example, an item of the + * form: <pre> + * [A ::= B * C d E , {a,b,c}] + * </pre> + * indicates that the parser is in the middle of parsing the production <pre> + * A ::= B C d E + * </pre> + * that B has already been parsed, and that we will expect to see a lookahead + * of either a, b, or c once the complete RHS of this production has been + * found.<p> + * + * Items may initially be missing some items from their lookahead sets. + * Links are maintained from each item to the set of items that would need + * to be updated if symbols are added to its lookahead set. During + * "lookahead propagation", we add symbols to various lookahead sets and + * propagate these changes across these dependency links as needed. + * + * @see java_cup.lalr_item_set + * @see java_cup.lalr_state + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class lalr_item extends lr_item_core { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param prod the production for the item. + * @param pos the position of the "dot" within the production. + * @param look the set of lookahead symbols. + */ + public lalr_item(production prod, int pos, terminal_set look) + throws internal_error + { + super(prod, pos); + _lookahead = look; + _propagate_items = new Stack(); + needs_propagation = true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with default position (dot at start). + * @param prod the production for the item. + * @param look the set of lookahead symbols. + */ + public lalr_item(production prod, terminal_set look) throws internal_error + { + this(prod,0,look); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with default position and empty lookahead set. + * @param prod the production for the item. + */ + public lalr_item(production prod) throws internal_error + { + this(prod,0,new terminal_set()); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The lookahead symbols of the item. */ + protected terminal_set _lookahead; + + /** The lookahead symbols of the item. */ + public terminal_set lookahead() {return _lookahead;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Links to items that the lookahead needs to be propagated to. */ + protected Stack _propagate_items; + + /** Links to items that the lookahead needs to be propagated to */ + public Stack propagate_items() {return _propagate_items;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Flag to indicate that this item needs to propagate its lookahead + * (whether it has changed or not). + */ + protected boolean needs_propagation; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add a new item to the set of items we propagate to. */ + public void add_propagate(lalr_item prop_to) + { + _propagate_items.push(prop_to); + needs_propagation = true; + } + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Propagate incoming lookaheads through this item to others need to + * be changed. + * @params incoming symbols to potentially be added to lookahead of this item. + */ + public void propagate_lookaheads(terminal_set incoming) throws internal_error + { + boolean change = false; + + /* if we don't need to propagate, then bail out now */ + if (!needs_propagation && (incoming == null || incoming.empty())) + return; + + /* if we have null incoming, treat as an empty set */ + if (incoming != null) + { + /* add the incoming to the lookahead of this item */ + change = lookahead().add(incoming); + } + + /* if we changed or need it anyway, propagate across our links */ + if (change || needs_propagation) + { + /* don't need to propagate again */ + needs_propagation = false; + + /* propagate our lookahead into each item we are linked to */ + for (int i = 0; i < propagate_items().size(); i++) + ((lalr_item)propagate_items().elementAt(i)) + .propagate_lookaheads(lookahead()); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce the new lalr_item that results from shifting the dot one position + * to the right. + */ + public lalr_item shift() throws internal_error + { + lalr_item result; + + /* can't shift if we have dot already at the end */ + if (dot_at_end()) + throw new internal_error("Attempt to shift past end of an lalr_item"); + + /* create the new item w/ the dot shifted by one */ + result = new lalr_item(the_production(), dot_pos()+1, + new terminal_set(lookahead())); + + /* change in our lookahead needs to be propagated to this item */ + add_propagate(result); + + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Calculate lookahead representing symbols that could appear after the + * symbol that the dot is currently in front of. Note: this routine must + * not be invoked before first sets and nullability has been calculated + * for all non terminals. + */ + public terminal_set calc_lookahead(terminal_set lookahead_after) + throws internal_error + { + terminal_set result; + int pos; + production_part part; + symbol sym; + + /* sanity check */ + if (dot_at_end()) + throw new internal_error( + "Attempt to calculate a lookahead set with a completed item"); + + /* start with an empty result */ + result = new terminal_set(); + + /* consider all nullable symbols after the one to the right of the dot */ + for (pos = dot_pos()+1; pos < the_production().rhs_length(); pos++) + { + part = the_production().rhs(pos); + + /* consider what kind of production part it is -- skip actions */ + if (!part.is_action()) + { + sym = ((symbol_part)part).the_symbol(); + + /* if its a terminal add it in and we are done */ + if (!sym.is_non_term()) + { + result.add((terminal)sym); + return result; + } + else + { + /* otherwise add in first set of the non terminal */ + result.add(((non_terminal)sym).first_set()); + + /* if its nullable we continue adding, if not, we are done */ + if (!((non_terminal)sym).nullable()) + return result; + } + } + } + + /* if we get here everything past the dot was nullable + we add in the lookahead for after the production and we are done */ + result.add(lookahead_after); + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if everything from the symbol one beyond the dot all the + * way to the end of the right hand side is nullable. This would indicate + * that the lookahead of this item must be included in the lookaheads of + * all items produced as a closure of this item. Note: this routine should + * not be invoked until after first sets and nullability have been + * calculated for all non terminals. + */ + public boolean lookahead_visible() throws internal_error + { + production_part part; + symbol sym; + + /* if the dot is at the end, we have a problem, but the cleanest thing + to do is just return true. */ + if (dot_at_end()) return true; + + /* walk down the rhs and bail if we get a non-nullable symbol */ + for (int pos = dot_pos() + 1; pos < the_production().rhs_length(); pos++) + { + part = the_production().rhs(pos); + + /* skip actions */ + if (!part.is_action()) + { + sym = ((symbol_part)part).the_symbol(); + + /* if its a terminal we fail */ + if (!sym.is_non_term()) return false; + + /* if its not nullable we fail */ + if (!((non_terminal)sym).nullable()) return false; + } + } + + /* if we get here its all nullable */ + return true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison -- here we only require the cores to be equal since + * we need to do sets of items based only on core equality (ignoring + * lookahead sets). + */ + public boolean equals(lalr_item other) + { + if (other == null) return false; + return super.equals(other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof lalr_item)) + return false; + else + return equals((lalr_item)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return a hash code -- here we only hash the core since we only test core + * matching in LALR items. + */ + public int hashCode() + { + return super.hashCode(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to string. */ + public String toString() + { + String result = ""; + + // additional output for debugging: + // result += "(" + obj_hash() + ")"; + result += "["; + result += super.toString(); + result += ", "; + if (lookahead() != null) + { + result += "{"; + for (int t = 0; t < terminal.number(); t++) + if (lookahead().contains(t)) + result += terminal.find(t).name() + " "; + result += "}"; + } + else + result += "NULL LOOKAHEAD!!"; + result += "]"; + + // additional output for debugging: + // result += " -> "; + // for (int i = 0; i<propagate_items().size(); i++) + // result+=((lalr_item)(propagate_items().elementAt(i))).obj_hash()+" "; + // + // if (needs_propagation) result += " NP"; + + return result; + } + /*-----------------------------------------------------------*/ +} diff --git a/open-nars/java_cup/lalr_item_set.java b/open-nars/java_cup/lalr_item_set.java new file mode 100644 index 0000000000000000000000000000000000000000..233a68f328de82f2a0971db609a5f640c9c8a700 --- /dev/null +++ b/open-nars/java_cup/lalr_item_set.java @@ -0,0 +1,371 @@ + +package java_cup; + +import java.util.Hashtable; +import java.util.Enumeration; + +/** This class represents a set of LALR items. For purposes of building + * these sets, items are considered unique only if they have unique cores + * (i.e., ignoring differences in their lookahead sets).<p> + * + * This class provides fairly conventional set oriented operations (union, + * sub/super-set tests, etc.), as well as an LALR "closure" operation (see + * compute_closure()). + * + * @see java_cup.lalr_item + * @see java_cup.lalr_state + * @version last updated: 3/6/96 + * @author Scott Hudson + */ + +public class lalr_item_set { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Constructor for an empty set. */ + public lalr_item_set() { } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor for cloning from another set. + * @param other indicates set we should copy from. + */ + public lalr_item_set(lalr_item_set other) + throws internal_error + { + not_null(other); + _all = (Hashtable)other._all.clone(); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** A hash table to implement the set. We store the items using themselves + * as keys. + */ + protected Hashtable _all = new Hashtable(11); + + /** Access to all elements of the set. */ + public Enumeration all() {return _all.elements();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Cached hashcode for this set. */ + protected Integer hashcode_cache = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Size of the set */ + public int size() {return _all.size();} + + /*-----------------------------------------------------------*/ + /*--- Set Operation Methods ---------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Does the set contain a particular item? + * @param itm the item in question. + */ + public boolean contains(lalr_item itm) {return _all.containsKey(itm);} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return the item in the set matching a particular item (or null if not + * found) + * @param itm the item we are looking for. + */ + public lalr_item find(lalr_item itm) {return (lalr_item)_all.get(itm);} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Is this set an (improper) subset of another? + * @param other the other set in question. + */ + public boolean is_subset_of(lalr_item_set other) throws internal_error + { + not_null(other); + + /* walk down our set and make sure every element is in the other */ + for (Enumeration e = all(); e.hasMoreElements(); ) + if (!other.contains((lalr_item)e.nextElement())) + return false; + + /* they were all there */ + return true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Is this set an (improper) superset of another? + * @param other the other set in question. + */ + public boolean is_superset_of(lalr_item_set other) throws internal_error + { + not_null(other); + return other.is_subset_of(this); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add a singleton item, merging lookahead sets if the item is already + * part of the set. returns the element of the set that was added or + * merged into. + * @param itm the item being added. + */ + public lalr_item add(lalr_item itm) throws internal_error + { + lalr_item other; + + not_null(itm); + + /* see if an item with a matching core is already there */ + other = (lalr_item)_all.get(itm); + + /* if so, merge this lookahead into the original and leave it */ + if (other != null) + { + other.lookahead().add(itm.lookahead()); + return other; + } + /* otherwise we just go in the set */ + else + { + /* invalidate cached hashcode */ + hashcode_cache = null; + + _all.put(itm,itm); + return itm; + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Remove a single item if it is in the set. + * @param itm the item to remove. + */ + public void remove(lalr_item itm) throws internal_error + { + not_null(itm); + + /* invalidate cached hashcode */ + hashcode_cache = null; + + /* remove it from hash table implementing set */ + _all.remove(itm); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add a complete set, merging lookaheads where items are already in + * the set + * @param other the set to be added. + */ + public void add(lalr_item_set other) throws internal_error + { + not_null(other); + + /* walk down the other set and do the adds individually */ + for (Enumeration e = other.all(); e.hasMoreElements(); ) + add((lalr_item)e.nextElement()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Remove (set subtract) a complete set. + * @param other the set to remove. + */ + public void remove(lalr_item_set other) throws internal_error + { + not_null(other); + + /* walk down the other set and do the removes individually */ + for (Enumeration e = other.all(); e.hasMoreElements(); ) + remove((lalr_item)e.nextElement()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Remove and return one item from the set (done in hash order). */ + public lalr_item get_one() throws internal_error + { + Enumeration the_set; + lalr_item result; + + the_set = all(); + if (the_set.hasMoreElements()) + { + result = (lalr_item)the_set.nextElement(); + remove(result); + return result; + } + else + return null; + } + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Helper function for null test. Throws an interal_error exception if its + * parameter is null. + * @param obj the object we are testing. + */ + protected void not_null(Object obj) throws internal_error + { + if (obj == null) + throw new internal_error("Null object used in set operation"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Compute the closure of the set using the LALR closure rules. Basically + * for every item of the form: <pre> + * [L ::= a *N alpha, l] + * </pre> + * (where N is a a non terminal and alpha is a string of symbols) make + * sure there are also items of the form: <pre> + * [N ::= *beta, first(alpha l)] + * </pre> + * corresponding to each production of N. Items with identical cores but + * differing lookahead sets are merged by creating a new item with the same + * core and the union of the lookahead sets (the LA in LALR stands for + * "lookahead merged" and this is where the merger is). This routine + * assumes that nullability and first sets have been computed for all + * productions before it is called. + */ + public void compute_closure() + throws internal_error + { + lalr_item_set consider; + lalr_item itm, new_itm, add_itm; + non_terminal nt; + terminal_set new_lookaheads; + Enumeration p; + production prod; + boolean need_prop; + + + + /* invalidate cached hashcode */ + hashcode_cache = null; + + /* each current element needs to be considered */ + consider = new lalr_item_set(this); + + /* repeat this until there is nothing else to consider */ + while (consider.size() > 0) + { + /* get one item to consider */ + itm = consider.get_one(); + + /* do we have a dot before a non terminal */ + nt = itm.dot_before_nt(); + if (nt != null) + { + /* create the lookahead set based on first after dot */ + new_lookaheads = itm.calc_lookahead(itm.lookahead()); + + /* are we going to need to propagate our lookahead to new item */ + need_prop = itm.lookahead_visible(); + + /* create items for each production of that non term */ + for (p = nt.productions(); p.hasMoreElements(); ) + { + prod = (production)p.nextElement(); + + /* create new item with dot at start and that lookahead */ + new_itm = new lalr_item(prod, + new terminal_set(new_lookaheads)); + + /* add/merge item into the set */ + add_itm = add(new_itm); + /* if propagation is needed link to that item */ + if (need_prop) + itm.add_propagate(add_itm); + + /* was this was a new item*/ + if (add_itm == new_itm) + { + /* that may need further closure, consider it also */ + consider.add(new_itm); + } + } + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(lalr_item_set other) + { + if (other == null || other.size() != size()) return false; + + /* once we know they are the same size, then improper subset does test */ + try { + return is_subset_of(other); + } catch (internal_error e) { + /* can't throw error from here (because superclass doesn't) so crash */ + e.crash(); + return false; + } + + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof lalr_item_set)) + return false; + else + return equals((lalr_item_set)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return hash code. */ + public int hashCode() + { + int result = 0; + Enumeration e; + int cnt; + + /* only compute a new one if we don't have it cached */ + if (hashcode_cache == null) + { + /* hash together codes from at most first 5 elements */ + // CSA fix! we'd *like* to hash just a few elements, but + // that means equal sets will have inequal hashcodes, which + // we're not allowed (by contract) to do. So hash them all. + for (e = all(), cnt=0 ; e.hasMoreElements() /*&& cnt<5*/; cnt++) + result ^= ((lalr_item)e.nextElement()).hashCode(); + + hashcode_cache = new Integer(result); + } + + return hashcode_cache.intValue(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to string. */ + public String toString() + { + StringBuffer result = new StringBuffer(); + + result.append("{\n"); + for (Enumeration e=all(); e.hasMoreElements(); ) + { + result.append(" " + (lalr_item)e.nextElement() + "\n"); + } + result.append("}"); + + return result.toString(); + } + /*-----------------------------------------------------------*/ +} + diff --git a/open-nars/java_cup/lalr_state.java b/open-nars/java_cup/lalr_state.java new file mode 100644 index 0000000000000000000000000000000000000000..5298e877c5497df37944692b92b22f1d7a94c8fb --- /dev/null +++ b/open-nars/java_cup/lalr_state.java @@ -0,0 +1,884 @@ + +package java_cup; + +import java.util.Hashtable; +import java.util.Enumeration; +import java.util.Stack; + +/** This class represents a state in the LALR viable prefix recognition machine. + * A state consists of an LALR item set and a set of transitions to other + * states under terminal and non-terminal symbols. Each state represents + * a potential configuration of the parser. If the item set of a state + * includes an item such as: <pre> + * [A ::= B * C d E , {a,b,c}] + * </pre> + * this indicates that when the parser is in this state it is currently + * looking for an A of the given form, has already seen the B, and would + * expect to see an a, b, or c after this sequence is complete. Note that + * the parser is normally looking for several things at once (represented + * by several items). In our example above, the state would also include + * items such as: <pre> + * [C ::= * X e Z, {d}] + * [X ::= * f, {e}] + * </pre> + * to indicate that it was currently looking for a C followed by a d (which + * would be reduced into a C, matching the first symbol in our production + * above), and the terminal f followed by e.<p> + * + * At runtime, the parser uses a viable prefix recognition machine made up + * of these states to parse. The parser has two operations, shift and reduce. + * In a shift, it consumes one Symbol and makes a transition to a new state. + * This corresponds to "moving the dot past" a terminal in one or more items + * in the state (these new shifted items will then be found in the state at + * the end of the transition). For a reduce operation, the parser is + * signifying that it is recognizing the RHS of some production. To do this + * it first "backs up" by popping a stack of previously saved states. It + * pops off the same number of states as are found in the RHS of the + * production. This leaves the machine in the same state is was in when the + * parser first attempted to find the RHS. From this state it makes a + * transition based on the non-terminal on the LHS of the production. This + * corresponds to placing the parse in a configuration equivalent to having + * replaced all the symbols from the the input corresponding to the RHS with + * the symbol on the LHS. + * + * @see java_cup.lalr_item + * @see java_cup.lalr_item_set + * @see java_cup.lalr_transition + * @version last updated: 7/3/96 + * @author Frank Flannery + * + */ + +public class lalr_state { + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Constructor for building a state from a set of items. + * @param itms the set of items that makes up this state. + */ + public lalr_state(lalr_item_set itms) throws internal_error + { + /* don't allow null or duplicate item sets */ + if (itms == null) + throw new internal_error( + "Attempt to construct an LALR state from a null item set"); + + if (find_state(itms) != null) + throw new internal_error( + "Attempt to construct a duplicate LALR state"); + + /* assign a unique index */ + _index = next_index++; + + /* store the items */ + _items = itms; + + /* add to the global collection, keyed with its item set */ + _all.put(_items,this); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + /** Collection of all states. */ + protected static Hashtable _all = new Hashtable(); + + /** Collection of all states. */ + public static Enumeration all() {return _all.elements();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Indicate total number of states there are. */ + public static int number() {return _all.size();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Hash table to find states by their kernels (i.e, the original, + * unclosed, set of items -- which uniquely define the state). This table + * stores state objects using (a copy of) their kernel item sets as keys. + */ + protected static Hashtable _all_kernels = new Hashtable(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Find and return state with a given a kernel item set (or null if not + * found). The kernel item set is the subset of items that were used to + * originally create the state. These items are formed by "shifting the + * dot" within items of other states that have a transition to this one. + * The remaining elements of this state's item set are added during closure. + * @param itms the kernel set of the state we are looking for. + */ + public static lalr_state find_state(lalr_item_set itms) + { + if (itms == null) + return null; + else + return (lalr_state)_all.get(itms); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Static counter for assigning unique state indexes. */ + protected static int next_index = 0; + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The item set for this state. */ + protected lalr_item_set _items; + + /** The item set for this state. */ + public lalr_item_set items() {return _items;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** List of transitions out of this state. */ + protected lalr_transition _transitions = null; + + /** List of transitions out of this state. */ + public lalr_transition transitions() {return _transitions;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Index of this state in the parse tables */ + protected int _index; + + /** Index of this state in the parse tables */ + public int index() {return _index;} + + /*-----------------------------------------------------------*/ + /*--- Static Methods ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Helper routine for debugging -- produces a dump of the given state + * onto System.out. + */ + protected static void dump_state(lalr_state st) throws internal_error + { + lalr_item_set itms; + lalr_item itm; + production_part part; + + if (st == null) + { + System.out.println("NULL lalr_state"); + return; + } + + System.out.println("lalr_state [" + st.index() + "] {"); + itms = st.items(); + for (Enumeration e = itms.all(); e.hasMoreElements(); ) + { + itm = (lalr_item)e.nextElement(); + System.out.print(" ["); + System.out.print(itm.the_production().lhs().the_symbol().name()); + System.out.print(" ::= "); + for (int i = 0; i<itm.the_production().rhs_length(); i++) + { + if (i == itm.dot_pos()) System.out.print("(*) "); + part = itm.the_production().rhs(i); + if (part.is_action()) + System.out.print("{action} "); + else + System.out.print(((symbol_part)part).the_symbol().name() + " "); + } + if (itm.dot_at_end()) System.out.print("(*) "); + System.out.println("]"); + } + System.out.println("}"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Propagate lookahead sets through the constructed viable prefix + * recognizer. When the machine is constructed, each item that results + in the creation of another such that its lookahead is included in the + other's will have a propagate link set up for it. This allows additions + to the lookahead of one item to be included in other items that it + was used to directly or indirectly create. + */ + protected static void propagate_all_lookaheads() throws internal_error + { + /* iterate across all states */ + for (Enumeration st = all(); st.hasMoreElements(); ) + { + /* propagate lookaheads out of that state */ + ((lalr_state)st.nextElement()).propagate_lookaheads(); + } + } + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Add a transition out of this state to another. + * @param on_sym the symbol the transition is under. + * @param to_st the state the transition goes to. + */ + public void add_transition(symbol on_sym, lalr_state to_st) + throws internal_error + { + lalr_transition trans; + + /* create a new transition object and put it in our list */ + trans = new lalr_transition(on_sym, to_st, _transitions); + _transitions = trans; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Build an LALR viable prefix recognition machine given a start + * production. This method operates by first building a start state + * from the start production (based on a single item with the dot at + * the beginning and EOF as expected lookahead). Then for each state + * it attempts to extend the machine by creating transitions out of + * the state to new or existing states. When considering extension + * from a state we make a transition on each symbol that appears before + * the dot in some item. For example, if we have the items: <pre> + * [A ::= a b * X c, {d,e}] + * [B ::= a b * X d, {a,b}] + * </pre> + * in some state, then we would be making a transition under X to a new + * state. This new state would be formed by a "kernel" of items + * corresponding to moving the dot past the X. In this case: <pre> + * [A ::= a b X * c, {d,e}] + * [B ::= a b X * Y, {a,b}] + * </pre> + * The full state would then be formed by "closing" this kernel set of + * items so that it included items that represented productions of things + * the parser was now looking for. In this case we would items + * corresponding to productions of Y, since various forms of Y are expected + * next when in this state (see lalr_item_set.compute_closure() for details + * on closure). <p> + * + * The process of building the viable prefix recognizer terminates when no + * new states can be added. However, in order to build a smaller number of + * states (i.e., corresponding to LALR rather than canonical LR) the state + * building process does not maintain full loookaheads in all items. + * Consequently, after the machine is built, we go back and propagate + * lookaheads through the constructed machine using a call to + * propagate_all_lookaheads(). This makes use of propagation links + * constructed during the closure and transition process. + * + * @param start_prod the start production of the grammar + * @see java_cup.lalr_item_set#compute_closure + * @see java_cup.lalr_state#propagate_all_lookaheads + */ + + public static lalr_state build_machine(production start_prod) + throws internal_error + { + lalr_state start_state; + lalr_item_set start_items; + lalr_item_set new_items; + lalr_item_set linked_items; + lalr_item_set kernel; + Stack work_stack = new Stack(); + lalr_state st, new_st; + symbol_set outgoing; + lalr_item itm, new_itm, existing, fix_itm; + symbol sym, sym2; + Enumeration i, s, fix; + + /* sanity check */ + if (start_prod == null) + throw new internal_error( + "Attempt to build viable prefix recognizer using a null production"); + + /* build item with dot at front of start production and EOF lookahead */ + start_items = new lalr_item_set(); + + itm = new lalr_item(start_prod); + itm.lookahead().add(terminal.EOF); + + start_items.add(itm); + + /* create copy the item set to form the kernel */ + kernel = new lalr_item_set(start_items); + + /* create the closure from that item set */ + start_items.compute_closure(); + + /* build a state out of that item set and put it in our work set */ + start_state = new lalr_state(start_items); + work_stack.push(start_state); + + /* enter the state using the kernel as the key */ + _all_kernels.put(kernel, start_state); + + /* continue looking at new states until we have no more work to do */ + while (!work_stack.empty()) + { + /* remove a state from the work set */ + st = (lalr_state)work_stack.pop(); + + /* gather up all the symbols that appear before dots */ + outgoing = new symbol_set(); + for (i = st.items().all(); i.hasMoreElements(); ) + { + itm = (lalr_item)i.nextElement(); + + /* add the symbol before the dot (if any) to our collection */ + sym = itm.symbol_after_dot(); + if (sym != null) outgoing.add(sym); + } + + /* now create a transition out for each individual symbol */ + for (s = outgoing.all(); s.hasMoreElements(); ) + { + sym = (symbol)s.nextElement(); + + /* will be keeping the set of items with propagate links */ + linked_items = new lalr_item_set(); + + /* gather up shifted versions of all the items that have this + symbol before the dot */ + new_items = new lalr_item_set(); + for (i = st.items().all(); i.hasMoreElements();) + { + itm = (lalr_item)i.nextElement(); + + /* if this is the symbol we are working on now, add to set */ + sym2 = itm.symbol_after_dot(); + if (sym.equals(sym2)) + { + /* add to the kernel of the new state */ + new_items.add(itm.shift()); + + /* remember that itm has propagate link to it */ + linked_items.add(itm); + } + } + + /* use new items as state kernel */ + kernel = new lalr_item_set(new_items); + + /* have we seen this one already? */ + new_st = (lalr_state)_all_kernels.get(kernel); + + /* if we haven't, build a new state out of the item set */ + if (new_st == null) + { + /* compute closure of the kernel for the full item set */ + new_items.compute_closure(); + + /* build the new state */ + new_st = new lalr_state(new_items); + + /* add the new state to our work set */ + work_stack.push(new_st); + + /* put it in our kernel table */ + _all_kernels.put(kernel, new_st); + } + /* otherwise relink propagation to items in existing state */ + else + { + /* walk through the items that have links to the new state */ + for (fix = linked_items.all(); fix.hasMoreElements(); ) + { + fix_itm = (lalr_item)fix.nextElement(); + + /* look at each propagate link out of that item */ + for (int l =0; l < fix_itm.propagate_items().size(); l++) + { + /* pull out item linked to in the new state */ + new_itm = + (lalr_item)fix_itm.propagate_items().elementAt(l); + + /* find corresponding item in the existing state */ + existing = new_st.items().find(new_itm); + + /* fix up the item so it points to the existing set */ + if (existing != null) + fix_itm.propagate_items().setElementAt(existing ,l); + } + } + } + + /* add a transition from current state to that state */ + st.add_transition(sym, new_st); + } + } + + /* all done building states */ + + /* propagate complete lookahead sets throughout the states */ + propagate_all_lookaheads(); + + return start_state; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Propagate lookahead sets out of this state. This recursively + * propagates to all items that have propagation links from some item + * in this state. + */ + protected void propagate_lookaheads() throws internal_error + { + /* recursively propagate out from each item in the state */ + for (Enumeration itm = items().all(); itm.hasMoreElements(); ) + ((lalr_item)itm.nextElement()).propagate_lookaheads(null); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Fill in the parse table entries for this state. There are two + * parse tables that encode the viable prefix recognition machine, an + * action table and a reduce-goto table. The rows in each table + * correspond to states of the machine. The columns of the action table + * are indexed by terminal symbols and correspond to either transitions + * out of the state (shift entries) or reductions from the state to some + * previous state saved on the stack (reduce entries). All entries in the + * action table that are not shifts or reduces, represent errors. The + * reduce-goto table is indexed by non terminals and represents transitions + * out of a state on that non-terminal.<p> + * Conflicts occur if more than one action needs to go in one entry of the + * action table (this cannot happen with the reduce-goto table). Conflicts + * are resolved by always shifting for shift/reduce conflicts and choosing + * the lowest numbered production (hence the one that appeared first in + * the specification) in reduce/reduce conflicts. All conflicts are + * reported and if more conflicts are detected than were declared by the + * user, code generation is aborted. + * + * @param act_table the action table to put entries in. + * @param reduce_table the reduce-goto table to put entries in. + */ + public void build_table_entries( + parse_action_table act_table, + parse_reduce_table reduce_table) + throws internal_error + { + parse_action_row our_act_row; + parse_reduce_row our_red_row; + lalr_item itm; + parse_action act, other_act; + symbol sym; + terminal_set conflict_set = new terminal_set(); + + /* pull out our rows from the tables */ + our_act_row = act_table.under_state[index()]; + our_red_row = reduce_table.under_state[index()]; + + /* consider each item in our state */ + for (Enumeration i = items().all(); i.hasMoreElements(); ) + { + itm = (lalr_item)i.nextElement(); + + + /* if its completed (dot at end) then reduce under the lookahead */ + if (itm.dot_at_end()) + { + act = new reduce_action(itm.the_production()); + + /* consider each lookahead symbol */ + for (int t = 0; t < terminal.number(); t++) + { + /* skip over the ones not in the lookahead */ + if (!itm.lookahead().contains(t)) continue; + + /* if we don't already have an action put this one in */ + if (our_act_row.under_term[t].kind() == + parse_action.ERROR) + { + our_act_row.under_term[t] = act; + } + else + { + /* we now have at least one conflict */ + terminal term = terminal.find(t); + other_act = our_act_row.under_term[t]; + + /* if the other act was not a shift */ + if ((other_act.kind() != parse_action.SHIFT) && + (other_act.kind() != parse_action.NONASSOC)) + { + /* if we have lower index hence priority, replace it*/ + if (itm.the_production().index() < + ((reduce_action)other_act).reduce_with().index()) + { + /* replace the action */ + our_act_row.under_term[t] = act; + } + } else { + /* Check precedences,see if problem is correctable */ + if(fix_with_precedence(itm.the_production(), + t, our_act_row, act)) { + term = null; + } + } + if(term!=null) { + + conflict_set.add(term); + } + } + } + } + } + + /* consider each outgoing transition */ + for (lalr_transition trans=transitions(); trans!=null; trans=trans.next()) + { + /* if its on an terminal add a shift entry */ + sym = trans.on_symbol(); + if (!sym.is_non_term()) + { + act = new shift_action(trans.to_state()); + + /* if we don't already have an action put this one in */ + if ( our_act_row.under_term[sym.index()].kind() == + parse_action.ERROR) + { + our_act_row.under_term[sym.index()] = act; + } + else + { + /* we now have at least one conflict */ + production p = ((reduce_action)our_act_row.under_term[sym.index()]).reduce_with(); + + /* shift always wins */ + if (!fix_with_precedence(p, sym.index(), our_act_row, act)) { + our_act_row.under_term[sym.index()] = act; + conflict_set.add(terminal.find(sym.index())); + } + } + } + else + { + /* for non terminals add an entry to the reduce-goto table */ + our_red_row.under_non_term[sym.index()] = trans.to_state(); + } + } + + /* if we end up with conflict(s), report them */ + if (!conflict_set.empty()) + report_conflicts(conflict_set); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + + /** Procedure that attempts to fix a shift/reduce error by using + * precedences. --frankf 6/26/96 + * + * if a production (also called rule) or the lookahead terminal + * has a precedence, then the table can be fixed. if the rule + * has greater precedence than the terminal, a reduce by that rule + * in inserted in the table. If the terminal has a higher precedence, + * it is shifted. if they have equal precedence, then the associativity + * of the precedence is used to determine what to put in the table: + * if the precedence is left associative, the action is to reduce. + * if the precedence is right associative, the action is to shift. + * if the precedence is non associative, then it is a syntax error. + * + * @param p the production + * @param term_index the index of the lokahead terminal + * @param parse_action_row a row of the action table + * @param act the rule in conflict with the table entry + */ + + protected boolean fix_with_precedence( + production p, + int term_index, + parse_action_row table_row, + parse_action act) + + throws internal_error { + + terminal term = terminal.find(term_index); + + /* if the production has a precedence number, it can be fixed */ + if (p.precedence_num() > assoc.no_prec) { + + /* if production precedes terminal, put reduce in table */ + if (p.precedence_num() > term.precedence_num()) { + table_row.under_term[term_index] = + insert_reduce(table_row.under_term[term_index],act); + return true; + } + + /* if terminal precedes rule, put shift in table */ + else if (p.precedence_num() < term.precedence_num()) { + table_row.under_term[term_index] = + insert_shift(table_row.under_term[term_index],act); + return true; + } + else { /* they are == precedence */ + + /* equal precedences have equal sides, so only need to + look at one: if it is right, put shift in table */ + if (term.precedence_side() == assoc.right) { + table_row.under_term[term_index] = + insert_shift(table_row.under_term[term_index],act); + return true; + } + + /* if it is left, put reduce in table */ + else if (term.precedence_side() == assoc.left) { + table_row.under_term[term_index] = + insert_reduce(table_row.under_term[term_index],act); + return true; + } + + /* if it is nonassoc, we're not allowed to have two nonassocs + of equal precedence in a row, so put in NONASSOC */ + else if (term.precedence_side() == assoc.nonassoc) { + table_row.under_term[term_index] = new nonassoc_action(); + return true; + } else { + /* something really went wrong */ + throw new internal_error("Unable to resolve conflict correctly"); + } + } + } + /* check if terminal has precedence, if so, shift, since + rule does not have precedence */ + else if (term.precedence_num() > assoc.no_prec) { + table_row.under_term[term_index] = + insert_shift(table_row.under_term[term_index],act); + return true; + } + + /* otherwise, neither the rule nor the terminal has a precedence, + so it can't be fixed. */ + return false; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + + /* given two actions, and an action type, return the + action of that action type. give an error if they are of + the same action, because that should never have tried + to be fixed + + */ + protected parse_action insert_action( + parse_action a1, + parse_action a2, + int act_type) + throws internal_error + { + if ((a1.kind() == act_type) && (a2.kind() == act_type)) { + throw new internal_error("Conflict resolution of bogus actions"); + } else if (a1.kind() == act_type) { + return a1; + } else if (a2.kind() == act_type) { + return a2; + } else { + throw new internal_error("Conflict resolution of bogus actions"); + } + } + + /* find the shift in the two actions */ + protected parse_action insert_shift( + parse_action a1, + parse_action a2) + throws internal_error + { + return insert_action(a1, a2, parse_action.SHIFT); + } + + /* find the reduce in the two actions */ + protected parse_action insert_reduce( + parse_action a1, + parse_action a2) + throws internal_error + { + return insert_action(a1, a2, parse_action.REDUCE); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce warning messages for all conflicts found in this state. */ + protected void report_conflicts(terminal_set conflict_set) + throws internal_error + { + lalr_item itm, compare; + symbol shift_sym; + + boolean after_itm; + + /* consider each element */ + for (Enumeration itms = items().all(); itms.hasMoreElements(); ) + { + itm = (lalr_item)itms.nextElement(); + + /* clear the S/R conflict set for this item */ + + /* if it results in a reduce, it could be a conflict */ + if (itm.dot_at_end()) + { + /* not yet after itm */ + after_itm = false; + + /* compare this item against all others looking for conflicts */ + for (Enumeration comps = items().all(); comps.hasMoreElements(); ) + { + compare = (lalr_item)comps.nextElement(); + + /* if this is the item, next one is after it */ + if (itm == compare) after_itm = true; + + /* only look at it if its not the same item */ + if (itm != compare) + { + /* is it a reduce */ + if (compare.dot_at_end()) + { + /* only look at reduces after itm */ + if (after_itm) + /* does the comparison item conflict? */ + if (compare.lookahead().intersects(itm.lookahead())) + /* report a reduce/reduce conflict */ + report_reduce_reduce(itm, compare); + } + } + } + /* report S/R conflicts under all the symbols we conflict under */ + for (int t = 0; t < terminal.number(); t++) + if (conflict_set.contains(t)) + report_shift_reduce(itm,t); + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a warning message for one reduce/reduce conflict. + * + * @param itm1 first item in conflict. + * @param itm2 second item in conflict. + */ + protected void report_reduce_reduce(lalr_item itm1, lalr_item itm2) + throws internal_error + { + boolean comma_flag = false; + + System.err.println("*** Reduce/Reduce conflict found in state #"+index()); + System.err.print (" between "); + System.err.println(itm1.to_simple_string()); + System.err.print (" and "); + System.err.println(itm2.to_simple_string()); + System.err.print(" under symbols: {" ); + for (int t = 0; t < terminal.number(); t++) + { + if (itm1.lookahead().contains(t) && itm2.lookahead().contains(t)) + { + if (comma_flag) System.err.print(", "); else comma_flag = true; + System.err.print(terminal.find(t).name()); + } + } + System.err.println("}"); + System.err.print(" Resolved in favor of "); + if (itm1.the_production().index() < itm2.the_production().index()) + System.err.println("the first production.\n"); + else + System.err.println("the second production.\n"); + + /* count the conflict */ + emit.num_conflicts++; + lexer.warning_count++; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a warning message for one shift/reduce conflict. + * + * @param red_itm the item with the reduce. + * @param conflict_sym the index of the symbol conflict occurs under. + */ + protected void report_shift_reduce( + lalr_item red_itm, + int conflict_sym) + throws internal_error + { + lalr_item itm; + symbol shift_sym; + + /* emit top part of message including the reduce item */ + System.err.println("*** Shift/Reduce conflict found in state #"+index()); + System.err.print (" between "); + System.err.println(red_itm.to_simple_string()); + + /* find and report on all items that shift under our conflict symbol */ + for (Enumeration itms = items().all(); itms.hasMoreElements(); ) + { + itm = (lalr_item)itms.nextElement(); + + /* only look if its not the same item and not a reduce */ + if (itm != red_itm && !itm.dot_at_end()) + { + /* is it a shift on our conflicting terminal */ + shift_sym = itm.symbol_after_dot(); + if (!shift_sym.is_non_term() && shift_sym.index() == conflict_sym) + { + /* yes, report on it */ + System.err.println(" and " + itm.to_simple_string()); + } + } + } + System.err.println(" under symbol "+ terminal.find(conflict_sym).name()); + System.err.println(" Resolved in favor of shifting.\n"); + + /* count the conflict */ + emit.num_conflicts++; + lexer.warning_count++; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(lalr_state other) + { + /* we are equal if our item sets are equal */ + return other != null && items().equals(other.items()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof lalr_state)) + return false; + else + return equals((lalr_state)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a hash code. */ + public int hashCode() + { + /* just use the item set hash code */ + return items().hashCode(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + String result; + lalr_transition tr; + + /* dump the item set */ + result = "lalr_state [" + index() + "]: " + _items + "\n"; + + /* do the transitions */ + for (tr = transitions(); tr != null; tr = tr.next()) + { + result += tr; + result += "\n"; + } + + return result; + } + + /*-----------------------------------------------------------*/ +} diff --git a/open-nars/java_cup/lalr_transition.java b/open-nars/java_cup/lalr_transition.java new file mode 100644 index 0000000000000000000000000000000000000000..1c941bd9ebc3094436cd37f0d7636f0ed3c42a2c --- /dev/null +++ b/open-nars/java_cup/lalr_transition.java @@ -0,0 +1,93 @@ +package java_cup; + +/** This class represents a transition in an LALR viable prefix recognition + * machine. Transitions can be under terminals for non-terminals. They are + * internally linked together into singly linked lists containing all the + * transitions out of a single state via the _next field. + * + * @see java_cup.lalr_state + * @version last updated: 11/25/95 + * @author Scott Hudson + * + */ +public class lalr_transition { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param on_sym symbol we are transitioning on. + * @param to_st state we transition to. + * @param nxt next transition in linked list. + */ + public lalr_transition(symbol on_sym, lalr_state to_st, lalr_transition nxt) + throws internal_error + { + /* sanity checks */ + if (on_sym == null) + throw new internal_error("Attempt to create transition on null symbol"); + if (to_st == null) + throw new internal_error("Attempt to create transition to null state"); + + /* initialize */ + _on_symbol = on_sym; + _to_state = to_st; + _next = nxt; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with null next. + * @param on_sym symbol we are transitioning on. + * @param to_st state we transition to. + */ + public lalr_transition(symbol on_sym, lalr_state to_st) throws internal_error + { + this(on_sym, to_st, null); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The symbol we make the transition on. */ + protected symbol _on_symbol; + + /** The symbol we make the transition on. */ + public symbol on_symbol() {return _on_symbol;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The state we transition to. */ + protected lalr_state _to_state; + + /** The state we transition to. */ + public lalr_state to_state() {return _to_state;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Next transition in linked list of transitions out of a state */ + protected lalr_transition _next; + + /** Next transition in linked list of transitions out of a state */ + public lalr_transition next() {return _next;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Convert to a string. */ + public String toString() + { + String result; + + result = "transition on " + on_symbol().name() + " to state ["; + result += _to_state.index(); + result += "]"; + + return result; + } + + /*-----------------------------------------------------------*/ +} diff --git a/open-nars/java_cup/lexer.java b/open-nars/java_cup/lexer.java new file mode 100644 index 0000000000000000000000000000000000000000..2230d123f10e9c7838440ac47a4199d61e31cfab --- /dev/null +++ b/open-nars/java_cup/lexer.java @@ -0,0 +1,543 @@ +package java_cup; + +import java_cup.runtime.Symbol; +import java.util.Hashtable; + +/** This class implements a small scanner (aka lexical analyzer or lexer) for + * the JavaCup specification. This scanner reads characters from standard + * input (System.in) and returns integers corresponding to the terminal + * number of the next Symbol. Once end of input is reached the EOF Symbol is + * returned on every subsequent call.<p> + * Symbols currently returned include: <pre> + * Symbol Constant Returned Symbol Constant Returned + * ------ ----------------- ------ ----------------- + * "package" PACKAGE "import" IMPORT + * "code" CODE "action" ACTION + * "parser" PARSER "terminal" TERMINAL + * "non" NON "init" INIT + * "scan" SCAN "with" WITH + * "start" START "precedence" PRECEDENCE + * "left" LEFT "right" RIGHT + * "nonassoc" NONASSOC "%prec PRECENT_PREC + * [ LBRACK ] RBRACK + * ; SEMI + * , COMMA * STAR + * . DOT : COLON + * ::= COLON_COLON_EQUALS | BAR + * identifier ID {:...:} CODE_STRING + * "nonterminal" NONTERMINAL + * </pre> + * All symbol constants are defined in sym.java which is generated by + * JavaCup from parser.cup.<p> + * + * In addition to the scanner proper (called first via init() then with + * next_token() to get each Symbol) this class provides simple error and + * warning routines and keeps a count of errors and warnings that is + * publicly accessible.<p> + * + * This class is "static" (i.e., it has only static members and methods). + * + * @version last updated: 7/3/96 + * @author Frank Flannery + */ +public class lexer { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** The only constructor is private, so no instances can be created. */ + private lexer() { } + + /*-----------------------------------------------------------*/ + /*--- Static (Class) Variables ------------------------------*/ + /*-----------------------------------------------------------*/ + + /** First character of lookahead. */ + protected static int next_char; + + /** Second character of lookahead. */ + protected static int next_char2; + + /** Second character of lookahead. */ + protected static int next_char3; + + /** Second character of lookahead. */ + protected static int next_char4; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** EOF constant. */ + protected static final int EOF_CHAR = -1; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Table of keywords. Keywords are initially treated as identifiers. + * Just before they are returned we look them up in this table to see if + * they match one of the keywords. The string of the name is the key here, + * which indexes Integer objects holding the symbol number. + */ + protected static Hashtable keywords = new Hashtable(23); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Table of single character symbols. For ease of implementation, we + * store all unambiguous single character Symbols in this table of Integer + * objects keyed by Integer objects with the numerical value of the + * appropriate char (currently Character objects have a bug which precludes + * their use in tables). + */ + protected static Hashtable char_symbols = new Hashtable(11); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Current line number for use in error messages. */ + protected static int current_line = 1; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Character position in current line. */ + protected static int current_position = 1; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Character position in current line. */ + protected static int absolute_position = 1; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of total errors detected so far. */ + public static int error_count = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of warnings issued so far */ + public static int warning_count = 0; + + /*-----------------------------------------------------------*/ + /*--- Static Methods ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Initialize the scanner. This sets up the keywords and char_symbols + * tables and reads the first two characters of lookahead. + */ + public static void init() throws java.io.IOException + { + /* set up the keyword table */ + keywords.put("package", new Integer(sym.PACKAGE)); + keywords.put("import", new Integer(sym.IMPORT)); + keywords.put("code", new Integer(sym.CODE)); + keywords.put("action", new Integer(sym.ACTION)); + keywords.put("parser", new Integer(sym.PARSER)); + keywords.put("terminal", new Integer(sym.TERMINAL)); + keywords.put("non", new Integer(sym.NON)); + keywords.put("nonterminal",new Integer(sym.NONTERMINAL));// [CSA] + keywords.put("init", new Integer(sym.INIT)); + keywords.put("scan", new Integer(sym.SCAN)); + keywords.put("with", new Integer(sym.WITH)); + keywords.put("start", new Integer(sym.START)); + keywords.put("precedence", new Integer(sym.PRECEDENCE)); + keywords.put("left", new Integer(sym.LEFT)); + keywords.put("right", new Integer(sym.RIGHT)); + keywords.put("nonassoc", new Integer(sym.NONASSOC)); + + /* set up the table of single character symbols */ + char_symbols.put(new Integer(';'), new Integer(sym.SEMI)); + char_symbols.put(new Integer(','), new Integer(sym.COMMA)); + char_symbols.put(new Integer('*'), new Integer(sym.STAR)); + char_symbols.put(new Integer('.'), new Integer(sym.DOT)); + char_symbols.put(new Integer('|'), new Integer(sym.BAR)); + char_symbols.put(new Integer('['), new Integer(sym.LBRACK)); + char_symbols.put(new Integer(']'), new Integer(sym.RBRACK)); + + /* read two characters of lookahead */ + next_char = System.in.read(); + if (next_char == EOF_CHAR) { + next_char2 = EOF_CHAR; + next_char3 = EOF_CHAR; + next_char4 = EOF_CHAR; + } else { + next_char2 = System.in.read(); + if (next_char2 == EOF_CHAR) { + next_char3 = EOF_CHAR; + next_char4 = EOF_CHAR; + } else { + next_char3 = System.in.read(); + if (next_char3 == EOF_CHAR) { + next_char4 = EOF_CHAR; + } else { + next_char4 = System.in.read(); + } + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Advance the scanner one character in the input stream. This moves + * next_char2 to next_char and then reads a new next_char2. + */ + protected static void advance() throws java.io.IOException + { + int old_char; + + old_char = next_char; + next_char = next_char2; + if (next_char == EOF_CHAR) { + next_char2 = EOF_CHAR; + next_char3 = EOF_CHAR; + next_char4 = EOF_CHAR; + } else { + next_char2 = next_char3; + if (next_char2 == EOF_CHAR) { + next_char3 = EOF_CHAR; + next_char4 = EOF_CHAR; + } else { + next_char3 = next_char4; + if (next_char3 == EOF_CHAR) { + next_char4 = EOF_CHAR; + } else { + next_char4 = System.in.read(); + } + } + } + + /* count this */ + absolute_position++; + current_position++; + if (old_char == '\n' || (old_char == '\r' && next_char!='\n')) + { + current_line++; + current_position = 1; + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit an error message. The message will be marked with both the + * current line number and the position in the line. Error messages + * are printed on standard error (System.err). + * @param message the message to print. + */ + public static void emit_error(String message) + { + System.err.println("Error at " + current_line + "(" + current_position + + "): " + message); + error_count++; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Emit a warning message. The message will be marked with both the + * current line number and the position in the line. Messages are + * printed on standard error (System.err). + * @param message the message to print. + */ + public static void emit_warn(String message) + { + System.err.println("Warning at " + current_line + "(" + current_position + + "): " + message); + warning_count++; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if a character is ok to start an id. + * @param ch the character in question. + */ + protected static boolean id_start_char(int ch) + { + /* allow for % in identifiers. a hack to allow my + %prec in. Should eventually make lex spec for this + frankf */ + return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || + (ch == '_'); + + // later need to deal with non-8-bit chars here + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if a character is ok for the middle of an id. + * @param ch the character in question. + */ + protected static boolean id_char(int ch) + { + return id_start_char(ch) || (ch >= '0' && ch <= '9'); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Try to look up a single character symbol, returns -1 for not found. + * @param ch the character in question. + */ + protected static int find_single_char(int ch) + { + Integer result; + + result = (Integer)char_symbols.get(new Integer((char)ch)); + if (result == null) + return -1; + else + return result.intValue(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Handle swallowing up a comment. Both old style C and new style C++ + * comments are handled. + */ + protected static void swallow_comment() throws java.io.IOException + { + /* next_char == '/' at this point */ + + /* is it a traditional comment */ + if (next_char2 == '*') + { + /* swallow the opener */ + advance(); advance(); + + /* swallow the comment until end of comment or EOF */ + for (;;) + { + /* if its EOF we have an error */ + if (next_char == EOF_CHAR) + { + emit_error("Specification file ends inside a comment"); + return; + } + + /* if we can see the closer we are done */ + if (next_char == '*' && next_char2 == '/') + { + advance(); + advance(); + return; + } + + /* otherwise swallow char and move on */ + advance(); + } + } + + /* is its a new style comment */ + if (next_char2 == '/') + { + /* swallow the opener */ + advance(); advance(); + + /* swallow to '\n', '\r', '\f', or EOF */ + while (next_char != '\n' && next_char != '\r' && + next_char != '\f' && next_char!=EOF_CHAR) + advance(); + + return; + + } + + /* shouldn't get here, but... if we get here we have an error */ + emit_error("Malformed comment in specification -- ignored"); + advance(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Swallow up a code string. Code strings begin with "{:" and include + all characters up to the first occurrence of ":}" (there is no way to + include ":}" inside a code string). The routine returns a String + object suitable for return by the scanner. + */ + protected static Symbol do_code_string() throws java.io.IOException + { + StringBuffer result = new StringBuffer(); + + /* at this point we have lookahead of "{:" -- swallow that */ + advance(); advance(); + + /* save chars until we see ":}" */ + while (!(next_char == ':' && next_char2 == '}')) + { + /* if we have run off the end issue a message and break out of loop */ + if (next_char == EOF_CHAR) + { + emit_error("Specification file ends inside a code string"); + break; + } + + /* otherwise record the char and move on */ + result.append(new Character((char)next_char)); + advance(); + } + + /* advance past the closer and build a return Symbol */ + advance(); advance(); + return new Symbol(sym.CODE_STRING, result.toString()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Process an identifier. Identifiers begin with a letter, underscore, + * or dollar sign, which is followed by zero or more letters, numbers, + * underscores or dollar signs. This routine returns a String suitable + * for return by the scanner. + */ + protected static Symbol do_id() throws java.io.IOException + { + StringBuffer result = new StringBuffer(); + String result_str; + Integer keyword_num; + char buffer[] = new char[1]; + + /* next_char holds first character of id */ + buffer[0] = (char)next_char; + result.append(buffer,0,1); + advance(); + + /* collect up characters while they fit in id */ + while(id_char(next_char)) + { + buffer[0] = (char)next_char; + result.append(buffer,0,1); + advance(); + } + + /* extract a string and try to look it up as a keyword */ + result_str = result.toString(); + keyword_num = (Integer)keywords.get(result_str); + + /* if we found something, return that keyword */ + if (keyword_num != null) + return new Symbol(keyword_num.intValue()); + + /* otherwise build and return an id Symbol with an attached string */ + return new Symbol(sym.ID, result_str); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return one Symbol. This is the main external interface to the scanner. + * It consumes sufficient characters to determine the next input Symbol + * and returns it. To help with debugging, this routine actually calls + * real_next_token() which does the work. If you need to debug the + * parser, this can be changed to call debug_next_token() which prints + * a debugging message before returning the Symbol. + */ + public static Symbol next_token() throws java.io.IOException + { + return real_next_token(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Debugging version of next_token(). This routine calls the real scanning + * routine, prints a message on System.out indicating what the Symbol is, + * then returns it. + */ + public static Symbol debug_next_token() throws java.io.IOException + { + Symbol result = real_next_token(); + System.out.println("# next_Symbol() => " + result.sym); + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The actual routine to return one Symbol. This is normally called from + * next_token(), but for debugging purposes can be called indirectly from + * debug_next_token(). + */ + protected static Symbol real_next_token() throws java.io.IOException + { + int sym_num; + + for (;;) + { + /* look for white space */ + if (next_char == ' ' || next_char == '\t' || next_char == '\n' || + next_char == '\f' || next_char == '\r') + { + /* advance past it and try the next character */ + advance(); + continue; + } + + /* look for a single character symbol */ + sym_num = find_single_char(next_char); + if (sym_num != -1) + { + /* found one -- advance past it and return a Symbol for it */ + advance(); + return new Symbol(sym_num); + } + + /* look for : or ::= */ + if (next_char == ':') + { + /* if we don't have a second ':' return COLON */ + if (next_char2 != ':') + { + advance(); + return new Symbol(sym.COLON); + } + + /* move forward and look for the '=' */ + advance(); + if (next_char2 == '=') + { + advance(); advance(); + return new Symbol(sym.COLON_COLON_EQUALS); + } + else + { + /* return just the colon (already consumed) */ + return new Symbol(sym.COLON); + } + } + + /* find a "%prec" string and return it. otherwise, a '%' was found, + which has no right being in the specification otherwise */ + if (next_char == '%') { + advance(); + if ((next_char == 'p') && (next_char2 == 'r') && (next_char3 == 'e') && + (next_char4 == 'c')) { + advance(); + advance(); + advance(); + advance(); + return new Symbol(sym.PERCENT_PREC); + } else { + emit_error("Found extraneous percent sign"); + } + } + + /* look for a comment */ + if (next_char == '/' && (next_char2 == '*' || next_char2 == '/')) + { + /* swallow then continue the scan */ + swallow_comment(); + continue; + } + + /* look for start of code string */ + if (next_char == '{' && next_char2 == ':') + return do_code_string(); + + /* look for an id or keyword */ + if (id_start_char(next_char)) return do_id(); + + /* look for EOF */ + if (next_char == EOF_CHAR) return new Symbol(sym.EOF); + + /* if we get here, we have an unrecognized character */ + emit_warn("Unrecognized character '" + + new Character((char)next_char) + "'(" + next_char + + ") -- ignored"); + + /* advance past it */ + advance(); + } + } + + /*-----------------------------------------------------------*/ +} + diff --git a/open-nars/java_cup/lr_item_core.java b/open-nars/java_cup/lr_item_core.java new file mode 100644 index 0000000000000000000000000000000000000000..c0fa656a140f9bb04a232b6132024cacc84883d0 --- /dev/null +++ b/open-nars/java_cup/lr_item_core.java @@ -0,0 +1,280 @@ + +package java_cup; + +/** The "core" of an LR item. This includes a production and the position + * of a marker (the "dot") within the production. Typically item cores + * are written using a production with an embedded "dot" to indicate their + * position. For example: <pre> + * A ::= B * C d E + * </pre> + * This represents a point in a parse where the parser is trying to match + * the given production, and has succeeded in matching everything before the + * "dot" (and hence is expecting to see the symbols after the dot next). See + * lalr_item, lalr_item_set, and lalr_start for full details on the meaning + * and use of items. + * + * @see java_cup.lalr_item + * @see java_cup.lalr_item_set + * @see java_cup.lalr_state + * @version last updated: 11/25/95 + * @author Scott Hudson +*/ + +public class lr_item_core { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param prod production this item uses. + * @param pos position of the "dot" within the item. + */ + public lr_item_core(production prod, int pos) throws internal_error + { + symbol after_dot = null; + production_part part; + + if (prod == null) + throw new internal_error( + "Attempt to create an lr_item_core with a null production"); + + _the_production = prod; + + if (pos < 0 || pos > _the_production.rhs_length()) + throw new internal_error( + "Attempt to create an lr_item_core with a bad dot position"); + + _dot_pos = pos; + + /* compute and cache hash code now */ + _core_hash_cache = 13*_the_production.hashCode() + pos; + + /* cache the symbol after the dot */ + if (_dot_pos < _the_production.rhs_length()) + { + part = _the_production.rhs(_dot_pos); + if (!part.is_action()) + _symbol_after_dot = ((symbol_part)part).the_symbol(); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor for dot at start of right hand side. + * @param prod production this item uses. + */ + public lr_item_core(production prod) throws internal_error + { + this(prod,0); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The production for the item. */ + protected production _the_production; + + /** The production for the item. */ + public production the_production() {return _the_production;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The position of the "dot" -- this indicates the part of the production + * that the marker is before, so 0 indicates a dot at the beginning of + * the RHS. + */ + protected int _dot_pos; + + /** The position of the "dot" -- this indicates the part of the production + * that the marker is before, so 0 indicates a dot at the beginning of + * the RHS. + */ + public int dot_pos() {return _dot_pos;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Cache of the hash code. */ + protected int _core_hash_cache; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Cache of symbol after the dot. */ + protected symbol _symbol_after_dot = null; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Is the dot at the end of the production? */ + public boolean dot_at_end() + { + return _dot_pos >= _the_production.rhs_length(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return the symbol after the dot. If there is no symbol after the dot + * we return null. */ + public symbol symbol_after_dot() + { + /* use the cached symbol */ + return _symbol_after_dot; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if we have a dot before a non terminal, and if so which one + * (return null or the non terminal). + */ + public non_terminal dot_before_nt() + { + symbol sym; + + /* get the symbol after the dot */ + sym = symbol_after_dot(); + + /* if it exists and is a non terminal, return it */ + if (sym != null && sym.is_non_term()) + return (non_terminal)sym; + else + return null; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a new lr_item_core that results from shifting the dot one + * position to the right. + */ + public lr_item_core shift_core() throws internal_error + { + if (dot_at_end()) + throw new internal_error( + "Attempt to shift past end of an lr_item_core"); + + return new lr_item_core(_the_production, _dot_pos+1); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison for the core only. This is separate out because we + * need separate access in a super class. + */ + public boolean core_equals(lr_item_core other) + { + return other != null && + _the_production.equals(other._the_production) && + _dot_pos == other._dot_pos; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(lr_item_core other) {return core_equals(other);} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof lr_item_core)) + return false; + else + return equals((lr_item_core)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Hash code for the core (separated so we keep non overridden version). */ + public int core_hashCode() + { + return _core_hash_cache; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Hash code for the item. */ + public int hashCode() + { + return _core_hash_cache; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return the hash code that object would have provided for us so we have + * a (nearly) unique id for debugging. + */ + protected int obj_hash() + { + return super.hashCode(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string (separated out from toString() so we can call it + * from subclass that overrides toString()). + */ + public String to_simple_string() throws internal_error + { + String result; + production_part part; + + if (_the_production.lhs() != null && + _the_production.lhs().the_symbol() != null && + _the_production.lhs().the_symbol().name() != null) + result = _the_production.lhs().the_symbol().name(); + else + result = "$$NULL$$"; + + result += " ::= "; + + for (int i = 0; i<_the_production.rhs_length(); i++) + { + /* do we need the dot before this one? */ + if (i == _dot_pos) + result += "(*) "; + + /* print the name of the part */ + if (_the_production.rhs(i) == null) + { + result += "$$NULL$$ "; + } + else + { + part = _the_production.rhs(i); + if (part == null) + result += "$$NULL$$ "; + else if (part.is_action()) + result += "{ACTION} "; + else if (((symbol_part)part).the_symbol() != null && + ((symbol_part)part).the_symbol().name() != null) + result += ((symbol_part)part).the_symbol().name() + " "; + else + result += "$$NULL$$ "; + } + } + + /* put the dot after if needed */ + if (_dot_pos == _the_production.rhs_length()) + result += "(*) "; + + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string */ + public String toString() + { + /* can't throw here since super class doesn't, so we crash instead */ + try { + return to_simple_string(); + } catch(internal_error e) { + e.crash(); + return null; + } + } + + /*-----------------------------------------------------------*/ + +} + diff --git a/open-nars/java_cup/non_terminal.java b/open-nars/java_cup/non_terminal.java new file mode 100644 index 0000000000000000000000000000000000000000..9354a7fa394923a6eb9a0a6c0bfc8f65c8511442 --- /dev/null +++ b/open-nars/java_cup/non_terminal.java @@ -0,0 +1,301 @@ +package java_cup; + +import java.util.Hashtable; +import java.util.Enumeration; + +/** This class represents a non-terminal symbol in the grammar. Each + * non terminal has a textual name, an index, and a string which indicates + * the type of object it will be implemented with at runtime (i.e. the class + * of object that will be pushed on the parse stack to represent it). + * + * @version last updated: 11/25/95 + * @author Scott Hudson + */ + +public class non_terminal extends symbol { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param nm the name of the non terminal. + * @param tp the type string for the non terminal. + */ + public non_terminal(String nm, String tp) + { + /* super class does most of the work */ + super(nm, tp); + + /* add to set of all non terminals and check for duplicates */ + Object conflict = _all.put(nm,this); + if (conflict != null) + // can't throw an exception here because these are used in static + // initializers, so we crash instead + // was: + // throw new internal_error("Duplicate non-terminal ("+nm+") created"); + (new internal_error("Duplicate non-terminal ("+nm+") created")).crash(); + + /* assign a unique index */ + _index = next_index++; + + /* add to by_index set */ + _all_by_index.put(new Integer(_index), this); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with default type. + * @param nm the name of the non terminal. + */ + public non_terminal(String nm) + { + this(nm, null); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + /** Table of all non-terminals -- elements are stored using name strings + * as the key + */ + protected static Hashtable _all = new Hashtable(); + + /** Access to all non-terminals. */ + public static Enumeration all() {return _all.elements();} + + /** lookup a non terminal by name string */ + public static non_terminal find(String with_name) + { + if (with_name == null) + return null; + else + return (non_terminal)_all.get(with_name); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Table of all non terminals indexed by their index number. */ + protected static Hashtable _all_by_index = new Hashtable(); + + /** Lookup a non terminal by index. */ + public static non_terminal find(int indx) + { + Integer the_indx = new Integer(indx); + + return (non_terminal)_all_by_index.get(the_indx); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Total number of non-terminals. */ + public static int number() {return _all.size();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Static counter to assign unique indexes. */ + protected static int next_index = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Static counter for creating unique non-terminal names */ + static protected int next_nt = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** special non-terminal for start symbol */ + public static final non_terminal START_nt = new non_terminal("$START"); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** flag non-terminals created to embed action productions */ + public boolean is_embedded_action = false; /* added 24-Mar-1998, CSA */ + + /*-----------------------------------------------------------*/ + /*--- Static Methods ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Method for creating a new uniquely named hidden non-terminal using + * the given string as a base for the name (or "NT$" if null is passed). + * @param prefix base name to construct unique name from. + */ + static non_terminal create_new(String prefix) throws internal_error + { + if (prefix == null) prefix = "NT$"; + return new non_terminal(prefix + next_nt++); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** static routine for creating a new uniquely named hidden non-terminal */ + static non_terminal create_new() throws internal_error + { + return create_new(null); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Compute nullability of all non-terminals. */ + public static void compute_nullability() throws internal_error + { + boolean change = true; + non_terminal nt; + Enumeration e; + production prod; + + /* repeat this process until there is no change */ + while (change) + { + /* look for a new change */ + change = false; + + /* consider each non-terminal */ + for (e=all(); e.hasMoreElements(); ) + { + nt = (non_terminal)e.nextElement(); + + /* only look at things that aren't already marked nullable */ + if (!nt.nullable()) + { + if (nt.looks_nullable()) + { + nt._nullable = true; + change = true; + } + } + } + } + + /* do one last pass over the productions to finalize all of them */ + for (e=production.all(); e.hasMoreElements(); ) + { + prod = (production)e.nextElement(); + prod.set_nullable(prod.check_nullable()); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Compute first sets for all non-terminals. This assumes nullability has + * already computed. + */ + public static void compute_first_sets() throws internal_error + { + boolean change = true; + Enumeration n; + Enumeration p; + non_terminal nt; + production prod; + terminal_set prod_first; + + /* repeat this process until we have no change */ + while (change) + { + /* look for a new change */ + change = false; + + /* consider each non-terminal */ + for (n = all(); n.hasMoreElements(); ) + { + nt = (non_terminal)n.nextElement(); + + /* consider every production of that non terminal */ + for (p = nt.productions(); p.hasMoreElements(); ) + { + prod = (production)p.nextElement(); + + /* get the updated first of that production */ + prod_first = prod.check_first_set(); + + /* if this going to add anything, add it */ + if (!prod_first.is_subset_of(nt._first_set)) + { + change = true; + nt._first_set.add(prod_first); + } + } + } + } + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** Table of all productions with this non terminal on the LHS. */ + protected Hashtable _productions = new Hashtable(11); + + /** Access to productions with this non terminal on the LHS. */ + public Enumeration productions() {return _productions.elements();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Total number of productions with this non terminal on the LHS. */ + public int num_productions() {return _productions.size();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add a production to our set of productions. */ + public void add_production(production prod) throws internal_error + { + /* catch improper productions */ + if (prod == null || prod.lhs() == null || prod.lhs().the_symbol() != this) + throw new internal_error( + "Attempt to add invalid production to non terminal production table"); + + /* add it to the table, keyed with itself */ + _productions.put(prod,prod); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Nullability of this non terminal. */ + protected boolean _nullable; + + /** Nullability of this non terminal. */ + public boolean nullable() {return _nullable;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** First set for this non-terminal. */ + protected terminal_set _first_set = new terminal_set(); + + /** First set for this non-terminal. */ + public terminal_set first_set() {return _first_set;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Indicate that this symbol is a non-terminal. */ + public boolean is_non_term() + { + return true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Test to see if this non terminal currently looks nullable. */ + protected boolean looks_nullable() throws internal_error + { + /* look and see if any of the productions now look nullable */ + for (Enumeration e = productions(); e.hasMoreElements(); ) + /* if the production can go to empty, we are nullable */ + if (((production)e.nextElement()).check_nullable()) + return true; + + /* none of the productions can go to empty, so we are not nullable */ + return false; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** convert to string */ + public String toString() + { + return super.toString() + "[" + index() + "]" + (nullable() ? "*" : ""); + } + + /*-----------------------------------------------------------*/ +} diff --git a/open-nars/java_cup/nonassoc_action.java b/open-nars/java_cup/nonassoc_action.java new file mode 100644 index 0000000000000000000000000000000000000000..38823244f72341b74e3ce44c4956afdadeeab5d2 --- /dev/null +++ b/open-nars/java_cup/nonassoc_action.java @@ -0,0 +1,71 @@ + +package java_cup; + +/** This class represents a shift/reduce nonassociative error within the + * parse table. If action_table element is assign to type + * nonassoc_action, it cannot be changed, and signifies that there + * is a conflict between shifting and reducing a production and a + * terminal that shouldn't be next to each other. + * + * @version last updated: 7/2/96 + * @author Frank Flannery + */ +public class nonassoc_action extends parse_action { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. + */ + public nonassoc_action() throws internal_error + { + /* don't need to set anything, since it signifies error */ + } + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Quick access to type of action. */ + public int kind() {return NONASSOC;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality test. */ + public boolean equals(parse_action other) + { + return other != null && other.kind() == NONASSOC; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality test. */ + public boolean equals(Object other) + { + if (other instanceof parse_action) + return equals((parse_action)other); + else + return false; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Compute a hash code. */ + public int hashCode() + { + /* all objects of this class hash together */ + return 0xCafe321; + } + + + + /** Convert to string. */ + public String toString() + { + return "NONASSOC"; + } + + /*-----------------------------------------------------------*/ + +} diff --git a/open-nars/java_cup/parse_action.java b/open-nars/java_cup/parse_action.java new file mode 100644 index 0000000000000000000000000000000000000000..9228663507ae4eaf47d71e0b892cfae741e060c6 --- /dev/null +++ b/open-nars/java_cup/parse_action.java @@ -0,0 +1,92 @@ + +package java_cup; + +/** This class serves as the base class for entries in a parse action table. + * Full entries will either be SHIFT(state_num), REDUCE(production), NONASSOC, + * or ERROR. Objects of this base class will default to ERROR, while + * the other three types will be represented by subclasses. + * + * @see java_cup.reduce_action + * @see java_cup.shift_action + * @version last updated: 7/2/96 + * @author Frank Flannery + */ + +public class parse_action { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. */ + public parse_action() + { + /* nothing to do in the base class */ + } + + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + /** Constant for action type -- error action. */ + public static final int ERROR = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constant for action type -- shift action. */ + public static final int SHIFT = 1; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constants for action type -- reduce action. */ + public static final int REDUCE = 2; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constants for action type -- reduce action. */ + public static final int NONASSOC = 3; + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Quick access to the type -- base class defaults to error. */ + public int kind() {return ERROR;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality test. */ + public boolean equals(parse_action other) + { + /* we match all error actions */ + return other != null && other.kind() == ERROR; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality test. */ + public boolean equals(Object other) + { + if (other instanceof parse_action) + return equals((parse_action)other); + else + return false; + } + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Compute a hash code. */ + public int hashCode() + { + /* all objects of this class hash together */ + return 0xCafe123; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to string. */ + public String toString() {return "ERROR";} + + /*-----------------------------------------------------------*/ +} + diff --git a/open-nars/java_cup/parse_action_row.java b/open-nars/java_cup/parse_action_row.java new file mode 100644 index 0000000000000000000000000000000000000000..817b8c52130efbc4e20f6d8f5fe8f7d3dffb399a --- /dev/null +++ b/open-nars/java_cup/parse_action_row.java @@ -0,0 +1,106 @@ + +package java_cup; + +/** This class represents one row (corresponding to one machine state) of the + * parse action table. + */ +public class parse_action_row { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. Note: this should not be used until the number of + * terminals in the grammar has been established. + */ + public parse_action_row() + { + /* make sure the size is set */ + if (_size <= 0 ) _size = terminal.number(); + + /* allocate the array */ + under_term = new parse_action[size()]; + + /* set each element to an error action */ + for (int i=0; i<_size; i++) + under_term[i] = new parse_action(); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + /** Number of columns (terminals) in every row. */ + protected static int _size = 0; + + /** Number of columns (terminals) in every row. */ + public static int size() {return _size;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Table of reduction counts (reused by compute_default()). */ + protected static int reduction_count[] = null; + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** Actual action entries for the row. */ + public parse_action under_term[]; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Default (reduce) action for this row. -1 will represent default + * of error. + */ + public int default_reduce; + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Compute the default (reduce) action for this row and store it in + * default_reduce. In the case of non-zero default we will have the + * effect of replacing all errors by that reduction. This may cause + * us to do erroneous reduces, but will never cause us to shift past + * the point of the error and never cause an incorrect parse. -1 will + * be used to encode the fact that no reduction can be used as a + * default (in which case error will be used). + */ + public void compute_default() + { + int i, prod, max_prod, max_red; + + /* if we haven't allocated the count table, do so now */ + if (reduction_count == null) + reduction_count = new int[production.number()]; + + /* clear the reduction count table and maximums */ + for (i = 0; i < production.number(); i++) + reduction_count[i] = 0; + max_prod = -1; + max_red = 0; + + /* walk down the row and look at the reduces */ + for (i = 0; i < size(); i++) + if (under_term[i].kind() == parse_action.REDUCE) + { + /* count the reduce in the proper production slot and keep the + max up to date */ + prod = ((reduce_action)under_term[i]).reduce_with().index(); + reduction_count[prod]++; + if (reduction_count[prod] > max_red) + { + max_red = reduction_count[prod]; + max_prod = prod; + } + } + + /* record the max as the default (or -1 for not found) */ + default_reduce = max_prod; + } + + /*-----------------------------------------------------------*/ + +} + diff --git a/open-nars/java_cup/parse_action_table.java b/open-nars/java_cup/parse_action_table.java new file mode 100644 index 0000000000000000000000000000000000000000..1e0edb2c86c0d0f1d198fa381db6b0499771f6c8 --- /dev/null +++ b/open-nars/java_cup/parse_action_table.java @@ -0,0 +1,143 @@ + +package java_cup; + +import java.util.Enumeration; + +/** This class represents the complete "action" table of the parser. + * It has one row for each state in the parse machine, and a column for + * each terminal symbol. Each entry in the table represents a shift, + * reduce, or an error. + * + * @see java_cup.parse_action + * @see java_cup.parse_action_row + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class parse_action_table { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. All terminals, non-terminals, and productions must + * already have been entered, and the viable prefix recognizer should + * have been constructed before this is called. + */ + public parse_action_table() + { + /* determine how many states we are working with */ + _num_states = lalr_state.number(); + + /* allocate the array and fill it in with empty rows */ + under_state = new parse_action_row[_num_states]; + for (int i=0; i<_num_states; i++) + under_state[i] = new parse_action_row(); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** How many rows/states are in the machine/table. */ + protected int _num_states; + + /** How many rows/states are in the machine/table. */ + public int num_states() {return _num_states;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Actual array of rows, one per state. */ + public parse_action_row[] under_state; + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Check the table to ensure that all productions have been reduced. + * Issue a warning message (to System.err) for each production that + * is never reduced. + */ + public void check_reductions() + throws internal_error + { + parse_action act; + production prod; + + /* tabulate reductions -- look at every table entry */ + for (int row = 0; row < num_states(); row++) + { + for (int col = 0; col < under_state[row].size(); col++) + { + /* look at the action entry to see if its a reduce */ + act = under_state[row].under_term[col]; + if (act != null && act.kind() == parse_action.REDUCE) + { + /* tell production that we used it */ + ((reduce_action)act).reduce_with().note_reduction_use(); + } + } + } + + /* now go across every production and make sure we hit it */ + for (Enumeration p = production.all(); p.hasMoreElements(); ) + { + prod = (production)p.nextElement(); + + /* if we didn't hit it give a warning */ + if (prod.num_reductions() == 0) + { + /* count it * + emit.not_reduced++; + + /* give a warning if they haven't been turned off */ + if (!emit.nowarn) + { + System.err.println("*** Production \"" + + prod.to_simple_string() + "\" never reduced"); + lexer.warning_count++; + } + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .* + + /** Convert to a string. */ + public String toString() + { + String result; + int cnt; + + result = "-------- ACTION_TABLE --------\n"; + for (int row = 0; row < num_states(); row++) + { + result += "From state #" + row + "\n"; + cnt = 0; + for (int col = 0; col < under_state[row].size(); col++) + { + /* if the action is not an error print it */ + if (under_state[row].under_term[col].kind() != parse_action.ERROR) + { + result += " [term " + col + ":" + under_state[row].under_term[col] + "]"; + + /* end the line after the 2nd one */ + cnt++; + if (cnt == 2) + { + result += "\n"; + cnt = 0; + } + } + } + /* finish the line if we haven't just done that */ + if (cnt != 0) result += "\n"; + } + result += "------------------------------"; + + return result; + } + + /*-----------------------------------------------------------*/ + +} + diff --git a/open-nars/java_cup/parse_reduce_row.java b/open-nars/java_cup/parse_reduce_row.java new file mode 100644 index 0000000000000000000000000000000000000000..57d978ec34379fa68d5aa15291bdbebbe9cca5c1 --- /dev/null +++ b/open-nars/java_cup/parse_reduce_row.java @@ -0,0 +1,41 @@ + +package java_cup; + +/** This class represents one row (corresponding to one machine state) of the + * reduce-goto parse table. + */ +public class parse_reduce_row { + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. Note: this should not be used until the number + * of terminals in the grammar has been established. + */ + public parse_reduce_row() + { + /* make sure the size is set */ + if (_size <= 0 ) _size = non_terminal.number(); + + /* allocate the array */ + under_non_term = new lalr_state[size()]; + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + /** Number of columns (non terminals) in every row. */ + protected static int _size = 0; + + /** Number of columns (non terminals) in every row. */ + public static int size() {return _size;} + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** Actual entries for the row. */ + public lalr_state under_non_term[]; +} + diff --git a/open-nars/java_cup/parse_reduce_table.java b/open-nars/java_cup/parse_reduce_table.java new file mode 100644 index 0000000000000000000000000000000000000000..9ac1b11cda9f5c6cc3aa78a84f9e34653415ddf0 --- /dev/null +++ b/open-nars/java_cup/parse_reduce_table.java @@ -0,0 +1,99 @@ + +package java_cup; + +import java.util.Enumeration; + +/** This class represents the complete "reduce-goto" table of the parser. + * It has one row for each state in the parse machines, and a column for + * each terminal symbol. Each entry contains a state number to shift to + * as the last step of a reduce. + * + * @see java_cup.parse_reduce_row + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class parse_reduce_table { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. Note: all terminals, non-terminals, and productions + * must already have been entered, and the viable prefix recognizer should + * have been constructed before this is called. + */ + public parse_reduce_table() + { + /* determine how many states we are working with */ + _num_states = lalr_state.number(); + + /* allocate the array and fill it in with empty rows */ + under_state = new parse_reduce_row[_num_states]; + for (int i=0; i<_num_states; i++) + under_state[i] = new parse_reduce_row(); + } + + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** How many rows/states in the machine/table. */ + protected int _num_states; + + /** How many rows/states in the machine/table. */ + public int num_states() {return _num_states;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Actual array of rows, one per state */ + public parse_reduce_row[] under_state; + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Convert to a string. */ + public String toString() + { + String result; + lalr_state goto_st; + int cnt; + + result = "-------- REDUCE_TABLE --------\n"; + for (int row = 0; row < num_states(); row++) + { + result += "From state #" + row + "\n"; + cnt = 0; + for (int col = 0; col < under_state[row].size(); col++) + { + /* pull out the table entry */ + goto_st = under_state[row].under_non_term[col]; + + /* if it has action in it, print it */ + if (goto_st != null) + { + result += " [non term " + col + "->"; + result += "state " + goto_st.index() + "]"; + + /* end the line after the 3rd one */ + cnt++; + if (cnt == 3) + { + result += "\n"; + cnt = 0; + } + } + } + /* finish the line if we haven't just done that */ + if (cnt != 0) result += "\n"; + } + result += "-----------------------------"; + + return result; + } + + /*-----------------------------------------------------------*/ + +} + diff --git a/open-nars/java_cup/parser.cup b/open-nars/java_cup/parser.cup new file mode 100644 index 0000000000000000000000000000000000000000..8af0d056728aeb24f167a6784749cb7c19e1a86c --- /dev/null +++ b/open-nars/java_cup/parser.cup @@ -0,0 +1,863 @@ + +/*================================================================*/ +/* + JavaCup Specification for the JavaCup Specification Language + by Scott Hudson, GVU Center, Georgia Tech, August 1995 + and Frank Flannery, Department of Computer Science, Princeton Univ, + July 1996 + Bug Fixes: C. Scott Ananian, Dept of Electrical Engineering, Princeton + University, October 1996. [later Massachusetts Institute of Technology] + + + This JavaCup specification is used to implement JavaCup itself. + It specifies the parser for the JavaCup specification language. + (It also serves as a reasonable example of what a typical JavaCup + spec looks like). + + The specification has the following parts: + Package and import declarations + These serve the same purpose as in a normal Java source file + (and will appear in the generated code for the parser). In this + case we are part of the java_cup package and we import both the + java_cup runtime system and Hashtable from the standard Java + utilities package. + + Action code + This section provides code that is included with the class encapsulating + the various pieces of user code embedded in the grammar (i.e., the + semantic actions). This provides a series of helper routines and + data structures that the semantic actions use. + + Parser code + This section provides code included in the parser class itself. In + this case we override the default error reporting routines. + + Init with and scan with + These sections provide small bits of code that initialize, then + indicate how to invoke the scanner. + + Symbols and grammar + These sections declare all the terminal and non terminal symbols + and the types of objects that they will be represented by at runtime, + then indicate the start symbol of the grammar (), and finally provide + the grammar itself (with embedded actions). + + Operation of the parser + The parser acts primarily by accumulating data structures representing + various parts of the specification. Various small parts (e.g., single + code strings) are stored as static variables of the emit class and + in a few cases as variables declared in the action code section. + Terminals, non terminals, and productions, are maintained as collection + accessible via static methods of those classes. In addition, two + symbol tables are kept: + symbols maintains the name to object mapping for all symbols + non_terms maintains a separate mapping containing only the non terms + + Several intermediate working structures are also declared in the action + code section. These include: rhs_parts, rhs_pos, and lhs_nt which + build up parts of the current production while it is being parsed. + + Author(s) + Scott Hudson, GVU Center, Georgia Tech. + Frank Flannery, Department of Computer Science, Princeton Univ. + C. Scott Ananian, Department of Electrical Engineering, Princeton Univ. + + Revisions + v0.9a First released version [SEH] 8/29/95 + v0.9b Updated for beta language (throws clauses) [SEH] 11/25/95 + v0.10a Made many improvements/changes. now offers: + return value + left/right positions and propagations + cleaner label references + precedence and associativity for terminals + contextual precedence for productions + [FF] 7/3/96 + v0.10b Fixed %prec directive so it works like it's supposed to. + [CSA] 10/10/96 + v0.10g Added support for array types on symbols. + [CSA] 03/23/98 + v0.10i Broaden set of IDs allowed in multipart_id and label_id so + that only java reserved words (and not CUP reserved words like + 'parser' and 'start') are prohibited. Allow reordering of + action code, parser code, init code, and scan with sections, + and made closing semicolon optional for these sections. + Added 'nonterminal' as a terminal symbol, finally fixing a + spelling mistake that's been around since the beginning. + For backwards compatibility, you can still misspell the + word if you like. +*/ +/*================================================================*/ + +package java_cup; +import java_cup.runtime.*; +import java.util.Hashtable; + +/*----------------------------------------------------------------*/ + +action code {: + /** helper routine to clone a new production part adding a given label */ + protected production_part add_lab(production_part part, String lab) + throws internal_error + { + /* if there is no label, or this is an action, just return the original */ + if (lab == null || part.is_action()) return part; + + /* otherwise build a new one with the given label attached */ + return new symbol_part(((symbol_part)part).the_symbol(),lab); + } + + /** max size of right hand side we will support */ + protected final int MAX_RHS = 200; + + /** array for accumulating right hand side parts */ + protected production_part[] rhs_parts = new production_part[MAX_RHS]; + + /** where we are currently in building a right hand side */ + protected int rhs_pos = 0; + + /** start a new right hand side */ + protected void new_rhs() {rhs_pos = 0; } + + /** add a new right hand side part */ + protected void add_rhs_part(production_part part) throws java.lang.Exception + { + if (rhs_pos >= MAX_RHS) + throw new Exception("Internal Error: Productions limited to " + + MAX_RHS + " symbols and actions"); + + rhs_parts[rhs_pos] = part; + rhs_pos++; + } + + /** string to build up multiple part names */ + protected String multipart_name = new String(); + + /** append a new name segment to the accumulated multipart name */ + protected void append_multipart(String name) + { + String dot = ""; + + /* if we aren't just starting out, put on a dot */ + if (multipart_name.length() != 0) dot = "."; + + multipart_name = multipart_name.concat(dot + name); + } + + /** table of declared symbols -- contains production parts indexed by name */ + protected Hashtable symbols = new Hashtable(); + + /** table of just non terminals -- contains non_terminals indexed by name */ + protected Hashtable non_terms = new Hashtable(); + + /** declared start non_terminal */ + protected non_terminal start_nt = null; + + /** left hand side non terminal of the current production */ + protected non_terminal lhs_nt; + + /** Current precedence number */ + int _cur_prec = 0; + + /** Current precedence side */ + int _cur_side = assoc.no_prec; + + /** update the precedences we are declaring */ + protected void update_precedence(int p) { + _cur_side = p; + _cur_prec++; + } + /** add relevant data to terminals */ + protected void add_precedence(String term) { + if (term == null) { + System.err.println("Unable to add precedence to nonexistent terminal"); + } else { + symbol_part sp = (symbol_part)symbols.get(term); + if (sp == null) { + System.err.println("Could find terminal " + term + " while declaring precedence"); + } else { + java_cup.symbol sym = sp.the_symbol(); + if (sym instanceof terminal) + ((terminal)sym).set_precedence(_cur_side, _cur_prec); + else System.err.println("Precedence declaration: Can't find terminal " + term); + } + } + } +:}; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +parser code {: + + /* override error routines */ + + public void report_fatal_error( + String message, + Object info) + { + done_parsing(); + lexer.emit_error(message); + System.err.println("Can't recover from previous error(s), giving up."); + System.exit(1); + } + + public void report_error(String message, Object info) + { + lexer.emit_error(message); + } +:}; + +/*----------------------------------------------------------------*/ + +init with {: lexer.init(); :}; +scan with {: return lexer.next_token(); :}; + +/*----------------------------------------------------------------*/ + +terminal + PACKAGE, IMPORT, CODE, ACTION, PARSER, TERMINAL, NON, INIT, SCAN, WITH, + START, SEMI, COMMA, STAR, DOT, COLON, COLON_COLON_EQUALS, BAR, PRECEDENCE, + LEFT, RIGHT, NONASSOC, PERCENT_PREC, LBRACK, RBRACK, NONTERMINAL; + +terminal String ID, CODE_STRING; + +non terminal + spec, package_spec, import_list, action_code_part, + code_parts, code_part, opt_semi, non_terminal, + parser_code_part, symbol_list, start_spec, production_list, + multipart_id, import_spec, import_id, init_code, scan_code, symbol, + type_id, term_name_list, non_term_name_list, production, prod_part_list, + prod_part, new_term_id, new_non_term_id, rhs_list, rhs, empty, + precedence_list, preced, terminal_list, precedence_l, declares_term, + declares_non_term; + +non terminal String nt_id, symbol_id, label_id, opt_label, terminal_id, + term_id, robust_id; + +/*----------------------------------------------------------------*/ + +start with spec; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +spec ::= + {: + /* declare "error" as a terminal */ + symbols.put("error", new symbol_part(terminal.error)); + + /* declare start non terminal */ + non_terms.put("$START", non_terminal.START_nt); + :} + package_spec + import_list + code_parts + symbol_list + precedence_list + start_spec + production_list + | + /* error recovery assuming something went wrong before symbols + and we have TERMINAL or NON TERMINAL to sync on. if we get + an error after that, we recover inside symbol_list or + production_list + */ + error + symbol_list + precedence_list + start_spec + production_list + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +package_spec ::= + PACKAGE + multipart_id + {: + /* save the package name */ + emit.package_name = multipart_name; + + /* reset the accumulated multipart name */ + multipart_name = new String(); + :} + SEMI + | + empty + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +import_list ::= + import_list + import_spec + | + empty + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +import_spec ::= + IMPORT + import_id + {: + /* save this import on the imports list */ + emit.import_list.push(multipart_name); + + /* reset the accumulated multipart name */ + multipart_name = new String(); + :} + SEMI + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +// allow any order; all parts are optional. [CSA, 23-Jul-1999] +// (we check in the part action to make sure we don't have 2 of any part) +code_part ::= + action_code_part | parser_code_part | init_code | scan_code ; +code_parts ::= + | code_parts code_part; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +action_code_part ::= + ACTION CODE CODE_STRING:user_code opt_semi + {: + if (emit.action_code!=null) + lexer.emit_error("Redundant action code (skipping)"); + else /* save the user included code string */ + emit.action_code = user_code; + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +parser_code_part ::= + PARSER CODE CODE_STRING:user_code opt_semi + {: + if (emit.parser_code!=null) + lexer.emit_error("Redundant parser code (skipping)"); + else /* save the user included code string */ + emit.parser_code = user_code; + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +init_code ::= + INIT WITH CODE_STRING:user_code opt_semi + {: + if (emit.init_code!=null) + lexer.emit_error("Redundant init code (skipping)"); + else /* save the user code */ + emit.init_code = user_code; + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +scan_code ::= + SCAN WITH CODE_STRING:user_code opt_semi + {: + if (emit.scan_code!=null) + lexer.emit_error("Redundant scan code (skipping)"); + else /* save the user code */ + emit.scan_code = user_code; + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +symbol_list ::= symbol_list symbol | symbol; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +symbol ::= + TERMINAL + type_id + declares_term + | + TERMINAL + declares_term + | + non_terminal + type_id + declares_non_term + | + non_terminal + declares_non_term + | + /* error recovery productions -- sync on semicolon */ + + TERMINAL + error + {: + /* reset the accumulated multipart name */ + multipart_name = new String(); + :} + SEMI + | + non_terminal + error + {: + /* reset the accumulated multipart name */ + multipart_name = new String(); + :} + SEMI + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +declares_term ::= + term_name_list + {: + /* reset the accumulated multipart name */ + multipart_name = new String(); + :} + SEMI + ; +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +declares_non_term ::= + non_term_name_list + {: + /* reset the accumulated multipart name */ + multipart_name = new String(); + :} + SEMI + ; +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +term_name_list ::= term_name_list COMMA new_term_id | new_term_id; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +non_term_name_list ::= + non_term_name_list + COMMA + new_non_term_id + | + new_non_term_id + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + + +precedence_list ::= precedence_l | empty; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +precedence_l ::= precedence_l preced | preced; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +preced ::= + PRECEDENCE LEFT + {: + update_precedence(assoc.left); + :} + terminal_list SEMI + | + PRECEDENCE RIGHT + {: + update_precedence(assoc.right); + :} + terminal_list SEMI + | + PRECEDENCE NONASSOC + {: + update_precedence(assoc.nonassoc); + :} + terminal_list SEMI + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +terminal_list ::= terminal_list COMMA terminal_id + | + terminal_id + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +terminal_id ::= term_id:sym + {: + add_precedence(sym); + RESULT = sym; + :}; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +term_id ::= symbol_id:sym + {: + /* check that the symbol_id is a terminal */ + if (symbols.get(sym) == null) + { + /* issue a message */ + lexer.emit_error("Terminal \"" + sym + + "\" has not been declared"); + } + RESULT = sym; + :}; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +start_spec ::= + START WITH nt_id:start_name + {: + /* verify that the name has been declared as a non terminal */ + non_terminal nt = (non_terminal)non_terms.get(start_name); + if (nt == null) + { + lexer.emit_error( "Start non terminal \"" + start_name + + "\" has not been declared"); + } + else + { + /* remember the non-terminal for later */ + start_nt = nt; + + /* build a special start production */ + new_rhs(); + add_rhs_part(add_lab(new symbol_part(start_nt), "start_val")); + add_rhs_part(new symbol_part(terminal.EOF)); + add_rhs_part(new action_part("RESULT = start_val;")); + emit.start_production = + new production(non_terminal.START_nt, rhs_parts, rhs_pos); + new_rhs(); + } + :} + SEMI + | + empty + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +production_list ::= production_list production | production; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +production ::= + nt_id:lhs_id + {: + /* lookup the lhs nt */ + lhs_nt = (non_terminal)non_terms.get(lhs_id); + + /* if it wasn't declared, emit a message */ + if (lhs_nt == null) + { + if (lexer.error_count == 0) + lexer.emit_error("LHS non terminal \"" + lhs_id + + "\" has not been declared"); + } + + /* reset the rhs accumulation */ + new_rhs(); + :} + COLON_COLON_EQUALS + {: :} + rhs_list + SEMI + | + error + {: lexer.emit_error("Syntax Error"); :} + SEMI + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +rhs_list ::= rhs_list BAR rhs | rhs; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +rhs ::= + prod_part_list PERCENT_PREC term_id:term_name + {: + java_cup.symbol sym = null; + if (lhs_nt != null) + { + /* Find the precedence symbol */ + if (term_name == null) { + System.err.println("No terminal for contextual precedence"); + sym = null; + } else { + sym = ((symbol_part)symbols.get(term_name)).the_symbol(); + } + /* build the production */ + production p; + if ((sym!=null) && (sym instanceof terminal)) { + p = new production(lhs_nt, rhs_parts, rhs_pos, + ((terminal)sym).precedence_num(), + ((terminal)sym).precedence_side()); + ((symbol_part)symbols.get(term_name)).the_symbol().note_use(); + } else { + System.err.println("Invalid terminal " + term_name + + " for contextual precedence assignment"); + p = new production(lhs_nt, rhs_parts, rhs_pos); + } + + /* if we have no start non-terminal declared and this is + the first production, make its lhs nt the start_nt + and build a special start production for it. */ + if (start_nt == null) + { + start_nt = lhs_nt; + + /* build a special start production */ + new_rhs(); + add_rhs_part(add_lab(new symbol_part(start_nt),"start_val")); + add_rhs_part(new symbol_part(terminal.EOF)); + add_rhs_part(new action_part("RESULT = start_val;")); + if ((sym!=null) && (sym instanceof terminal)) { + emit.start_production = + new production(non_terminal.START_nt, rhs_parts, + rhs_pos, ((terminal)sym).precedence_num(), + ((terminal)sym).precedence_side()); + } else { + emit.start_production = + new production(non_terminal.START_nt, rhs_parts, rhs_pos); + } + new_rhs(); + } + } + + /* reset the rhs accumulation in any case */ + new_rhs(); + :} + | + prod_part_list + {: + if (lhs_nt != null) + { + /* build the production */ + production p = new production(lhs_nt, rhs_parts, rhs_pos); + + /* if we have no start non-terminal declared and this is + the first production, make its lhs nt the start_nt + and build a special start production for it. */ + if (start_nt == null) + { + start_nt = lhs_nt; + + /* build a special start production */ + new_rhs(); + add_rhs_part(add_lab(new symbol_part(start_nt),"start_val")); + add_rhs_part(new symbol_part(terminal.EOF)); + add_rhs_part(new action_part("RESULT = start_val;")); + emit.start_production = + new production(non_terminal.START_nt, rhs_parts, rhs_pos); + + new_rhs(); + } + } + + /* reset the rhs accumulation in any case */ + new_rhs(); + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +prod_part_list ::= prod_part_list prod_part | empty; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +prod_part ::= + symbol_id:symid opt_label:labid + {: + /* try to look up the id */ + production_part symb = (production_part)symbols.get(symid); + + /* if that fails, symbol is undeclared */ + if (symb == null) + { + if (lexer.error_count == 0) + lexer.emit_error("java_cup.runtime.Symbol \"" + symid + + "\" has not been declared"); + } + else + { + /* add a labeled production part */ + add_rhs_part(add_lab(symb, labid)); + } + :} + | + CODE_STRING:code_str + {: + /* add a new production part */ + add_rhs_part(new action_part(code_str)); + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +opt_label ::= + COLON label_id:labid + {: RESULT = labid; :} + | + empty + {: RESULT = null; :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +multipart_id ::= + multipart_id DOT robust_id:another_id + {: append_multipart(another_id); :} + | + robust_id:an_id + {: append_multipart(an_id); :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +import_id ::= + multipart_id DOT STAR + {: append_multipart("*"); :} + | + multipart_id + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +type_id ::= multipart_id + | type_id LBRACK RBRACK + {: multipart_name = multipart_name.concat("[]"); :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +new_term_id ::= + ID:term_id + {: + /* see if this terminal has been declared before */ + if (symbols.get(term_id) != null) + { + /* issue a message */ + lexer.emit_error("java_cup.runtime.Symbol \"" + term_id + + "\" has already been declared"); + } + else + { + /* if no type declared, declare one */ + if (multipart_name.equals("")) { + append_multipart("Object"); + } + /* build a production_part and put it in the table */ + symbols.put(term_id, + new symbol_part(new terminal(term_id, multipart_name))); + } + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +new_non_term_id ::= + ID:non_term_id + {: + /* see if this non terminal has been declared before */ + if (symbols.get(non_term_id) != null) + { + /* issue a message */ + lexer.emit_error( "java_cup.runtime.Symbol \"" + non_term_id + + "\" has already been declared"); + } + else + { + if (multipart_name.equals("")) { + append_multipart("Object"); + } + /* build the non terminal object */ + non_terminal this_nt = + new non_terminal(non_term_id, multipart_name); + + /* put it in the non_terms table */ + non_terms.put(non_term_id, this_nt); + + /* build a production_part and put it in the symbols table */ + symbols.put(non_term_id, new symbol_part(this_nt)); + } + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +nt_id ::= + ID:the_id + {: RESULT = the_id; :} + | error + {: + lexer.emit_error("Illegal use of reserved word"); + RESULT="ILLEGAL"; + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +symbol_id ::= + ID:the_id + {: RESULT = the_id; :} + | error + {: + lexer.emit_error("Illegal use of reserved word"); + RESULT="ILLEGAL"; + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +label_id ::= + robust_id:the_id + {: RESULT = the_id; :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +robust_id ::= /* all ids that aren't reserved words in Java */ + ID:the_id {: RESULT = the_id; :} + /* package is reserved. */ + /* import is reserved. */ + | CODE {: RESULT = "code"; :} + | ACTION {: RESULT = "action"; :} + | PARSER {: RESULT = "parser"; :} + | TERMINAL {: RESULT = "terminal"; :} + | NON {: RESULT = "non"; :} + | NONTERMINAL {: RESULT = "nonterminal"; :} + | INIT {: RESULT = "init"; :} + | SCAN {: RESULT = "scan"; :} + | WITH {: RESULT = "with"; :} + | START {: RESULT = "start"; :} + | PRECEDENCE {: RESULT = "precedence"; :} + | LEFT {: RESULT = "left"; :} + | RIGHT {: RESULT = "right"; :} + | NONASSOC {: RESULT = "nonassoc"; :} + | error + {: + lexer.emit_error("Illegal use of reserved word"); + RESULT="ILLEGAL"; + :} + ; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +non_terminal ::= NON TERMINAL | NONTERMINAL; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +opt_semi ::= /* nothing */ + | SEMI; + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ + +empty ::= /* nothing */; + +/*----------------------------------------------------------------*/ + + + + + + + + + diff --git a/open-nars/java_cup/parser.java b/open-nars/java_cup/parser.java new file mode 100644 index 0000000000000000000000000000000000000000..163968e248137c7dcb343c995cfaf638a103f69d --- /dev/null +++ b/open-nars/java_cup/parser.java @@ -0,0 +1,1849 @@ + +//---------------------------------------------------- +// The following code was generated by CUP v0.10k +// Sun Jul 25 13:35:26 EDT 1999 +//---------------------------------------------------- + +package java_cup; + +import java_cup.runtime.*; +import java.util.Hashtable; + +/** CUP v0.10k generated parser. + * @version Sun Jul 25 13:35:26 EDT 1999 + */ +public class parser extends java_cup.runtime.lr_parser { + + /** Default constructor. */ + public parser() {super();} + + /** Constructor which sets the default scanner. */ + public parser(java_cup.runtime.Scanner s) {super(s);} + + /** Production table. */ + protected static final short _production_table[][] = + unpackFromStrings(new String[] { + "\000\153\000\002\002\004\000\002\055\002\000\002\003" + + "\012\000\002\003\007\000\002\056\002\000\002\004\006" + + "\000\002\004\003\000\002\005\004\000\002\005\003\000" + + "\002\057\002\000\002\020\006\000\002\010\003\000\002" + + "\010\003\000\002\010\003\000\002\010\003\000\002\007" + + "\002\000\002\007\004\000\002\006\006\000\002\013\006" + + "\000\002\022\006\000\002\023\006\000\002\014\004\000" + + "\002\014\003\000\002\024\005\000\002\024\004\000\002" + + "\024\005\000\002\024\004\000\002\060\002\000\002\024" + + "\006\000\002\061\002\000\002\024\006\000\002\062\002" + + "\000\002\044\005\000\002\063\002\000\002\045\005\000" + + "\002\026\005\000\002\026\003\000\002\027\005\000\002" + + "\027\003\000\002\040\003\000\002\040\003\000\002\043" + + "\004\000\002\043\003\000\002\064\002\000\002\041\007" + + "\000\002\065\002\000\002\041\007\000\002\066\002\000" + + "\002\041\007\000\002\042\005\000\002\042\003\000\002" + + "\052\003\000\002\053\003\000\002\067\002\000\002\015" + + "\007\000\002\015\003\000\002\016\004\000\002\016\003" + + "\000\002\070\002\000\002\071\002\000\002\030\010\000" + + "\002\072\002\000\002\030\005\000\002\035\005\000\002" + + "\035\003\000\002\036\005\000\002\036\003\000\002\031" + + "\004\000\002\031\003\000\002\032\004\000\002\032\003" + + "\000\002\051\004\000\002\051\003\000\002\017\005\000" + + "\002\017\003\000\002\021\005\000\002\021\003\000\002" + + "\025\003\000\002\025\005\000\002\033\003\000\002\034" + + "\003\000\002\046\003\000\002\046\003\000\002\047\003" + + "\000\002\047\003\000\002\050\003\000\002\054\003\000" + + "\002\054\003\000\002\054\003\000\002\054\003\000\002" + + "\054\003\000\002\054\003\000\002\054\003\000\002\054" + + "\003\000\002\054\003\000\002\054\003\000\002\054\003" + + "\000\002\054\003\000\002\054\003\000\002\054\003\000" + + "\002\054\003\000\002\054\003\000\002\012\004\000\002" + + "\012\003\000\002\011\002\000\002\011\003\000\002\037" + + "\002" }); + + /** Access to production table. */ + public short[][] production_table() {return _production_table;} + + /** Parse-action table. */ + protected static final short[][] _action_table = + unpackFromStrings(new String[] { + "\000\247\000\026\003\006\004\000\005\000\007\000\010" + + "\000\011\000\012\000\013\000\014\000\035\000\001\002" + + "\000\004\002\251\001\002\000\024\004\200\005\uff97\007" + + "\uff97\010\uff97\011\uff97\012\uff97\013\uff97\014\uff97\035\uff97" + + "\001\002\000\010\011\007\012\012\035\014\001\002\000" + + "\042\003\163\006\026\007\027\010\040\011\036\012\022" + + "\013\042\014\030\015\017\016\015\026\033\027\023\030" + + "\035\031\041\035\025\036\160\001\002\000\020\003\uffeb" + + "\011\uffeb\012\uffeb\016\uffeb\026\uffeb\035\uffeb\036\uffeb\001" + + "\002\000\020\003\uff97\011\007\012\012\016\uff97\026\065" + + "\035\014\036\uff97\001\002\000\004\011\061\001\002\000" + + "\042\003\034\006\026\007\027\010\040\011\036\012\022" + + "\013\042\014\030\015\017\016\015\026\033\027\023\030" + + "\035\031\041\035\025\036\016\001\002\000\042\003\uff9a" + + "\006\uff9a\007\uff9a\010\uff9a\011\uff9a\012\uff9a\013\uff9a\014" + + "\uff9a\015\uff9a\016\uff9a\026\uff9a\027\uff9a\030\uff9a\031\uff9a" + + "\035\uff9a\036\uff9a\001\002\000\022\003\uffa1\017\uffa1\022" + + "\uffa1\025\uffa1\032\uffa1\033\uffa1\036\uffa1\037\uffa1\001\002" + + "\000\014\017\uffb1\020\uffb1\022\uffab\033\uffab\036\uffab\001" + + "\002\000\022\003\uffa2\017\uffa2\022\uffa2\025\uffa2\032\uffa2" + + "\033\uffa2\036\uffa2\037\uffa2\001\002\000\006\017\uffe0\020" + + "\055\001\002\000\010\022\051\033\uffb4\036\uffb4\001\002" + + "\000\022\003\uffa6\017\uffa6\022\uffa6\025\uffa6\032\uffa6\033" + + "\uffa6\036\uffa6\037\uffa6\001\002\000\022\003\uff9f\017\uff9f" + + "\022\uff9f\025\uff9f\032\uff9f\033\uff9f\036\uff9f\037\uff9f\001" + + "\002\000\006\033\047\036\045\001\002\000\022\003\uffa5" + + "\017\uffa5\022\uffa5\025\uffa5\032\uffa5\033\uffa5\036\uffa5\037" + + "\uffa5\001\002\000\022\003\uffaa\017\uffaa\022\uffaa\025\uffaa" + + "\032\uffaa\033\uffaa\036\uffaa\037\uffaa\001\002\000\022\003" + + "\uffa9\017\uffa9\022\uffa9\025\uffa9\032\uffa9\033\uffa9\036\uffa9" + + "\037\uffa9\001\002\000\022\003\uffa3\017\uffa3\022\uffa3\025" + + "\uffa3\032\uffa3\033\uffa3\036\uffa3\037\uffa3\001\002\000\012" + + "\017\uffb7\022\uffb7\033\uffb7\036\uffb7\001\002\000\020\003" + + "\uffe7\011\uffe7\012\uffe7\016\uffe7\026\uffe7\035\uffe7\036\uffe7" + + "\001\002\000\022\003\uffa0\017\uffa0\022\uffa0\025\uffa0\032" + + "\uffa0\033\uffa0\036\uffa0\037\uffa0\001\002\000\012\017\uffe4" + + "\022\uff9c\033\uff9c\036\uff9c\001\002\000\022\003\uff9e\017" + + "\uff9e\022\uff9e\025\uff9e\032\uff9e\033\uff9e\036\uff9e\037\uff9e" + + "\001\002\000\022\003\uffa7\017\uffa7\022\uffa7\025\uffa7\032" + + "\uffa7\033\uffa7\036\uffa7\037\uffa7\001\002\000\006\017\uffdb" + + "\020\uffdb\001\002\000\022\003\uffa8\017\uffa8\022\uffa8\025" + + "\uffa8\032\uffa8\033\uffa8\036\uffa8\037\uffa8\001\002\000\022" + + "\003\uff9d\017\uff9d\022\uff9d\025\uff9d\032\uff9d\033\uff9d\036" + + "\uff9d\037\uff9d\001\002\000\022\003\uffa4\017\uffa4\022\uffa4" + + "\025\uffa4\032\uffa4\033\uffa4\036\uffa4\037\uffa4\001\002\000" + + "\004\017\044\001\002\000\020\003\uffe3\011\uffe3\012\uffe3" + + "\016\uffe3\026\uffe3\035\uffe3\036\uffe3\001\002\000\006\017" + + "\uffb1\020\uffb1\001\002\000\020\003\uffe8\011\uffe8\012\uffe8" + + "\016\uffe8\026\uffe8\035\uffe8\036\uffe8\001\002\000\004\034" + + "\050\001\002\000\006\033\uffb3\036\uffb3\001\002\000\042" + + "\003\054\006\026\007\027\010\040\011\036\012\022\013" + + "\042\014\030\015\017\016\015\026\033\027\023\030\035" + + "\031\041\035\025\036\053\001\002\000\012\017\uffb8\022" + + "\uffb8\033\uffb8\036\uffb8\001\002\000\022\003\uffab\017\uffab" + + "\022\uffab\025\uffab\032\uffab\033\uffab\036\uffab\037\uffab\001" + + "\002\000\022\003\uff9c\017\uff9c\022\uff9c\025\uff9c\032\uff9c" + + "\033\uff9c\036\uff9c\037\uff9c\001\002\000\004\036\045\001" + + "\002\000\004\017\057\001\002\000\020\003\uffdf\011\uffdf" + + "\012\uffdf\016\uffdf\026\uffdf\035\uffdf\036\uffdf\001\002\000" + + "\006\017\uffdc\020\uffdc\001\002\000\042\003\uff9b\006\uff9b" + + "\007\uff9b\010\uff9b\011\uff9b\012\uff9b\013\uff9b\014\uff9b\015" + + "\uff9b\016\uff9b\026\uff9b\027\uff9b\030\uff9b\031\uff9b\035\uff9b" + + "\036\uff9b\001\002\000\010\003\uff97\016\116\036\uff97\001" + + "\002\000\012\003\uffda\016\uffda\026\065\036\uffda\001\002" + + "\000\010\003\uffd9\016\uffd9\036\uffd9\001\002\000\010\027" + + "\071\030\072\031\070\001\002\000\020\003\uffec\011\uffec" + + "\012\uffec\016\uffec\026\uffec\035\uffec\036\uffec\001\002\000" + + "\012\003\uffd7\016\uffd7\026\uffd7\036\uffd7\001\002\000\006" + + "\003\uffd2\036\uffd2\001\002\000\006\003\uffd6\036\uffd6\001" + + "\002\000\006\003\uffd4\036\uffd4\001\002\000\006\003\077" + + "\036\074\001\002\000\022\003\uffae\017\uffae\020\uffae\023" + + "\uffae\025\uffae\032\uffae\036\uffae\037\uffae\001\002\000\010" + + "\017\uffcd\020\uffcd\025\uffcd\001\002\000\006\017\uffce\020" + + "\uffce\001\002\000\022\003\uffad\017\uffad\020\uffad\023\uffad" + + "\025\uffad\032\uffad\036\uffad\037\uffad\001\002\000\006\017" + + "\102\020\103\001\002\000\006\017\uffcf\020\uffcf\001\002" + + "\000\012\003\uffd3\016\uffd3\026\uffd3\036\uffd3\001\002\000" + + "\006\003\077\036\074\001\002\000\006\017\uffd0\020\uffd0" + + "\001\002\000\006\003\077\036\074\001\002\000\006\017" + + "\107\020\103\001\002\000\012\003\uffd5\016\uffd5\026\uffd5" + + "\036\uffd5\001\002\000\006\003\077\036\074\001\002\000" + + "\006\017\112\020\103\001\002\000\012\003\uffd1\016\uffd1" + + "\026\uffd1\036\uffd1\001\002\000\012\003\uffd8\016\uffd8\026" + + "\uffd8\036\uffd8\001\002\000\006\003\uffca\036\uffca\001\002" + + "\000\006\003\126\036\120\001\002\000\004\015\117\001" + + "\002\000\006\003\122\036\120\001\002\000\006\017\uffb0" + + "\024\uffb0\001\002\000\004\017\uffcc\001\002\000\004\017" + + "\uffaf\001\002\000\004\017\124\001\002\000\006\003\uffcb" + + "\036\uffcb\001\002\000\004\024\uffc7\001\002\000\006\017" + + "\uffc4\024\uffaf\001\002\000\010\002\ufffe\003\126\036\120" + + "\001\002\000\010\002\uffc8\003\uffc8\036\uffc8\001\002\000" + + "\010\002\uffc9\003\uffc9\036\uffc9\001\002\000\004\017\133" + + "\001\002\000\010\002\uffc3\003\uffc3\036\uffc3\001\002\000" + + "\004\024\135\001\002\000\016\003\uffc6\017\uffc6\025\uffc6" + + "\032\uffc6\036\uffc6\037\uffc6\001\002\000\016\003\uff97\017" + + "\uff97\025\uff97\032\uff97\036\uff97\037\uff97\001\002\000\016" + + "\003\uffbd\017\uffbd\025\uffbd\032\uffbd\036\uffbd\037\uffbd\001" + + "\002\000\016\003\077\017\uffbf\025\uffbf\032\147\036\074" + + "\037\146\001\002\000\006\017\uffc1\025\uffc1\001\002\000" + + "\006\017\143\025\144\001\002\000\010\002\uffc5\003\uffc5" + + "\036\uffc5\001\002\000\016\003\uff97\017\uff97\025\uff97\032" + + "\uff97\036\uff97\037\uff97\001\002\000\006\017\uffc2\025\uffc2" + + "\001\002\000\016\003\uffbb\017\uffbb\025\uffbb\032\uffbb\036" + + "\uffbb\037\uffbb\001\002\000\006\003\077\036\074\001\002" + + "\000\020\003\uff97\017\uff97\023\154\025\uff97\032\uff97\036" + + "\uff97\037\uff97\001\002\000\016\003\uffbe\017\uffbe\025\uffbe" + + "\032\uffbe\036\uffbe\037\uffbe\001\002\000\016\003\uffb9\017" + + "\uffb9\025\uffb9\032\uffb9\036\uffb9\037\uffb9\001\002\000\016" + + "\003\uffbc\017\uffbc\025\uffbc\032\uffbc\036\uffbc\037\uffbc\001" + + "\002\000\042\003\054\006\026\007\027\010\040\011\036" + + "\012\022\013\042\014\030\015\017\016\015\026\033\027" + + "\023\030\035\031\041\035\025\036\053\001\002\000\016" + + "\003\uffba\017\uffba\025\uffba\032\uffba\036\uffba\037\uffba\001" + + "\002\000\016\003\uffac\017\uffac\025\uffac\032\uffac\036\uffac" + + "\037\uffac\001\002\000\006\017\uffc0\025\uffc0\001\002\000" + + "\014\017\uffb2\020\uffb2\022\uffab\033\uffab\036\uffab\001\002" + + "\000\006\033\047\036\170\001\002\000\006\017\uffdd\020" + + "\uffdd\001\002\000\012\017\uffe6\022\uff9c\033\uff9c\036\uff9c" + + "\001\002\000\020\003\uffe9\011\uffe9\012\uffe9\016\uffe9\026" + + "\uffe9\035\uffe9\036\uffe9\001\002\000\006\017\uffe2\020\167" + + "\001\002\000\004\017\172\001\002\000\004\036\170\001" + + "\002\000\006\017\uffb2\020\uffb2\001\002\000\006\017\uffde" + + "\020\uffde\001\002\000\020\003\uffe1\011\uffe1\012\uffe1\016" + + "\uffe1\026\uffe1\035\uffe1\036\uffe1\001\002\000\004\017\174" + + "\001\002\000\020\003\uffe5\011\uffe5\012\uffe5\016\uffe5\026" + + "\uffe5\035\uffe5\036\uffe5\001\002\000\020\003\uffea\011\uffea" + + "\012\uffea\016\uffea\026\uffea\035\uffea\036\uffea\001\002\000" + + "\022\005\ufffb\007\ufffb\010\ufffb\011\ufffb\012\ufffb\013\ufffb" + + "\014\ufffb\035\ufffb\001\002\000\022\005\uff97\007\uff97\010" + + "\uff97\011\uff97\012\uff97\013\uff97\014\uff97\035\uff97\001\002" + + "\000\042\003\054\006\026\007\027\010\040\011\036\012" + + "\022\013\042\014\030\015\017\016\015\026\033\027\023" + + "\030\035\031\041\035\025\036\053\001\002\000\006\017" + + "\ufffd\022\051\001\002\000\004\017\203\001\002\000\022" + + "\005\ufffc\007\ufffc\010\ufffc\011\ufffc\012\ufffc\013\ufffc\014" + + "\ufffc\035\ufffc\001\002\000\022\005\210\007\ufff2\010\ufff2" + + "\011\ufff2\012\ufff2\013\ufff2\014\ufff2\035\ufff2\001\002\000" + + "\022\005\ufff9\007\ufff9\010\ufff9\011\ufff9\012\ufff9\013\ufff9" + + "\014\ufff9\035\ufff9\001\002\000\020\007\223\010\224\011" + + "\007\012\012\013\227\014\225\035\014\001\002\000\022" + + "\005\ufffa\007\ufffa\010\ufffa\011\ufffa\012\ufffa\013\ufffa\014" + + "\ufffa\035\ufffa\001\002\000\042\003\054\006\026\007\027" + + "\010\040\011\036\012\022\013\042\014\030\015\017\016" + + "\015\026\033\027\023\030\035\031\041\035\025\036\053" + + "\001\002\000\006\017\uffb5\022\215\001\002\000\004\017" + + "\ufff8\001\002\000\004\017\214\001\002\000\022\005\ufff7" + + "\007\ufff7\010\ufff7\011\ufff7\012\ufff7\013\ufff7\014\ufff7\035" + + "\ufff7\001\002\000\044\003\054\006\026\007\027\010\040" + + "\011\036\012\022\013\042\014\030\015\017\016\015\021" + + "\216\026\033\027\023\030\035\031\041\035\025\036\053" + + "\001\002\000\004\017\uffb6\001\002\000\020\007\ufff3\010" + + "\ufff3\011\ufff3\012\ufff3\013\ufff3\014\ufff3\035\ufff3\001\002" + + "\000\020\007\ufff5\010\ufff5\011\ufff5\012\ufff5\013\ufff5\014" + + "\ufff5\035\ufff5\001\002\000\020\007\ufff1\010\ufff1\011\ufff1" + + "\012\ufff1\013\ufff1\014\ufff1\035\ufff1\001\002\000\020\007" + + "\ufff4\010\ufff4\011\ufff4\012\ufff4\013\ufff4\014\ufff4\035\ufff4" + + "\001\002\000\004\006\246\001\002\000\004\006\243\001" + + "\002\000\004\015\240\001\002\000\020\007\ufff6\010\ufff6" + + "\011\ufff6\012\ufff6\013\ufff6\014\ufff6\035\ufff6\001\002\000" + + "\004\015\234\001\002\000\020\003\uff97\011\007\012\012" + + "\016\uff97\026\065\035\014\036\uff97\001\002\000\010\003" + + "\uff97\016\116\036\uff97\001\002\000\006\003\126\036\120" + + "\001\002\000\010\002\uffff\003\126\036\120\001\002\000" + + "\004\037\235\001\002\000\022\007\uff99\010\uff99\011\uff99" + + "\012\uff99\013\uff99\014\uff99\017\236\035\uff99\001\002\000" + + "\020\007\uff98\010\uff98\011\uff98\012\uff98\013\uff98\014\uff98" + + "\035\uff98\001\002\000\020\007\uffee\010\uffee\011\uffee\012" + + "\uffee\013\uffee\014\uffee\035\uffee\001\002\000\004\037\241" + + "\001\002\000\022\007\uff99\010\uff99\011\uff99\012\uff99\013" + + "\uff99\014\uff99\017\236\035\uff99\001\002\000\020\007\uffed" + + "\010\uffed\011\uffed\012\uffed\013\uffed\014\uffed\035\uffed\001" + + "\002\000\004\037\244\001\002\000\022\007\uff99\010\uff99" + + "\011\uff99\012\uff99\013\uff99\014\uff99\017\236\035\uff99\001" + + "\002\000\020\007\uffef\010\uffef\011\uffef\012\uffef\013\uffef" + + "\014\uffef\035\uffef\001\002\000\004\037\247\001\002\000" + + "\022\007\uff99\010\uff99\011\uff99\012\uff99\013\uff99\014\uff99" + + "\017\236\035\uff99\001\002\000\020\007\ufff0\010\ufff0\011" + + "\ufff0\012\ufff0\013\ufff0\014\ufff0\035\ufff0\001\002\000\004" + + "\002\001\001\002" }); + + /** Access to parse-action table. */ + public short[][] action_table() {return _action_table;} + + /** <code>reduce_goto</code> table. */ + protected static final short[][] _reduce_table = + unpackFromStrings(new String[] { + "\000\247\000\006\003\003\055\004\001\001\000\002\001" + + "\001\000\006\004\176\037\175\001\001\000\010\012\012" + + "\014\010\024\007\001\001\000\016\017\020\025\160\026" + + "\164\033\161\044\163\054\030\001\001\000\002\001\001" + + "\000\016\012\012\024\065\037\063\040\061\041\066\043" + + "\062\001\001\000\002\001\001\000\016\017\020\025\023" + + "\027\017\034\036\045\031\054\030\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\004\063\055\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\010\027\017\034\036\045\045" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\002\001\001\000\004\061\042\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + + "\002\001\001\000\002\001\001\000\002\001\001\000\002" + + "\001\001\000\002\001\001\000\004\054\051\001\001\000" + + "\002\001\001\000\002\001\001\000\002\001\001\000\004" + + "\034\057\001\001\000\002\001\001\000\002\001\001\000" + + "\002\001\001\000\002\001\001\000\006\015\114\037\113" + + "\001\001\000\004\041\112\001\001\000\002\001\001\000" + + "\002\001\001\000\002\001\001\000\002\001\001\000\004" + + "\066\107\001\001\000\004\064\104\001\001\000\004\065" + + "\072\001\001\000\012\042\077\047\074\052\100\053\075" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\002\001\001\000\010\047\074\052\103\053\075\001" + + "\001\000\002\001\001\000\012\042\105\047\074\052\100" + + "\053\075\001\001\000\002\001\001\000\002\001\001\000" + + "\012\042\110\047\074\052\100\053\075\001\001\000\002" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\010\016\126\030\127\046\124\001\001\000\002" + + "\001\001\000\004\046\120\001\001\000\002\001\001\000" + + "\004\067\122\001\001\000\002\001\001\000\002\001\001" + + "\000\002\001\001\000\004\070\133\001\001\000\004\072" + + "\131\001\001\000\006\030\130\046\124\001\001\000\002" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\004\071\135\001\001\000\012" + + "\031\137\035\141\036\140\037\136\001\001\000\002\001" + + "\001\000\006\032\150\047\147\001\001\000\002\001\001" + + "\000\002\001\001\000\002\001\001\000\010\031\137\036" + + "\144\037\136\001\001\000\002\001\001\000\002\001\001" + + "\000\006\047\074\053\156\001\001\000\006\037\151\051" + + "\152\001\001\000\002\001\001\000\002\001\001\000\002" + + "\001\001\000\006\050\154\054\155\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\010\026\164\033\161\044\174\001\001\000\002\001" + + "\001\000\004\060\172\001\001\000\002\001\001\000\004" + + "\062\165\001\001\000\002\001\001\000\004\033\170\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + + "\002\001\001\000\006\005\203\037\204\001\001\000\006" + + "\017\200\054\030\001\001\000\004\056\201\001\001\000" + + "\002\001\001\000\002\001\001\000\006\007\205\020\206" + + "\001\001\000\002\001\001\000\022\006\225\010\220\012" + + "\012\013\217\014\227\022\221\023\216\024\007\001\001" + + "\000\002\001\001\000\010\017\210\021\211\054\030\001" + + "\001\000\002\001\001\000\004\057\212\001\001\000\002" + + "\001\001\000\002\001\001\000\004\054\051\001\001\000" + + "\002\001\001\000\002\001\001\000\002\001\001\000\002" + + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\016\012\012\024\065\037\063\040\230\041\066\043" + + "\062\001\001\000\006\015\231\037\113\001\001\000\010" + + "\016\232\030\127\046\124\001\001\000\006\030\130\046" + + "\124\001\001\000\002\001\001\000\004\011\236\001\001" + + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + + "\004\011\241\001\001\000\002\001\001\000\002\001\001" + + "\000\004\011\244\001\001\000\002\001\001\000\002\001" + + "\001\000\004\011\247\001\001\000\002\001\001\000\002" + + "\001\001" }); + + /** Access to <code>reduce_goto</code> table. */ + public short[][] reduce_table() {return _reduce_table;} + + /** Instance of action encapsulation class. */ + protected CUP$parser$actions action_obj; + + /** Action encapsulation object initializer. */ + protected void init_actions() + { + action_obj = new CUP$parser$actions(this); + } + + /** Invoke a user supplied parse action. */ + public java_cup.runtime.Symbol do_action( + int act_num, + java_cup.runtime.lr_parser parser, + java.util.Stack stack, + int top) + throws java.lang.Exception + { + /* call code in generated class */ + return action_obj.CUP$parser$do_action(act_num, parser, stack, top); + } + + /** Indicates start state. */ + public int start_state() {return 0;} + /** Indicates start production. */ + public int start_production() {return 0;} + + /** <code>EOF</code> Symbol index. */ + public int EOF_sym() {return 0;} + + /** <code>error</code> Symbol index. */ + public int error_sym() {return 1;} + + + /** User initialization code. */ + public void user_init() throws java.lang.Exception + { + lexer.init(); + } + + /** Scan to get the next Symbol. */ + public java_cup.runtime.Symbol scan() + throws java.lang.Exception + { + return lexer.next_token(); + } + + + + /* override error routines */ + + public void report_fatal_error( + String message, + Object info) + { + done_parsing(); + lexer.emit_error(message); + System.err.println("Can't recover from previous error(s), giving up."); + System.exit(1); + } + + public void report_error(String message, Object info) + { + lexer.emit_error(message); + } + +} + +/** Cup generated class to encapsulate user supplied action code.*/ +class CUP$parser$actions { + + + /** helper routine to clone a new production part adding a given label */ + protected production_part add_lab(production_part part, String lab) + throws internal_error + { + /* if there is no label, or this is an action, just return the original */ + if (lab == null || part.is_action()) return part; + + /* otherwise build a new one with the given label attached */ + return new symbol_part(((symbol_part)part).the_symbol(),lab); + } + + /** max size of right hand side we will support */ + protected final int MAX_RHS = 200; + + /** array for accumulating right hand side parts */ + protected production_part[] rhs_parts = new production_part[MAX_RHS]; + + /** where we are currently in building a right hand side */ + protected int rhs_pos = 0; + + /** start a new right hand side */ + protected void new_rhs() {rhs_pos = 0; } + + /** add a new right hand side part */ + protected void add_rhs_part(production_part part) throws java.lang.Exception + { + if (rhs_pos >= MAX_RHS) + throw new Exception("Internal Error: Productions limited to " + + MAX_RHS + " symbols and actions"); + + rhs_parts[rhs_pos] = part; + rhs_pos++; + } + + /** string to build up multiple part names */ + protected String multipart_name = new String(); + + /** append a new name segment to the accumulated multipart name */ + protected void append_multipart(String name) + { + String dot = ""; + + /* if we aren't just starting out, put on a dot */ + if (multipart_name.length() != 0) dot = "."; + + multipart_name = multipart_name.concat(dot + name); + } + + /** table of declared symbols -- contains production parts indexed by name */ + protected Hashtable symbols = new Hashtable(); + + /** table of just non terminals -- contains non_terminals indexed by name */ + protected Hashtable non_terms = new Hashtable(); + + /** declared start non_terminal */ + protected non_terminal start_nt = null; + + /** left hand side non terminal of the current production */ + protected non_terminal lhs_nt; + + /** Current precedence number */ + int _cur_prec = 0; + + /** Current precedence side */ + int _cur_side = assoc.no_prec; + + /** update the precedences we are declaring */ + protected void update_precedence(int p) { + _cur_side = p; + _cur_prec++; + } + /** add relevant data to terminals */ + protected void add_precedence(String term) { + if (term == null) { + System.err.println("Unable to add precedence to nonexistent terminal"); + } else { + symbol_part sp = (symbol_part)symbols.get(term); + if (sp == null) { + System.err.println("Could find terminal " + term + " while declaring precedence"); + } else { + java_cup.symbol sym = sp.the_symbol(); + if (sym instanceof terminal) + ((terminal)sym).set_precedence(_cur_side, _cur_prec); + else System.err.println("Precedence declaration: Can't find terminal " + term); + } + } + } + + private final parser parser; + + /** Constructor */ + CUP$parser$actions(parser parser) { + this.parser = parser; + } + + /** Method with the actual generated action code. */ + public final java_cup.runtime.Symbol CUP$parser$do_action( + int CUP$parser$act_num, + java_cup.runtime.lr_parser CUP$parser$parser, + java.util.Stack CUP$parser$stack, + int CUP$parser$top) + throws java.lang.Exception + { + /* Symbol object for return from actions */ + java_cup.runtime.Symbol CUP$parser$result; + + /* select the action based on the action number */ + switch (CUP$parser$act_num) + { + /*. . . . . . . . . . . . . . . . . . . .*/ + case 106: // empty ::= + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(29/*empty*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 105: // opt_semi ::= SEMI + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(7/*opt_semi*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 104: // opt_semi ::= + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(7/*opt_semi*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 103: // non_terminal ::= NONTERMINAL + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(8/*non_terminal*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 102: // non_terminal ::= NON TERMINAL + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(8/*non_terminal*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 101: // robust_id ::= error + { + String RESULT = null; + + lexer.emit_error("Illegal use of reserved word"); + RESULT="ILLEGAL"; + + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 100: // robust_id ::= NONASSOC + { + String RESULT = null; + RESULT = "nonassoc"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 99: // robust_id ::= RIGHT + { + String RESULT = null; + RESULT = "right"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 98: // robust_id ::= LEFT + { + String RESULT = null; + RESULT = "left"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 97: // robust_id ::= PRECEDENCE + { + String RESULT = null; + RESULT = "precedence"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 96: // robust_id ::= START + { + String RESULT = null; + RESULT = "start"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 95: // robust_id ::= WITH + { + String RESULT = null; + RESULT = "with"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 94: // robust_id ::= SCAN + { + String RESULT = null; + RESULT = "scan"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 93: // robust_id ::= INIT + { + String RESULT = null; + RESULT = "init"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 92: // robust_id ::= NONTERMINAL + { + String RESULT = null; + RESULT = "nonterminal"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 91: // robust_id ::= NON + { + String RESULT = null; + RESULT = "non"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 90: // robust_id ::= TERMINAL + { + String RESULT = null; + RESULT = "terminal"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 89: // robust_id ::= PARSER + { + String RESULT = null; + RESULT = "parser"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 88: // robust_id ::= ACTION + { + String RESULT = null; + RESULT = "action"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 87: // robust_id ::= CODE + { + String RESULT = null; + RESULT = "code"; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 86: // robust_id ::= ID + { + String RESULT = null; + int the_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int the_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String the_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = the_id; + CUP$parser$result = new java_cup.runtime.Symbol(42/*robust_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 85: // label_id ::= robust_id + { + String RESULT = null; + int the_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int the_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String the_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = the_id; + CUP$parser$result = new java_cup.runtime.Symbol(38/*label_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 84: // symbol_id ::= error + { + String RESULT = null; + + lexer.emit_error("Illegal use of reserved word"); + RESULT="ILLEGAL"; + + CUP$parser$result = new java_cup.runtime.Symbol(37/*symbol_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 83: // symbol_id ::= ID + { + String RESULT = null; + int the_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int the_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String the_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = the_id; + CUP$parser$result = new java_cup.runtime.Symbol(37/*symbol_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 82: // nt_id ::= error + { + String RESULT = null; + + lexer.emit_error("Illegal use of reserved word"); + RESULT="ILLEGAL"; + + CUP$parser$result = new java_cup.runtime.Symbol(36/*nt_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 81: // nt_id ::= ID + { + String RESULT = null; + int the_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int the_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String the_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = the_id; + CUP$parser$result = new java_cup.runtime.Symbol(36/*nt_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 80: // new_non_term_id ::= ID + { + Object RESULT = null; + int non_term_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int non_term_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String non_term_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + + /* see if this non terminal has been declared before */ + if (symbols.get(non_term_id) != null) + { + /* issue a message */ + lexer.emit_error( "java_cup.runtime.Symbol \"" + non_term_id + + "\" has already been declared"); + } + else + { + if (multipart_name.equals("")) { + append_multipart("Object"); + } + /* build the non terminal object */ + non_terminal this_nt = + new non_terminal(non_term_id, multipart_name); + + /* put it in the non_terms table */ + non_terms.put(non_term_id, this_nt); + + /* build a production_part and put it in the symbols table */ + symbols.put(non_term_id, new symbol_part(this_nt)); + } + + CUP$parser$result = new java_cup.runtime.Symbol(26/*new_non_term_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 79: // new_term_id ::= ID + { + Object RESULT = null; + int term_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int term_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String term_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + + /* see if this terminal has been declared before */ + if (symbols.get(term_id) != null) + { + /* issue a message */ + lexer.emit_error("java_cup.runtime.Symbol \"" + term_id + + "\" has already been declared"); + } + else + { + /* if no type declared, declare one */ + if (multipart_name.equals("")) { + append_multipart("Object"); + } + /* build a production_part and put it in the table */ + symbols.put(term_id, + new symbol_part(new terminal(term_id, multipart_name))); + } + + CUP$parser$result = new java_cup.runtime.Symbol(25/*new_term_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 78: // type_id ::= type_id LBRACK RBRACK + { + Object RESULT = null; + multipart_name = multipart_name.concat("[]"); + CUP$parser$result = new java_cup.runtime.Symbol(19/*type_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 77: // type_id ::= multipart_id + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(19/*type_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 76: // import_id ::= multipart_id + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(15/*import_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 75: // import_id ::= multipart_id DOT STAR + { + Object RESULT = null; + append_multipart("*"); + CUP$parser$result = new java_cup.runtime.Symbol(15/*import_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 74: // multipart_id ::= robust_id + { + Object RESULT = null; + int an_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int an_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String an_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + append_multipart(an_id); + CUP$parser$result = new java_cup.runtime.Symbol(13/*multipart_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 73: // multipart_id ::= multipart_id DOT robust_id + { + Object RESULT = null; + int another_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int another_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String another_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + append_multipart(another_id); + CUP$parser$result = new java_cup.runtime.Symbol(13/*multipart_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 72: // opt_label ::= empty + { + String RESULT = null; + RESULT = null; + CUP$parser$result = new java_cup.runtime.Symbol(39/*opt_label*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 71: // opt_label ::= COLON label_id + { + String RESULT = null; + int labidleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int labidright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String labid = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = labid; + CUP$parser$result = new java_cup.runtime.Symbol(39/*opt_label*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 70: // prod_part ::= CODE_STRING + { + Object RESULT = null; + int code_strleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int code_strright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String code_str = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + + /* add a new production part */ + add_rhs_part(new action_part(code_str)); + + CUP$parser$result = new java_cup.runtime.Symbol(24/*prod_part*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 69: // prod_part ::= symbol_id opt_label + { + Object RESULT = null; + int symidleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left; + int symidright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right; + String symid = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + int labidleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int labidright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String labid = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + + /* try to look up the id */ + production_part symb = (production_part)symbols.get(symid); + + /* if that fails, symbol is undeclared */ + if (symb == null) + { + if (lexer.error_count == 0) + lexer.emit_error("java_cup.runtime.Symbol \"" + symid + + "\" has not been declared"); + } + else + { + /* add a labeled production part */ + add_rhs_part(add_lab(symb, labid)); + } + + CUP$parser$result = new java_cup.runtime.Symbol(24/*prod_part*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 68: // prod_part_list ::= empty + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(23/*prod_part_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 67: // prod_part_list ::= prod_part_list prod_part + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(23/*prod_part_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 66: // rhs ::= prod_part_list + { + Object RESULT = null; + + if (lhs_nt != null) + { + /* build the production */ + production p = new production(lhs_nt, rhs_parts, rhs_pos); + + /* if we have no start non-terminal declared and this is + the first production, make its lhs nt the start_nt + and build a special start production for it. */ + if (start_nt == null) + { + start_nt = lhs_nt; + + /* build a special start production */ + new_rhs(); + add_rhs_part(add_lab(new symbol_part(start_nt),"start_val")); + add_rhs_part(new symbol_part(terminal.EOF)); + add_rhs_part(new action_part("RESULT = start_val;")); + emit.start_production = + new production(non_terminal.START_nt, rhs_parts, rhs_pos); + + new_rhs(); + } + } + + /* reset the rhs accumulation in any case */ + new_rhs(); + + CUP$parser$result = new java_cup.runtime.Symbol(28/*rhs*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 65: // rhs ::= prod_part_list PERCENT_PREC term_id + { + Object RESULT = null; + int term_nameleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int term_nameright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String term_name = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + + java_cup.symbol sym = null; + if (lhs_nt != null) + { + /* Find the precedence symbol */ + if (term_name == null) { + System.err.println("No terminal for contextual precedence"); + sym = null; + } else { + sym = ((symbol_part)symbols.get(term_name)).the_symbol(); + } + /* build the production */ + production p; + if ((sym!=null) && (sym instanceof terminal)) { + p = new production(lhs_nt, rhs_parts, rhs_pos, + ((terminal)sym).precedence_num(), + ((terminal)sym).precedence_side()); + ((symbol_part)symbols.get(term_name)).the_symbol().note_use(); + } else { + System.err.println("Invalid terminal " + term_name + + " for contextual precedence assignment"); + p = new production(lhs_nt, rhs_parts, rhs_pos); + } + + /* if we have no start non-terminal declared and this is + the first production, make its lhs nt the start_nt + and build a special start production for it. */ + if (start_nt == null) + { + start_nt = lhs_nt; + + /* build a special start production */ + new_rhs(); + add_rhs_part(add_lab(new symbol_part(start_nt),"start_val")); + add_rhs_part(new symbol_part(terminal.EOF)); + add_rhs_part(new action_part("RESULT = start_val;")); + if ((sym!=null) && (sym instanceof terminal)) { + emit.start_production = + new production(non_terminal.START_nt, rhs_parts, + rhs_pos, ((terminal)sym).precedence_num(), + ((terminal)sym).precedence_side()); + } else { + emit.start_production = + new production(non_terminal.START_nt, rhs_parts, rhs_pos); + } + new_rhs(); + } + } + + /* reset the rhs accumulation in any case */ + new_rhs(); + + CUP$parser$result = new java_cup.runtime.Symbol(28/*rhs*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 64: // rhs_list ::= rhs + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(27/*rhs_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 63: // rhs_list ::= rhs_list BAR rhs + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(27/*rhs_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 62: // production ::= error NT$13 SEMI + { + Object RESULT = null; + // propagate RESULT from NT$13 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(22/*production*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 61: // NT$13 ::= + { + Object RESULT = null; + lexer.emit_error("Syntax Error"); + CUP$parser$result = new java_cup.runtime.Symbol(56/*NT$13*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 60: // production ::= nt_id NT$11 COLON_COLON_EQUALS NT$12 rhs_list SEMI + { + Object RESULT = null; + // propagate RESULT from NT$11 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-4)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-4)).value; + // propagate RESULT from NT$12 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + int lhs_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-5)).left; + int lhs_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-5)).right; + String lhs_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-5)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(22/*production*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-5)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 59: // NT$12 ::= + { + Object RESULT = null; + int lhs_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left; + int lhs_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right; + String lhs_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(55/*NT$12*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 58: // NT$11 ::= + { + Object RESULT = null; + int lhs_idleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int lhs_idright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String lhs_id = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + + /* lookup the lhs nt */ + lhs_nt = (non_terminal)non_terms.get(lhs_id); + + /* if it wasn't declared, emit a message */ + if (lhs_nt == null) + { + if (lexer.error_count == 0) + lexer.emit_error("LHS non terminal \"" + lhs_id + + "\" has not been declared"); + } + + /* reset the rhs accumulation */ + new_rhs(); + + CUP$parser$result = new java_cup.runtime.Symbol(54/*NT$11*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 57: // production_list ::= production + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(12/*production_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 56: // production_list ::= production_list production + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(12/*production_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 55: // start_spec ::= empty + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(11/*start_spec*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 54: // start_spec ::= START WITH nt_id NT$10 SEMI + { + Object RESULT = null; + // propagate RESULT from NT$10 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + int start_nameleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left; + int start_nameright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right; + String start_name = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(11/*start_spec*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-4)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 53: // NT$10 ::= + { + Object RESULT = null; + int start_nameleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int start_nameright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String start_name = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + + /* verify that the name has been declared as a non terminal */ + non_terminal nt = (non_terminal)non_terms.get(start_name); + if (nt == null) + { + lexer.emit_error( "Start non terminal \"" + start_name + + "\" has not been declared"); + } + else + { + /* remember the non-terminal for later */ + start_nt = nt; + + /* build a special start production */ + new_rhs(); + add_rhs_part(add_lab(new symbol_part(start_nt), "start_val")); + add_rhs_part(new symbol_part(terminal.EOF)); + add_rhs_part(new action_part("RESULT = start_val;")); + emit.start_production = + new production(non_terminal.START_nt, rhs_parts, rhs_pos); + new_rhs(); + } + + CUP$parser$result = new java_cup.runtime.Symbol(53/*NT$10*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 52: // term_id ::= symbol_id + { + String RESULT = null; + int symleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int symright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String sym = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + + /* check that the symbol_id is a terminal */ + if (symbols.get(sym) == null) + { + /* issue a message */ + lexer.emit_error("Terminal \"" + sym + + "\" has not been declared"); + } + RESULT = sym; + + CUP$parser$result = new java_cup.runtime.Symbol(41/*term_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 51: // terminal_id ::= term_id + { + String RESULT = null; + int symleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int symright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + String sym = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + + add_precedence(sym); + RESULT = sym; + + CUP$parser$result = new java_cup.runtime.Symbol(40/*terminal_id*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 50: // terminal_list ::= terminal_id + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(32/*terminal_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 49: // terminal_list ::= terminal_list COMMA terminal_id + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(32/*terminal_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 48: // preced ::= PRECEDENCE NONASSOC NT$9 terminal_list SEMI + { + Object RESULT = null; + // propagate RESULT from NT$9 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(31/*preced*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-4)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 47: // NT$9 ::= + { + Object RESULT = null; + + update_precedence(assoc.nonassoc); + + CUP$parser$result = new java_cup.runtime.Symbol(52/*NT$9*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 46: // preced ::= PRECEDENCE RIGHT NT$8 terminal_list SEMI + { + Object RESULT = null; + // propagate RESULT from NT$8 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(31/*preced*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-4)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 45: // NT$8 ::= + { + Object RESULT = null; + + update_precedence(assoc.right); + + CUP$parser$result = new java_cup.runtime.Symbol(51/*NT$8*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 44: // preced ::= PRECEDENCE LEFT NT$7 terminal_list SEMI + { + Object RESULT = null; + // propagate RESULT from NT$7 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(31/*preced*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-4)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 43: // NT$7 ::= + { + Object RESULT = null; + + update_precedence(assoc.left); + + CUP$parser$result = new java_cup.runtime.Symbol(50/*NT$7*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 42: // precedence_l ::= preced + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(33/*precedence_l*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 41: // precedence_l ::= precedence_l preced + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(33/*precedence_l*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 40: // precedence_list ::= empty + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(30/*precedence_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 39: // precedence_list ::= precedence_l + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(30/*precedence_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 38: // non_term_name_list ::= new_non_term_id + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(21/*non_term_name_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 37: // non_term_name_list ::= non_term_name_list COMMA new_non_term_id + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(21/*non_term_name_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 36: // term_name_list ::= new_term_id + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(20/*term_name_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 35: // term_name_list ::= term_name_list COMMA new_term_id + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(20/*term_name_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 34: // declares_non_term ::= non_term_name_list NT$6 SEMI + { + Object RESULT = null; + // propagate RESULT from NT$6 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(35/*declares_non_term*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 33: // NT$6 ::= + { + Object RESULT = null; + + /* reset the accumulated multipart name */ + multipart_name = new String(); + + CUP$parser$result = new java_cup.runtime.Symbol(49/*NT$6*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 32: // declares_term ::= term_name_list NT$5 SEMI + { + Object RESULT = null; + // propagate RESULT from NT$5 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(34/*declares_term*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 31: // NT$5 ::= + { + Object RESULT = null; + + /* reset the accumulated multipart name */ + multipart_name = new String(); + + CUP$parser$result = new java_cup.runtime.Symbol(48/*NT$5*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 30: // symbol ::= non_terminal error NT$4 SEMI + { + Object RESULT = null; + // propagate RESULT from NT$4 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(18/*symbol*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-3)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 29: // NT$4 ::= + { + Object RESULT = null; + + /* reset the accumulated multipart name */ + multipart_name = new String(); + + CUP$parser$result = new java_cup.runtime.Symbol(47/*NT$4*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 28: // symbol ::= TERMINAL error NT$3 SEMI + { + Object RESULT = null; + // propagate RESULT from NT$3 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(18/*symbol*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-3)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 27: // NT$3 ::= + { + Object RESULT = null; + + /* reset the accumulated multipart name */ + multipart_name = new String(); + + CUP$parser$result = new java_cup.runtime.Symbol(46/*NT$3*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 26: // symbol ::= non_terminal declares_non_term + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(18/*symbol*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 25: // symbol ::= non_terminal type_id declares_non_term + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(18/*symbol*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 24: // symbol ::= TERMINAL declares_term + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(18/*symbol*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 23: // symbol ::= TERMINAL type_id declares_term + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(18/*symbol*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 22: // symbol_list ::= symbol + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(10/*symbol_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 21: // symbol_list ::= symbol_list symbol + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(10/*symbol_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 20: // scan_code ::= SCAN WITH CODE_STRING opt_semi + { + Object RESULT = null; + int user_codeleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left; + int user_coderight = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right; + String user_code = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + if (emit.scan_code!=null) + lexer.emit_error("Redundant scan code (skipping)"); + else /* save the user code */ + emit.scan_code = user_code; + + CUP$parser$result = new java_cup.runtime.Symbol(17/*scan_code*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-3)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 19: // init_code ::= INIT WITH CODE_STRING opt_semi + { + Object RESULT = null; + int user_codeleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left; + int user_coderight = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right; + String user_code = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + if (emit.init_code!=null) + lexer.emit_error("Redundant init code (skipping)"); + else /* save the user code */ + emit.init_code = user_code; + + CUP$parser$result = new java_cup.runtime.Symbol(16/*init_code*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-3)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 18: // parser_code_part ::= PARSER CODE CODE_STRING opt_semi + { + Object RESULT = null; + int user_codeleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left; + int user_coderight = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right; + String user_code = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + if (emit.parser_code!=null) + lexer.emit_error("Redundant parser code (skipping)"); + else /* save the user included code string */ + emit.parser_code = user_code; + + CUP$parser$result = new java_cup.runtime.Symbol(9/*parser_code_part*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-3)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 17: // action_code_part ::= ACTION CODE CODE_STRING opt_semi + { + Object RESULT = null; + int user_codeleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left; + int user_coderight = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right; + String user_code = (String)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + if (emit.action_code!=null) + lexer.emit_error("Redundant action code (skipping)"); + else /* save the user included code string */ + emit.action_code = user_code; + + CUP$parser$result = new java_cup.runtime.Symbol(4/*action_code_part*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-3)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 16: // code_parts ::= code_parts code_part + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(5/*code_parts*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 15: // code_parts ::= + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(5/*code_parts*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 14: // code_part ::= scan_code + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(6/*code_part*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 13: // code_part ::= init_code + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(6/*code_part*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 12: // code_part ::= parser_code_part + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(6/*code_part*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 11: // code_part ::= action_code_part + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(6/*code_part*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 10: // import_spec ::= IMPORT import_id NT$2 SEMI + { + Object RESULT = null; + // propagate RESULT from NT$2 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(14/*import_spec*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-3)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 9: // NT$2 ::= + { + Object RESULT = null; + + /* save this import on the imports list */ + emit.import_list.push(multipart_name); + + /* reset the accumulated multipart name */ + multipart_name = new String(); + + CUP$parser$result = new java_cup.runtime.Symbol(45/*NT$2*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 8: // import_list ::= empty + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(3/*import_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 7: // import_list ::= import_list import_spec + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(3/*import_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 6: // package_spec ::= empty + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(2/*package_spec*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 5: // package_spec ::= PACKAGE multipart_id NT$1 SEMI + { + Object RESULT = null; + // propagate RESULT from NT$1 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(2/*package_spec*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-3)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 4: // NT$1 ::= + { + Object RESULT = null; + + /* save the package name */ + emit.package_name = multipart_name; + + /* reset the accumulated multipart name */ + multipart_name = new String(); + + CUP$parser$result = new java_cup.runtime.Symbol(44/*NT$1*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 3: // spec ::= error symbol_list precedence_list start_spec production_list + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(1/*spec*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-4)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 2: // spec ::= NT$0 package_spec import_list code_parts symbol_list precedence_list start_spec production_list + { + Object RESULT = null; + // propagate RESULT from NT$0 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-7)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-7)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(1/*spec*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-7)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 1: // NT$0 ::= + { + Object RESULT = null; + + /* declare "error" as a terminal */ + symbols.put("error", new symbol_part(terminal.error)); + + /* declare start non terminal */ + non_terms.put("$START", non_terminal.START_nt); + + CUP$parser$result = new java_cup.runtime.Symbol(43/*NT$0*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 0: // $START ::= spec EOF + { + Object RESULT = null; + int start_valleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left; + int start_valright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right; + Object start_val = (Object)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = start_val; + CUP$parser$result = new java_cup.runtime.Symbol(0/*$START*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + /* ACCEPT */ + CUP$parser$parser.done_parsing(); + return CUP$parser$result; + + /* . . . . . .*/ + default: + throw new Exception( + "Invalid action number found in internal parse table"); + + } + } +} + diff --git a/open-nars/java_cup/production.java b/open-nars/java_cup/production.java new file mode 100644 index 0000000000000000000000000000000000000000..5a4128713feb0894d053a8c9b208aed729e8ab8d --- /dev/null +++ b/open-nars/java_cup/production.java @@ -0,0 +1,756 @@ + +package java_cup; + +import java.util.Hashtable; +import java.util.Enumeration; + +/** This class represents a production in the grammar. It contains + * a LHS non terminal, and an array of RHS symbols. As various + * transformations are done on the RHS of the production, it may shrink. + * As a result a separate length is always maintained to indicate how much + * of the RHS array is still valid.<p> + * + * I addition to construction and manipulation operations, productions provide + * methods for factoring out actions (see remove_embedded_actions()), for + * computing the nullability of the production (i.e., can it derive the empty + * string, see check_nullable()), and operations for computing its first + * set (i.e., the set of terminals that could appear at the beginning of some + * string derived from the production, see check_first_set()). + * + * @see java_cup.production_part + * @see java_cup.symbol_part + * @see java_cup.action_part + * @version last updated: 7/3/96 + * @author Frank Flannery + */ + +public class production { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. This constructor accepts a LHS non terminal, + * an array of RHS parts (including terminals, non terminals, and + * actions), and a string for a final reduce action. It does several + * manipulations in the process of creating a production object. + * After some validity checking it translates labels that appear in + * actions into code for accessing objects on the runtime parse stack. + * It them merges adjacent actions if they appear and moves any trailing + * action into the final reduce actions string. Next it removes any + * embedded actions by factoring them out with new action productions. + * Finally it assigns a unique index to the production.<p> + * + * Factoring out of actions is accomplished by creating new "hidden" + * non terminals. For example if the production was originally: <pre> + * A ::= B {action} C D + * </pre> + * then it is factored into two productions:<pre> + * A ::= B X C D + * X ::= {action} + * </pre> + * (where X is a unique new non terminal). This has the effect of placing + * all actions at the end where they can be handled as part of a reduce by + * the parser. + */ + public production( + non_terminal lhs_sym, + production_part rhs_parts[], + int rhs_l, + String action_str) + throws internal_error + { + int i; + action_part tail_action; + String declare_str; + int rightlen = rhs_l; + + /* remember the length */ + if (rhs_l >= 0) + _rhs_length = rhs_l; + else if (rhs_parts != null) + _rhs_length = rhs_parts.length; + else + _rhs_length = 0; + + /* make sure we have a valid left-hand-side */ + if (lhs_sym == null) + throw new internal_error( + "Attempt to construct a production with a null LHS"); + + /* I'm not translating labels anymore, I'm adding code to declare + labels as valid variables. This way, the users code string is + untouched + 6/96 frankf */ + + /* check if the last part of the right hand side is an action. If + it is, it won't be on the stack, so we don't want to count it + in the rightlen. Then when we search down the stack for a + Symbol, we don't try to search past action */ + + if (rhs_l > 0) { + if (rhs_parts[rhs_l - 1].is_action()) { + rightlen = rhs_l - 1; + } else { + rightlen = rhs_l; + } + } + + /* get the generated declaration code for the necessary labels. */ + declare_str = declare_labels( + rhs_parts, rightlen, action_str); + + if (action_str == null) + action_str = declare_str; + else + action_str = declare_str + action_str; + + /* count use of lhs */ + lhs_sym.note_use(); + + /* create the part for left-hand-side */ + _lhs = new symbol_part(lhs_sym); + + /* merge adjacent actions (if any) */ + _rhs_length = merge_adjacent_actions(rhs_parts, _rhs_length); + + /* strip off any trailing action */ + tail_action = strip_trailing_action(rhs_parts, _rhs_length); + if (tail_action != null) _rhs_length--; + + /* Why does this run through the right hand side happen + over and over? here a quick combination of two + prior runs plus one I wanted of my own + frankf 6/25/96 */ + /* allocate and copy over the right-hand-side */ + /* count use of each rhs symbol */ + _rhs = new production_part[_rhs_length]; + for (i=0; i<_rhs_length; i++) { + _rhs[i] = rhs_parts[i]; + if (!_rhs[i].is_action()) { + ((symbol_part)_rhs[i]).the_symbol().note_use(); + if (((symbol_part)_rhs[i]).the_symbol() instanceof terminal) { + _rhs_prec = + ((terminal)((symbol_part)_rhs[i]).the_symbol()).precedence_num(); + _rhs_assoc = + ((terminal)((symbol_part)_rhs[i]).the_symbol()).precedence_side(); + } + } + } + + /*now action string is really declaration string, so put it in front! + 6/14/96 frankf */ + if (action_str == null) action_str = ""; + if (tail_action != null && tail_action.code_string() != null) + action_str = action_str + "\t\t" + tail_action.code_string(); + + /* stash the action */ + _action = new action_part(action_str); + + /* rewrite production to remove any embedded actions */ + remove_embedded_actions(); + + /* assign an index */ + _index = next_index++; + + /* put us in the global collection of productions */ + _all.put(new Integer(_index),this); + + /* put us in the production list of the lhs non terminal */ + lhs_sym.add_production(this); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with no action string. */ + public production( + non_terminal lhs_sym, + production_part rhs_parts[], + int rhs_l) + throws internal_error + { + this(lhs_sym,rhs_parts,rhs_l,null); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /* Constructor with precedence and associativity of production + contextually define */ + public production( + non_terminal lhs_sym, + production_part rhs_parts[], + int rhs_l, + String action_str, + int prec_num, + int prec_side) + throws internal_error + { + this(lhs_sym,rhs_parts,rhs_l,action_str); + + /* set the precedence */ + set_precedence_num(prec_num); + set_precedence_side(prec_side); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /* Constructor w/ no action string and contextual precedence + defined */ + public production( + non_terminal lhs_sym, + production_part rhs_parts[], + int rhs_l, + int prec_num, + int prec_side) + throws internal_error + { + this(lhs_sym,rhs_parts,rhs_l,null); + /* set the precedence */ + set_precedence_num(prec_num); + set_precedence_side(prec_side); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + + /** Table of all productions. Elements are stored using their index as + * the key. + */ + protected static Hashtable _all = new Hashtable(); + + /** Access to all productions. */ + public static Enumeration all() {return _all.elements();} + + /** Lookup a production by index. */ + public static production find(int indx) { + return (production) _all.get(new Integer(indx)); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Total number of productions. */ + public static int number() {return _all.size();} + + /** Static counter for assigning unique index numbers. */ + protected static int next_index; + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The left hand side non-terminal. */ + protected symbol_part _lhs; + + /** The left hand side non-terminal. */ + public symbol_part lhs() {return _lhs;} + + + /** The precedence of the rule */ + protected int _rhs_prec = -1; + protected int _rhs_assoc = -1; + + /** Access to the precedence of the rule */ + public int precedence_num() { return _rhs_prec; } + public int precedence_side() { return _rhs_assoc; } + + /** Setting the precedence of a rule */ + public void set_precedence_num(int prec_num) { + _rhs_prec = prec_num; + } + public void set_precedence_side(int prec_side) { + _rhs_assoc = prec_side; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** A collection of parts for the right hand side. */ + protected production_part _rhs[]; + + /** Access to the collection of parts for the right hand side. */ + public production_part rhs(int indx) throws internal_error + { + if (indx >= 0 && indx < _rhs_length) + return _rhs[indx]; + else + throw new internal_error( + "Index out of range for right hand side of production"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** How much of the right hand side array we are presently using. */ + protected int _rhs_length; + + /** How much of the right hand side array we are presently using. */ + public int rhs_length() {return _rhs_length;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** An action_part containing code for the action to be performed when we + * reduce with this production. + */ + protected action_part _action; + + /** An action_part containing code for the action to be performed when we + * reduce with this production. + */ + public action_part action() {return _action;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Index number of the production. */ + protected int _index; + + /** Index number of the production. */ + public int index() {return _index;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of number of reductions using this production. */ + protected int _num_reductions = 0; + + /** Count of number of reductions using this production. */ + public int num_reductions() {return _num_reductions;} + + /** Increment the count of reductions with this non-terminal */ + public void note_reduction_use() {_num_reductions++;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Is the nullability of the production known or unknown? */ + protected boolean _nullable_known = false; + + /** Is the nullability of the production known or unknown? */ + public boolean nullable_known() {return _nullable_known;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Nullability of the production (can it derive the empty string). */ + protected boolean _nullable = false; + + /** Nullability of the production (can it derive the empty string). */ + public boolean nullable() {return _nullable;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** First set of the production. This is the set of terminals that + * could appear at the front of some string derived from this production. + */ + protected terminal_set _first_set = new terminal_set(); + + /** First set of the production. This is the set of terminals that + * could appear at the front of some string derived from this production. + */ + public terminal_set first_set() {return _first_set;} + + /*-----------------------------------------------------------*/ + /*--- Static Methods ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Determine if a given character can be a label id starter. + * @param c the character in question. + */ + protected static boolean is_id_start(char c) + { + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '_'); + + //later need to handle non-8-bit chars here + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if a character can be in a label id. + * @param c the character in question. + */ + protected static boolean is_id_char(char c) + { + return is_id_start(c) || (c >= '0' && c <= '9'); + } + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + + /** Return label declaration code + * @param labelname the label name + * @param stack_type the stack type of label? + * @author frankf + */ + protected String make_declaration( + String labelname, + String stack_type, + int offset) + { + String ret; + + /* Put in the left/right value labels */ + if (emit.lr_values()) + ret = "\t\tint " + labelname + "left = ((java_cup.runtime.Symbol)" + + emit.pre("stack") + ".elementAt(" + emit.pre("top") + + "-" + offset + ")).left;\n" + + "\t\tint " + labelname + "right = ((java_cup.runtime.Symbol)" + + emit.pre("stack") + ".elementAt(" + emit.pre("top") + + "-" + offset + ")).right;\n"; + else ret = ""; + + /* otherwise, just declare label. */ + return ret + "\t\t" + stack_type + " " + labelname + " = (" + stack_type + + ")((" + "java_cup.runtime.Symbol) " + emit.pre("stack") + ".elementAt(" + emit.pre("top") + + "-" + offset + ")).value;\n"; + + } + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Declare label names as valid variables within the action string + * @param rhs array of RHS parts. + * @param rhs_len how much of rhs to consider valid. + * @param final_action the final action string of the production. + * @param lhs_type the object type associated with the LHS symbol. + */ + protected String declare_labels( + production_part rhs[], + int rhs_len, + String final_action) + { + String declaration = ""; + + symbol_part part; + action_part act_part; + int pos; + + /* walk down the parts and extract the labels */ + for (pos = 0; pos < rhs_len; pos++) + { + if (!rhs[pos].is_action()) + { + part = (symbol_part)rhs[pos]; + + /* if it has a label, make declaration! */ + if (part.label() != null) + { + declaration = declaration + + make_declaration(part.label(), part.the_symbol().stack_type(), + rhs_len-pos-1); + } + } + } + return declaration; + } + + + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Helper routine to merge adjacent actions in a set of RHS parts + * @param rhs_parts array of RHS parts. + * @param len amount of that array that is valid. + * @return remaining valid length. + */ + protected int merge_adjacent_actions(production_part rhs_parts[], int len) + { + int from_loc, to_loc, merge_cnt; + + /* bail out early if we have no work to do */ + if (rhs_parts == null || len == 0) return 0; + + merge_cnt = 0; + to_loc = -1; + for (from_loc=0; from_loc<len; from_loc++) + { + /* do we go in the current position or one further */ + if (to_loc < 0 || !rhs_parts[to_loc].is_action() + || !rhs_parts[from_loc].is_action()) + { + /* next one */ + to_loc++; + + /* clear the way for it */ + if (to_loc != from_loc) rhs_parts[to_loc] = null; + } + + /* if this is not trivial? */ + if (to_loc != from_loc) + { + /* do we merge or copy? */ + if (rhs_parts[to_loc] != null && rhs_parts[to_loc].is_action() && + rhs_parts[from_loc].is_action()) + { + /* merge */ + rhs_parts[to_loc] = new action_part( + ((action_part)rhs_parts[to_loc]).code_string() + + ((action_part)rhs_parts[from_loc]).code_string()); + merge_cnt++; + } + else + { + /* copy */ + rhs_parts[to_loc] = rhs_parts[from_loc]; + } + } + } + + /* return the used length */ + return len - merge_cnt; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Helper routine to strip a trailing action off rhs and return it + * @param rhs_parts array of RHS parts. + * @param len how many of those are valid. + * @return the removed action part. + */ + protected action_part strip_trailing_action( + production_part rhs_parts[], + int len) + { + action_part result; + + /* bail out early if we have nothing to do */ + if (rhs_parts == null || len == 0) return null; + + /* see if we have a trailing action */ + if (rhs_parts[len-1].is_action()) + { + /* snip it out and return it */ + result = (action_part)rhs_parts[len-1]; + rhs_parts[len-1] = null; + return result; + } + else + return null; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Remove all embedded actions from a production by factoring them + * out into individual action production using new non terminals. + * if the original production was: <pre> + * A ::= B {action1} C {action2} D + * </pre> + * then it will be factored into: <pre> + * A ::= B NT$1 C NT$2 D + * NT$1 ::= {action1} + * NT$2 ::= {action2} + * </pre> + * where NT$1 and NT$2 are new system created non terminals. + */ + + /* the declarations added to the parent production are also passed along, + as they should be perfectly valid in this code string, since it + was originally a code string in the parent, not on its own. + frank 6/20/96 */ + protected void remove_embedded_actions( + + ) throws internal_error + { + non_terminal new_nt; + production new_prod; + String declare_str; + + /* walk over the production and process each action */ + for (int act_loc = 0; act_loc < rhs_length(); act_loc++) + if (rhs(act_loc).is_action()) + { + + + declare_str = declare_labels( + _rhs, act_loc, ""); + /* create a new non terminal for the action production */ + new_nt = non_terminal.create_new(); + new_nt.is_embedded_action = true; /* 24-Mar-1998, CSA */ + + /* create a new production with just the action */ + new_prod = new action_production(this, new_nt, null, 0, + declare_str + ((action_part)rhs(act_loc)).code_string()); + + /* replace the action with the generated non terminal */ + _rhs[act_loc] = new symbol_part(new_nt); + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Check to see if the production (now) appears to be nullable. + * A production is nullable if its RHS could derive the empty string. + * This results when the RHS is empty or contains only non terminals + * which themselves are nullable. + */ + public boolean check_nullable() throws internal_error + { + production_part part; + symbol sym; + int pos; + + /* if we already know bail out early */ + if (nullable_known()) return nullable(); + + /* if we have a zero size RHS we are directly nullable */ + if (rhs_length() == 0) + { + /* stash and return the result */ + return set_nullable(true); + } + + /* otherwise we need to test all of our parts */ + for (pos=0; pos<rhs_length(); pos++) + { + part = rhs(pos); + + /* only look at non-actions */ + if (!part.is_action()) + { + sym = ((symbol_part)part).the_symbol(); + + /* if its a terminal we are definitely not nullable */ + if (!sym.is_non_term()) + return set_nullable(false); + /* its a non-term, is it marked nullable */ + else if (!((non_terminal)sym).nullable()) + /* this one not (yet) nullable, so we aren't */ + return false; + } + } + + /* if we make it here all parts are nullable */ + return set_nullable(true); + } + + /** set (and return) nullability */ + boolean set_nullable(boolean v) + { + _nullable_known = true; + _nullable = v; + return v; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Update (and return) the first set based on current NT firsts. + * This assumes that nullability has already been computed for all non + * terminals and productions. + */ + public terminal_set check_first_set() throws internal_error + { + int part; + symbol sym; + + /* walk down the right hand side till we get past all nullables */ + for (part=0; part<rhs_length(); part++) + { + /* only look at non-actions */ + if (!rhs(part).is_action()) + { + sym = ((symbol_part)rhs(part)).the_symbol(); + + /* is it a non-terminal?*/ + if (sym.is_non_term()) + { + /* add in current firsts from that NT */ + _first_set.add(((non_terminal)sym).first_set()); + + /* if its not nullable, we are done */ + if (!((non_terminal)sym).nullable()) + break; + } + else + { + /* its a terminal -- add that to the set */ + _first_set.add((terminal)sym); + + /* we are done */ + break; + } + } + } + + /* return our updated first set */ + return first_set(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(production other) + { + if (other == null) return false; + return other._index == _index; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof production)) + return false; + else + return equals((production)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a hash code. */ + public int hashCode() + { + /* just use a simple function of the index */ + return _index*13; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + String result; + + /* catch any internal errors */ + try { + result = "production [" + index() + "]: "; + result += ((lhs() != null) ? lhs().toString() : "$$NULL-LHS$$"); + result += " :: = "; + for (int i = 0; i<rhs_length(); i++) + result += rhs(i) + " "; + result += ";"; + if (action() != null && action().code_string() != null) + result += " {" + action().code_string() + "}"; + + if (nullable_known()) + if (nullable()) + result += "[NULLABLE]"; + else + result += "[NOT NULLABLE]"; + } catch (internal_error e) { + /* crash on internal error since we can't throw it from here (because + superclass does not throw anything. */ + e.crash(); + result = null; + } + + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a simpler string. */ + public String to_simple_string() throws internal_error + { + String result; + + result = ((lhs() != null) ? lhs().the_symbol().name() : "NULL_LHS"); + result += " ::= "; + for (int i = 0; i < rhs_length(); i++) + if (!rhs(i).is_action()) + result += ((symbol_part)rhs(i)).the_symbol().name() + " "; + + return result; + } + + /*-----------------------------------------------------------*/ + +} diff --git a/open-nars/java_cup/production_part.java b/open-nars/java_cup/production_part.java new file mode 100644 index 0000000000000000000000000000000000000000..a790ec0b23720e6bdc6b94808ebb72140331ad9f --- /dev/null +++ b/open-nars/java_cup/production_part.java @@ -0,0 +1,94 @@ +package java_cup; + +/** This class represents one part (either a symbol or an action) of a + * production. In this base class it contains only an optional label + * string that the user can use to refer to the part within actions.<p> + * + * This is an abstract class. + * + * @see java_cup.production + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public abstract class production_part { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. */ + public production_part(String lab) + { + _label = lab; + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** Optional label for referring to the part within an action (null for + * no label). + */ + protected String _label; + + /** Optional label for referring to the part within an action (null for + * no label). + */ + public String label() {return _label;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Indicate if this is an action (rather than a symbol). Here in the + * base class, we don't this know yet, so its an abstract method. + */ + public abstract boolean is_action(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(production_part other) + { + if (other == null) return false; + + /* compare the labels */ + if (label() != null) + return label().equals(other.label()); + else + return other.label() == null; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof production_part)) + return false; + else + return equals((production_part)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a hash code. */ + public int hashCode() + { + return label()==null ? 0 : label().hashCode(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + if (label() != null) + return label() + ":"; + else + return " "; + } + + /*-----------------------------------------------------------*/ + +} diff --git a/open-nars/java_cup/reduce_action.java b/open-nars/java_cup/reduce_action.java new file mode 100644 index 0000000000000000000000000000000000000000..e8f4c84a5375de38226342632ecb06a6cb581846 --- /dev/null +++ b/open-nars/java_cup/reduce_action.java @@ -0,0 +1,84 @@ + +package java_cup; + +/** This class represents a reduce action within the parse table. + * The action simply stores the production that it reduces with and + * responds to queries about its type. + * + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class reduce_action extends parse_action { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. + * @param prod the production this action reduces with. + */ + public reduce_action(production prod ) throws internal_error + { + /* sanity check */ + if (prod == null) + throw new internal_error( + "Attempt to create a reduce_action with a null production"); + + _reduce_with = prod; + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The production we reduce with. */ + protected production _reduce_with; + + /** The production we reduce with. */ + public production reduce_with() {return _reduce_with;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Quick access to type of action. */ + public int kind() {return REDUCE;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality test. */ + public boolean equals(reduce_action other) + { + return other != null && other.reduce_with() == reduce_with(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality test. */ + public boolean equals(Object other) + { + if (other instanceof reduce_action) + return equals((reduce_action)other); + else + return false; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Compute a hash code. */ + public int hashCode() + { + /* use the hash code of the production we are reducing with */ + return reduce_with().hashCode(); + } + + + /** Convert to string. */ + public String toString() + { + return "REDUCE(with prod " + reduce_with().index() + ")"; + } + + /*-----------------------------------------------------------*/ + +} diff --git a/open-nars/java_cup/runtime/Scanner.java b/open-nars/java_cup/runtime/Scanner.java new file mode 100644 index 0000000000000000000000000000000000000000..32335516f082ca6f757c843c4f1f11d0c69fb262 --- /dev/null +++ b/open-nars/java_cup/runtime/Scanner.java @@ -0,0 +1,25 @@ +package java_cup.runtime; + +/** + * Defines the Scanner interface, which CUP uses in the default + * implementation of <code>lr_parser.scan()</code>. Integration + * of scanners implementing <code>Scanner</code> is facilitated. + * + * @version last updated 23-Jul-1999 + * @author David MacMahon <davidm@smartsc.com> + */ + +/* ************************************************* + Interface Scanner + + Declares the next_token() method that should be + implemented by scanners. This method is typically + called by lr_parser.scan(). End-of-file can be + indicated either by returning + <code>new Symbol(lr_parser.EOF_sym())</code> or + <code>null</code>. + ***************************************************/ +public interface Scanner { + /** Return the next token, or <code>null</code> on end-of-file. */ + public Symbol next_token() throws java.lang.Exception; +} diff --git a/open-nars/java_cup/runtime/Symbol.java b/open-nars/java_cup/runtime/Symbol.java new file mode 100644 index 0000000000000000000000000000000000000000..eeb6a0b4c6d630f5f4307a42fce9df4a6208ebf1 --- /dev/null +++ b/open-nars/java_cup/runtime/Symbol.java @@ -0,0 +1,105 @@ +package java_cup.runtime; + +/** + * Defines the Symbol class, which is used to represent all terminals + * and nonterminals while parsing. The lexer should pass CUP Symbols + * and CUP returns a Symbol. + * + * @version last updated: 7/3/96 + * @author Frank Flannery + */ + +/* **************************************************************** + Class Symbol + what the parser expects to receive from the lexer. + the token is identified as follows: + sym: the symbol type + parse_state: the parse state. + value: is the lexical value of type Object + left : is the left position in the original input file + right: is the right position in the original input file +******************************************************************/ + +public class Symbol { + +/******************************* + Constructor for l,r values + *******************************/ + + public Symbol(int id, int l, int r, Object o) { + this(id); + left = l; + right = r; + value = o; + } + +/******************************* + Constructor for no l,r values +********************************/ + + public Symbol(int id, Object o) { + this(id, -1, -1, o); + } + +/***************************** + Constructor for no value + ***************************/ + + public Symbol(int id, int l, int r) { + this(id, l, r, null); + } + +/*********************************** + Constructor for no value or l,r +***********************************/ + + public Symbol(int sym_num) { + this(sym_num, -1); + left = -1; + right = -1; + value = null; + } + +/*********************************** + Constructor to give a start state +***********************************/ + Symbol(int sym_num, int state) + { + sym = sym_num; + parse_state = state; + } + +/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The symbol number of the terminal or non terminal being represented */ + public int sym; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The parse state to be recorded on the parse stack with this symbol. + * This field is for the convenience of the parser and shouldn't be + * modified except by the parser. + */ + public int parse_state; + /** This allows us to catch some errors caused by scanners recycling + * symbols. For the use of the parser only. [CSA, 23-Jul-1999] */ + boolean used_by_parser = false; + +/******************************* + The data passed to parser + *******************************/ + + public int left, right; + public Object value; + + /***************************** + Printing this token out. (Override for pretty-print). + ****************************/ + public String toString() { return "#"+sym; } +} + + + + + + diff --git a/open-nars/java_cup/runtime/lr_parser.java b/open-nars/java_cup/runtime/lr_parser.java new file mode 100644 index 0000000000000000000000000000000000000000..3c8335cb25248cc6619f8f5324ce30d08b5e5543 --- /dev/null +++ b/open-nars/java_cup/runtime/lr_parser.java @@ -0,0 +1,1238 @@ + +package java_cup.runtime; + +import java.util.Stack; + +/** This class implements a skeleton table driven LR parser. In general, + * LR parsers are a form of bottom up shift-reduce parsers. Shift-reduce + * parsers act by shifting input onto a parse stack until the Symbols + * matching the right hand side of a production appear on the top of the + * stack. Once this occurs, a reduce is performed. This involves removing + * the Symbols corresponding to the right hand side of the production + * (the so called "handle") and replacing them with the non-terminal from + * the left hand side of the production. <p> + * + * To control the decision of whether to shift or reduce at any given point, + * the parser uses a state machine (the "viable prefix recognition machine" + * built by the parser generator). The current state of the machine is placed + * on top of the parse stack (stored as part of a Symbol object representing + * a terminal or non terminal). The parse action table is consulted + * (using the current state and the current lookahead Symbol as indexes) to + * determine whether to shift or to reduce. When the parser shifts, it + * changes to a new state by pushing a new Symbol (containing a new state) + * onto the stack. When the parser reduces, it pops the handle (right hand + * side of a production) off the stack. This leaves the parser in the state + * it was in before any of those Symbols were matched. Next the reduce-goto + * table is consulted (using the new state and current lookahead Symbol as + * indexes) to determine a new state to go to. The parser then shifts to + * this goto state by pushing the left hand side Symbol of the production + * (also containing the new state) onto the stack.<p> + * + * This class actually provides four LR parsers. The methods parse() and + * debug_parse() provide two versions of the main parser (the only difference + * being that debug_parse() emits debugging trace messages as it parses). + * In addition to these main parsers, the error recovery mechanism uses two + * more. One of these is used to simulate "parsing ahead" in the input + * without carrying out actions (to verify that a potential error recovery + * has worked), and the other is used to parse through buffered "parse ahead" + * input in order to execute all actions and re-synchronize the actual parser + * configuration.<p> + * + * This is an abstract class which is normally filled out by a subclass + * generated by the JavaCup parser generator. In addition to supplying + * the actual parse tables, generated code also supplies methods which + * invoke various pieces of user supplied code, provide access to certain + * special Symbols (e.g., EOF and error), etc. Specifically, the following + * abstract methods are normally supplied by generated code: + * <dl compact> + * <dt> short[][] production_table() + * <dd> Provides a reference to the production table (indicating the index of + * the left hand side non terminal and the length of the right hand side + * for each production in the grammar). + * <dt> short[][] action_table() + * <dd> Provides a reference to the parse action table. + * <dt> short[][] reduce_table() + * <dd> Provides a reference to the reduce-goto table. + * <dt> int start_state() + * <dd> Indicates the index of the start state. + * <dt> int start_production() + * <dd> Indicates the index of the starting production. + * <dt> int EOF_sym() + * <dd> Indicates the index of the EOF Symbol. + * <dt> int error_sym() + * <dd> Indicates the index of the error Symbol. + * <dt> Symbol do_action() + * <dd> Executes a piece of user supplied action code. This always comes at + * the point of a reduce in the parse, so this code also allocates and + * fills in the left hand side non terminal Symbol object that is to be + * pushed onto the stack for the reduce. + * <dt> void init_actions() + * <dd> Code to initialize a special object that encapsulates user supplied + * actions (this object is used by do_action() to actually carry out the + * actions). + * </dl> + * + * In addition to these routines that <i>must</i> be supplied by the + * generated subclass there are also a series of routines that <i>may</i> + * be supplied. These include: + * <dl> + * <dt> Symbol scan() + * <dd> Used to get the next input Symbol from the scanner. + * <dt> Scanner getScanner() + * <dd> Used to provide a scanner for the default implementation of + * scan(). + * <dt> int error_sync_size() + * <dd> This determines how many Symbols past the point of an error + * must be parsed without error in order to consider a recovery to + * be valid. This defaults to 3. Values less than 2 are not + * recommended. + * <dt> void report_error(String message, Object info) + * <dd> This method is called to report an error. The default implementation + * simply prints a message to System.err and where the error occurred. + * This method is often replaced in order to provide a more sophisticated + * error reporting mechanism. + * <dt> void report_fatal_error(String message, Object info) + * <dd> This method is called when a fatal error that cannot be recovered from + * is encountered. In the default implementation, it calls + * report_error() to emit a message, then throws an exception. + * <dt> void syntax_error(Symbol cur_token) + * <dd> This method is called as soon as syntax error is detected (but + * before recovery is attempted). In the default implementation it + * invokes: report_error("Syntax error", null); + * <dt> void unrecovered_syntax_error(Symbol cur_token) + * <dd> This method is called if syntax error recovery fails. In the default + * implementation it invokes:<br> + * report_fatal_error("Couldn't repair and continue parse", null); + * </dl> + * + * @see java_cup.runtime.Symbol + * @see java_cup.runtime.Symbol + * @see java_cup.runtime.virtual_parse_stack + * @version last updated: 7/3/96 + * @author Frank Flannery + */ + +public abstract class lr_parser { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. */ + public lr_parser() + { + /* nothing to do here */ + } + + /** Constructor that sets the default scanner. [CSA/davidm] */ + public lr_parser(Scanner s) { + this(); /* in case default constructor someday does something */ + setScanner(s); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + /** The default number of Symbols after an error we much match to consider + * it recovered from. + */ + protected final static int _error_sync_size = 3; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The number of Symbols after an error we much match to consider it + * recovered from. + */ + protected int error_sync_size() {return _error_sync_size; } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** Table of production information (supplied by generated subclass). + * This table contains one entry per production and is indexed by + * the negative-encoded values (reduce actions) in the action_table. + * Each entry has two parts, the index of the non-terminal on the + * left hand side of the production, and the number of Symbols + * on the right hand side. + */ + public abstract short[][] production_table(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The action table (supplied by generated subclass). This table is + * indexed by state and terminal number indicating what action is to + * be taken when the parser is in the given state (i.e., the given state + * is on top of the stack) and the given terminal is next on the input. + * States are indexed using the first dimension, however, the entries for + * a given state are compacted and stored in adjacent index, value pairs + * which are searched for rather than accessed directly (see get_action()). + * The actions stored in the table will be either shifts, reduces, or + * errors. Shifts are encoded as positive values (one greater than the + * state shifted to). Reduces are encoded as negative values (one less + * than the production reduced by). Error entries are denoted by zero. + * + * @see java_cup.runtime.lr_parser#get_action + */ + public abstract short[][] action_table(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The reduce-goto table (supplied by generated subclass). This + * table is indexed by state and non-terminal number and contains + * state numbers. States are indexed using the first dimension, however, + * the entries for a given state are compacted and stored in adjacent + * index, value pairs which are searched for rather than accessed + * directly (see get_reduce()). When a reduce occurs, the handle + * (corresponding to the RHS of the matched production) is popped off + * the stack. The new top of stack indicates a state. This table is + * then indexed by that state and the LHS of the reducing production to + * indicate where to "shift" to. + * + * @see java_cup.runtime.lr_parser#get_reduce + */ + public abstract short[][] reduce_table(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The index of the start state (supplied by generated subclass). */ + public abstract int start_state(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The index of the start production (supplied by generated subclass). */ + public abstract int start_production(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The index of the end of file terminal Symbol (supplied by generated + * subclass). + */ + public abstract int EOF_sym(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The index of the special error Symbol (supplied by generated subclass). */ + public abstract int error_sym(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Internal flag to indicate when parser should quit. */ + protected boolean _done_parsing = false; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** This method is called to indicate that the parser should quit. This is + * normally called by an accept action, but can be used to cancel parsing + * early in other circumstances if desired. + */ + public void done_parsing() + { + _done_parsing = true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + /* Global parse state shared by parse(), error recovery, and + * debugging routines */ + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Indication of the index for top of stack (for use by actions). */ + protected int tos; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The current lookahead Symbol. */ + protected Symbol cur_token; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The parse stack itself. */ + protected Stack stack = new Stack(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Direct reference to the production table. */ + protected short[][] production_tab; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Direct reference to the action table. */ + protected short[][] action_tab; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Direct reference to the reduce-goto table. */ + protected short[][] reduce_tab; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** This is the scanner object used by the default implementation + * of scan() to get Symbols. To avoid name conflicts with existing + * code, this field is private. [CSA/davidm] */ + private Scanner _scanner; + + /** + * Simple accessor method to set the default scanner. + */ + public void setScanner(Scanner s) { _scanner = s; } + + /** + * Simple accessor method to get the default scanner. + */ + public Scanner getScanner() { return _scanner; } + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Perform a bit of user supplied action code (supplied by generated + * subclass). Actions are indexed by an internal action number assigned + * at parser generation time. + * + * @param act_num the internal index of the action to be performed. + * @param parser the parser object we are acting for. + * @param stack the parse stack of that object. + * @param top the index of the top element of the parse stack. + */ + public abstract Symbol do_action( + int act_num, + lr_parser parser, + Stack stack, + int top) + throws java.lang.Exception; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** User code for initialization inside the parser. Typically this + * initializes the scanner. This is called before the parser requests + * the first Symbol. Here this is just a placeholder for subclasses that + * might need this and we perform no action. This method is normally + * overridden by the generated code using this contents of the "init with" + * clause as its body. + */ + public void user_init() throws java.lang.Exception { } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Initialize the action object. This is called before the parser does + * any parse actions. This is filled in by generated code to create + * an object that encapsulates all action code. + */ + protected abstract void init_actions() throws java.lang.Exception; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Get the next Symbol from the input (supplied by generated subclass). + * Once end of file has been reached, all subsequent calls to scan + * should return an EOF Symbol (which is Symbol number 0). By default + * this method returns getScanner().next_token(); this implementation + * can be overriden by the generated parser using the code declared in + * the "scan with" clause. Do not recycle objects; every call to + * scan() should return a fresh object. + */ + public Symbol scan() throws java.lang.Exception { + Symbol sym = getScanner().next_token(); + return (sym!=null) ? sym : new Symbol(EOF_sym()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Report a fatal error. This method takes a message string and an + * additional object (to be used by specializations implemented in + * subclasses). Here in the base class a very simple implementation + * is provided which reports the error then throws an exception. + * + * @param message an error message. + * @param info an extra object reserved for use by specialized subclasses. + */ + public void report_fatal_error( + String message, + Object info) + throws java.lang.Exception + { + /* stop parsing (not really necessary since we throw an exception, but) */ + done_parsing(); + + /* use the normal error message reporting to put out the message */ + report_error(message, info); + + /* throw an exception */ + throw new Exception("Can't recover from previous error(s)"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Report a non fatal error (or warning). This method takes a message + * string and an additional object (to be used by specializations + * implemented in subclasses). Here in the base class a very simple + * implementation is provided which simply prints the message to + * System.err. + * + * @param message an error message. + * @param info an extra object reserved for use by specialized subclasses. + */ + public void report_error(String message, Object info) + { + System.err.print(message); + if (info instanceof Symbol) + if (((Symbol)info).left != -1) + System.err.println(" at character " + ((Symbol)info).left + + " of input"); + else System.err.println(""); + else System.err.println(""); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** This method is called when a syntax error has been detected and recovery + * is about to be invoked. Here in the base class we just emit a + * "Syntax error" error message. + * + * @param cur_token the current lookahead Symbol. + */ + public void syntax_error(Symbol cur_token) + { + report_error("Syntax error", cur_token); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** This method is called if it is determined that syntax error recovery + * has been unsuccessful. Here in the base class we report a fatal error. + * + * @param cur_token the current lookahead Symbol. + */ + public void unrecovered_syntax_error(Symbol cur_token) + throws java.lang.Exception + { + report_fatal_error("Couldn't repair and continue parse", cur_token); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Fetch an action from the action table. The table is broken up into + * rows, one per state (rows are indexed directly by state number). + * Within each row, a list of index, value pairs are given (as sequential + * entries in the table), and the list is terminated by a default entry + * (denoted with a Symbol index of -1). To find the proper entry in a row + * we do a linear or binary search (depending on the size of the row). + * + * @param state the state index of the action being accessed. + * @param sym the Symbol index of the action being accessed. + */ + protected final short get_action(int state, int sym) + { + short tag; + int first, last, probe; + short[] row = action_tab[state]; + + /* linear search if we are < 10 entries */ + if (row.length < 20) + for (probe = 0; probe < row.length; probe++) + { + /* is this entry labeled with our Symbol or the default? */ + tag = row[probe++]; + if (tag == sym || tag == -1) + { + /* return the next entry */ + return row[probe]; + } + } + /* otherwise binary search */ + else + { + first = 0; + last = (row.length-1)/2 - 1; /* leave out trailing default entry */ + while (first <= last) + { + probe = (first+last)/2; + if (sym == row[probe*2]) + return row[probe*2+1]; + else if (sym > row[probe*2]) + first = probe+1; + else + last = probe-1; + } + + /* not found, use the default at the end */ + return row[row.length-1]; + } + + /* shouldn't happened, but if we run off the end we return the + default (error == 0) */ + return 0; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Fetch a state from the reduce-goto table. The table is broken up into + * rows, one per state (rows are indexed directly by state number). + * Within each row, a list of index, value pairs are given (as sequential + * entries in the table), and the list is terminated by a default entry + * (denoted with a Symbol index of -1). To find the proper entry in a row + * we do a linear search. + * + * @param state the state index of the entry being accessed. + * @param sym the Symbol index of the entry being accessed. + */ + protected final short get_reduce(int state, int sym) + { + short tag; + short[] row = reduce_tab[state]; + + /* if we have a null row we go with the default */ + if (row == null) + return -1; + + for (int probe = 0; probe < row.length; probe++) + { + /* is this entry labeled with our Symbol or the default? */ + tag = row[probe++]; + if (tag == sym || tag == -1) + { + /* return the next entry */ + return row[probe]; + } + } + /* if we run off the end we return the default (error == -1) */ + return -1; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** This method provides the main parsing routine. It returns only when + * done_parsing() has been called (typically because the parser has + * accepted, or a fatal error has been reported). See the header + * documentation for the class regarding how shift/reduce parsers operate + * and how the various tables are used. + */ + public Symbol parse() throws java.lang.Exception + { + /* the current action code */ + int act; + + /* the Symbol/stack element returned by a reduce */ + Symbol lhs_sym = null; + + /* information about production being reduced with */ + short handle_size, lhs_sym_num; + + /* set up direct reference to tables to drive the parser */ + + production_tab = production_table(); + action_tab = action_table(); + reduce_tab = reduce_table(); + + /* initialize the action encapsulation object */ + init_actions(); + + /* do user initialization */ + user_init(); + + /* get the first token */ + cur_token = scan(); + + /* push dummy Symbol with start state to get us underway */ + stack.removeAllElements(); + stack.push(new Symbol(0, start_state())); + tos = 0; + + /* continue until we are told to stop */ + for (_done_parsing = false; !_done_parsing; ) + { + /* Check current token for freshness. */ + if (cur_token.used_by_parser) + throw new Error("Symbol recycling detected (fix your scanner)."); + + /* current state is always on the top of the stack */ + + /* look up action out of the current state with the current input */ + act = get_action(((Symbol)stack.peek()).parse_state, cur_token.sym); + + /* decode the action -- > 0 encodes shift */ + if (act > 0) + { + /* shift to the encoded state by pushing it on the stack */ + cur_token.parse_state = act-1; + cur_token.used_by_parser = true; + stack.push(cur_token); + tos++; + + /* advance to the next Symbol */ + cur_token = scan(); + } + /* if its less than zero, then it encodes a reduce action */ + else if (act < 0) + { + /* perform the action for the reduce */ + lhs_sym = do_action((-act)-1, this, stack, tos); + + /* look up information about the production */ + lhs_sym_num = production_tab[(-act)-1][0]; + handle_size = production_tab[(-act)-1][1]; + + /* pop the handle off the stack */ + for (int i = 0; i < handle_size; i++) + { + stack.pop(); + tos--; + } + + /* look up the state to go to from the one popped back to */ + act = get_reduce(((Symbol)stack.peek()).parse_state, lhs_sym_num); + + /* shift to that state */ + lhs_sym.parse_state = act; + lhs_sym.used_by_parser = true; + stack.push(lhs_sym); + tos++; + } + /* finally if the entry is zero, we have an error */ + else if (act == 0) + { + /* call user syntax error reporting routine */ + syntax_error(cur_token); + + /* try to error recover */ + if (!error_recovery(false)) + { + /* if that fails give up with a fatal syntax error */ + unrecovered_syntax_error(cur_token); + + /* just in case that wasn't fatal enough, end parse */ + done_parsing(); + } else { + lhs_sym = (Symbol)stack.peek(); + } + } + } + return lhs_sym; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Write a debugging message to System.err for the debugging version + * of the parser. + * + * @param mess the text of the debugging message. + */ + public void debug_message(String mess) + { + System.err.println(mess); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Dump the parse stack for debugging purposes. */ + public void dump_stack() + { + if (stack == null) + { + debug_message("# Stack dump requested, but stack is null"); + return; + } + + debug_message("============ Parse Stack Dump ============"); + + /* dump the stack */ + for (int i=0; i<stack.size(); i++) + { + debug_message("Symbol: " + ((Symbol)stack.elementAt(i)).sym + + " State: " + ((Symbol)stack.elementAt(i)).parse_state); + } + debug_message("=========================================="); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Do debug output for a reduce. + * + * @param prod_num the production we are reducing with. + * @param nt_num the index of the LHS non terminal. + * @param rhs_size the size of the RHS. + */ + public void debug_reduce(int prod_num, int nt_num, int rhs_size) + { + debug_message("# Reduce with prod #" + prod_num + " [NT=" + nt_num + + ", " + "SZ=" + rhs_size + "]"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Do debug output for shift. + * + * @param shift_tkn the Symbol being shifted onto the stack. + */ + public void debug_shift(Symbol shift_tkn) + { + debug_message("# Shift under term #" + shift_tkn.sym + + " to state #" + shift_tkn.parse_state); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Do debug output for stack state. [CSA] + */ + public void debug_stack() { + StringBuffer sb=new StringBuffer("## STACK:"); + for (int i=0; i<stack.size(); i++) { + Symbol s = (Symbol) stack.elementAt(i); + sb.append(" <state "+s.parse_state+", sym "+s.sym+">"); + if ((i%3)==2 || (i==(stack.size()-1))) { + debug_message(sb.toString()); + sb = new StringBuffer(" "); + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Perform a parse with debugging output. This does exactly the + * same things as parse(), except that it calls debug_shift() and + * debug_reduce() when shift and reduce moves are taken by the parser + * and produces various other debugging messages. + */ + public Symbol debug_parse() + throws java.lang.Exception + { + /* the current action code */ + int act; + + /* the Symbol/stack element returned by a reduce */ + Symbol lhs_sym = null; + + /* information about production being reduced with */ + short handle_size, lhs_sym_num; + + /* set up direct reference to tables to drive the parser */ + production_tab = production_table(); + action_tab = action_table(); + reduce_tab = reduce_table(); + + debug_message("# Initializing parser"); + + /* initialize the action encapsulation object */ + init_actions(); + + /* do user initialization */ + user_init(); + + /* the current Symbol */ + cur_token = scan(); + + debug_message("# Current Symbol is #" + cur_token.sym); + + /* push dummy Symbol with start state to get us underway */ + stack.removeAllElements(); + stack.push(new Symbol(0, start_state())); + tos = 0; + + /* continue until we are told to stop */ + for (_done_parsing = false; !_done_parsing; ) + { + /* Check current token for freshness. */ + if (cur_token.used_by_parser) + throw new Error("Symbol recycling detected (fix your scanner)."); + + /* current state is always on the top of the stack */ + //debug_stack(); + + /* look up action out of the current state with the current input */ + act = get_action(((Symbol)stack.peek()).parse_state, cur_token.sym); + + /* decode the action -- > 0 encodes shift */ + if (act > 0) + { + /* shift to the encoded state by pushing it on the stack */ + cur_token.parse_state = act-1; + cur_token.used_by_parser = true; + debug_shift(cur_token); + stack.push(cur_token); + tos++; + + /* advance to the next Symbol */ + cur_token = scan(); + debug_message("# Current token is " + cur_token); + } + /* if its less than zero, then it encodes a reduce action */ + else if (act < 0) + { + /* perform the action for the reduce */ + lhs_sym = do_action((-act)-1, this, stack, tos); + + /* look up information about the production */ + lhs_sym_num = production_tab[(-act)-1][0]; + handle_size = production_tab[(-act)-1][1]; + + debug_reduce((-act)-1, lhs_sym_num, handle_size); + + /* pop the handle off the stack */ + for (int i = 0; i < handle_size; i++) + { + stack.pop(); + tos--; + } + + /* look up the state to go to from the one popped back to */ + act = get_reduce(((Symbol)stack.peek()).parse_state, lhs_sym_num); + debug_message("# Reduce rule: top state " + + ((Symbol)stack.peek()).parse_state + + ", lhs sym " + lhs_sym_num + " -> state " + act); + + /* shift to that state */ + lhs_sym.parse_state = act; + lhs_sym.used_by_parser = true; + stack.push(lhs_sym); + tos++; + + debug_message("# Goto state #" + act); + } + /* finally if the entry is zero, we have an error */ + else if (act == 0) + { + /* call user syntax error reporting routine */ + syntax_error(cur_token); + + /* try to error recover */ + if (!error_recovery(true)) + { + /* if that fails give up with a fatal syntax error */ + unrecovered_syntax_error(cur_token); + + /* just in case that wasn't fatal enough, end parse */ + done_parsing(); + } else { + lhs_sym = (Symbol)stack.peek(); + } + } + } + return lhs_sym; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + /* Error recovery code */ + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Attempt to recover from a syntax error. This returns false if recovery + * fails, true if it succeeds. Recovery happens in 4 steps. First we + * pop the parse stack down to a point at which we have a shift out + * of the top-most state on the error Symbol. This represents the + * initial error recovery configuration. If no such configuration is + * found, then we fail. Next a small number of "lookahead" or "parse + * ahead" Symbols are read into a buffer. The size of this buffer is + * determined by error_sync_size() and determines how many Symbols beyond + * the error must be matched to consider the recovery a success. Next, + * we begin to discard Symbols in attempt to get past the point of error + * to a point where we can continue parsing. After each Symbol, we attempt + * to "parse ahead" though the buffered lookahead Symbols. The "parse ahead" + * process simulates that actual parse, but does not modify the real + * parser's configuration, nor execute any actions. If we can parse all + * the stored Symbols without error, then the recovery is considered a + * success. Once a successful recovery point is determined, we do an + * actual parse over the stored input -- modifying the real parse + * configuration and executing all actions. Finally, we return the the + * normal parser to continue with the overall parse. + * + * @param debug should we produce debugging messages as we parse. + */ + protected boolean error_recovery(boolean debug) + throws java.lang.Exception + { + if (debug) debug_message("# Attempting error recovery"); + + /* first pop the stack back into a state that can shift on error and + do that shift (if that fails, we fail) */ + if (!find_recovery_config(debug)) + { + if (debug) debug_message("# Error recovery fails"); + return false; + } + + /* read ahead to create lookahead we can parse multiple times */ + read_lookahead(); + + /* repeatedly try to parse forward until we make it the required dist */ + for (;;) + { + /* try to parse forward, if it makes it, bail out of loop */ + if (debug) debug_message("# Trying to parse ahead"); + if (try_parse_ahead(debug)) + { + break; + } + + /* if we are now at EOF, we have failed */ + if (lookahead[0].sym == EOF_sym()) + { + if (debug) debug_message("# Error recovery fails at EOF"); + return false; + } + + /* otherwise, we consume another Symbol and try again */ + // BUG FIX by Bruce Hutton + // Computer Science Department, University of Auckland, + // Auckland, New Zealand. + // It is the first token that is being consumed, not the one + // we were up to parsing + if (debug) + debug_message("# Consuming Symbol #" + lookahead[ 0 ].sym); + restart_lookahead(); + } + + /* we have consumed to a point where we can parse forward */ + if (debug) debug_message("# Parse-ahead ok, going back to normal parse"); + + /* do the real parse (including actions) across the lookahead */ + parse_lookahead(debug); + + /* we have success */ + return true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if we can shift under the special error Symbol out of the + * state currently on the top of the (real) parse stack. + */ + protected boolean shift_under_error() + { + /* is there a shift under error Symbol */ + return get_action(((Symbol)stack.peek()).parse_state, error_sym()) > 0; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Put the (real) parse stack into error recovery configuration by + * popping the stack down to a state that can shift on the special + * error Symbol, then doing the shift. If no suitable state exists on + * the stack we return false + * + * @param debug should we produce debugging messages as we parse. + */ + protected boolean find_recovery_config(boolean debug) + { + Symbol error_token; + int act; + + if (debug) debug_message("# Finding recovery state on stack"); + + /* Remember the right-position of the top symbol on the stack */ + int right_pos = ((Symbol)stack.peek()).right; + int left_pos = ((Symbol)stack.peek()).left; + + /* pop down until we can shift under error Symbol */ + while (!shift_under_error()) + { + /* pop the stack */ + if (debug) + debug_message("# Pop stack by one, state was # " + + ((Symbol)stack.peek()).parse_state); + left_pos = ((Symbol)stack.pop()).left; + tos--; + + /* if we have hit bottom, we fail */ + if (stack.empty()) + { + if (debug) debug_message("# No recovery state found on stack"); + return false; + } + } + + /* state on top of the stack can shift under error, find the shift */ + act = get_action(((Symbol)stack.peek()).parse_state, error_sym()); + if (debug) + { + debug_message("# Recover state found (#" + + ((Symbol)stack.peek()).parse_state + ")"); + debug_message("# Shifting on error to state #" + (act-1)); + } + + /* build and shift a special error Symbol */ + error_token = new Symbol(error_sym(), left_pos, right_pos); + error_token.parse_state = act-1; + error_token.used_by_parser = true; + stack.push(error_token); + tos++; + + return true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Lookahead Symbols used for attempting error recovery "parse aheads". */ + protected Symbol lookahead[]; + + /** Position in lookahead input buffer used for "parse ahead". */ + protected int lookahead_pos; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Read from input to establish our buffer of "parse ahead" lookahead + * Symbols. + */ + protected void read_lookahead() throws java.lang.Exception + { + /* create the lookahead array */ + lookahead = new Symbol[error_sync_size()]; + + /* fill in the array */ + for (int i = 0; i < error_sync_size(); i++) + { + lookahead[i] = cur_token; + cur_token = scan(); + } + + /* start at the beginning */ + lookahead_pos = 0; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return the current lookahead in our error "parse ahead" buffer. */ + protected Symbol cur_err_token() { return lookahead[lookahead_pos]; } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Advance to next "parse ahead" input Symbol. Return true if we have + * input to advance to, false otherwise. + */ + protected boolean advance_lookahead() + { + /* advance the input location */ + lookahead_pos++; + + /* return true if we didn't go off the end */ + return lookahead_pos < error_sync_size(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Reset the parse ahead input to one Symbol past where we started error + * recovery (this consumes one new Symbol from the real input). + */ + protected void restart_lookahead() throws java.lang.Exception + { + /* move all the existing input over */ + for (int i = 1; i < error_sync_size(); i++) + lookahead[i-1] = lookahead[i]; + + /* read a new Symbol into the last spot */ + // BUG Fix by Bruce Hutton + // Computer Science Department, University of Auckland, + // Auckland, New Zealand. [applied 5-sep-1999 by csa] + // The following two lines were out of order!! + lookahead[error_sync_size()-1] = cur_token; + cur_token = scan(); + + /* reset our internal position marker */ + lookahead_pos = 0; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Do a simulated parse forward (a "parse ahead") from the current + * stack configuration using stored lookahead input and a virtual parse + * stack. Return true if we make it all the way through the stored + * lookahead input without error. This basically simulates the action of + * parse() using only our saved "parse ahead" input, and not executing any + * actions. + * + * @param debug should we produce debugging messages as we parse. + */ + protected boolean try_parse_ahead(boolean debug) + throws java.lang.Exception + { + int act; + short lhs, rhs_size; + + /* create a virtual stack from the real parse stack */ + virtual_parse_stack vstack = new virtual_parse_stack(stack); + + /* parse until we fail or get past the lookahead input */ + for (;;) + { + /* look up the action from the current state (on top of stack) */ + act = get_action(vstack.top(), cur_err_token().sym); + + /* if its an error, we fail */ + if (act == 0) return false; + + /* > 0 encodes a shift */ + if (act > 0) + { + /* push the new state on the stack */ + vstack.push(act-1); + + if (debug) debug_message("# Parse-ahead shifts Symbol #" + + cur_err_token().sym + " into state #" + (act-1)); + + /* advance simulated input, if we run off the end, we are done */ + if (!advance_lookahead()) return true; + } + /* < 0 encodes a reduce */ + else + { + /* if this is a reduce with the start production we are done */ + if ((-act)-1 == start_production()) + { + if (debug) debug_message("# Parse-ahead accepts"); + return true; + } + + /* get the lhs Symbol and the rhs size */ + lhs = production_tab[(-act)-1][0]; + rhs_size = production_tab[(-act)-1][1]; + + /* pop handle off the stack */ + for (int i = 0; i < rhs_size; i++) + vstack.pop(); + + if (debug) + debug_message("# Parse-ahead reduces: handle size = " + + rhs_size + " lhs = #" + lhs + " from state #" + vstack.top()); + + /* look up goto and push it onto the stack */ + vstack.push(get_reduce(vstack.top(), lhs)); + if (debug) + debug_message("# Goto state #" + vstack.top()); + } + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Parse forward using stored lookahead Symbols. In this case we have + * already verified that parsing will make it through the stored lookahead + * Symbols and we are now getting back to the point at which we can hand + * control back to the normal parser. Consequently, this version of the + * parser performs all actions and modifies the real parse configuration. + * This returns once we have consumed all the stored input or we accept. + * + * @param debug should we produce debugging messages as we parse. + */ + protected void parse_lookahead(boolean debug) + throws java.lang.Exception + { + /* the current action code */ + int act; + + /* the Symbol/stack element returned by a reduce */ + Symbol lhs_sym = null; + + /* information about production being reduced with */ + short handle_size, lhs_sym_num; + + /* restart the saved input at the beginning */ + lookahead_pos = 0; + + if (debug) + { + debug_message("# Reparsing saved input with actions"); + debug_message("# Current Symbol is #" + cur_err_token().sym); + debug_message("# Current state is #" + + ((Symbol)stack.peek()).parse_state); + } + + /* continue until we accept or have read all lookahead input */ + while(!_done_parsing) + { + /* current state is always on the top of the stack */ + + /* look up action out of the current state with the current input */ + act = + get_action(((Symbol)stack.peek()).parse_state, cur_err_token().sym); + + /* decode the action -- > 0 encodes shift */ + if (act > 0) + { + /* shift to the encoded state by pushing it on the stack */ + cur_err_token().parse_state = act-1; + cur_err_token().used_by_parser = true; + if (debug) debug_shift(cur_err_token()); + stack.push(cur_err_token()); + tos++; + + /* advance to the next Symbol, if there is none, we are done */ + if (!advance_lookahead()) + { + if (debug) debug_message("# Completed reparse"); + + /* scan next Symbol so we can continue parse */ + // BUGFIX by Chris Harris <ckharris@ucsd.edu>: + // correct a one-off error by commenting out + // this next line. + /*cur_token = scan();*/ + + /* go back to normal parser */ + return; + } + + if (debug) + debug_message("# Current Symbol is #" + cur_err_token().sym); + } + /* if its less than zero, then it encodes a reduce action */ + else if (act < 0) + { + /* perform the action for the reduce */ + lhs_sym = do_action((-act)-1, this, stack, tos); + + /* look up information about the production */ + lhs_sym_num = production_tab[(-act)-1][0]; + handle_size = production_tab[(-act)-1][1]; + + if (debug) debug_reduce((-act)-1, lhs_sym_num, handle_size); + + /* pop the handle off the stack */ + for (int i = 0; i < handle_size; i++) + { + stack.pop(); + tos--; + } + + /* look up the state to go to from the one popped back to */ + act = get_reduce(((Symbol)stack.peek()).parse_state, lhs_sym_num); + + /* shift to that state */ + lhs_sym.parse_state = act; + lhs_sym.used_by_parser = true; + stack.push(lhs_sym); + tos++; + + if (debug) debug_message("# Goto state #" + act); + + } + /* finally if the entry is zero, we have an error + (shouldn't happen here, but...)*/ + else if (act == 0) + { + report_fatal_error("Syntax error", lhs_sym); + return; + } + } + + + } + + /*-----------------------------------------------------------*/ + + /** Utility function: unpacks parse tables from strings */ + protected static short[][] unpackFromStrings(String[] sa) + { + // Concatanate initialization strings. + StringBuffer sb = new StringBuffer(sa[0]); + for (int i=1; i<sa.length; i++) + sb.append(sa[i]); + int n=0; // location in initialization string + int size1 = (((int)sb.charAt(n))<<16) | ((int)sb.charAt(n+1)); n+=2; + short[][] result = new short[size1][]; + for (int i=0; i<size1; i++) { + int size2 = (((int)sb.charAt(n))<<16) | ((int)sb.charAt(n+1)); n+=2; + result[i] = new short[size2]; + for (int j=0; j<size2; j++) + result[i][j] = (short) (sb.charAt(n++)-2); + } + return result; + } +} + diff --git a/open-nars/java_cup/runtime/virtual_parse_stack.java b/open-nars/java_cup/runtime/virtual_parse_stack.java new file mode 100644 index 0000000000000000000000000000000000000000..a4386aad82213b979b90ecce18b4b43d828ced2c --- /dev/null +++ b/open-nars/java_cup/runtime/virtual_parse_stack.java @@ -0,0 +1,145 @@ + +package java_cup.runtime; + +import java.util.Stack; + +/** This class implements a temporary or "virtual" parse stack that + * replaces the top portion of the actual parse stack (the part that + * has been changed by some set of operations) while maintaining its + * original contents. This data structure is used when the parse needs + * to "parse ahead" to determine if a given error recovery attempt will + * allow the parse to continue far enough to consider it successful. Once + * success or failure of parse ahead is determined the system then + * reverts to the original parse stack (which has not actually been + * modified). Since parse ahead does not execute actions, only parse + * state is maintained on the virtual stack, not full Symbol objects. + * + * @see java_cup.runtime.lr_parser + * @version last updated: 7/3/96 + * @author Frank Flannery + */ + +public class virtual_parse_stack { + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Constructor to build a virtual stack out of a real stack. */ + public virtual_parse_stack(Stack shadowing_stack) throws java.lang.Exception + { + /* sanity check */ + if (shadowing_stack == null) + throw new Exception( + "Internal parser error: attempt to create null virtual stack"); + + /* set up our internals */ + real_stack = shadowing_stack; + vstack = new Stack(); + real_next = 0; + + /* get one element onto the virtual portion of the stack */ + get_from_real(); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The real stack that we shadow. This is accessed when we move off + * the bottom of the virtual portion of the stack, but is always left + * unmodified. + */ + protected Stack real_stack; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Top of stack indicator for where we leave off in the real stack. + * This is measured from top of stack, so 0 would indicate that no + * elements have been "moved" from the real to virtual stack. + */ + protected int real_next; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The virtual top portion of the stack. This stack contains Integer + * objects with state numbers. This stack shadows the top portion + * of the real stack within the area that has been modified (via operations + * on the virtual stack). When this portion of the stack becomes empty we + * transfer elements from the underlying stack onto this stack. + */ + protected Stack vstack; + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Transfer an element from the real to the virtual stack. This assumes + * that the virtual stack is currently empty. + */ + protected void get_from_real() + { + Symbol stack_sym; + + /* don't transfer if the real stack is empty */ + if (real_next >= real_stack.size()) return; + + /* get a copy of the first Symbol we have not transfered */ + stack_sym = (Symbol)real_stack.elementAt(real_stack.size()-1-real_next); + + /* record the transfer */ + real_next++; + + /* put the state number from the Symbol onto the virtual stack */ + vstack.push(new Integer(stack_sym.parse_state)); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Indicate whether the stack is empty. */ + public boolean empty() + { + /* if vstack is empty then we were unable to transfer onto it and + the whole thing is empty. */ + return vstack.empty(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Return value on the top of the stack (without popping it). */ + public int top() throws java.lang.Exception + { + if (vstack.empty()) + throw new Exception( + "Internal parser error: top() called on empty virtual stack"); + + return ((Integer)vstack.peek()).intValue(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Pop the stack. */ + public void pop() throws java.lang.Exception + { + if (vstack.empty()) + throw new Exception( + "Internal parser error: pop from empty virtual stack"); + + /* pop it */ + vstack.pop(); + + /* if we are now empty transfer an element (if there is one) */ + if (vstack.empty()) + get_from_real(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Push a state number onto the stack. */ + public void push(int state_num) + { + vstack.push(new Integer(state_num)); + } + + /*-----------------------------------------------------------*/ + +} diff --git a/open-nars/java_cup/shift_action.java b/open-nars/java_cup/shift_action.java new file mode 100644 index 0000000000000000000000000000000000000000..33fc17a6bf806eb3533619d6056b9ef1139a8aa3 --- /dev/null +++ b/open-nars/java_cup/shift_action.java @@ -0,0 +1,82 @@ + +package java_cup; + +/** This class represents a shift action within the parse table. + * The action simply stores the state that it shifts to and responds + * to queries about its type. + * + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class shift_action extends parse_action { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Simple constructor. + * @param shft_to the state that this action shifts to. + */ + public shift_action(lalr_state shft_to) throws internal_error + { + /* sanity check */ + if (shft_to == null) + throw new internal_error( + "Attempt to create a shift_action to a null state"); + + _shift_to = shft_to; + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The state we shift to. */ + protected lalr_state _shift_to; + + /** The state we shift to. */ + public lalr_state shift_to() {return _shift_to;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Quick access to type of action. */ + public int kind() {return SHIFT;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality test. */ + public boolean equals(shift_action other) + { + return other != null && other.shift_to() == shift_to(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality test. */ + public boolean equals(Object other) + { + if (other instanceof shift_action) + return equals((shift_action)other); + else + return false; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Compute a hash code. */ + public int hashCode() + { + /* use the hash code of the state we are shifting to */ + return shift_to().hashCode(); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() {return "SHIFT(to state " + shift_to().index() + ")";} + + /*-----------------------------------------------------------*/ + +} diff --git a/open-nars/java_cup/simple_calc/Main.java b/open-nars/java_cup/simple_calc/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..21ff5aa580a25c25dd6cd4e7889134363e2d1a09 --- /dev/null +++ b/open-nars/java_cup/simple_calc/Main.java @@ -0,0 +1,32 @@ +// Driver for parser + +package java_cup.simple_calc; + +import java_cup.simple_calc.parser; +import java_cup.runtime.Symbol; + +class Main { + + static boolean do_debug_parse = false; + + static public void main(String[] args) throws java.io.IOException { + + /* create a parsing object */ + parser parser_obj = new parser(new scanner()); + + /* open input files, etc. here */ + Symbol parse_tree = null; + + try { + if (do_debug_parse) + parse_tree = parser_obj.debug_parse(); + else + parse_tree = parser_obj.parse(); + } catch (Exception e) { + /* do cleanup here -- possibly rethrow e */ + } finally { + /* do close out here */ + } + } +} + diff --git a/open-nars/java_cup/simple_calc/parser.cup b/open-nars/java_cup/simple_calc/parser.cup new file mode 100644 index 0000000000000000000000000000000000000000..a88d90079e4544e603d05bb3b40a402dfff8be5a --- /dev/null +++ b/open-nars/java_cup/simple_calc/parser.cup @@ -0,0 +1,55 @@ +// JavaCup specification for a simple expression evaluator (w/ actions) + +package java_cup.simple_calc; + +import java_cup.runtime.*; + +/* Terminals (tokens returned by the scanner). */ +terminal SEMI, PLUS, MINUS, TIMES, DIVIDE, MOD; +terminal UMINUS, LPAREN, RPAREN; +terminal Integer NUMBER; + +/* Non terminals */ +non terminal Object expr_list, expr_part; +non terminal Integer expr; + +/* Precedences */ +precedence left PLUS, MINUS; +precedence left TIMES, DIVIDE, MOD; +precedence left UMINUS, LPAREN; + +/* The grammar */ +expr_list ::= expr_list expr_part + | + expr_part; + +expr_part ::= expr:e + {: System.out.println("= " + e); :} + SEMI + ; + +expr ::= expr:e1 PLUS expr:e2 + {: RESULT = new Integer(e1.intValue() + e2.intValue()); :} + | + expr:e1 MINUS expr:e2 + {: RESULT = new Integer(e1.intValue() - e2.intValue()); :} + | + expr:e1 TIMES expr:e2 + {: RESULT = new Integer(e1.intValue() * e2.intValue()); :} + | + expr:e1 DIVIDE expr:e2 + {: RESULT = new Integer(e1.intValue() / e2.intValue()); :} + | + expr:e1 MOD expr:e2 + {: RESULT = new Integer(e1.intValue() % e2.intValue()); :} + | + NUMBER:n + {: RESULT = n; :} + | + MINUS expr:e + {: RESULT = new Integer(0 - e.intValue()); :} + %prec UMINUS + | + LPAREN expr:e RPAREN + {: RESULT = e; :} + ; diff --git a/open-nars/java_cup/simple_calc/parser.java b/open-nars/java_cup/simple_calc/parser.java new file mode 100644 index 0000000000000000000000000000000000000000..d6003c72087a6a2fbc66e5bc0c33b49bc228b54c --- /dev/null +++ b/open-nars/java_cup/simple_calc/parser.java @@ -0,0 +1,318 @@ + +//---------------------------------------------------- +// The following code was generated by CUP v0.10k +// Sun Jul 25 13:36:02 EDT 1999 +//---------------------------------------------------- + +package java_cup.simple_calc; + +import java_cup.runtime.*; + +/** CUP v0.10k generated parser. + * @version Sun Jul 25 13:36:02 EDT 1999 + */ +public class parser extends java_cup.runtime.lr_parser { + + /** Default constructor. */ + public parser() {super();} + + /** Constructor which sets the default scanner. */ + public parser(java_cup.runtime.Scanner s) {super(s);} + + /** Production table. */ + protected static final short _production_table[][] = + unpackFromStrings(new String[] { + "\000\015\000\002\003\004\000\002\002\004\000\002\003" + + "\003\000\002\006\002\000\002\004\005\000\002\005\005" + + "\000\002\005\005\000\002\005\005\000\002\005\005\000" + + "\002\005\005\000\002\005\003\000\002\005\004\000\002" + + "\005\005" }); + + /** Access to production table. */ + public short[][] production_table() {return _production_table;} + + /** Parse-action table. */ + protected static final short[][] _action_table = + unpackFromStrings(new String[] { + "\000\030\000\010\006\004\013\011\015\005\001\002\000" + + "\010\006\004\013\011\015\005\001\002\000\020\004\ufff7" + + "\005\ufff7\006\ufff7\007\ufff7\010\ufff7\011\ufff7\014\ufff7\001" + + "\002\000\012\002\uffff\006\uffff\013\uffff\015\uffff\001\002" + + "\000\016\004\ufffe\005\016\006\014\007\020\010\017\011" + + "\013\001\002\000\012\002\027\006\004\013\011\015\005" + + "\001\002\000\010\006\004\013\011\015\005\001\002\000" + + "\016\005\016\006\014\007\020\010\017\011\013\014\015" + + "\001\002\000\010\006\004\013\011\015\005\001\002\000" + + "\010\006\004\013\011\015\005\001\002\000\020\004\ufff5" + + "\005\ufff5\006\ufff5\007\ufff5\010\ufff5\011\ufff5\014\ufff5\001" + + "\002\000\010\006\004\013\011\015\005\001\002\000\010" + + "\006\004\013\011\015\005\001\002\000\010\006\004\013" + + "\011\015\005\001\002\000\020\004\ufffa\005\ufffa\006\ufffa" + + "\007\ufffa\010\ufffa\011\ufffa\014\ufffa\001\002\000\020\004" + + "\ufff9\005\ufff9\006\ufff9\007\ufff9\010\ufff9\011\ufff9\014\ufff9" + + "\001\002\000\020\004\ufffc\005\ufffc\006\ufffc\007\020\010" + + "\017\011\013\014\ufffc\001\002\000\020\004\ufffb\005\ufffb" + + "\006\ufffb\007\020\010\017\011\013\014\ufffb\001\002\000" + + "\020\004\ufff8\005\ufff8\006\ufff8\007\ufff8\010\ufff8\011\ufff8" + + "\014\ufff8\001\002\000\012\002\001\006\001\013\001\015" + + "\001\001\002\000\004\002\000\001\002\000\004\004\031" + + "\001\002\000\012\002\ufffd\006\ufffd\013\ufffd\015\ufffd\001" + + "\002\000\020\004\ufff6\005\ufff6\006\ufff6\007\ufff6\010\ufff6" + + "\011\ufff6\014\ufff6\001\002" }); + + /** Access to parse-action table. */ + public short[][] action_table() {return _action_table;} + + /** <code>reduce_goto</code> table. */ + protected static final short[][] _reduce_table = + unpackFromStrings(new String[] { + "\000\030\000\010\003\007\004\005\005\006\001\001\000" + + "\004\005\031\001\001\000\002\001\001\000\002\001\001" + + "\000\004\006\027\001\001\000\006\004\025\005\006\001" + + "\001\000\004\005\011\001\001\000\002\001\001\000\004" + + "\005\024\001\001\000\004\005\023\001\001\000\002\001" + + "\001\000\004\005\022\001\001\000\004\005\021\001\001" + + "\000\004\005\020\001\001\000\002\001\001\000\002\001" + + "\001\000\002\001\001\000\002\001\001\000\002\001\001" + + "\000\002\001\001\000\002\001\001\000\002\001\001\000" + + "\002\001\001\000\002\001\001" }); + + /** Access to <code>reduce_goto</code> table. */ + public short[][] reduce_table() {return _reduce_table;} + + /** Instance of action encapsulation class. */ + protected CUP$parser$actions action_obj; + + /** Action encapsulation object initializer. */ + protected void init_actions() + { + action_obj = new CUP$parser$actions(this); + } + + /** Invoke a user supplied parse action. */ + public java_cup.runtime.Symbol do_action( + int act_num, + java_cup.runtime.lr_parser parser, + java.util.Stack stack, + int top) + throws java.lang.Exception + { + /* call code in generated class */ + return action_obj.CUP$parser$do_action(act_num, parser, stack, top); + } + + /** Indicates start state. */ + public int start_state() {return 0;} + /** Indicates start production. */ + public int start_production() {return 1;} + + /** <code>EOF</code> Symbol index. */ + public int EOF_sym() {return 0;} + + /** <code>error</code> Symbol index. */ + public int error_sym() {return 1;} + +} + +/** Cup generated class to encapsulate user supplied action code.*/ +class CUP$parser$actions { + private final parser parser; + + /** Constructor */ + CUP$parser$actions(parser parser) { + this.parser = parser; + } + + /** Method with the actual generated action code. */ + public final java_cup.runtime.Symbol CUP$parser$do_action( + int CUP$parser$act_num, + java_cup.runtime.lr_parser CUP$parser$parser, + java.util.Stack CUP$parser$stack, + int CUP$parser$top) + throws java.lang.Exception + { + /* Symbol object for return from actions */ + java_cup.runtime.Symbol CUP$parser$result; + + /* select the action based on the action number */ + switch (CUP$parser$act_num) + { + /*. . . . . . . . . . . . . . . . . . . .*/ + case 12: // expr ::= LPAREN expr RPAREN + { + Integer RESULT = null; + int eleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left; + int eright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right; + Integer e = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = e; + CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 11: // expr ::= MINUS expr + { + Integer RESULT = null; + int eleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int eright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + Integer e = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new Integer(0 - e.intValue()); + CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 10: // expr ::= NUMBER + { + Integer RESULT = null; + int nleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int nright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + Integer n = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = n; + CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 9: // expr ::= expr MOD expr + { + Integer RESULT = null; + int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left; + int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right; + Integer e1 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + Integer e2 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new Integer(e1.intValue() % e2.intValue()); + CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 8: // expr ::= expr DIVIDE expr + { + Integer RESULT = null; + int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left; + int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right; + Integer e1 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + Integer e2 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new Integer(e1.intValue() / e2.intValue()); + CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 7: // expr ::= expr TIMES expr + { + Integer RESULT = null; + int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left; + int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right; + Integer e1 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + Integer e2 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new Integer(e1.intValue() * e2.intValue()); + CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 6: // expr ::= expr MINUS expr + { + Integer RESULT = null; + int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left; + int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right; + Integer e1 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + Integer e2 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new Integer(e1.intValue() - e2.intValue()); + CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 5: // expr ::= expr PLUS expr + { + Integer RESULT = null; + int e1left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left; + int e1right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right; + Integer e1 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + int e2left = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int e2right = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + Integer e2 = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + RESULT = new Integer(e1.intValue() + e2.intValue()); + CUP$parser$result = new java_cup.runtime.Symbol(3/*expr*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 4: // expr_part ::= expr NT$0 SEMI + { + Object RESULT = null; + // propagate RESULT from NT$0 + if ( ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value != null ) + RESULT = (Object) ((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + int eleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left; + int eright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right; + Integer e = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value; + + CUP$parser$result = new java_cup.runtime.Symbol(2/*expr_part*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 3: // NT$0 ::= + { + Object RESULT = null; + int eleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left; + int eright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right; + Integer e = (Integer)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-0)).value; + System.out.println("= " + e); + CUP$parser$result = new java_cup.runtime.Symbol(4/*NT$0*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 2: // expr_list ::= expr_part + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(1/*expr_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 1: // $START ::= expr_list EOF + { + Object RESULT = null; + int start_valleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left; + int start_valright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).right; + Object start_val = (Object)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-1)).value; + RESULT = start_val; + CUP$parser$result = new java_cup.runtime.Symbol(0/*$START*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + /* ACCEPT */ + CUP$parser$parser.done_parsing(); + return CUP$parser$result; + + /*. . . . . . . . . . . . . . . . . . . .*/ + case 0: // expr_list ::= expr_list expr_part + { + Object RESULT = null; + + CUP$parser$result = new java_cup.runtime.Symbol(1/*expr_list*/, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-1)).left, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-0)).right, RESULT); + } + return CUP$parser$result; + + /* . . . . . .*/ + default: + throw new Exception( + "Invalid action number found in internal parse table"); + + } + } +} + diff --git a/open-nars/java_cup/simple_calc/scanner.java b/open-nars/java_cup/simple_calc/scanner.java new file mode 100644 index 0000000000000000000000000000000000000000..f8f850acad7431764d212939083c87b31182670a --- /dev/null +++ b/open-nars/java_cup/simple_calc/scanner.java @@ -0,0 +1,63 @@ +// Simple Example Scanner Class + +package java_cup.simple_calc; + +import java_cup.runtime.Symbol; + +public class scanner implements java_cup.runtime.Scanner { + final java.io.InputStream instream; + + public scanner(java.io.InputStream is) throws java.io.IOException { + instream = is; + } + public scanner() throws java.io.IOException { this(System.in); } + + /* single lookahead character */ + protected int next_char = -2; + + /* advance input by one character */ + protected void advance() + throws java.io.IOException + { next_char = instream.read(); } + + /* initialize the scanner */ + private void init() + throws java.io.IOException + { advance(); } + + /* recognize and return the next complete token */ + public Symbol next_token() + throws java.io.IOException + { + if (next_char==-2) init(); // set stuff up first time we are called. + for (;;) + switch (next_char) + { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* parse a decimal integer */ + int i_val = 0; + do { + i_val = i_val * 10 + (next_char - '0'); + advance(); + } while (next_char >= '0' && next_char <= '9'); + return new Symbol(sym.NUMBER, new Integer(i_val)); + + case ';': advance(); return new Symbol(sym.SEMI); + case '+': advance(); return new Symbol(sym.PLUS); + case '-': advance(); return new Symbol(sym.MINUS); + case '*': advance(); return new Symbol(sym.TIMES); + case '/': advance(); return new Symbol(sym.DIVIDE); + case '%': advance(); return new Symbol(sym.MOD); + case '(': advance(); return new Symbol(sym.LPAREN); + case ')': advance(); return new Symbol(sym.RPAREN); + + case -1: return new Symbol(sym.EOF); + + default: + /* in this simple scanner we just ignore everything else */ + advance(); + break; + } + } +}; diff --git a/open-nars/java_cup/simple_calc/sym.java b/open-nars/java_cup/simple_calc/sym.java new file mode 100644 index 0000000000000000000000000000000000000000..2584f2f09d98c08b3ef6df87a1d17576df891d55 --- /dev/null +++ b/open-nars/java_cup/simple_calc/sym.java @@ -0,0 +1,25 @@ + +//---------------------------------------------------- +// The following code was generated by CUP v0.10k +// Sun Jul 25 13:36:02 EDT 1999 +//---------------------------------------------------- + +package java_cup.simple_calc; + +/** CUP generated class containing symbol constants. */ +public class sym { + /* terminals */ + public static final int SEMI = 2; + public static final int EOF = 0; + public static final int DIVIDE = 6; + public static final int NUMBER = 11; + public static final int error = 1; + public static final int UMINUS = 8; + public static final int MINUS = 4; + public static final int TIMES = 5; + public static final int LPAREN = 9; + public static final int RPAREN = 10; + public static final int MOD = 7; + public static final int PLUS = 3; +} + diff --git a/open-nars/java_cup/sym.java b/open-nars/java_cup/sym.java new file mode 100644 index 0000000000000000000000000000000000000000..9810a3d7f6c3aa33edcc39fe3336a90082612055 --- /dev/null +++ b/open-nars/java_cup/sym.java @@ -0,0 +1,43 @@ + +//---------------------------------------------------- +// The following code was generated by CUP v0.10k +// Sun Jul 25 13:35:26 EDT 1999 +//---------------------------------------------------- + +package java_cup; + +/** CUP generated class containing symbol constants. */ +public class sym { + /* terminals */ + public static final int NON = 8; + public static final int NONTERMINAL = 27; + public static final int STAR = 15; + public static final int SEMI = 13; + public static final int CODE = 4; + public static final int EOF = 0; + public static final int NONASSOC = 23; + public static final int LEFT = 21; + public static final int PACKAGE = 2; + public static final int COLON = 17; + public static final int WITH = 11; + public static final int IMPORT = 3; + public static final int error = 1; + public static final int COLON_COLON_EQUALS = 18; + public static final int COMMA = 14; + public static final int DOT = 16; + public static final int SCAN = 10; + public static final int ID = 28; + public static final int INIT = 9; + public static final int PARSER = 6; + public static final int TERMINAL = 7; + public static final int PRECEDENCE = 20; + public static final int LBRACK = 25; + public static final int RBRACK = 26; + public static final int PERCENT_PREC = 24; + public static final int START = 12; + public static final int RIGHT = 22; + public static final int BAR = 19; + public static final int ACTION = 5; + public static final int CODE_STRING = 29; +} + diff --git a/open-nars/java_cup/symbol.java b/open-nars/java_cup/symbol.java new file mode 100644 index 0000000000000000000000000000000000000000..94d8b7d391c79f72d9248dcf3a6322220b71de91 --- /dev/null +++ b/open-nars/java_cup/symbol.java @@ -0,0 +1,107 @@ +package java_cup; + +/** This abstract class serves as the base class for grammar symbols (i.e., + * both terminals and non-terminals). Each symbol has a name string, and + * a string giving the type of object that the symbol will be represented by + * on the runtime parse stack. In addition, each symbol maintains a use count + * in order to detect symbols that are declared but never used, and an index + * number that indicates where it appears in parse tables (index numbers are + * unique within terminals or non terminals, but not across both). + * + * @see java_cup.terminal + * @see java_cup.non_terminal + * @version last updated: 7/3/96 + * @author Frank Flannery + */ +public abstract class symbol { + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param nm the name of the symbol. + * @param tp a string with the type name. + */ + public symbol(String nm, String tp) + { + /* sanity check */ + if (nm == null) nm = ""; + + /* apply default if no type given */ + if (tp == null) tp = "Object"; + + _name = nm; + _stack_type = tp; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with default type. + * @param nm the name of the symbol. + */ + public symbol(String nm) + { + this(nm, null); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** String for the human readable name of the symbol. */ + protected String _name; + + /** String for the human readable name of the symbol. */ + public String name() {return _name;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** String for the type of object used for the symbol on the parse stack. */ + protected String _stack_type; + + /** String for the type of object used for the symbol on the parse stack. */ + public String stack_type() {return _stack_type;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Count of how many times the symbol appears in productions. */ + protected int _use_count = 0; + + /** Count of how many times the symbol appears in productions. */ + public int use_count() {return _use_count;} + + /** Increment the use count. */ + public void note_use() {_use_count++;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Index of this symbol (terminal or non terminal) in the parse tables. + * Note: indexes are unique among terminals and unique among non terminals, + * however, a terminal may have the same index as a non-terminal, etc. + */ + protected int _index; + + /** Index of this symbol (terminal or non terminal) in the parse tables. + * Note: indexes are unique among terminals and unique among non terminals, + * however, a terminal may have the same index as a non-terminal, etc. + */ + public int index() {return _index;} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Indicate if this is a non-terminal. Here in the base class we + * don't know, so this is abstract. + */ + public abstract boolean is_non_term(); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + return name(); + } + + /*-----------------------------------------------------------*/ + +} diff --git a/open-nars/java_cup/symbol_part.java b/open-nars/java_cup/symbol_part.java new file mode 100644 index 0000000000000000000000000000000000000000..9142b5fce90c8e4f36fd0bbc1e99a27bc537f304 --- /dev/null +++ b/open-nars/java_cup/symbol_part.java @@ -0,0 +1,100 @@ +package java_cup; + +/** This class represents a part of a production which is a symbol (terminal + * or non terminal). This simply maintains a reference to the symbol in + * question. + * + * @see java_cup.production + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class symbol_part extends production_part { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param sym the symbol that this part is made up of. + * @param lab an optional label string for the part. + */ + public symbol_part(symbol sym, String lab) throws internal_error + { + super(lab); + + if (sym == null) + throw new internal_error( + "Attempt to construct a symbol_part with a null symbol"); + _the_symbol = sym; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with no label. + * @param sym the symbol that this part is made up of. + */ + public symbol_part(symbol sym) throws internal_error + { + this(sym,null); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** The symbol that this part is made up of. */ + protected symbol _the_symbol; + + /** The symbol that this part is made up of. */ + public symbol the_symbol() {return _the_symbol;} + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Respond that we are not an action part. */ + public boolean is_action() { return false; } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(symbol_part other) + { + return other != null && super.equals(other) && + the_symbol().equals(other.the_symbol()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof symbol_part)) + return false; + else + return equals((symbol_part)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Produce a hash code. */ + public int hashCode() + { + return super.hashCode() ^ + (the_symbol()==null ? 0 : the_symbol().hashCode()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + if (the_symbol() != null) + return super.toString() + the_symbol(); + else + return super.toString() + "$$MISSING-SYMBOL$$"; + } + + /*-----------------------------------------------------------*/ + +} diff --git a/open-nars/java_cup/symbol_set.java b/open-nars/java_cup/symbol_set.java new file mode 100644 index 0000000000000000000000000000000000000000..a1aec1028891ee9a9abab481ff5a00d0a395642b --- /dev/null +++ b/open-nars/java_cup/symbol_set.java @@ -0,0 +1,231 @@ + +package java_cup; + +import java.util.Hashtable; +import java.util.Enumeration; + +/** This class represents a set of symbols and provides a series of + * set operations to manipulate them. + * + * @see java_cup.symbol + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class symbol_set { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Constructor for an empty set. */ + public symbol_set() { } + + /** Constructor for cloning from another set. + * @param other the set we are cloning from. + */ + public symbol_set(symbol_set other) throws internal_error + { + not_null(other); + _all = (Hashtable)other._all.clone(); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** A hash table to hold the set. Symbols are keyed using their name string. + */ + protected Hashtable _all = new Hashtable(11); + + /** Access to all elements of the set. */ + public Enumeration all() {return _all.elements();} + + /** size of the set */ + public int size() {return _all.size();} + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** Helper function to test for a null object and throw an exception + * if one is found. + * @param obj the object we are testing. + */ + protected void not_null(Object obj) throws internal_error + { + if (obj == null) + throw new internal_error("Null object used in set operation"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if the set contains a particular symbol. + * @param sym the symbol we are looking for. + */ + public boolean contains(symbol sym) {return _all.containsKey(sym.name());} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if this set is an (improper) subset of another. + * @param other the set we are testing against. + */ + public boolean is_subset_of(symbol_set other) throws internal_error + { + not_null(other); + + /* walk down our set and make sure every element is in the other */ + for (Enumeration e = all(); e.hasMoreElements(); ) + if (!other.contains((symbol)e.nextElement())) + return false; + + /* they were all there */ + return true; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if this set is an (improper) superset of another. + * @param other the set we are are testing against. + */ + public boolean is_superset_of(symbol_set other) throws internal_error + { + not_null(other); + return other.is_subset_of(this); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add a single symbol to the set. + * @param sym the symbol we are adding. + * @return true if this changes the set. + */ + public boolean add(symbol sym) throws internal_error + { + Object previous; + + not_null(sym); + + /* put the object in */ + previous = _all.put(sym.name(),sym); + + /* if we had a previous, this is no change */ + return previous == null; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Remove a single symbol if it is in the set. + * @param sym the symbol we are removing. + */ + public void remove(symbol sym) throws internal_error + { + not_null(sym); + _all.remove(sym.name()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add (union) in a complete set. + * @param other the set we are adding in. + * @return true if this changes the set. + */ + public boolean add(symbol_set other) throws internal_error + { + boolean result = false; + + not_null(other); + + /* walk down the other set and do the adds individually */ + for (Enumeration e = other.all(); e.hasMoreElements(); ) + result = add((symbol)e.nextElement()) || result; + + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Remove (set subtract) a complete set. + * @param other the set we are removing. + */ + public void remove(symbol_set other) throws internal_error + { + not_null(other); + + /* walk down the other set and do the removes individually */ + for (Enumeration e = other.all(); e.hasMoreElements(); ) + remove((symbol)e.nextElement()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(symbol_set other) + { + if (other == null || other.size() != size()) return false; + + /* once we know they are the same size, then improper subset does test */ + try { + return is_subset_of(other); + } catch (internal_error e) { + /* can't throw the error (because super class doesn't), so we crash */ + e.crash(); + return false; + } + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof symbol_set)) + return false; + else + return equals((symbol_set)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Compute a hash code. */ + public int hashCode() + { + int result = 0; + int cnt; + Enumeration e; + + /* hash together codes from at most first 5 elements */ + for (e = all(), cnt=0 ; e.hasMoreElements() && cnt<5; cnt++) + result ^= ((symbol)e.nextElement()).hashCode(); + + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + String result; + boolean comma_flag; + + result = "{"; + comma_flag = false; + for (Enumeration e = all(); e.hasMoreElements(); ) + { + if (comma_flag) + result += ", "; + else + comma_flag = true; + + result += ((symbol)e.nextElement()).name(); + } + result += "}"; + + return result; + } + + /*-----------------------------------------------------------*/ + +} + + diff --git a/open-nars/java_cup/terminal.java b/open-nars/java_cup/terminal.java new file mode 100644 index 0000000000000000000000000000000000000000..e1a40aa3de4cfd6f29d7fb6a154a9863cabc3351 --- /dev/null +++ b/open-nars/java_cup/terminal.java @@ -0,0 +1,169 @@ +package java_cup; + +import java_cup.assoc; +import java.util.Hashtable; +import java.util.Enumeration; + +/** This class represents a terminal symbol in the grammar. Each terminal + * has a textual name, an index, and a string which indicates the type of + * object it will be implemented with at runtime (i.e. the class of object + * that will be returned by the scanner and pushed on the parse stack to + * represent it). + * + * @version last updated: 7/3/96 + * @author Frank Flannery + */ +public class terminal extends symbol { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Full constructor. + * @param nm the name of the terminal. + * @param tp the type of the terminal. + */ + public terminal(String nm, String tp, int precedence_side, int precedence_num) + { + /* superclass does most of the work */ + super(nm, tp); + + /* add to set of all terminals and check for duplicates */ + Object conflict = _all.put(nm,this); + if (conflict != null) + // can't throw an execption here because this is used in static + // initializers, so we do a crash instead + // was: + // throw new internal_error("Duplicate terminal (" + nm + ") created"); + (new internal_error("Duplicate terminal (" + nm + ") created")).crash(); + + /* assign a unique index */ + _index = next_index++; + + /* set the precedence */ + _precedence_num = precedence_num; + _precedence_side = precedence_side; + + /* add to by_index set */ + _all_by_index.put(new Integer(_index), this); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor for non-precedented terminal + */ + + public terminal(String nm, String tp) + { + this(nm, tp, assoc.no_prec, -1); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor with default type. + * @param nm the name of the terminal. + */ + public terminal(String nm) + { + this(nm, null); + } + + /*-----------------------------------------------------------*/ + /*------------------- Class Variables ---------------------*/ + /*-----------------------------------------------------------*/ + + private int _precedence_num; + private int _precedence_side; + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + /** Table of all terminals. Elements are stored using name strings as + * the key + */ + protected static Hashtable _all = new Hashtable(); + + /** Access to all terminals. */ + public static Enumeration all() {return _all.elements();} + + /** Lookup a terminal by name string. */ + public static terminal find(String with_name) + { + if (with_name == null) + return null; + else + return (terminal)_all.get(with_name); + } + + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Table of all terminals indexed by their index number. */ + protected static Hashtable _all_by_index = new Hashtable(); + + /** Lookup a terminal by index. */ + public static terminal find(int indx) + { + Integer the_indx = new Integer(indx); + + return (terminal)_all_by_index.get(the_indx); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Total number of terminals. */ + public static int number() {return _all.size();} + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Static counter to assign unique index. */ + protected static int next_index = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Special terminal for end of input. */ + public static final terminal EOF = new terminal("EOF"); + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** special terminal used for error recovery */ + public static final terminal error = new terminal("error"); + + /*-----------------------------------------------------------*/ + /*--- General Methods ---------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Report this symbol as not being a non-terminal. */ + public boolean is_non_term() + { + return false; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to a string. */ + public String toString() + { + return super.toString() + "[" + index() + "]"; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** get the precedence of a terminal */ + public int precedence_num() { + return _precedence_num; + } + public int precedence_side() { + return _precedence_side; + } + + /** set the precedence of a terminal */ + public void set_precedence(int p, int new_prec) { + _precedence_side = p; + _precedence_num = new_prec; + } + + /*-----------------------------------------------------------*/ + +} diff --git a/open-nars/java_cup/terminal_set.java b/open-nars/java_cup/terminal_set.java new file mode 100644 index 0000000000000000000000000000000000000000..e921cb592e9e021a1d450e9561389a0f9f23ba53 --- /dev/null +++ b/open-nars/java_cup/terminal_set.java @@ -0,0 +1,253 @@ + +package java_cup; + +import java.util.BitSet; + +/** A set of terminals implemented as a bitset. + * @version last updated: 11/25/95 + * @author Scott Hudson + */ +public class terminal_set { + + /*-----------------------------------------------------------*/ + /*--- Constructor(s) ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Constructor for an empty set. */ + public terminal_set() + { + /* allocate the bitset at what is probably the right size */ + _elements = new BitSet(terminal.number()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Constructor for cloning from another set. + * @param other the set we are cloning from. + */ + public terminal_set(terminal_set other) + throws internal_error + { + not_null(other); + _elements = (BitSet)other._elements.clone(); + } + + /*-----------------------------------------------------------*/ + /*--- (Access to) Static (Class) Variables ------------------*/ + /*-----------------------------------------------------------*/ + + /** Constant for the empty set. */ + public static final terminal_set EMPTY = new terminal_set(); + + /*-----------------------------------------------------------*/ + /*--- (Access to) Instance Variables ------------------------*/ + /*-----------------------------------------------------------*/ + + /** Bitset to implement the actual set. */ + protected BitSet _elements; + + /*-----------------------------------------------------------*/ + /*--- General Methods ----------------------------------------*/ + /*-----------------------------------------------------------*/ + + /** Helper function to test for a null object and throw an exception if + * one is found. + * @param obj the object we are testing. + */ + protected void not_null(Object obj) throws internal_error + { + if (obj == null) + throw new internal_error("Null object used in set operation"); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if the set is empty. */ + public boolean empty() + { + return equals(EMPTY); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if the set contains a particular terminal. + * @param sym the terminal symbol we are looking for. + */ + public boolean contains(terminal sym) + throws internal_error + { + not_null(sym); + return _elements.get(sym.index()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Given its index determine if the set contains a particular terminal. + * @param indx the index of the terminal in question. + */ + public boolean contains(int indx) + { + return _elements.get(indx); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if this set is an (improper) subset of another. + * @param other the set we are testing against. + */ + public boolean is_subset_of(terminal_set other) + throws internal_error + { + not_null(other); + + /* make a copy of the other set */ + BitSet copy_other = (BitSet)other._elements.clone(); + + /* and or in */ + copy_other.or(_elements); + + /* if it hasn't changed, we were a subset */ + return copy_other.equals(other._elements); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if this set is an (improper) superset of another. + * @param other the set we are testing against. + */ + public boolean is_superset_of(terminal_set other) + throws internal_error + { + not_null(other); + return other.is_subset_of(this); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add a single terminal to the set. + * @param sym the terminal being added. + * @return true if this changes the set. + */ + public boolean add(terminal sym) + throws internal_error + { + boolean result; + + not_null(sym); + + /* see if we already have this */ + result = _elements.get(sym.index()); + + /* if not we add it */ + if (!result) + _elements.set(sym.index()); + + return result; + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Remove a terminal if it is in the set. + * @param sym the terminal being removed. + */ + public void remove(terminal sym) + throws internal_error + { + not_null(sym); + _elements.clear(sym.index()); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Add (union) in a complete set. + * @param other the set being added. + * @return true if this changes the set. + */ + public boolean add(terminal_set other) + throws internal_error + { + not_null(other); + + /* make a copy */ + BitSet copy = (BitSet)_elements.clone(); + + /* or in the other set */ + _elements.or(other._elements); + + /* changed if we are not the same as the copy */ + return !_elements.equals(copy); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Determine if this set intersects another. + * @param other the other set in question. + */ + public boolean intersects(terminal_set other) + throws internal_error + { + not_null(other); + + /* make a copy of the other set */ + BitSet copy = (BitSet)other._elements.clone(); + + /* xor out our values */ + copy.xor(this._elements); + + /* see if its different */ + return !copy.equals(other._elements); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Equality comparison. */ + public boolean equals(terminal_set other) + { + if (other == null) + return false; + else + return _elements.equals(other._elements); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Generic equality comparison. */ + public boolean equals(Object other) + { + if (!(other instanceof terminal_set)) + return false; + else + return equals((terminal_set)other); + } + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Convert to string. */ + public String toString() + { + String result; + boolean comma_flag; + + result = "{"; + comma_flag = false; + for (int t = 0; t < terminal.number(); t++) + { + if (_elements.get(t)) + { + if (comma_flag) + result += ", "; + else + comma_flag = true; + + result += terminal.find(t).name(); + } + } + result += "}"; + + return result; + } + + /*-----------------------------------------------------------*/ + +} + diff --git a/open-nars/java_cup/version.java b/open-nars/java_cup/version.java new file mode 100644 index 0000000000000000000000000000000000000000..06600b595ef6df3ecd638f00147d5a8805d8797a --- /dev/null +++ b/open-nars/java_cup/version.java @@ -0,0 +1,55 @@ + +package java_cup; + +/** This class contains version and authorship information. + * It contains only static data elements and basically just a central + * place to put this kind of information so it can be updated easily + * for each release. + * + * Version numbers used here are broken into 3 parts: major, minor, and + * update, and are written as v<major>.<minor>.<update> (e.g. v0.10a). + * Major numbers will change at the time of major reworking of some + * part of the system. Minor numbers for each public release or + * change big enough to cause incompatibilities. Finally update + * letter will be incremented for small bug fixes and changes that + * probably wouldn't be noticed by a user. + * + * @version last updated: 12/22/97 [CSA] + * @author Frank Flannery + */ + +public class version { + /** The major version number. */ + public static final int major = 0; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The minor version number. */ + public static final int minor = 10; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The update letter. */ + public static final char update = 'k'; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** String for the current version. */ + public static final String version_str = "v" + major + "." + minor + update; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Full title of the system */ + public static final String title_str = "CUP " + version_str; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** Name of the author */ + public static final String author_str = + "Scott E. Hudson, Frank Flannery, and C. Scott Ananian"; + + /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ + + /** The command name normally used to invoke this program */ + public static final String program_name = "java_cup"; +} diff --git a/open-nars/lib/antlr-runtime-3.0.1.jar b/open-nars/lib/antlr-runtime-3.0.1.jar deleted file mode 100644 index b2efb5b6669945c818a71989c49943b18ffcef49..0000000000000000000000000000000000000000 Binary files a/open-nars/lib/antlr-runtime-3.0.1.jar and /dev/null differ diff --git a/open-nars/lib/stringtemplate-3.0.jar b/open-nars/lib/stringtemplate-3.0.jar deleted file mode 100644 index 5efcffce509c7ce466fd6f5c0e5a56ed2ce75e21..0000000000000000000000000000000000000000 Binary files a/open-nars/lib/stringtemplate-3.0.jar and /dev/null differ