Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am interested in making a compiler for IEC 61131 Structured Text to target an ARM processor. I want the code generator output to be in C++. Then I plan on using GCC C++ to ARM. I already have C++ code for ARM to act as a runtime.

The PC program tool of choice is C# and I was looking at Antlr or Coco/R to convert Structured Text to C++. After reviewing Antlr I was confused on how it could generate C++. And if I understand Coco/R correctly, the code generation is part of the .atg file in the Production area.

I am new to parser concepts. So any advice would be appreciated.

What I have tried:

I have been looking at example projects and grammar files for Antlr and COCO/R. I have also tried installing and running Antlr works 1 and 2. But both Antlr editors don't function for various reasons.
I also noticed IEC 61131 Structured Text is very similar to Pascal and thought I could use Pascal grammar files as a starting point.
Posted
Updated 3-Feb-22 1:48am
Comments
George Jonsson 1-Jun-16 22:14pm    
ANTLR4 could be a good choice, it as free without any licensing as far as I know.
However, in order to get the most out of it I recommend you to buy the book. In the book you have lots examples including how to write a simple language parser.

I'm not sure what (particularly the 2nd sentence) in
Quote:
Then I plan on using GCC C++ to ARM. I already have C++ code for ARM to act as a runtime.
means - can you elaborate ?

Certainly I see no real issue using Antlr or COCO/R or ? to take IEC 61131 Structured Text, and build a 'parse tree', and then take that parse tree and produce [something] - had you not have indicated that you want to run on an ARM processor, I was originally thinking of

IEC 61131 ST --parse--> 'P-Code' ---//---> Destination machine with 'P-Code' interpreter

where 'P-Code' was a machine dependant dare I say byte-code representation. Your version 'looks like'

IEC 61131 ST --parse--> c++ source --compile for ARM using GCC--> ARM MCU binary

If I interpret what you're saying correctly.

I'd say stick with Antlr or such, get the tools to work, build a grammar, possibly starting as you say with a Pascal type grammar, then walk the Parse/AST tree and produce your c++ file
 
Share this answer
 
Comments
Member 8816170 16-Jun-16 21:57pm    
Thanks for the response. I have a Coco/R grammar running now and translating to C++. But I dont like the direction it is going. The Code Generator for Coco/R could get very complicated I started a project with Antlr4 and this seems to be a better solution. Antlr4 avoids the intermediate AST. I am trying to understand how the Antlr4 listener couples to StringTemplate. This seems like the best solution.
Member 8816170 16-Jun-16 22:14pm    
In response to your question about the C++ code for ARM. We make controllers with ARM processors and we program them with Keil MDK ARM. We could convert our firmware into a library for C++ and the GCC compiler could build this along with the IEC 61131 converted code. The plan would be to make a compact IEC 61131 programmable controller.
Have a look at the Eclipse Xtext project. Once you have your grammar defined, you can write a generator pretty easily that will generate the C++ code based on your AST.
 
Share this answer
 
I see this is an old post but I thought I would put my ten pence in,,,
Get the statement list into post-fix notation. You can then walk through the notation performing actions on the and/or logic. Once you get it into that format you will hopefully see the solution.
If you opt for the full compiler thing and you have no idea about compilers.....well good luck with that ... that is a big job.
But I don't think that's what you want, you want to bolt the code onto some other compiler and let that do the work....if so I suggest my ten pence solution..
Not sure what PLC you are making reference too. You mention the standard but there are different flavours/interpretations of the standard. If this is a start from scratch PLC then forget about the references to the 5 languages of the standard and just deal with a boolean expression e.g. ((a&b)|c);...the 5 languages will naturally fall out from the expression.
 
Share this answer
 
Comments
OriginalGriff 11-Apr-20 12:06pm    
While I applaud your urge to help people, it's a good idea to stick to new questions, rather than 4 year old ones. After that amount of time, it's unlikely that the original poster is at all interested in the problem any more!
Answering old questions can be seen as rep-point hunting, which is a form of site abuse. The more trigger happy amongst us will start the process of banning you from the site if you aren't careful. Stick to new questions and you'll be fine.
carl1248 12-Apr-20 3:36am    
Thanks for that tip, yes I did see the age of the post, the reason I answered the question was because of the the question and with the possible hope that the original poster might have progressed his interest in the subject ...there really is no agenda
I just wanted to help the guy/girl....but thanks I will take you advice on board
OriginalGriff 12-Apr-20 3:49am    
No problem - I figured it was something like that, but some of our more trigger-happy members wouldn't stop to talk ... :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900