23. 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,REALCONSTANTrepresent 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
;