Modo, Easy Modeling Language

Documentation

Structure and Syntax

This chapter describes the basic structure of the Modo language. Additionally Modo syntax is introduced in this chapter.

Syntax

This section defines the Modo syntax. Besides some fundamental differences, Modo syntax shows similarities to Cascading Style Sheets (CSS) language specified in Bos et al. (Bos et al., 2009). The reasons for these similarities are 1) CSS provides great ease for the definition of the elements and their properties and 2) common use of CSS language among different disciplines, especially designers and developers.

Modo syntax is defined using Extended BNF metalanguage specified in ISO/IEC 14977 (ISO/IEC 14977, 1996). By using the Extended BNF metalanguage, syntactic sequence of the Modo is separated into lexical units. This helps to identify every lexical unit in a meaningful Modo sentence.

These definitions include some of the main syntactic parts of the Modo language. For the complete list of definitions, please refer to Appendix A. Grammar.

Following example shows the declaration of an element in Modo syntax:

/* Company Element Declaration */
Company {
    Name = String;
    $Name = "Doe Software Inc.";
    Founder = String;
    $Founder = "John Doe";
    TaxNumber = String;	
    $TaxNumber = "123456789987654321";
}                

The example above shows the declaration of Company element. On line 1, a descriptive comment is added to the declaration. On line 2, the declaration of the Company element starts.

On lines 3, 5 and 7 the member elements, Name, Founder and TaxNumber of the Company element are declared respectively. On lines 4, 6 and 8 initial values of those member elements are assigned. Please note that the dollar symbol "$" preceding the member element name refers to the value of that member element.

Finally on line 9, Company element declaration ends with end declaration symbol "}".

Note: The above example assumes that the element String has already been defined.

Tokenization

For better understanding, Modo syntax is separated into tokens at lexical level. A Modo declaration consists of a sequence of these tokens.

Following is the general Extended BNF notation of the Modo:

modo = { 
    directive | rule | declaration | comment
};

As you can see above, Modo definition consists of directives, rules, declarations and comments. Followings are the Extended BNF notations of each token:

(* Directive Definition *)
directive = {blank}, at symbol, identifier,
        {blank}-, expression, {blank},
        end sentence symbol;

(* Rule Definition *)
rule = {blank}, at symbol, {blank},
        start group symbol, {blank},
        expression, {blank}, end group symbol,
        {blank}, start declaration symbol,
        {blank}, modo, {blank},
        end declaration symbol;

(* Comment Definition *)
comment = delimited comment
        | single line comment;

(* Declaration Definition *)
declaration = {
    assignment
    | basic declaration
    | extended declaration
};

Characters (The Unicode Standard, 2003), letters, numerals, symbols and operators used in Modo syntax are defined as follows:

letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H"
        | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P"
        | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X"
        | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f"
        | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n"
        | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v"
        | "w" | "x" | "y" | "z";

character = any Unicode character;

whitespace = {
    space character
    | tab character
    | line feed character
    | carriage return character
    | form feed character
};

new line = carriage return character
    | line feed character
    | next line character
    | line separator character
    | paragraph separator character;

space character = " ";

tab character =
        ? The Unicode Standard Tab Character (U+0009) ? ;

line feed character =
        ? The Unicode Standard Line Feed Character (U+000A) ? ;

carriage return character =
        ? The Unicode Standard
        Carriage Return Character (U+000D) ? ;

form feed character =
        ? The Unicode Standard Form Feed Character (U+000C) ? ;

next line character =
        ? The Unicode Standard Next Line Character (U+0085) ? ;

line separator character =
        ? The Unicode Standard
        Line Separator Character (U+2028) ? ;

paragraph separator character =
        ? The Unicode Standard
        Paragraph Separator Character (U+2029) ? ;

digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"
        | "8" | "9";

at symbol = "@";

assignment symbol = "=";

end sentence symbol = ";";

start group symbol = "(";

end group symbol = ")";

start declaration symbol = "{";

end declaration symbol = "}";

backslash symbol = "\";

start attribute selector symbol = "[";

end attribute selector symbol = "]";

start delimited comment symbol = "/*";

end delimited comment symbol = "*/";

start single line comment symbol = "//";

dot symbol = ".";

comma symbol = ",";

underscore symbol = "_";

hyphens symbol = "-";

escaped single quote symbol = "\'";

escaped double quote symbol = '\"';

single quote symbol = "'";

double quote symbol = '"';

increment operator = "++";

decrement operator = "--";

unary operator = "+" | "-" | "!" | "~"
        | increment operator
        | decrement operator;

operator = "*" | "/" | "%" | "+" | "-" | "<<" | ">>" | "<"
        | ">" | "<=" | ">=" | "==" | "!=" | "&" | "^" | "|"
        | "&&" | "||";

unary selector operator = "$", ".", "#", "?", " ";

selector operator = ">", "<", "+", "-", "~", "^", ":",
        "::", "%", "&", "|", "\", "/";

selector expression operator = "*" | "/" | "%" | "+" | "-"
        | "<<" | ">>" | "<" | ">" | "=" | "&" | "^" | "|"
        | "<=" | ">=" | "==" | "!=" | "*=" | "/=" | "%="
        | "+=" | "-=" | "&=" | "^=" | "|=" | "$=" | "~="
        | ".=" | "#=" | "?=" | ":=" | "&&" | "||";

universal selector = "*";

Additionally there are some extra tokens used in Modo syntax. For the sake of continuity, only main syntactic parts are shown here. Please refer to Appendix A. Grammar for complete list of tokens.

In Modo syntax, characters of any kind including whitespace are not allowed between syntactic parts.

Only the space character, tab character, line feed character, carriage return character and form feed character can occur in whitespace

Characters and case

Modo syntax is case-insensitive. Elements and member elements declared in Modo can be considered as case-insensitive.

Following is the Extended BNF notation of identifier and lhs identifier:


identifier = {letter | underscore symbol}-,

        {

            digit

            | letter

            | underscore symbol

        };

The identifier definition above shows that the identifier starts with letter or underscore symbol "_" and can continue with digit, letter or underscore symbol "_".


lhs identifier = {

            letter

            | underscore symbol

            | hyphens symbol

        }-,

        {

            digit

            | letter

            | underscore symbol

            | hyphens symbol

        };

The left-hand side selector (lhs) identifier shows that lhs identifier starts with either letter, underscore symbol "_" or hyphens symbol "-".

/* Company Element Declaration */
Company {
    Name = String;
    $Name = "Doe\'s Software Inc.";
    Founder = String;
    $Founder = "John Doe";
    TaxNumber = String;	
    $TaxNumber = "123456789987654321";
}             

The example above shows the declaration of Company element. In this declaration Company, Name, Founder and TaxNumber are the left-hand side identifiers.

Additionally, there is an alternative use of backslash symbol "\" in strings. Backslash symbol is used to print single and double quote symbols in string values. Also for printing backslash symbol in string values, one must specify two backslash symbols "\\" consecutively.

Following is the Extended BNF notation of escaped single quote symbol and escaped double quote symbol:


escaped single quote symbol = "\'";



escaped double quote symbol = '\"';

In addition to that, string, single quote escaped string and double quote escaped string definitions are as follows:


string = (

            single quote symbol,

            single quote escaped string,

            single quote symbol

        )

        |

        (

            double quote symbol,

            double quote escaped string,

            double quote symbol

        );



single quote escaped string = {

        (any Unicode character - single quote symbol)

        | escaped single quote symbol

};



double quote escaped string = {

        (any Unicode character - double quote symbol)

        | escaped double quote symbol

};
Directives

Directives are the instructions directly related with the Modo generators/compilers/interpreters. They are not a part of the system declared in Modo. Directives start with at symbol "@" and continue with identifier and expression. Finally, directives end with end sentence symbol ";".


(* Directive Definition *)

directive = {blank},

        at symbol,

        identifier,

        {blank}-,

        expression,

	  {blank},

        end sentence symbol;
Rules

In Modo syntax, Rules play an important role of representing the different states of a system. In real life, the elements of a system might contain different properties or values for different states of the system. When modeling the system, those different states, values and properties must be included in the model. In Modo syntax, those different properties and values are reflected using the Rules.

Declarations, types and the values of the elements can be specified depending on rules. With the help of rules, values and properties of the system can be changed or set depending on one or more conditions. Rules start with at symbol "@".

There are two types of rules: 1) Rule blocks and 2) inline rules. Following is the Extended BNF notation of rules (rule blocks) and inline rules:


rule = {blank},

        at symbol,

        {blank},

        start group symbol,

        {blank},

        expression,

        {blank},

        end group symbol,

        {blank},

        start declaration symbol,

        {blank},

        modo,

        {blank},

        end declaration symbol;

The rule definition above shows that rule starts with at symbol "@", and continues with start group symbol, expression and end group symbol. After rule expression is specified, rule specific declaration starts with start declaration symbol. Any meaningful Modo declaration can be placed between declaration symbols. Finally, rule ends with end declaration symbol.


inline rule = {blank},

        at symbol,

        {blank},

        start group symbol,

        {blank},

        expression,

        {blank},

        end group symbol;

Similarly, the inline rule starts with at symbol "@" and continues with start group symbol, expression and end group symbol.

Following example shows the use of rules in Modo declarations:

Company {
    Name = String;
    $Name = "Doe Software Inc.";
    $Name = "DOE Corp." @ ($CurrentYear > 2008);
    Founder = String;
    $Founder = "John Doe";
    TaxNumber = String;
    $TaxNumber = "123456789987654321";	
}
                

The example above shows the use of inline rules. On line 2, the Name member element of the Company element is defined and on line 3, it is assigned an initial value. On line 4, another value is assigned to the Name element, but this time depending on the rule ($CurrentYear > 2008).

Imagine a scenario where the company's name was changed to "DOE Corp." in the year 2008. Therefore, once the value of the CurrentYear is greater than 2008 the value of the Name element is "DOE Corp.". In other cases, the value of the Name element is "Doe Software Co.,Ltd.".

Company {
    Name = String;
    Founder = String;
    TaxNumber = String;	
    $Name = "Doe Software Inc.";
    @ ($CurrentYear > 2008) {
        $Name = "DOE Corp.";
    }
    $Founder = "John Doe";
    $TaxNumber = "123456789987654321";	
}
                

The example above shows the use of rule blocks. On line 6, rule block starts with at symbol "@". On line 7, a new value is assigned to the Name element. Finally, rule block ends with end declaration symbol on line 8.

One possible implementation of Rules in Modo syntax is to define a value or property of elements that does not change in any state of the system.

For the previous scenario, assume that the tax number of the company is always the same. Therefore, value of the TaxNumber element never changes. The following example shows the Modo syntax, which defines an everlasting rule.

Company {
    Name = String;
    Founder = String;
    TaxNumber = String;	
    $Name = "Doe Software Inc.";
    $Founder = "John Doe";
    $TaxNumber = "123456789987654321" @ (1);	
}                

In the above example, the elements are defined similarly to the previous example. However, when assigning values a rule is defined for the value of the TaxNumber element. On line 7, after the value is assigned to the TaxNumber element the rule (1) is defined. This rule indicates that, for all states of the system the value of the TaxNumber element is "123456789987654321".

Note: The above examples assume that the member element CurrentYear and element String have already been declared.

Blocks

Blocks are used for element and rule declarations. In Modo syntax, blocks start with start declaration symbol "{" and end with end declaration symbol "}" (Appendix A. Grammar). Every start declaration symbol must end with end declaration symbol.

Similarly, in string values if a string starts with single quote symbol, it must end with single quote symbol. In addition, if a string starts with double quote symbol, it must end with double quote symbol. Every expression that starts with start group symbol "(" likewise ends with end group symbol ")".

Selectors

Modo syntax provides some pattern-matching rules for element and member element declarations. These pattern-matching rules are called "Selectors".

Modo syntax introduces selectors conceptually. For further information, please refer to Selectors.

Elements

Elements are the basic Modo structures that define real life entities. Elements can be declared by single line definitions or block declarations.

Following example shows the declaration of Company element.

/* Company Element Declaration */
Company {
    Name = String;
    $Name = "Doe Software Inc.";
    Founder = String;
    $Founder = "John Doe";
    TaxNumber = String;	
    $TaxNumber = "123456789987654321";
}  
              

Elements can be declared by extending built-in or previously declared elements. Following example shows the declaration of Worker and Developer elements:

Worker {
    FirstName = String;
    LastName = String;
    Department = String;
}
                

The example above shows the declaration of Worker element. On line 1, "Worker" identifier is specified and declaration of the Worker element starts with start declaration symbol. On line 2, FirstName member element is defined. On line 3, LastName member element is defined and on line 4, Department member element is defined. Finally, element declaration ends with end declaration symbol.

Below is the declaration of the Developer element, which is an extension of the Worker element.

Developer = Worker {
    $Department = "Software Development";
}                

The example above extends the Worker declaration. On line 1, Developer element is declared extending the Worker element. Additionally on line 2, a specific value is assigned to the Department element.

Declarations

There are three types of Modo element declarations:

  • Assignments
  • Basic Declarations
  • Extended Declarations

Assignments are one-line declarations where the assignment symbol "=" is used and values are assigned to the elements and member elements.

Basic declarations are the typical element declarations as blocks.

Extended declarations are the declarations that extend built-in or previously declared elements.

For further information about declarations, please refer to Declarations.

Expressions

Modo syntax allows using expressions for assignments. Following example shows the use of expression in assignments:

Worker {
    $FirstName = "John";
    $LastName = "Doe";
    $FullName = ($FirstName + " " + $LastName);
}
                

The example above shows the declaration of Worker element. On line 4, the value of the FullName member element is specified by an expression. According to this expression, value of the FullName member element is composed of the value of the FirstName member element, the space character " " and the value of the LastName member element.

Modo declarations specify the state of the system for the given time periods. This nature of the Modo necessitates that the assignments must be valid for the given time periods. Therefore, for the above example, when the FirstName attribute value changes, FullName attribute value must be recalculated and updated by the generators/compilers/interpreters using this Modo model.

For further information, please refer to Expressions chapter.

Comments

There are two types of comments:

  • Delimited Comments
  • Single Line Comments

comment = delimited comment

        | single line comment;

Delimited comments start with start delimited comment symbol "/*" and end with end delimited comment symbol "*/".


delimited comment = {blank},

        start delimited comment symbol,

        ({character} - end delimited comment symbol),

        end delimited comment symbol;

Single line comments start with start single line comment symbol "//" and end with any kind of new line character.


single line comment = {blank},

	  start single line comment symbol,

        ({character} - new line),

        new line;

Comments include descriptions and notes about Modo declarations. Modo generators/compilers/interpreters ignore comments during generation, compiling and interpreting process. Comments are useful for making code more readable.

/* Beginning of Company element declaration */
Company {
    /* Name member element definition */
    Name = String;
    /* Value assigned to Name element */
    $Name = "Doe Software Inc.";
    /* Founder member element definition */
    Founder = String;
    /* Value assigned to Founder element */
    $Founder = "John Doe";
    /* TaxNumber member element definition */
    TaxNumber = String;	
    /* Value assigned to TaxNumber element */
    $TaxNumber = "123456789987654321";
}
/* End of Company element declaration */
                

In the example above, comments are used on lines 1, 3, 5, 7, 9, 11, 13 and 16.

Values

There are two types of values in Modo syntax.

  • Numeric values (integers and real numbers)
  • Strings

All the element or member element values must be specified using either numeric values or strings.

Integers and real numbers

Integers and real numbers are formed by bringing digits [0-9] together.

Following is the Extended BNF notation of integer and constant (real number) syntax:


integer = "0" | (digit - "0", {digit});



constant = integer,

        [

            dot symbol,

            {digit}-

        ];

The syntax above shows that constant (real number) values include integer values. Decimal digits are separated using dot symbol ".".

Strings

Except numerals, all the values in Modo declarations must be specified as strings. Strings start with single quote symbol or double quote symbol and end with single quote symbol or double quote symbol respectively. Following examples show the different use of strings:

A = "This is double quote string.";
A = 'This is single quote string.';
A = "This is double quote \" escaped string";
A = 'This is single quote \' escaped string';
A = 'This is a \'string\'';
A = "This is a \"string\"";