📄 ggeneratorparser.java
字号:
// $ANTLR 2.7.4: "expandedgenerator.g" -> "GGeneratorParser.java"$ package org.tzi.use.parser.generator;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 org.tzi.use.parser.*;import org.tzi.use.parser.ocl.*;import org.tzi.use.parser.use.*;import java.util.List;import java.util.ArrayList;import java.util.HashMap;public class GGeneratorParser extends antlr.LLkParser implements GGeneratorTokenTypes { 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 GGeneratorParser(TokenBuffer tokenBuf, int k) { super(tokenBuf,k); tokenNames = _tokenNames;}public GGeneratorParser(TokenBuffer tokenBuf) { this(tokenBuf,5);}protected GGeneratorParser(TokenStream lexer, int k) { super(lexer,k); tokenNames = _tokenNames;}public GGeneratorParser(TokenStream lexer) { this(lexer,5);}public GGeneratorParser(ParserSharedInputState state) { super(state,5); tokenNames = _tokenNames;} public final List invariantListOnly() throws RecognitionException, TokenStreamException { List invariantList; invariantList = new ArrayList(); ASTConstraintDefinition def; try { // for error handling { _loop3: do { if ((LA(1)==LITERAL_context)) { def=invariant(); invariantList.add(def); } else { break _loop3; } } while (true); } match(Token.EOF_TYPE); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_0); } return invariantList; } 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_1.member(LA(2)))) { } else { throw new NoViableAltException(LT(1), getFilename()); } } t=simpleType(); n.setType(t); { _loop104: do { if ((LA(1)==LITERAL_inv)) { inv=invariantClause(); n.addInvariantClause(inv); } else { break _loop104; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_2); } return n; } public final List procedureListOnly() throws RecognitionException, TokenStreamException { List procedureList; procedureList = new ArrayList(); try { // for error handling { _loop6: do { if ((LA(1)==LITERAL_procedure)) { ASTGProcedure proc; proc=procedure(); procedureList.add(proc); } else { break _loop6; } } while (true); } match(Token.EOF_TYPE); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_0); } return procedureList; } public final ASTGProcedure procedure() throws RecognitionException, TokenStreamException { ASTGProcedure proc; Token name = null; List parameterDecls; List localDecls; List instructions; localDecls = new ArrayList(); proc = null; try { // for error handling match(LITERAL_procedure); name = LT(1); match(IDENT); match(LPAREN); parameterDecls=variableDeclarationList(); match(RPAREN); { switch ( LA(1)) { case LITERAL_var: { match(LITERAL_var); localDecls=variableDeclarationList(); match(SEMI); break; } case LITERAL_begin: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } match(LITERAL_begin); instructions=instructionList(); match(LITERAL_end); match(SEMI); proc = new ASTGProcedure( (MyToken) name, parameterDecls, localDecls, instructions ); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_3); } return proc; } public final List variableDeclarationList() throws RecognitionException, TokenStreamException { List varDecls; ASTVariableDeclaration decl; varDecls = new ArrayList(); try { // for error handling { switch ( LA(1)) { case IDENT: { decl=variableDeclaration(); varDecls.add(decl); { _loop12: do { if ((LA(1)==COMMA)) { match(COMMA); decl=variableDeclaration(); varDecls.add(decl); } else { break _loop12; } } while (true); } break; } case RPAREN: case SEMI: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_4); } return varDecls; } public final List instructionList() throws RecognitionException, TokenStreamException { List instructions; ASTGInstruction instr; instructions = new ArrayList(); try { // for error handling { _loop15: do { if ((_tokenSet_5.member(LA(1)))) { instr=instruction(); match(SEMI); instructions.add(instr); } else { break _loop15; } } while (true); } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_6); } return instructions; } 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_7); } return n; } public final ASTGInstruction instruction() throws RecognitionException, TokenStreamException { ASTGInstruction instr; instr=null; try { // for error handling switch ( LA(1)) { case LBRACK: { instr=attributeAssignment(); break; } case LITERAL_for: { instr=loop(); break; } case LITERAL_if: { instr=ifThenElse(); break; } default: if ((LA(1)==IDENT) && (LA(2)==COLON_EQUAL)) { instr=variableAssignment(); } else if ((LA(1)==IDENT) && (LA(2)==LPAREN)) { instr=atomicInstruction(); } else { throw new NoViableAltException(LT(1), getFilename()); } } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_8); } return instr; } public final ASTGVariableAssignment variableAssignment() throws RecognitionException, TokenStreamException { ASTGVariableAssignment assignment; Token target = null; ASTGValueInstruction source; assignment=null; try { // for error handling target = LT(1); match(IDENT); match(COLON_EQUAL); source=valueInstruction(); assignment = new ASTGVariableAssignment( (MyToken) target, source ); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_8); } return assignment; } public final ASTGAttributeAssignment attributeAssignment() throws RecognitionException, TokenStreamException { ASTGAttributeAssignment assignment; Token attributeName = null; ASTGValueInstruction source; ASTGocl targetObject; assignment=null; try { // for error handling targetObject=oclExpression(); match(DOT); attributeName = LT(1); match(IDENT); match(COLON_EQUAL); source=valueInstruction(); assignment = new ASTGAttributeAssignment( targetObject, (MyToken) attributeName, source ); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_8); } return assignment; } public final ASTGLoop loop() throws RecognitionException, TokenStreamException { ASTGLoop loop; Token t = null; ASTVariableDeclaration decl; ASTGocl sequence; List instructions; loop=null; try { // for error handling t = LT(1); match(LITERAL_for); decl=variableDeclaration(); match(LITERAL_in); sequence=oclExpression(); match(LITERAL_begin); instructions=instructionList(); match(LITERAL_end); loop= new ASTGLoop( decl, sequence, instructions, (MyToken)t ); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_8); } return loop; } public final ASTGAtomicInstruction atomicInstruction() throws RecognitionException, TokenStreamException { ASTGAtomicInstruction instr; Token name = null; instr=null; ASTGInstructionParameterInterface parameter; try { // for error handling name = LT(1); match(IDENT); instr= new ASTGAtomicInstruction((MyToken) name); match(LPAREN); { switch ( LA(1)) { case IDENT: case LBRACK: { parameter=instructionParameter(); instr.addParameter(parameter); { _loop26: do { if ((LA(1)==COMMA)) { match(COMMA); parameter=instructionParameter(); instr.addParameter(parameter); } else { break _loop26; } } while (true); } break; } case RPAREN: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } match(RPAREN); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_8); } return instr; } public final ASTGIfThenElse ifThenElse() throws RecognitionException, TokenStreamException { ASTGIfThenElse ifThenElse; Token token = null; ASTGocl sequence; List thenInstructions; List elseInstructions; elseInstructions = new ArrayList(); ifThenElse=null; try { // for error handling token = LT(1); match(LITERAL_if); sequence=oclExpression(); match(LITERAL_then); match(LITERAL_begin); thenInstructions=instructionList(); match(LITERAL_end); { switch ( LA(1)) { case LITERAL_else: { match(LITERAL_else); match(LITERAL_begin); elseInstructions=instructionList(); match(LITERAL_end); break; } case SEMI: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } ifThenElse= new ASTGIfThenElse( sequence, thenInstructions, elseInstructions, (MyToken)token ); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_8); } return ifThenElse; } public final ASTGValueInstruction valueInstruction() throws RecognitionException, TokenStreamException { ASTGValueInstruction valueinstr; valueinstr = null; try { // for error handling switch ( LA(1)) { case IDENT: { valueinstr=atomicInstruction(); break; } case LBRACK: { valueinstr=oclExpression(); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_8); } return valueinstr; } public final ASTGocl oclExpression() throws RecognitionException, TokenStreamException { ASTGocl encapOcl; Token i = null; ASTExpression ocl; encapOcl=null; try { // for error handling i = LT(1); match(LBRACK); ocl=expression(); match(RBRACK); encapOcl = new ASTGocl(ocl, (MyToken)i); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_9); } return encapOcl; } public final ASTGInstructionParameterInterface instructionParameter() throws RecognitionException, TokenStreamException { ASTGInstructionParameterInterface parameter; parameter=null; try { // for error handling switch ( LA(1)) { case LBRACK: { parameter=oclExpression(); break; } case IDENT: { parameter=instrParameterIdent(); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(_tokenSet_10); } return parameter; } public final MyToken instrParameterIdent() throws RecognitionException, TokenStreamException { MyToken t; Token i = null; t=null; try { // for error handling i = LT(1); match(IDENT); t = (MyToken) i; } catch (RecognitionException ex) { reportError(ex); consume();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -