From 25ec87c63a5ba79846e147e3d153bf8d884a664e Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sun, 18 Dec 2016 23:02:38 -0800 Subject: parser: more weird examples --- .../examples/modelica_models/polynomial_evaluator.mo | 14 -------------- .../examples/modelica_other/multiple.mo | 17 +++++++++++++++++ .../examples/modelica_other/package.mo | 15 +++++++++++++++ .../examples/modelica_other/polynomial_evaluator.mo | 14 ++++++++++++++ .../examples/modelica_other/polynomial_evaluator2.mo | 14 ++++++++++++++ .../examples/modelica_other/record.mo | 3 +++ 6 files changed, 63 insertions(+), 14 deletions(-) delete mode 100644 modelica-parser-lalrpop/examples/modelica_models/polynomial_evaluator.mo create mode 100644 modelica-parser-lalrpop/examples/modelica_other/multiple.mo create mode 100644 modelica-parser-lalrpop/examples/modelica_other/package.mo create mode 100644 modelica-parser-lalrpop/examples/modelica_other/polynomial_evaluator.mo create mode 100644 modelica-parser-lalrpop/examples/modelica_other/polynomial_evaluator2.mo create mode 100644 modelica-parser-lalrpop/examples/modelica_other/record.mo (limited to 'modelica-parser-lalrpop/examples') diff --git a/modelica-parser-lalrpop/examples/modelica_models/polynomial_evaluator.mo b/modelica-parser-lalrpop/examples/modelica_models/polynomial_evaluator.mo deleted file mode 100644 index f11d375..0000000 --- a/modelica-parser-lalrpop/examples/modelica_models/polynomial_evaluator.mo +++ /dev/null @@ -1,14 +0,0 @@ -block PolynomialEvaluator - parameter Real a[:]; - input Real x; - output Real y; -protected - constant n = size(a, 1)-1; - Real xpowers[n+1]; -equation - xpowers[1] = 1; - for i in 1:n loop - xpowers[i+1] = xpowers[i]*x; - end for; - y = transpose(a) * xpowers; -end PolynomialEvaluator; diff --git a/modelica-parser-lalrpop/examples/modelica_other/multiple.mo b/modelica-parser-lalrpop/examples/modelica_other/multiple.mo new file mode 100644 index 0000000..45d5cb8 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_other/multiple.mo @@ -0,0 +1,17 @@ +type Voltage = Real(unit="V"); +type Current = Real(unit="A"); + +connector Pin + Voltage v; + flow Current i; +end Pin; + +model Resistor + Pin p, n; + // "Positive" and "negative" pins. + parameter Real R(unit="Ohm") "Resistance"; +equation + R*p.i = p.v - n.v; + p.i + n.i = 0; + // Positive currents into component. +end Resistor; diff --git a/modelica-parser-lalrpop/examples/modelica_other/package.mo b/modelica-parser-lalrpop/examples/modelica_other/package.mo new file mode 100644 index 0000000..ef1eb82 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_other/package.mo @@ -0,0 +1,15 @@ +package Electric + // This package providestypes, connectors and partial models for the electric domain. + extends SIunit; + // Commonly used short names for electric types + type Current = ElectricCurrent; + type Charge = ElectricCharge; + type Voltage = ElectricPotential; + + // Connector types for electric components + connector Pin "Pin of an electric component" + Voltage + v "Potential at the pin"; + flow Current i "Current flowing into the pin"; + end Pin; +end Electric; diff --git a/modelica-parser-lalrpop/examples/modelica_other/polynomial_evaluator.mo b/modelica-parser-lalrpop/examples/modelica_other/polynomial_evaluator.mo new file mode 100644 index 0000000..f11d375 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_other/polynomial_evaluator.mo @@ -0,0 +1,14 @@ +block PolynomialEvaluator + parameter Real a[:]; + input Real x; + output Real y; +protected + constant n = size(a, 1)-1; + Real xpowers[n+1]; +equation + xpowers[1] = 1; + for i in 1:n loop + xpowers[i+1] = xpowers[i]*x; + end for; + y = transpose(a) * xpowers; +end PolynomialEvaluator; diff --git a/modelica-parser-lalrpop/examples/modelica_other/polynomial_evaluator2.mo b/modelica-parser-lalrpop/examples/modelica_other/polynomial_evaluator2.mo new file mode 100644 index 0000000..cf86779 --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_other/polynomial_evaluator2.mo @@ -0,0 +1,14 @@ +function PolynomialEvaluator2 + input Real a[:]; + input Real x; + output Real y; +protected + Real xpower; +algorithm + y := 0; + xpower := 1; + for i in 1:size(a, 1) loop + y := y + a[i]*xpower; + xpower := xpower*x; + end for; +end PolynomialEvaluator2; diff --git a/modelica-parser-lalrpop/examples/modelica_other/record.mo b/modelica-parser-lalrpop/examples/modelica_other/record.mo new file mode 100644 index 0000000..3d37b3d --- /dev/null +++ b/modelica-parser-lalrpop/examples/modelica_other/record.mo @@ -0,0 +1,3 @@ +record FilterData + Real T; +end FilterData; -- cgit v1.2.3