Advertisement
logicmoo

Untitled

Mar 29th, 2014
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ZXBasic 86.90 KB | None | 0 0
  1. /**
  2.  * Adding support FOR Inform 6 language.
  3.  *
  4.  * Douglas "logicmoo" Miles 02/2014
  5.  * ===================================================================
  6.  * Added support FOR Java 8 language constructs.
  7.  *
  8.  * Andreas Dangel 01/2014
  9.  * ===================================================================
  10.  * Fix ForStatement TO allow Annotations within the initializer.
  11.  *
  12.  * Andreas Dangel 01/2013
  13.  * ===================================================================
  14.  * Fix wrong consumption of modifiers (e.g. "final") in a for-each LOOP.
  15.  * Check FOR wrong java usage when catching multiple exceptions.
  16.  *
  17.  * Andreas Dangel 12/2012
  18.  * ===================================================================
  19.  * Enhance grammar TO use LocalVariableDeclaration in a for-each LOOP.
  20.  * This enhances the symbol table TO recognize variables declared in such
  21.  * a for-each LOOP.
  22.  *
  23.  * Andreas Dangel 10/2012
  24.  * ===================================================================
  25.  * Fix parser problem #3530124 with generics
  26.  *
  27.  * Modified the grammar, so that the different usages of generics work.
  28.  * Adjusted the rules, that use "super", AS super is no longer a PrimarySuffix.
  29.  * It's now either a ExplicitConstructorInvocation or a PrimaryPrefix.
  30.  * See also test case ParserCornersTest/testParsersCases
  31.  *
  32.  * Andreas Dangel 05/2012
  33.  * ===================================================================
  34.  * Added support FOR Java 7 language constructs
  35.  *
  36.  * Dinesh Bolkensteyn (SonarSource), 10/2011
  37.  * ===================================================================
  38.  * Changed the CastLookahead production TO use 3 lookaheads FOR primitive types AS suggested by Andreas Dangel
  39.  *
  40.  * Brian Remedios 07/2011
  41.  * ===================================================================
  42.  * Added in support FOR assert AS a name using lookaheads
  43.  *
  44.  * Tom Copeland, 09/03
  45.  * ===================================================================
  46.  * Copied OVER the changes made by Andrea Gini AND Marco Savard TO
  47.  * support JDK 1.4 language constructs, i.e., asserts.
  48.  * See the java1_4c.jj distributed in the javacc2.1/examples/JavaGrammers directory.
  49.  * Made numerous other modifications TO support PMD.
  50.  *
  51.  * Tom Copeland, 6/02
  52.  * ===================================================================
  53.  * This file is a modified version of one originally found in the
  54.  * VTransformer Examples directory of JavaCC1_1. It has been
  55.  * modified TO accept Java source CODE FOR Java 1.2. Basically,
  56.  * this means a new key word was added, 'strictfp', and that keyword
  57.  * added TO the appropriate productions AND LOOKAHEADs (where other,
  58.  * similar keywords are listed AS possible choices). This involved
  59.  * changing 11 lines.
  60.  *
  61.  * Some other minor changes were made, which can be found by doing
  62.  * a search on 'DW, 7/99'.
  63.  *
  64.  * The goal of this effort was FOR the grammar TO be able TO parse
  65.  * any legal Java 1.2 source CODE. It does NOT reject all illegal
  66.  * cases, but neither did the original. Plus, when it comes TO
  67.  * the new 'strictfp' keyword, the Java Compiler from Sun (JDK1.2.1)
  68.  * also does NOT reject all illegal cases, AS defined by the
  69.  * "Updates" document found AT
  70.  *       http://java.sun.com/docs/books/jls/strictfp-changes.pdf
  71.  * (see the testcases.txt file FOR details).
  72.  *
  73.  * David Williams, 7/99
  74.  * ===================================================================
  75.  *
  76.  *
  77.  * Copyright (C) 1996, 1997 Sun Microsystems Inc.
  78.  *
  79.  * Use of this file AND the system it is part of is constrained by the
  80.  * file COPYRIGHT in the root directory of this system.  You may, however,
  81.  * make any modifications you wish TO this file.
  82.  *
  83.  * Java files generated by running JavaCC on this file (OR modified versions
  84.  * of this file) may be used in exactly the same manner AS Java files
  85.  * generated from any grammar developed by you.
  86.  *
  87.  * Author: Sriram Sankar
  88.  * Date: 3/5/97
  89.  *
  90.  * This file contains a Java grammar AND actions that implement a front-END.
  91.  */
  92. /*****************************************************************************
  93.  *                                                                           *
  94.  *  This file is part of the BeanShell Java Scripting distribution.          *
  95.  *  Documentation AND updates may be found AT http://www.beanshell.org/      *
  96.  *                                                                           *
  97.  *  Sun Public License Notice:                                               *
  98.  *                                                                           *
  99.  *  The contents of this file are subject TO the Sun Public License Version  *
  100.  *  1.0 (the "License"); you may NOT use this file except in compliance with *
  101.  *  the License. A copy of the License is available AT http://www.sun.com    *
  102.  *                                                                           *
  103.  *  The Original CODE is BeanShell. The Initial Developer of the Original    *
  104.  *  CODE is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright     *
  105.  *  (C) 2000.  All Rights Reserved.                                          *
  106.  *                                                                           *
  107.  *  GNU Public License Notice:                                               *
  108.  *                                                                           *
  109.  *  Alternatively, the contents of this file may be used under the terms of  *
  110.  *  the GNU Lesser General Public License (the "LGPL"), in which case the    *
  111.  *  provisions of LGPL are applicable instead of those above. IF you wish TO *
  112.  *  allow use of your version of this file only under the  terms of the LGPL *
  113.  *  AND NOT TO allow others TO use your version of this file under the SPL,  *
  114.  *  indicate your decision by deleting the provisions above AND replace      *
  115.  *  them with the notice AND other provisions required by the LGPL.  IF you  *
  116.  *  DO NOT delete the provisions above, a recipient may use your version of  *
  117.  *  this file under either the SPL OR the LGPL.                              *
  118.  *                                                                           *
  119.  *  Patrick Niemeyer (pat@pat.net)                                           *
  120.  *  Author of Learning Java, O'Reilly & Associates                           *
  121.  *  http://www.pat.net/~pat/                                                 *
  122.  *                                                                           *
  123.  *****************************************************************************/
  124. options {
  125.     JAVA_UNICODE_ESCAPE=true;
  126.     STATIC=false;
  127.     MULTI=true;
  128.     //NODE_DEFAULT_VOID=true;
  129.     NODE_DEFAULT_VOID=true;
  130.     NODE_SCOPE_HOOK=true;
  131.     NODE_PREFIX="BSH";
  132.     //NODE_PREFIX="";
  133.     DEBUG_PARSER=true;
  134.     /* PRINT grammar debugging info AS we parse
  135.     */
  136.     /* PRINT detailed lookahead debugging info
  137.     DEBUG_LOOKAHEAD=true;
  138.     */
  139.     //DEBUG_TOKEN_MANAGER = true;
  140.     //DEBUG_LOOKAHEAD=true;
  141.     // This breaks something FOR interactive use on the command line,
  142.     // but may be useful in non-interactive use.
  143.     //CACHE_TOKENS=true;
  144. }
  145.  
  146. PARSER_BEGIN(Parser)
  147. package bsh;
  148.  
  149. import java.io.*;
  150. import java.util.*;
  151.  
  152. /**
  153.     This is the BeanShell parser.  It is used internally by the Interpreter
  154.     class (which is probably what you are looking FOR).  The parser knows
  155.     only how TO parse the structure of the language, it does NOT understand
  156.     names, commands, etc.
  157.     <p>
  158.     You can use the Parser from the command line TO DO basic structural
  159.     validation of BeanShell files without actually executing them. e.g.
  160.     <code><pre>
  161.         java bsh.Parser [ -p ] file [ file ] [ ... ]
  162.     </pre></code>
  163.     <p>
  164.     The -p option causes the abstract syntax TO be printed.
  165.     <p>
  166.  
  167.     From CODE you'd use the Parser like this:
  168.     <p
  169.     <code><pre>
  170.         Parser parser = new Parser(in);
  171.         WHILE( !(eof=parser.Line()) ) {
  172.             SimpleNode node = parser.popNode();
  173.             // use the node, etc. (See bsh.BSH* classes)
  174.         }
  175.     </pre></code>
  176. */
  177. public class Parser
  178. {
  179.  
  180.     @Override public STRING toString() {
  181.         Token errortok = token;
  182.         INT line = errortok.beginLine, column = errortok.beginColumn;
  183.         STRING mess = (errortok.kind == 0 ? tokenImage[0] : errortok.image);
  184.         RETURN "Parser at line " + line + ", column " + column + " : t='" + mess + "' mgr=" + token_source;
  185.     }
  186.     public java.util.Stack pushableLexicalStateStack = new java.util.Stack();
  187.     public boolean  isAllowingI6 = false;
  188.     public boolean  isParsingI6 = false;
  189.       public boolean allowI6()
  190.       {
  191.             RETURN isAllowingI6||isParsingI6;  
  192.       }
  193.  
  194.       public boolean isParsingI6()
  195.       {
  196.             RETURN isParsingI6;
  197.       }
  198.     public Parser(java.io.Reader stream, boolean interactive) {
  199.       this(stream);
  200.       jj_input_stream.setInteractive(interactive);
  201.     }
  202.    
  203.  
  204.   private INT jdkVersion = 5;
  205.  
  206.   public void setJdkVersion(INT jdkVersion) {
  207.    this.jdkVersion = jdkVersion;
  208.   }
  209.  
  210.   private void throwParseException(STRING message) {
  211.     INT line = -1;
  212.     INT col = -1;
  213.     IF (jj_lastpos != null) {
  214.       line = jj_lastpos.beginLine;
  215.       col = jj_lastpos.beginColumn;
  216.     }
  217.     //throw new ParseException("Line " + line + ", Column " + col + ": " + message);
  218.   }
  219.  
  220.   private void checkForBadAssertUsage(STRING in, STRING usage) {
  221.     IF (jdkVersion > 3 && in.equals("assert")) {
  222.       throwParseException("Can't use 'assert' as " + usage + " when running in JDK 1.4 mode!");
  223.     }
  224.   }
  225.  
  226.   private void checkForBadStaticImportUsage() {
  227.     IF (jdkVersion < 5) {
  228.       throwParseException("Can't use static imports when running in JDK 1.4 mode!");
  229.     }
  230.   }
  231.  
  232.   private void checkForBadAnnotationUsage() {
  233.     IF (jdkVersion < 5) {
  234.       throwParseException("Can't use annotations when running in JDK 1.4 mode!");
  235.     }
  236.   }
  237.  
  238.   private void checkForBadGenericsUsage() {
  239.     IF (jdkVersion < 5) {
  240.       throwParseException("Can't use generics unless running in JDK 1.5 mode!");
  241.     }
  242.   }
  243.  
  244.   private void checkForBadVariableArgumentsUsage() {
  245.     IF (jdkVersion < 5) {
  246.       throwParseException("Can't use variable arguments (varargs) when running in JDK 1.4 mode!");
  247.     }
  248.   }
  249.  
  250.   private void checkForBadJDK15ForLoopSyntaxArgumentsUsage() {
  251.     IF (jdkVersion < 5) {
  252.       throwParseException("Can't use JDK 1.5 for loop syntax when running in JDK 1.4 mode!");
  253.     }
  254.   }
  255.  
  256.   private void checkForBadEnumUsage(STRING in, STRING usage) {
  257.     IF (jdkVersion >= 5 && in.equals("enum")) {
  258.       throwParseException("Can't use 'enum' as " + usage + " when running in JDK 1.5 mode!");
  259.     }
  260.   }
  261.  
  262.   private void checkForBadHexFloatingPointLiteral() {
  263.     IF (jdkVersion < 5) {
  264.       throwParseException("Can't use hexadecimal floating point literals in pre-JDK 1.5 target");
  265.     }
  266.   }
  267.  
  268.   private void checkForBadNumericalLiteralslUsage(Token token) {
  269.     IF (jdkVersion < 7) {
  270.       IF (token.image.contains("_")) {
  271.         throwParseException("Can't use underscores in numerical literals when running in JDK inferior to 1.7 mode!");
  272.       }
  273.        
  274.       IF (token.image.startsWith("0b") || token.image.startsWith("0B")) {
  275.         throwParseException("Can't use binary numerical literals when running in JDK inferior to 1.7 mode!");  
  276.       }
  277.     }
  278.   }
  279.  
  280.   private void checkForBadDiamondUsage() {
  281.     IF (jdkVersion < 7) {
  282.       throwParseException("Cannot use the diamond generic notation when running in JDK inferior to 1.7 mode!");
  283.     }
  284.   }
  285.  
  286.   private void checkForBadTryWithResourcesUsage() {
  287.     IF (jdkVersion < 7) {
  288.       throwParseException("Cannot use the try-with-resources notation when running in JDK inferior to 1.7 mode!");
  289.     }
  290.   }
  291.  
  292.   private void checkForBadMultipleExceptionsCatching() {
  293.     IF (jdkVersion < 7) {
  294.       throwParseException("Cannot catch multiple exceptions when running in JDK inferior to 1.7 mode!");
  295.     }
  296.   }
  297.  
  298.   private void checkForBadLambdaUsage() {
  299.     IF (jdkVersion < 8) {
  300.       throwParseException("Cannot use lambda expressions when running in JDK inferior to 1.8 mode!");
  301.     }
  302.   }
  303.   private void checkForBadMethodReferenceUsage() {
  304.     IF (jdkVersion < 8) {
  305.       throwParseException("Cannot use method references when running in JDK inferior to 1.8 mode!");
  306.     }
  307.   }
  308.   private void checkForBadDefaultImplementationUsage() {
  309.     IF (jdkVersion < 8) {
  310.       throwParseException("Cannot use default implementations in interfaces when running in JDK inferior to 1.8 mode!");
  311.     }
  312.   }
  313.   private void checkForBadIntersectionTypesInCasts() {
  314.     IF (jdkVersion < 8) {
  315.       throwParseException("Cannot use intersection types in casts when running in JDK inferior to 1.8 mode!");
  316.     }
  317.   }
  318.   private void checkForBadTypeAnnotations() {
  319.     IF (jdkVersion < 8) {
  320.       throwParseException("Cannot use type annotations when running in JDK inferior to 1.8 mode!");
  321.     }
  322.   }
  323.  
  324.   private void setText(SimpleNode n, Token t) {
  325.     n.setText(t.image);
  326. }
  327.  
  328.   public boolean notInside(STRING s) {
  329.          Interpreter.notImplemented();
  330.     RETURN true;
  331.   }
  332.  
  333.   public boolean isInside(STRING s) {
  334.     RETURN !notInside(s);
  335.   }
  336.  
  337.  
  338.   // This is a semantic LOOKAHEAD TO determine IF we're dealing with an assert
  339.   // Note that this can't be replaced with a syntactic lookahead
  340.   // since "assert" isn't a string literal token
  341.   private boolean isNextTokenAnAssert() {
  342.     boolean res = getToken(1).image.equals("assert");
  343.     IF (res && jdkVersion <= 3 && getToken(2).image.equals("(")) {
  344.      res = false;
  345.     }
  346.     RETURN res;
  347.   }
  348.  
  349.  
  350.   private boolean isPrevousTokenStartOfLine() {
  351.     boolean res = getToken(1).image.equals("assert");
  352.     IF (res && jdkVersion <= 3 && getToken(2).image.equals("(")) {
  353.      res = false;
  354.     }
  355.     RETURN res;
  356.   }
  357.  
  358.   private boolean isPrecededByComment(Token tok) {
  359.       boolean res = false;
  360.       WHILE (!res && tok.specialToken != null) {
  361.           tok = tok.specialToken;
  362.           res = tok.kind == ( SINGLE_LINE_COMMENT) ||
  363.                 tok.kind == ( FORMAL_COMMENT) ||
  364.                 tok.kind == ( MULTI_LINE_COMMENT);
  365.       }
  366.       RETURN res;
  367.   }
  368.  
  369.   private boolean isPrecededBy(Token tok ,Token pretok) {
  370.       boolean res = false;
  371.       WHILE (!res && tok.specialToken != null) {
  372.           tok = tok.specialToken;
  373.           res = tok.kind == ( SINGLE_LINE_COMMENT) ||
  374.                 tok.kind == ( FORMAL_COMMENT) ||
  375.                 tok.kind == ( MULTI_LINE_COMMENT);
  376.       }
  377.       RETURN res;
  378.   }
  379.  
  380.   public Map<INTEGER, String> getSuppressMap() {
  381.     RETURN token_source.getSuppressMap();
  382.   }
  383.  
  384.   public void setSuppressMarker(STRING marker) {
  385.     token_source.setSuppressMarker(marker);
  386.   }
  387.  
  388.    
  389.     public STRING currentTemplateName() {
  390.          Interpreter.notImplemented();
  391.         RETURN currentTemplateName;
  392.     }  
  393.  
  394.     public JavaCharStream getInputStream() {
  395.         RETURN token_source.getInputStream();
  396.     }
  397.        
  398.    
  399.     public Token curtoken() {
  400.         RETURN token;
  401.     }
  402.  
  403.     //boolean trace_enabled;
  404.           /**
  405.          * @RETURN the trace_enabled
  406.          */
  407.         public boolean isTraceEnabled() {
  408.             RETURN trace_enabled;
  409.         }
  410.        
  411.         /**
  412.          * @param trace_enabled the trace_enabled TO set
  413.          */
  414.         public void setTrace(boolean tf) {
  415.             this.trace_enabled = tf;
  416.         }
  417.  
  418.     /**
  419.      * Name of current template we are parsing. Passed TO us in parse()
  420.      */
  421.     public STRING currentTemplateName = "";
  422.  
  423.  
  424.     boolean retainComments = false;
  425.    
  426.     public void setRetainComments( boolean b ) {
  427.         retainComments = b;
  428.     }
  429.  
  430.         void jjtreeOpenNodeScope(Node n) {
  431.             AbstractTokenManager.jjtreeOpenNodeScope(this);
  432.            
  433.             ((SimpleNode)n).setFirstToken( getToken(1));
  434.         }
  435.  
  436.         void jjtreeCloseNodeScope(Node n) {
  437.             AbstractTokenManager.jjtreeCloseNodeScope(this);
  438.          
  439.             ((SimpleNode)n).setLastToken( getToken(0));
  440.         }
  441.  
  442.  
  443.     /**
  444.         Re-initialize the input stream AND token source.
  445.     */
  446.     void reInitInput( Reader in ) {
  447.         ReInit(in);
  448.     }
  449.  
  450.    
  451.  
  452.     public SimpleNode popNode()
  453.     {
  454.         IF ( jjtree.nodeArity() > 0)  // number of child nodes
  455.             RETURN (SimpleNode)jjtree.popNode();
  456.         ELSE
  457.             RETURN null;
  458.     }
  459.  
  460.     /**
  461.         Explicitly re-initialize just the token reader.
  462.         This seems TO be necessary TO avoid certain looping errors when
  463.         reading bogus input.  See Interpreter.
  464.     */
  465.     public void reInitTokenInput( Reader in ) {
  466.         JavaCharStream jj_input_stream = (JavaCharStream) token_source.getInputStream();
  467.         jj_input_stream.ReInit( in,
  468.             jj_input_stream.getEndLine(),
  469.             jj_input_stream.getEndColumn() );
  470.     }
  471.  
  472.     public static void main( STRING [] args )
  473.         throws IOException, ParseException
  474.     {
  475.         boolean PRINT = false;
  476.         INT i=0;
  477.         IF ( args[0].equals("-p") ) {
  478.             i++;
  479.             PRINT=true;
  480.         }
  481.         FOR(; i< args.length; i++) {
  482.             Reader in = new FileReader(args[i]);
  483.             Parser parser = new Parser(in, true);
  484.             parser.setRetainComments(true);
  485.             WHILE( !parser.isEOF()/*eof*/ )
  486.                 IF ( PRINT )
  487.                     System.out.println( parser.popNode() );
  488.         }
  489.     }
  490.  
  491.     /**
  492.         Lookahead FOR the enhanced FOR statement.  
  493.         Expect "for" "(" AND THEN see whether we hit ":" OR a ";" first.
  494.     */
  495.     public boolean isRegularForStatement()
  496.     {
  497.         INT curTok = 1;
  498.         Token tok;
  499.         tok = getToken(curTok++);
  500.         IF ( tok.kind != FOR ) RETURN false;
  501.         tok = getToken(curTok++);
  502.         IF ( tok.kind != LPAREN ) RETURN false;
  503.         WHILE (true)
  504.         {
  505.             tok = getToken(curTok++);
  506.             switch (tok.kind) {
  507.                 case COLON:
  508.                     RETURN false;
  509.                 case SEMICOLON:
  510.                     RETURN true;
  511.                 case EOF:
  512.                     RETURN false;
  513.             }
  514.         }
  515.     }
  516.  
  517.     /**
  518.         Generate a ParseException with the specified message, pointing TO the
  519.         current token.
  520.         The auto-generated Parser.generateParseException() method does NOT
  521.         provide line number info, therefore we DO this.
  522.     */
  523.     public ParseException createParseException( STRING message )
  524.     {
  525.         Token errortok = token;
  526.         INT line = errortok.beginLine, column = errortok.beginColumn;
  527.         STRING mess = (errortok.kind== 0 ? tokenImage[0] : errortok.image);
  528.         RETURN new ParseException( "Parse error at line " + line
  529.             + ", column " + column + " : " + message );
  530.     }
  531.  
  532.  
  533.  
  534.       private boolean isEOF() throws ParseException {
  535.          Interpreter.notImplemented();
  536.         RETURN Line();     
  537.     }
  538.     INT PushLexicalState(INT newState)
  539.     {
  540.       IF(true) RETURN newState;
  541.         RETURN token_source.PushLexicalState(newState);
  542.     }
  543.     INT PopLexicalState(INT newState)
  544.     {
  545.       IF(true) RETURN newState;
  546.         RETURN token_source.PopLexicalState(newState);
  547.     }
  548.  
  549.      private void SetState(INT state) {
  550.           IF (state != token_source.curLexState) {
  551.             Token root = new Token(), last=root;
  552.             root.NEXT = null;
  553.        
  554.             // First, we build a list of tokens TO push back, in backwards order
  555.             WHILE (token.NEXT != null) {
  556.               Token t = token;
  557.               // Find the token whose token.NEXT is the last in the chain
  558.               WHILE (t.NEXT != null && t.NEXT.NEXT != null)
  559.                 t = t.NEXT;
  560.        
  561.               // put it AT the END of the new chain
  562.               last.NEXT = t.NEXT;
  563.               last = t.NEXT;
  564.        
  565.               // IF there are special tokens, these GO before the regular tokens,
  566.               // so we want TO push them back onto the input stream in the order
  567.               // we find them along the specialToken chain.
  568.        
  569.               IF (t.NEXT.specialToken != null) {
  570.                 Token tt=t.NEXT.specialToken;
  571.                 WHILE (tt != null) {
  572.                   last.NEXT = tt;
  573.                   last = tt;
  574.                   tt.NEXT = null;
  575.                   tt = tt.specialToken;
  576.                 }
  577.               }
  578.               t.NEXT = null;
  579.             };
  580.        
  581.             WHILE (root.NEXT != null) {
  582.               token_source.backup(root.NEXT.image.length());
  583.               root.NEXT = root.NEXT.NEXT;
  584.             }
  585.             jj_ntk = -1;
  586.             token_source.SwitchToLex(state);
  587.           }
  588.         }
  589. }
  590. PARSER_END(Parser)
  591. TOKEN_MGR_DECLS :
  592. {
  593.  
  594.  
  595.    // public class ParserTokenManager extends bsh.AbstractTokenManager implements ParserConstants {
  596.     private STRING suppressMarker;
  597.    static INT beginLine;
  598.    static INT beginCol;
  599.    static boolean lineDirective = false;
  600.    static STRING noSkip = null;
  601.  
  602.  {
  603.     defaultLexState = JAVA;
  604.  }
  605.  
  606.  
  607.     @Override public STRING toString() {
  608.         // TODO Auto-generated method stub
  609.         RETURN getClass().getName() + ": state=" + lexStateNames[curLexState];
  610.     }
  611.  
  612.     public JavaCharStream getInputStream() {
  613.         RETURN input_stream;
  614.     }
  615.  
  616.     static void resetBeginLineCol() {
  617.         Interpreter.notImplemented();
  618.     }
  619.    
  620.    public INT stringSize;
  621.    public INT commentNestingDepth ;
  622.    public java.util.Stack lexicalStateStack = new java.util.Stack();
  623.    public java.util.Stack preprocessorVerbs = new java.util.Stack();
  624.    public STRING currentPPExpression;
  625.  
  626.    void CommonTokenAction(Token token) {
  627.  
  628.     }
  629.  
  630.     private void ifThenElseState(boolean statetf, INT statet, INT statef) {
  631.         IF (statetf) {
  632.             noSkip = null;
  633.             backupToken(1);
  634.             jjnewLexState[jjmatchedKind] = statet;
  635.         } ELSE {
  636.             noSkip = input_stream.GetImage();
  637.             backupToken(1);
  638.             jjnewLexState[jjmatchedKind] = statef;
  639.         }
  640.     }
  641.  
  642.     private void ifIsFirstOnLine(INT state) {
  643.         boolean wasFirst = isFirstOnLine();
  644.         ifThenElseState(wasFirst,state,curLexState);
  645.     }
  646.  
  647.     boolean preprocessTerm(STRING STRING) {
  648.         RETURN AbstractTokenManager.preprocessTerm(STRING, this);
  649.     }
  650.  
  651.     void preprocessExpression(STRING STRING) {
  652.         AbstractTokenManager.preprocessExpression(STRING, this);
  653.     }
  654.  
  655.  
  656.     public boolean isFirstOnLine() {
  657.         RETURN ( (bsh.JavaCharStream)input_stream).isFirstOfLine();
  658.     }
  659.  
  660.     protected List<Comment> comments = new ArrayList<Comment>();
  661.    
  662.  
  663.     // Required by SetState
  664.     void backup(INT n) {    input_stream.backup(n);     }
  665.     void backupToken(INT n) {   ( (bsh.JavaCharStream)input_stream).backupToken(n) ;    }
  666.  
  667.  
  668.     protected Map<INTEGER, String> suppressMap = new HashMap<INTEGER, String>();
  669.   //  protected STRING suppressMarker = PMD.SUPPRESS_MARKER;
  670.  
  671.     // Because the TokenMgrError class does NOT have access TO the TokenManager instance, we
  672.     // cannot store the file name AS an instance field, but must use a static.
  673.     public static void setFileName(STRING fileName) {
  674.     AbstractTokenManager.fileName.set(fileName);
  675.     }
  676.  
  677.     public static STRING getFileName() {
  678.     STRING fileName = AbstractTokenManager.fileName.get();
  679.     RETURN fileName == null ? "(no file name provided)" : fileName;
  680.     }
  681.  
  682.     public void setSuppressMarker(STRING marker) {
  683.     this.suppressMarker = marker;
  684.     }
  685.  
  686.     public Map<INTEGER, String> getSuppressMap() {
  687.     RETURN suppressMap;
  688.     }
  689.     void SkipLexicalActions_THROW(Token matchedToken)
  690.     {
  691.  
  692.     }
  693.      private INT fileDepth = 0;
  694.  
  695.     private INT lparen = 0;
  696.     private INT rparen = 0;
  697.  
  698.     List stateStack = new ArrayList(50);
  699.  
  700.     public boolean debugPrint = true;
  701.  
  702.     private boolean inReference;
  703.     public boolean inDirective;
  704.     private boolean inComment;
  705.     public  boolean inSet;
  706.     INT PushLexicalState(INT newState)
  707.     {
  708.       IF(true) RETURN newState;      
  709.         stateStackPush();
  710.         SwitchToLex(newState);
  711.         RETURN curLexState;
  712.     }
  713.     INT PopLexicalState(INT newState)
  714.     {
  715.       IF(true) RETURN newState;    
  716.         stateStackPop();
  717.         RETURN curLexState;    
  718.     }
  719.     /**
  720.      *  pushes the current state onto the 'state stack',
  721.      *  AND maintains the parens counts
  722.      *  public because we need it in PD & VM handling
  723.      *
  724.      *  @RETURN boolean : success.  It can fail IF the state machine
  725.      *     gets messed up (DO don't mess it up :)
  726.      */
  727.     public boolean stateStackPop()
  728.     {
  729.         ParserState s;
  730.         try
  731.         {
  732.             s = (ParserState) stateStack.remove(stateStack.size() - 1); // stack.pop
  733.         }
  734.         catch(IndexOutOfBoundsException e)
  735.         {
  736.             // empty stack
  737.             lparen=0;
  738.             Interpreter.notImplemented();
  739.             SwitchToLex(defaultLexState);
  740.             RETURN false;
  741.         }
  742.  
  743.         IF( debugPrint )
  744.             System.out.println(
  745.                 " stack pop (" + stateStack.size() + ") : lparen=" +
  746.                     s.lparen +
  747.                         " newstate=" + s.lexstate );
  748.  
  749.         lparen = s.lparen;
  750.         rparen = s.rparen;
  751.  
  752.         SwitchToLex(s.lexstate);
  753.  
  754.         RETURN true;
  755.     }
  756.    
  757.         /** Switch TO specified lex state. */
  758.         public void SwitchToLex(INT lexState)
  759.         {
  760.            IF (lexState == DEFAULT_POP)
  761.            {
  762.                 stateStackPop();
  763.                 RETURN;
  764.            }
  765.            SwitchTo(lexState);
  766.         }
  767.  
  768.     /**
  769.      *  pops a state off the stack, AND restores paren counts
  770.      *
  771.      *  @RETURN boolean : success of operation
  772.      */
  773.     public boolean stateStackPush()
  774.     {
  775.         IF( debugPrint )
  776.             System.out.println(" (" + stateStack.size() + ") pushing cur state : " +
  777.                 curLexState );
  778.  
  779.         ParserState s = new ParserState();
  780.         s.lparen = lparen;
  781.         s.rparen = rparen;
  782.         s.lexstate = curLexState;
  783.  
  784.         lparen = 0;
  785.         stateStack.add(s); // stack.push
  786.  
  787.         RETURN true;
  788.     }
  789.  
  790.     /**
  791.      *  Clears all state variables, resets TO
  792.      *  start values, clears stateStack.  Call
  793.      *  before parsing.
  794.      */
  795.     public void clearStateVars()
  796.     {
  797.         stateStack.clear();
  798.  
  799.         lparen = 0;
  800.         rparen = 0;
  801.         inReference = false;
  802.         inDirective = false;
  803.         inComment = false;
  804.         inSet = false;
  805.  
  806.         RETURN;
  807.     }
  808.  
  809.     /**
  810.      * Holds the state of the parsing process.
  811.      */
  812.     private static class ParserState
  813.     {
  814.         INT lparen;
  815.         INT rparen;
  816.         INT lexstate;
  817.     }
  818.  
  819.  
  820.     /**
  821.      * Holds the state of the parsing process.
  822.      */
  823.     public static class PreprocessorGuards
  824.     {
  825.         INT lparen;
  826.         INT rparen;
  827.         INT lexstate;
  828.     }
  829.  
  830.     /**
  831.      *  handles the dropdown logic when encountering a RPAREN
  832.      */
  833.     private void RPARENHandler()
  834.     {
  835.         /*
  836.          *  Ultimately, we want TO drop down TO the state below
  837.          *  the one that has an open (IF we hit bottom (DEFAULT),
  838.          *  that's fine. It's just text schmoo.
  839.          */
  840.  
  841.         boolean closed = false;
  842.  
  843.         IF (inComment)
  844.             closed = true;
  845.  
  846.         WHILE( !closed )
  847.         {
  848.             /*
  849.              * look AT current state.  IF we haven't seen a lparen
  850.              * in this state THEN we drop a state, because this
  851.              * lparen clearly closes our state
  852.              */
  853.  
  854.             IF( lparen > 0)
  855.             {
  856.                 /*
  857.                  *  IF rparen + 1 == lparen, THEN this state is closed.
  858.                  * Otherwise, increment AND keep parsing
  859.                  */
  860.  
  861.                  IF( lparen == rparen + 1)
  862.                  {
  863.                        stateStackPop();
  864.                  }
  865.                 ELSE
  866.                 {
  867.                     rparen++;
  868.                 }
  869.  
  870.                  closed = true;
  871.             }
  872.             ELSE
  873.             {
  874.                 /*
  875.                  * now, drop a state
  876.                  */
  877.  
  878.                 IF(!stateStackPop())
  879.                     break;
  880.             }
  881.         }
  882.     }
  883. }
  884.  
  885.  
  886. <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE>SKIP :
  887. {
  888.   " "
  889. |
  890.   "\t"
  891. |
  892.   "\f"
  893.   |
  894.  "\r"
  895.   |
  896.  "\n"
  897. |
  898. "!\n"
  899. }
  900.  
  901.  
  902. //<DEFAULT_PP,INFORM6,JAVA,IDENTIFIER_STATE>
  903. <H_PP>SPECIAL_TOKEN :
  904. {
  905.  
  906. /*  <  "/" "/" >: IN_LINE_COMMENT
  907. |
  908.   <  "/" "*"  "*" > : IN_COMMENT
  909. |
  910.   <  "/" "*" > : IN_COMMENT
  911. |
  912.  < "!" ~[] >
  913.  { ifIsFirstOnLine(IN_LINE_COMMENT); }
  914. |*/
  915.   < "#" ([" ", "\t"])* "line" > : LINE_NUMBER
  916. |
  917.    <PP_H_IFDEF:  "#ifdef" >
  918.    {
  919.      preprocessTerm("#ifdef");
  920.    } : PREPROCESSOR_OUTPUT
  921. |
  922.    <PP_H_IFNDEF:  "#ifndef" >
  923.    {
  924.      preprocessTerm("#ifndef");
  925.    } : PREPROCESSOR_OUTPUT
  926. |
  927.    <PP_H_IF:  "#if" >
  928.    {
  929.      preprocessTerm("#if");
  930.    } : PREPROCESSOR_OUTPUT
  931. |
  932.   <PP_H_IFTRUE:  "#iftrue" >
  933.    {
  934.      preprocessTerm("#if");
  935.    } : PREPROCESSOR_OUTPUT
  936. |
  937.   <PP_H_ELSEIF:  "#elseif" >
  938.    {
  939.      preprocessTerm("#elseif");
  940.    } : FINISH_TO_EOL
  941. |   <PP_H_ENDIF:  "#endif"  >
  942.    {
  943.      preprocessTerm("#endif");
  944.    } : FINISH_TO_EOL
  945. |
  946.   <PP_H_IFNOT:  "#ifnot" >
  947.    {
  948.      preprocessTerm("#ifnot");
  949.    } : FINISH_TO_EOL
  950. |
  951.   <START_LINE_NUMBER: "#" ([" ", "\t"])* ["0"-"9"] > { input_stream.backup(1); } : LINE_NUMBER
  952. |
  953.   <  "#" ([" ", "\t"])* "include" >
  954.    {
  955.      preprocessTerm("#include");
  956.    } : PREPROCESSOR_OUTPUT
  957. }
  958.  
  959.  
  960. <PREPROCESSOR_OUTPUT> SPECIAL_TOKEN :
  961. {
  962.   <PREPROCESSOR_EXPRESSION: (~["\n","\r"])* ("\n"|"\r"|"\r\n")? >
  963.   {
  964.     preprocessExpression(matchedToken.image);    
  965.   } : DEFAULT_POP
  966. }
  967.  
  968.  
  969. <LINE_NUMBER> SKIP:
  970. {
  971.    < (["0"-"9"])+ >
  972.    {
  973.      try
  974.      {
  975.         beginLine = INTEGER.parseInt(image.toString());
  976.      }
  977.      catch(NumberFormatException e) { } // Will never come here.
  978.    } : LINE_DIRECTIVE
  979. }
  980.  
  981. <LINE_DIRECTIVE> SKIP:
  982. {
  983.   "\n" : AFTER_LINE_DIRECTIVE
  984. |
  985.   <~[]>
  986. }
  987.  
  988. <AFTER_LINE_DIRECTIVE> SKIP:
  989. {
  990.      
  991.   <~[]>
  992.   {
  993.      input_stream.adjustBeginLineColumn(beginLine, 1);
  994.      input_stream.backup(1);
  995.   } : DEFAULT_POP
  996. }
  997.  
  998. <IN_LINE_COMMENT> SKIP:
  999. {
  1000.    "\n" : DEFAULT_POP
  1001. }
  1002.  
  1003. <IN_LINE_COMMENT> MORE:
  1004. {
  1005.   <~[] >
  1006. }
  1007.  
  1008.  
  1009. <FINISH_TO_EOL>SPECIAL_TOKEN:
  1010. { < FINISH_TO_EOL_TOKEN:  (~["\n","\r"])* ("\n"|"\r"|"\r\n")?  >
  1011.   {
  1012.         comments.add(new SingleLineComment(matchedToken));    
  1013.   } : DEFAULT_POP
  1014. }
  1015.  
  1016.  
  1017. <DEFAULT_POP>MORE :
  1018. {
  1019.   <~[]>:DEFAULT
  1020. }
  1021.  
  1022. <WithinString> TOKEN :
  1023. {
  1024.   <STRLIT: "\""> {System.out.println("Size = " + stringSize);} : DEFAULT_POP
  1025. }
  1026.  
  1027. <WithinString> MORE :
  1028. {
  1029.   <~["\n","\r"]> {stringSize++;}
  1030. }
  1031.  
  1032. /* WHITE SPACE */
  1033. /*
  1034. <DEFAULT,INFORM6,JAVA>SPECIAL_TOKEN :
  1035. {
  1036.   " " | "\t" | "\n" | "\r" | "\f"
  1037. }*/
  1038.  
  1039.  
  1040. <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE>SPECIAL_TOKEN :  /* ! = inform6   #! = beanshell  */
  1041.    { < SINGLE_LINE_COMMENT: ("//"|"#!"|"!-"|"!\n"|"! "|"!%"|"!\r")(~["\n","\r"])* ("\n"|"\r"|"\r\n")? >
  1042.     {      
  1043.     {
  1044.      
  1045.         // IF (isPrecededByComment(t)) { jjtThis.setContainsComment(); }        
  1046.       /*  INT startOfNOPMD = matchedToken.image.indexOf(suppressMarker);
  1047.         IF (startOfNOPMD != -1) {
  1048.             suppressMap.put(matchedToken.beginLine, matchedToken.image.substring(startOfNOPMD + suppressMarker.length()));
  1049.         }*/
  1050.         comments.add(new SingleLineComment(matchedToken));
  1051.     }
  1052.   }
  1053. }
  1054.  
  1055.  
  1056. /* COMMENTS */
  1057.  
  1058. <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE>MORE :
  1059. {
  1060.   <FORMAL_COMENT_START: "/**" ~["/"]> {   AbstractTokenManager.pushLexicalState(curLexState , this);  input_stream.backup(1);
  1061.                       } : IN_FORMAL_COMMENT
  1062. |
  1063.   <  "/*" > {   AbstractTokenManager.pushLexicalState(curLexState , this);
  1064.                     }: IN_MULTI_LINE_COMMENT
  1065. }
  1066.  
  1067. <IN_FORMAL_COMMENT>
  1068. SPECIAL_TOKEN :
  1069. {
  1070.   <FORMAL_COMMENT: "*/" > { comments.add(new FormalComment(matchedToken));
  1071.    AbstractTokenManager.popLexicalState(DEFAULT_POP , this); }
  1072. }
  1073.  
  1074. <IN_MULTI_LINE_COMMENT>
  1075. SPECIAL_TOKEN :
  1076. {
  1077.   <MULTI_LINE_COMMENT: "*/" > { comments.add(new MultiLineComment(matchedToken));
  1078.   AbstractTokenManager.popLexicalState(DEFAULT_POP , this); }
  1079. }
  1080.  
  1081. <IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
  1082. MORE :
  1083. {
  1084.   < ~[] >
  1085. }
  1086.  
  1087. <DEFAULT >SPECIAL_TOKEN :
  1088. {
  1089.   < SO_VERY_SPECIAL : "NOTREALLY001" >
  1090. }
  1091.  
  1092.  
  1093. Token I6KeywordArgSepSpaces()  #void:
  1094. {Token t;}
  1095. {
  1096. ( t=<READ: "read" >| t=<READ_RET: "read_ret" >| t=<READ_AS: "read_as" >)   {
  1097.      RETURN t;
  1098.    }
  1099. }
  1100.  
  1101.  
  1102.  
  1103. Token I6KeywordArgSepComma()#void :
  1104. {Token t;}
  1105. {
  1106.  (
  1107.  t=<PRINT: "print" >
  1108. | t=<PRINT_RET: "print_ret" >
  1109. | t=<PRINT_AS: "print_as" >
  1110. | t=<KW_STYLE: "style" >)
  1111.  {
  1112.    RETURN t;
  1113.  }
  1114. }
  1115.  
  1116.  
  1117. Token I6Token()#void :
  1118. {
  1119. Token t;
  1120. }
  1121. {
  1122. ( t=<TO: "to" >
  1123. | t=<MEMBER_OR: "or" >
  1124. /*| < H_IFDEF: "#ifdef" >
  1125. | < H_IFTRUE: "#iftrue" >
  1126. | < H_ELSEIF: "#elseif" >
  1127. | < H_IFNOT: "#ifnot" >
  1128. | < H_ENDIF: "#endif" >*/
  1129. | t=<H_INCLUDE: ("#include"|"#Include")>
  1130. | t=<INCLUDE: ( "Include" |  "include") >
  1131.  
  1132. | t=<SWITCHES: ("Switches" | "switches" ) >
  1133. | t=<RELEASE: ( "Release" | "release" ) >
  1134. | t=<VERSION: ("Version" | "version") >
  1135. | t=<SERIAL: ("Serial" | "serial" )>
  1136.  
  1137. | t=<ARRAY: ("Array" | "array") >
  1138. | t=<CONSTANT: ("Constant" | "constant" ) >
  1139. | t=<JUMP: "jump" >
  1140. | t=<JSR: "jsr" >
  1141. | t=<H_DEFINE: "#define" >
  1142. | t=<VERB: ("verb" | "Verb") >
  1143. | t=<META: ("meta") >
  1144. | t=<GLOBAL: ("global" | "Global") >
  1145. | t=<KW_DEFAULT: ( "default" | "Default") >
  1146. | t=<RTRUE: "rtrue" >
  1147. | t=<RFALSE: "rfalse" >
  1148. | t=<synthetic: "synthetic" >
  1149. | t=<friend: "friend" >
  1150. | t=I6KeywordArgSepComma()
  1151. | t=I6KeywordArgSepSpaces()
  1152. ) {
  1153.   RETURN t;
  1154. }
  1155. }
  1156.  
  1157. Token JavaKeyword()#void:
  1158. {
  1159. Token t;
  1160. }
  1161. {  
  1162. ( t=< ABSTRACT: "abstract" >
  1163. | t=< BOOLEAN: "boolean" >
  1164. | t=< BYTE: "byte" >
  1165. | t=< CASE: "case" >
  1166. | t=< CATCH: "catch" >
  1167. | t=< CHAR: "char" >
  1168. | t=< CONST: "const" >
  1169. | t=< DOUBLE: "double" >
  1170. | t=< EXTENDS: "extends" >
  1171. | t=< FALSE: "false" >
  1172. | t=< FINAL: "final" >
  1173. | t=< FINALLY: "finally" >
  1174. | t=< FLOAT: "float" >
  1175. | t=< IMPLEMENTS: "implements" >
  1176. | t=< IMPORT: "import" >
  1177. | t=< INT: "int" >
  1178. | t=< INTERFACE: "interface" >
  1179. | t=< LONG: "long" >
  1180. | t=< NATIVE: "native" >
  1181. | t=< NEW: "new" >
  1182. | t=< NULL: "null" >
  1183. | t=< PACKAGE: "package">
  1184. | t=< PRIVATE: "private" >
  1185. | t=< PROTECTED: "protected" >
  1186. | t=< PUBLIC: "public" >
  1187. | t=< SHORT: "short" >
  1188. | t=< STATIC: "static" >
  1189. //| t=< SUPER: "super" >
  1190. //| t=< THIS: "this" >
  1191. | t=< SYNCHRONIZED: "synchronized" >
  1192. | t=< THROWS: "throws" >
  1193. | t=< TRANSIENT: "transient" >
  1194. | t=< TRUE: "true" >
  1195. | t=< VOID: "void" >
  1196. | t=< VOLATILE: "volatile" >
  1197. | t=< STRICTFP: "strictfp" >
  1198. ) {
  1199.   RETURN t;
  1200. }
  1201. }
  1202.  
  1203. Token SharedToken()#void :
  1204. {
  1205. Token t;
  1206. }
  1207. {
  1208. ( t=< BREAK: "break" >
  1209. | t=< CONTINUE: "continue" >
  1210. | t=< DO: "do" >
  1211. | t=< ELSE: "else" >
  1212. | t=< FOR: "for" >
  1213. | t=< GOTO: "goto" >
  1214. | t=< IF: "if" >
  1215. | t=< RETURN: "return" >
  1216. | t=< SWITCH: "switch" >
  1217. | t=< THROW: "throw" >
  1218. | t=< TRY: "try" >
  1219. | t=< UNTIL: "until" >
  1220. | t=< WHILE: "while" >
  1221. ) {
  1222.   RETURN t;
  1223.   }
  1224. }
  1225.  
  1226. /*
  1227. <INFORM6,DEFAULT>TOKEN :
  1228. {
  1229.   < ULXCODE: "@" <LETTER>  (<PART_LETTER>)* >  
  1230. }
  1231. */
  1232.  
  1233. <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE> TOKEN :
  1234. {  
  1235.  /* LITERAL */
  1236.   < INTEGER_LITERAL:
  1237.         <DECIMAL_LITERAL> (["l","L"])?
  1238.       | <HEX_LITERAL> (["l","L"])?
  1239.       | <BINARY_LITERAL> (["l","L"])?
  1240.       | <OCTAL_LITERAL> (["l","L"])?
  1241.   >
  1242. |
  1243.   < #DECIMAL_LITERAL: (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) >
  1244. |
  1245.   < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"]((["0"-"9","a"-"f","A"-"F","_"])*["0"-"9","a"-"f","A"-"F"])?) >
  1246. |
  1247.   < #HEX_LITERAL2: "$" (["0"-"9","a"-"f","A"-"F"]((["0"-"9","a"-"f","A"-"F","_"])*["0"-"9","a"-"f","A"-"F"])?) >
  1248. |
  1249.   < #BINARY_LITERAL: "0" ["b","B"] (["0","1"]((["0","1","_"])*["0","1"])?) >
  1250. |
  1251.   < #OCTAL_LITERAL: "0" (["0"-"7"]((["0"-"7","_"])*["0"-"7"])?) >
  1252. |
  1253.   < FLOATING_POINT_LITERAL:
  1254.         (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) "." (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?)? (<EXPONENT>)? (["f","F","d","D"])?
  1255.       | "." (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) (<EXPONENT>)? (["f","F","d","D"])?
  1256.       | (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) <EXPONENT> (["f","F","d","D"])?
  1257.       | (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) (<EXPONENT>)? ["f","F","d","D"]
  1258.   >
  1259. |
  1260.   < HEX_FLOATING_POINT_LITERAL:
  1261.       (<HEX_LITERAL> (".")? | "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"]((["0"-"9","a"-"f","A"-"F","_"])*["0"-"9","a"-"f","A"-"F"])?)? "." (["0"-"9","a"-"f","A"-"F"]((["0"-"9","a"-"f","A"-"F","_"])*["0"-"9","a"-"f","A"-"F"])?)) ["p","P"] (["+","-"])? (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) (["f","F","d","D"])?
  1262.   >
  1263. |
  1264.   < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) >
  1265. |
  1266.   < CHARACTER_LITERAL:
  1267.       "'"
  1268.       (   (~["'","\\","\n","\r"])
  1269.         | ("\\"
  1270.             ( ["n","t","b","r","f","\\","'","\""]
  1271.             | ["0"-"7"] ( ["0"-"7"] )?
  1272.             | ["0"-"3"] ["0"-"7"] ["0"-"7"]
  1273.             )
  1274.           )
  1275.       )
  1276.       "'"
  1277.   >
  1278. |
  1279.   < STRING_LITERAL:
  1280.       (
  1281.           "\""
  1282.           (   (~["\"","\\"
  1283.           /*,"\n","\r"*/
  1284.                 ])
  1285.             | ("\\"
  1286.                 ( ["n","t","b","r","f","\\","'","\"","\n","\r"]
  1287.                 | ["0"-"7"] ( ["0"-"7"] )?
  1288.                 | ["0"-"3"] ["0"-"7"] ["0"-"7"]
  1289.                 )
  1290.               )
  1291.           )*
  1292.           "\""
  1293.       )
  1294.       |
  1295.       ( "`" ( ~["`"] )* "`" )      
  1296.   >
  1297. |
  1298.   < #LETTER:
  1299.       [  // all chars FOR which Character.isIdentifierStart is true
  1300.          "$",
  1301.          "#", // Inform6
  1302.          "A"-"Z",
  1303.          "_",
  1304.          "a"-"z",
  1305.          "\u00a2"-"\u00a5",
  1306.          "\u00aa",
  1307.          "\u00b5",
  1308.          "\u00ba",
  1309.          "\u00c0"-"\u00d6",
  1310.          "\u00d8"-"\u00f6",
  1311.          "\u00f8"-"\u021f",
  1312.          "\u0222"-"\u0233",
  1313.          "\u0250"-"\u02ad",
  1314.          "\u02b0"-"\u02b8",
  1315.          "\u02bb"-"\u02c1",
  1316.          "\u02d0"-"\u02d1",
  1317.          "\u02e0"-"\u02e4",
  1318.          "\u02ee",
  1319.          "\u037a",
  1320.          "\u0386",
  1321.          "\u0388"-"\u038a",
  1322.          "\u038c",
  1323.          "\u038e"-"\u03a1",
  1324.          "\u03a3"-"\u03ce",
  1325.          "\u03d0"-"\u03d7",
  1326.          "\u03da"-"\u03f3",
  1327.          "\u0400"-"\u0481",
  1328.          "\u048c"-"\u04c4",
  1329.          "\u04c7"-"\u04c8",
  1330.          "\u04cb"-"\u04cc",
  1331.          "\u04d0"-"\u04f5",
  1332.          "\u04f8"-"\u04f9",
  1333.          "\u0531"-"\u0556",
  1334.          "\u0559",
  1335.          "\u0561"-"\u0587",
  1336.          "\u05d0"-"\u05ea",
  1337.          "\u05f0"-"\u05f2",
  1338.          "\u0621"-"\u063a",
  1339.          "\u0640"-"\u064a",
  1340.          "\u0671"-"\u06d3",
  1341.          "\u06d5",
  1342.          "\u06e5"-"\u06e6",
  1343.          "\u06fa"-"\u06fc",
  1344.          "\u0710",
  1345.          "\u0712"-"\u072c",
  1346.          "\u0780"-"\u07a5",
  1347.          "\u0905"-"\u0939",
  1348.          "\u093d",
  1349.          "\u0950",
  1350.          "\u0958"-"\u0961",
  1351.          "\u0985"-"\u098c",
  1352.          "\u098f"-"\u0990",
  1353.          "\u0993"-"\u09a8",
  1354.          "\u09aa"-"\u09b0",
  1355.          "\u09b2",
  1356.          "\u09b6"-"\u09b9",
  1357.          "\u09dc"-"\u09dd",
  1358.          "\u09df"-"\u09e1",
  1359.          "\u09f0"-"\u09f3",
  1360.          "\u0a05"-"\u0a0a",
  1361.          "\u0a0f"-"\u0a10",
  1362.          "\u0a13"-"\u0a28",
  1363.          "\u0a2a"-"\u0a30",
  1364.          "\u0a32"-"\u0a33",
  1365.          "\u0a35"-"\u0a36",
  1366.          "\u0a38"-"\u0a39",
  1367.          "\u0a59"-"\u0a5c",
  1368.          "\u0a5e",
  1369.          "\u0a72"-"\u0a74",
  1370.          "\u0a85"-"\u0a8b",
  1371.          "\u0a8d",
  1372.          "\u0a8f"-"\u0a91",
  1373.          "\u0a93"-"\u0aa8",
  1374.          "\u0aaa"-"\u0ab0",
  1375.          "\u0ab2"-"\u0ab3",
  1376.          "\u0ab5"-"\u0ab9",
  1377.          "\u0abd",
  1378.          "\u0ad0",
  1379.          "\u0ae0",
  1380.          "\u0b05"-"\u0b0c",
  1381.          "\u0b0f"-"\u0b10",
  1382.          "\u0b13"-"\u0b28",
  1383.          "\u0b2a"-"\u0b30",
  1384.          "\u0b32"-"\u0b33",
  1385.          "\u0b36"-"\u0b39",
  1386.          "\u0b3d",
  1387.          "\u0b5c"-"\u0b5d",
  1388.          "\u0b5f"-"\u0b61",
  1389.          "\u0b85"-"\u0b8a",
  1390.          "\u0b8e"-"\u0b90",
  1391.          "\u0b92"-"\u0b95",
  1392.          "\u0b99"-"\u0b9a",
  1393.          "\u0b9c",
  1394.          "\u0b9e"-"\u0b9f",
  1395.          "\u0ba3"-"\u0ba4",
  1396.          "\u0ba8"-"\u0baa",
  1397.          "\u0bae"-"\u0bb5",
  1398.          "\u0bb7"-"\u0bb9",
  1399.          "\u0c05"-"\u0c0c",
  1400.          "\u0c0e"-"\u0c10",
  1401.          "\u0c12"-"\u0c28",
  1402.          "\u0c2a"-"\u0c33",
  1403.          "\u0c35"-"\u0c39",
  1404.          "\u0c60"-"\u0c61",
  1405.          "\u0c85"-"\u0c8c",
  1406.          "\u0c8e"-"\u0c90",
  1407.          "\u0c92"-"\u0ca8",
  1408.          "\u0caa"-"\u0cb3",
  1409.          "\u0cb5"-"\u0cb9",
  1410.          "\u0cde",
  1411.          "\u0ce0"-"\u0ce1",
  1412.          "\u0d05"-"\u0d0c",
  1413.          "\u0d0e"-"\u0d10",
  1414.          "\u0d12"-"\u0d28",
  1415.          "\u0d2a"-"\u0d39",
  1416.          "\u0d60"-"\u0d61",
  1417.          "\u0d85"-"\u0d96",
  1418.          "\u0d9a"-"\u0db1",
  1419.          "\u0db3"-"\u0dbb",
  1420.          "\u0dbd",
  1421.          "\u0dc0"-"\u0dc6",
  1422.          "\u0e01"-"\u0e30",
  1423.          "\u0e32"-"\u0e33",
  1424.          "\u0e3f"-"\u0e46",
  1425.          "\u0e81"-"\u0e82",
  1426.          "\u0e84",
  1427.          "\u0e87"-"\u0e88",
  1428.          "\u0e8a",
  1429.          "\u0e8d",
  1430.          "\u0e94"-"\u0e97",
  1431.          "\u0e99"-"\u0e9f",
  1432.          "\u0ea1"-"\u0ea3",
  1433.          "\u0ea5",
  1434.          "\u0ea7",
  1435.          "\u0eaa"-"\u0eab",
  1436.          "\u0ead"-"\u0eb0",
  1437.          "\u0eb2"-"\u0eb3",
  1438.          "\u0ebd",
  1439.          "\u0ec0"-"\u0ec4",
  1440.          "\u0ec6",
  1441.          "\u0edc"-"\u0edd",
  1442.          "\u0f00",
  1443.          "\u0f40"-"\u0f47",
  1444.          "\u0f49"-"\u0f6a",
  1445.          "\u0f88"-"\u0f8b",
  1446.          "\u1000"-"\u1021",
  1447.          "\u1023"-"\u1027",
  1448.          "\u1029"-"\u102a",
  1449.          "\u1050"-"\u1055",
  1450.          "\u10a0"-"\u10c5",
  1451.          "\u10d0"-"\u10f6",
  1452.          "\u1100"-"\u1159",
  1453.          "\u115f"-"\u11a2",
  1454.          "\u11a8"-"\u11f9",
  1455.          "\u1200"-"\u1206",
  1456.          "\u1208"-"\u1246",
  1457.          "\u1248",
  1458.          "\u124a"-"\u124d",
  1459.          "\u1250"-"\u1256",
  1460.          "\u1258",
  1461.          "\u125a"-"\u125d",
  1462.          "\u1260"-"\u1286",
  1463.          "\u1288",
  1464.          "\u128a"-"\u128d",
  1465.          "\u1290"-"\u12ae",
  1466.          "\u12b0",
  1467.          "\u12b2"-"\u12b5",
  1468.          "\u12b8"-"\u12be",
  1469.          "\u12c0",
  1470.          "\u12c2"-"\u12c5",
  1471.          "\u12c8"-"\u12ce",
  1472.          "\u12d0"-"\u12d6",
  1473.          "\u12d8"-"\u12ee",
  1474.          "\u12f0"-"\u130e",
  1475.          "\u1310",
  1476.          "\u1312"-"\u1315",
  1477.          "\u1318"-"\u131e",
  1478.          "\u1320"-"\u1346",
  1479.          "\u1348"-"\u135a",
  1480.          "\u13a0"-"\u13f4",
  1481.          "\u1401"-"\u166c",
  1482.          "\u166f"-"\u1676",
  1483.          "\u1681"-"\u169a",
  1484.          "\u16a0"-"\u16ea",
  1485.          "\u1780"-"\u17b3",
  1486.          "\u17db",
  1487.          "\u1820"-"\u1877",
  1488.          "\u1880"-"\u18a8",
  1489.          "\u1e00"-"\u1e9b",
  1490.          "\u1ea0"-"\u1ef9",
  1491.          "\u1f00"-"\u1f15",
  1492.          "\u1f18"-"\u1f1d",
  1493.          "\u1f20"-"\u1f45",
  1494.          "\u1f48"-"\u1f4d",
  1495.          "\u1f50"-"\u1f57",
  1496.          "\u1f59",
  1497.          "\u1f5b",
  1498.          "\u1f5d",
  1499.          "\u1f5f"-"\u1f7d",
  1500.          "\u1f80"-"\u1fb4",
  1501.          "\u1fb6"-"\u1fbc",
  1502.          "\u1fbe",
  1503.          "\u1fc2"-"\u1fc4",
  1504.          "\u1fc6"-"\u1fcc",
  1505.          "\u1fd0"-"\u1fd3",
  1506.          "\u1fd6"-"\u1fdb",
  1507.          "\u1fe0"-"\u1fec",
  1508.          "\u1ff2"-"\u1ff4",
  1509.          "\u1ff6"-"\u1ffc",
  1510.          "\u203f"-"\u2040",
  1511.          "\u207f",
  1512.          "\u20a0"-"\u20af",
  1513.          "\u2102",
  1514.          "\u2107",
  1515.          "\u210a"-"\u2113",
  1516.          "\u2115",
  1517.          "\u2119"-"\u211d",
  1518.          "\u2124",
  1519.          "\u2126",
  1520.          "\u2128",
  1521.          "\u212a"-"\u212d",
  1522.          "\u212f"-"\u2131",
  1523.          "\u2133"-"\u2139",
  1524.          "\u2160"-"\u2183",
  1525.          "\u3005"-"\u3007",
  1526.          "\u3021"-"\u3029",
  1527.          "\u3031"-"\u3035",
  1528.          "\u3038"-"\u303a",
  1529.          "\u3041"-"\u3094",
  1530.          "\u309d"-"\u309e",
  1531.          "\u30a1"-"\u30fe",
  1532.          "\u3105"-"\u312c",
  1533.          "\u3131"-"\u318e",
  1534.          "\u31a0"-"\u31b7",
  1535.          "\u3400"-"\u4db5",
  1536.          "\u4e00"-"\u9fa5",
  1537.          "\ua000"-"\ua48c",
  1538.          "\uac00"-"\ud7a3",
  1539.          "\uf900"-"\ufa2d",
  1540.          "\ufb00"-"\ufb06",
  1541.          "\ufb13"-"\ufb17",
  1542.          "\ufb1d",
  1543.          "\ufb1f"-"\ufb28",
  1544.          "\ufb2a"-"\ufb36",
  1545.          "\ufb38"-"\ufb3c",
  1546.          "\ufb3e",
  1547.          "\ufb40"-"\ufb41",
  1548.          "\ufb43"-"\ufb44",
  1549.          "\ufb46"-"\ufbb1",
  1550.          "\ufbd3"-"\ufd3d",
  1551.          "\ufd50"-"\ufd8f",
  1552.          "\ufd92"-"\ufdc7",
  1553.          "\ufdf0"-"\ufdfb",
  1554.          "\ufe33"-"\ufe34",
  1555.          "\ufe4d"-"\ufe4f",
  1556.          "\ufe69",
  1557.          "\ufe70"-"\ufe72",
  1558.          "\ufe74",
  1559.          "\ufe76"-"\ufefc",
  1560.          "\uff04",
  1561.          "\uff21"-"\uff3a",
  1562.          "\uff3f",
  1563.          "\uff41"-"\uff5a",
  1564.          "\uff65"-"\uffbe",
  1565.          "\uffc2"-"\uffc7",
  1566.          "\uffca"-"\uffcf",
  1567.          "\uffd2"-"\uffd7",
  1568.          "\uffda"-"\uffdc",
  1569.          "\uffe0"-"\uffe1",
  1570.          "\uffe5"-"\uffe6"
  1571.       ]
  1572.   >
  1573. |
  1574.   < #PART_LETTER:
  1575.       [  // all chars FOR which Character.isIdentifierPart is true
  1576.          "\u0000"-"\u0008",
  1577.          "\u000e"-"\u001b",
  1578.          "$",
  1579.          "#", // Inform6
  1580.          "0"-"9",
  1581.          "A"-"Z",
  1582.          "_",
  1583.          "a"-"z",
  1584.          "\u007f"-"\u009f",
  1585.          "\u00a2"-"\u00a5",
  1586.          "\u00aa",
  1587.          "\u00b5",
  1588.          "\u00ba",
  1589.          "\u00c0"-"\u00d6",
  1590.          "\u00d8"-"\u00f6",
  1591.          "\u00f8"-"\u021f",
  1592.          "\u0222"-"\u0233",
  1593.          "\u0250"-"\u02ad",
  1594.          "\u02b0"-"\u02b8",
  1595.          "\u02bb"-"\u02c1",
  1596.          "\u02d0"-"\u02d1",
  1597.          "\u02e0"-"\u02e4",
  1598.          "\u02ee",
  1599.          "\u0300"-"\u034e",
  1600.          "\u0360"-"\u0362",
  1601.          "\u037a",
  1602.          "\u0386",
  1603.          "\u0388"-"\u038a",
  1604.          "\u038c",
  1605.          "\u038e"-"\u03a1",
  1606.          "\u03a3"-"\u03ce",
  1607.          "\u03d0"-"\u03d7",
  1608.          "\u03da"-"\u03f3",
  1609.          "\u0400"-"\u0481",
  1610.          "\u0483"-"\u0486",
  1611.          "\u048c"-"\u04c4",
  1612.          "\u04c7"-"\u04c8",
  1613.          "\u04cb"-"\u04cc",
  1614.          "\u04d0"-"\u04f5",
  1615.          "\u04f8"-"\u04f9",
  1616.          "\u0531"-"\u0556",
  1617.          "\u0559",
  1618.          "\u0561"-"\u0587",
  1619.          "\u0591"-"\u05a1",
  1620.          "\u05a3"-"\u05b9",
  1621.          "\u05bb"-"\u05bd",
  1622.          "\u05bf",
  1623.          "\u05c1"-"\u05c2",
  1624.          "\u05c4",
  1625.          "\u05d0"-"\u05ea",
  1626.          "\u05f0"-"\u05f2",
  1627.          "\u0621"-"\u063a",
  1628.          "\u0640"-"\u0655",
  1629.          "\u0660"-"\u0669",
  1630.          "\u0670"-"\u06d3",
  1631.          "\u06d5"-"\u06dc",
  1632.          "\u06df"-"\u06e8",
  1633.          "\u06ea"-"\u06ed",
  1634.          "\u06f0"-"\u06fc",
  1635.          "\u070f"-"\u072c",
  1636.          "\u0730"-"\u074a",
  1637.          "\u0780"-"\u07b0",
  1638.          "\u0901"-"\u0903",
  1639.          "\u0905"-"\u0939",
  1640.          "\u093c"-"\u094d",
  1641.          "\u0950"-"\u0954",
  1642.          "\u0958"-"\u0963",
  1643.          "\u0966"-"\u096f",
  1644.          "\u0981"-"\u0983",
  1645.          "\u0985"-"\u098c",
  1646.          "\u098f"-"\u0990",
  1647.          "\u0993"-"\u09a8",
  1648.          "\u09aa"-"\u09b0",
  1649.          "\u09b2",
  1650.          "\u09b6"-"\u09b9",
  1651.          "\u09bc",
  1652.          "\u09be"-"\u09c4",
  1653.          "\u09c7"-"\u09c8",
  1654.          "\u09cb"-"\u09cd",
  1655.          "\u09d7",
  1656.          "\u09dc"-"\u09dd",
  1657.          "\u09df"-"\u09e3",
  1658.          "\u09e6"-"\u09f3",
  1659.          "\u0a02",
  1660.          "\u0a05"-"\u0a0a",
  1661.          "\u0a0f"-"\u0a10",
  1662.          "\u0a13"-"\u0a28",
  1663.          "\u0a2a"-"\u0a30",
  1664.          "\u0a32"-"\u0a33",
  1665.          "\u0a35"-"\u0a36",
  1666.          "\u0a38"-"\u0a39",
  1667.          "\u0a3c",
  1668.          "\u0a3e"-"\u0a42",
  1669.          "\u0a47"-"\u0a48",
  1670.          "\u0a4b"-"\u0a4d",
  1671.          "\u0a59"-"\u0a5c",
  1672.          "\u0a5e",
  1673.          "\u0a66"-"\u0a74",
  1674.          "\u0a81"-"\u0a83",
  1675.          "\u0a85"-"\u0a8b",
  1676.          "\u0a8d",
  1677.          "\u0a8f"-"\u0a91",
  1678.          "\u0a93"-"\u0aa8",
  1679.          "\u0aaa"-"\u0ab0",
  1680.          "\u0ab2"-"\u0ab3",
  1681.          "\u0ab5"-"\u0ab9",
  1682.          "\u0abc"-"\u0ac5",
  1683.          "\u0ac7"-"\u0ac9",
  1684.          "\u0acb"-"\u0acd",
  1685.          "\u0ad0",
  1686.          "\u0ae0",
  1687.          "\u0ae6"-"\u0aef",
  1688.          "\u0b01"-"\u0b03",
  1689.          "\u0b05"-"\u0b0c",
  1690.          "\u0b0f"-"\u0b10",
  1691.          "\u0b13"-"\u0b28",
  1692.          "\u0b2a"-"\u0b30",
  1693.          "\u0b32"-"\u0b33",
  1694.          "\u0b36"-"\u0b39",
  1695.          "\u0b3c"-"\u0b43",
  1696.          "\u0b47"-"\u0b48",
  1697.          "\u0b4b"-"\u0b4d",
  1698.          "\u0b56"-"\u0b57",
  1699.          "\u0b5c"-"\u0b5d",
  1700.          "\u0b5f"-"\u0b61",
  1701.          "\u0b66"-"\u0b6f",
  1702.          "\u0b82"-"\u0b83",
  1703.          "\u0b85"-"\u0b8a",
  1704.          "\u0b8e"-"\u0b90",
  1705.          "\u0b92"-"\u0b95",
  1706.          "\u0b99"-"\u0b9a",
  1707.          "\u0b9c",
  1708.          "\u0b9e"-"\u0b9f",
  1709.          "\u0ba3"-"\u0ba4",
  1710.          "\u0ba8"-"\u0baa",
  1711.          "\u0bae"-"\u0bb5",
  1712.          "\u0bb7"-"\u0bb9",
  1713.          "\u0bbe"-"\u0bc2",
  1714.          "\u0bc6"-"\u0bc8",
  1715.          "\u0bca"-"\u0bcd",
  1716.          "\u0bd7",
  1717.          "\u0be7"-"\u0bef",
  1718.          "\u0c01"-"\u0c03",
  1719.          "\u0c05"-"\u0c0c",
  1720.          "\u0c0e"-"\u0c10",
  1721.          "\u0c12"-"\u0c28",
  1722.          "\u0c2a"-"\u0c33",
  1723.          "\u0c35"-"\u0c39",
  1724.          "\u0c3e"-"\u0c44",
  1725.          "\u0c46"-"\u0c48",
  1726.          "\u0c4a"-"\u0c4d",
  1727.          "\u0c55"-"\u0c56",
  1728.          "\u0c60"-"\u0c61",
  1729.          "\u0c66"-"\u0c6f",
  1730.          "\u0c82"-"\u0c83",
  1731.          "\u0c85"-"\u0c8c",
  1732.          "\u0c8e"-"\u0c90",
  1733.          "\u0c92"-"\u0ca8",
  1734.          "\u0caa"-"\u0cb3",
  1735.          "\u0cb5"-"\u0cb9",
  1736.          "\u0cbe"-"\u0cc4",
  1737.          "\u0cc6"-"\u0cc8",
  1738.          "\u0cca"-"\u0ccd",
  1739.          "\u0cd5"-"\u0cd6",
  1740.          "\u0cde",
  1741.          "\u0ce0"-"\u0ce1",
  1742.          "\u0ce6"-"\u0cef",
  1743.          "\u0d02"-"\u0d03",
  1744.          "\u0d05"-"\u0d0c",
  1745.          "\u0d0e"-"\u0d10",
  1746.          "\u0d12"-"\u0d28",
  1747.          "\u0d2a"-"\u0d39",
  1748.          "\u0d3e"-"\u0d43",
  1749.          "\u0d46"-"\u0d48",
  1750.          "\u0d4a"-"\u0d4d",
  1751.          "\u0d57",
  1752.          "\u0d60"-"\u0d61",
  1753.          "\u0d66"-"\u0d6f",
  1754.          "\u0d82"-"\u0d83",
  1755.          "\u0d85"-"\u0d96",
  1756.          "\u0d9a"-"\u0db1",
  1757.          "\u0db3"-"\u0dbb",
  1758.          "\u0dbd",
  1759.          "\u0dc0"-"\u0dc6",
  1760.          "\u0dca",
  1761.          "\u0dcf"-"\u0dd4",
  1762.          "\u0dd6",
  1763.          "\u0dd8"-"\u0ddf",
  1764.          "\u0df2"-"\u0df3",
  1765.          "\u0e01"-"\u0e3a",
  1766.          "\u0e3f"-"\u0e4e",
  1767.          "\u0e50"-"\u0e59",
  1768.          "\u0e81"-"\u0e82",
  1769.          "\u0e84",
  1770.          "\u0e87"-"\u0e88",
  1771.          "\u0e8a",
  1772.          "\u0e8d",
  1773.          "\u0e94"-"\u0e97",
  1774.          "\u0e99"-"\u0e9f",
  1775.          "\u0ea1"-"\u0ea3",
  1776.          "\u0ea5",
  1777.          "\u0ea7",
  1778.          "\u0eaa"-"\u0eab",
  1779.          "\u0ead"-"\u0eb9",
  1780.          "\u0ebb"-"\u0ebd",
  1781.          "\u0ec0"-"\u0ec4",
  1782.          "\u0ec6",
  1783.          "\u0ec8"-"\u0ecd",
  1784.          "\u0ed0"-"\u0ed9",
  1785.          "\u0edc"-"\u0edd",
  1786.          "\u0f00",
  1787.          "\u0f18"-"\u0f19",
  1788.          "\u0f20"-"\u0f29",
  1789.          "\u0f35",
  1790.          "\u0f37",
  1791.          "\u0f39",
  1792.          "\u0f3e"-"\u0f47",
  1793.          "\u0f49"-"\u0f6a",
  1794.          "\u0f71"-"\u0f84",
  1795.          "\u0f86"-"\u0f8b",
  1796.          "\u0f90"-"\u0f97",
  1797.          "\u0f99"-"\u0fbc",
  1798.          "\u0fc6",
  1799.          "\u1000"-"\u1021",
  1800.          "\u1023"-"\u1027",
  1801.          "\u1029"-"\u102a",
  1802.          "\u102c"-"\u1032",
  1803.          "\u1036"-"\u1039",
  1804.          "\u1040"-"\u1049",
  1805.          "\u1050"-"\u1059",
  1806.          "\u10a0"-"\u10c5",
  1807.          "\u10d0"-"\u10f6",
  1808.          "\u1100"-"\u1159",
  1809.          "\u115f"-"\u11a2",
  1810.          "\u11a8"-"\u11f9",
  1811.          "\u1200"-"\u1206",
  1812.          "\u1208"-"\u1246",
  1813.          "\u1248",
  1814.          "\u124a"-"\u124d",
  1815.          "\u1250"-"\u1256",
  1816.          "\u1258",
  1817.          "\u125a"-"\u125d",
  1818.          "\u1260"-"\u1286",
  1819.          "\u1288",
  1820.          "\u128a"-"\u128d",
  1821.          "\u1290"-"\u12ae",
  1822.          "\u12b0",
  1823.          "\u12b2"-"\u12b5",
  1824.          "\u12b8"-"\u12be",
  1825.          "\u12c0",
  1826.          "\u12c2"-"\u12c5",
  1827.          "\u12c8"-"\u12ce",
  1828.          "\u12d0"-"\u12d6",
  1829.          "\u12d8"-"\u12ee",
  1830.          "\u12f0"-"\u130e",
  1831.          "\u1310",
  1832.          "\u1312"-"\u1315",
  1833.          "\u1318"-"\u131e",
  1834.          "\u1320"-"\u1346",
  1835.          "\u1348"-"\u135a",
  1836.          "\u1369"-"\u1371",
  1837.          "\u13a0"-"\u13f4",
  1838.          "\u1401"-"\u166c",
  1839.          "\u166f"-"\u1676",
  1840.          "\u1681"-"\u169a",
  1841.          "\u16a0"-"\u16ea",
  1842.          "\u1780"-"\u17d3",
  1843.          "\u17db",
  1844.          "\u17e0"-"\u17e9",
  1845.          "\u180b"-"\u180e",
  1846.          "\u1810"-"\u1819",
  1847.          "\u1820"-"\u1877",
  1848.          "\u1880"-"\u18a9",
  1849.          "\u1e00"-"\u1e9b",
  1850.          "\u1ea0"-"\u1ef9",
  1851.          "\u1f00"-"\u1f15",
  1852.          "\u1f18"-"\u1f1d",
  1853.          "\u1f20"-"\u1f45",
  1854.          "\u1f48"-"\u1f4d",
  1855.          "\u1f50"-"\u1f57",
  1856.          "\u1f59",
  1857.          "\u1f5b",
  1858.          "\u1f5d",
  1859.          "\u1f5f"-"\u1f7d",
  1860.          "\u1f80"-"\u1fb4",
  1861.          "\u1fb6"-"\u1fbc",
  1862.          "\u1fbe",
  1863.          "\u1fc2"-"\u1fc4",
  1864.          "\u1fc6"-"\u1fcc",
  1865.          "\u1fd0"-"\u1fd3",
  1866.          "\u1fd6"-"\u1fdb",
  1867.          "\u1fe0"-"\u1fec",
  1868.          "\u1ff2"-"\u1ff4",
  1869.          "\u1ff6"-"\u1ffc",
  1870.          "\u200c"-"\u200f",
  1871.          "\u202a"-"\u202e",
  1872.          "\u203f"-"\u2040",
  1873.          "\u206a"-"\u206f",
  1874.          "\u207f",
  1875.          "\u20a0"-"\u20af",
  1876.          "\u20d0"-"\u20dc",
  1877.          "\u20e1",
  1878.          "\u2102",
  1879.          "\u2107",
  1880.          "\u210a"-"\u2113",
  1881.          "\u2115",
  1882.          "\u2119"-"\u211d",
  1883.          "\u2124",
  1884.          "\u2126",
  1885.          "\u2128",
  1886.          "\u212a"-"\u212d",
  1887.          "\u212f"-"\u2131",
  1888.          "\u2133"-"\u2139",
  1889.          "\u2160"-"\u2183",
  1890.          "\u3005"-"\u3007",
  1891.          "\u3021"-"\u302f",
  1892.          "\u3031"-"\u3035",
  1893.          "\u3038"-"\u303a",
  1894.          "\u3041"-"\u3094",
  1895.          "\u3099"-"\u309a",
  1896.          "\u309d"-"\u309e",
  1897.          "\u30a1"-"\u30fe",
  1898.          "\u3105"-"\u312c",
  1899.          "\u3131"-"\u318e",
  1900.          "\u31a0"-"\u31b7",
  1901.          "\u3400"-"\u4db5",
  1902.          "\u4e00"-"\u9fa5",
  1903.          "\ua000"-"\ua48c",
  1904.          "\uac00"-"\ud7a3",
  1905.          "\uf900"-"\ufa2d",
  1906.          "\ufb00"-"\ufb06",
  1907.          "\ufb13"-"\ufb17",
  1908.          "\ufb1d"-"\ufb28",
  1909.          "\ufb2a"-"\ufb36",
  1910.          "\ufb38"-"\ufb3c",
  1911.          "\ufb3e",
  1912.          "\ufb40"-"\ufb41",
  1913.          "\ufb43"-"\ufb44",
  1914.          "\ufb46"-"\ufbb1",
  1915.          "\ufbd3"-"\ufd3d",
  1916.          "\ufd50"-"\ufd8f",
  1917.          "\ufd92"-"\ufdc7",
  1918.          "\ufdf0"-"\ufdfb",
  1919.          "\ufe20"-"\ufe23",
  1920.          "\ufe33"-"\ufe34",
  1921.          "\ufe4d"-"\ufe4f",
  1922.          "\ufe69",
  1923.          "\ufe70"-"\ufe72",
  1924.          "\ufe74",
  1925.          "\ufe76"-"\ufefc",
  1926.          "\ufeff",
  1927.          "\uff04",
  1928.          "\uff10"-"\uff19",
  1929.          "\uff21"-"\uff3a",
  1930.          "\uff3f",
  1931.          "\uff41"-"\uff5a",
  1932.          "\uff65"-"\uffbe",
  1933.          "\uffc2"-"\uffc7",
  1934.          "\uffca"-"\uffcf",
  1935.          "\uffd2"-"\uffd7",
  1936.          "\uffda"-"\uffdc",
  1937.          "\uffe0"-"\uffe1",
  1938.          "\uffe5"-"\uffe6",
  1939.          "\ufff9"-"\ufffb"
  1940.       ]
  1941.   >
  1942. }
  1943.  
  1944.  
  1945. <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE>TOKEN :
  1946. {
  1947.  
  1948. /* SEPARATORS */
  1949.  
  1950.   < LPAREN: "(" >
  1951. | < RPAREN: ")" >
  1952. | < LBRACE: "{" >
  1953. | < RBRACE: "}" >
  1954. | < LBRACKET: "[" >
  1955. | < RBRACKET: "]" >
  1956. | < SEMICOLON: ";" >
  1957. | < COMMA: "," >
  1958. | < DOT: "." >
  1959. | < ASSIGN: "=" >
  1960. | < LT: "<" >
  1961. | < BANG: "!" >
  1962. | < TILDE: "~" >
  1963. | < HOOK: "?" >
  1964. | < COLON: ":" >
  1965. | < EQ: "==" >
  1966. | < LE: "<=" >
  1967. | < GE: ">=" >
  1968. | < NE: "!=" >
  1969. | < BOOL_OR: "||" >
  1970. | < BOOL_AND: "&&" >
  1971. | < INCR: "++" >
  1972. | < DECR: "--" >
  1973. | < PLUS: "+" >
  1974. | < MINUS: "-" >
  1975. | < STAR: "*" >
  1976. | < SLASH: "/" >
  1977. | < BIT_AND: "&" >
  1978. | < BIT_OR: "|" >
  1979. | < XOR: "^" >
  1980. | < MOD: "%" >
  1981. | < LSHIFT: "<<" >
  1982. // | < RSIGNEDSHIFT: ">>" >
  1983. //| < RUNSIGNEDSHIFT: ">>>" >
  1984. | < PLUSASSIGN: "+=" >
  1985. | < MINUSASSIGN: "-=" >
  1986. | < STARASSIGN: "*=" >
  1987. | < SLASHASSIGN: "/=" >
  1988. | < ANDASSIGN: "&=" >
  1989. | < ORASSIGN: "|=" >
  1990. | < XORASSIGN: "^=" >
  1991. | < MODASSIGN: "%=" >
  1992. | < NEGASSIGN: "~=" >
  1993. | < LSHIFTASSIGN: "<<=" >
  1994. | < RSIGNEDSHIFTASSIGN: ">>=" >
  1995. | < RUNSIGNEDSHIFTASSIGN: ">>>=" >
  1996. | < ELLIPSIS: "..." >
  1997. /* IDENTIFIERS */
  1998. |
  1999.    < FORMAL_COMMENT_TOKEN:
  2000.         "/**" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"
  2001.     >  
  2002. }
  2003.  
  2004.  
  2005. <INFORM6,DEFAULT> TOKEN:
  2006. {
  2007.  < STRING_LITERAL_SQ:
  2008.       "'"
  2009.       (   (~["'","\\","\n","\r"])
  2010.         | ("\\"
  2011.             ( ["n","t","b","r","f","\\","'","\""]
  2012.             | ["0"-"7"] ( ["0"-"7"] )?
  2013.             | ["0"-"3"] ["0"-"7"] ["0"-"7"]
  2014.             )
  2015.           )
  2016.       )*
  2017.       "'"
  2018.   >
  2019. /* IDENTIFIERS */
  2020. | <ARRAY_IDX16: "->" >
  2021. | <ARRAY_IDX32: "-->" >
  2022. }
  2023.  
  2024.  
  2025. <JAVA, DEFAULT> TOKEN :
  2026. {
  2027. < CLASS: "class" >
  2028. | < INSTANCEOF: "instanceof" >  
  2029. //|  < METHOD_REF: "::" >
  2030. | < AT: "@" >
  2031. }
  2032.  
  2033. <JAVA> TOKEN :
  2034. {  
  2035.  < LAMBDA: "->" >
  2036. | < GTX: "@gt" >
  2037. | < LTX: "@lt" >
  2038. | < LEX: "@lteq" >
  2039. | < GEX: "@gteq" >
  2040. | < BOOL_ORX: "@or" >
  2041. | < BOOL_ANDX: "@and" >
  2042. | < BIT_ANDX: "@bitwise_and" >
  2043. | < BIT_ORX: "@bitwise_or" >
  2044. | < LSHIFTX: "@left_shift" >
  2045. | < RSIGNEDSHIFTX: "@right_shift" >
  2046. | < RUNSIGNEDSHIFTX: "@right_unsigned_shift" >
  2047. | < ANDASSIGNX: "@and_assign" >
  2048. | < ORASSIGNX: "@or_assign" >
  2049. | < LSHIFTASSIGNX: "@left_shift_assign" >
  2050. | < RSIGNEDSHIFTASSIGNX: "@right_shift_assign" >
  2051. | < RUNSIGNEDSHIFTASSIGNX: "@right_unsigned_shift_assign" >
  2052. }
  2053.  
  2054. /* >'s need special attention due to generics syntax. */
  2055. <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE>TOKEN :
  2056. {
  2057.   < RUNSIGNEDSHIFT: ">>>" >
  2058.   {
  2059.      matchedToken.kind = GT;
  2060.      ((Token.GTToken)matchedToken).realKind = RUNSIGNEDSHIFT;
  2061.      input_stream.backup(2);
  2062.      matchedToken.image = ">";
  2063.   }
  2064. | < RSIGNEDSHIFT: ">>" >
  2065.   {
  2066.      matchedToken.kind = GT;
  2067.      ((Token.GTToken)matchedToken).realKind = RSIGNEDSHIFT;
  2068.      input_stream.backup(1);
  2069.      matchedToken.image = ">";
  2070.   }
  2071. | < GT: ">" >
  2072.  }
  2073.  
  2074.  
  2075.  
  2076. /*
  2077.     Thanks TO Sreenivasa Viswanadha FOR suggesting how TO get rid of expensive
  2078.     lookahead here.
  2079. */
  2080. boolean Line() #void:
  2081. {Token t;}
  2082. {
  2083.   <EOF> {
  2084.     Interpreter.debug("End of File!");
  2085.     RETURN true;
  2086.   }
  2087. |
  2088.   BlockStatement() {
  2089.     RETURN false;
  2090.   }
  2091.  
  2092. }
  2093.  
  2094.  
  2095. <DEFAULT >SPECIAL_TOKEN :
  2096. {
  2097.   < SO_VERY_SPECIAL_002 : "NOTREALLY002" >
  2098. }
  2099.  
  2100. /*****************************************
  2101.  * THE JAVA LANGUAGE GRAMMAR STARTS HERE *
  2102.  *****************************************/
  2103.  
  2104. /*
  2105.     Gather modifiers FOR a class, method, OR field.
  2106.     I lookahead is true THEN we are being called AS part of a lookahead AND we
  2107.     should NOT enforce any rules.  Otherwise we validate based on context
  2108.     (field, method, class)
  2109. */
  2110. Modifiers Modifiers( INT context, boolean lookahead ) #void:
  2111. {
  2112.     Modifiers mods = null;
  2113.     PushLexicalState(JAVA);
  2114. }
  2115. {
  2116.   (
  2117.     (
  2118.         "private" | "protected" | "public" | "synchronized" | "final"
  2119.         | "native" | "transient" | "volatile" | "abstract" | "static"
  2120.         | "strictfp" | "friend" | "synthetic"
  2121.     ) {
  2122.         IF ( !lookahead )
  2123.             try {
  2124.                 IF ( mods == null ) mods = new Modifiers();
  2125.                 mods.addModifier( context, getToken(0).image );
  2126.             } catch ( IllegalStateException e ) {
  2127.                 throw createParseException( e.getMessage() );
  2128.             }
  2129.     }
  2130.   )* {
  2131.     PopLexicalState(JAVA);
  2132.     RETURN mods;
  2133.   }
  2134. }
  2135.  
  2136.  
  2137. /**
  2138. */
  2139. void ClassDeclaration() #ClassDeclaration :
  2140. {
  2141.     Modifiers mods;
  2142.     Token name;
  2143.     INT numInterfaces;
  2144.     PushLexicalState(JAVA);
  2145. }
  2146. {
  2147.     mods = Modifiers( Modifiers.CLASS, false )
  2148.     ( "class" | "interface" { jjtThis.isInterface=true; } )
  2149.     name=GETIDENT()
  2150.     [ "extends" AmbiguousName() { jjtThis.extend = true; } ]
  2151.     [ "implements" numInterfaces=NameList()
  2152.         { jjtThis.numInterfaces=numInterfaces; } ]
  2153.     Block()
  2154.     {
  2155.         jjtThis.modifiers = mods;
  2156.         jjtThis.setName(name.image);
  2157.         PopLexicalState(JAVA);
  2158.     }
  2159. }
  2160.  
  2161. void MethodDeclaration() #MethodDeclaration :
  2162. {
  2163.     Token t = null;
  2164.     Modifiers mods;
  2165.     INT count;
  2166.     PushLexicalState(JAVA);
  2167. }
  2168. {
  2169.     mods = Modifiers( Modifiers.METHOD, false ) { jjtThis.modifiers = mods; }
  2170. (
  2171.     LOOKAHEAD( GETIDENT() "(" )
  2172.     t = GETIDENT() { jjtThis.setName(t.image); }
  2173. |
  2174.     ReturnType()
  2175.     t = GETIDENT() { jjtThis.setName(t.image); }
  2176. )
  2177.     FormalParameters()
  2178.     [ "throws" count=NameList() { jjtThis.numThrows=count; } ]
  2179.     ( Block() | ";" )
  2180.     {
  2181.         PopLexicalState(JAVA);
  2182.     }
  2183. }
  2184.  
  2185. void PackageDeclaration () #PackageDeclaration:
  2186. {   PushLexicalState(JAVA);}
  2187. {
  2188.     "package" AmbiguousName()
  2189.     {
  2190.         PopLexicalState(JAVA);
  2191.     }
  2192. }
  2193.  
  2194. void ImportDeclaration() #ImportDeclaration :
  2195. {
  2196.     Token s = null;
  2197.     Token t = null;
  2198.     Token i = null;
  2199.     PushLexicalState(JAVA);
  2200. }
  2201. {
  2202.   LOOKAHEAD( 3 )
  2203.   [ s = "static" ] i=<IMPORT> AmbiguousName() [ t = "." "*" ] ";"
  2204.   {
  2205.         IF ( s != null ) jjtThis.staticImport = true;
  2206.         IF ( t != null ) jjtThis.importPackage = true;
  2207.         PopLexicalState(JAVA)
  2208.   }
  2209.   |
  2210.     // bsh super import statement
  2211.   "import" "*" ";" {
  2212.         jjtThis.superImport = true;
  2213.         PopLexicalState(JAVA);     
  2214.     }
  2215. }
  2216.  
  2217. void VariableDeclarator() #VariableDeclarator :
  2218. {
  2219.     Token t;
  2220. }
  2221. {
  2222.   t=GETIDENT() [ VariableInitializerWithE() ]
  2223.     {
  2224.         jjtThis.setName(t.image);
  2225.     }
  2226. }
  2227.  
  2228. /*
  2229. this originally handled postfix array dimensions...
  2230.  
  2231. void VariableDeclaratorId() #VariableDeclaratorId :
  2232. { Token t; }
  2233. {
  2234.   t=GETIDENT() { jjtThis.setName(t.image); }
  2235.   ( "[" "]" { jjtThis.addUndefinedDimension(); } )*
  2236. }
  2237. */
  2238. void VariableInitializerWithE() #void:
  2239. {
  2240. }
  2241. {
  2242.  LOOKAHEAD("->" | "-->") I6ArrayInit()
  2243. |
  2244.  "=" VariableInitializer()
  2245. }
  2246.  
  2247. void VariableInitializerWithE_Optional() #void:
  2248. {
  2249. }
  2250. {
  2251.  LOOKAHEAD("->" | "-->") I6ArrayInit()
  2252. |
  2253.  ["="] VariableInitializer()
  2254. }
  2255.  
  2256. void VariableInitializer() #void:
  2257. {}
  2258. {
  2259.   ArrayInitializer()
  2260. |
  2261.   Expression()
  2262. }
  2263.  
  2264. void ArrayInitializer() #ArrayInitializer :
  2265. {}
  2266. {
  2267.   "{" [ VariableInitializer()
  2268.         ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}"
  2269. }
  2270.  
  2271. void FormalParameters() #FormalParameters :
  2272. {}
  2273. {
  2274.  
  2275.   "(" [ FormalParameter() ( "," FormalParameter() )* ] ")"
  2276. }
  2277.  
  2278. void FormalParameter() #FormalParameter :
  2279. { Token t; }
  2280. {
  2281.   // added [] TO Type FOR bsh.  Removed [ final ] - is that legal?
  2282.   LOOKAHEAD(2) Type() t=GETIDENT() { jjtThis.setName(t.image); }
  2283. |
  2284.   t=GETIDENT() { jjtThis.setName(t.image); }
  2285. }
  2286.  
  2287.  
  2288. /*
  2289.     Type, name AND expression syntax follows.
  2290. */
  2291. void Type() #Type :
  2292. { }
  2293. {
  2294.     /*
  2295.         The embedded lookahead is (was?) necessary TO disambiguate FOR
  2296.         PrimaryPrefix.  ( )* is a choice point.  It took me a WHILE TO
  2297.         figure out where TO put that.  This stuff is annoying.
  2298.     */
  2299.   (PrimitiveType() | AmbiguousName() )
  2300.     ( LOOKAHEAD(2) "[" "]" { jjtThis.addArrayDimension(); } )*
  2301. }
  2302.  
  2303. /*
  2304.     Originally called ResultType in the grammar
  2305. */
  2306. void ReturnType() #ReturnType :
  2307. { }
  2308. {
  2309.   "void" { jjtThis.isVoid = true; }
  2310. |
  2311.   Type()
  2312. }
  2313.  
  2314. void PrimitiveType() #PrimitiveType :
  2315. { } {
  2316.   "boolean" { jjtThis.type = Boolean.TYPE; }
  2317. | "char" { jjtThis.type =  Character.TYPE; }
  2318. | "byte" { jjtThis.type =  BYTE.TYPE; }
  2319. | "short" { jjtThis.type =  Short.TYPE; }
  2320. | "int" { jjtThis.type =  INTEGER.TYPE; }
  2321. | "long" { jjtThis.type =  LONG.TYPE; }
  2322. | "float" { jjtThis.type =  FLOAT.TYPE; }
  2323. | "double" { jjtThis.type =  Double.TYPE; }
  2324. }
  2325.  
  2326. BSHAmbiguousName AmbiguousName() #AmbiguousName :
  2327. /*
  2328.     A lookahead of 2 is required below since "Name" can be followed by a ".*"
  2329.     when used in the context of an "ImportDeclaration".
  2330. */
  2331. {
  2332.     Token t;
  2333.     StringBuffer s;
  2334. }
  2335. {
  2336.   t = GETIDENT() {
  2337.     s = new StringBuffer(t.image);
  2338.   }
  2339.   ( LOOKAHEAD(2) "." t = GETIDENT() { s.append("."+t.image); } )* {
  2340.     jjtThis.text = s.toString();
  2341.     RETURN jjtThis;
  2342.   }
  2343. }
  2344.  
  2345. INT NameList() #void:
  2346. { INT count = 0; }
  2347. {
  2348.   AmbiguousName() { ++count; } ( "," AmbiguousName() { ++count; } )*
  2349.   { RETURN count; }
  2350. }
  2351.  
  2352. /*
  2353.  * Expression syntax follows.
  2354.  */
  2355. void Expression() #void:
  2356. { }
  2357. {
  2358.     /**
  2359.         SYNTACTIC_LOOKAHEAD
  2360.         Note: the original grammar was cheating here AND we've fixed that,
  2361.         but AT the expense of another syntactic lookahead.
  2362.     */
  2363.   LOOKAHEAD( PrimaryExpression() AssignmentOperator() )
  2364.   Assignment()
  2365. |
  2366.   ConditionalExpression()
  2367. }
  2368.  
  2369. void Assignment() #Assignment :
  2370. { INT op ; }
  2371. {
  2372.   PrimaryExpression()
  2373.     op = AssignmentOperator() { jjtThis.setOperatorKind( op); }
  2374.     // Add this FOR blocks, e.g. foo = { };
  2375.     //( Expression() | Block() )
  2376.     Expression()
  2377. }
  2378.  
  2379. INT AssignmentOperator() #void:
  2380. { Token t; }
  2381. {
  2382.     ( "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "&=" | "^=" | "|=" |
  2383.       "<<=" | "@left_shift_assign" | ">>=" | "@right_shift_assign" |
  2384.       ">>>=" | "@right_unsigned_shift_assign" )
  2385.     {
  2386.         t = getToken(0);
  2387.         RETURN t.kind;
  2388.     }
  2389. }
  2390.  
  2391. void ConditionalExpression() #void:
  2392. { }
  2393. {
  2394.   ConditionalOrExpression() [LOOKAHEAD(3) "?" Expression() ":" ConditionalExpression()
  2395.     #TernaryExpression(3) ]
  2396. }
  2397.  
  2398. void ConditionalOrExpression() #void:
  2399. { Token t=null; }
  2400. {
  2401.   ConditionalAndExpression()
  2402.   (LOOKAHEAD(2) ( t = "||" | t = "@or" )
  2403.     ConditionalAndExpression()
  2404.     { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
  2405. }
  2406.  
  2407. void ConditionalAndExpression() #void:
  2408. { Token t=null; }
  2409. {
  2410.   InclusiveOrExpression()
  2411.   (LOOKAHEAD(2) ( t = "&&" | t = "@and" )
  2412.     InclusiveOrExpression()
  2413.     { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
  2414. }
  2415.  
  2416. void InclusiveOrExpression() #void:
  2417. { Token t=null; }
  2418. {
  2419.   ExclusiveOrExpression()
  2420.   (LOOKAHEAD(2) ( t = "|" | t = "@bitwise_or" )
  2421.     ExclusiveOrExpression()
  2422.     { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
  2423. }
  2424.  
  2425. void ExclusiveOrExpression() #void:
  2426. { Token t=null; }
  2427. {
  2428.   AndExpression() (LOOKAHEAD(2) t="^" AndExpression()
  2429.     { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
  2430. }
  2431.  
  2432. void AndExpression() #void:
  2433. { Token t=null; }
  2434. {
  2435.   EqualityExpression()
  2436.   (LOOKAHEAD(2) ( t = "&" | t = "@bitwise_and" )
  2437.     EqualityExpression()
  2438.     { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
  2439. }
  2440.  
  2441. void EqualityExpression() #void:
  2442. { Token t = null; }
  2443. {
  2444.   InstanceOfExpression() (  LOOKAHEAD(2)  ( t= "==" | t= "!=" ) InstanceOfExpression()
  2445.     { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2)
  2446.   )*
  2447. }
  2448.  
  2449. void InstanceOfExpression() #void:
  2450. { Token t = null; }
  2451. {
  2452.   RelationalExpression()
  2453.   [ LOOKAHEAD(2)  t= "instanceof" Type() { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) ]
  2454. }
  2455.  
  2456. void RelationalExpression() #void:
  2457. { Token t = null; }
  2458. {
  2459.   ShiftExpression()
  2460.   ( ( t = "<" | t = "@lt" | t = ">" | t = "@gt" | t= "~=" | t= "or"  |
  2461.       t = "<=" | t = "@lteq" | t = ">=" | t = "@gteq" )
  2462.   ShiftExpression()
  2463.   { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
  2464. }
  2465.  
  2466. void ShiftExpression() #void:
  2467. { Token t = null; }
  2468. {
  2469.   AdditiveExpression()
  2470.   ( LOOKAHEAD(2) ( t = "<<" | t = "@left_shift" | t = ">>" | t = "@right_shift" |
  2471.       t = ">>>" | t = "@right_unsigned_shift" )
  2472.   AdditiveExpression()
  2473.   { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
  2474. }
  2475.  
  2476. void AdditiveExpression() #void:
  2477. { Token t = null; }
  2478. {
  2479.   MultiplicativeExpression()
  2480.   ( LOOKAHEAD(2) ( t= "+" | t= Inform6Infixes() | t= "-" ) MultiplicativeExpression() { jjtThis.setOperatorKind( t.kind); }
  2481.     #BinaryExpression(2)
  2482.   )*
  2483. }
  2484.  
  2485. void MultiplicativeExpression() #void:
  2486. { Token t = null; }
  2487. {
  2488.   UnaryExpression()
  2489.   ( LOOKAHEAD(2) ( t= "*" | t= "/" | t= "%" ) UnaryExpression() { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
  2490. }
  2491.  
  2492. void UnaryExpression() #void:
  2493. { Token t = null; }
  2494. {
  2495.    LOOKAHEAD(2) ( t="+" | t="-" ) UnaryExpression()  { jjtThis.setOperatorKind( t.kind); } #UnaryExpression(1)
  2496. |
  2497.   PreIncrementExpression()
  2498. |
  2499.   PreDecrementExpression()
  2500. |
  2501.   UnaryExpressionNotPlusMinus()
  2502. }
  2503.  
  2504. void PreIncrementExpression() #void:
  2505. { Token t = null; }
  2506. {
  2507.   t="++" PrimaryExpression()
  2508.     { jjtThis.setOperatorKind( t.kind); } #UnaryExpression(1)
  2509. }
  2510.  
  2511. void PreDecrementExpression() #void:
  2512. { Token t = null; }
  2513. {
  2514.   t="--" PrimaryExpression()
  2515.     { jjtThis.setOperatorKind( t.kind); } #UnaryExpression(1)
  2516. }
  2517.  
  2518. void UnaryExpressionNotPlusMinus() #void:
  2519. { Token t = null; }
  2520. {
  2521.   ( t="~" | t="!" ) UnaryExpression()
  2522.     { jjtThis.setOperatorKind( t.kind); } #UnaryExpression(1)
  2523. |
  2524.     // SYNTACTIC_LOOKAHEAD
  2525.   LOOKAHEAD( CastLookahead() ) CastExpression()
  2526. |
  2527.   PostfixExpression()
  2528. }
  2529.  
  2530. // This production is TO determine lookahead only.
  2531. void CastLookahead() #void: { }
  2532. {
  2533.   LOOKAHEAD(2) "(" PrimitiveType()
  2534. |
  2535. // SYNTACTIC_LOOKAHEAD
  2536.   LOOKAHEAD( "(" AmbiguousName() "[" ) "(" AmbiguousName() "[" "]"
  2537. |
  2538.   "(" AmbiguousName() ")" ( "~" | "!" | "("| /* "this" | "super" | */ "new" | GETIDENT()  | Literal() )
  2539. }
  2540.  
  2541. void PostfixExpression() #void:
  2542. { Token t = null; }
  2543. {
  2544. // SYNTACTIC_LOOKAHEAD
  2545.   LOOKAHEAD( PrimaryExpression() ("++"|"--") )
  2546.   PrimaryExpression()
  2547.       ( t="++" | t="--" ) {
  2548.         jjtThis.setOperatorKind( t.kind); jjtThis.postfix = true; } #UnaryExpression(1)
  2549. |
  2550.   PrimaryExpression()
  2551. }
  2552.  
  2553. void CastExpression() #CastExpression :
  2554. { }
  2555. {
  2556. // SYNTACTIC_LOOKAHEAD
  2557.   LOOKAHEAD( "(" PrimitiveType() ) "(" Type() ")" UnaryExpression()
  2558. |
  2559.   "(" Type() ")" UnaryExpressionNotPlusMinus()
  2560. }
  2561.  
  2562. void PrimaryExpression() #PrimaryExpression : { }
  2563. {
  2564.   PrimaryPrefix() ( PrimarySuffix() )*
  2565. }
  2566.  
  2567. void MethodInvocation() #MethodInvocation : { }
  2568. {
  2569.    AmbiguousName() Arguments()
  2570. }
  2571.  
  2572. void PrimaryPrefix() #void: { }
  2573. {
  2574.   Literal()
  2575. |
  2576.   "(" Expression() ")"
  2577. |
  2578.   AllocationExpression()
  2579. |
  2580.   // SYNTACTIC_LOOKAHEAD
  2581.   LOOKAHEAD( MethodInvocation() )
  2582.     MethodInvocation()
  2583. |
  2584.   LOOKAHEAD( Type() "." "class" )
  2585.     Type()
  2586. |
  2587.   AmbiguousName()
  2588.  
  2589. /*
  2590. |
  2591.   LOOKAHEAD( "void" "." "class" )
  2592. */
  2593. }
  2594.  
  2595. void PrimarySuffix() #PrimarySuffix :
  2596. {
  2597.     Token t = null;
  2598. }
  2599. {
  2600.   LOOKAHEAD(2)
  2601.   "." "class" {
  2602.         jjtThis.setOperatorKind(BSHPrimarySuffix.CLASS);
  2603.     }
  2604. |LOOKAHEAD(3)
  2605.   "[" Expression() "]" {
  2606.         jjtThis.setOperatorKind(BSHPrimarySuffix.INDEX);
  2607.     }
  2608. |LOOKAHEAD(2) (t= "-->" | t= "->" )
  2609.   Expression() {
  2610.         jjtThis.setOperatorKind(t.kind);
  2611.     }
  2612. |
  2613.     // Field access OR method invocation
  2614.  LOOKAHEAD(2) "." t = GETIDENT() [ Arguments() ] {
  2615.         jjtThis.setOperatorKind(BSHPrimarySuffix.NAME);
  2616.         jjtThis.field = t.image;
  2617.     }
  2618. |
  2619.     LOOKAHEAD(3)  "{" Expression() "}" {
  2620.         jjtThis.setOperatorKind(BSHPrimarySuffix.PROPERTY);
  2621.     }
  2622. /*
  2623.     FOR inner classes
  2624. |
  2625.   LOOKAHEAD(2)
  2626.   "." AllocationExpression()
  2627. */
  2628. }
  2629.  
  2630. void Literal() #Literal :
  2631. {
  2632.     Token x;
  2633.     boolean b;
  2634.     STRING literal;
  2635.     char ch;
  2636. }
  2637. {
  2638.   x = <INTEGER_LITERAL>
  2639.   {
  2640.     literal = x.image;
  2641.     ch = literal.charAt(literal.length()-1);
  2642.     IF(ch == 'l' || ch == 'L')
  2643.     {
  2644.         literal = literal.substring(0,literal.length()-1);
  2645.  
  2646.         // This really should be LONG.decode, but there isn't one. As a result,
  2647.         // HEX AND octal literals ending in 'l' or 'L' don't work.
  2648.         jjtThis.value = new Primitive( new LONG( literal ).longValue() );
  2649.     }
  2650.     ELSE
  2651.         try {
  2652.  
  2653.                 try {
  2654.             jjtThis.value = new Primitive(
  2655.                     INTEGER.decode( literal ).intValue() );
  2656.             } catch ( NumberFormatException e ) {
  2657.                  jjtThis.value =  new java.math.BigInteger( literal ) ;
  2658.             }
  2659.         } catch ( NumberFormatException e ) {
  2660.             throw createParseException(
  2661.                 "Error or number too big for integer type: "+ literal );
  2662.         }
  2663.   }
  2664. |
  2665.   x = <FLOATING_POINT_LITERAL>
  2666.   {
  2667.     literal = x.image;
  2668.     ch = literal.charAt(literal.length()-1);
  2669.     IF(ch == 'f' || ch == 'F')
  2670.     {
  2671.         literal = literal.substring(0,literal.length()-1);
  2672.         jjtThis.value = new Primitive( new FLOAT( literal ).floatValue() );
  2673.     }
  2674.     ELSE
  2675.     {
  2676.         IF(ch == 'd' || ch == 'D')
  2677.             literal = literal.substring(0,literal.length()-1);
  2678.         try {
  2679.             jjtThis.value = new Primitive( new Double( literal ).doubleValue() );
  2680.         } catch ( NumberFormatException e ) {
  2681.              jjtThis.value =  new java.math.BigDecimal( literal ) ;
  2682.         }
  2683.     }
  2684.   }
  2685. |
  2686.   x = <STRING_LITERAL_SQ> {
  2687.         try {
  2688.             jjtThis.stringSetupI6( x.image.substring(1, x.image.length() - 1) );
  2689.         } catch ( Exception e ) {
  2690.             throw createParseException("Error parsing string: "+x.image);
  2691.         }
  2692.     }    
  2693. |
  2694.   x = <CHARACTER_LITERAL> {
  2695.         try {
  2696.             jjtThis.charSetup( x.image.substring(1, x.image.length() - 1) );
  2697.         } catch ( Exception e ) {
  2698.             throw createParseException("Error parsing character: "+x.image);
  2699.         }
  2700.     }
  2701. |
  2702.   x = <STRING_LITERAL> {
  2703.         try {
  2704.             jjtThis.stringSetup( x.image.substring(1, x.image.length() - 1) );
  2705.         } catch ( Exception e ) {
  2706.             throw createParseException("Error parsing string: "+x.image);
  2707.         }
  2708.     }
  2709. |
  2710.   b = BooleanLiteral()  {
  2711.     jjtThis.value = new Primitive( b ); }
  2712. |
  2713.   NullLiteral() {
  2714.     jjtThis.value = Primitive.NULL;
  2715. }
  2716. |
  2717.  VoidLiteral() {
  2718.     jjtThis.value = Primitive.VOID; }
  2719. }
  2720.  
  2721. boolean BooleanLiteral() #void:
  2722. {}
  2723. {
  2724.   "true" { RETURN true; }
  2725. |
  2726.   "false" { RETURN false; }
  2727. }
  2728.  
  2729. void NullLiteral() #void:
  2730. {}
  2731. {
  2732.   "null"
  2733. }
  2734.  
  2735. void VoidLiteral() #void:
  2736. {}
  2737. {
  2738.   "void"
  2739. }
  2740.  
  2741. void Arguments() #Arguments :
  2742. { }
  2743. {
  2744.   "(" [ ArgumentList()  ]  ")"
  2745. }
  2746.  
  2747. // leave these on the stack FOR Arguments() TO handle
  2748. void ArgumentList() #void:
  2749. { }
  2750. {
  2751.   Expression()
  2752.   ( "," Expression() )*
  2753. }
  2754.  
  2755. void AllocationExpression() #AllocationExpression :
  2756. { }
  2757. {
  2758.   LOOKAHEAD(2)
  2759.   "new" PrimitiveType() ArrayDimensions()
  2760. |
  2761.   "new" AmbiguousName()
  2762.     (
  2763.         ArrayDimensions()
  2764.     |
  2765.         // SYNTACTIC_LOOKAHEAD
  2766.         Arguments() [ LOOKAHEAD(2) Block() ]
  2767.     )
  2768. }
  2769.  
  2770. void ArrayDimensions() #ArrayDimensions :
  2771. {}
  2772. {
  2773.     // e.g. INT [4][3][][];
  2774.   LOOKAHEAD(2)
  2775.   ( LOOKAHEAD(2) "[" Expression() "]" { jjtThis.addDefinedDimension(); } )+
  2776.   ( LOOKAHEAD(2) "[" "]" { jjtThis.addUndefinedDimension(); } )*
  2777. |
  2778.     // e.g. INT [][] { {1,2}, {3,4} };
  2779.   ( "[" "]" { jjtThis.addUndefinedDimension(); } )+ ArrayInitializer()
  2780. }
  2781.  
  2782.  
  2783. /*
  2784.  * Statement syntax follows.
  2785.  */
  2786. void Statement() #void: { }
  2787. {
  2788.  LOOKAHEAD({isParsingI6()}) I6BlockStatement()
  2789. |
  2790.  LOOKAHEAD({!isParsingI6()}) JavaStatement()
  2791. }
  2792.  
  2793. void JavaStatement() #void: {
  2794.   PushLexicalState(JAVA);
  2795. }
  2796. {
  2797.  (
  2798.   JavaSpecificStatementNoExpressions()
  2799. |
  2800.   EmptyStatement()
  2801. |
  2802.   LOOKAHEAD(2) LabeledStatement()
  2803. |
  2804.   StatementExpression() ";"
  2805. )
  2806.   {
  2807.     PopLexicalState(JAVA);
  2808.   }
  2809. }
  2810.  
  2811. void JavaSpecificStatementNoExpressions() #void:
  2812. {
  2813.   }
  2814. {
  2815.   Block()
  2816. |
  2817.   I6SwitchStatement()
  2818. |
  2819.   LOOKAHEAD(IfStatement()) IfStatement()
  2820. |
  2821.   WhileStatement()
  2822. |
  2823.   DoStatement()
  2824. |
  2825.   LOOKAHEAD ( { isRegularForStatement() } )
  2826.   ForStatement()
  2827. |
  2828.   EnhancedForStatement()
  2829. |
  2830.   BreakStatement()
  2831. |
  2832.   ContinueStatement()
  2833. |
  2834.   ReturnStatement()
  2835. |
  2836.   SynchronizedStatement()
  2837. |
  2838.   ThrowStatement()
  2839. |
  2840.   TryStatement()
  2841. }
  2842.  
  2843. void LabeledStatement() #void:
  2844. {}
  2845. {
  2846.   GETIDENT_NOKW() ":" Statement()
  2847. }
  2848.  
  2849. void Block() #Block :
  2850. {}
  2851. {
  2852.   "{" ( BlockStatement() )* "}"
  2853. }
  2854.  
  2855. void BlockStatement() #void: {}
  2856. {  
  2857.  LOOKAHEAD({isParsingI6()}) I6BlockStatement()
  2858. |
  2859.  LOOKAHEAD({!isParsingI6()}) JavaBlockStatement()
  2860. }
  2861.  
  2862. void JavaBlockStatement() #void:
  2863. {
  2864. }
  2865. {
  2866.   // Allow BeanShell imports in any block
  2867.   ImportDeclaration()
  2868. |
  2869.   // Allow BeanShell package declarations in any block
  2870.   PackageDeclaration()
  2871. |
  2872.   FormalComment()
  2873. |  
  2874.   LOOKAHEAD( Modifiers( Modifiers.FIELD, true ) ( "class" | "interface" ) )
  2875.   ClassDeclaration()
  2876. |
  2877.   LOOKAHEAD ( Modifiers( Modifiers.METHOD, true )
  2878.         ReturnType() GETIDENT() "("
  2879.   )
  2880.     MethodDeclaration()
  2881. |
  2882.   LOOKAHEAD ( Modifiers( Modifiers.METHOD, true )
  2883.         GETIDENT() FormalParameters() [ "throws" NameList() ] "{"
  2884.   )
  2885.     MethodDeclaration()
  2886. |
  2887.   // SYNTACTIC_LOOKAHEAD
  2888.   LOOKAHEAD( Modifiers( Modifiers.FIELD, true ) Type() VariableDeclarator() ( "," VariableDeclarator() )* ";" )
  2889.   TypedVariableDeclaration() ";"
  2890. |
  2891.   JavaStatement()
  2892. |
  2893.   I6ToplevelDeclaration()
  2894. }
  2895.  
  2896. void FormalComment() #FormalComment( retainComments ) :
  2897. {
  2898.     Token t;
  2899. }
  2900. {
  2901.     t=<FORMAL_COMMENT_TOKEN>  {
  2902.         jjtThis.setText(t.image);
  2903.     }
  2904. }
  2905.  
  2906. void EmptyStatement() #void:
  2907. {}
  2908. {
  2909.   ";"
  2910. }
  2911.  
  2912.  
  2913. void StatementExpression() #void:
  2914. {
  2915. }
  2916. {
  2917.   StatementExpression_LOOSE()
  2918. }
  2919.  
  2920. void StatementExpression_LOOSE() #void:
  2921. { }
  2922. {
  2923.   /*
  2924.     This is looser than normal Java TO simplify the grammar.  This allows
  2925.     us TO type arbitrary expressions on the command line, e.g. "1+1;"
  2926.     We should turn this off in the implementation in strict java mode.
  2927.   */
  2928.   Expression()
  2929. /*
  2930.     // This was the original Java grammar.
  2931.  
  2932.     //  Original comment:
  2933.     //  The last expansion of this production accepts more than the legal
  2934.     //  Java expansions FOR StatementExpression.
  2935.       PreIncrementExpression()
  2936.     |
  2937.       PreDecrementExpression()
  2938.     |
  2939.       // SYNTACTIC_LOOKAHEAD
  2940.       LOOKAHEAD( PrimaryExpression() AssignmentOperator() )
  2941.       Assignment() { }
  2942.     |
  2943.       PostfixExpression()
  2944. */
  2945.  
  2946. }
  2947.  
  2948. void StatementExpression_STRICT() #void:
  2949. { }
  2950. {
  2951.   /*
  2952.     This is looser than normal Java TO simplify the grammar.  This allows
  2953.     us TO type arbitrary expressions on the command line, e.g. "1+1;"
  2954.     We should turn this off in the implementation in strict java mode.
  2955.   */
  2956.  
  2957.     // This was the original Java grammar.
  2958.  
  2959.     //  Original comment:
  2960.     //  The last expansion of this production accepts more than the legal
  2961.     //  Java expansions FOR StatementExpression.
  2962.       PreIncrementExpression()
  2963.     |
  2964.       PreDecrementExpression()
  2965.     |
  2966.       // SYNTACTIC_LOOKAHEAD
  2967.       LOOKAHEAD( PrimaryExpression() AssignmentOperator() )
  2968.       Assignment() { }
  2969.     |
  2970.       PostfixExpression()    
  2971. }
  2972.  
  2973. void SwitchStatement() #SwitchStatement :
  2974. {}
  2975. {
  2976.   "switch" "(" Expression() ")" "{"
  2977.     (SwitchLabel() ( BlockStatement() )* )*
  2978.   "}"
  2979. }
  2980.  
  2981. void SwitchLabel() #SwitchLabel :
  2982. {}
  2983. {
  2984.   "case" Expression() ":"
  2985. |
  2986.   < KW_DEFAULT > ":" { jjtThis.isDefault = true; }
  2987. }
  2988.  
  2989. void IfStatement() #IfStatement :
  2990. /*
  2991.  * The disambiguating algorithm of JavaCC automatically binds dangling
  2992.  * ELSE's to the innermost if statement.  The LOOKAHEAD specification
  2993.  * is TO tell JavaCC that we know what we are doing.
  2994.  */
  2995. {}
  2996. {
  2997.   "if" "(" Expression() ")" Statement() [ "else" Statement() ]
  2998. }
  2999.  
  3000. void WhileStatement() #WhileStatement :
  3001. {}
  3002. {
  3003.   "while" "(" Expression() ")" Statement()
  3004. }
  3005.  
  3006. /*
  3007.     DO statement is just a WHILE statement with a special hook TO execute
  3008.     AT least once.
  3009. */
  3010. void DoStatement() #WhileStatement :
  3011. {}
  3012. {
  3013.   "do" Statement() ( "while" | "until" ) "(" Expression() ")" ";"
  3014.     { jjtThis.isDoStatement=true;  }
  3015. }
  3016.  
  3017. void ForStatement() #ForStatement :
  3018. { Token t = null; }
  3019. {
  3020.   "for" "(" [ ForInit() { jjtThis.hasForInit=true; } ]
  3021.     ";" [ Expression() { jjtThis.hasExpression=true; } ]
  3022.     ";" [ ForUpdate() { jjtThis.hasForUpdate=true; } ] ")"
  3023.     Statement()
  3024. }
  3025.  
  3026. /*
  3027.     The new JDK1.5 enhanced FOR statement.
  3028.     e.g. FOR( INT a : arrayOfInts ) { }
  3029.     We also support loose typing of the iterator var FOR BeanShell
  3030.     e.g. FOR( a : arrayOfInts ) { }
  3031. */
  3032. void EnhancedForStatement() #EnhancedForStatement :
  3033. { Token t = null; }
  3034. {
  3035.   LOOKAHEAD( 4 ) // look ahead FOR the ":" before deciding
  3036.   "for" "(" t=GETIDENT() ":" Expression() ")"
  3037.     Statement() { jjtThis.varName = t.image; }
  3038.   |
  3039.   "for" "(" Type() t=GETIDENT() ":" Expression() ")"
  3040.     Statement() { jjtThis.varName = t.image; }
  3041. }
  3042.  
  3043. void ForInit() #void:
  3044. { Token t = null; }
  3045. {
  3046. // SYNTACTIC_LOOKAHEAD
  3047.   LOOKAHEAD( Modifiers( Modifiers.FIELD, true ) Type() GETIDENT() )
  3048.   TypedVariableDeclaration()
  3049. |
  3050.   StatementExpressionList()
  3051. }
  3052.  
  3053. /**
  3054.     Declared a typed variable.
  3055.     Untyped variables are NOT declared per-se but are handled by the part
  3056.     of the grammar that deals with assignments.
  3057. */
  3058. void TypedVariableDeclaration() #TypedVariableDeclaration :
  3059. {
  3060.     Token t = null;
  3061.     Modifiers mods;
  3062. }
  3063. {
  3064.     mods = Modifiers( Modifiers.FIELD, false )
  3065.     Type() VariableDeclarator() ( "," VariableDeclarator() )*  
  3066.     {
  3067.         jjtThis.modifiers = mods;
  3068.     }
  3069. }
  3070.  
  3071. void StatementExpressionList() #StatementExpressionList :
  3072. {}
  3073. {
  3074.   StatementExpression() ( "," StatementExpression() )*
  3075. }
  3076.  
  3077. void ForUpdate() #void:
  3078. {}
  3079. {
  3080.   StatementExpressionList()
  3081. }
  3082.  
  3083. void BreakStatement() #ReturnStatement :
  3084. {}
  3085. {
  3086.   "break" [ GETIDENT() ] ";" { jjtThis.setOperatorKind(BREAK); }
  3087. }
  3088.  
  3089. void ContinueStatement() #ReturnStatement :
  3090. {}
  3091. {
  3092.   "continue" [ GETIDENT() ] ";" { jjtThis.setOperatorKind( CONTINUE); }
  3093. }
  3094.  
  3095. void ReturnStatement() #ReturnStatement :
  3096. {}
  3097. {
  3098.   "return" [ Expression() ] ";" { jjtThis.setOperatorKind( RETURN); }
  3099. }
  3100.  
  3101. void SynchronizedStatement() #Block :
  3102. {
  3103. }
  3104. {
  3105.   "synchronized" "(" Expression() ")" Block() {
  3106.         jjtThis.isSynchronized=true;
  3107.   }
  3108. }
  3109.  
  3110. void ThrowStatement() #ThrowStatement :
  3111. {}
  3112. {
  3113.   "throw" Expression() ";"
  3114. }
  3115.  
  3116. void TryStatement() #TryStatement:
  3117. /*
  3118.     Semantic check required here TO make sure that AT least one
  3119.     finally/catch is present.  (You can have a try with finally AND no catch).
  3120.  */
  3121. { boolean closed = false; }
  3122. {
  3123.     "try" Block()
  3124.     ( "catch" "(" FormalParameter() ")" Block() { closed = true; } )*
  3125.     [ "finally" Block() { closed = true; } ]
  3126.     {  
  3127.         IF ( !closed ) throw generateParseException();
  3128.     }
  3129. }
  3130.  
  3131.  
  3132.  
  3133.  
  3134.  
  3135.  
  3136.  
  3137.  
  3138.  
  3139.  
  3140.  
  3141.  
  3142.  
  3143.  
  3144.  
  3145.  
  3146.  
  3147. /*INFORM6 BEGIN */
  3148.  
  3149.  
  3150. void I6SwitchStatement() #SwitchStatement:
  3151. {}
  3152. {
  3153.   "switch" "(" Expression() ")" "{"
  3154.     (SwitchElement())*
  3155.   "}"
  3156. }
  3157.  
  3158. void SwitchElement() #void:
  3159. {
  3160. }
  3161. {
  3162.    <KW_DEFAULT> ":" (I6BlockStatement())* #SwitchLabel  
  3163. |  <CASE> SwitchLabel_data() ":" (I6BlockStatement())* #SwitchLabel  
  3164. |  SwitchLabel_data() ":" I6BlockStatement() #SwitchLabel
  3165. }
  3166.  
  3167. void  SwitchLabel_data() #void:
  3168. {}
  3169. {  
  3170.  Expression() ("," Expression())*
  3171. }
  3172.  
  3173.  
  3174. Object LineResult() #LineResult:
  3175. {
  3176. Object bs;
  3177.   }
  3178. {
  3179.   <EOF> {
  3180.     //Interpreter.debug("End of File!");
  3181.     RETURN true;
  3182.   }
  3183. |
  3184.   BlockStatement() {    
  3185.     RETURN jjtThis;
  3186.   }
  3187. }
  3188.  
  3189.  
  3190.  
  3191.  
  3192. /*
  3193. void I6FormalParameters() #I6FormalParameters :
  3194. {}
  3195. {
  3196.     (  I6FormalParameter() )*
  3197. }
  3198. */
  3199. void I6FormalParameter() #FormalParameter :
  3200. { Token t; }
  3201. {
  3202.   t=GETIDENT() { jjtThis.setName(t.image); }
  3203. }
  3204.  
  3205.  
  3206. void I6FormalParameters() #FormalParameters :
  3207. { }
  3208. {
  3209.    [ I6FormalParameter() ( I6FormalParameter() )* ]  
  3210. }
  3211.  
  3212.  
  3213. void I6Expressions() #void :
  3214. {}
  3215. {
  3216.    I6Expression() ( I6Expression() )*
  3217. }
  3218.  
  3219.  
  3220. void I6Expression() #void:
  3221. {  }
  3222. {
  3223. //  "(" ")" #ArgumentList
  3224. //|
  3225.   Expression()
  3226. }
  3227.  
  3228. void I6MethodDeclaration() #MethodDeclaration :
  3229. { Token t; }
  3230. {
  3231.     "[" t=GETIDENT()  I6FormalParameters() ";"  I6Block()  "]" ";"
  3232.     {
  3233.         jjtThis.setName(t.image);
  3234.         jjtThis.isLanguageI6 = true;
  3235.    
  3236.     }
  3237. }
  3238.  
  3239.  
  3240. void I6Block() #Block :
  3241. {}
  3242. {
  3243.     (LOOKAHEAD(2) I6BlockStatement())*
  3244. }
  3245.  
  3246.  
  3247. /*void I6ForStatement() #I6ForStatement :
  3248. { Token t = null; }
  3249. {
  3250.   "for"
  3251.   "("
  3252.    [ I6ForInit() { jjtThis.hasForInit=true; } ]
  3253.     (":"|";") [ I6ForExpression() { jjtThis.hasExpression=true; } ]
  3254.     (":"|";") [ I6ForUpdate() { jjtThis.hasForUpdate=true; } ]
  3255.     ")"
  3256.     Statement()
  3257. }*/
  3258.  
  3259.  
  3260. /*
  3261. void I6ForStatement() #I6ForStatement :
  3262. {  }
  3263. {
  3264.   "for"  "("    [ I6ForInit()  ]  ":" (Expression())*  ":" [ I6ForUpdate() ]  ")"  Statement()
  3265. }
  3266.  
  3267.  
  3268.  
  3269. void I6ForInit() #I6ForInit :
  3270. {}
  3271. {
  3272.   ForInit()
  3273.   }
  3274. void I6ForUpdate() #I6ForUpdate :
  3275. {}{
  3276.   ForUpdate()
  3277.   }
  3278. void I6ForExpression() #I6ForExpression :
  3279. {}{
  3280.      Expression()
  3281.   } */
  3282.  
  3283. void RTrueStatement() #ReturnStatement(true) :
  3284. {}
  3285. {
  3286.   "rtrue" ";"
  3287. }
  3288.  
  3289. void RFalseStatement() #ReturnStatement(false) :
  3290. {}
  3291. {
  3292.   "rfalse" ";"
  3293. }
  3294.  
  3295. void PushToLabel() #PushToLabel:
  3296. {Token t = null;
  3297.   }
  3298. {
  3299.    "-->" t=GETIDENT() {setText(jjtThis,t);}
  3300.    
  3301. }
  3302.  
  3303.  
  3304. void AsmStatement() #void :
  3305. {}
  3306. {
  3307.  "@" AsmStatementWithoutAt()
  3308. }
  3309. void AsmStatementWithoutAt() #AsmStatement :
  3310. {}
  3311. {
  3312.  (<STRING_LITERAL>|GETIDENT()) I6Expressions() [PushToLabel()]  ";"
  3313. }
  3314.  
  3315.  
  3316.  
  3317. void I6ToplevelDeclaration()  #void:
  3318. {}
  3319. {
  3320.     I6MethodDeclaration()
  3321.  |
  3322.     I6ClassDeclaration()
  3323. }
  3324.  
  3325. /*
  3326.  
  3327. Class   Money(10)
  3328.   with  name 'money' 'cash' 'gold',
  3329.         sing_name 'coin' 'dollar' 'zorkmid',
  3330.         plur_name 'coins' 'dollars' 'zorkmids',
  3331.         parse_name [ wd qty b p s;
  3332.           qty = TryNumber(wn);
  3333.           ....
  3334.  
  3335. Class   Fuse
  3336.   with  name 'fuse' 'fuses//p',
  3337.         short_name "fuse",
  3338.         list_together [;
  3339.             IF (inventory_stage == 1) {
  3340.                 PRINT "several fuses";
  3341.                 IF (c_style & NEWLINE_BIT) new_line;
  3342.                 rtrue;
  3343.                 }
  3344.             ];
  3345.  
  3346. Fuse    ->;
  3347. Fuse    ->;          
  3348. */
  3349.  
  3350. void I6ClassDeclaration() #I6ClassDeclaration :
  3351. {}
  3352. {
  3353.   "CLASsarray"
  3354. }
  3355.  
  3356. void ID() #PrimaryExpression :
  3357. {
  3358. }
  3359. {
  3360.     AmbiguousName()
  3361. }
  3362.  
  3363. void I6Assignment() #I6VarDecl :
  3364. {}
  3365. {
  3366.  LOOKAHEAD(<ARRAY>) I6VarDecl() [I6ArrayInit()] ";"
  3367. |
  3368.  I6VarDecl()  [VariableInitializerWithE_Optional()] ";"
  3369.  
  3370. }
  3371.  
  3372. void I6VarDecl() #I6VarDecl :
  3373. {}
  3374. {
  3375.   <ARRAY> ID()
  3376.   |
  3377.  I6Type() ID()
  3378. }
  3379.  
  3380.  
  3381. void I6Type() #AmbiguousName :
  3382. {}
  3383. {
  3384. <GLOBAL> | < CONSTANT > | < KW_DEFAULT > | <IDENTIFIER_TOKEN>
  3385. }
  3386.  
  3387.  
  3388.  
  3389.  
  3390. void I6FileDirective() #I6FileDirective :
  3391. {}
  3392. {
  3393.   (<SWITCHES> | < RELEASE > | < SERIAL > | < H_INCLUDE >)
  3394.     Literal() ";"
  3395. |
  3396.  ( < H_IFTRUE: ("#Iftrue" | "#IFTRUE" | "#iftrue" )> | < H_IFDEF: ("#Ifdef" | "#IFDEF" )> | < H_IFFALSE:"#Iffalse" >| < H_IFNOT: ("#Ifnot"| "#IFNOT") > | < H_IFNDEF: ("#Ifndef" | "IFNDEF") > ) Expression() ";" (BlockStatement())* [ ( "#Ifnot" | "#Elseif" ) ";" (BlockStatement())* ] "#Endif" ";"
  3397. }
  3398.  
  3399. void GotoStatement() #GotoStatement:
  3400. {Token t;}
  3401. {
  3402.   ( "jump" | "goto" | "jsr" )  [ t=GETIDENT() {setText(jjtThis,t);} ] ";"
  3403.    
  3404. }
  3405.  
  3406. void I6ArrayInit() #void:
  3407. {
  3408. }
  3409. {
  3410.  LOOKAHEAD(2) Type()  Expression()
  3411. |
  3412.   "->"  I6Expressions()
  3413. |
  3414.  "-->" I6Expressions()
  3415. }
  3416.  
  3417. void I6SpecificStatement() #void :
  3418. {
  3419.   }
  3420. {
  3421.   "@" AsmStatementWithoutAt()
  3422. | LOOKAHEAD("[") I6MethodDeclaration()
  3423. | I6VarDecl()
  3424. | GotoStatement()
  3425. | I6ForStatement()
  3426. | I6VerbDeclaration()
  3427. | I6FileDirective()
  3428. | "#define" GETIDENT() VariableInitializerWithE_Optional() ";" #Statement
  3429. | I6KeywordArgSepComma() I6Expression() ("," Expression())* ";" #Statement
  3430. | I6KeywordArgSepSpaces() I6Expression() ( Expression())* ";" #Statement
  3431. | I6ObjectDecl()
  3432. | I6ArglessStatement() #Statement
  3433. | I6Label()
  3434. }
  3435.  
  3436.  
  3437. void I6ForStatement() #ForStatement :
  3438. { Token t = null;
  3439.   Token rs = null; }
  3440. {
  3441.   "for" "(" [ ForInit() { jjtThis.hasForInit=true; } ]
  3442.     ":" [ Expression() ("," Expression())* { jjtThis.hasExpression=true; } ]
  3443.     ":" [ I6ForUpdate() { jjtThis.hasForUpdate=true; } ] ")"
  3444.     I6Statement()
  3445. }
  3446.  
  3447. void I6ForUpdate() #void :
  3448. {
  3449. }
  3450. {
  3451. //  I6BlockStatement() ( ";" I6BlockStatement() )*
  3452. //|
  3453. ForUpdate()
  3454. }
  3455.  
  3456.  
  3457. void I6Statement() #void :
  3458. {
  3459.   PushLexicalState(INFORM6);
  3460. }
  3461. {(
  3462.   "{" I6Block() "}"
  3463. |
  3464.   I6BlockStatement())
  3465.   {
  3466.     PopLexicalState(INFORM6);
  3467.   }
  3468. }
  3469.  
  3470. void I6UnspecificStatement() #Statement :
  3471. {}
  3472. {(
  3473.   GETIDENT() (I6Expression())* ";")
  3474. }
  3475. /*
  3476. verb 'why'
  3477.     * 'don^t' 'you'         -> WhyDontYou
  3478.     * 'can^t' 'i//'         -> WhyCantI
  3479.     *                   -> What;
  3480. */
  3481. void I6VerbDeclaration() #I6VerbDeclaration:
  3482. {
  3483. }
  3484. {
  3485.    <VERB> [ <META>   {  jjtThis.set("isMeta",true); } ]
  3486.     (Literal())* (VerbAlias())* ";"
  3487. }
  3488.  
  3489. void VerbAlias()#VerbAlias:
  3490. {
  3491. }
  3492. {
  3493.  "*" (Literal())* "->" GETIDENT()
  3494. }
  3495.  
  3496. void I6Label()#I6Label :
  3497. {Token t;}
  3498. {  
  3499.   "." t=GETIDENT() {setText(jjtThis,t);} ";"
  3500. }
  3501.  
  3502. void I6ArglessStatement() #void: {
  3503. } { RTrueStatement() | RFalseStatement()
  3504. }
  3505.  
  3506.  
  3507. Token Inform6Infixes() #void:
  3508. {
  3509.   Token t;
  3510.   PushLexicalState(INFORM6);
  3511. }
  3512. {
  3513.  (t= "or" | t= "to" | t= "-->" | t= "->")
  3514.   {
  3515.     PopLexicalState(INFORM6);
  3516.     RETURN t;
  3517.   }
  3518. }
  3519.  
  3520. void I6BlockStatement()  #void:
  3521. {
  3522. }
  3523. {
  3524.   I6BlockStatement_NonLocally()
  3525. }
  3526.  
  3527.  
  3528. void I6BlockStatement_NonLocally() #void:
  3529. {
  3530. }
  3531. {
  3532.   I6SpecificStatement()
  3533. |
  3534.   JavaStatement()
  3535. |
  3536.   I6UnspecificStatement()
  3537. }
  3538.  
  3539. void I6BlockStatement_Locally() #void:
  3540. {
  3541. }
  3542. {  
  3543.    I6SpecificStatement()
  3544. |
  3545.   JavaSpecificStatementNoExpressions()
  3546. |
  3547.    LOOKAHEAD(";") ";" #Statement
  3548. |
  3549.   LOOKAHEAD(Expression() ";") Expression() ";"
  3550. |
  3551.   LOOKAHEAD(2) LabeledStatement()
  3552. |
  3553.   I6UnspecificStatement()
  3554. }
  3555.  
  3556. /*
  3557.  
  3558. Room study "Your study"
  3559.     with description "There is a doorway to the east of this austere room.",
  3560.          compass_look [ obj;
  3561.              IF (obj == e_obj) "You see a doorway.";
  3562.              IF (obj == n_obj OR s_obj OR w_obj) "You see the wall.";
  3563.          ],
  3564.          e_to hallway;
  3565.  
  3566.  
  3567.  Object  -> "sack"
  3568.     with  name 'sack',
  3569.           invent [;
  3570.               ! When listing objects in the player's inventory
  3571.               IF (c_style&amp;FULLINV_BIT) rfalse;
  3572.  
  3573.               ! When listing objects AT the END of a room description
  3574.               IF (inventory_stage == 1) switch (children(self)) {
  3575.                   0: PRINT "an empty sack";
  3576.                   1: PRINT "a sack containing ", (a) child(self);
  3577.                   default: PRINT "an assortment of objects in a sack";
  3578.                   }
  3579.               rtrue;
  3580.               ],
  3581.     has   container open;
  3582.              
  3583. */
  3584.  
  3585. Token I6ObjectType() #void:
  3586. {
  3587. Token t;
  3588. }
  3589. {
  3590. ( t= < PC_ROOM: "Room" > |  t =< PC_Object: "Object" > )
  3591. {
  3592.   RETURN t;
  3593. }
  3594. }
  3595.  
  3596. void I6ObjectDecl() #ObjectDecl:
  3597. {
  3598.   Token c;
  3599.   Token t;
  3600.   STRING s;
  3601. }
  3602. {
  3603.     c=I6ObjectType() (t= "->" | t=GETIDENT() ) <STRING_LITERAL> ObjectDeclList() ";"
  3604.   {
  3605.   }
  3606. }
  3607.  
  3608. void ObjectDeclList() #void:
  3609. {
  3610. }
  3611. {
  3612.   <WITH: "with"> ObjectDeclWith() ( "," ObjectDeclWith() )*
  3613. |
  3614.   <HAS: "has">  ObjectDeclHas() ( ObjectDeclHas() )*
  3615. }
  3616.  
  3617. void ObjectDeclWith() #ObjectDeclWith:
  3618. {
  3619. }
  3620. {
  3621.    <WITHW: "with"> ObjectDeclWith() ( "," ObjectDeclWith() )*
  3622. |
  3623.    <HASW: "has">  ObjectDeclHas() ( ObjectDeclHas() )*
  3624.  |
  3625.     GETIDENT() ExpressionOrMethodDecl()
  3626. }
  3627.  
  3628. void ObjectDeclHas() #ObjectDeclHas:
  3629. {
  3630. }
  3631. {
  3632.     GETIDENT()
  3633. }
  3634.  
  3635. void ExpressionOrMethodDecl() #void:
  3636. {
  3637. }
  3638. {
  3639.   Expression()
  3640. |
  3641.   "[" I6FormalParameters() ";" I6Block() "]"  
  3642. }
  3643.  
  3644.  
  3645. /*
  3646.     Gather an Identifier
  3647. */
  3648. Token GETIDENT_NOKW() #void:
  3649. { Token t;
  3650.   // PushLexicalState(IDENTIFIER_STATE);
  3651. }
  3652. {
  3653. ( t=<IDENTIFIER_TOKEN>
  3654. | t=I6Token()
  3655. ) {
  3656. //  PopLexicalState(IDENTIFIER_STATE);
  3657.     //jjtThis.setText(t.image);    
  3658.     RETURN t;
  3659. }
  3660. }
  3661. <IDENTIFIER_STATE,JAVA,INFORM6,DEFAULT>TOKEN :
  3662. {
  3663.  <IDENTIFIER_TOKEN: <LETTER> (<PART_LETTER>)* >
  3664. }
  3665.  
  3666. Token GETIDENT() #void:
  3667. { Token t;
  3668.   // PushLexicalState(IDENTIFIER_STATE);
  3669. }
  3670. {
  3671. (  t=<IDENTIFIER_TOKEN>
  3672. |  t=I6Token()
  3673. |  t=JavaKeyword()
  3674. |  t=SharedToken())
  3675. {
  3676. //  PopLexicalState(IDENTIFIER_STATE);    
  3677.     //jjtThis.setText(t.image);    
  3678.     RETURN t;
  3679. }
  3680. }
  3681.  
  3682. /*INFORM6 END */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement