📄 use.g
字号:
/* * 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. *//* $ProjectHeader: use 2-3-0-release.1 Mon, 12 Sep 2005 20:18:33 +0200 green $ */// set package for all generated classesheader { /* * 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; }// ------------------------------------// USE parser// ------------------------------------{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.*;}class GUSEParser extends GOCLParser;options { exportVocab = GUSE; defaultErrorHandler = true; buildAST = false; k = 5; //codeGenMakeSwitchThreshold = 2; //codeGenBitsetTestThreshold = 3;}// grammar start/* ------------------------------------ model ::= "model" id { enumTypeDefinition } { classDefinition | associationDefinition | "constraints" { invariant | prePost } } */model returns [ASTModel n]{ ASTEnumTypeDefinition e = null; ASTAssociation a = null; ASTConstraintDefinition cons = null; ASTPrePost ppc = null; n = null;}: "model" name:IDENT { n = new ASTModel((MyToken) name); } ( e=enumTypeDefinition { n.addEnumTypeDef(e); } )* ( ( generalClassDefinition[n] ) | ( a=associationDefinition { n.addAssociation(a); } ) | ( "constraints" ( cons=invariant { n.addConstraint(cons); } | ppc=prePost { n.addPrePost(ppc); } )* ) )* EOF ;/* ------------------------------------ enumTypeDefinition ::= "enum" id "{" idList "}" [ ";" ]*/enumTypeDefinition returns [ASTEnumTypeDefinition n]{ List idList; n = null; }: "enum" name:IDENT LBRACE idList=idList RBRACE ( SEMI )? { n = new ASTEnumTypeDefinition((MyToken) name, idList); } ;/* ------------------------------------ generalClassDefinition ::= [ "abstract" ] { classDefinition | associationClassDefinition }*/generalClassDefinition[ASTModel n]{ boolean isAbstract = false; ASTClass c = null; ASTAssociationClass ac = null;}: ( "abstract" { isAbstract = true; } )? ( ( c=classDefinition[isAbstract] { n.addClass(c); } ) | ( ac=associationClassDefinition[isAbstract] { n.addAssociationClass(ac); } ) ) ;/* ------------------------------------ classDefinition ::= [ "abstract" ] "class" id [ specialization ] [ attributes ] [ operations ] [ constraints ] "end" specialization ::= "<" idList attributes ::= "attributes" { attributeDefinition } operations ::= "operations" { operationDefinition } constraints ::= "constraints" { invariantClause }*/classDefinition[boolean isAbstract] returns [ASTClass n]{ List idList; n = null; }: "class" name:IDENT { n = new ASTClass((MyToken) name, isAbstract); } ( LESS idList=idList { n.addSuperClasses(idList); } )? ( "attributes" { ASTAttribute a; } ( a=attributeDefinition { n.addAttribute(a); } )* )? ( "operations" { ASTOperation op; } ( op=operationDefinition { n.addOperation(op); } )* )? ( "constraints" ( { ASTInvariantClause inv; } inv=invariantClause { n.addInvariantClause(inv); } )* )? "end" ;/* ------------------------------------ associationClassDefinition ::= [ "abstract" ] "associationClass" id [ specialization ] [ attributes ] [ operations ] [ constraints ] [( "aggregation" | "composition" )] "between" associationEnd { associationEnd }+ "end" specialization ::= "<" idList attributes ::= "attributes" { attributeDefinition } operations ::= "operations" { operationDefinition } constraints ::= "constraints" { invariantClause }*/associationClassDefinition[boolean isAbstract] returns [ASTAssociationClass n]{List idList; n = null; ASTAssociationEnd ae; }: { MyToken t1 = (MyToken) LT(1); } ("associationClass"|"associationclass") { if (t1.getText().equals("associationClass")) { reportWarning("the 'associationClass' keyword is deprecated and will " + "not be supported in the future, use 'associationclass' instead"); } } name:IDENT { n = new ASTAssociationClass((MyToken) name, isAbstract); } ( LESS idList=idList { n.addSuperClasses(idList); } )? "between" ae=associationEnd { n.addEnd(ae); } ( ae=associationEnd { n.addEnd(ae); } )+ ( "attributes" { ASTAttribute a; } ( a=attributeDefinition { n.addAttribute(a); } )* )? ( "operations" { ASTOperation op; } ( op=operationDefinition { n.addOperation(op); } )* )? ( "constraints" ( { ASTInvariantClause inv; } inv=invariantClause { n.addInvariantClause(inv); } )* )? ( { MyToken t = (MyToken) LT(1); } ( "aggregation" | "composition" ) { n.setKind(t); } )? "end" ;/* ------------------------------------ attributeDefinition ::= id ":" type [ ";" ]*/attributeDefinition returns [ASTAttribute n]{ ASTType t; n = null; }: name:IDENT COLON t=type ( SEMI )? { n = new ASTAttribute((MyToken) name, t); } ;/* ------------------------------------ operationDefinition ::= id paramList [ ":" type [ "=" expression ] ] { prePostClause } [ ";" ]*/operationDefinition returns [ASTOperation n]{ List pl; ASTType t = null; ASTExpression e = null; ASTPrePostClause ppc = null; n = null; }: name:IDENT pl=paramList ( ( COLON t=type ( EQUAL e=expression )? ) )? { n = new ASTOperation((MyToken) name, pl, t, e); } ( ppc=prePostClause { n.addPrePostClause(ppc); } )* ( SEMI )? ;/* ------------------------------------ associationDefinition ::= ( "association" | "aggregation" | "composition" ) id "between" associationEnd associationEnd { associationEnd } "end"*/associationDefinition returns [ASTAssociation n]{ ASTAssociationEnd ae; n = null; }: { MyToken t = (MyToken) LT(1); } ( "association" | "aggregation" | "composition" ) // ( classDefinition | (name:IDENT { n = new ASTAssociation(t, (MyToken) name); }) ) name:IDENT { n = new ASTAssociation(t, (MyToken) name); } "between" ae=associationEnd { n.addEnd(ae); } ( ae=associationEnd { n.addEnd(ae); } )+ "end" ;/* ------------------------------------ associationEnd ::= id "[" multiplicity "]" [ "role" id ] [ "ordered" ] [ ";" ]*/associationEnd returns [ASTAssociationEnd n]{ ASTMultiplicity m; n = null; }: name:IDENT LBRACK m=multiplicity RBRACK { n = new ASTAssociationEnd((MyToken) name, m); } ( "role" rn:IDENT { n.setRolename((MyToken) rn); } )? ( "ordered" { n.setOrdered(); } )? ( SEMI )? ;/* ------------------------------------ multiplicity ::= multiplicityRange { "," multiplicityRange } multiplicityRange ::= multiplicitySpec [ ".." multiplicitySpec ] multiplicitySpec ::= "*" | INT*/multiplicity returns [ASTMultiplicity n]{ ASTMultiplicityRange mr; n = null; }: { MyToken t = (MyToken) LT(1); // remember start position of expression n = new ASTMultiplicity(t); } mr=multiplicityRange { n.addRange(mr); } ( COMMA mr=multiplicityRange { n.addRange(mr); } )* ;multiplicityRange returns [ASTMultiplicityRange n]{ int ms1, ms2; n = null; }: ms1=multiplicitySpec { n = new ASTMultiplicityRange(ms1); } ( DOTDOT ms2=multiplicitySpec { n.setHigh(ms2); } )? ;multiplicitySpec returns [int m]{ m = -1; }: i:INT { m = Integer.parseInt(i.getText()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -