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

📄 gcmdparser.java

📁 UML设计测试工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
// $ANTLR 2.7.4: "expandedcmd.g" -> "GCmdParser.java"$ package org.tzi.use.parser.cmd;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 org.tzi.use.parser.ParseErrorHandler;import org.tzi.use.parser.MyToken;import org.tzi.use.parser.ocl.*;import org.tzi.use.parser.use.*;public class GCmdParser extends antlr.LLkParser       implements GCmdTokenTypes {      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 GCmdParser(TokenBuffer tokenBuf, int k) {  super(tokenBuf,k);  tokenNames = _tokenNames;}public GCmdParser(TokenBuffer tokenBuf) {  this(tokenBuf,5);}protected GCmdParser(TokenStream lexer, int k) {  super(lexer,k);  tokenNames = _tokenNames;}public GCmdParser(TokenStream lexer) {  this(lexer,5);}public GCmdParser(ParserSharedInputState state) {  super(state,5);  tokenNames = _tokenNames;}	public final ASTCmdList  cmdList() throws RecognitionException, TokenStreamException {		ASTCmdList cmdList;				cmdList = new ASTCmdList(); ASTCmd c;				try {      // for error handling			c=cmd();			cmdList.add(c);			{			_loop3:			do {				if ((_tokenSet_0.member(LA(1)))) {					c=cmd();					cmdList.add(c);				}				else {					break _loop3;				}							} while (true);			}			match(Token.EOF_TYPE);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_1);		}		return cmdList;	}		public final ASTCmd  cmd() throws RecognitionException, TokenStreamException {		ASTCmd n;				n = null;				try {      // for error handling			n=cmdStmt();			{			switch ( LA(1)) {			case SEMI:			{				match(SEMI);				break;			}			case EOF:			case LITERAL_let:			case LITERAL_create:			case LITERAL_assign:			case LITERAL_destroy:			case LITERAL_insert:			case LITERAL_delete:			case LITERAL_set:			case LITERAL_openter:			case LITERAL_opexit:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_2);		}		return n;	}		public final ASTCmd  cmdStmt() throws RecognitionException, TokenStreamException {		ASTCmd n;				n = null;				try {      // for error handling			switch ( LA(1)) {			case LITERAL_assign:			{				n=createAssignCmd();				break;			}			case LITERAL_destroy:			{				n=destroyCmd();				break;			}			case LITERAL_insert:			{				n=insertCmd();				break;			}			case LITERAL_delete:			{				n=deleteCmd();				break;			}			case LITERAL_set:			{				n=setCmd();				break;			}			case LITERAL_openter:			{				n=opEnterCmd();				break;			}			case LITERAL_opexit:			{				n=opExitCmd();				break;			}			case LITERAL_let:			{				n=letCmd();				break;			}			default:				if ((LA(1)==LITERAL_create) && (LA(2)==IDENT) && (LA(3)==COMMA||LA(3)==COLON) && (LA(4)==IDENT) && (_tokenSet_3.member(LA(5)))) {					n=createCmd();				}				else if ((LA(1)==LITERAL_create) && (LA(2)==IDENT) && (LA(3)==COLON) && (LA(4)==IDENT) && (LA(5)==LITERAL_between)) {					n=createInsertCmd();				}			else {				throw new NoViableAltException(LT(1), getFilename());			}			}		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		return n;	}		public final ASTCreateCmd  createCmd() throws RecognitionException, TokenStreamException {		ASTCreateCmd n;				List idList; ASTType t; n = null;				try {      // for error handling			match(LITERAL_create);			idList=idList();			match(COLON);			t=simpleType();			n = new ASTCreateCmd(idList, t);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		return n;	}		public final ASTCreateAssignCmd  createAssignCmd() throws RecognitionException, TokenStreamException {		ASTCreateAssignCmd n;				List idList; ASTType t; n = null;				try {      // for error handling			match(LITERAL_assign);			idList=idList();			match(COLON_EQUAL);			match(LITERAL_create);			t=simpleType();			n = new ASTCreateAssignCmd(idList, t);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		return n;	}		public final ASTCreateInsertCmd  createInsertCmd() throws RecognitionException, TokenStreamException {		ASTCreateInsertCmd n;				Token  id = null;		Token  idAssoc = null;		List idListInsert; ASTType t; n = null;				try {      // for error handling			match(LITERAL_create);			id = LT(1);			match(IDENT);			match(COLON);			idAssoc = LT(1);			match(IDENT);			match(LITERAL_between);			match(LPAREN);			idListInsert=idList();			match(RPAREN);			n = new ASTCreateInsertCmd( (MyToken) id, (MyToken) idAssoc, idListInsert);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		return n;	}		public final ASTDestroyCmd  destroyCmd() throws RecognitionException, TokenStreamException {		ASTDestroyCmd n;				ASTExpression e = null; List exprList = new ArrayList(); n = null;				try {      // for error handling			match(LITERAL_destroy);			e=expression();			exprList.add(e);			{			_loop12:			do {				if ((LA(1)==COMMA)) {					match(COMMA);					e=expression();					exprList.add(e);				}				else {					break _loop12;				}							} while (true);			}			n = new ASTDestroyCmd(exprList);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		return n;	}		public final ASTInsertCmd  insertCmd() throws RecognitionException, TokenStreamException {		ASTInsertCmd n;				Token  id = null;		ASTExpression e; List exprList = new ArrayList(); n = null;				try {      // for error handling			match(LITERAL_insert);			match(LPAREN);			e=expression();			exprList.add(e);			match(COMMA);			e=expression();			exprList.add(e);			{			_loop15:			do {				if ((LA(1)==COMMA)) {					match(COMMA);					e=expression();					exprList.add(e);				}				else {					break _loop15;				}							} while (true);			}			match(RPAREN);			match(LITERAL_into);			id = LT(1);			match(IDENT);			n = new ASTInsertCmd(exprList, (MyToken) id);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		return n;	}		public final ASTDeleteCmd  deleteCmd() throws RecognitionException, TokenStreamException {		ASTDeleteCmd n;				Token  id = null;		ASTExpression e; List exprList = new ArrayList(); n = null;				try {      // for error handling			match(LITERAL_delete);			match(LPAREN);			e=expression();			exprList.add(e);			match(COMMA);			e=expression();			exprList.add(e);			{			_loop18:			do {				if ((LA(1)==COMMA)) {					match(COMMA);					e=expression();					exprList.add(e);				}				else {					break _loop18;				}							} while (true);			}			match(RPAREN);			match(LITERAL_from);			id = LT(1);			match(IDENT);			n = new ASTDeleteCmd(exprList, (MyToken) id);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		return n;	}		public final ASTSetCmd  setCmd() throws RecognitionException, TokenStreamException {		ASTSetCmd n;				ASTExpression e1, e2; n = null;				try {      // for error handling			match(LITERAL_set);			e1=expression();			match(COLON_EQUAL);			e2=expression();			n = new ASTSetCmd(e1, e2);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		return n;	}		public final ASTOpEnterCmd  opEnterCmd() throws RecognitionException, TokenStreamException {		ASTOpEnterCmd n;				Token  id = null;		ASTExpression e; n = null;				try {      // for error handling			match(LITERAL_openter);			e=expression();			id = LT(1);			match(IDENT);			n = new ASTOpEnterCmd(e, (MyToken) id);			match(LPAREN);			{			switch ( LA(1)) {			case LPAREN:			case IDENT:			case LITERAL_let:			case PLUS:			case MINUS:			case LITERAL_not:			case LITERAL_iterate:			case LITERAL_oclAsType:			case LITERAL_oclIsKindOf:			case LITERAL_oclIsTypeOf:			case LITERAL_if:			case LITERAL_true:			case LITERAL_false:			case INT:			case REAL:			case STRING:			case HASH:			case LITERAL_Set:			case LITERAL_Sequence:			case LITERAL_Bag:			case LITERAL_oclEmpty:			case LITERAL_oclUndefined:			case LITERAL_Tuple:			{				e=expression();				n.addArg(e);				{				_loop23:				do {					if ((LA(1)==COMMA)) {						match(COMMA);						e=expression();						n.addArg(e);					}					else {						break _loop23;					}									} while (true);				}				break;			}			case RPAREN:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			match(RPAREN);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		return n;	}		public final ASTOpExitCmd  opExitCmd() throws RecognitionException, TokenStreamException {		ASTOpExitCmd n;				ASTExpression e = null; n = null;				try {      // for error handling			match(LITERAL_opexit);			{			if ((_tokenSet_5.member(LA(1))) && (_tokenSet_6.member(LA(2))) && (_tokenSet_7.member(LA(3))) && (_tokenSet_8.member(LA(4))) && (_tokenSet_9.member(LA(5)))) {				e=expression();			}			else if ((_tokenSet_4.member(LA(1))) && (_tokenSet_10.member(LA(2))) && (_tokenSet_11.member(LA(3))) && (_tokenSet_12.member(LA(4))) && (_tokenSet_13.member(LA(5)))) {			}			else {				throw new NoViableAltException(LT(1), getFilename());			}						}			n = new ASTOpExitCmd(e);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		return n;	}		public final ASTLetCmd  letCmd() throws RecognitionException, TokenStreamException {		ASTLetCmd n;				Token  name = null;		ASTExpression e = null; ASTType t = null; n = null;				try {      // for error handling			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);			e=expression();			n = new ASTLetCmd((MyToken) name, t, e);		}		catch (RecognitionException ex) {			reportError(ex);			consume();			consumeUntil(_tokenSet_4);		}		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);			{			_loop34:			do {				if ((LA(1)==COMMA)) {					match(COMMA);					idn = LT(1);					match(IDENT);					idList.add((MyToken) idn);				}				else {					break _loop34;				}							} while (true);			}

⌨️ 快捷键说明

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