uOttawaUniversity of Ottawa - Canadas University
list of dots

Umple User Manual    [Previous]   [Next]   

Loading

Umple Grammar

Below is the complete grammar for Umple . This page is generated automatically from the grammar used to parse Umple code.

  • Rules are in blue. You may click on a usage of a rule (underlined and in [[ ]]) anywhere in this manual in order to see the definition.
  • Terminal symbols are in red. These keywords and symbols that are key to Umple's syntax.
  • Identifiers are in green and are surrounded by [ ]. These are places where you can supply a sequence of alphanumeric characters to name a class, attribute or some other entity.
  • Arbitrary input is in yellowish green and surrounded by [** ]. Umple ignores everything until it finds the symbol that terminates the input. This is used for comments and to embed code in a language like Java or PhP. Umple will pass this text to the parser of the underlying language.
  • Comments about the grammar itself are in brown and preceded by //
  • symbols controlling how the grammar is parsed are in black.
      * means zero or more
    • | means 'or'
    • ? means optional
    • Other black items are of interest only to experts

Refer to the Grammar Notation section for more explanation of the EBNF syntax used here.



// The master source of this first part of the Umple grammar is available at
// http://code.google.com/p/umple/source/browse/trunk/cruise.umple/src/umple_core.grammar
// The html rendering is generated from the master and appears in the Umple User manual
// at page http://grammar.umple.org

// Copyright: All contributors to the Umple Project
// This file is made available subject to the open source license found at:
// http://umple.org/license

// The core of umple is a "program". This is the grammar's 'start symbol'
// Comments and lone semicolons are ignored
program- : ( [[comment]] | [[directive]] | ; )*


// Directives are the top-level items in an umple file. See manual page TypesofDirectives
// A directive is either used to configure the system or else is
// an actual entity of the system to be modelled or generated
directive- : [[glossary]]
    | [[generate]]
    | [[generate_path]]
    | [[useStatement]]
    | [[namespace]]
    | [[traceType]]
    | [[entity]]
    | [[debug]]
    | [[strictness]]


// A glossary item is used to fine tune pluralization during code generation
glossary : glossary { [[word]]* }

word : [singular] : [plural] ;


// A high level of strictness will cause warnings to be issued when base language code
// is found, where it might not have been intended. Strictness can also be used
// To either suppress certain messages, or to declare that they should be present.
// NOTE: This is currently under development
strictness : strictness ( [=strictnessLevel:modelOnly|noExtraCode|none]
    | [=message:allow|expect|disallow] [messageNumber] ) ;


// The generate clause can be used to generate multiple outputs
// The --override is used to say that subsequent generate statements will be ignored
generate- : generate [=generate:Java|Php|RTCpp|Ruby|Cpp|Json|Yuml|Violet|Umlet|Simulate|TextUml|GvStateDiagram|GvClassDiagram|Papyrus|Ecore|Xmi|Sql] ;

generate_path : generate [=language:Java|Php|RTCpp|Ruby|Cpp|Json|Yuml|Violet|Umlet|Simulate|TextUml|GvStateDiagram|GvClassDiagram|Papyrus|Ecore|Xmi|Sql] " [**output] " [=override:--override|--override-all]? ;


// Use statements allow incorporation of other Umple files. See UseStatements
useStatement- : use [use] ;


// Namespaces divide the code into logical groups. See NamespaceDirectives
namespace- : namespace [namespace] ;


// The main top level elements to be found in an Umple file
entity- : [[classDefinition]]
    | [[interfaceDefinition]]
    | [[externalDefinition]]
    | [[associationDefinition]]
    | [[associationClassDefinition]]
    | [[stateMachineDefinition]]


// Comments follow the same conventions as C-family languages. UmpleComments
comment- : [[inlineComment]] | [[multilineComment]]

inlineComment- : // [**inlineComment]

multilineComment- : /* [**multilineComment] */


// The Debug statement turns on debugging in code generation. For developer use only
debug- : [=debug] ;


// Instructs a class or method to be abstract
abstract- : [=abstract] ;


// The master of this second part of the Umple grammar is available at
// http://code.google.com/p/umple/source/browse/trunk/cruise.umple/src/umple_classes.grammar

// Copyright: All contributors to the Umple Project
// This file is made available subject to the open source license found at:
// http://umple.org/license

// Classes are the most common elements in Umple.
// See user manual page ClassDefinition
classDefinition : class [name] { [[classContent]]* }


//The external keyword declares a class that is defined in a different
// compilation unit
externalDefinition : external [=interface]? [name] { [[classContent]]* }


// An Interface can only contain method. See interfaceDefinition
interfaceDefinition : interface [name] { [[depend]]* [[interfaceBody]] }


// Associations can be declared outside the body of classes.
// See user manual page IndependentlyDefinedAssociations
associationDefinition : association [name]? { [[association]]* }


// Associations that would be many-many can also become full-fledged classes too
// See user manual page AssociationClassDefinition
associationClassDefinition : associationClass [name] { [[associationClassContent]]* }


// The following items can be found inside the body of classes or association classes
classContent- : [[comment]]
    | [[classDefinition]]
    | [[trace]]
    | [[position]]
    | [[displayColor]]
    | [[abstract]]
    | [[invariant]]
    | [[softwarePattern]]
    | [[depend]]
    | [[symmetricReflexiveAssociation]]
    | [[attribute]]
    | [[stateMachine]]
    | [[inlineAssociation]]
    | [[concreteMethodDeclaration]]
    | [[constantDeclaration]]
    | ;
    | [[extraCode]]

associationClassContent- : [[comment]]
    | [[classDefinition]]
    | [[position]]
    | [[displayColor]]
    | [[invariant]]
    | [[softwarePattern]]
    | [[depend]]
    | [[singleAssociationEnd]] [[singleAssociationEnd]]
    | [[stateMachine]]
    | [[attribute]]
    | [[association]]
    | [[inlineAssociation]]
    | ;
    | [[extraCode]]



// Interfaces: Note that if the format of an abstractMethodDeclaration is not
// followed, then the body will extraCode and passed to the base language
// See user manual page interfaceDefinition
interfaceBody- : [[interfaceMemberDeclaration]]*

interfaceMemberDeclaration : [[constantDeclaration]]
    | [[abstractMethodDeclaration]]
    | [[position]]
    | [[displayColor]]
    | [[isA]]
    | [[extraCode]]


// Constants in interfaces (e.g. constant String ACONSTANT="aValue";)
constantDeclaration : constant ([=list:[]] [name]
    | [type] [=list:[]] [name]
    | [type,name>1,0]) (= [**value]) ;



moreCode- : ([[codeLang]] [[codeLangs]])? { [**code] }

codeLangs- : ( , [[codeLang]] )*

codeLang- : [=codeLang:Java|RTCpp|Cpp|Php|Ruby]


// Methods: The code in concrete methods is passed to the base language
// See user manual page MethodDefinition
methodBody- : ( [[precondition]] )* [**code] ( [[postcondition]] )*

concreteMethodDeclaration : [type] [[methodDeclarator]] ([[codeLang]] [[codeLangs]])? { [[methodBody]] } ( [[moreCode]] )*

abstractMethodDeclaration : [type] [[methodDeclarator]] ;

methodDeclarator : [methodName] [[parameterList]]
    | [methodName] ( )

parameterList : ( [[parameter]] ( , [[parameter]] )* )

parameter : ([=list:[]] [name] | [type] [=list:[]] [name] | [type,name>1,0])


// Details of associations: See manual page AssociationDefinition
association : [=modifier:immutable]? [[associationEnd]] [=arrow:--|->|<-|><] [[associationEnd]] ;

symmetricReflexiveAssociation : [[multiplicity]] self [roleName] ;

inlineAssociation : [=modifier:immutable]? [[inlineAssociationEnd]] [=arrow:--|->|<-|><] [[associationEnd]] ;

inlineAssociationEnd : [[multiplicity]] [[isSorted]]
    | [[multiplicity]] [roleName] [[isSorted]]
    | [[multiplicity]] [roleName]?

singleAssociationEnd : [[multiplicity]] [type,roleName] ;

associationEnd : [[multiplicity]] [type,roleName]
    | [[multiplicity]] [type,roleName] [[isSorted]]

multiplicity- : [=bound:*] | [lowerBound] .. [upperBound] | [bound]

isSorted- : sorted { [priority] }


// Details of attributes. See user manual page AttributeDefinition
attribute : [[simpleAttribute]]
    | [[autouniqueAttribute]]
    | [[derivedAttribute]]
    | [[complexAttribute]]

simpleAttribute- : [~name] ;

autouniqueAttribute- : [=autounique] [name] ;

derivedAttribute- : [=modifier:immutable|settable|internal|defaulted|const]? ([=list:[]] [name]
    | [type] [=list:[]] [name]
    | [type,name>1,0]) = ([[codeLang]] [[codeLangs]])? { [**code] } ( [[moreCode]] )*

complexAttribute- : [=unique]? [=lazy]? [=modifier:immutable|settable|internal|defaulted|const]? ([=list:[]] [name]
    | [type] [=list:[]] [name]
    | [type,name>1,0]) (= [**value])? ;



// Keys are used to define quality and hash codes, plus Sql keys.
// See user manual page KeysforEqualityandHashing
defaultKey : key { }

key : key { [keyId] ( , [keyId] )* }


// Depend clause. See user manual page Dependclause
depend- : depend [depend] ;


// Anything inside a class that is not parsable by Umple is passed on to the base language
// compiler. To raise warnings when this occurs, use the strictness directive.
extraCode- : [**extraCode]

// The master of this second part of the Umple grammar is available at
// http://code.google.com/p/umple/source/browse/trunk/cruise.umple/src/umple_patterns.grammar

// Copyright: All contributors to the Umple Project
// This file is made available subject to the open source license found at:
// http://umple.org/license

softwarePattern- : [[isA]] | [[singleton]] | [[immutable]] | [[keyDefinition]] | [[codeInjection]]


// Generalization and inheritance isAclause
isA- : [[singleIsA]] | [[multipleIsA]]

singleIsA- : isA [extendsName] ( , isA [extendsName] )* ;

multipleIsA- : isA [extendsName] ( , [extendsName] )* ;


// A class that can have only one instance SingletonPattern
singleton- : [=singleton] ;


// A class that can't be modified when created ImmutablePattern
immutable- : [=immutable] ;


// For equality and hashing KeysforEqualityandHashing
keyDefinition- : [[defaultKey]] | [[key]]


// Aspect oriented code injection: BeforeandAfterStatements
codeInjection- : [[beforeCode]] | [[afterCode]]


beforeCode : before [operationName] ([[codeLang]] [[codeLangs]])? { [**code] } ( [[moreCode]] )*

afterCode : after [operationName] ([[codeLang]] [[codeLangs]])? { [**code] } ( [[moreCode]] )*


// The master of this part of the Umple grammar is available at
// http://code.google.com/p/umple/source/browse/trunk/cruise.umple/src/umple_state_machines.grammar

// Copyright: All contributors to the Umple Project
// This file is made available subject to the open source license found at:
// http://umple.org/license

// State machine elements in Umple. See user manual page: BasicStateMachines
stateMachineDefinition : statemachine [=queued]? [name] { [[state]]* }

stateMachine : [[enum]]
    | [[inlineStateMachine]]
    | [[referencedStateMachine]]
    | [[activeDefinition]]


activeDefinition : [=active] [name]? { [**code] }


inlineStateMachine : [=queued]? [name] { ( [[comment]]
    | [[state]]
    | [[trace]]
    | [=||] )* }

referencedStateMachine : [name] as [definitionName] ;
    | [name] as [definitionName] { [[extendedStateMachine]] }


extendedStateMachine : ( [[comment]] | [=changeType:+|-|*]? [[state]] )*


// An enum is a state machine that has no events
enum : [name] { } | [name] { [stateName] (, [stateName])* }


state : [stateName] { ( [[stateInternal]] )* }
    | [=final] [stateName] { ( [[stateInternal]] )* }

stateInternal- : [[comment]] | [=changeType:+|-|*]? [[stateEntity]]

stateEntity- : [=||]
    | [[entryOrExitAction]]
    | [[autoTransition]]
    | [[transition]]
    | [[activity]]
    | [[state]]
    | [[trace]]


autoTransition : [[autoTransitionBlock]] | [[activity]] [[autoTransitionBlock]]



// Autotransitions have no event. The transition is immediately taken
// or taken after the do activity ends
// The action can come before or after the arrow
autoTransitionBlock- : [[guard]]? -> [[action]]? [stateName] ;
    | [[guard]]? [[action]]? -> [stateName] ;


// A transition guard can come before or after the arrow
// The order of guard and event definition can also be interchanged
transition : [[guard]]? [[eventDefinition]]? -> [[action]]? [stateName] ;
    | [[guard]]? [[eventDefinition]]? [[action]]? -> [stateName] ;
    | [[eventDefinition]]? [[guard]]? -> [[action]]? [stateName] ;
    | [[eventDefinition]]? [[guard]]? [[action]]? -> [stateName] ;


eventDefinition- : [[afterEveryEvent]] | [[afterEvent]] | [[eventWithArgs]] | [~event]

afterEveryEvent- : afterEvery ( [timer] )

afterEvent- : after ( [timer] )

eventWithArgs- : [event] ( [**eventArgs] )


// An action can be executed on a transition, or on entry or exit
action : / ([[codeLang]] [[codeLangs]])? { [**code] } ( [[moreCode]] )*

entryOrExitAction : [=type:entry|exit] / ([[codeLang]] [[codeLangs]])? { [**code] } ( [[moreCode]] )*


// A do activity is long-lasting and can be interrupted
activity : do ([[codeLang]] [[codeLangs]])? { [**code] } ( [[moreCode]] )*


moreGuards- : ([[codeLang]] [[codeLangs]])? [ [**code] ]

guard : ([[codeLang]] [[codeLangs]])? [ [**code] ] ( [[moreGuards]] )*

// The master of this part of the Umple grammar is available at
// http://code.google.com/p/umple/source/browse/trunk/cruise.umple/src/umple_traces.grammar

// Copyright: All contributors to the Umple Project
// This file is made available subject to the open source license found at:
// http://umple.org/license

// Trace capabilities of the MOTL sublanguage of Umple.
// See user manual page: ModelOrientedTracingLanguage(MOTL)

// The tool to output the trace: Tracers
traceType : tracer [tracerType] ( [=verbisty:verbose] )? ( [tracerArgument] )* ;


trace : [[traceDirective]] | [[traceCase]]


traceDirective- : trace [[traceItem]] ( [[executeClause]]|[[traceWhen]]|[[traceFor]]|[[tracePeriod]]|[[traceDuring]]|[[traceCaseActivation]]|[[traceRecord]]|[[traceLevel]] )* ;


traceItem- : [[traceEntity]] | [[PreOrPostCondition]]

traceEntity- : [[traceOptions]] [trace_entity] ( , [trace_entity] )*

traceOptions : [[traceOption]] ( , [[traceOption]] )*

traceOption- : [=option:set|get|in|out|entry|exit|cardinality|transition]

PreOrPostCondition- : (giving | where)? [[traceCondition]]


executeClause- : execute { [**trace_execute] }

traceWhen : [=conditionType:where|until|after|giving]? [ [[constraintToken]] ]


traceFor- : for [trace_for]

traceLevel- : level [trace_level]

tracePeriod- : period [trace_period]

traceDuring- : during [trace_duration]

traceRecord- : record [[recordEntity]]

recordEntity- : ( only )? [trace_record] ( , [trace_record] )*


traceCondition- : [LHS] [[conditionRHS]]

conditionRHS- : [comparison_operator] [RHS]


traceCase- : [[traceCaseDef]] | [[traceCaseActivation]] | [[traceCaseDeactivation]]

traceCaseDef- : tracecase [tracecase_name] { [[traceDirective]]* }

traceCaseActivation- : activate [tracecase_act_name] (onAllObjects | onThisThreadOnly)? ;

traceCaseDeactivation- : deactivate [tracecase_deact_name] onThisObject [[deActivateFor]]? ;

deActivateFor- : for [deactivate_for]

// The master of this part of the Umple grammar is available at
// http://code.google.com/p/umple/source/browse/trunk/cruise.umple/src/umple_constraints.grammar

// Copyright: All contributors to the Umple Project
// This file is made available subject to the open source license found at:
// http://umple.org/license

// Constraints in Umple.
// This is currently under development. Constraint capability is being
// developed in agile increments. The first step, described below,
// allows limiting the values of attributes. Code generation is not currently enabled.
// Constraints may appear in classes (including association classes)
// as well as in states.
precondition : [ [name]? pre: [[constraint]] ]

postcondition : [ [name]? post: [[constraint]] ]


invariant : [ ([name] :)? ([[constraint]]) ]

constraintToken : [[constraint]]


// A constraint is an expression optionally be surrounded in round brackets or negated
constraint- : ( ([[constraintBody]]) )
    | [[constraintBody]]

negativeConstraint : ! [[constraint]] | not [[constraint]] | ~ [[constraint]]


// A constraint body is a constraint expression (possibly with a linking operator such as && or ||).
constraintBody- : [[constraintExpr]] ([[linkingOp]])*

linkingOp : ( [=||] [[constraintExpr]])
    | ( [=andOp:and|&&|&] [[constraintExpr]])
    | ( [=orOp:or] [[constraintExpr]])

constraintExpr- : [[negativeConstraint]]
    | [[stringExpr]]
    | [[boolExpr]]
    | [[genExpr]]
    | [[numExpr]]
    | [loneBoolean] ( [ [index] ] )?


compoundExpr- : [[stringExpr]]|[[boolExpr]]|[[numExpr]]|[[genExpr]]


//must be a boolean
boolExpr : [=literal:true|false]
    | [~name] [[equalityOp]] [=literal:true|false]
    | [=literal:true|false] [[equalityOp]] [~name]
    | [~name] [ [~index] ] [[equalityOp]] [=literal:true|false]


//must be string
stringExpr : [~name] [[equalityOp]] [[stringLit]]
    | [[stringLit]] [[equalityOp]] [~name]
    | [~name] [ [~index] ] [[equalityOp]] [[stringLit]]

stringLit- : " [**quote] " | ' [**quote] '


//basically the "other" catagory, contains everything that can be equal to something else
genExpr : [~name] ( [ [index] ] )? [[equalityOp]] [~name] ( [ [index] ] )?


//for floats, doubles and ints
numExpr :[~name] ( . [~tail] )? ( [ [index] ] )? [[ordinalOp]] [~name] ( . [~tail] )? ( [ [index] ] )?


equalityOp- : [[equalsOp]] | [[notequalsOp]]


equalsOp- : [=equalsOp:==|=|equals]

notequalsOp- : [=notequalsOp:!=|/=|=!|=/=]


ordinalOp- : [[greaterOp]]|[[lessOp]]|[[moreOp]]|[[smallerOp]]


greaterOp- :[=greaterOp:greater|>=|=>]

lessOp- :[=lessOp:less|<=|=<]

moreOp- :[=moreOp:larger|>]

smallerOp- :[=smallerOp:smaller|<]


// assOps- : [=associationOp : larger | smaller | exact | hasAll]

// constraintVal : [name]

// constraintBody : [name]


// NOTE: Additional grammar parts deleted while testing is ongoing.
// The master of this part of the Umple grammar is available at
// http://code.google.com/p/umple/source/browse/trunk/cruise.umple/src/umple_layout.grammar

// Copyright: All contributors to the Umple Project
// This file is made available subject to the open source license found at:
// http://umple.org/license

// Layout elements are injected into classes as mixins by diagramming tools such
// as UmpleOnline. Programmers can tweak the layout textually.
position- : [[associationPosition]] | [[elementPosition]]

elementPosition : position [x] [y] [width] [height] ;

associationPosition : position.association [name] [[coordinate]] [[coordinate]] ;

coordinate : [x] , [y]

displayColor : ( displayColor | displayColour ) [**colorValue] ;