Closed taheruddin closed 3 years ago
In Python2, you can do:
import opengeode
and then:
ast = opengeode.parse ([set of .pr files])
From there you can find the SDL Process like this:
root_ast = ast[0]
proc = root_ast.processes[0]
All the AST is described in ogAST.py
There are many possibilities - in addition to looking into the model. You can render it in a window and interact, by e.g. highlightning symbols. That's what is done by the SDL simulator prototype.
Let me know if you need help.
Thanks for the reply. Also, I need to modify the AST (such as add state, input, transition) and write back to the file. Would you please give some direction on How to do this?
The best is to look at ogAST.py
. You can create new nodes, and add them to the tree..
This is what ogParser.py
is doing when parsing the output of ANTLR
. You can check this one as well.
Then to write back to a .pr, you have to look at the Save function in opengeode.py
.
Thanks for the direction. By reading ogParser.py
I am trying to know how to add a node. But, failed. Would you please give a trivial example of adding two states and a transition between these states. Something like below -
s0 = ogAST.Start()
s1 = ogAST.State('S1')
inp = ogAST.Input('press')
s2 = ogAST.State('S2')
root_ast.processes[0].add([s0, s1, imp, s2])
opengeode.save()
Big thanks in advance.
Are you trying to create a model from scratch or add some elements to an existing model ?
My aim is to create a model from scratch, but easy my work, I am creating a project in TASTE first, then I work in data-view and interface-view to get an almost blank model OpenGEODE. Then I am trying to get the handle on the blank model and edit it (add states, transitions).
In that case the easiest is to generate the SDL model in text form and to let OG parse it (using the "parse" API). This will be much easier than trying to add nodes using the AST.
It seems, opengeode module still support only Python 2?
@dondublon : No, I ported opengeode to Python3. This is the current baseline, the Python2 code is not is the master branch anymore.
@maxime-esa Thank you for the answer. Could I ask about the installation process? Maybe, here is not the appropriate branch. opengeode requires antlr3. I installed antlr4 successfully, but failed antlr3. The error:
File "C:\Users\s2400244\AppData\Local\Temp\pip-install-rx7p4qmy\antlr3-python-runtime\setup.py", line 49
except OSError, exc:
^
SyntaxError: invalid syntax
This is Python2 syntax, that is why I suspected that opendeoge is for Python2.
The installation of dependencies should be done automatically if you do:
make full-install
(In a Debian-based Linux)
But I'm on Windows.
To be honest, I have never tried to run the Python3 version on Windows. In the past (Python2 version) I made a build for Windows, using dependencies I had found here: https://www.lfd.uci.edu/~gohlke/pythonlibs/
However I can see that the antlr3 runtime for Python3 is not there, neither is Pyside2... I would not know how to find them. Any help welcome. If you find out I will update the documentation.
The antlr3 proclaimed for Python3 is actually for Python2. I fixed it manually, it was a real quest. Firstly I downloaded .gz from PyPi, and at last I had to replace one file from Github (antlr3 repository). The last obstacle I've faced is installing pygraphviz. So, I drop this direction and switched to another modelling tool, a experiment, too.
Hi, I need to read SDL state machine in python (or other), though I can generate some information based on its structure. Expecting something like below-
Please, help on how to read SDL? Or suggest anything better.