From 7b29df28d3fd18cf6118862ef0cc2a88c1e3c803 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Fri, 16 Sep 2016 20:32:37 -0700 Subject: move files around --- bnfc/modelica33r1_spec.txt | 347 ----------------------------- examples/classic_gravitation/metadata.toml | 59 +++++ examples/lotka_volterra/metadata.toml | 63 ++++++ notes/classic_gravitation.toml | 59 ----- notes/lotka_volterra.toml | 63 ------ notes/modelica33r1_spec.txt | 347 +++++++++++++++++++++++++++++ 6 files changed, 469 insertions(+), 469 deletions(-) delete mode 100644 bnfc/modelica33r1_spec.txt create mode 100644 examples/classic_gravitation/metadata.toml create mode 100644 examples/lotka_volterra/metadata.toml delete mode 100644 notes/classic_gravitation.toml delete mode 100644 notes/lotka_volterra.toml create mode 100644 notes/modelica33r1_spec.txt diff --git a/bnfc/modelica33r1_spec.txt b/bnfc/modelica33r1_spec.txt deleted file mode 100644 index 2df42dd..0000000 --- a/bnfc/modelica33r1_spec.txt +++ /dev/null @@ -1,347 +0,0 @@ -# These come directly the Modelica 3.3 Spec, Appendix B - -## B.1 Lexical Convetions - -IDENT = NONDIGIT { DIGIT | NONDIGIT } | Q-IDENT -Q-IDENT = "’" ( Q-CHAR | S-ESCAPE ) { Q-CHAR | S-ESCAPE } "’" -NONDIGIT = "_" | letters "a" to "z" | letters "A" to "Z" -STRING = """ { S-CHAR | S-ESCAPE } """ -S-CHAR = any member of the Unicode character set (http://www.unicode.org; see Section 13.2.2 for storing as UTF-8 on files) except double-quote """, and backslash "\" -Q-CHAR = NONDIGIT | DIGIT | "!" | "#" | "$" | "%" | "&" | "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | "<" | ">" | "=" | "?" | "@" | "[" | "]" | "^" | "{" | "}" | "|" | "~" | " " -S-ESCAPE = "\’" | "\"" | "\?" | "\\" | "\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v" -DIGIT = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" -UNSIGNED_INTEGER = DIGIT { DIGIT } -UNSIGNED_NUMBER = UNSIGNED_INTEGER [ "." [ UNSIGNED_INTEGER ] ] [ ( "e" | "E" ) [ "+" | "-" ] UNSIGNED_INTEGER ] - -## B.2 Grammar - -### B.2.1 - -stored_definition: - [ within [ name ] ";" ] - { [ final ] class_definition ";" } - -### B.2.2 Class Definition - -class_definition : - [ encapsulated ] class_prefixes - class_specifier - -class_prefixes : - [ partial ] - ( class | model | [ operator ] record | block | [ expandable ] connector | type | - package | [ ( pure | impure ) ] [ operator ] function | operator ) - -class_specifier : - long_class_specifier | short_class_specifier | der_class_specifier - -long_class_specifier : - IDENT string_comment composition end IDENT - | extends IDENT [ class_modification ] string_comment composition - end IDENT - -short_class_specifier : - IDENT "=" base_prefix name [ array_subscripts ] - [ class_modification ] comment - | IDENT "=" enumeration "(" ( [enum_list] | ":" ) ")" comment - -der_class_specifier : - IDENT "=" der "(" name "," IDENT { "," IDENT } ")" comment - -base_prefix : - type_prefix - -enum_list : - enumeration_literal { "," enumeration_literal} - -enumeration_literal : - IDENT comment - -composition : - element_list - { public element_list | - protected element_list | - equation_section | - algorithm_section - } - [ external [ language_specification ] - [ external_function_call ] [ annotation ] ";" ] - [ annotation ";" ] - -language_specification : - STRING - -external_function_call : - [ component_reference "=" ] - IDENT "(" [ expression_list ] ")" - -element_list : - { element ";" } - -element : - import_clause | - extends_clause | - [ redeclare ] - [ final ] - [ inner ] [ outer ] - ( ( class_definition | component_clause) | - replaceable ( class_definition | component_clause) - [constraining_clause comment]) - -import_clause : - import ( IDENT "=" name | name ["." ( "*" | "{" import_list "}" ) ] ) comment - -import_list : - IDENT { "," IDENT } - -### B.2.3 Extends - -extends_clause : - extends name [ class_modification ] [annotation] - -constraining_clause : - constrainedby name [ class_modification ] - -### B.2.4 Component Clause - -component_clause: - type_prefix type_specifier [ array_subscripts ] component_list - type_prefix : - [ flow | stream ] - [ discrete | parameter | constant ] [ input | output ] - -type_specifier : - name - -component_list : - component_declaration { "," component_declaration } - -component_declaration : - declaration [ condition_attribute ] comment - -condition_attribute: - if expression - -declaration : - IDENT [ array_subscripts ] [ modification ] - -### B.2.5 Modification - -modification : - class_modification [ "=" expression ] - | "=" expression - | ":=" expression - -class_modification : - "(" [ argument_list ] ")" - -argument_list : - argument { "," argument } - -argument : - element_modification_or_replaceable - | element_redeclaration - element_modification_or_replaceable: - [ each ] [ final ] ( element_modification | element_replaceable) - -element_modification : - name [ modification ] string_comment - -element_redeclaration : - redeclare [ each ] [ final ] - ( ( short_class_definition | component_clause1) | element_replaceable ) - -element_replaceable: - replaceable ( short_class_definition | component_clause1) - [constraining_clause] - -component_clause1 : - type_prefix type_specifier component_declaration1 - -component_declaration1 : - declaration comment - -short_class_definition : - class_prefixes short_class_specifier - -### B.2.6 Equations - -equation_section : - [ initial ] equation { equation ";" } - -algorithm_section : - [ initial ] algorithm { statement ";" } - -equation : - ( simple_expression "=" expression - | if_equation - | for_equation - | connect_clause - | when_equation - | name function_call_args ) - comment - -statement : - ( component_reference ( ":=" expression | function_call_args ) - | "(" output_expression_list ")" ":=" component_reference function_call_args - | break - | return - | if_statement - | for_statement - | while_statement - | when_statement ) - comment - -if_equation : - if expression then - { equation ";" } - { elseif expression then - { equation ";" } - } - [ else - { equation ";" } - ] - end if - -if_statement : - if expression then - { statement ";" } - { elseif expression then - { statement ";" } - } - [ else - { statement ";" } - ] - end if - -for_equation : - for for_indices loop - { equation ";" } - end for - -for_statement : - for for_indices loop - { statement ";" } - end for - -for_indices : - for_index {"," for_index} - -for_index: - IDENT [ in expression ] - while_statement : - while expression loop - { statement ";" } - end while - -when_equation : - when expression then - { equation ";" } - { elsewhen expression then - { equation ";" } } - end when - -when_statement : - when expression then - { statement ";" } - { elsewhen expression then - { statement ";" } } - end when - -connect_clause : - connect "(" component_reference "," component_reference ")" - -### B.2.7 Expressions - -expression : - simple_expression - | if expression then expression { elseif expression then expression } - else expression - -simple_expression : - logical_expression [ ":" logical_expression [ ":" logical_expression ] ] - -logical_expression : - logical_term { or logical_term } - -logical_term : - logical_factor { and logical_factor } - -logical_factor : - [ not ] relation - -relation : - arithmetic_expression [ rel_op arithmetic_expression ] - -rel_op : - "<" | "<=" | ">" | ">=" | "==" | "<>" - -arithmetic_expression : - [ add_op ] term { add_op term } - -add_op : - "+" | "-" | ".+" | ".-" - -term : - factor { mul_op factor } - -mul_op : - "*" | "/" | ".*" | "./" - -factor : - primary [ ("^" | ".^") primary ] - -primary : - UNSIGNED_NUMBER - | STRING - | false - | true - | ( name | der | initial ) function_call_args - | component_reference - | "(" output_expression_list ")" - | "[" expression_list { ";" expression_list } "]" - | "{" function_arguments "}" - | end - -name : - [ "." ] IDENT { "." IDENT } - -component_reference : - [ "." ] IDENT [ array_subscripts ] { "." IDENT [ array_subscripts ] } - -function_call_args : - "(" [ function_arguments ] ")" - function_arguments : - function_argument [ "," function_arguments | for for_indices ] - | named_arguments - -named_arguments: - named_argument [ "," named_arguments ] - -named_argument: - IDENT "=" function_argument - -function_argument : - function name "(" [ named_arguments ] ")" | expression - -output_expression_list: - [ expression ] { "," [ expression ] } - -expression_list : - expression { "," expression } - -array_subscripts : - "[" subscript { "," subscript } "]" - -subscript : - ":" | expression - -comment : - string_comment [ annotation ] - -string_comment : - [ STRING { "+" STRING } ] - -annotation : - annotation class_modification - diff --git a/examples/classic_gravitation/metadata.toml b/examples/classic_gravitation/metadata.toml new file mode 100644 index 0000000..953dad8 --- /dev/null +++ b/examples/classic_gravitation/metadata.toml @@ -0,0 +1,59 @@ + +[model] +name-en = "Classic Gravitation" +descrption-en = "Newtonian" +sexprs = [''' + (= + F + (/ (* G m1 m2) + (square r 2))) + '''] + +[variables] + + [variables.G] + type = "constant" + name-en = "Gravitational Constant" + value_si = 6.674e-11 + + [variables.F] + type = 'dependent' + name-en = "force" + units_si = "unit" + + [variables.r] + type = 'independent' + name-en = "distance" + units_si = "meter" + + [variables.m1] + type = 'independent' + latex = 'm_1' + name = "mass #1" + units_si = "kilogram" + + [variables.m2] + type = 'independent' + latex = 'm_2' + name = "mass #2" + units_si = "kilogram" + +[examples] + + [examples.earth_surface] + r = 6.371e6 # radius of earth + m1 = 5.972e24 # mass of earth + m2 = 70 # mass of human + + [examples.earth_moon] + r = 385000 # radius of earth + m1 = 5.972e24 # mass of earth + m2 = 7.348e22 # mass of moon + + +[references] + + [references.url] + "Mathworld" = "http://mathworld.wolfram.com/Lotka-VolterraEquations.html" + "Wikipedia" = "https://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equations" + diff --git a/examples/lotka_volterra/metadata.toml b/examples/lotka_volterra/metadata.toml new file mode 100644 index 0000000..7d2cf0d --- /dev/null +++ b/examples/lotka_volterra/metadata.toml @@ -0,0 +1,63 @@ + +[model] +name-en = "Lotka–Volterra equations" +descrption-en = "Predator-Prey Model" +sexprs = [''' + (= + (partial-derivative x t) + (- (* alpha x) + (* beta x y))) + ''',''' + (= + (partial-derivative y t) + (- (* delta x y) + (* gamma y))) + '''] + +[variables] + + [variables.t] + type = 'time' # or "independent"? + + [variables.x] + type = 'state' + + [variables.y] + type = 'state' + + [variables.alpha] + type = 'parameter' + latex = '\alpha' + unicode = 'α' + + [variables.beta] + type = 'parameter' + latex = '\beta' + unicode = 'β' + + [variables.delta] + type = 'parameter' + latex = '\delta' + unicode = 'δ' + + [variables.gamma] + type = 'parameter' + latex = '\gamma' + unicode = 'γ' + +[examples] + + [examples.mathworld] + x = 10 + y = 5 + alpha = 1.5 + beta = 1 + gamma = 1 + t = [0, 20] + +[references] + + [references.url] + "Mathworld" = "http://mathworld.wolfram.com/Lotka-VolterraEquations.html" + "Wikipedia" = "https://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equations" + diff --git a/notes/classic_gravitation.toml b/notes/classic_gravitation.toml deleted file mode 100644 index 953dad8..0000000 --- a/notes/classic_gravitation.toml +++ /dev/null @@ -1,59 +0,0 @@ - -[model] -name-en = "Classic Gravitation" -descrption-en = "Newtonian" -sexprs = [''' - (= - F - (/ (* G m1 m2) - (square r 2))) - '''] - -[variables] - - [variables.G] - type = "constant" - name-en = "Gravitational Constant" - value_si = 6.674e-11 - - [variables.F] - type = 'dependent' - name-en = "force" - units_si = "unit" - - [variables.r] - type = 'independent' - name-en = "distance" - units_si = "meter" - - [variables.m1] - type = 'independent' - latex = 'm_1' - name = "mass #1" - units_si = "kilogram" - - [variables.m2] - type = 'independent' - latex = 'm_2' - name = "mass #2" - units_si = "kilogram" - -[examples] - - [examples.earth_surface] - r = 6.371e6 # radius of earth - m1 = 5.972e24 # mass of earth - m2 = 70 # mass of human - - [examples.earth_moon] - r = 385000 # radius of earth - m1 = 5.972e24 # mass of earth - m2 = 7.348e22 # mass of moon - - -[references] - - [references.url] - "Mathworld" = "http://mathworld.wolfram.com/Lotka-VolterraEquations.html" - "Wikipedia" = "https://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equations" - diff --git a/notes/lotka_volterra.toml b/notes/lotka_volterra.toml deleted file mode 100644 index 7d2cf0d..0000000 --- a/notes/lotka_volterra.toml +++ /dev/null @@ -1,63 +0,0 @@ - -[model] -name-en = "Lotka–Volterra equations" -descrption-en = "Predator-Prey Model" -sexprs = [''' - (= - (partial-derivative x t) - (- (* alpha x) - (* beta x y))) - ''',''' - (= - (partial-derivative y t) - (- (* delta x y) - (* gamma y))) - '''] - -[variables] - - [variables.t] - type = 'time' # or "independent"? - - [variables.x] - type = 'state' - - [variables.y] - type = 'state' - - [variables.alpha] - type = 'parameter' - latex = '\alpha' - unicode = 'α' - - [variables.beta] - type = 'parameter' - latex = '\beta' - unicode = 'β' - - [variables.delta] - type = 'parameter' - latex = '\delta' - unicode = 'δ' - - [variables.gamma] - type = 'parameter' - latex = '\gamma' - unicode = 'γ' - -[examples] - - [examples.mathworld] - x = 10 - y = 5 - alpha = 1.5 - beta = 1 - gamma = 1 - t = [0, 20] - -[references] - - [references.url] - "Mathworld" = "http://mathworld.wolfram.com/Lotka-VolterraEquations.html" - "Wikipedia" = "https://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equations" - diff --git a/notes/modelica33r1_spec.txt b/notes/modelica33r1_spec.txt new file mode 100644 index 0000000..2df42dd --- /dev/null +++ b/notes/modelica33r1_spec.txt @@ -0,0 +1,347 @@ +# These come directly the Modelica 3.3 Spec, Appendix B + +## B.1 Lexical Convetions + +IDENT = NONDIGIT { DIGIT | NONDIGIT } | Q-IDENT +Q-IDENT = "’" ( Q-CHAR | S-ESCAPE ) { Q-CHAR | S-ESCAPE } "’" +NONDIGIT = "_" | letters "a" to "z" | letters "A" to "Z" +STRING = """ { S-CHAR | S-ESCAPE } """ +S-CHAR = any member of the Unicode character set (http://www.unicode.org; see Section 13.2.2 for storing as UTF-8 on files) except double-quote """, and backslash "\" +Q-CHAR = NONDIGIT | DIGIT | "!" | "#" | "$" | "%" | "&" | "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | "<" | ">" | "=" | "?" | "@" | "[" | "]" | "^" | "{" | "}" | "|" | "~" | " " +S-ESCAPE = "\’" | "\"" | "\?" | "\\" | "\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v" +DIGIT = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" +UNSIGNED_INTEGER = DIGIT { DIGIT } +UNSIGNED_NUMBER = UNSIGNED_INTEGER [ "." [ UNSIGNED_INTEGER ] ] [ ( "e" | "E" ) [ "+" | "-" ] UNSIGNED_INTEGER ] + +## B.2 Grammar + +### B.2.1 + +stored_definition: + [ within [ name ] ";" ] + { [ final ] class_definition ";" } + +### B.2.2 Class Definition + +class_definition : + [ encapsulated ] class_prefixes + class_specifier + +class_prefixes : + [ partial ] + ( class | model | [ operator ] record | block | [ expandable ] connector | type | + package | [ ( pure | impure ) ] [ operator ] function | operator ) + +class_specifier : + long_class_specifier | short_class_specifier | der_class_specifier + +long_class_specifier : + IDENT string_comment composition end IDENT + | extends IDENT [ class_modification ] string_comment composition + end IDENT + +short_class_specifier : + IDENT "=" base_prefix name [ array_subscripts ] + [ class_modification ] comment + | IDENT "=" enumeration "(" ( [enum_list] | ":" ) ")" comment + +der_class_specifier : + IDENT "=" der "(" name "," IDENT { "," IDENT } ")" comment + +base_prefix : + type_prefix + +enum_list : + enumeration_literal { "," enumeration_literal} + +enumeration_literal : + IDENT comment + +composition : + element_list + { public element_list | + protected element_list | + equation_section | + algorithm_section + } + [ external [ language_specification ] + [ external_function_call ] [ annotation ] ";" ] + [ annotation ";" ] + +language_specification : + STRING + +external_function_call : + [ component_reference "=" ] + IDENT "(" [ expression_list ] ")" + +element_list : + { element ";" } + +element : + import_clause | + extends_clause | + [ redeclare ] + [ final ] + [ inner ] [ outer ] + ( ( class_definition | component_clause) | + replaceable ( class_definition | component_clause) + [constraining_clause comment]) + +import_clause : + import ( IDENT "=" name | name ["." ( "*" | "{" import_list "}" ) ] ) comment + +import_list : + IDENT { "," IDENT } + +### B.2.3 Extends + +extends_clause : + extends name [ class_modification ] [annotation] + +constraining_clause : + constrainedby name [ class_modification ] + +### B.2.4 Component Clause + +component_clause: + type_prefix type_specifier [ array_subscripts ] component_list + type_prefix : + [ flow | stream ] + [ discrete | parameter | constant ] [ input | output ] + +type_specifier : + name + +component_list : + component_declaration { "," component_declaration } + +component_declaration : + declaration [ condition_attribute ] comment + +condition_attribute: + if expression + +declaration : + IDENT [ array_subscripts ] [ modification ] + +### B.2.5 Modification + +modification : + class_modification [ "=" expression ] + | "=" expression + | ":=" expression + +class_modification : + "(" [ argument_list ] ")" + +argument_list : + argument { "," argument } + +argument : + element_modification_or_replaceable + | element_redeclaration + element_modification_or_replaceable: + [ each ] [ final ] ( element_modification | element_replaceable) + +element_modification : + name [ modification ] string_comment + +element_redeclaration : + redeclare [ each ] [ final ] + ( ( short_class_definition | component_clause1) | element_replaceable ) + +element_replaceable: + replaceable ( short_class_definition | component_clause1) + [constraining_clause] + +component_clause1 : + type_prefix type_specifier component_declaration1 + +component_declaration1 : + declaration comment + +short_class_definition : + class_prefixes short_class_specifier + +### B.2.6 Equations + +equation_section : + [ initial ] equation { equation ";" } + +algorithm_section : + [ initial ] algorithm { statement ";" } + +equation : + ( simple_expression "=" expression + | if_equation + | for_equation + | connect_clause + | when_equation + | name function_call_args ) + comment + +statement : + ( component_reference ( ":=" expression | function_call_args ) + | "(" output_expression_list ")" ":=" component_reference function_call_args + | break + | return + | if_statement + | for_statement + | while_statement + | when_statement ) + comment + +if_equation : + if expression then + { equation ";" } + { elseif expression then + { equation ";" } + } + [ else + { equation ";" } + ] + end if + +if_statement : + if expression then + { statement ";" } + { elseif expression then + { statement ";" } + } + [ else + { statement ";" } + ] + end if + +for_equation : + for for_indices loop + { equation ";" } + end for + +for_statement : + for for_indices loop + { statement ";" } + end for + +for_indices : + for_index {"," for_index} + +for_index: + IDENT [ in expression ] + while_statement : + while expression loop + { statement ";" } + end while + +when_equation : + when expression then + { equation ";" } + { elsewhen expression then + { equation ";" } } + end when + +when_statement : + when expression then + { statement ";" } + { elsewhen expression then + { statement ";" } } + end when + +connect_clause : + connect "(" component_reference "," component_reference ")" + +### B.2.7 Expressions + +expression : + simple_expression + | if expression then expression { elseif expression then expression } + else expression + +simple_expression : + logical_expression [ ":" logical_expression [ ":" logical_expression ] ] + +logical_expression : + logical_term { or logical_term } + +logical_term : + logical_factor { and logical_factor } + +logical_factor : + [ not ] relation + +relation : + arithmetic_expression [ rel_op arithmetic_expression ] + +rel_op : + "<" | "<=" | ">" | ">=" | "==" | "<>" + +arithmetic_expression : + [ add_op ] term { add_op term } + +add_op : + "+" | "-" | ".+" | ".-" + +term : + factor { mul_op factor } + +mul_op : + "*" | "/" | ".*" | "./" + +factor : + primary [ ("^" | ".^") primary ] + +primary : + UNSIGNED_NUMBER + | STRING + | false + | true + | ( name | der | initial ) function_call_args + | component_reference + | "(" output_expression_list ")" + | "[" expression_list { ";" expression_list } "]" + | "{" function_arguments "}" + | end + +name : + [ "." ] IDENT { "." IDENT } + +component_reference : + [ "." ] IDENT [ array_subscripts ] { "." IDENT [ array_subscripts ] } + +function_call_args : + "(" [ function_arguments ] ")" + function_arguments : + function_argument [ "," function_arguments | for for_indices ] + | named_arguments + +named_arguments: + named_argument [ "," named_arguments ] + +named_argument: + IDENT "=" function_argument + +function_argument : + function name "(" [ named_arguments ] ")" | expression + +output_expression_list: + [ expression ] { "," [ expression ] } + +expression_list : + expression { "," expression } + +array_subscripts : + "[" subscript { "," subscript } "]" + +subscript : + ":" | expression + +comment : + string_comment [ annotation ] + +string_comment : + [ STRING { "+" STRING } ] + +annotation : + annotation class_modification + -- cgit v1.2.3