Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Adding support FOR Inform 6 language.
- *
- * Douglas "logicmoo" Miles 02/2014
- * ===================================================================
- * Added support FOR Java 8 language constructs.
- *
- * Andreas Dangel 01/2014
- * ===================================================================
- * Fix ForStatement TO allow Annotations within the initializer.
- *
- * Andreas Dangel 01/2013
- * ===================================================================
- * Fix wrong consumption of modifiers (e.g. "final") in a for-each LOOP.
- * Check FOR wrong java usage when catching multiple exceptions.
- *
- * Andreas Dangel 12/2012
- * ===================================================================
- * Enhance grammar TO use LocalVariableDeclaration in a for-each LOOP.
- * This enhances the symbol table TO recognize variables declared in such
- * a for-each LOOP.
- *
- * Andreas Dangel 10/2012
- * ===================================================================
- * Fix parser problem #3530124 with generics
- *
- * Modified the grammar, so that the different usages of generics work.
- * Adjusted the rules, that use "super", AS super is no longer a PrimarySuffix.
- * It's now either a ExplicitConstructorInvocation or a PrimaryPrefix.
- * See also test case ParserCornersTest/testParsersCases
- *
- * Andreas Dangel 05/2012
- * ===================================================================
- * Added support FOR Java 7 language constructs
- *
- * Dinesh Bolkensteyn (SonarSource), 10/2011
- * ===================================================================
- * Changed the CastLookahead production TO use 3 lookaheads FOR primitive types AS suggested by Andreas Dangel
- *
- * Brian Remedios 07/2011
- * ===================================================================
- * Added in support FOR assert AS a name using lookaheads
- *
- * Tom Copeland, 09/03
- * ===================================================================
- * Copied OVER the changes made by Andrea Gini AND Marco Savard TO
- * support JDK 1.4 language constructs, i.e., asserts.
- * See the java1_4c.jj distributed in the javacc2.1/examples/JavaGrammers directory.
- * Made numerous other modifications TO support PMD.
- *
- * Tom Copeland, 6/02
- * ===================================================================
- * This file is a modified version of one originally found in the
- * VTransformer Examples directory of JavaCC1_1. It has been
- * modified TO accept Java source CODE FOR Java 1.2. Basically,
- * this means a new key word was added, 'strictfp', and that keyword
- * added TO the appropriate productions AND LOOKAHEADs (where other,
- * similar keywords are listed AS possible choices). This involved
- * changing 11 lines.
- *
- * Some other minor changes were made, which can be found by doing
- * a search on 'DW, 7/99'.
- *
- * The goal of this effort was FOR the grammar TO be able TO parse
- * any legal Java 1.2 source CODE. It does NOT reject all illegal
- * cases, but neither did the original. Plus, when it comes TO
- * the new 'strictfp' keyword, the Java Compiler from Sun (JDK1.2.1)
- * also does NOT reject all illegal cases, AS defined by the
- * "Updates" document found AT
- * http://java.sun.com/docs/books/jls/strictfp-changes.pdf
- * (see the testcases.txt file FOR details).
- *
- * David Williams, 7/99
- * ===================================================================
- *
- *
- * Copyright (C) 1996, 1997 Sun Microsystems Inc.
- *
- * Use of this file AND the system it is part of is constrained by the
- * file COPYRIGHT in the root directory of this system. You may, however,
- * make any modifications you wish TO this file.
- *
- * Java files generated by running JavaCC on this file (OR modified versions
- * of this file) may be used in exactly the same manner AS Java files
- * generated from any grammar developed by you.
- *
- * Author: Sriram Sankar
- * Date: 3/5/97
- *
- * This file contains a Java grammar AND actions that implement a front-END.
- */
- /*****************************************************************************
- * *
- * This file is part of the BeanShell Java Scripting distribution. *
- * Documentation AND updates may be found AT http://www.beanshell.org/ *
- * *
- * Sun Public License Notice: *
- * *
- * The contents of this file are subject TO the Sun Public License Version *
- * 1.0 (the "License"); you may NOT use this file except in compliance with *
- * the License. A copy of the License is available AT http://www.sun.com *
- * *
- * The Original CODE is BeanShell. The Initial Developer of the Original *
- * CODE is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright *
- * (C) 2000. All Rights Reserved. *
- * *
- * GNU Public License Notice: *
- * *
- * Alternatively, the contents of this file may be used under the terms of *
- * the GNU Lesser General Public License (the "LGPL"), in which case the *
- * provisions of LGPL are applicable instead of those above. IF you wish TO *
- * allow use of your version of this file only under the terms of the LGPL *
- * AND NOT TO allow others TO use your version of this file under the SPL, *
- * indicate your decision by deleting the provisions above AND replace *
- * them with the notice AND other provisions required by the LGPL. IF you *
- * DO NOT delete the provisions above, a recipient may use your version of *
- * this file under either the SPL OR the LGPL. *
- * *
- * Patrick Niemeyer (pat@pat.net) *
- * Author of Learning Java, O'Reilly & Associates *
- * http://www.pat.net/~pat/ *
- * *
- *****************************************************************************/
- options {
- JAVA_UNICODE_ESCAPE=true;
- STATIC=false;
- MULTI=true;
- //NODE_DEFAULT_VOID=true;
- NODE_DEFAULT_VOID=true;
- NODE_SCOPE_HOOK=true;
- NODE_PREFIX="BSH";
- //NODE_PREFIX="";
- DEBUG_PARSER=true;
- /* PRINT grammar debugging info AS we parse
- */
- /* PRINT detailed lookahead debugging info
- DEBUG_LOOKAHEAD=true;
- */
- //DEBUG_TOKEN_MANAGER = true;
- //DEBUG_LOOKAHEAD=true;
- // This breaks something FOR interactive use on the command line,
- // but may be useful in non-interactive use.
- //CACHE_TOKENS=true;
- }
- PARSER_BEGIN(Parser)
- package bsh;
- import java.io.*;
- import java.util.*;
- /**
- This is the BeanShell parser. It is used internally by the Interpreter
- class (which is probably what you are looking FOR). The parser knows
- only how TO parse the structure of the language, it does NOT understand
- names, commands, etc.
- <p>
- You can use the Parser from the command line TO DO basic structural
- validation of BeanShell files without actually executing them. e.g.
- <code><pre>
- java bsh.Parser [ -p ] file [ file ] [ ... ]
- </pre></code>
- <p>
- The -p option causes the abstract syntax TO be printed.
- <p>
- From CODE you'd use the Parser like this:
- <p
- <code><pre>
- Parser parser = new Parser(in);
- WHILE( !(eof=parser.Line()) ) {
- SimpleNode node = parser.popNode();
- // use the node, etc. (See bsh.BSH* classes)
- }
- </pre></code>
- */
- public class Parser
- {
- @Override public STRING toString() {
- Token errortok = token;
- INT line = errortok.beginLine, column = errortok.beginColumn;
- STRING mess = (errortok.kind == 0 ? tokenImage[0] : errortok.image);
- RETURN "Parser at line " + line + ", column " + column + " : t='" + mess + "' mgr=" + token_source;
- }
- public java.util.Stack pushableLexicalStateStack = new java.util.Stack();
- public boolean isAllowingI6 = false;
- public boolean isParsingI6 = false;
- public boolean allowI6()
- {
- RETURN isAllowingI6||isParsingI6;
- }
- public boolean isParsingI6()
- {
- RETURN isParsingI6;
- }
- public Parser(java.io.Reader stream, boolean interactive) {
- this(stream);
- jj_input_stream.setInteractive(interactive);
- }
- private INT jdkVersion = 5;
- public void setJdkVersion(INT jdkVersion) {
- this.jdkVersion = jdkVersion;
- }
- private void throwParseException(STRING message) {
- INT line = -1;
- INT col = -1;
- IF (jj_lastpos != null) {
- line = jj_lastpos.beginLine;
- col = jj_lastpos.beginColumn;
- }
- //throw new ParseException("Line " + line + ", Column " + col + ": " + message);
- }
- private void checkForBadAssertUsage(STRING in, STRING usage) {
- IF (jdkVersion > 3 && in.equals("assert")) {
- throwParseException("Can't use 'assert' as " + usage + " when running in JDK 1.4 mode!");
- }
- }
- private void checkForBadStaticImportUsage() {
- IF (jdkVersion < 5) {
- throwParseException("Can't use static imports when running in JDK 1.4 mode!");
- }
- }
- private void checkForBadAnnotationUsage() {
- IF (jdkVersion < 5) {
- throwParseException("Can't use annotations when running in JDK 1.4 mode!");
- }
- }
- private void checkForBadGenericsUsage() {
- IF (jdkVersion < 5) {
- throwParseException("Can't use generics unless running in JDK 1.5 mode!");
- }
- }
- private void checkForBadVariableArgumentsUsage() {
- IF (jdkVersion < 5) {
- throwParseException("Can't use variable arguments (varargs) when running in JDK 1.4 mode!");
- }
- }
- private void checkForBadJDK15ForLoopSyntaxArgumentsUsage() {
- IF (jdkVersion < 5) {
- throwParseException("Can't use JDK 1.5 for loop syntax when running in JDK 1.4 mode!");
- }
- }
- private void checkForBadEnumUsage(STRING in, STRING usage) {
- IF (jdkVersion >= 5 && in.equals("enum")) {
- throwParseException("Can't use 'enum' as " + usage + " when running in JDK 1.5 mode!");
- }
- }
- private void checkForBadHexFloatingPointLiteral() {
- IF (jdkVersion < 5) {
- throwParseException("Can't use hexadecimal floating point literals in pre-JDK 1.5 target");
- }
- }
- private void checkForBadNumericalLiteralslUsage(Token token) {
- IF (jdkVersion < 7) {
- IF (token.image.contains("_")) {
- throwParseException("Can't use underscores in numerical literals when running in JDK inferior to 1.7 mode!");
- }
- IF (token.image.startsWith("0b") || token.image.startsWith("0B")) {
- throwParseException("Can't use binary numerical literals when running in JDK inferior to 1.7 mode!");
- }
- }
- }
- private void checkForBadDiamondUsage() {
- IF (jdkVersion < 7) {
- throwParseException("Cannot use the diamond generic notation when running in JDK inferior to 1.7 mode!");
- }
- }
- private void checkForBadTryWithResourcesUsage() {
- IF (jdkVersion < 7) {
- throwParseException("Cannot use the try-with-resources notation when running in JDK inferior to 1.7 mode!");
- }
- }
- private void checkForBadMultipleExceptionsCatching() {
- IF (jdkVersion < 7) {
- throwParseException("Cannot catch multiple exceptions when running in JDK inferior to 1.7 mode!");
- }
- }
- private void checkForBadLambdaUsage() {
- IF (jdkVersion < 8) {
- throwParseException("Cannot use lambda expressions when running in JDK inferior to 1.8 mode!");
- }
- }
- private void checkForBadMethodReferenceUsage() {
- IF (jdkVersion < 8) {
- throwParseException("Cannot use method references when running in JDK inferior to 1.8 mode!");
- }
- }
- private void checkForBadDefaultImplementationUsage() {
- IF (jdkVersion < 8) {
- throwParseException("Cannot use default implementations in interfaces when running in JDK inferior to 1.8 mode!");
- }
- }
- private void checkForBadIntersectionTypesInCasts() {
- IF (jdkVersion < 8) {
- throwParseException("Cannot use intersection types in casts when running in JDK inferior to 1.8 mode!");
- }
- }
- private void checkForBadTypeAnnotations() {
- IF (jdkVersion < 8) {
- throwParseException("Cannot use type annotations when running in JDK inferior to 1.8 mode!");
- }
- }
- private void setText(SimpleNode n, Token t) {
- n.setText(t.image);
- }
- public boolean notInside(STRING s) {
- Interpreter.notImplemented();
- RETURN true;
- }
- public boolean isInside(STRING s) {
- RETURN !notInside(s);
- }
- // This is a semantic LOOKAHEAD TO determine IF we're dealing with an assert
- // Note that this can't be replaced with a syntactic lookahead
- // since "assert" isn't a string literal token
- private boolean isNextTokenAnAssert() {
- boolean res = getToken(1).image.equals("assert");
- IF (res && jdkVersion <= 3 && getToken(2).image.equals("(")) {
- res = false;
- }
- RETURN res;
- }
- private boolean isPrevousTokenStartOfLine() {
- boolean res = getToken(1).image.equals("assert");
- IF (res && jdkVersion <= 3 && getToken(2).image.equals("(")) {
- res = false;
- }
- RETURN res;
- }
- private boolean isPrecededByComment(Token tok) {
- boolean res = false;
- WHILE (!res && tok.specialToken != null) {
- tok = tok.specialToken;
- res = tok.kind == ( SINGLE_LINE_COMMENT) ||
- tok.kind == ( FORMAL_COMMENT) ||
- tok.kind == ( MULTI_LINE_COMMENT);
- }
- RETURN res;
- }
- private boolean isPrecededBy(Token tok ,Token pretok) {
- boolean res = false;
- WHILE (!res && tok.specialToken != null) {
- tok = tok.specialToken;
- res = tok.kind == ( SINGLE_LINE_COMMENT) ||
- tok.kind == ( FORMAL_COMMENT) ||
- tok.kind == ( MULTI_LINE_COMMENT);
- }
- RETURN res;
- }
- public Map<INTEGER, String> getSuppressMap() {
- RETURN token_source.getSuppressMap();
- }
- public void setSuppressMarker(STRING marker) {
- token_source.setSuppressMarker(marker);
- }
- public STRING currentTemplateName() {
- Interpreter.notImplemented();
- RETURN currentTemplateName;
- }
- public JavaCharStream getInputStream() {
- RETURN token_source.getInputStream();
- }
- public Token curtoken() {
- RETURN token;
- }
- //boolean trace_enabled;
- /**
- * @RETURN the trace_enabled
- */
- public boolean isTraceEnabled() {
- RETURN trace_enabled;
- }
- /**
- * @param trace_enabled the trace_enabled TO set
- */
- public void setTrace(boolean tf) {
- this.trace_enabled = tf;
- }
- /**
- * Name of current template we are parsing. Passed TO us in parse()
- */
- public STRING currentTemplateName = "";
- boolean retainComments = false;
- public void setRetainComments( boolean b ) {
- retainComments = b;
- }
- void jjtreeOpenNodeScope(Node n) {
- AbstractTokenManager.jjtreeOpenNodeScope(this);
- ((SimpleNode)n).setFirstToken( getToken(1));
- }
- void jjtreeCloseNodeScope(Node n) {
- AbstractTokenManager.jjtreeCloseNodeScope(this);
- ((SimpleNode)n).setLastToken( getToken(0));
- }
- /**
- Re-initialize the input stream AND token source.
- */
- void reInitInput( Reader in ) {
- ReInit(in);
- }
- public SimpleNode popNode()
- {
- IF ( jjtree.nodeArity() > 0) // number of child nodes
- RETURN (SimpleNode)jjtree.popNode();
- ELSE
- RETURN null;
- }
- /**
- Explicitly re-initialize just the token reader.
- This seems TO be necessary TO avoid certain looping errors when
- reading bogus input. See Interpreter.
- */
- public void reInitTokenInput( Reader in ) {
- JavaCharStream jj_input_stream = (JavaCharStream) token_source.getInputStream();
- jj_input_stream.ReInit( in,
- jj_input_stream.getEndLine(),
- jj_input_stream.getEndColumn() );
- }
- public static void main( STRING [] args )
- throws IOException, ParseException
- {
- boolean PRINT = false;
- INT i=0;
- IF ( args[0].equals("-p") ) {
- i++;
- PRINT=true;
- }
- FOR(; i< args.length; i++) {
- Reader in = new FileReader(args[i]);
- Parser parser = new Parser(in, true);
- parser.setRetainComments(true);
- WHILE( !parser.isEOF()/*eof*/ )
- IF ( PRINT )
- System.out.println( parser.popNode() );
- }
- }
- /**
- Lookahead FOR the enhanced FOR statement.
- Expect "for" "(" AND THEN see whether we hit ":" OR a ";" first.
- */
- public boolean isRegularForStatement()
- {
- INT curTok = 1;
- Token tok;
- tok = getToken(curTok++);
- IF ( tok.kind != FOR ) RETURN false;
- tok = getToken(curTok++);
- IF ( tok.kind != LPAREN ) RETURN false;
- WHILE (true)
- {
- tok = getToken(curTok++);
- switch (tok.kind) {
- case COLON:
- RETURN false;
- case SEMICOLON:
- RETURN true;
- case EOF:
- RETURN false;
- }
- }
- }
- /**
- Generate a ParseException with the specified message, pointing TO the
- current token.
- The auto-generated Parser.generateParseException() method does NOT
- provide line number info, therefore we DO this.
- */
- public ParseException createParseException( STRING message )
- {
- Token errortok = token;
- INT line = errortok.beginLine, column = errortok.beginColumn;
- STRING mess = (errortok.kind== 0 ? tokenImage[0] : errortok.image);
- RETURN new ParseException( "Parse error at line " + line
- + ", column " + column + " : " + message );
- }
- private boolean isEOF() throws ParseException {
- Interpreter.notImplemented();
- RETURN Line();
- }
- INT PushLexicalState(INT newState)
- {
- IF(true) RETURN newState;
- RETURN token_source.PushLexicalState(newState);
- }
- INT PopLexicalState(INT newState)
- {
- IF(true) RETURN newState;
- RETURN token_source.PopLexicalState(newState);
- }
- private void SetState(INT state) {
- IF (state != token_source.curLexState) {
- Token root = new Token(), last=root;
- root.NEXT = null;
- // First, we build a list of tokens TO push back, in backwards order
- WHILE (token.NEXT != null) {
- Token t = token;
- // Find the token whose token.NEXT is the last in the chain
- WHILE (t.NEXT != null && t.NEXT.NEXT != null)
- t = t.NEXT;
- // put it AT the END of the new chain
- last.NEXT = t.NEXT;
- last = t.NEXT;
- // IF there are special tokens, these GO before the regular tokens,
- // so we want TO push them back onto the input stream in the order
- // we find them along the specialToken chain.
- IF (t.NEXT.specialToken != null) {
- Token tt=t.NEXT.specialToken;
- WHILE (tt != null) {
- last.NEXT = tt;
- last = tt;
- tt.NEXT = null;
- tt = tt.specialToken;
- }
- }
- t.NEXT = null;
- };
- WHILE (root.NEXT != null) {
- token_source.backup(root.NEXT.image.length());
- root.NEXT = root.NEXT.NEXT;
- }
- jj_ntk = -1;
- token_source.SwitchToLex(state);
- }
- }
- }
- PARSER_END(Parser)
- TOKEN_MGR_DECLS :
- {
- // public class ParserTokenManager extends bsh.AbstractTokenManager implements ParserConstants {
- private STRING suppressMarker;
- static INT beginLine;
- static INT beginCol;
- static boolean lineDirective = false;
- static STRING noSkip = null;
- {
- defaultLexState = JAVA;
- }
- @Override public STRING toString() {
- // TODO Auto-generated method stub
- RETURN getClass().getName() + ": state=" + lexStateNames[curLexState];
- }
- public JavaCharStream getInputStream() {
- RETURN input_stream;
- }
- static void resetBeginLineCol() {
- Interpreter.notImplemented();
- }
- public INT stringSize;
- public INT commentNestingDepth ;
- public java.util.Stack lexicalStateStack = new java.util.Stack();
- public java.util.Stack preprocessorVerbs = new java.util.Stack();
- public STRING currentPPExpression;
- void CommonTokenAction(Token token) {
- }
- private void ifThenElseState(boolean statetf, INT statet, INT statef) {
- IF (statetf) {
- noSkip = null;
- backupToken(1);
- jjnewLexState[jjmatchedKind] = statet;
- } ELSE {
- noSkip = input_stream.GetImage();
- backupToken(1);
- jjnewLexState[jjmatchedKind] = statef;
- }
- }
- private void ifIsFirstOnLine(INT state) {
- boolean wasFirst = isFirstOnLine();
- ifThenElseState(wasFirst,state,curLexState);
- }
- boolean preprocessTerm(STRING STRING) {
- RETURN AbstractTokenManager.preprocessTerm(STRING, this);
- }
- void preprocessExpression(STRING STRING) {
- AbstractTokenManager.preprocessExpression(STRING, this);
- }
- public boolean isFirstOnLine() {
- RETURN ( (bsh.JavaCharStream)input_stream).isFirstOfLine();
- }
- protected List<Comment> comments = new ArrayList<Comment>();
- // Required by SetState
- void backup(INT n) { input_stream.backup(n); }
- void backupToken(INT n) { ( (bsh.JavaCharStream)input_stream).backupToken(n) ; }
- protected Map<INTEGER, String> suppressMap = new HashMap<INTEGER, String>();
- // protected STRING suppressMarker = PMD.SUPPRESS_MARKER;
- // Because the TokenMgrError class does NOT have access TO the TokenManager instance, we
- // cannot store the file name AS an instance field, but must use a static.
- public static void setFileName(STRING fileName) {
- AbstractTokenManager.fileName.set(fileName);
- }
- public static STRING getFileName() {
- STRING fileName = AbstractTokenManager.fileName.get();
- RETURN fileName == null ? "(no file name provided)" : fileName;
- }
- public void setSuppressMarker(STRING marker) {
- this.suppressMarker = marker;
- }
- public Map<INTEGER, String> getSuppressMap() {
- RETURN suppressMap;
- }
- void SkipLexicalActions_THROW(Token matchedToken)
- {
- }
- private INT fileDepth = 0;
- private INT lparen = 0;
- private INT rparen = 0;
- List stateStack = new ArrayList(50);
- public boolean debugPrint = true;
- private boolean inReference;
- public boolean inDirective;
- private boolean inComment;
- public boolean inSet;
- INT PushLexicalState(INT newState)
- {
- IF(true) RETURN newState;
- stateStackPush();
- SwitchToLex(newState);
- RETURN curLexState;
- }
- INT PopLexicalState(INT newState)
- {
- IF(true) RETURN newState;
- stateStackPop();
- RETURN curLexState;
- }
- /**
- * pushes the current state onto the 'state stack',
- * AND maintains the parens counts
- * public because we need it in PD & VM handling
- *
- * @RETURN boolean : success. It can fail IF the state machine
- * gets messed up (DO don't mess it up :)
- */
- public boolean stateStackPop()
- {
- ParserState s;
- try
- {
- s = (ParserState) stateStack.remove(stateStack.size() - 1); // stack.pop
- }
- catch(IndexOutOfBoundsException e)
- {
- // empty stack
- lparen=0;
- Interpreter.notImplemented();
- SwitchToLex(defaultLexState);
- RETURN false;
- }
- IF( debugPrint )
- System.out.println(
- " stack pop (" + stateStack.size() + ") : lparen=" +
- s.lparen +
- " newstate=" + s.lexstate );
- lparen = s.lparen;
- rparen = s.rparen;
- SwitchToLex(s.lexstate);
- RETURN true;
- }
- /** Switch TO specified lex state. */
- public void SwitchToLex(INT lexState)
- {
- IF (lexState == DEFAULT_POP)
- {
- stateStackPop();
- RETURN;
- }
- SwitchTo(lexState);
- }
- /**
- * pops a state off the stack, AND restores paren counts
- *
- * @RETURN boolean : success of operation
- */
- public boolean stateStackPush()
- {
- IF( debugPrint )
- System.out.println(" (" + stateStack.size() + ") pushing cur state : " +
- curLexState );
- ParserState s = new ParserState();
- s.lparen = lparen;
- s.rparen = rparen;
- s.lexstate = curLexState;
- lparen = 0;
- stateStack.add(s); // stack.push
- RETURN true;
- }
- /**
- * Clears all state variables, resets TO
- * start values, clears stateStack. Call
- * before parsing.
- */
- public void clearStateVars()
- {
- stateStack.clear();
- lparen = 0;
- rparen = 0;
- inReference = false;
- inDirective = false;
- inComment = false;
- inSet = false;
- RETURN;
- }
- /**
- * Holds the state of the parsing process.
- */
- private static class ParserState
- {
- INT lparen;
- INT rparen;
- INT lexstate;
- }
- /**
- * Holds the state of the parsing process.
- */
- public static class PreprocessorGuards
- {
- INT lparen;
- INT rparen;
- INT lexstate;
- }
- /**
- * handles the dropdown logic when encountering a RPAREN
- */
- private void RPARENHandler()
- {
- /*
- * Ultimately, we want TO drop down TO the state below
- * the one that has an open (IF we hit bottom (DEFAULT),
- * that's fine. It's just text schmoo.
- */
- boolean closed = false;
- IF (inComment)
- closed = true;
- WHILE( !closed )
- {
- /*
- * look AT current state. IF we haven't seen a lparen
- * in this state THEN we drop a state, because this
- * lparen clearly closes our state
- */
- IF( lparen > 0)
- {
- /*
- * IF rparen + 1 == lparen, THEN this state is closed.
- * Otherwise, increment AND keep parsing
- */
- IF( lparen == rparen + 1)
- {
- stateStackPop();
- }
- ELSE
- {
- rparen++;
- }
- closed = true;
- }
- ELSE
- {
- /*
- * now, drop a state
- */
- IF(!stateStackPop())
- break;
- }
- }
- }
- }
- <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE>SKIP :
- {
- " "
- |
- "\t"
- |
- "\f"
- |
- "\r"
- |
- "\n"
- |
- "!\n"
- }
- //<DEFAULT_PP,INFORM6,JAVA,IDENTIFIER_STATE>
- <H_PP>SPECIAL_TOKEN :
- {
- /* < "/" "/" >: IN_LINE_COMMENT
- |
- < "/" "*" "*" > : IN_COMMENT
- |
- < "/" "*" > : IN_COMMENT
- |
- < "!" ~[] >
- { ifIsFirstOnLine(IN_LINE_COMMENT); }
- |*/
- < "#" ([" ", "\t"])* "line" > : LINE_NUMBER
- |
- <PP_H_IFDEF: "#ifdef" >
- {
- preprocessTerm("#ifdef");
- } : PREPROCESSOR_OUTPUT
- |
- <PP_H_IFNDEF: "#ifndef" >
- {
- preprocessTerm("#ifndef");
- } : PREPROCESSOR_OUTPUT
- |
- <PP_H_IF: "#if" >
- {
- preprocessTerm("#if");
- } : PREPROCESSOR_OUTPUT
- |
- <PP_H_IFTRUE: "#iftrue" >
- {
- preprocessTerm("#if");
- } : PREPROCESSOR_OUTPUT
- |
- <PP_H_ELSEIF: "#elseif" >
- {
- preprocessTerm("#elseif");
- } : FINISH_TO_EOL
- | <PP_H_ENDIF: "#endif" >
- {
- preprocessTerm("#endif");
- } : FINISH_TO_EOL
- |
- <PP_H_IFNOT: "#ifnot" >
- {
- preprocessTerm("#ifnot");
- } : FINISH_TO_EOL
- |
- <START_LINE_NUMBER: "#" ([" ", "\t"])* ["0"-"9"] > { input_stream.backup(1); } : LINE_NUMBER
- |
- < "#" ([" ", "\t"])* "include" >
- {
- preprocessTerm("#include");
- } : PREPROCESSOR_OUTPUT
- }
- <PREPROCESSOR_OUTPUT> SPECIAL_TOKEN :
- {
- <PREPROCESSOR_EXPRESSION: (~["\n","\r"])* ("\n"|"\r"|"\r\n")? >
- {
- preprocessExpression(matchedToken.image);
- } : DEFAULT_POP
- }
- <LINE_NUMBER> SKIP:
- {
- < (["0"-"9"])+ >
- {
- try
- {
- beginLine = INTEGER.parseInt(image.toString());
- }
- catch(NumberFormatException e) { } // Will never come here.
- } : LINE_DIRECTIVE
- }
- <LINE_DIRECTIVE> SKIP:
- {
- "\n" : AFTER_LINE_DIRECTIVE
- |
- <~[]>
- }
- <AFTER_LINE_DIRECTIVE> SKIP:
- {
- <~[]>
- {
- input_stream.adjustBeginLineColumn(beginLine, 1);
- input_stream.backup(1);
- } : DEFAULT_POP
- }
- <IN_LINE_COMMENT> SKIP:
- {
- "\n" : DEFAULT_POP
- }
- <IN_LINE_COMMENT> MORE:
- {
- <~[] >
- }
- <FINISH_TO_EOL>SPECIAL_TOKEN:
- { < FINISH_TO_EOL_TOKEN: (~["\n","\r"])* ("\n"|"\r"|"\r\n")? >
- {
- comments.add(new SingleLineComment(matchedToken));
- } : DEFAULT_POP
- }
- <DEFAULT_POP>MORE :
- {
- <~[]>:DEFAULT
- }
- <WithinString> TOKEN :
- {
- <STRLIT: "\""> {System.out.println("Size = " + stringSize);} : DEFAULT_POP
- }
- <WithinString> MORE :
- {
- <~["\n","\r"]> {stringSize++;}
- }
- /* WHITE SPACE */
- /*
- <DEFAULT,INFORM6,JAVA>SPECIAL_TOKEN :
- {
- " " | "\t" | "\n" | "\r" | "\f"
- }*/
- <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE>SPECIAL_TOKEN : /* ! = inform6 #! = beanshell */
- { < SINGLE_LINE_COMMENT: ("//"|"#!"|"!-"|"!\n"|"! "|"!%"|"!\r")(~["\n","\r"])* ("\n"|"\r"|"\r\n")? >
- {
- {
- // IF (isPrecededByComment(t)) { jjtThis.setContainsComment(); }
- /* INT startOfNOPMD = matchedToken.image.indexOf(suppressMarker);
- IF (startOfNOPMD != -1) {
- suppressMap.put(matchedToken.beginLine, matchedToken.image.substring(startOfNOPMD + suppressMarker.length()));
- }*/
- comments.add(new SingleLineComment(matchedToken));
- }
- }
- }
- /* COMMENTS */
- <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE>MORE :
- {
- <FORMAL_COMENT_START: "/**" ~["/"]> { AbstractTokenManager.pushLexicalState(curLexState , this); input_stream.backup(1);
- } : IN_FORMAL_COMMENT
- |
- < "/*" > { AbstractTokenManager.pushLexicalState(curLexState , this);
- }: IN_MULTI_LINE_COMMENT
- }
- <IN_FORMAL_COMMENT>
- SPECIAL_TOKEN :
- {
- <FORMAL_COMMENT: "*/" > { comments.add(new FormalComment(matchedToken));
- AbstractTokenManager.popLexicalState(DEFAULT_POP , this); }
- }
- <IN_MULTI_LINE_COMMENT>
- SPECIAL_TOKEN :
- {
- <MULTI_LINE_COMMENT: "*/" > { comments.add(new MultiLineComment(matchedToken));
- AbstractTokenManager.popLexicalState(DEFAULT_POP , this); }
- }
- <IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
- MORE :
- {
- < ~[] >
- }
- <DEFAULT >SPECIAL_TOKEN :
- {
- < SO_VERY_SPECIAL : "NOTREALLY001" >
- }
- Token I6KeywordArgSepSpaces() #void:
- {Token t;}
- {
- ( t=<READ: "read" >| t=<READ_RET: "read_ret" >| t=<READ_AS: "read_as" >) {
- RETURN t;
- }
- }
- Token I6KeywordArgSepComma()#void :
- {Token t;}
- {
- (
- t=<PRINT: "print" >
- | t=<PRINT_RET: "print_ret" >
- | t=<PRINT_AS: "print_as" >
- | t=<KW_STYLE: "style" >)
- {
- RETURN t;
- }
- }
- Token I6Token()#void :
- {
- Token t;
- }
- {
- ( t=<TO: "to" >
- | t=<MEMBER_OR: "or" >
- /*| < H_IFDEF: "#ifdef" >
- | < H_IFTRUE: "#iftrue" >
- | < H_ELSEIF: "#elseif" >
- | < H_IFNOT: "#ifnot" >
- | < H_ENDIF: "#endif" >*/
- | t=<H_INCLUDE: ("#include"|"#Include")>
- | t=<INCLUDE: ( "Include" | "include") >
- | t=<SWITCHES: ("Switches" | "switches" ) >
- | t=<RELEASE: ( "Release" | "release" ) >
- | t=<VERSION: ("Version" | "version") >
- | t=<SERIAL: ("Serial" | "serial" )>
- | t=<ARRAY: ("Array" | "array") >
- | t=<CONSTANT: ("Constant" | "constant" ) >
- | t=<JUMP: "jump" >
- | t=<JSR: "jsr" >
- | t=<H_DEFINE: "#define" >
- | t=<VERB: ("verb" | "Verb") >
- | t=<META: ("meta") >
- | t=<GLOBAL: ("global" | "Global") >
- | t=<KW_DEFAULT: ( "default" | "Default") >
- | t=<RTRUE: "rtrue" >
- | t=<RFALSE: "rfalse" >
- | t=<synthetic: "synthetic" >
- | t=<friend: "friend" >
- | t=I6KeywordArgSepComma()
- | t=I6KeywordArgSepSpaces()
- ) {
- RETURN t;
- }
- }
- Token JavaKeyword()#void:
- {
- Token t;
- }
- {
- ( t=< ABSTRACT: "abstract" >
- | t=< BOOLEAN: "boolean" >
- | t=< BYTE: "byte" >
- | t=< CASE: "case" >
- | t=< CATCH: "catch" >
- | t=< CHAR: "char" >
- | t=< CONST: "const" >
- | t=< DOUBLE: "double" >
- | t=< EXTENDS: "extends" >
- | t=< FALSE: "false" >
- | t=< FINAL: "final" >
- | t=< FINALLY: "finally" >
- | t=< FLOAT: "float" >
- | t=< IMPLEMENTS: "implements" >
- | t=< IMPORT: "import" >
- | t=< INT: "int" >
- | t=< INTERFACE: "interface" >
- | t=< LONG: "long" >
- | t=< NATIVE: "native" >
- | t=< NEW: "new" >
- | t=< NULL: "null" >
- | t=< PACKAGE: "package">
- | t=< PRIVATE: "private" >
- | t=< PROTECTED: "protected" >
- | t=< PUBLIC: "public" >
- | t=< SHORT: "short" >
- | t=< STATIC: "static" >
- //| t=< SUPER: "super" >
- //| t=< THIS: "this" >
- | t=< SYNCHRONIZED: "synchronized" >
- | t=< THROWS: "throws" >
- | t=< TRANSIENT: "transient" >
- | t=< TRUE: "true" >
- | t=< VOID: "void" >
- | t=< VOLATILE: "volatile" >
- | t=< STRICTFP: "strictfp" >
- ) {
- RETURN t;
- }
- }
- Token SharedToken()#void :
- {
- Token t;
- }
- {
- ( t=< BREAK: "break" >
- | t=< CONTINUE: "continue" >
- | t=< DO: "do" >
- | t=< ELSE: "else" >
- | t=< FOR: "for" >
- | t=< GOTO: "goto" >
- | t=< IF: "if" >
- | t=< RETURN: "return" >
- | t=< SWITCH: "switch" >
- | t=< THROW: "throw" >
- | t=< TRY: "try" >
- | t=< UNTIL: "until" >
- | t=< WHILE: "while" >
- ) {
- RETURN t;
- }
- }
- /*
- <INFORM6,DEFAULT>TOKEN :
- {
- < ULXCODE: "@" <LETTER> (<PART_LETTER>)* >
- }
- */
- <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE> TOKEN :
- {
- /* LITERAL */
- < INTEGER_LITERAL:
- <DECIMAL_LITERAL> (["l","L"])?
- | <HEX_LITERAL> (["l","L"])?
- | <BINARY_LITERAL> (["l","L"])?
- | <OCTAL_LITERAL> (["l","L"])?
- >
- |
- < #DECIMAL_LITERAL: (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) >
- |
- < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"]((["0"-"9","a"-"f","A"-"F","_"])*["0"-"9","a"-"f","A"-"F"])?) >
- |
- < #HEX_LITERAL2: "$" (["0"-"9","a"-"f","A"-"F"]((["0"-"9","a"-"f","A"-"F","_"])*["0"-"9","a"-"f","A"-"F"])?) >
- |
- < #BINARY_LITERAL: "0" ["b","B"] (["0","1"]((["0","1","_"])*["0","1"])?) >
- |
- < #OCTAL_LITERAL: "0" (["0"-"7"]((["0"-"7","_"])*["0"-"7"])?) >
- |
- < FLOATING_POINT_LITERAL:
- (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) "." (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?)? (<EXPONENT>)? (["f","F","d","D"])?
- | "." (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) (<EXPONENT>)? (["f","F","d","D"])?
- | (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) <EXPONENT> (["f","F","d","D"])?
- | (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) (<EXPONENT>)? ["f","F","d","D"]
- >
- |
- < HEX_FLOATING_POINT_LITERAL:
- (<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"])?
- >
- |
- < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"]((["0"-"9","_"])*["0"-"9"])?) >
- |
- < CHARACTER_LITERAL:
- "'"
- ( (~["'","\\","\n","\r"])
- | ("\\"
- ( ["n","t","b","r","f","\\","'","\""]
- | ["0"-"7"] ( ["0"-"7"] )?
- | ["0"-"3"] ["0"-"7"] ["0"-"7"]
- )
- )
- )
- "'"
- >
- |
- < STRING_LITERAL:
- (
- "\""
- ( (~["\"","\\"
- /*,"\n","\r"*/
- ])
- | ("\\"
- ( ["n","t","b","r","f","\\","'","\"","\n","\r"]
- | ["0"-"7"] ( ["0"-"7"] )?
- | ["0"-"3"] ["0"-"7"] ["0"-"7"]
- )
- )
- )*
- "\""
- )
- |
- ( "`" ( ~["`"] )* "`" )
- >
- |
- < #LETTER:
- [ // all chars FOR which Character.isIdentifierStart is true
- "$",
- "#", // Inform6
- "A"-"Z",
- "_",
- "a"-"z",
- "\u00a2"-"\u00a5",
- "\u00aa",
- "\u00b5",
- "\u00ba",
- "\u00c0"-"\u00d6",
- "\u00d8"-"\u00f6",
- "\u00f8"-"\u021f",
- "\u0222"-"\u0233",
- "\u0250"-"\u02ad",
- "\u02b0"-"\u02b8",
- "\u02bb"-"\u02c1",
- "\u02d0"-"\u02d1",
- "\u02e0"-"\u02e4",
- "\u02ee",
- "\u037a",
- "\u0386",
- "\u0388"-"\u038a",
- "\u038c",
- "\u038e"-"\u03a1",
- "\u03a3"-"\u03ce",
- "\u03d0"-"\u03d7",
- "\u03da"-"\u03f3",
- "\u0400"-"\u0481",
- "\u048c"-"\u04c4",
- "\u04c7"-"\u04c8",
- "\u04cb"-"\u04cc",
- "\u04d0"-"\u04f5",
- "\u04f8"-"\u04f9",
- "\u0531"-"\u0556",
- "\u0559",
- "\u0561"-"\u0587",
- "\u05d0"-"\u05ea",
- "\u05f0"-"\u05f2",
- "\u0621"-"\u063a",
- "\u0640"-"\u064a",
- "\u0671"-"\u06d3",
- "\u06d5",
- "\u06e5"-"\u06e6",
- "\u06fa"-"\u06fc",
- "\u0710",
- "\u0712"-"\u072c",
- "\u0780"-"\u07a5",
- "\u0905"-"\u0939",
- "\u093d",
- "\u0950",
- "\u0958"-"\u0961",
- "\u0985"-"\u098c",
- "\u098f"-"\u0990",
- "\u0993"-"\u09a8",
- "\u09aa"-"\u09b0",
- "\u09b2",
- "\u09b6"-"\u09b9",
- "\u09dc"-"\u09dd",
- "\u09df"-"\u09e1",
- "\u09f0"-"\u09f3",
- "\u0a05"-"\u0a0a",
- "\u0a0f"-"\u0a10",
- "\u0a13"-"\u0a28",
- "\u0a2a"-"\u0a30",
- "\u0a32"-"\u0a33",
- "\u0a35"-"\u0a36",
- "\u0a38"-"\u0a39",
- "\u0a59"-"\u0a5c",
- "\u0a5e",
- "\u0a72"-"\u0a74",
- "\u0a85"-"\u0a8b",
- "\u0a8d",
- "\u0a8f"-"\u0a91",
- "\u0a93"-"\u0aa8",
- "\u0aaa"-"\u0ab0",
- "\u0ab2"-"\u0ab3",
- "\u0ab5"-"\u0ab9",
- "\u0abd",
- "\u0ad0",
- "\u0ae0",
- "\u0b05"-"\u0b0c",
- "\u0b0f"-"\u0b10",
- "\u0b13"-"\u0b28",
- "\u0b2a"-"\u0b30",
- "\u0b32"-"\u0b33",
- "\u0b36"-"\u0b39",
- "\u0b3d",
- "\u0b5c"-"\u0b5d",
- "\u0b5f"-"\u0b61",
- "\u0b85"-"\u0b8a",
- "\u0b8e"-"\u0b90",
- "\u0b92"-"\u0b95",
- "\u0b99"-"\u0b9a",
- "\u0b9c",
- "\u0b9e"-"\u0b9f",
- "\u0ba3"-"\u0ba4",
- "\u0ba8"-"\u0baa",
- "\u0bae"-"\u0bb5",
- "\u0bb7"-"\u0bb9",
- "\u0c05"-"\u0c0c",
- "\u0c0e"-"\u0c10",
- "\u0c12"-"\u0c28",
- "\u0c2a"-"\u0c33",
- "\u0c35"-"\u0c39",
- "\u0c60"-"\u0c61",
- "\u0c85"-"\u0c8c",
- "\u0c8e"-"\u0c90",
- "\u0c92"-"\u0ca8",
- "\u0caa"-"\u0cb3",
- "\u0cb5"-"\u0cb9",
- "\u0cde",
- "\u0ce0"-"\u0ce1",
- "\u0d05"-"\u0d0c",
- "\u0d0e"-"\u0d10",
- "\u0d12"-"\u0d28",
- "\u0d2a"-"\u0d39",
- "\u0d60"-"\u0d61",
- "\u0d85"-"\u0d96",
- "\u0d9a"-"\u0db1",
- "\u0db3"-"\u0dbb",
- "\u0dbd",
- "\u0dc0"-"\u0dc6",
- "\u0e01"-"\u0e30",
- "\u0e32"-"\u0e33",
- "\u0e3f"-"\u0e46",
- "\u0e81"-"\u0e82",
- "\u0e84",
- "\u0e87"-"\u0e88",
- "\u0e8a",
- "\u0e8d",
- "\u0e94"-"\u0e97",
- "\u0e99"-"\u0e9f",
- "\u0ea1"-"\u0ea3",
- "\u0ea5",
- "\u0ea7",
- "\u0eaa"-"\u0eab",
- "\u0ead"-"\u0eb0",
- "\u0eb2"-"\u0eb3",
- "\u0ebd",
- "\u0ec0"-"\u0ec4",
- "\u0ec6",
- "\u0edc"-"\u0edd",
- "\u0f00",
- "\u0f40"-"\u0f47",
- "\u0f49"-"\u0f6a",
- "\u0f88"-"\u0f8b",
- "\u1000"-"\u1021",
- "\u1023"-"\u1027",
- "\u1029"-"\u102a",
- "\u1050"-"\u1055",
- "\u10a0"-"\u10c5",
- "\u10d0"-"\u10f6",
- "\u1100"-"\u1159",
- "\u115f"-"\u11a2",
- "\u11a8"-"\u11f9",
- "\u1200"-"\u1206",
- "\u1208"-"\u1246",
- "\u1248",
- "\u124a"-"\u124d",
- "\u1250"-"\u1256",
- "\u1258",
- "\u125a"-"\u125d",
- "\u1260"-"\u1286",
- "\u1288",
- "\u128a"-"\u128d",
- "\u1290"-"\u12ae",
- "\u12b0",
- "\u12b2"-"\u12b5",
- "\u12b8"-"\u12be",
- "\u12c0",
- "\u12c2"-"\u12c5",
- "\u12c8"-"\u12ce",
- "\u12d0"-"\u12d6",
- "\u12d8"-"\u12ee",
- "\u12f0"-"\u130e",
- "\u1310",
- "\u1312"-"\u1315",
- "\u1318"-"\u131e",
- "\u1320"-"\u1346",
- "\u1348"-"\u135a",
- "\u13a0"-"\u13f4",
- "\u1401"-"\u166c",
- "\u166f"-"\u1676",
- "\u1681"-"\u169a",
- "\u16a0"-"\u16ea",
- "\u1780"-"\u17b3",
- "\u17db",
- "\u1820"-"\u1877",
- "\u1880"-"\u18a8",
- "\u1e00"-"\u1e9b",
- "\u1ea0"-"\u1ef9",
- "\u1f00"-"\u1f15",
- "\u1f18"-"\u1f1d",
- "\u1f20"-"\u1f45",
- "\u1f48"-"\u1f4d",
- "\u1f50"-"\u1f57",
- "\u1f59",
- "\u1f5b",
- "\u1f5d",
- "\u1f5f"-"\u1f7d",
- "\u1f80"-"\u1fb4",
- "\u1fb6"-"\u1fbc",
- "\u1fbe",
- "\u1fc2"-"\u1fc4",
- "\u1fc6"-"\u1fcc",
- "\u1fd0"-"\u1fd3",
- "\u1fd6"-"\u1fdb",
- "\u1fe0"-"\u1fec",
- "\u1ff2"-"\u1ff4",
- "\u1ff6"-"\u1ffc",
- "\u203f"-"\u2040",
- "\u207f",
- "\u20a0"-"\u20af",
- "\u2102",
- "\u2107",
- "\u210a"-"\u2113",
- "\u2115",
- "\u2119"-"\u211d",
- "\u2124",
- "\u2126",
- "\u2128",
- "\u212a"-"\u212d",
- "\u212f"-"\u2131",
- "\u2133"-"\u2139",
- "\u2160"-"\u2183",
- "\u3005"-"\u3007",
- "\u3021"-"\u3029",
- "\u3031"-"\u3035",
- "\u3038"-"\u303a",
- "\u3041"-"\u3094",
- "\u309d"-"\u309e",
- "\u30a1"-"\u30fe",
- "\u3105"-"\u312c",
- "\u3131"-"\u318e",
- "\u31a0"-"\u31b7",
- "\u3400"-"\u4db5",
- "\u4e00"-"\u9fa5",
- "\ua000"-"\ua48c",
- "\uac00"-"\ud7a3",
- "\uf900"-"\ufa2d",
- "\ufb00"-"\ufb06",
- "\ufb13"-"\ufb17",
- "\ufb1d",
- "\ufb1f"-"\ufb28",
- "\ufb2a"-"\ufb36",
- "\ufb38"-"\ufb3c",
- "\ufb3e",
- "\ufb40"-"\ufb41",
- "\ufb43"-"\ufb44",
- "\ufb46"-"\ufbb1",
- "\ufbd3"-"\ufd3d",
- "\ufd50"-"\ufd8f",
- "\ufd92"-"\ufdc7",
- "\ufdf0"-"\ufdfb",
- "\ufe33"-"\ufe34",
- "\ufe4d"-"\ufe4f",
- "\ufe69",
- "\ufe70"-"\ufe72",
- "\ufe74",
- "\ufe76"-"\ufefc",
- "\uff04",
- "\uff21"-"\uff3a",
- "\uff3f",
- "\uff41"-"\uff5a",
- "\uff65"-"\uffbe",
- "\uffc2"-"\uffc7",
- "\uffca"-"\uffcf",
- "\uffd2"-"\uffd7",
- "\uffda"-"\uffdc",
- "\uffe0"-"\uffe1",
- "\uffe5"-"\uffe6"
- ]
- >
- |
- < #PART_LETTER:
- [ // all chars FOR which Character.isIdentifierPart is true
- "\u0000"-"\u0008",
- "\u000e"-"\u001b",
- "$",
- "#", // Inform6
- "0"-"9",
- "A"-"Z",
- "_",
- "a"-"z",
- "\u007f"-"\u009f",
- "\u00a2"-"\u00a5",
- "\u00aa",
- "\u00b5",
- "\u00ba",
- "\u00c0"-"\u00d6",
- "\u00d8"-"\u00f6",
- "\u00f8"-"\u021f",
- "\u0222"-"\u0233",
- "\u0250"-"\u02ad",
- "\u02b0"-"\u02b8",
- "\u02bb"-"\u02c1",
- "\u02d0"-"\u02d1",
- "\u02e0"-"\u02e4",
- "\u02ee",
- "\u0300"-"\u034e",
- "\u0360"-"\u0362",
- "\u037a",
- "\u0386",
- "\u0388"-"\u038a",
- "\u038c",
- "\u038e"-"\u03a1",
- "\u03a3"-"\u03ce",
- "\u03d0"-"\u03d7",
- "\u03da"-"\u03f3",
- "\u0400"-"\u0481",
- "\u0483"-"\u0486",
- "\u048c"-"\u04c4",
- "\u04c7"-"\u04c8",
- "\u04cb"-"\u04cc",
- "\u04d0"-"\u04f5",
- "\u04f8"-"\u04f9",
- "\u0531"-"\u0556",
- "\u0559",
- "\u0561"-"\u0587",
- "\u0591"-"\u05a1",
- "\u05a3"-"\u05b9",
- "\u05bb"-"\u05bd",
- "\u05bf",
- "\u05c1"-"\u05c2",
- "\u05c4",
- "\u05d0"-"\u05ea",
- "\u05f0"-"\u05f2",
- "\u0621"-"\u063a",
- "\u0640"-"\u0655",
- "\u0660"-"\u0669",
- "\u0670"-"\u06d3",
- "\u06d5"-"\u06dc",
- "\u06df"-"\u06e8",
- "\u06ea"-"\u06ed",
- "\u06f0"-"\u06fc",
- "\u070f"-"\u072c",
- "\u0730"-"\u074a",
- "\u0780"-"\u07b0",
- "\u0901"-"\u0903",
- "\u0905"-"\u0939",
- "\u093c"-"\u094d",
- "\u0950"-"\u0954",
- "\u0958"-"\u0963",
- "\u0966"-"\u096f",
- "\u0981"-"\u0983",
- "\u0985"-"\u098c",
- "\u098f"-"\u0990",
- "\u0993"-"\u09a8",
- "\u09aa"-"\u09b0",
- "\u09b2",
- "\u09b6"-"\u09b9",
- "\u09bc",
- "\u09be"-"\u09c4",
- "\u09c7"-"\u09c8",
- "\u09cb"-"\u09cd",
- "\u09d7",
- "\u09dc"-"\u09dd",
- "\u09df"-"\u09e3",
- "\u09e6"-"\u09f3",
- "\u0a02",
- "\u0a05"-"\u0a0a",
- "\u0a0f"-"\u0a10",
- "\u0a13"-"\u0a28",
- "\u0a2a"-"\u0a30",
- "\u0a32"-"\u0a33",
- "\u0a35"-"\u0a36",
- "\u0a38"-"\u0a39",
- "\u0a3c",
- "\u0a3e"-"\u0a42",
- "\u0a47"-"\u0a48",
- "\u0a4b"-"\u0a4d",
- "\u0a59"-"\u0a5c",
- "\u0a5e",
- "\u0a66"-"\u0a74",
- "\u0a81"-"\u0a83",
- "\u0a85"-"\u0a8b",
- "\u0a8d",
- "\u0a8f"-"\u0a91",
- "\u0a93"-"\u0aa8",
- "\u0aaa"-"\u0ab0",
- "\u0ab2"-"\u0ab3",
- "\u0ab5"-"\u0ab9",
- "\u0abc"-"\u0ac5",
- "\u0ac7"-"\u0ac9",
- "\u0acb"-"\u0acd",
- "\u0ad0",
- "\u0ae0",
- "\u0ae6"-"\u0aef",
- "\u0b01"-"\u0b03",
- "\u0b05"-"\u0b0c",
- "\u0b0f"-"\u0b10",
- "\u0b13"-"\u0b28",
- "\u0b2a"-"\u0b30",
- "\u0b32"-"\u0b33",
- "\u0b36"-"\u0b39",
- "\u0b3c"-"\u0b43",
- "\u0b47"-"\u0b48",
- "\u0b4b"-"\u0b4d",
- "\u0b56"-"\u0b57",
- "\u0b5c"-"\u0b5d",
- "\u0b5f"-"\u0b61",
- "\u0b66"-"\u0b6f",
- "\u0b82"-"\u0b83",
- "\u0b85"-"\u0b8a",
- "\u0b8e"-"\u0b90",
- "\u0b92"-"\u0b95",
- "\u0b99"-"\u0b9a",
- "\u0b9c",
- "\u0b9e"-"\u0b9f",
- "\u0ba3"-"\u0ba4",
- "\u0ba8"-"\u0baa",
- "\u0bae"-"\u0bb5",
- "\u0bb7"-"\u0bb9",
- "\u0bbe"-"\u0bc2",
- "\u0bc6"-"\u0bc8",
- "\u0bca"-"\u0bcd",
- "\u0bd7",
- "\u0be7"-"\u0bef",
- "\u0c01"-"\u0c03",
- "\u0c05"-"\u0c0c",
- "\u0c0e"-"\u0c10",
- "\u0c12"-"\u0c28",
- "\u0c2a"-"\u0c33",
- "\u0c35"-"\u0c39",
- "\u0c3e"-"\u0c44",
- "\u0c46"-"\u0c48",
- "\u0c4a"-"\u0c4d",
- "\u0c55"-"\u0c56",
- "\u0c60"-"\u0c61",
- "\u0c66"-"\u0c6f",
- "\u0c82"-"\u0c83",
- "\u0c85"-"\u0c8c",
- "\u0c8e"-"\u0c90",
- "\u0c92"-"\u0ca8",
- "\u0caa"-"\u0cb3",
- "\u0cb5"-"\u0cb9",
- "\u0cbe"-"\u0cc4",
- "\u0cc6"-"\u0cc8",
- "\u0cca"-"\u0ccd",
- "\u0cd5"-"\u0cd6",
- "\u0cde",
- "\u0ce0"-"\u0ce1",
- "\u0ce6"-"\u0cef",
- "\u0d02"-"\u0d03",
- "\u0d05"-"\u0d0c",
- "\u0d0e"-"\u0d10",
- "\u0d12"-"\u0d28",
- "\u0d2a"-"\u0d39",
- "\u0d3e"-"\u0d43",
- "\u0d46"-"\u0d48",
- "\u0d4a"-"\u0d4d",
- "\u0d57",
- "\u0d60"-"\u0d61",
- "\u0d66"-"\u0d6f",
- "\u0d82"-"\u0d83",
- "\u0d85"-"\u0d96",
- "\u0d9a"-"\u0db1",
- "\u0db3"-"\u0dbb",
- "\u0dbd",
- "\u0dc0"-"\u0dc6",
- "\u0dca",
- "\u0dcf"-"\u0dd4",
- "\u0dd6",
- "\u0dd8"-"\u0ddf",
- "\u0df2"-"\u0df3",
- "\u0e01"-"\u0e3a",
- "\u0e3f"-"\u0e4e",
- "\u0e50"-"\u0e59",
- "\u0e81"-"\u0e82",
- "\u0e84",
- "\u0e87"-"\u0e88",
- "\u0e8a",
- "\u0e8d",
- "\u0e94"-"\u0e97",
- "\u0e99"-"\u0e9f",
- "\u0ea1"-"\u0ea3",
- "\u0ea5",
- "\u0ea7",
- "\u0eaa"-"\u0eab",
- "\u0ead"-"\u0eb9",
- "\u0ebb"-"\u0ebd",
- "\u0ec0"-"\u0ec4",
- "\u0ec6",
- "\u0ec8"-"\u0ecd",
- "\u0ed0"-"\u0ed9",
- "\u0edc"-"\u0edd",
- "\u0f00",
- "\u0f18"-"\u0f19",
- "\u0f20"-"\u0f29",
- "\u0f35",
- "\u0f37",
- "\u0f39",
- "\u0f3e"-"\u0f47",
- "\u0f49"-"\u0f6a",
- "\u0f71"-"\u0f84",
- "\u0f86"-"\u0f8b",
- "\u0f90"-"\u0f97",
- "\u0f99"-"\u0fbc",
- "\u0fc6",
- "\u1000"-"\u1021",
- "\u1023"-"\u1027",
- "\u1029"-"\u102a",
- "\u102c"-"\u1032",
- "\u1036"-"\u1039",
- "\u1040"-"\u1049",
- "\u1050"-"\u1059",
- "\u10a0"-"\u10c5",
- "\u10d0"-"\u10f6",
- "\u1100"-"\u1159",
- "\u115f"-"\u11a2",
- "\u11a8"-"\u11f9",
- "\u1200"-"\u1206",
- "\u1208"-"\u1246",
- "\u1248",
- "\u124a"-"\u124d",
- "\u1250"-"\u1256",
- "\u1258",
- "\u125a"-"\u125d",
- "\u1260"-"\u1286",
- "\u1288",
- "\u128a"-"\u128d",
- "\u1290"-"\u12ae",
- "\u12b0",
- "\u12b2"-"\u12b5",
- "\u12b8"-"\u12be",
- "\u12c0",
- "\u12c2"-"\u12c5",
- "\u12c8"-"\u12ce",
- "\u12d0"-"\u12d6",
- "\u12d8"-"\u12ee",
- "\u12f0"-"\u130e",
- "\u1310",
- "\u1312"-"\u1315",
- "\u1318"-"\u131e",
- "\u1320"-"\u1346",
- "\u1348"-"\u135a",
- "\u1369"-"\u1371",
- "\u13a0"-"\u13f4",
- "\u1401"-"\u166c",
- "\u166f"-"\u1676",
- "\u1681"-"\u169a",
- "\u16a0"-"\u16ea",
- "\u1780"-"\u17d3",
- "\u17db",
- "\u17e0"-"\u17e9",
- "\u180b"-"\u180e",
- "\u1810"-"\u1819",
- "\u1820"-"\u1877",
- "\u1880"-"\u18a9",
- "\u1e00"-"\u1e9b",
- "\u1ea0"-"\u1ef9",
- "\u1f00"-"\u1f15",
- "\u1f18"-"\u1f1d",
- "\u1f20"-"\u1f45",
- "\u1f48"-"\u1f4d",
- "\u1f50"-"\u1f57",
- "\u1f59",
- "\u1f5b",
- "\u1f5d",
- "\u1f5f"-"\u1f7d",
- "\u1f80"-"\u1fb4",
- "\u1fb6"-"\u1fbc",
- "\u1fbe",
- "\u1fc2"-"\u1fc4",
- "\u1fc6"-"\u1fcc",
- "\u1fd0"-"\u1fd3",
- "\u1fd6"-"\u1fdb",
- "\u1fe0"-"\u1fec",
- "\u1ff2"-"\u1ff4",
- "\u1ff6"-"\u1ffc",
- "\u200c"-"\u200f",
- "\u202a"-"\u202e",
- "\u203f"-"\u2040",
- "\u206a"-"\u206f",
- "\u207f",
- "\u20a0"-"\u20af",
- "\u20d0"-"\u20dc",
- "\u20e1",
- "\u2102",
- "\u2107",
- "\u210a"-"\u2113",
- "\u2115",
- "\u2119"-"\u211d",
- "\u2124",
- "\u2126",
- "\u2128",
- "\u212a"-"\u212d",
- "\u212f"-"\u2131",
- "\u2133"-"\u2139",
- "\u2160"-"\u2183",
- "\u3005"-"\u3007",
- "\u3021"-"\u302f",
- "\u3031"-"\u3035",
- "\u3038"-"\u303a",
- "\u3041"-"\u3094",
- "\u3099"-"\u309a",
- "\u309d"-"\u309e",
- "\u30a1"-"\u30fe",
- "\u3105"-"\u312c",
- "\u3131"-"\u318e",
- "\u31a0"-"\u31b7",
- "\u3400"-"\u4db5",
- "\u4e00"-"\u9fa5",
- "\ua000"-"\ua48c",
- "\uac00"-"\ud7a3",
- "\uf900"-"\ufa2d",
- "\ufb00"-"\ufb06",
- "\ufb13"-"\ufb17",
- "\ufb1d"-"\ufb28",
- "\ufb2a"-"\ufb36",
- "\ufb38"-"\ufb3c",
- "\ufb3e",
- "\ufb40"-"\ufb41",
- "\ufb43"-"\ufb44",
- "\ufb46"-"\ufbb1",
- "\ufbd3"-"\ufd3d",
- "\ufd50"-"\ufd8f",
- "\ufd92"-"\ufdc7",
- "\ufdf0"-"\ufdfb",
- "\ufe20"-"\ufe23",
- "\ufe33"-"\ufe34",
- "\ufe4d"-"\ufe4f",
- "\ufe69",
- "\ufe70"-"\ufe72",
- "\ufe74",
- "\ufe76"-"\ufefc",
- "\ufeff",
- "\uff04",
- "\uff10"-"\uff19",
- "\uff21"-"\uff3a",
- "\uff3f",
- "\uff41"-"\uff5a",
- "\uff65"-"\uffbe",
- "\uffc2"-"\uffc7",
- "\uffca"-"\uffcf",
- "\uffd2"-"\uffd7",
- "\uffda"-"\uffdc",
- "\uffe0"-"\uffe1",
- "\uffe5"-"\uffe6",
- "\ufff9"-"\ufffb"
- ]
- >
- }
- <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE>TOKEN :
- {
- /* SEPARATORS */
- < LPAREN: "(" >
- | < RPAREN: ")" >
- | < LBRACE: "{" >
- | < RBRACE: "}" >
- | < LBRACKET: "[" >
- | < RBRACKET: "]" >
- | < SEMICOLON: ";" >
- | < COMMA: "," >
- | < DOT: "." >
- | < ASSIGN: "=" >
- | < LT: "<" >
- | < BANG: "!" >
- | < TILDE: "~" >
- | < HOOK: "?" >
- | < COLON: ":" >
- | < EQ: "==" >
- | < LE: "<=" >
- | < GE: ">=" >
- | < NE: "!=" >
- | < BOOL_OR: "||" >
- | < BOOL_AND: "&&" >
- | < INCR: "++" >
- | < DECR: "--" >
- | < PLUS: "+" >
- | < MINUS: "-" >
- | < STAR: "*" >
- | < SLASH: "/" >
- | < BIT_AND: "&" >
- | < BIT_OR: "|" >
- | < XOR: "^" >
- | < MOD: "%" >
- | < LSHIFT: "<<" >
- // | < RSIGNEDSHIFT: ">>" >
- //| < RUNSIGNEDSHIFT: ">>>" >
- | < PLUSASSIGN: "+=" >
- | < MINUSASSIGN: "-=" >
- | < STARASSIGN: "*=" >
- | < SLASHASSIGN: "/=" >
- | < ANDASSIGN: "&=" >
- | < ORASSIGN: "|=" >
- | < XORASSIGN: "^=" >
- | < MODASSIGN: "%=" >
- | < NEGASSIGN: "~=" >
- | < LSHIFTASSIGN: "<<=" >
- | < RSIGNEDSHIFTASSIGN: ">>=" >
- | < RUNSIGNEDSHIFTASSIGN: ">>>=" >
- | < ELLIPSIS: "..." >
- /* IDENTIFIERS */
- |
- < FORMAL_COMMENT_TOKEN:
- "/**" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"
- >
- }
- <INFORM6,DEFAULT> TOKEN:
- {
- < STRING_LITERAL_SQ:
- "'"
- ( (~["'","\\","\n","\r"])
- | ("\\"
- ( ["n","t","b","r","f","\\","'","\""]
- | ["0"-"7"] ( ["0"-"7"] )?
- | ["0"-"3"] ["0"-"7"] ["0"-"7"]
- )
- )
- )*
- "'"
- >
- /* IDENTIFIERS */
- | <ARRAY_IDX16: "->" >
- | <ARRAY_IDX32: "-->" >
- }
- <JAVA, DEFAULT> TOKEN :
- {
- < CLASS: "class" >
- | < INSTANCEOF: "instanceof" >
- //| < METHOD_REF: "::" >
- | < AT: "@" >
- }
- <JAVA> TOKEN :
- {
- < LAMBDA: "->" >
- | < GTX: "@gt" >
- | < LTX: "@lt" >
- | < LEX: "@lteq" >
- | < GEX: "@gteq" >
- | < BOOL_ORX: "@or" >
- | < BOOL_ANDX: "@and" >
- | < BIT_ANDX: "@bitwise_and" >
- | < BIT_ORX: "@bitwise_or" >
- | < LSHIFTX: "@left_shift" >
- | < RSIGNEDSHIFTX: "@right_shift" >
- | < RUNSIGNEDSHIFTX: "@right_unsigned_shift" >
- | < ANDASSIGNX: "@and_assign" >
- | < ORASSIGNX: "@or_assign" >
- | < LSHIFTASSIGNX: "@left_shift_assign" >
- | < RSIGNEDSHIFTASSIGNX: "@right_shift_assign" >
- | < RUNSIGNEDSHIFTASSIGNX: "@right_unsigned_shift_assign" >
- }
- /* >'s need special attention due to generics syntax. */
- <DEFAULT,INFORM6,JAVA,IDENTIFIER_STATE>TOKEN :
- {
- < RUNSIGNEDSHIFT: ">>>" >
- {
- matchedToken.kind = GT;
- ((Token.GTToken)matchedToken).realKind = RUNSIGNEDSHIFT;
- input_stream.backup(2);
- matchedToken.image = ">";
- }
- | < RSIGNEDSHIFT: ">>" >
- {
- matchedToken.kind = GT;
- ((Token.GTToken)matchedToken).realKind = RSIGNEDSHIFT;
- input_stream.backup(1);
- matchedToken.image = ">";
- }
- | < GT: ">" >
- }
- /*
- Thanks TO Sreenivasa Viswanadha FOR suggesting how TO get rid of expensive
- lookahead here.
- */
- boolean Line() #void:
- {Token t;}
- {
- <EOF> {
- Interpreter.debug("End of File!");
- RETURN true;
- }
- |
- BlockStatement() {
- RETURN false;
- }
- }
- <DEFAULT >SPECIAL_TOKEN :
- {
- < SO_VERY_SPECIAL_002 : "NOTREALLY002" >
- }
- /*****************************************
- * THE JAVA LANGUAGE GRAMMAR STARTS HERE *
- *****************************************/
- /*
- Gather modifiers FOR a class, method, OR field.
- I lookahead is true THEN we are being called AS part of a lookahead AND we
- should NOT enforce any rules. Otherwise we validate based on context
- (field, method, class)
- */
- Modifiers Modifiers( INT context, boolean lookahead ) #void:
- {
- Modifiers mods = null;
- PushLexicalState(JAVA);
- }
- {
- (
- (
- "private" | "protected" | "public" | "synchronized" | "final"
- | "native" | "transient" | "volatile" | "abstract" | "static"
- | "strictfp" | "friend" | "synthetic"
- ) {
- IF ( !lookahead )
- try {
- IF ( mods == null ) mods = new Modifiers();
- mods.addModifier( context, getToken(0).image );
- } catch ( IllegalStateException e ) {
- throw createParseException( e.getMessage() );
- }
- }
- )* {
- PopLexicalState(JAVA);
- RETURN mods;
- }
- }
- /**
- */
- void ClassDeclaration() #ClassDeclaration :
- {
- Modifiers mods;
- Token name;
- INT numInterfaces;
- PushLexicalState(JAVA);
- }
- {
- mods = Modifiers( Modifiers.CLASS, false )
- ( "class" | "interface" { jjtThis.isInterface=true; } )
- name=GETIDENT()
- [ "extends" AmbiguousName() { jjtThis.extend = true; } ]
- [ "implements" numInterfaces=NameList()
- { jjtThis.numInterfaces=numInterfaces; } ]
- Block()
- {
- jjtThis.modifiers = mods;
- jjtThis.setName(name.image);
- PopLexicalState(JAVA);
- }
- }
- void MethodDeclaration() #MethodDeclaration :
- {
- Token t = null;
- Modifiers mods;
- INT count;
- PushLexicalState(JAVA);
- }
- {
- mods = Modifiers( Modifiers.METHOD, false ) { jjtThis.modifiers = mods; }
- (
- LOOKAHEAD( GETIDENT() "(" )
- t = GETIDENT() { jjtThis.setName(t.image); }
- |
- ReturnType()
- t = GETIDENT() { jjtThis.setName(t.image); }
- )
- FormalParameters()
- [ "throws" count=NameList() { jjtThis.numThrows=count; } ]
- ( Block() | ";" )
- {
- PopLexicalState(JAVA);
- }
- }
- void PackageDeclaration () #PackageDeclaration:
- { PushLexicalState(JAVA);}
- {
- "package" AmbiguousName()
- {
- PopLexicalState(JAVA);
- }
- }
- void ImportDeclaration() #ImportDeclaration :
- {
- Token s = null;
- Token t = null;
- Token i = null;
- PushLexicalState(JAVA);
- }
- {
- LOOKAHEAD( 3 )
- [ s = "static" ] i=<IMPORT> AmbiguousName() [ t = "." "*" ] ";"
- {
- IF ( s != null ) jjtThis.staticImport = true;
- IF ( t != null ) jjtThis.importPackage = true;
- PopLexicalState(JAVA);
- }
- |
- // bsh super import statement
- "import" "*" ";" {
- jjtThis.superImport = true;
- PopLexicalState(JAVA);
- }
- }
- void VariableDeclarator() #VariableDeclarator :
- {
- Token t;
- }
- {
- t=GETIDENT() [ VariableInitializerWithE() ]
- {
- jjtThis.setName(t.image);
- }
- }
- /*
- this originally handled postfix array dimensions...
- void VariableDeclaratorId() #VariableDeclaratorId :
- { Token t; }
- {
- t=GETIDENT() { jjtThis.setName(t.image); }
- ( "[" "]" { jjtThis.addUndefinedDimension(); } )*
- }
- */
- void VariableInitializerWithE() #void:
- {
- }
- {
- LOOKAHEAD("->" | "-->") I6ArrayInit()
- |
- "=" VariableInitializer()
- }
- void VariableInitializerWithE_Optional() #void:
- {
- }
- {
- LOOKAHEAD("->" | "-->") I6ArrayInit()
- |
- ["="] VariableInitializer()
- }
- void VariableInitializer() #void:
- {}
- {
- ArrayInitializer()
- |
- Expression()
- }
- void ArrayInitializer() #ArrayInitializer :
- {}
- {
- "{" [ VariableInitializer()
- ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}"
- }
- void FormalParameters() #FormalParameters :
- {}
- {
- "(" [ FormalParameter() ( "," FormalParameter() )* ] ")"
- }
- void FormalParameter() #FormalParameter :
- { Token t; }
- {
- // added [] TO Type FOR bsh. Removed [ final ] - is that legal?
- LOOKAHEAD(2) Type() t=GETIDENT() { jjtThis.setName(t.image); }
- |
- t=GETIDENT() { jjtThis.setName(t.image); }
- }
- /*
- Type, name AND expression syntax follows.
- */
- void Type() #Type :
- { }
- {
- /*
- The embedded lookahead is (was?) necessary TO disambiguate FOR
- PrimaryPrefix. ( )* is a choice point. It took me a WHILE TO
- figure out where TO put that. This stuff is annoying.
- */
- (PrimitiveType() | AmbiguousName() )
- ( LOOKAHEAD(2) "[" "]" { jjtThis.addArrayDimension(); } )*
- }
- /*
- Originally called ResultType in the grammar
- */
- void ReturnType() #ReturnType :
- { }
- {
- "void" { jjtThis.isVoid = true; }
- |
- Type()
- }
- void PrimitiveType() #PrimitiveType :
- { } {
- "boolean" { jjtThis.type = Boolean.TYPE; }
- | "char" { jjtThis.type = Character.TYPE; }
- | "byte" { jjtThis.type = BYTE.TYPE; }
- | "short" { jjtThis.type = Short.TYPE; }
- | "int" { jjtThis.type = INTEGER.TYPE; }
- | "long" { jjtThis.type = LONG.TYPE; }
- | "float" { jjtThis.type = FLOAT.TYPE; }
- | "double" { jjtThis.type = Double.TYPE; }
- }
- BSHAmbiguousName AmbiguousName() #AmbiguousName :
- /*
- A lookahead of 2 is required below since "Name" can be followed by a ".*"
- when used in the context of an "ImportDeclaration".
- */
- {
- Token t;
- StringBuffer s;
- }
- {
- t = GETIDENT() {
- s = new StringBuffer(t.image);
- }
- ( LOOKAHEAD(2) "." t = GETIDENT() { s.append("."+t.image); } )* {
- jjtThis.text = s.toString();
- RETURN jjtThis;
- }
- }
- INT NameList() #void:
- { INT count = 0; }
- {
- AmbiguousName() { ++count; } ( "," AmbiguousName() { ++count; } )*
- { RETURN count; }
- }
- /*
- * Expression syntax follows.
- */
- void Expression() #void:
- { }
- {
- /**
- SYNTACTIC_LOOKAHEAD
- Note: the original grammar was cheating here AND we've fixed that,
- but AT the expense of another syntactic lookahead.
- */
- LOOKAHEAD( PrimaryExpression() AssignmentOperator() )
- Assignment()
- |
- ConditionalExpression()
- }
- void Assignment() #Assignment :
- { INT op ; }
- {
- PrimaryExpression()
- op = AssignmentOperator() { jjtThis.setOperatorKind( op); }
- // Add this FOR blocks, e.g. foo = { };
- //( Expression() | Block() )
- Expression()
- }
- INT AssignmentOperator() #void:
- { Token t; }
- {
- ( "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "&=" | "^=" | "|=" |
- "<<=" | "@left_shift_assign" | ">>=" | "@right_shift_assign" |
- ">>>=" | "@right_unsigned_shift_assign" )
- {
- t = getToken(0);
- RETURN t.kind;
- }
- }
- void ConditionalExpression() #void:
- { }
- {
- ConditionalOrExpression() [LOOKAHEAD(3) "?" Expression() ":" ConditionalExpression()
- #TernaryExpression(3) ]
- }
- void ConditionalOrExpression() #void:
- { Token t=null; }
- {
- ConditionalAndExpression()
- (LOOKAHEAD(2) ( t = "||" | t = "@or" )
- ConditionalAndExpression()
- { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
- }
- void ConditionalAndExpression() #void:
- { Token t=null; }
- {
- InclusiveOrExpression()
- (LOOKAHEAD(2) ( t = "&&" | t = "@and" )
- InclusiveOrExpression()
- { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
- }
- void InclusiveOrExpression() #void:
- { Token t=null; }
- {
- ExclusiveOrExpression()
- (LOOKAHEAD(2) ( t = "|" | t = "@bitwise_or" )
- ExclusiveOrExpression()
- { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
- }
- void ExclusiveOrExpression() #void:
- { Token t=null; }
- {
- AndExpression() (LOOKAHEAD(2) t="^" AndExpression()
- { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
- }
- void AndExpression() #void:
- { Token t=null; }
- {
- EqualityExpression()
- (LOOKAHEAD(2) ( t = "&" | t = "@bitwise_and" )
- EqualityExpression()
- { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
- }
- void EqualityExpression() #void:
- { Token t = null; }
- {
- InstanceOfExpression() ( LOOKAHEAD(2) ( t= "==" | t= "!=" ) InstanceOfExpression()
- { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2)
- )*
- }
- void InstanceOfExpression() #void:
- { Token t = null; }
- {
- RelationalExpression()
- [ LOOKAHEAD(2) t= "instanceof" Type() { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) ]
- }
- void RelationalExpression() #void:
- { Token t = null; }
- {
- ShiftExpression()
- ( ( t = "<" | t = "@lt" | t = ">" | t = "@gt" | t= "~=" | t= "or" |
- t = "<=" | t = "@lteq" | t = ">=" | t = "@gteq" )
- ShiftExpression()
- { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
- }
- void ShiftExpression() #void:
- { Token t = null; }
- {
- AdditiveExpression()
- ( LOOKAHEAD(2) ( t = "<<" | t = "@left_shift" | t = ">>" | t = "@right_shift" |
- t = ">>>" | t = "@right_unsigned_shift" )
- AdditiveExpression()
- { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
- }
- void AdditiveExpression() #void:
- { Token t = null; }
- {
- MultiplicativeExpression()
- ( LOOKAHEAD(2) ( t= "+" | t= Inform6Infixes() | t= "-" ) MultiplicativeExpression() { jjtThis.setOperatorKind( t.kind); }
- #BinaryExpression(2)
- )*
- }
- void MultiplicativeExpression() #void:
- { Token t = null; }
- {
- UnaryExpression()
- ( LOOKAHEAD(2) ( t= "*" | t= "/" | t= "%" ) UnaryExpression() { jjtThis.setOperatorKind( t.kind); } #BinaryExpression(2) )*
- }
- void UnaryExpression() #void:
- { Token t = null; }
- {
- LOOKAHEAD(2) ( t="+" | t="-" ) UnaryExpression() { jjtThis.setOperatorKind( t.kind); } #UnaryExpression(1)
- |
- PreIncrementExpression()
- |
- PreDecrementExpression()
- |
- UnaryExpressionNotPlusMinus()
- }
- void PreIncrementExpression() #void:
- { Token t = null; }
- {
- t="++" PrimaryExpression()
- { jjtThis.setOperatorKind( t.kind); } #UnaryExpression(1)
- }
- void PreDecrementExpression() #void:
- { Token t = null; }
- {
- t="--" PrimaryExpression()
- { jjtThis.setOperatorKind( t.kind); } #UnaryExpression(1)
- }
- void UnaryExpressionNotPlusMinus() #void:
- { Token t = null; }
- {
- ( t="~" | t="!" ) UnaryExpression()
- { jjtThis.setOperatorKind( t.kind); } #UnaryExpression(1)
- |
- // SYNTACTIC_LOOKAHEAD
- LOOKAHEAD( CastLookahead() ) CastExpression()
- |
- PostfixExpression()
- }
- // This production is TO determine lookahead only.
- void CastLookahead() #void: { }
- {
- LOOKAHEAD(2) "(" PrimitiveType()
- |
- // SYNTACTIC_LOOKAHEAD
- LOOKAHEAD( "(" AmbiguousName() "[" ) "(" AmbiguousName() "[" "]"
- |
- "(" AmbiguousName() ")" ( "~" | "!" | "("| /* "this" | "super" | */ "new" | GETIDENT() | Literal() )
- }
- void PostfixExpression() #void:
- { Token t = null; }
- {
- // SYNTACTIC_LOOKAHEAD
- LOOKAHEAD( PrimaryExpression() ("++"|"--") )
- PrimaryExpression()
- ( t="++" | t="--" ) {
- jjtThis.setOperatorKind( t.kind); jjtThis.postfix = true; } #UnaryExpression(1)
- |
- PrimaryExpression()
- }
- void CastExpression() #CastExpression :
- { }
- {
- // SYNTACTIC_LOOKAHEAD
- LOOKAHEAD( "(" PrimitiveType() ) "(" Type() ")" UnaryExpression()
- |
- "(" Type() ")" UnaryExpressionNotPlusMinus()
- }
- void PrimaryExpression() #PrimaryExpression : { }
- {
- PrimaryPrefix() ( PrimarySuffix() )*
- }
- void MethodInvocation() #MethodInvocation : { }
- {
- AmbiguousName() Arguments()
- }
- void PrimaryPrefix() #void: { }
- {
- Literal()
- |
- "(" Expression() ")"
- |
- AllocationExpression()
- |
- // SYNTACTIC_LOOKAHEAD
- LOOKAHEAD( MethodInvocation() )
- MethodInvocation()
- |
- LOOKAHEAD( Type() "." "class" )
- Type()
- |
- AmbiguousName()
- /*
- |
- LOOKAHEAD( "void" "." "class" )
- */
- }
- void PrimarySuffix() #PrimarySuffix :
- {
- Token t = null;
- }
- {
- LOOKAHEAD(2)
- "." "class" {
- jjtThis.setOperatorKind(BSHPrimarySuffix.CLASS);
- }
- |LOOKAHEAD(3)
- "[" Expression() "]" {
- jjtThis.setOperatorKind(BSHPrimarySuffix.INDEX);
- }
- |LOOKAHEAD(2) (t= "-->" | t= "->" )
- Expression() {
- jjtThis.setOperatorKind(t.kind);
- }
- |
- // Field access OR method invocation
- LOOKAHEAD(2) "." t = GETIDENT() [ Arguments() ] {
- jjtThis.setOperatorKind(BSHPrimarySuffix.NAME);
- jjtThis.field = t.image;
- }
- |
- LOOKAHEAD(3) "{" Expression() "}" {
- jjtThis.setOperatorKind(BSHPrimarySuffix.PROPERTY);
- }
- /*
- FOR inner classes
- |
- LOOKAHEAD(2)
- "." AllocationExpression()
- */
- }
- void Literal() #Literal :
- {
- Token x;
- boolean b;
- STRING literal;
- char ch;
- }
- {
- x = <INTEGER_LITERAL>
- {
- literal = x.image;
- ch = literal.charAt(literal.length()-1);
- IF(ch == 'l' || ch == 'L')
- {
- literal = literal.substring(0,literal.length()-1);
- // This really should be LONG.decode, but there isn't one. As a result,
- // HEX AND octal literals ending in 'l' or 'L' don't work.
- jjtThis.value = new Primitive( new LONG( literal ).longValue() );
- }
- ELSE
- try {
- try {
- jjtThis.value = new Primitive(
- INTEGER.decode( literal ).intValue() );
- } catch ( NumberFormatException e ) {
- jjtThis.value = new java.math.BigInteger( literal ) ;
- }
- } catch ( NumberFormatException e ) {
- throw createParseException(
- "Error or number too big for integer type: "+ literal );
- }
- }
- |
- x = <FLOATING_POINT_LITERAL>
- {
- literal = x.image;
- ch = literal.charAt(literal.length()-1);
- IF(ch == 'f' || ch == 'F')
- {
- literal = literal.substring(0,literal.length()-1);
- jjtThis.value = new Primitive( new FLOAT( literal ).floatValue() );
- }
- ELSE
- {
- IF(ch == 'd' || ch == 'D')
- literal = literal.substring(0,literal.length()-1);
- try {
- jjtThis.value = new Primitive( new Double( literal ).doubleValue() );
- } catch ( NumberFormatException e ) {
- jjtThis.value = new java.math.BigDecimal( literal ) ;
- }
- }
- }
- |
- x = <STRING_LITERAL_SQ> {
- try {
- jjtThis.stringSetupI6( x.image.substring(1, x.image.length() - 1) );
- } catch ( Exception e ) {
- throw createParseException("Error parsing string: "+x.image);
- }
- }
- |
- x = <CHARACTER_LITERAL> {
- try {
- jjtThis.charSetup( x.image.substring(1, x.image.length() - 1) );
- } catch ( Exception e ) {
- throw createParseException("Error parsing character: "+x.image);
- }
- }
- |
- x = <STRING_LITERAL> {
- try {
- jjtThis.stringSetup( x.image.substring(1, x.image.length() - 1) );
- } catch ( Exception e ) {
- throw createParseException("Error parsing string: "+x.image);
- }
- }
- |
- b = BooleanLiteral() {
- jjtThis.value = new Primitive( b ); }
- |
- NullLiteral() {
- jjtThis.value = Primitive.NULL;
- }
- |
- VoidLiteral() {
- jjtThis.value = Primitive.VOID; }
- }
- boolean BooleanLiteral() #void:
- {}
- {
- "true" { RETURN true; }
- |
- "false" { RETURN false; }
- }
- void NullLiteral() #void:
- {}
- {
- "null"
- }
- void VoidLiteral() #void:
- {}
- {
- "void"
- }
- void Arguments() #Arguments :
- { }
- {
- "(" [ ArgumentList() ] ")"
- }
- // leave these on the stack FOR Arguments() TO handle
- void ArgumentList() #void:
- { }
- {
- Expression()
- ( "," Expression() )*
- }
- void AllocationExpression() #AllocationExpression :
- { }
- {
- LOOKAHEAD(2)
- "new" PrimitiveType() ArrayDimensions()
- |
- "new" AmbiguousName()
- (
- ArrayDimensions()
- |
- // SYNTACTIC_LOOKAHEAD
- Arguments() [ LOOKAHEAD(2) Block() ]
- )
- }
- void ArrayDimensions() #ArrayDimensions :
- {}
- {
- // e.g. INT [4][3][][];
- LOOKAHEAD(2)
- ( LOOKAHEAD(2) "[" Expression() "]" { jjtThis.addDefinedDimension(); } )+
- ( LOOKAHEAD(2) "[" "]" { jjtThis.addUndefinedDimension(); } )*
- |
- // e.g. INT [][] { {1,2}, {3,4} };
- ( "[" "]" { jjtThis.addUndefinedDimension(); } )+ ArrayInitializer()
- }
- /*
- * Statement syntax follows.
- */
- void Statement() #void: { }
- {
- LOOKAHEAD({isParsingI6()}) I6BlockStatement()
- |
- LOOKAHEAD({!isParsingI6()}) JavaStatement()
- }
- void JavaStatement() #void: {
- PushLexicalState(JAVA);
- }
- {
- (
- JavaSpecificStatementNoExpressions()
- |
- EmptyStatement()
- |
- LOOKAHEAD(2) LabeledStatement()
- |
- StatementExpression() ";"
- )
- {
- PopLexicalState(JAVA);
- }
- }
- void JavaSpecificStatementNoExpressions() #void:
- {
- }
- {
- Block()
- |
- I6SwitchStatement()
- |
- LOOKAHEAD(IfStatement()) IfStatement()
- |
- WhileStatement()
- |
- DoStatement()
- |
- LOOKAHEAD ( { isRegularForStatement() } )
- ForStatement()
- |
- EnhancedForStatement()
- |
- BreakStatement()
- |
- ContinueStatement()
- |
- ReturnStatement()
- |
- SynchronizedStatement()
- |
- ThrowStatement()
- |
- TryStatement()
- }
- void LabeledStatement() #void:
- {}
- {
- GETIDENT_NOKW() ":" Statement()
- }
- void Block() #Block :
- {}
- {
- "{" ( BlockStatement() )* "}"
- }
- void BlockStatement() #void: {}
- {
- LOOKAHEAD({isParsingI6()}) I6BlockStatement()
- |
- LOOKAHEAD({!isParsingI6()}) JavaBlockStatement()
- }
- void JavaBlockStatement() #void:
- {
- }
- {
- // Allow BeanShell imports in any block
- ImportDeclaration()
- |
- // Allow BeanShell package declarations in any block
- PackageDeclaration()
- |
- FormalComment()
- |
- LOOKAHEAD( Modifiers( Modifiers.FIELD, true ) ( "class" | "interface" ) )
- ClassDeclaration()
- |
- LOOKAHEAD ( Modifiers( Modifiers.METHOD, true )
- ReturnType() GETIDENT() "("
- )
- MethodDeclaration()
- |
- LOOKAHEAD ( Modifiers( Modifiers.METHOD, true )
- GETIDENT() FormalParameters() [ "throws" NameList() ] "{"
- )
- MethodDeclaration()
- |
- // SYNTACTIC_LOOKAHEAD
- LOOKAHEAD( Modifiers( Modifiers.FIELD, true ) Type() VariableDeclarator() ( "," VariableDeclarator() )* ";" )
- TypedVariableDeclaration() ";"
- |
- JavaStatement()
- |
- I6ToplevelDeclaration()
- }
- void FormalComment() #FormalComment( retainComments ) :
- {
- Token t;
- }
- {
- t=<FORMAL_COMMENT_TOKEN> {
- jjtThis.setText(t.image);
- }
- }
- void EmptyStatement() #void:
- {}
- {
- ";"
- }
- void StatementExpression() #void:
- {
- }
- {
- StatementExpression_LOOSE()
- }
- void StatementExpression_LOOSE() #void:
- { }
- {
- /*
- This is looser than normal Java TO simplify the grammar. This allows
- us TO type arbitrary expressions on the command line, e.g. "1+1;"
- We should turn this off in the implementation in strict java mode.
- */
- Expression()
- /*
- // This was the original Java grammar.
- // Original comment:
- // The last expansion of this production accepts more than the legal
- // Java expansions FOR StatementExpression.
- PreIncrementExpression()
- |
- PreDecrementExpression()
- |
- // SYNTACTIC_LOOKAHEAD
- LOOKAHEAD( PrimaryExpression() AssignmentOperator() )
- Assignment() { }
- |
- PostfixExpression()
- */
- }
- void StatementExpression_STRICT() #void:
- { }
- {
- /*
- This is looser than normal Java TO simplify the grammar. This allows
- us TO type arbitrary expressions on the command line, e.g. "1+1;"
- We should turn this off in the implementation in strict java mode.
- */
- // This was the original Java grammar.
- // Original comment:
- // The last expansion of this production accepts more than the legal
- // Java expansions FOR StatementExpression.
- PreIncrementExpression()
- |
- PreDecrementExpression()
- |
- // SYNTACTIC_LOOKAHEAD
- LOOKAHEAD( PrimaryExpression() AssignmentOperator() )
- Assignment() { }
- |
- PostfixExpression()
- }
- void SwitchStatement() #SwitchStatement :
- {}
- {
- "switch" "(" Expression() ")" "{"
- (SwitchLabel() ( BlockStatement() )* )*
- "}"
- }
- void SwitchLabel() #SwitchLabel :
- {}
- {
- "case" Expression() ":"
- |
- < KW_DEFAULT > ":" { jjtThis.isDefault = true; }
- }
- void IfStatement() #IfStatement :
- /*
- * The disambiguating algorithm of JavaCC automatically binds dangling
- * ELSE's to the innermost if statement. The LOOKAHEAD specification
- * is TO tell JavaCC that we know what we are doing.
- */
- {}
- {
- "if" "(" Expression() ")" Statement() [ "else" Statement() ]
- }
- void WhileStatement() #WhileStatement :
- {}
- {
- "while" "(" Expression() ")" Statement()
- }
- /*
- DO statement is just a WHILE statement with a special hook TO execute
- AT least once.
- */
- void DoStatement() #WhileStatement :
- {}
- {
- "do" Statement() ( "while" | "until" ) "(" Expression() ")" ";"
- { jjtThis.isDoStatement=true; }
- }
- void ForStatement() #ForStatement :
- { Token t = null; }
- {
- "for" "(" [ ForInit() { jjtThis.hasForInit=true; } ]
- ";" [ Expression() { jjtThis.hasExpression=true; } ]
- ";" [ ForUpdate() { jjtThis.hasForUpdate=true; } ] ")"
- Statement()
- }
- /*
- The new JDK1.5 enhanced FOR statement.
- e.g. FOR( INT a : arrayOfInts ) { }
- We also support loose typing of the iterator var FOR BeanShell
- e.g. FOR( a : arrayOfInts ) { }
- */
- void EnhancedForStatement() #EnhancedForStatement :
- { Token t = null; }
- {
- LOOKAHEAD( 4 ) // look ahead FOR the ":" before deciding
- "for" "(" t=GETIDENT() ":" Expression() ")"
- Statement() { jjtThis.varName = t.image; }
- |
- "for" "(" Type() t=GETIDENT() ":" Expression() ")"
- Statement() { jjtThis.varName = t.image; }
- }
- void ForInit() #void:
- { Token t = null; }
- {
- // SYNTACTIC_LOOKAHEAD
- LOOKAHEAD( Modifiers( Modifiers.FIELD, true ) Type() GETIDENT() )
- TypedVariableDeclaration()
- |
- StatementExpressionList()
- }
- /**
- Declared a typed variable.
- Untyped variables are NOT declared per-se but are handled by the part
- of the grammar that deals with assignments.
- */
- void TypedVariableDeclaration() #TypedVariableDeclaration :
- {
- Token t = null;
- Modifiers mods;
- }
- {
- mods = Modifiers( Modifiers.FIELD, false )
- Type() VariableDeclarator() ( "," VariableDeclarator() )*
- {
- jjtThis.modifiers = mods;
- }
- }
- void StatementExpressionList() #StatementExpressionList :
- {}
- {
- StatementExpression() ( "," StatementExpression() )*
- }
- void ForUpdate() #void:
- {}
- {
- StatementExpressionList()
- }
- void BreakStatement() #ReturnStatement :
- {}
- {
- "break" [ GETIDENT() ] ";" { jjtThis.setOperatorKind(BREAK); }
- }
- void ContinueStatement() #ReturnStatement :
- {}
- {
- "continue" [ GETIDENT() ] ";" { jjtThis.setOperatorKind( CONTINUE); }
- }
- void ReturnStatement() #ReturnStatement :
- {}
- {
- "return" [ Expression() ] ";" { jjtThis.setOperatorKind( RETURN); }
- }
- void SynchronizedStatement() #Block :
- {
- }
- {
- "synchronized" "(" Expression() ")" Block() {
- jjtThis.isSynchronized=true;
- }
- }
- void ThrowStatement() #ThrowStatement :
- {}
- {
- "throw" Expression() ";"
- }
- void TryStatement() #TryStatement:
- /*
- Semantic check required here TO make sure that AT least one
- finally/catch is present. (You can have a try with finally AND no catch).
- */
- { boolean closed = false; }
- {
- "try" Block()
- ( "catch" "(" FormalParameter() ")" Block() { closed = true; } )*
- [ "finally" Block() { closed = true; } ]
- {
- IF ( !closed ) throw generateParseException();
- }
- }
- /*INFORM6 BEGIN */
- void I6SwitchStatement() #SwitchStatement:
- {}
- {
- "switch" "(" Expression() ")" "{"
- (SwitchElement())*
- "}"
- }
- void SwitchElement() #void:
- {
- }
- {
- <KW_DEFAULT> ":" (I6BlockStatement())* #SwitchLabel
- | <CASE> SwitchLabel_data() ":" (I6BlockStatement())* #SwitchLabel
- | SwitchLabel_data() ":" I6BlockStatement() #SwitchLabel
- }
- void SwitchLabel_data() #void:
- {}
- {
- Expression() ("," Expression())*
- }
- Object LineResult() #LineResult:
- {
- Object bs;
- }
- {
- <EOF> {
- //Interpreter.debug("End of File!");
- RETURN true;
- }
- |
- BlockStatement() {
- RETURN jjtThis;
- }
- }
- /*
- void I6FormalParameters() #I6FormalParameters :
- {}
- {
- ( I6FormalParameter() )*
- }
- */
- void I6FormalParameter() #FormalParameter :
- { Token t; }
- {
- t=GETIDENT() { jjtThis.setName(t.image); }
- }
- void I6FormalParameters() #FormalParameters :
- { }
- {
- [ I6FormalParameter() ( I6FormalParameter() )* ]
- }
- void I6Expressions() #void :
- {}
- {
- I6Expression() ( I6Expression() )*
- }
- void I6Expression() #void:
- { }
- {
- // "(" ")" #ArgumentList
- //|
- Expression()
- }
- void I6MethodDeclaration() #MethodDeclaration :
- { Token t; }
- {
- "[" t=GETIDENT() I6FormalParameters() ";" I6Block() "]" ";"
- {
- jjtThis.setName(t.image);
- jjtThis.isLanguageI6 = true;
- }
- }
- void I6Block() #Block :
- {}
- {
- (LOOKAHEAD(2) I6BlockStatement())*
- }
- /*void I6ForStatement() #I6ForStatement :
- { Token t = null; }
- {
- "for"
- "("
- [ I6ForInit() { jjtThis.hasForInit=true; } ]
- (":"|";") [ I6ForExpression() { jjtThis.hasExpression=true; } ]
- (":"|";") [ I6ForUpdate() { jjtThis.hasForUpdate=true; } ]
- ")"
- Statement()
- }*/
- /*
- void I6ForStatement() #I6ForStatement :
- { }
- {
- "for" "(" [ I6ForInit() ] ":" (Expression())* ":" [ I6ForUpdate() ] ")" Statement()
- }
- void I6ForInit() #I6ForInit :
- {}
- {
- ForInit()
- }
- void I6ForUpdate() #I6ForUpdate :
- {}{
- ForUpdate()
- }
- void I6ForExpression() #I6ForExpression :
- {}{
- Expression()
- } */
- void RTrueStatement() #ReturnStatement(true) :
- {}
- {
- "rtrue" ";"
- }
- void RFalseStatement() #ReturnStatement(false) :
- {}
- {
- "rfalse" ";"
- }
- void PushToLabel() #PushToLabel:
- {Token t = null;
- }
- {
- "-->" t=GETIDENT() {setText(jjtThis,t);}
- }
- void AsmStatement() #void :
- {}
- {
- "@" AsmStatementWithoutAt()
- }
- void AsmStatementWithoutAt() #AsmStatement :
- {}
- {
- (<STRING_LITERAL>|GETIDENT()) I6Expressions() [PushToLabel()] ";"
- }
- void I6ToplevelDeclaration() #void:
- {}
- {
- I6MethodDeclaration()
- |
- I6ClassDeclaration()
- }
- /*
- Class Money(10)
- with name 'money' 'cash' 'gold',
- sing_name 'coin' 'dollar' 'zorkmid',
- plur_name 'coins' 'dollars' 'zorkmids',
- parse_name [ wd qty b p s;
- qty = TryNumber(wn);
- ....
- Class Fuse
- with name 'fuse' 'fuses//p',
- short_name "fuse",
- list_together [;
- IF (inventory_stage == 1) {
- PRINT "several fuses";
- IF (c_style & NEWLINE_BIT) new_line;
- rtrue;
- }
- ];
- Fuse ->;
- Fuse ->;
- */
- void I6ClassDeclaration() #I6ClassDeclaration :
- {}
- {
- "CLASsarray"
- }
- void ID() #PrimaryExpression :
- {
- }
- {
- AmbiguousName()
- }
- void I6Assignment() #I6VarDecl :
- {}
- {
- LOOKAHEAD(<ARRAY>) I6VarDecl() [I6ArrayInit()] ";"
- |
- I6VarDecl() [VariableInitializerWithE_Optional()] ";"
- }
- void I6VarDecl() #I6VarDecl :
- {}
- {
- <ARRAY> ID()
- |
- I6Type() ID()
- }
- void I6Type() #AmbiguousName :
- {}
- {
- <GLOBAL> | < CONSTANT > | < KW_DEFAULT > | <IDENTIFIER_TOKEN>
- }
- void I6FileDirective() #I6FileDirective :
- {}
- {
- (<SWITCHES> | < RELEASE > | < SERIAL > | < H_INCLUDE >)
- Literal() ";"
- |
- ( < 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" ";"
- }
- void GotoStatement() #GotoStatement:
- {Token t;}
- {
- ( "jump" | "goto" | "jsr" ) [ t=GETIDENT() {setText(jjtThis,t);} ] ";"
- }
- void I6ArrayInit() #void:
- {
- }
- {
- LOOKAHEAD(2) Type() Expression()
- |
- "->" I6Expressions()
- |
- "-->" I6Expressions()
- }
- void I6SpecificStatement() #void :
- {
- }
- {
- "@" AsmStatementWithoutAt()
- | LOOKAHEAD("[") I6MethodDeclaration()
- | I6VarDecl()
- | GotoStatement()
- | I6ForStatement()
- | I6VerbDeclaration()
- | I6FileDirective()
- | "#define" GETIDENT() VariableInitializerWithE_Optional() ";" #Statement
- | I6KeywordArgSepComma() I6Expression() ("," Expression())* ";" #Statement
- | I6KeywordArgSepSpaces() I6Expression() ( Expression())* ";" #Statement
- | I6ObjectDecl()
- | I6ArglessStatement() #Statement
- | I6Label()
- }
- void I6ForStatement() #ForStatement :
- { Token t = null;
- Token rs = null; }
- {
- "for" "(" [ ForInit() { jjtThis.hasForInit=true; } ]
- ":" [ Expression() ("," Expression())* { jjtThis.hasExpression=true; } ]
- ":" [ I6ForUpdate() { jjtThis.hasForUpdate=true; } ] ")"
- I6Statement()
- }
- void I6ForUpdate() #void :
- {
- }
- {
- // I6BlockStatement() ( ";" I6BlockStatement() )*
- //|
- ForUpdate()
- }
- void I6Statement() #void :
- {
- PushLexicalState(INFORM6);
- }
- {(
- "{" I6Block() "}"
- |
- I6BlockStatement())
- {
- PopLexicalState(INFORM6);
- }
- }
- void I6UnspecificStatement() #Statement :
- {}
- {(
- GETIDENT() (I6Expression())* ";")
- }
- /*
- verb 'why'
- * 'don^t' 'you' -> WhyDontYou
- * 'can^t' 'i//' -> WhyCantI
- * -> What;
- */
- void I6VerbDeclaration() #I6VerbDeclaration:
- {
- }
- {
- <VERB> [ <META> { jjtThis.set("isMeta",true); } ]
- (Literal())* (VerbAlias())* ";"
- }
- void VerbAlias()#VerbAlias:
- {
- }
- {
- "*" (Literal())* "->" GETIDENT()
- }
- void I6Label()#I6Label :
- {Token t;}
- {
- "." t=GETIDENT() {setText(jjtThis,t);} ";"
- }
- void I6ArglessStatement() #void: {
- } { RTrueStatement() | RFalseStatement()
- }
- Token Inform6Infixes() #void:
- {
- Token t;
- PushLexicalState(INFORM6);
- }
- {
- (t= "or" | t= "to" | t= "-->" | t= "->")
- {
- PopLexicalState(INFORM6);
- RETURN t;
- }
- }
- void I6BlockStatement() #void:
- {
- }
- {
- I6BlockStatement_NonLocally()
- }
- void I6BlockStatement_NonLocally() #void:
- {
- }
- {
- I6SpecificStatement()
- |
- JavaStatement()
- |
- I6UnspecificStatement()
- }
- void I6BlockStatement_Locally() #void:
- {
- }
- {
- I6SpecificStatement()
- |
- JavaSpecificStatementNoExpressions()
- |
- LOOKAHEAD(";") ";" #Statement
- |
- LOOKAHEAD(Expression() ";") Expression() ";"
- |
- LOOKAHEAD(2) LabeledStatement()
- |
- I6UnspecificStatement()
- }
- /*
- Room study "Your study"
- with description "There is a doorway to the east of this austere room.",
- compass_look [ obj;
- IF (obj == e_obj) "You see a doorway.";
- IF (obj == n_obj OR s_obj OR w_obj) "You see the wall.";
- ],
- e_to hallway;
- Object -> "sack"
- with name 'sack',
- invent [;
- ! When listing objects in the player's inventory
- IF (c_style&FULLINV_BIT) rfalse;
- ! When listing objects AT the END of a room description
- IF (inventory_stage == 1) switch (children(self)) {
- 0: PRINT "an empty sack";
- 1: PRINT "a sack containing ", (a) child(self);
- default: PRINT "an assortment of objects in a sack";
- }
- rtrue;
- ],
- has container open;
- */
- Token I6ObjectType() #void:
- {
- Token t;
- }
- {
- ( t= < PC_ROOM: "Room" > | t =< PC_Object: "Object" > )
- {
- RETURN t;
- }
- }
- void I6ObjectDecl() #ObjectDecl:
- {
- Token c;
- Token t;
- STRING s;
- }
- {
- c=I6ObjectType() (t= "->" | t=GETIDENT() ) <STRING_LITERAL> ObjectDeclList() ";"
- {
- }
- }
- void ObjectDeclList() #void:
- {
- }
- {
- <WITH: "with"> ObjectDeclWith() ( "," ObjectDeclWith() )*
- |
- <HAS: "has"> ObjectDeclHas() ( ObjectDeclHas() )*
- }
- void ObjectDeclWith() #ObjectDeclWith:
- {
- }
- {
- <WITHW: "with"> ObjectDeclWith() ( "," ObjectDeclWith() )*
- |
- <HASW: "has"> ObjectDeclHas() ( ObjectDeclHas() )*
- |
- GETIDENT() ExpressionOrMethodDecl()
- }
- void ObjectDeclHas() #ObjectDeclHas:
- {
- }
- {
- GETIDENT()
- }
- void ExpressionOrMethodDecl() #void:
- {
- }
- {
- Expression()
- |
- "[" I6FormalParameters() ";" I6Block() "]"
- }
- /*
- Gather an Identifier
- */
- Token GETIDENT_NOKW() #void:
- { Token t;
- // PushLexicalState(IDENTIFIER_STATE);
- }
- {
- ( t=<IDENTIFIER_TOKEN>
- | t=I6Token()
- ) {
- // PopLexicalState(IDENTIFIER_STATE);
- //jjtThis.setText(t.image);
- RETURN t;
- }
- }
- <IDENTIFIER_STATE,JAVA,INFORM6,DEFAULT>TOKEN :
- {
- <IDENTIFIER_TOKEN: <LETTER> (<PART_LETTER>)* >
- }
- Token GETIDENT() #void:
- { Token t;
- // PushLexicalState(IDENTIFIER_STATE);
- }
- {
- ( t=<IDENTIFIER_TOKEN>
- | t=I6Token()
- | t=JavaKeyword()
- | t=SharedToken())
- {
- // PopLexicalState(IDENTIFIER_STATE);
- //jjtThis.setText(t.image);
- RETURN t;
- }
- }
- /*INFORM6 END */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement