victorlei / smop

Small Matlab to Python compiler
MIT License
1.08k stars 409 forks source link

New Matlab Lexer & Parser #179

Open RobBW opened 2 years ago

RobBW commented 2 years ago

There is a new and open source tool for parsing and lexing Matlab at:https://misshit.org Github repository at https://github.com/florianschanda/miss_hit It is described as follows:

"There have been other attempts at this, but MISSHIT tries to do things differently (and I hope better). Specifically: • It is completely stand-alone. It does not require a working MATLAB or Octave setup. • It is not just a bag of reg-ex, or a wrapper arounds some undocumented MATLAB internals. It is based on a feature complete lexer and parser, which supports every single weird feature of the MATLAB language. • It contains features specifically for huge industrial code-bases (i.e. millions of lines): multi-threaded analysis and a sophisticated configuration and justification mechanism. • Designed for both interactive use during development, and integration into modern CI environments."

It will undoubtedly be a good resource for people wanting to extend the capabilities of smop.

Helveg commented 2 years ago

Do you have any idea how to use it though? It promotes a couple of CLI tools but doesn't really go into much detail for the lexing/parsing. I see there's a fork that's trying to implement something for parsing to Python: https://github.com/chaoqing/miss_hit/blob/9304eb2800681fa2bcfe5a18fc3a5d898d1da35d/miss_hit_core/m_ast.py#L3358

florianschanda commented 2 years ago

Hey. :)

Lexing and parsing is fully complete with all features of MATLAB (even the dumb ones) supported. What is not working yet is semantic analysis (i.e. name resolution and type inference). I am very happy to assist you or answer any questions you might have to get something working.

It's enough to write a bunch of tools (code formatter, code metrics, linter, etc.) but to do more interesting things (like code generation) I still need to put in place a lot of code.

Generally the focus is completeness and correctness over "do everything fast but only for a small subset".

Helveg commented 2 years ago

That's a nice focus for the project! For the SMOP community what is going to matter most is translation of MATLAB code into equivalent Python code. I saw someone with a fork who is trying to do just that. How would one go about using the project for transpilation purposes?

RobBW commented 2 years ago

You can test that fork online here: https://translate.mat2py.org The underlying code is here: https://github.com/mat2py/mat2py

chaoqing commented 2 years ago

Hi @RobBW, thanks for linking mat2py. Actually mh_python is responsible for code translating and mat2py is the runtime to evaluate the generated code. Hi @Helveg, you can give a try to this online matlab emulator.