⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javaparser.java

📁 jboss规则引擎
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
// $ANTLR 3.0ea8 /Users/bob/checkouts/jbossrules/drools-compiler/src/main/resources/org/drools/semantics/java/parser/java.g 2006-04-10 01:50:29
/*
 * Copyright 2005 JBoss Inc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.drools.semantics.java.parser;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.antlr.runtime.BitSet;
import org.antlr.runtime.CommonToken;
import org.antlr.runtime.DFA;
import org.antlr.runtime.EarlyExitException;
import org.antlr.runtime.FailedPredicateException;
import org.antlr.runtime.IntStream;
import org.antlr.runtime.MismatchedNotSetException;
import org.antlr.runtime.MismatchedSetException;
import org.antlr.runtime.MismatchedTokenException;
import org.antlr.runtime.MismatchedTreeNodeException;
import org.antlr.runtime.NoViableAltException;
import org.antlr.runtime.Parser;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenStream;

public class JavaParser extends Parser {
    public static final String[] tokenNames        = new String[]{"<invalid>", "<EOR>", "<DOWN>", "<UP>", "LBRACK", "RBRACK", "IDENT", "DOT", "STAR", "LCURLY", "SEMI", "RCURLY", "COMMA", "LPAREN", "RPAREN", "ASSIGN", "COLON", "PLUS_ASSIGN",
            "MINUS_ASSIGN", "STAR_ASSIGN", "DIV_ASSIGN", "MOD_ASSIGN", "SR_ASSIGN", "BSR_ASSIGN", "SL_ASSIGN", "BAND_ASSIGN", "BXOR_ASSIGN", "BOR_ASSIGN", "QUESTION", "LOR", "LAND", "BOR", "BXOR", "BAND", "NOT_EQUAL", "EQUAL", "LT", "GT", "LE",
            "GE", "SL", "SR", "BSR", "PLUS", "MINUS", "DIV", "MOD", "INC", "DEC", "BNOT", "LNOT", "NUM_INT", "CHAR_LITERAL", "STRING_LITERAL", "NUM_FLOAT", "WS", "SL_COMMENT", "ML_COMMENT", "DECIMAL_LITERAL", "HEX_LITERAL", "OCTAL_LITERAL",
            "DIGITS", "EXPONENT_PART", "FLOAT_TYPE_SUFFIX", "ESCAPE_SEQUENCE", "OCTAL_DIGIT", "UNICODE_CHAR", "HEX_DIGIT", "\'void\'", "\'boolean\'", "\'byte\'", "\'char\'", "\'short\'", "\'int\'", "\'float\'", "\'long\'", "\'double\'",
            "\'private\'", "\'public\'", "\'protected\'", "\'static\'", "\'transient\'", "\'final\'", "\'abstract\'", "\'native\'", "\'threadsafe\'", "\'synchronized\'", "\'volatile\'", "\'strictfp\'", "\'class\'", "\'extends\'", "\'interface\'",
            "\'implements\'", "\'this\'", "\'super\'", "\'throws\'", "\'if\'", "\'else\'", "\'for\'", "\'while\'", "\'do\'", "\'break\'", "\'continue\'", "\'return\'", "\'switch\'", "\'throw\'", "\'case\'", "\'default\'", "\'try\'", "\'finally\'",
            "\'catch\'", "\'instanceof\'", "\'true\'", "\'false\'", "\'null\'", "\'new\'"};
    public static final int      COMMA             = 12;
    public static final int      SR_ASSIGN         = 22;
    public static final int      MINUS             = 44;
    public static final int      LOR               = 29;
    public static final int      BNOT              = 49;
    public static final int      INC               = 47;
    public static final int      MOD               = 46;
    public static final int      OCTAL_LITERAL     = 60;
    public static final int      PLUS_ASSIGN       = 17;
    public static final int      QUESTION          = 28;
    public static final int      HEX_LITERAL       = 59;
    public static final int      BOR               = 31;
    public static final int      DOT               = 7;
    public static final int      SR                = 41;
    public static final int      FLOAT_TYPE_SUFFIX = 63;
    public static final int      RCURLY            = 11;
    public static final int      LCURLY            = 9;
    public static final int      CHAR_LITERAL      = 52;
    public static final int      BOR_ASSIGN        = 27;
    public static final int      STRING_LITERAL    = 53;
    public static final int      ASSIGN            = 15;
    public static final int      LE                = 38;
    public static final int      RPAREN            = 14;
    public static final int      STAR_ASSIGN       = 19;
    public static final int      NUM_INT           = 51;
    public static final int      LPAREN            = 13;
    public static final int      HEX_DIGIT         = 67;
    public static final int      ML_COMMENT        = 57;
    public static final int      PLUS              = 43;
    public static final int      SL_COMMENT        = 56;
    public static final int      BAND              = 33;
    public static final int      MINUS_ASSIGN      = 18;
    public static final int      NOT_EQUAL         = 34;
    public static final int      BAND_ASSIGN       = 25;
    public static final int      DIGITS            = 61;
    public static final int      DECIMAL_LITERAL   = 58;
    public static final int      IDENT             = 6;
    public static final int      MOD_ASSIGN        = 21;
    public static final int      WS                = 55;
    public static final int      BXOR_ASSIGN       = 26;
    public static final int      LT                = 36;
    public static final int      BSR               = 42;
    public static final int      GT                = 37;
    public static final int      BSR_ASSIGN        = 23;
    public static final int      SL_ASSIGN         = 24;
    public static final int      LAND              = 30;
    public static final int      LBRACK            = 4;
    public static final int      NUM_FLOAT         = 54;
    public static final int      SEMI              = 10;
    public static final int      GE                = 39;
    public static final int      LNOT              = 50;
    public static final int      DIV_ASSIGN        = 20;
    public static final int      UNICODE_CHAR      = 66;
    public static final int      DEC               = 48;
    public static final int      EQUAL             = 35;
    public static final int      ESCAPE_SEQUENCE   = 64;
    public static final int      EOF               = -1;
    public static final int      OCTAL_DIGIT       = 65;
    public static final int      RBRACK            = 5;
    public static final int      COLON             = 16;
    public static final int      SL                = 40;
    public static final int      DIV               = 45;
    public static final int      STAR              = 8;
    public static final int      BXOR              = 32;
    public static final int      EXPONENT_PART     = 62;

    public JavaParser(final TokenStream input) {
        super( input );
    }

    public String[] getTokenNames() {
        return JavaParser.tokenNames;
    }

    private final List identifiers = new ArrayList();

    public List getIdentifiers() {
        return this.identifiers;
    }

    public static final CommonToken IGNORE_TOKEN = new CommonToken( null,
                                                                    0,
                                                                    99,
                                                                    0,
                                                                    0 );
    private final List                    errors       = new ArrayList();

    private String                  source       = "unknown";

    public void setSource(final String source) {
        this.source = source;
    }

    public String getSource() {
        return this.source;
    }

    public void reportError(final RecognitionException ex) {
        // if we've already reported an error and have not matched a token
        // yet successfully, don't report any errors.
        if ( this.errorRecovery ) {
            //System.err.print("[SPURIOUS] ");
            return;
        }
        this.errorRecovery = true;

        this.errors.add( ex );
    }

    /** return the raw RecognitionException errors */
    public List getErrors() {
        return this.errors;
    }

    /** Return a list of pretty strings summarising the errors */
    public List getErrorMessages() {
        final List messages = new ArrayList();
        for ( final Iterator errorIter = this.errors.iterator(); errorIter.hasNext(); ) {
            messages.add( createErrorMessage( (RecognitionException) errorIter.next() ) );
        }
        return messages;
    }

    /** return true if any parser errors were accumulated */
    public boolean hasErrors() {
        return !this.errors.isEmpty();
    }

    /** This will take a RecognitionException, and create a sensible error message out of it */
    public String createErrorMessage(final RecognitionException e) {
        final StringBuffer message = new StringBuffer();
        message.append( this.source + ":" + e.line + ":" + e.charPositionInLine + " " );
        if ( e instanceof MismatchedTokenException ) {
            final MismatchedTokenException mte = (MismatchedTokenException) e;
            message.append( "mismatched token: " + e.token + "; expecting type " + JavaParser.tokenNames[mte.expecting] );
        } else if ( e instanceof MismatchedTreeNodeException ) {
            final MismatchedTreeNodeException mtne = (MismatchedTreeNodeException) e;
            message.append( "mismatched tree node: " + mtne.foundNode + "; expecting type " + JavaParser.tokenNames[mtne.expecting] );
        } else if ( e instanceof NoViableAltException ) {
            final NoViableAltException nvae = (NoViableAltException) e;
            message.append( "Unexpected token '" + e.token.getText() + "'" );
            /*
             message.append("decision=<<"+nvae.grammarDecisionDescription+">>"+
             " state "+nvae.stateNumber+
             " (decision="+nvae.decisionNumber+
             ") no viable alt; token="+
             e.token);
             */
        } else if ( e instanceof EarlyExitException ) {
            final EarlyExitException eee = (EarlyExitException) e;
            message.append( "required (...)+ loop (decision=" + eee.decisionNumber + ") did not match anything; token=" + e.token );
        } else if ( e instanceof MismatchedSetException ) {
            final MismatchedSetException mse = (MismatchedSetException) e;
            message.append( "mismatched token '" + e.token + "' expecting set " + mse.expecting );
        } else if ( e instanceof MismatchedNotSetException ) {
            final MismatchedNotSetException mse = (MismatchedNotSetException) e;
            message.append( "mismatched token '" + e.token + "' expecting set " + mse.expecting );
        } else if ( e instanceof FailedPredicateException ) {
            final FailedPredicateException fpe = (FailedPredicateException) e;
            message.append( "rule " + fpe.ruleName + " failed predicate: {" + fpe.predicateText + "}?" );
        }
        return message.toString();
    }

    // $ANTLR start declaration
    // /Users/bob/checkouts/jbossrules/drools-compiler/src/main/resources/org/drools/semantics/java/parser/java.g:139:1: declaration : modifiers typeSpec variableDefinitions ;
    public void declaration() throws RecognitionException {
        try {
            // /Users/bob/checkouts/jbossrules/drools-compiler/src/main/resources/org/drools/semantics/java/parser/java.g:143:17: ( modifiers typeSpec variableDefinitions )
            // /Users/bob/checkouts/jbossrules/drools-compiler/src/main/resources/org/drools/semantics/java/parser/java.g:143:17: modifiers typeSpec variableDefinitions
            {
                this.following.push( JavaParser.FOLLOW_modifiers_in_declaration59 );
                modifiers();
                this.following.pop();

                this.following.push( JavaParser.FOLLOW_typeSpec_in_declaration61 );
                typeSpec();
                this.following.pop();

                this.following.push( JavaParser.FOLLOW_variableDefinitions_in_declaration63 );
                variableDefinitions();
                this.following.pop();

            }

        } catch ( final RecognitionException re ) {
            reportError( re );
            recover( this.input,
                     re );
        } finally {
        }
        return;
    }

    // $ANTLR end declaration

    // $ANTLR start typeSpec
    // /Users/bob/checkouts/jbossrules/drools-compiler/src/main/resources/org/drools/semantics/java/parser/java.g:149:1: typeSpec : ( classTypeSpec | builtInTypeSpec );
    public void typeSpec() throws RecognitionException {
        try {
            // /Users/bob/checkouts/jbossrules/drools-compiler/src/main/resources/org/drools/semantics/java/parser/java.g:150:11: ( classTypeSpec | builtInTypeSpec )
            int alt1 = 2;
            final int LA1_0 = this.input.LA( 1 );
            if ( LA1_0 == JavaParser.IDENT ) {
                alt1 = 1;
            } else if ( (LA1_0 >= 68 && LA1_0 <= 76) ) {
                alt1 = 2;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -