goccmack / gocc

Parser / Scanner Generator
Other
603 stars 48 forks source link

Can you confirm that i am in s right place? #97

Open Serhioromano opened 4 years ago

Serhioromano commented 4 years ago

I am new to compiler creation.

I am building IDE for developing for PLC. As a PLC language Structured Text will be used standard IEC 61131-3. This is Pascal like language. PLC will run on Linux.

There are no compiler or parser for this language or any tool. Every vendor implement it themselves.

My original idea was to transpile ST cod to GO and compile GO. Then I've got across this tool. But few things are not clear to me.

  1. Will it generate GO app first am then compile or it will create binary right from ST?

  2. There will be ability to connect libraries in ST program. Those libs will be mirror of some GO libraries. Or written in GO as packages. Will I be able to inject those to final build?

  3. The ST program is only part that is executed periodically. But for final binary I need to add sorry of runtime environment. Wrap what developer created in ST to for cycle and call other staff to initialise I\O. Will that be possible?

awalterschulze commented 4 years ago

Sounds like a fun project.

gocc is a parser generator similar to yacc. Once you have written a BNF you can pass it to gocc and it will generate a parser and scanner in Go. You will need to create the AST as Go structs yourself, write the interpreter or compiler, figure out how to connect libraries etc.

I hope this helps to clarify. gocc is a good first step in your plan.

There might be a caveat, if your grammar requires more parsing power than LR(1), but gocc has a -a flag, which is sometimes useful to enable maximal munch. Or you can switch to https://github.com/goccmack/gogll

Serhioromano commented 4 years ago

Thank you. That makes more sense. But still not absolutely clear.

I ask question so that people can answer Yes\No stile. You answer clear somethings and make new questions. Can you answer yes or no.

Can I use gocc to parse ST and generate Go project without compiling it?

Right now it is not important for me to understand how it works, I can figure that out later by reading through all documentation. Right now I just need to make a decision to use this tool or not.