%{ static char const rcsid[] = "$Id: harmony.yacc,v 1.9 1998/07/31 22:45:56 liddl Exp liddl $"; /*======================================================================== * Harmony Core Language Parser * Object-Oriented Systems Modeling Research Group * * Dr. Stephen W. Liddle (liddle@byu.edu) * School of Accountancy and Information Systems * Marriott School of Management * 540 TNRB, P.O. Box 23068-3068 * Brigham Young University * Provo, UT 84602 * * Dr. David W. Embley (embley@cs.byu.edu) and * Dr. Scott N. Woodfield (woodfiel@cs.byu.edu) * Department of Computer Science * 3361 TMCB * Brigham Young University * Provo, UT 84602 * * Copyright (C) 1995-1998, Board of Trustees of Brigham Young University * * Harmony Core Language Parser software, both binary and source * (hereafter, Software) is copyrighted by The Board of Trustees of * Brigham Young University (BYU), and ownership remains with BYU. * * BYU grants you (hereafter, Licensee) a license to use the Software * for academic, research and internal business purposes only, without a * fee. Licensee may distribute the binary and source code (if released) * to third parties provided that the copyright notice and this statement * appears on all copies and that no charge is associated with such * copies. * * Licensee may not make derivative works without first arranging an * additional license agreement with BYU. * * Any Licensee wishing to make commercial use of the Software should * contact BYU to negotiate an appropriate license for such * commercial use. Commercial use includes (1) integration of all or * part of the source code into a product for sale or license by or on * behalf of Licensee to third parties, or (2) distribution of the binary * code or source code to third parties that need it to utilize a * commercial product sold or licensed by or on behalf of Licensee. * * BYU MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR * ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED * WARRANTY. BYU SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE * USERS OF THIS SOFTWARE. * * By using or copying this Software, Licensee agrees to abide by the * copyright law and all other applicable laws of the United States * including, but not limited to, export control laws, and the terms * of this license. BYU shall have the right to terminate this license * immediately by written notice upon Licensee's breach of, or * non-compliance with, any of its terms. Licensee may be held legally * responsible for any copyright infringement that is caused or * encouraged by Licensee's failure to abide by the terms of this license. * * Comments and questions are welcome and can be sent to liddle@byu.edu. */ /*======================================================================== * $RCSfile: harmony.yacc,v $ * * $Author: liddl (Stephen W. Liddle) $ * $Date: 1998/07/31 22:45:56 $ * $Revision: 1.9 $ * * $Description: * Harmony Language Grammar. $ * * $Log: harmony.yacc,v $ * Revision 1.9 1998/07/31 22:45:56 liddl * Fixed miscellaneous bugs that Scott found. * * Revision 1.8 1998/07/23 21:17:11 liddl * Removed duplicate definition of ObjectConversion. * * Revision 1.7 1998/07/10 20:51:36 liddl * Added support for non-printing characters (nul, bel, etc.) * and Unicode(expression). * * Revision 1.6 1998/07/09 18:55:39 liddl * Minor updates. We have now gone through the whole * grammar and are working on creating a substantial * set of test cases. * * Revision 1.5 1998/06/24 19:01:23 liddl * Updated for 1.1 core. * * NOTE: These rules use YACC format with three exceptions. First, items * in square brackets, e.g., [item], are considered optional. * Second, items in parentheses followed by an asterisk, e.g., * (item)*, are repeated zero or more times. Finally, items in * parentheses followed by a plus sign, e.g., (item)+, are * repeated one or more times. This file is run through a * preprocessor before handing it to btyacc. */ /*------------------------------------------------------------------------ * INCLUDES */ #include #include "harmony.H" #include #include "semantic.H" #define yylex Harmonylex %} /*------------------------------------------------------------------------ * TOKENS */ /* * Operator Tokens */ %token ASSIGNOP AT BAR COLON COMMA DETERMINES DOTDOT FLOAT %token INFORMAL LBRACE LBRACKET LOGICSEP %token LOWERWORD LPAREN NONNEGINT RBRACE RBRACKET %token RPAREN SEMICOLON STRING UPPERWORD %left WHERE %left IMPLIES EQUIV %left AND OR %left NOT ONEOF %left INCSYM INCSYMEQ SUBSETOF SUBSETEQ %left LANGLE LESSEQ RANGLE GREATEQ EQUAL NOTEQ %left PLUS MINUS %left STAR SLASH MODULO DIV %right CARET %left PERIOD %right UMINUS /* * Key-Word Tokens */ %token ADD ASCENDING BOOLEAN BY COMMIT CONSTANT DESCENDING %token DIGITS DO ELSE ELSEIF END ENTER ENTERING %token EXCEPTION EXISTS FALSEKEY FORALL %token FOREACH FROM IF IN INCLUDES %token INF INTEGER INTERACTION ISA ISAI ISAM ISAP %token ISAU NAN NEWTHREAD OBJECTSET %token OBJECTKEY MERGETHR REAL %token REMOVE SELF SELFTHREAD %token START STATE STRINGKEY %token THEN TO TOALL TRUEKEY %token WAIT WHEN WHILE %token NUL BEL BS TAB LF FF CR ESC QUOTE TIC UNICODE %start OSM_Module %% /*======================================================================== * RULE DECLARATIONS */ /*------------------------------------------------------------------------ * START RULES */ OSM_Module : ([OSM_Declaration] SEMICOLON)* ; ORM_OIM_Module : ([ORM_OIM_Declaration] SEMICOLON)* ; OBM_OIM_Module : ([OBM_OIM_Declaration] SEMICOLON)* ; OSM_Declaration : ORM_Declaration | OBM_Declaration | OIM_Declaration | OSM_ConstraintDecl | INFORMAL ; ORM_OIM_Declaration : ORM_Declaration | OIM_Declaration | OSM_ConstraintDecl | INFORMAL ; OBM_OIM_Declaration : OBM_Declaration | OIM_Declaration | OSM_ConstraintDecl | INFORMAL ; ORM_Declaration : ObjectDecl | ObjectSetDecl | RelSetDecl | GenSpecDecl | LogicRuleDecl ; OBM_Declaration : StateDecl | TransitionDecl ; OIM_Declaration : InteractionDecl ; OSM_ConstraintDecl : LBRACKET ConstraintBody RBRACKET ; /*------------------------------------------------------------------------ * CONSTRAINT RULES */ ConstraintBody : GeneralConstraint | PathRealTimeConstraint | INFORMAL ; GeneralConstraint : Expression /* BooleanExpression */ ; PathRealTimeConstraint : ConjunctionName TO ConjunctionName RealTimeExpression | InteractionName TO InteractionName RealTimeExpression ; RealTimeConstraintDecl : LBRACKET RealTimeConstraintBody RBRACKET ; RealTimeConstraintBody : RealTimeExpression | INFORMAL ; RealTimeExpression : RTCInequalityComparator Expression /* RealExpression */ ; RTCInequalityComparator : LANGLE | RANGLE | LESSEQ | GREATEQ ; /*------------------------------------------------------------------------ * OBJECT RULES */ ObjectDecl : OBJECTKEY ObjectDeclBody ; ObjectDeclBody : ObjectDeclTerm (COMMA ObjectDeclTerm)* ; ObjectDeclTerm : ObjectName [Generalization] [ObjectAliases] [ObjHighLevelBody] ; ObjectAliases : (BAR ObjectName)+ ; Generalization : COLON ObjectSet ; ObjHighLevelBody : INCLUDES OSM_Module END ; /*------------------------------------------------------------------------ * OBJECT-LITERAL RULES */ Object : SELF | ObjectName ; ObjectConversion : OBJECTKEY LPAREN ObjectSetName RPAREN ; BuiltInObject : BooleanLiteral | NumericLiteral | StringLiteral ; BooleanLiteral : TRUEKEY | FALSEKEY ; NumericLiteral : NonNANReal | NAN ; PosIntLiteral : NONNEGINT | INF | PLUS NONNEGINT | PLUS INF ; NonNANInt : PosIntLiteral | MINUS NONNEGINT | MINUS INF ; PosRealLiteral : FLOAT | PLUS FLOAT | PosIntLiteral ; NonNANReal : PosRealLiteral | MINUS NONNEGINT | MINUS FLOAT | MINUS INF ; StringLiteral : StringComponent | StringLiteral PLUS StringComponent ; StringComponent : NUL | BEL | BS | TAB | LF | FF | CR | ESC | QUOTE | TIC | UNICODE LPAREN Expression RPAREN /* IntegerExpression */ | STRING ; /*------------------------------------------------------------------------ * OBJECT-SET RULES */ ObjectSetDecl : [CONSTANT] ObjectSetDeclBody (COMMA ObjectSetDeclBody)* ; ObjectSetDeclBody : Name [Generalization] [ObjectSetAliases] [ObjectSetCardConstr] [ObjHighLevelBody] [ObjectSetInitializer] ; ObjectSetAliases : (BAR ObjectSet)+ ; ObjectSetInitializer : ASSIGNOP Expression ; ObjectSetConversion : OBJECTSET LPAREN RelationshipSetName RPAREN ; /*------------------------------------------------------------------------ * RELATIONSHIP-SET RULES */ RelSetDecl : [CONSTANT] RelSetDeclName [RelSetAliases] [CoOccurrenceList] [RelHighLevelBody] [RelSetInitializer] ; RelSetDeclName : RelSetDeclTerm (RelSetDeclTerm)+ [LowerWordSeq] ; RelSetDeclTerm : RSNameFragment [Generalization] ParticipationConstraint ; RSNameFragment : [LowerWordSeq] ObjectSetName RelSetAliases : (BAR RelationshipSetName)+ ; CoOccurrenceList : CoOccurrenceDecl (COMMA CoOccurrenceDecl)* ; CoOccurrenceDecl : LBRACKET ObjectSetNameList DETERMINES [CardinalityConstraint] ObjectSetNameList RBRACKET ; ObjectSetNameList : ObjectSetName (COMMA ObjectSetName)* ; RelSetInitializer : ASSIGNOP Expression ; RelHighLevelBody : INCLUDES ORM_OIM_Module END ; /*------------------------------------------------------------------------ * CARDINALITY-CONSTRAINT RULES */ ParticipationConstraint : CardinalityConstraint ; ObjectSetCardConstr : CardinalityConstraint ; CardinalityConstraint : LBRACKET CardConstraintBody RBRACKET ; CardConstraintBody : ConstraintTerm (COMMA ConstraintTerm)* ; ConstraintTerm : ConstraintMin [RangeSymbol ConstraintMax] ; RangeSymbol : DOTDOT | COLON { static bool printed = false; if (!printed) { fprintf(stderr, "\nWarning: The use of ':'" " (e.g., 1:*) is deprecated.\n"); fprintf(stderr, " Use '..' instead" " (e.g., 1..*).\n\n"); } printed = true; } ; ConstraintMin : Expression /* IntegerExpression */ | INFORMAL ; ConstraintMax : Expression /* IntegerExpression */ | STAR | INFORMAL ; /*------------------------------------------------------------------------ * GENERALIZATION-SPECIALIZATION RULES */ GenSpecDecl : SpecializationNameList GenSpecAnyKey GeneralizationNameList | SpecializationNameList GenSpecSingleKey ObjectSet | ObjectSet ISAI GeneralizationNameList ; GenSpecAnyKey : COLON | ISA | ISAM ; GenSpecSingleKey : ISAP | ISAU ; GeneralizationNameList : ObjectSet (COMMA ObjectSet)* ; SpecializationNameList : GeneralizationNameList ; /*------------------------------------------------------------------------ * LOGIC RULES */ LogicRuleDecl : LogicHead LOGICSEP LogicBody ; LogicHead : FormalPredicate ; FormalPredicate : (RSNameFragment LPAREN LogicVariable RPAREN)+ [LowerWordSeq] ; LogicVariable : Name /* OBJECTSETNAME */ ; LogicBody : LogicLiteral (COMMA LogicLiteral)* ; LogicLiteral : LogicAtom | NOT LogicAtom ; LogicAtom : LogicPredicate | LogicTerm EqComparator LogicTerm ; LogicPredicate : (RSNameFragment [LPAREN [LogicTerm] RPAREN])+ [LowerWordSeq] ; LogicTerm : LogicConstant | LogicVariable ; LogicConstant : Object ; /*------------------------------------------------------------------------ * SET-ENUMERATION RULES */ ObjectEnumeration : LBRACE [Object (COMMA Object)*] RBRACE ; RelationshipEnumeration : LBRACE [Relationship (COMMA Relationship)*] RBRACE ; /*------------------------------------------------------------------------ * STATE RULES */ StateDecl : STATE QualifiedName [StateAliases] [RealTimeConstraintDecl] [StateHighLevelBody] StateAliases : (BAR QualifiedName)+ ; StateHighLevelBody : INCLUDES OBM_OIM_Module END ; /*------------------------------------------------------------------------ * TRANSITION RULES */ TransitionDecl : [QualifiedName] TransitionHead TransitionBody [RealTimeConstraintDecl] ; TransitionHead : WHEN [PriorStateConjunction] [WhenClauseTail] | TransitionTrigger ; WhenClauseTail : AND WhenTrigger | TransitionTrigger ; WhenTrigger : Expression [RealTimeConstraintDecl] /* BooleanExpression */ | TransitionTrigger ; TransitionTrigger : EventHandler [AndOrKey Expression] /* BooleanExpression */ [RealTimeConstraintDecl] ; AndOrKey : AND | OR ; EventHandler : AT InteractionName [FormalParameterList] [DETERMINES FormalParameterList] ; PriorStateConjunction : PriorStateExpr (OR PriorStateExpr)* | ENTERING ; PriorStateExpr : PriorState [EXCEPTION] | [ConjunctionName] LPAREN PriorState (AND PriorState)* RPAREN [EXCEPTION] ; PriorState : QualifiedName [NEWTHREAD] ; TransitionBody : TransactionBody | NonTransactionBody ; NonTransactionBody : [THEN Scope [RealTimeConstraintDecl]] TransitionExit END ; TransactionBody : START Scope [RealTimeConstraintDecl] TransitionExit COMMIT ; TransitionExit : [EnterClause] (TransitionException)* ; EnterClause : ENTER SubsequentStateConj SEMICOLON ; SubsequentStateConj : SubsequentStateExpr (OR SubsequentStateExpr)* ; SubsequentStateExpr : SubsequentState | [ConjunctionName] LPAREN SubsequentState (AND SubsequentState)* RPAREN ; SubsequentState : QualifiedName [MERGETHR] ; TransitionException : EXCEPTION ExceptionCondition EnterClause ; ExceptionCondition : Expression /* BooleanExpression */ | AT InteractionName (OR AT InteractionName)* [AndOrKey Expression] /* BooleanExpression */ ; /*------------------------------------------------------------------------ * INTERACTION RULES */ InteractionDecl : INTERACTION InteractionBody ToFromClause [RelHighLevelBody] (RealTimeConstraintDecl)* ; InteractionBody : InteractionName (BAR InteractionName)* [FormalParameterList] [DETERMINES FormalParameterList] ; FormalParameterList : LPAREN [FormalParameter (COMMA FormalParameter)*] RPAREN ; FormalParameter : Name [Generalization] /* OBJECTSETNAME or RELATIONSHIPSETNAME, but * RELATIONSHIPSETNAME may appear only if * there is no Generalization phrase. * If Generalization is not present, we treat * the parameter as being syntactically correct * but semantically incomplete. This is more * common in abstract interactions than in * interaction send and receive expressions. */ | RelSetDeclName ; ToFromClause : ToKey InteractionPath [FromKey InteractionPath] | FromKey InteractionPath [ToKey InteractionPath] ; InteractionPath : PathExpression [PERIOD Name] /* TRANSITIONNAME or STATENAME */ ; ToKey : TO | TOALL ; FromKey : FROM ; /*------------------------------------------------------------------------ * EXPRESSION RULES */ Expression : Object | UnaryOp Expression | Expression BinaryOp Expression | PathExpression | FunctionalInteraction | StatusQuery | QuantifierExpression | LPAREN Expression RPAREN | BAR Expression BAR | SELFTHREAD | INFORMAL ; PathExpression : PathTerm (PERIOD PathTerm)* ; PathTerm : Object | ObjectSet | RelationshipSetName | RelationshipEnumeration | (RSNameFragment [LPAREN [Expression] RPAREN])+ [LowerWordSeq] ; FunctionalInteraction : [PathExpression [PERIOD Name]] /* TRANSITIONNAME or STATENAME */ InteractionName [SendParameterList] [DETERMINES FormalParameterList] ; SendParameterList : LPAREN [Expression (COMMA Expression)*] RPAREN ; StatusQuery : Expression IN QualifiedName /* ObjectExpression */ ; QuantifierExpression : QuantifierHead LPAREN Expression RPAREN /* BooleanExpression */ ; QuantifierHead : (Quantifier QuantifiedElement (COMMA QuantifiedElement)*)+ ; Quantifier : FORALL | EXISTS [CardinalityConstraint] ; QuantifiedElement : Name /* OBJECTSETNAME */ | FormalPredicate ; /*------------------------------------------------------------------------ * OPERATOR RULES */ UnaryOp : NOT | ONEOF | MINUS ; BinaryOp : ArithOp | EqComparator | LogOp | SetComparator ; ArithOp : PLUS | MINUS | STAR | SLASH | MODULO | DIV | CARET ; EqComparator : EQUAL | GREATEQ | LESSEQ | NOTEQ | LANGLE | RANGLE ; LogOp : IMPLIES | EQUIV | AND | OR ; SetComparator : INCSYM | INCSYMEQ | SUBSETOF | SUBSETEQ ; /*------------------------------------------------------------------------ * STATEMENT RULES */ Scope : (ActionStatement SEMICOLON)* | INFORMAL ; ActionStatement : OSM_Declaration | [TOALL] FunctionalInteraction [WaitClause] | PathExpression ASSIGNOP Expression | ADD UpdateBody | REMOVE UpdateBody | FOREACH PathExpression [OrderByClause] DO Scope END | IF Expression THEN Scope /* BooleanExpression */ (ElseIfClause)* [ElseClause] END | WHILE Expression DO Scope END /* BooleanExpression */ ; WaitClause : LBRACKET WAIT Expression RBRACKET /* RealExpression */ ; UpdateBody : LogicPredicate (COMMA LogicPredicate)* [WHERE LogicBody] ; ElseIfClause : ELSEIF Expression THEN Scope /* BooleanExpression */ ; ElseClause : ELSE Scope ; OrderByClause : (OrderByTerm)+ ; OrderByTerm : ASCENDING ObjSetNameList | DESCENDING ObjSetNameList ; ObjSetNameList : Name [BY Expression] (COMMA Name [BY Expression])* /* OBJECTSETNAMEs */ ; /*------------------------------------------------------------------------ * NAME RULES */ ConjunctionName : [ObjectSetName PERIOD] Name /* CONJUNCTIONNAME */ ; InteractionName : Name ; ObjectName : Name | BuiltInObject | ObjectConversion ; Relationship : Name /* RELATIONSHIPNAME */ | LPAREN ObjectName (COMMA ObjectName)* RPAREN ; ObjectSet : ObjectSetName | ObjectEnumeration ; ObjectSetName : Name /* OBJECTSETNAME */ | BuiltInObjectSet | ObjectSetConversion ; RelationshipSetName : Name /* RELATIONSHIPSETNAME */ ; QualifiedName : [ObjectSetName PERIOD] StateOrTransitionID ; StateOrTransitionID : Name /* STATENAME or TRANSITIONNAME */ | NONNEGINT ; Name : (NameTerm)+ ; NameTerm : UPPERWORD | LowerWordSeq ; LowerWordSeq : (LOWERWORD)+ BuiltInObjectSet : BOOLEAN | STRINGKEY | INTEGER [NonNANIntStar RangeSymbol NonNANIntStar] | REAL [RealRange] [PrecisionClause] ; RealRange : NonNANRealStar RangeSymbol NonNANRealStar ; PrecisionClause : PosIntLiteral DIGITS ; NonNANIntStar : NonNANInt | STAR | MINUS STAR ; NonNANRealStar : NonNANReal | STAR | MINUS STAR ; /*======================================================================== * END OF RULE DECLARATIONS */ %% /*======================================================================== * END OF FILE $RCSfile: harmony.yacc,v $ */