languageengineer_modellanguage.rst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. Modelling Language
  2. ==================
  3. We now revisit the modelling language.
  4. All concepts defined for modellers, are equally valid for language engineers.
  5. Indeed, language engineering is a specific type of modelling.
  6. The only real extension that we need to make, is to extend the syntax with a specific construct to define a generalization hierarchy and attributes.
  7. Generalization
  8. --------------
  9. The first concept is that of generalization.
  10. As expected, a class can inherit from another class through the intuitive notation::
  11. Class NamedElement {}
  12. Class Place : NamedElement {}
  13. Class Transition : NamedElement {}
  14. What is special in the Modelverse, is that associations can just as well inherit from one another::
  15. Association Arc (NamedElement, NamedElement) {}
  16. Association P2T : Arc (Place, Transition) {}
  17. Association T2P : Arc (Transition, Place) {}
  18. Attributes
  19. ----------
  20. Attributes can still be created using only modelling constructs, as introduced before, though this becomes convoluted.
  21. More efficiently, the attribute can be defined as follows.
  22. Note that, thanks to inheritance, the *Place* and *Transition* can also access the *name* attribute, as they inherit it.
  23. The *NamedElement* can now be defined as follows::
  24. Class NamedElement{
  25. name : String
  26. }
  27. Note that now as well, it is necessary to define the types.
  28. This can just be done as expected::
  29. SimpleAttribute String {
  30. constraint = $
  31. String function constraint(value : Element):
  32. if (is_primitive_string(value)):
  33. return "OK"!
  34. else:
  35. return "String has a non-string value"!
  36. $
  37. }
  38. Finally, it is possible to define an *optional* attribute.
  39. In that case, the attribute must not be defined, though you should be aware that reading an undefined attribute will result in an error value being returned.
  40. Default values are not supported in the Modelverse.
  41. This is done by using the following notation to make the attribute optional::
  42. Class NamedElement {
  43. name? : String
  44. }
  45. A Petri Net metamodel can now be created, based on the SimpleClassDiagrams metamodel.
  46. This looks like this::
  47. include "primitives.alh"
  48. SimpleAttribute String {
  49. constraint = $
  50. String function constraint(value : Element):
  51. if (is_primitive_string(value)):
  52. return "OK"!
  53. else:
  54. return "String has a non-string value"!
  55. $
  56. }
  57. SimpleAttribute Natural {
  58. constraint = $
  59. String function constraint(value : Element):
  60. if (bool_not(is_physical_int(value))):
  61. return "Natural has no integer value"!
  62. elif (integer_lt(value, 0)):
  63. return "Natural does not have a positive or zero value"!
  64. else:
  65. return "OK"!
  66. $
  67. }
  68. Class NamedElement {
  69. name : String
  70. }
  71. Class Place : NamedElement {
  72. tokens : Natural
  73. }
  74. Class Transition : NamedElement {}
  75. Association Arc (NamedElement, NamedElement) {
  76. weight : Natural
  77. }
  78. Association P2T : Arc (Place, Transition) {}
  79. Association T2P : Arc (Transition, Place) {}