Extract Types/Classnames from flat Modelica code











up vote
2
down vote

favorite












I was wondering if there already exists a possibility to extract from flat Modelica code all variables AND their corresponding types (classnames respectively).



For example:

Given an extract from a flattened Modelica model:



constant Integer nSurfaces = 8;
constant Integer construction1.nLayers(min = 1.0) = 2 "Number of layers of the construction";
parameter Modelica.SIunits.Length construction1.thickness[construction1.nLayers]= {0.2, 0.1} "Thickness of each construction layer";


Here, the wanted output would be something like:



nSurfaces, Integer, constant;
construction1.nLayers, Integer, constant;
construction1.thickness[construction1.nLayers], Modelica.SIunits.Length, parameter


Ideally, for construction1.thickness there would be two lines (=number of construction1.nLayers).



I know, that it is possible to get a list of used variables from the dsin.txt, which is produced while translating a model. But until now I did not find an already existing way to get the corresponding types. And I really would like to avoid writing an own parser :-).










share|improve this question






















  • related: stackoverflow.com/questions/26023434/…
    – matth
    Mar 8 at 8:11















up vote
2
down vote

favorite












I was wondering if there already exists a possibility to extract from flat Modelica code all variables AND their corresponding types (classnames respectively).



For example:

Given an extract from a flattened Modelica model:



constant Integer nSurfaces = 8;
constant Integer construction1.nLayers(min = 1.0) = 2 "Number of layers of the construction";
parameter Modelica.SIunits.Length construction1.thickness[construction1.nLayers]= {0.2, 0.1} "Thickness of each construction layer";


Here, the wanted output would be something like:



nSurfaces, Integer, constant;
construction1.nLayers, Integer, constant;
construction1.thickness[construction1.nLayers], Modelica.SIunits.Length, parameter


Ideally, for construction1.thickness there would be two lines (=number of construction1.nLayers).



I know, that it is possible to get a list of used variables from the dsin.txt, which is produced while translating a model. But until now I did not find an already existing way to get the corresponding types. And I really would like to avoid writing an own parser :-).










share|improve this question






















  • related: stackoverflow.com/questions/26023434/…
    – matth
    Mar 8 at 8:11













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I was wondering if there already exists a possibility to extract from flat Modelica code all variables AND their corresponding types (classnames respectively).



For example:

Given an extract from a flattened Modelica model:



constant Integer nSurfaces = 8;
constant Integer construction1.nLayers(min = 1.0) = 2 "Number of layers of the construction";
parameter Modelica.SIunits.Length construction1.thickness[construction1.nLayers]= {0.2, 0.1} "Thickness of each construction layer";


Here, the wanted output would be something like:



nSurfaces, Integer, constant;
construction1.nLayers, Integer, constant;
construction1.thickness[construction1.nLayers], Modelica.SIunits.Length, parameter


Ideally, for construction1.thickness there would be two lines (=number of construction1.nLayers).



I know, that it is possible to get a list of used variables from the dsin.txt, which is produced while translating a model. But until now I did not find an already existing way to get the corresponding types. And I really would like to avoid writing an own parser :-).










share|improve this question













I was wondering if there already exists a possibility to extract from flat Modelica code all variables AND their corresponding types (classnames respectively).



For example:

Given an extract from a flattened Modelica model:



constant Integer nSurfaces = 8;
constant Integer construction1.nLayers(min = 1.0) = 2 "Number of layers of the construction";
parameter Modelica.SIunits.Length construction1.thickness[construction1.nLayers]= {0.2, 0.1} "Thickness of each construction layer";


Here, the wanted output would be something like:



nSurfaces, Integer, constant;
construction1.nLayers, Integer, constant;
construction1.thickness[construction1.nLayers], Modelica.SIunits.Length, parameter


Ideally, for construction1.thickness there would be two lines (=number of construction1.nLayers).



I know, that it is possible to get a list of used variables from the dsin.txt, which is produced while translating a model. But until now I did not find an already existing way to get the corresponding types. And I really would like to avoid writing an own parser :-).







modelica dymola






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 2 at 9:00









jmoeckel

385




385












  • related: stackoverflow.com/questions/26023434/…
    – matth
    Mar 8 at 8:11


















  • related: stackoverflow.com/questions/26023434/…
    – matth
    Mar 8 at 8:11
















related: stackoverflow.com/questions/26023434/…
– matth
Mar 8 at 8:11




related: stackoverflow.com/questions/26023434/…
– matth
Mar 8 at 8:11












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










You could try to generate the file modelDescription.xml as defined by the FMI standard. It contains a ton of information and XML should be easier to parse, e.g. python has a couple of xml parsing/reading packages.
If you are using Dymola you just set the flag Advanced.FMI.GenerateModelDescriptionInterface2 = true to generate the model description file.



The second idea could be to let the compiler/tool parse the Modelica file for you as they need to do that anyway, try searching for AST (abstract syntax tree). In Dymola, this is available through the ModelManagement library, and also through the Python interface.



Third idea could be to use one of the Modelica parsers available, e.g. have a look at:




  • https://github.com/lbl-srg/modelica-json

  • https://hackage.haskell.org/package/modelicaparser

  • https://github.com/xie-dongping/modparc

  • https://github.com/pymoca/pymoca

  • https://github.com/pymola/pymola/tree/master/src/pymola


Fourth, if all that did not work, you still do not have to write a full parser, you could use ANTLR, then use an existing grammar file (look for e.g. modelica.g4).






share|improve this answer























  • Thanks for all the hints. I should have googled for "Modelica" and "parser" - I was too fixed on the term "classes". The mentioned Dymola flag worked quite well for me.
    – jmoeckel
    Mar 8 at 19:22













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49065763%2fextract-types-classnames-from-flat-modelica-code%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










You could try to generate the file modelDescription.xml as defined by the FMI standard. It contains a ton of information and XML should be easier to parse, e.g. python has a couple of xml parsing/reading packages.
If you are using Dymola you just set the flag Advanced.FMI.GenerateModelDescriptionInterface2 = true to generate the model description file.



The second idea could be to let the compiler/tool parse the Modelica file for you as they need to do that anyway, try searching for AST (abstract syntax tree). In Dymola, this is available through the ModelManagement library, and also through the Python interface.



Third idea could be to use one of the Modelica parsers available, e.g. have a look at:




  • https://github.com/lbl-srg/modelica-json

  • https://hackage.haskell.org/package/modelicaparser

  • https://github.com/xie-dongping/modparc

  • https://github.com/pymoca/pymoca

  • https://github.com/pymola/pymola/tree/master/src/pymola


Fourth, if all that did not work, you still do not have to write a full parser, you could use ANTLR, then use an existing grammar file (look for e.g. modelica.g4).






share|improve this answer























  • Thanks for all the hints. I should have googled for "Modelica" and "parser" - I was too fixed on the term "classes". The mentioned Dymola flag worked quite well for me.
    – jmoeckel
    Mar 8 at 19:22

















up vote
2
down vote



accepted










You could try to generate the file modelDescription.xml as defined by the FMI standard. It contains a ton of information and XML should be easier to parse, e.g. python has a couple of xml parsing/reading packages.
If you are using Dymola you just set the flag Advanced.FMI.GenerateModelDescriptionInterface2 = true to generate the model description file.



The second idea could be to let the compiler/tool parse the Modelica file for you as they need to do that anyway, try searching for AST (abstract syntax tree). In Dymola, this is available through the ModelManagement library, and also through the Python interface.



Third idea could be to use one of the Modelica parsers available, e.g. have a look at:




  • https://github.com/lbl-srg/modelica-json

  • https://hackage.haskell.org/package/modelicaparser

  • https://github.com/xie-dongping/modparc

  • https://github.com/pymoca/pymoca

  • https://github.com/pymola/pymola/tree/master/src/pymola


Fourth, if all that did not work, you still do not have to write a full parser, you could use ANTLR, then use an existing grammar file (look for e.g. modelica.g4).






share|improve this answer























  • Thanks for all the hints. I should have googled for "Modelica" and "parser" - I was too fixed on the term "classes". The mentioned Dymola flag worked quite well for me.
    – jmoeckel
    Mar 8 at 19:22















up vote
2
down vote



accepted







up vote
2
down vote



accepted






You could try to generate the file modelDescription.xml as defined by the FMI standard. It contains a ton of information and XML should be easier to parse, e.g. python has a couple of xml parsing/reading packages.
If you are using Dymola you just set the flag Advanced.FMI.GenerateModelDescriptionInterface2 = true to generate the model description file.



The second idea could be to let the compiler/tool parse the Modelica file for you as they need to do that anyway, try searching for AST (abstract syntax tree). In Dymola, this is available through the ModelManagement library, and also through the Python interface.



Third idea could be to use one of the Modelica parsers available, e.g. have a look at:




  • https://github.com/lbl-srg/modelica-json

  • https://hackage.haskell.org/package/modelicaparser

  • https://github.com/xie-dongping/modparc

  • https://github.com/pymoca/pymoca

  • https://github.com/pymola/pymola/tree/master/src/pymola


Fourth, if all that did not work, you still do not have to write a full parser, you could use ANTLR, then use an existing grammar file (look for e.g. modelica.g4).






share|improve this answer














You could try to generate the file modelDescription.xml as defined by the FMI standard. It contains a ton of information and XML should be easier to parse, e.g. python has a couple of xml parsing/reading packages.
If you are using Dymola you just set the flag Advanced.FMI.GenerateModelDescriptionInterface2 = true to generate the model description file.



The second idea could be to let the compiler/tool parse the Modelica file for you as they need to do that anyway, try searching for AST (abstract syntax tree). In Dymola, this is available through the ModelManagement library, and also through the Python interface.



Third idea could be to use one of the Modelica parsers available, e.g. have a look at:




  • https://github.com/lbl-srg/modelica-json

  • https://hackage.haskell.org/package/modelicaparser

  • https://github.com/xie-dongping/modparc

  • https://github.com/pymoca/pymoca

  • https://github.com/pymola/pymola/tree/master/src/pymola


Fourth, if all that did not work, you still do not have to write a full parser, you could use ANTLR, then use an existing grammar file (look for e.g. modelica.g4).







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 11:15

























answered Mar 8 at 8:11









matth

1,20711132




1,20711132












  • Thanks for all the hints. I should have googled for "Modelica" and "parser" - I was too fixed on the term "classes". The mentioned Dymola flag worked quite well for me.
    – jmoeckel
    Mar 8 at 19:22




















  • Thanks for all the hints. I should have googled for "Modelica" and "parser" - I was too fixed on the term "classes". The mentioned Dymola flag worked quite well for me.
    – jmoeckel
    Mar 8 at 19:22


















Thanks for all the hints. I should have googled for "Modelica" and "parser" - I was too fixed on the term "classes". The mentioned Dymola flag worked quite well for me.
– jmoeckel
Mar 8 at 19:22






Thanks for all the hints. I should have googled for "Modelica" and "parser" - I was too fixed on the term "classes". The mentioned Dymola flag worked quite well for me.
– jmoeckel
Mar 8 at 19:22




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49065763%2fextract-types-classnames-from-flat-modelica-code%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Sphinx de Gizeh

Dijon

Langue