Appendix: Message Definitions Grammar

This appendix contains the grammar for the message definitions language.

In the language, space, horizontal tab and new line characters count as delimiters, so one or more of them is required between two elements of the description which would otherwise be unseparable.

The // symbol initiates comments that extend to the end of the line.

The language is case sensitive.

Notation:

  • rule syntax is that of bison

  • uppercase words are terminals, lowercase words are nonterminals

  • NAME, CHARCONSTANT, STRINGCONSTANT, INTCONSTANT, REALCONSTANT represent identifier names and string, character, integer and real number literals (defined as in the C language)

  • other terminals represent keywords in all lowercase

Nonterminals ending in _old are present so that message files from OMNeT++ (3.x) can be parsed.

msgfile
        : definitions
        ;

definitions
        : definitions definition
        | %empty
        ;

definition
        : namespace\_decl
        | fileproperty
        | cplusplus
        | import
        | struct\_decl
        | class\_decl
        | message\_decl
        | packet\_decl
        | enum\_decl
        | enum
        | message
        | packet
        | class
        | struct
        ;

namespace\_decl
        : NAMESPACE qname ';'
        | NAMESPACE ';'

qname
        : '::' qname1
        | qname1
        ;

qname1
        : qname1 '::' NAME
        | NAME
        ;

fileproperty
        : property\_namevalue ';'
        ;

cplusplus
        : CPLUSPLUS '{{' ... '}}' opt\_semicolon
        | CPLUSPLUS '(' targetspec ')' '{{' ... '}}' opt\_semicolon
        ;
        ;

targetspec
        : targetspec targetitem
        | targetitem
        ;

targetitem
        : NAME | '::' | INTCONSTANT | ':' | '.' | ',' | '~' | '=' | '&'
        ;

import
        : IMPORT importspec ';'
        ;

importspec
        : importspec '.' importname
        | importname
        ;

importname
        : NAME
        | MESSAGE | PACKET | CLASS | STRUCT | ENUM | ABSTRACT
        ;

struct\_decl
        : STRUCT qname ';'
        ;

class\_decl
        : CLASS qname ';'
        | CLASS NONCOBJECT qname ';'
        | CLASS qname EXTENDS qname ';'
        ;

message\_decl
        : MESSAGE qname ';'
        ;

packet\_decl
        : PACKET qname ';'
        ;

enum\_decl
        : ENUM qname ';'
        ;

enum
        : ENUM qname '{'
          opt\_enumfields\_and\_properties '}' opt\_semicolon
        ;

opt\_enumfields\_and\_properties
        : enumfields\_and\_properties
        | %empty
        ;

enumfields\_and\_properties
        : enumfields\_and\_properties enumfield
        | enumfields\_and\_properties property
        | enumfield
        | property
        ;

enumfield
        : NAME ';'
        | NAME '=' enumvalue ';'
        ;

message
        : message\_header body
        ;

packet
        : packet\_header body
        ;

class
        : class\_header body
        ;

struct
        : struct\_header body
        ;

message\_header
        : MESSAGE qname '{'
        | MESSAGE qname EXTENDS qname '{'
        ;

packet\_header
        : PACKET qname '{'
        | PACKET qname EXTENDS qname '{'
        ;

class\_header
        : CLASS qname '{'
        | CLASS qname EXTENDS qname '{'
        ;

struct\_header
        : STRUCT qname '{'
        | STRUCT qname EXTENDS qname '{'
        ;

body
        : opt\_fields\_and\_properties
          '}' opt\_semicolon
        ;

opt\_fields\_and\_properties
        : fields\_and\_properties
        | %empty
        ;

fields\_and\_properties
        : fields\_and\_properties field
        | fields\_and\_properties property
        | field
        | property
        ;

field
        :  fieldtypename opt\_fieldvector opt\_inline\_properties ';'
        |  fieldtypename opt\_fieldvector opt\_inline\_properties '=' fieldvalue opt\_inline\_properties ';'
        ;

fieldtypename
        : fieldmodifiers fielddatatype NAME
        | fieldmodifiers NAME
        ;

fieldmodifiers
        : ABSTRACT
        | %empty
        ;

fielddatatype
        : fieldsimpledatatype
        | fieldsimpledatatype '*'
        | CONST fieldsimpledatatype
        | CONST fieldsimpledatatype '*'
        ;

fieldsimpledatatype
        : qname
        | CHAR
        | SHORT
        | INT
        | LONG
        | UNSIGNED CHAR
        | UNSIGNED SHORT
        | UNSIGNED INT
        | UNSIGNED LONG
        | DOUBLE
        | STRING
        | BOOL
        ;

opt\_fieldvector
        : '[' INTCONSTANT ']'
        | '[' qname ']'
        | '[' ']'
        | %empty
        ;

fieldvalue
        : fieldvalue fieldvalueitem
        | fieldvalueitem
        ;

fieldvalueitem
        : STRINGCONSTANT
        | CHARCONSTANT
        | INTCONSTANT
        | REALCONSTANT
        | TRUE
        | FALSE
        | NAME
        | '::'
        | '?' | ':' | '&&' | '||' | '##' | '==' | '!=' | '>' | '>=' | '<' | '<='
        | '&' | '|' | '#' | '<<' | '>>'
        | '+' | '-' | '*' | '/' | '%' | '^' | UMIN | '!' | '~'
        | '.' | ',' | '(' | ')' | '[' | ']'
        ;

enumvalue
        : INTCONSTANT
        | '-' INTCONSTANT
        | NAME
        ;

opt\_inline\_properties
        : inline\_properties
        | %empty
        ;

inline\_properties
        : inline\_properties property\_namevalue
        | property\_namevalue
        ;

property
        : property\_namevalue ';'
        ;

property\_namevalue
        : property\_name
        | property\_name '(' opt\_property\_keys ')'
        | ENUM '(' NAME ')'
        ;

property\_name
        : '@' PROPNAME
        | '@' PROPNAME '[' PROPNAME ']'
        ;

opt\_property\_keys
        : property\_keys
        ;

property\_keys
        : property\_keys ';' property\_key
        | property\_key
        ;

property\_key
        : property\_literal '=' property\_values
        | property\_values
        ;

property\_values
        : property\_values ',' property\_value
        | property\_value
        ;

property\_value
        : property\_literal
        | %empty
        ;

property\_literal
        : property\_literal CHAR
        | property\_literal STRINGCONSTANT
        | CHAR
        | STRINGCONSTANT
        ;

opt\_semicolon
        : ';'
        | %empty
        ;