如何创建将IEC 61131结构化文本转换为C +的代码生成器 [英] How do I make a code generator that converts IEC 61131 structured text to C+
问题描述
我有兴趣为IEC 61131结构化文本制作一个目标ARM处理器的编译器。我希望代码生成器输出是C ++。然后我打算在ARM上使用GCC C ++。我已经有了ARM的C ++代码作为运行时。
选择的PC程序工具是C#而我正在查看Antlr或Coco / R来转换结构化文本到C ++。在审查了Antlr后,我对如何生成C ++感到困惑。如果我正确理解Coco / R,代码生成是生产区域中.atg文件的一部分。
我是解析器概念的新手。所以任何建议都会受到赞赏。
我尝试过:
我一直在查看Antlr和COCO / R的示例项目和语法文件。我也尝试过安装和运行Antlr工程1和2.但是两个Antlr编辑器由于各种原因都不起作用。
我也注意到IEC 61131结构化文本与Pascal非常相似,我想我可以使用Pascal语法文件作为起点。
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.
推荐答案
我不确定
然后我打算在ARM上使用GCC C ++。 我已经拥有ARM的C ++代码作为运行时。
Then I plan on using GCC C++ to ARM. I already have C++ code for ARM to act as a runtime.
意味着 - 你能详细说明吗?
当然我看不到使用Antlr或COCO / R的真正问题还是?采用IEC 61131结构化文本,并构建一个'解析树',然后采取该解析树并生成[某事] - 如果你没有表明你想在ARM处理器上运行,我原本想的是
IEC 61131 ST --parse - > 'P-Code'--- // --->具有'P-Code'解释器的目标机器
其中'P-Code'是机器相关的敢于说我的字节码表示。你的版本'看起来像'
IEC 61131 ST --parse - > c ++ source - 使用GCC进行ARM编译 - > ARM MCU二进制文件
如果我解释你正确说的话。
我会说棒使用Antlr等,让工具工作,构建一个语法,可能就像你说的Pascal类型语法一样,然后走Parse / AST树并生成你的c ++文件
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
有看一下Eclipse Xtext项目。一旦定义了语法,就可以很容易地编写一个生成器来生成基于AST的C ++代码。
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.
这篇关于如何创建将IEC 61131结构化文本转换为C +的代码生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!