Skip to content

Grammar railroad diagram #272

@mingodad

Description

@mingodad

The link for https://www.cifasis-conicet.gov.ar/jfernandez/micromodelica/micromodelicaspec.pdf on the README is broken.

I've just added this project grammar to https://mingodad.github.io/parsertl-playground/playground/ an Yacc/Lexer compatible online editor/interpeter (select "Mocc QSS-Solver parser (partially working)" from Examples then click Parse to see a parse tree for the content in Input source), from there I generated an EBNF understood by https://github.com/GuntherRademacher/rr to generate a nice navigable railroad diagram for the grammar (see bellow instructions at the top).

While doing so I replaced several right recursive rules by left recursive ones and the parser speed increased significantly (also removed/inlined some simple rules).

I hope this can help document/develop/debug the grammar for this project !

//
// EBNF to be viewd at
//    (IPV6) https://www.bottlecaps.de/rr/ui
//    (IPV4) https://rr.red-dove.com/ui
//
// Copy and paste this at one of the urls shown above in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//

input::=
	  stored_definition

stored_definition::=
	  opt_within_name class_definition_list

opt_within_name::=
	  /*%empty*/
	| TOKWITHIN opt_name TOKSEMICOLON

opt_name::=
	  /*%empty*/
	| name

name::=
	  TOKID
	| TOKDOT TOKID
	| name TOKDOT TOKID

class_definition_list::=
	  /*%empty*/
	| class_definition_list class_definition_aux

class_definition_aux::=
	  opt_final class_definition TOKSEMICOLON

class_definition::=
	  opt_encapsulated class_prefix class_specifier

opt_encapsulated::=
	  /*%empty*/
	| TOKENCAPSULATED

class_prefix::=
	  opt_partial class_prefixes

opt_expandable::=
	  /*%empty*/
	| TOKEXPANDABLE

opt_pure_impure_operator::=
	  /*%empty*/
	| TOKPURE opt_operator
	| TOKIMPURE opt_operator

opt_final::=
	  /*%empty*/
	| TOKFINAL

class_prefixes::=
	  TOKCLASS
	| TOKMODEL
	| opt_operator TOKRECORD
	| TOKBLOCK
	| opt_expandable TOKCONNECTOR
	| TOKTYPE
	| TOKPACKAGE
	| opt_pure_impure_operator TOKFUNCTION
	| TOKOPERATOR

opt_operator::=
	  /*%empty*/
	| TOKOPERATOR

opt_partial::=
	  /*%empty*/
	| TOKPARTIAL

class_specifier::=
	  TOKID string_comment composition TOKEND TOKID
	| TOKID TOKEQUAL base_prefix name opt_array_subscripts opt_class_modification comment
	| TOKID TOKEQUAL TOKENUMERATION TOKOPAREN enumeration_args TOKCPAREN comment
	| TOKID TOKEQUAL TOKDER TOKOPAREN name more_ids TOKCPAREN comment
	| TOKEXTENDS TOKID opt_class_modification string_comment composition TOKEND TOKID

more_ids::=
	  TOKCOMA TOKID
	| more_ids TOKCOMA TOKID

composition::=
	  composition_aux_1 opt_external_composition opt_annotation_composition

opt_external_composition::=
	  /*%empty*/
	| TOKEXTERNAL opt_language_specification opt_external_function_call opt_annotation TOKSEMICOLON
	| TOKEXTERNAL opt_language_specification component_reference TOKEQUAL opt_external_function_call opt_annotation TOKSEMICOLON

opt_language_specification::=
	  /*%empty*/
	| TOKSTRING

opt_external_function_call::=
	  /*%empty*/
	| TOKID TOKOPAREN expression_list TOKCPAREN
	| TOKID TOKOPAREN TOKCPAREN

opt_annotation_composition::=
	  /*%empty*/
	| annotation TOKSEMICOLON

composition_aux_1::=
	  /*%empty*/
	| element TOKSEMICOLON element_list
	| element TOKSEMICOLON element_list composition_element composition_list
	| composition_element composition_list

string_comment::=
	  /*%empty*/
	| TOKSTRING
	| TOKSTRING TOKPLUS string_comment_no_empty

string_comment_no_empty::=
	  TOKSTRING
	| TOKSTRING TOKPLUS string_comment_no_empty

element::=
	  import_clause
	| extends_clause
	| opt_redeclare opt_final opt_inner opt_outer element_option opt_constraining_clause

import_clause::=
	  TOKIMPORT opt_import comment

opt_import::=
	  TOKID TOKEQUAL name
	| name opt_import_spec

opt_import_spec::=
	  /*%empty*/
	| TOKDOTSTAR
	| TOKDOT TOKOBRACE import_list TOKCBRACE

import_list::=
	  TOKID
	| import_list TOKCOMA TOKID

comment::=
	  string_comment opt_annotation

element_list::=
	  /*%empty*/
	| element_list element TOKSEMICOLON

extends_clause::=
	  TOKEXTENDS name opt_class_modification opt_annotation

opt_redeclare::=
	  /*%empty*/
	| TOKREDECLARE

opt_inner::=
	  /*%empty*/
	| TOKINNER

opt_outer::=
	  /*%empty*/
	| TOKOUTER

opt_constraining_clause::=
	  /*%empty*/
	| constraining_clause comment

constraining_clause::=
	  TOKCONSTRAINEDBY name opt_class_modification

element_option::=
	  element_option_1
	| TOKREPLACEABLE element_option_1

element_option_1::=
	  class_definition
	| component_clause

component_clause::=
	  type_prefix type_specifier opt_array_subscripts component_list

type_prefix::=
	  /*%empty*/
	| opt_input_output
	| opt_disc_param_const
	| opt_disc_param_const opt_input_output
	| opt_flow_stream
	| opt_flow_stream opt_disc_param_const
	| opt_flow_stream opt_disc_param_const opt_input_output

opt_flow_stream::=
	  TOKFLOW
	| TOKSTREAM

opt_disc_param_const::=
	  TOKDISCRETE
	| TOKPARAMETER
	| TOKCONSTANT

opt_input_output::=
	  TOKINPUT
	| TOKOUTPUT

type_specifier::=
	  name

opt_array_subscripts::=
	  /*%empty*/
	| array_subscripts

component_list::=
	  component_declaration
	| component_list TOKCOMA component_declaration

component_declaration::=
	  declaration opt_condition_attribute comment

declaration::=
	  TOKID opt_array_subscripts opt_modification

opt_condition_attribute::=
	  /*%empty*/
	| TOKIF expression

composition_list::=
	  /*%empty*/
	| composition_list composition_element

composition_element::=
	  TOKPUBLIC element_list
	| TOKPROTECTED element_list
	| eq_alg_section_init

opt_modification::=
	  /*%empty*/
	| modification

modification::=
	  class_modification opt_equal_exp
	| TOKEQUAL expression
	| TOKASSING expression

class_modification::=
	  TOKOPAREN opt_argument_list TOKCPAREN

opt_argument_list::=
	  /*%empty*/
	| argument_list

argument_list::=
	  argument
	| argument_list TOKCOMA argument

argument::=
	  element_modification_replaceable
	| element_redeclaration

opt_each::=
	  /*%empty*/
	| TOKEACH

element_modification_replaceable::=
	  opt_each opt_final element_modification
	| opt_each opt_final element_replaceable

element_modification::=
	  name opt_modification string_comment

element_replaceable::=
	  TOKREPLACEABLE short_class_definition opt_constraining_clause
	| TOKREPLACEABLE component_clause1 opt_constraining_clause

opt_equal_exp::=
	  /*%empty*/
	| TOKEQUAL expression

element_redeclaration::=
	  TOKREDECLARE opt_each opt_final element_redeclaration_1

element_redeclaration_1::=
	  element_redeclaration_2
	| element_replaceable

element_redeclaration_2::=
	  short_class_definition
	| component_clause1

short_class_definition::=
	  class_prefixes TOKID TOKEQUAL short_class_definition_exp

short_class_definition_exp::=
	  base_prefix name opt_array_subscripts opt_class_modification comment
	| TOKENUMERATION TOKOPAREN enumeration_args TOKCPAREN comment

enumeration_args::=
	  TOKSEMICOLON
	| enum_list

enum_list::=
	  enumeration_literal
	| enum_list TOKCOMA enumeration_literal

enumeration_literal::=
	  TOKID comment

component_clause1::=
	  type_prefix type_specifier declaration comment

opt_class_modification::=
	  /*%empty*/
	| class_modification

base_prefix::=
	  type_prefix

subscript_list::=
	  subscript
	| subscript_list TOKCOMA subscript

subscript::=
	  TOKCOLON
	| expression

array_subscripts::=
	  TOKOBRACKET subscript_list TOKCBRACKET

opt_annotation::=
	  /*%empty*/
	| annotation

annotation::=
	  TOKANNOTATION class_modification

eq_alg_section_init::=
	  TOKINITIALEQ equation_list
	| TOKEQUATION equation_list
	| TOKINITIALALG statement_list
	| TOKALGORITHM statement_list

equation_list::=
	  /*%empty*/
	| equation_list equation TOKSEMICOLON

equation::=
	  connect_clause comment
	| if_equation comment
	| simple_expression TOKEQUAL expression comment
	| primary
	| for_equation comment
	| when_equation

for_indices::=
	  for_index
	| for_indices TOKCOMA for_index

for_index::=
	  TOKID opt_in

opt_in::=
	  /*%empty*/
	| TOKIN expression

for_equation::=
	  TOKFOR for_indices TOKLOOP equation_list TOKEND TOKFOR

when_equation::=
	  TOKWHEN expression TOKTHEN equation_list opt_else_when TOKEND TOKWHEN comment

opt_else_when::=
	  /*%empty*/
	| opt_else_when TOKELSEWHEN expression TOKTHEN equation_list

if_equation::=
	  TOKIF expression TOKTHEN equation_list opt_elseif_eq opt_else_eq TOKEND TOKIF

opt_elseif_eq::=
	  /*%empty*/
	| opt_elseif_eq TOKELSEIF expression TOKTHEN equation_list

opt_else_eq::=
	  /*%empty*/
	| TOKELSE equation_list

connect_clause::=
	  TOKCONNECT TOKOPAREN component_reference TOKCOMA component_reference TOKCPAREN

statement_list::=
	  /*%empty*/
	| statement_list statement TOKSEMICOLON

statement::=
	  component_reference opt_assing comment
	| TOKOPAREN output_expression_list TOKCPAREN TOKASSING component_reference function_call_args
	| while_statement comment
	| when_statement
	| for_statement comment
	| if_statement comment
	| TOKBREAK comment
	| TOKRETURN comment

while_statement::=
	  TOKWHILE expression TOKLOOP statement_list TOKEND TOKWHILE

when_statement::=
	  TOKWHEN expression TOKTHEN statement_list opt_else_when_list TOKEND TOKWHEN comment

opt_else_when_list::=
	  /*%empty*/
	| opt_else_when_list TOKELSEWHEN expression TOKTHEN statement_list

for_statement::=
	  TOKFOR for_indices TOKLOOP statement_list TOKEND TOKFOR

if_statement::=
	  TOKIF expression TOKTHEN statement_list opt_esleif_st opt_else_st TOKEND TOKIF

opt_esleif_st::=
	  /*%empty*/
	| opt_esleif_st TOKELSEIF expression TOKTHEN statement_list

opt_else_st::=
	  /*%empty*/
	| TOKELSE statement_list

output_expression_list::=
	  /*%empty*/
	| output_expression_list_more

output_expression_list_more::=
	  expression
	| output_expression_list_more TOKCOMA opt_expression

opt_named_arguments::=
	  /*%empty*/
	| named_arguments

named_arguments::=
	  named_argument
	| named_arguments TOKCOMA named_argument

named_argument::=
	  TOKID TOKEQUAL function_argument

opt_assing::=
	  TOKASSING expression
	| function_call_args

function_argument::=
	  TOKFUNCTION name TOKOPAREN opt_named_arguments TOKCPAREN
	| expression

function_call_args::=
	  TOKOPAREN opt_function_args TOKCPAREN

opt_function_args::=
	  /*%empty*/
	| function_arguments

function_arguments::=
	  function_argument opt_function_arguments
	| named_argument opt_function_arguments

opt_function_arguments::=
	  /*%empty*/
	| TOKCOMA function_arguments
	| TOKFOR for_indices

expression::=
	  primary
	| TOKOPAREN output_expression_list TOKCPAREN
	| TOKMINUS expression
	| TOKPLUS expression
	| TOKNOT expression
	| expression TOKCOLON expression
	| expression TOKLOWER expression
	| expression TOKLOWEREQ expression
	| expression TOKGREATER expression
	| expression TOKGREATEREQ expression
	| expression TOKCOMPNE expression
	| expression TOKCOMPEQ expression
	| expression TOKSLASH expression
	| expression TOKDOTSLASH expression
	| expression TOKSTAR expression
	| expression TOKDOTSTAR expression
	| expression TOKPLUS expression
	| expression TOKMINUS expression
	| expression TOKDOTPLUS expression
	| expression TOKDOTMINUS expression
	| expression TOKCARET expression
	| expression TOKDOTCARET expression
	| expression TOKAND expression
	| expression TOKOR expression
	| TOKIF expression TOKTHEN expression opt_elseif_exp TOKELSE expression

opt_expression::=
	  /*%empty*/
	| expression

opt_elseif_exp::=
	  /*%empty*/
	| opt_elseif_exp TOKELSEIF expression TOKTHEN expression

primary::=
	  TOKINT
	| TOKFLOAT
	| TOKSTRING
	| TOKFALSE
	| TOKTRUE
	| TOKDER function_call_args
	| TOKINITIAL function_call_args
	| opt_comp_call
	| TOKOBRACKET expression_list primary_exp_list TOKCBRACKET
	| TOKOBRACE function_arguments TOKCBRACE
	| TOKENDSUB

primary_exp_list::=
	  /*%empty*/
	| primary_exp_list TOKSEMICOLON expression_list

component_reference::=
	  TOKID opt_array_subscripts component_reference_list
	| TOKDOT TOKID opt_array_subscripts component_reference_list

expression_list::=
	  expression
	| expression_list TOKCOMA expression

component_reference_list::=
	  /*%empty*/
	| component_reference_list TOKDOT TOKID opt_array_subscripts

simple_expression::=
	  primary
	| TOKOPAREN output_expression_list TOKCPAREN
	| TOKMINUS expression
	| TOKPLUS expression
	| TOKNOT expression
	| simple_expression TOKCOLON expression
	| simple_expression TOKLOWER expression
	| simple_expression TOKLOWEREQ expression
	| simple_expression TOKGREATER expression
	| simple_expression TOKGREATEREQ expression
	| simple_expression TOKCOMPNE expression
	| simple_expression TOKCOMPEQ expression
	| simple_expression TOKSLASH expression
	| simple_expression TOKDOTSLASH expression
	| simple_expression TOKSTAR expression
	| simple_expression TOKDOTSTAR expression
	| simple_expression TOKPLUS expression
	| simple_expression TOKMINUS expression
	| simple_expression TOKDOTPLUS expression
	| simple_expression TOKDOTMINUS expression
	| simple_expression TOKCARET expression
	| simple_expression TOKDOTCARET expression
	| simple_expression TOKAND expression
	| simple_expression TOKOR expression

more_cr::=
	  /*%empty*/
	| more_cr TOKDOT TOKID opt_array_subscripts

more_comp_call::=
	  /*%empty*/
	| more_comp_call TOKDOT TOKID

opt_comp_call::=
	  TOKDOT TOKID more_comp_call
	| TOKID more_comp_call
	| TOKDOT TOKID more_comp_call array_subscripts more_cr
	| TOKID more_comp_call array_subscripts more_cr
	| TOKDOT TOKID more_comp_call function_call_args
	| TOKID more_comp_call function_call_args

//Tokens

TOKCOMPEQ ::= "=="
TOKEQUAL ::= "="
TOKSEMICOLON ::= ";"
TOKCOMA ::= ","
TOKDOTCARET ::= ".^"
TOKCARET ::= "^"
TOKOPAREN ::= "("
TOKCPAREN ::= ")"
TOKOBRACE ::= "{"
TOKCBRACE ::= "}"
TOKOBRACKET ::= "["
TOKCBRACKET ::= "]"
TOKDOTPLUS ::= ".+"
TOKDOTMINUS ::= ".-"
TOKDOTSTAR ::= ".*"
TOKDOTSLASH ::= "./"
TOKDOT ::= "."
TOKPLUS ::= "+"
TOKMINUS ::= "-"
TOKSTAR ::= "*"
TOKSLASH ::= "/"
TOKCOMPNE ::= "<>"
TOKLOWEREQ ::= "<="
TOKLOWER ::= "<"
TOKGREATEREQ ::= ">="
TOKGREATER ::= ">"
TOKASSING ::= ":="
TOKCOLON ::= ":"


TOKINITIALEQ ::= "initial"[\t\ \n]*"equation"	
TOKINITIALALG ::= "initial"[\t\ \n]*"algorithm" 
TOKINITIAL ::= "initial"

TOKALGORITHM ::= "algorithm"
TOKAND ::= "and"
TOKANNOTATION ::= "annotation"

TOKBLOCK ::= "block"
TOKBREAK ::= "break"
TOKCLASS ::= "class"
TOKCONNECT ::= "connect"
TOKCONNECTOR ::= "connector"
TOKCONSTANT ::= "constant"
TOKCONSTRAINEDBY ::= "constrainedby"
TOKDER ::= "der"
TOKDISCRETE ::= "discrete"
TOKEACH ::= "each"
TOKELSE ::= "else"
TOKELSEIF ::= "elseif"
TOKELSEWHEN ::= "elsewhen"
TOKENCAPSULATED ::= "encapsulated"
TOKEND ::= "end" //      { if (parser->isParsingSubscript()) { ENDSUB) } else { END} }
ENDSUB	TOKENDSUB
TOKENUMERATION ::= "enumeration"
TOKEQUATION ::= "equation"
TOKEXPANDABLE ::= "expandable"
TOKEXTENDS ::= "extends"
TOKEXTERNAL ::= "external"
TOKFALSE ::= "false"
TOKFINAL ::= "final"
TOKFLOW ::= "flow"
TOKFOR ::= "for"
TOKFUNCTION ::= "function"
TOKIF ::= "if"
TOKIMPORT ::= "import"
TOKIMPURE ::= "impure"
TOKIN ::= "in"
TOKINNER ::= "inner"
TOKINPUT ::= "input"
TOKLOOP ::= "loop"
TOKMODEL ::= "model"
TOKNOT ::= "not"
TOKOPERATOR ::= "operator"
TOKOR ::= "or"
TOKOUTER ::= "outer"
TOKOUTPUT ::= "output"
TOKPACKAGE ::= "package"
TOKPARAMETER ::= "parameter"
TOKPARTIAL ::= "partial"
TOKPROTECTED ::= "protected"
TOKPUBLIC ::= "public"
TOKPURE ::= "pure"
TOKRECORD ::= "record"
TOKREDECLARE ::= "redeclare"
TOKREPLACEABLE ::= "replaceable"
TOKRETURN ::= "return"
TOKSTREAM ::= "stream"
TOKTHEN ::= "then"
TOKTRUE ::= "true"
TOKTYPE ::= "type"
TOKWHEN ::= "when"
TOKWHILE ::= "while"
TOKWITHIN ::= "within"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions