📄 guseparser.java
字号:
// $ANTLR 2.7.4: "expandeduse.g" -> "GUSEParser.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.use; 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;import org.tzi.use.parser.ocl.*;public class GUSEParser extends antlr.LLkParser implements GUSETokenTypes { 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 GUSEParser(TokenBuffer tokenBuf, int k) { super(tokenBuf,k); tokenNames = _tokenNames;}public GUSEParser(TokenBuffer tokenBuf) { this(tokenBuf,5);}protected GUSEParser(TokenStream lexer, int k) { super(lexer,k); tokenNames = _tokenNames;}public GUSEParser(TokenStream lexer) { this(lexer,5);}public GUSEParser(ParserSharedInputState state) { super(state,5); tokenNames = _tokenNames;} public final ASTModel model() throws RecognitionException, TokenStreamException { ASTModel n; Token name = null; ASTEnumTypeDefinition e = null; ASTAssociation a = null; ASTConstraintDefinition cons = null; ASTPrePost ppc = null; n = null; try { // for error handling match(LITERAL_model); name = LT(1); match(IDENT); n = new ASTModel((MyToken) name); { _loop3: do { if ((LA(1)==LITERAL_enum)) { e=enumTypeDefinition(); n.addEnumTypeDef(e); } else { break _loop3; } } while (true); } { _loop10: do { switch ( LA(1)) { case LITERAL_abstract: case LITERAL_class: case LITERAL_associationClass: case LITERAL_associationclass: { { generalClassDefinition(n); } break; } case LITERAL_aggregation: case LITERAL_composition: case LITERAL_association: { { a=associationDefinition(); n.addAssociation(a); } break; } case LITERAL_constraints: { { match(LITERAL_constraints); { _loop9: do { if ((LA(1)==LITERAL_context) && (LA(2)==IDENT) && (_tokenSet_0.member(LA(3)))) { cons=invariant(); n.addConstraint(cons); } else if ((LA(1)==LITERAL_context) && (LA(2)==IDENT) && (LA(3)==COLON_COLON)) { ppc=prePost(); n.addPrePost(ppc); } else { break _loop9; } } while (true); } } break; } default: { break _loop10; } } } while (true); } match(Token.EOF_TYPE); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_1); } return n; } public final ASTEnumTypeDefinition enumTypeDefinition() throws RecognitionException, TokenStreamException { ASTEnumTypeDefinition n; Token name = null; List idList; n = null; try { // for error handling match(LITERAL_enum); name = LT(1); match(IDENT); match(LBRACE); idList=idList(); match(RBRACE); { switch ( LA(1)) { case SEMI: { match(SEMI); break; } case EOF: case LITERAL_constraints: case LITERAL_enum: case LITERAL_abstract: case LITERAL_class: case LITERAL_associationClass: case LITERAL_associationclass: case LITERAL_aggregation: case LITERAL_composition: case LITERAL_association: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } n = new ASTEnumTypeDefinition((MyToken) name, idList); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_2); } return n; } public final void generalClassDefinition( ASTModel n ) throws RecognitionException, TokenStreamException { boolean isAbstract = false; ASTClass c = null; ASTAssociationClass ac = null; try { // for error handling { switch ( LA(1)) { case LITERAL_abstract: { match(LITERAL_abstract); isAbstract = true; break; } case LITERAL_class: case LITERAL_associationClass: case LITERAL_associationclass: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { switch ( LA(1)) { case LITERAL_class: { { c=classDefinition(isAbstract); n.addClass(c); } break; } case LITERAL_associationClass: case LITERAL_associationclass: { { ac=associationClassDefinition(isAbstract); n.addAssociationClass(ac); } break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_3); } } public final ASTAssociation associationDefinition() throws RecognitionException, TokenStreamException { ASTAssociation n; Token name = null; ASTAssociationEnd ae; n = null; try { // for error handling MyToken t = (MyToken) LT(1); { switch ( LA(1)) { case LITERAL_association: { match(LITERAL_association); break; } case LITERAL_aggregation: { match(LITERAL_aggregation); break; } case LITERAL_composition: { match(LITERAL_composition); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } name = LT(1); match(IDENT); n = new ASTAssociation(t, (MyToken) name); match(LITERAL_between); ae=associationEnd(); n.addEnd(ae); { int _cnt57=0; _loop57: do { if ((LA(1)==IDENT)) { ae=associationEnd(); n.addEnd(ae); } else { if ( _cnt57>=1 ) { break _loop57; } else {throw new NoViableAltException(LT(1), getFilename());} } _cnt57++; } while (true); } match(LITERAL_end); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_3); } return n; } public final ASTConstraintDefinition invariant() throws RecognitionException, TokenStreamException { ASTConstraintDefinition n; Token v = null; n = null; ASTType t = null; ASTInvariantClause inv = null; try { // for error handling n = new ASTConstraintDefinition(); match(LITERAL_context); { if ((LA(1)==IDENT) && (LA(2)==COLON)) { v = LT(1); match(IDENT); match(COLON); n.setVarName((MyToken) v); } else if ((LA(1)==IDENT) && (_tokenSet_4.member(LA(2)))) { } else { throw new NoViableAltException(LT(1), getFilename()); } } t=simpleType(); n.setType(t); { _loop71: do { if ((LA(1)==LITERAL_inv)) { inv=invariantClause(); n.addInvariantClause(inv); } else { break _loop71; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_5); } return n; } public final ASTPrePost prePost() throws RecognitionException, TokenStreamException { ASTPrePost n; Token classname = null; Token opname = null; n = null; List pl = null; ASTType rt = null; ASTPrePostClause ppc = null; try { // for error handling match(LITERAL_context); classname = LT(1); match(IDENT); match(COLON_COLON); opname = LT(1); match(IDENT); pl=paramList(); { switch ( LA(1)) { case COLON: { match(COLON); rt=type(); break; } case LITERAL_pre: case LITERAL_post: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } n = new ASTPrePost((MyToken) classname, (MyToken) opname, pl, rt); { int _cnt77=0; _loop77: do { if ((LA(1)==LITERAL_pre||LA(1)==LITERAL_post)) { ppc=prePostClause(); n.addPrePostClause(ppc); } else { if ( _cnt77>=1 ) { break _loop77; } else {throw new NoViableAltException(LT(1), getFilename());} } _cnt77++; } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_5); } 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); { _loop87: do { if ((LA(1)==COMMA)) { match(COMMA); idn = LT(1); match(IDENT); idList.add((MyToken) idn); } else { break _loop87; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_6); } return idList; } public final ASTClass classDefinition( boolean isAbstract ) throws RecognitionException, TokenStreamException { ASTClass n; Token name = null; List idList; n = null; try { // for error handling match(LITERAL_class); name = LT(1); match(IDENT); n = new ASTClass((MyToken) name, isAbstract); { switch ( LA(1)) { case LESS: { match(LESS); idList=idList(); n.addSuperClasses(idList); break; } case LITERAL_constraints: case LITERAL_attributes: case LITERAL_operations: case LITERAL_end: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { switch ( LA(1)) { case LITERAL_attributes: { match(LITERAL_attributes); ASTAttribute a; { _loop22: do { if ((LA(1)==IDENT)) { a=attributeDefinition(); n.addAttribute(a); } else { break _loop22; } } while (true); } break; } case LITERAL_constraints: case LITERAL_operations: case LITERAL_end: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { switch ( LA(1)) { case LITERAL_operations: { match(LITERAL_operations); ASTOperation op; { _loop25: do { if ((LA(1)==IDENT)) { op=operationDefinition(); n.addOperation(op); } else { break _loop25; } } while (true); } break; } case LITERAL_constraints: case LITERAL_end: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } { switch ( LA(1)) { case LITERAL_constraints: { match(LITERAL_constraints);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -