📄 goclparser.java
字号:
// $ANTLR 2.7.4: "ocl.g" -> "GOCLParser.java"$ /* * USE - UML based specification environment * Copyright (C) 1999-2004 Mark Richters, University of Bremen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package org.tzi.use.parser.ocl; import antlr.TokenBuffer;import antlr.TokenStreamException;import antlr.TokenStreamIOException;import antlr.ANTLRException;import antlr.LLkParser;import antlr.Token;import antlr.TokenStream;import antlr.RecognitionException;import antlr.NoViableAltException;import antlr.MismatchedTokenException;import antlr.SemanticException;import antlr.ParserSharedInputState;import antlr.collections.impl.BitSet;import java.util.List;import java.util.ArrayList;import java.util.HashMap;import java.io.PrintWriter;import org.tzi.use.parser.MyToken;import org.tzi.use.parser.ParseErrorHandler;public class GOCLParser extends antlr.LLkParser implements GOCLTokenTypes { final static String Q_COLLECT = "collect"; final static String Q_SELECT = "select"; final static String Q_REJECT = "reject"; final static String Q_FORALL = "forAll"; final static String Q_EXISTS = "exists"; final static String Q_ISUNIQUE = "isUnique"; final static String Q_SORTEDBY = "sortedBy"; final static String Q_ANY = "any"; final static String Q_ONE = "one"; final static int Q_COLLECT_ID = 1; final static int Q_SELECT_ID = 2; final static int Q_REJECT_ID = 3; final static int Q_FORALL_ID = 4; final static int Q_EXISTS_ID = 5; final static int Q_ISUNIQUE_ID = 6; final static int Q_SORTEDBY_ID = 7; final static int Q_ANY_ID = 8; final static int Q_ONE_ID = 9; final static HashMap queryIdentMap = new HashMap(); static { queryIdentMap.put(Q_COLLECT, new Integer(Q_COLLECT_ID)); queryIdentMap.put(Q_SELECT, new Integer(Q_SELECT_ID)); queryIdentMap.put(Q_REJECT, new Integer(Q_REJECT_ID)); queryIdentMap.put(Q_FORALL, new Integer(Q_FORALL_ID)); queryIdentMap.put(Q_EXISTS, new Integer(Q_EXISTS_ID)); queryIdentMap.put(Q_ISUNIQUE, new Integer(Q_ISUNIQUE_ID)); queryIdentMap.put(Q_SORTEDBY, new Integer(Q_SORTEDBY_ID)); queryIdentMap.put(Q_ANY, new Integer(Q_ANY_ID)); queryIdentMap.put(Q_ONE, new Integer(Q_ONE_ID)); } protected boolean isQueryIdent(Token t) { return queryIdentMap.containsKey(t.getText()); } private int fNest = 0; public void traceIn(String rname) throws TokenStreamException { for (int i = 0; i < fNest; i++) System.out.print(" "); super.traceIn(rname); fNest++; } public void traceOut(String rname) throws TokenStreamException { fNest--; for (int i = 0; i < fNest; i++) System.out.print(" "); super.traceOut(rname); } public void init(ParseErrorHandler handler) { fParseErrorHandler = handler; } /* Overridden methods. */ private ParseErrorHandler fParseErrorHandler; public void reportError(RecognitionException ex) { fParseErrorHandler.reportError( ex.getLine() + ":" +ex.getColumn() + ": " + ex.getMessage()); }protected GOCLParser(TokenBuffer tokenBuf, int k) { super(tokenBuf,k); tokenNames = _tokenNames;}public GOCLParser(TokenBuffer tokenBuf) { this(tokenBuf,5);}protected GOCLParser(TokenStream lexer, int k) { super(lexer,k); tokenNames = _tokenNames;}public GOCLParser(TokenStream lexer) { this(lexer,5);}public GOCLParser(ParserSharedInputState state) { super(state,5); tokenNames = _tokenNames;} public final List paramList() throws RecognitionException, TokenStreamException { List paramList; ASTVariableDeclaration v; paramList = new ArrayList(); try { // for error handling match(LPAREN); { switch ( LA(1)) { case IDENT: { v=variableDeclaration(); paramList.add(v); { _loop4: do { if ((LA(1)==COMMA)) { match(COMMA); v=variableDeclaration(); paramList.add(v); } else { break _loop4; } } while (true); } break; } case RPAREN: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } match(RPAREN); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_0); } return paramList; } public final ASTVariableDeclaration variableDeclaration() throws RecognitionException, TokenStreamException { ASTVariableDeclaration n; Token name = null; ASTType t; n = null; try { // for error handling name = LT(1); match(IDENT); match(COLON); t=type(); n = new ASTVariableDeclaration((MyToken) name, t); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_1); } return n; } public final List idList() throws RecognitionException, TokenStreamException { List idList; Token id0 = null; Token idn = null; idList = new ArrayList(); try { // for error handling id0 = LT(1); match(IDENT); idList.add((MyToken) id0); { _loop7: do { if ((LA(1)==COMMA)) { match(COMMA); idn = LT(1); match(IDENT); idList.add((MyToken) idn); } else { break _loop7; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_2); } return idList; } public final ASTType type() throws RecognitionException, TokenStreamException { ASTType n; n = null; try { // for error handling MyToken tok = (MyToken) LT(1); /* remember start of type */ { switch ( LA(1)) { case IDENT: { n=simpleType(); break; } case LITERAL_Set: case LITERAL_Sequence: case LITERAL_Bag: case LITERAL_Collection: { n=collectionType(); break; } case LITERAL_Tuple: { n=tupleType(); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } n.setStartToken(tok); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_3); } return n; } public final ASTExpression expressionOnly() throws RecognitionException, TokenStreamException { ASTExpression n; n = null; try { // for error handling n=expression(); match(Token.EOF_TYPE); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_0); } return n; } public final ASTExpression expression() throws RecognitionException, TokenStreamException { ASTExpression n; Token name = null; ASTLetExpression prevLet = null, firstLet = null; ASTType t = null; ASTExpression e1, e2; n = null; try { // for error handling MyToken tok = (MyToken) LT(1); /* remember start of expression */ { _loop13: do { if ((LA(1)==LITERAL_let)) { match(LITERAL_let); name = LT(1); match(IDENT); { switch ( LA(1)) { case COLON: { match(COLON); t=type(); break; } case EQUAL: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } match(EQUAL); e1=expression(); match(LITERAL_in); ASTLetExpression nextLet = new ASTLetExpression((MyToken) name, t, e1); if ( firstLet == null ) firstLet = nextLet; if ( prevLet != null ) prevLet.setInExpr(nextLet); prevLet = nextLet; } else { break _loop13; } } while (true); } n=conditionalImpliesExpression(); if ( n != null ) n.setStartToken(tok); if ( prevLet != null ) { prevLet.setInExpr(n); n = firstLet; n.setStartToken(tok); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_4); } return n; } public final ASTExpression conditionalImpliesExpression() throws RecognitionException, TokenStreamException { ASTExpression n; Token op = null; ASTExpression n1; n = null; try { // for error handling n=conditionalOrExpression(); { _loop16: do { if ((LA(1)==LITERAL_implies)) { op = LT(1); match(LITERAL_implies); n1=conditionalOrExpression(); n = new ASTBinaryExpression((MyToken) op, n, n1); } else { break _loop16; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_4); } return n; } public final ASTExpression conditionalOrExpression() throws RecognitionException, TokenStreamException { ASTExpression n; Token op = null; ASTExpression n1; n = null; try { // for error handling n=conditionalXOrExpression(); { _loop19: do { if ((LA(1)==LITERAL_or)) { op = LT(1); match(LITERAL_or); n1=conditionalXOrExpression(); n = new ASTBinaryExpression((MyToken) op, n, n1); } else { break _loop19; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_5); } return n; } public final ASTExpression conditionalXOrExpression() throws RecognitionException, TokenStreamException { ASTExpression n; Token op = null; ASTExpression n1; n = null; try { // for error handling n=conditionalAndExpression(); { _loop22: do { if ((LA(1)==LITERAL_xor)) { op = LT(1); match(LITERAL_xor); n1=conditionalAndExpression(); n = new ASTBinaryExpression((MyToken) op, n, n1); } else { break _loop22; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_6); } return n; } public final ASTExpression conditionalAndExpression() throws RecognitionException, TokenStreamException { ASTExpression n; Token op = null; ASTExpression n1; n = null; try { // for error handling n=equalityExpression(); { _loop25: do { if ((LA(1)==LITERAL_and)) { op = LT(1); match(LITERAL_and); n1=equalityExpression(); n = new ASTBinaryExpression((MyToken) op, n, n1); } else { break _loop25; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_7); } return n; } public final ASTExpression equalityExpression() throws RecognitionException, TokenStreamException { ASTExpression n; ASTExpression n1; n = null; try { // for error handling n=relationalExpression(); { _loop29: do { if ((LA(1)==EQUAL||LA(1)==NOT_EQUAL)) { MyToken op = (MyToken) LT(1); { switch ( LA(1)) { case EQUAL: { match(EQUAL); break; } case NOT_EQUAL: { match(NOT_EQUAL); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } n1=relationalExpression(); n = new ASTBinaryExpression(op, n, n1); } else { break _loop29; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_8); } return n; } public final ASTExpression relationalExpression() throws RecognitionException, TokenStreamException { ASTExpression n; ASTExpression n1; n = null; try { // for error handling n=additiveExpression(); { _loop33: do { if (((LA(1) >= LESS && LA(1) <= GREATER_EQUAL))) { MyToken op = (MyToken) LT(1); { switch ( LA(1)) { case LESS: { match(LESS); break; } case GREATER: { match(GREATER); break; } case LESS_EQUAL: { match(LESS_EQUAL); break; } case GREATER_EQUAL: { match(GREATER_EQUAL); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } n1=additiveExpression(); n = new ASTBinaryExpression(op, n, n1); } else { break _loop33; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_9); } return n; } public final ASTExpression additiveExpression() throws RecognitionException, TokenStreamException { ASTExpression n; ASTExpression n1; n = null; try { // for error handling n=multiplicativeExpression(); { _loop37: do { if ((LA(1)==PLUS||LA(1)==MINUS)) { MyToken op = (MyToken) LT(1); { switch ( LA(1)) { case PLUS: { match(PLUS); break; } case MINUS: { match(MINUS); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } n1=multiplicativeExpression(); n = new ASTBinaryExpression(op, n, n1); } else { break _loop37; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_10); } return n;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -