本文介绍了向C ++语言添加statemachine支持的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,作为我工作的一部分,我一直在学习IBM Rhapsody,并使用它从UML生成C ++代码。

Lately as part of my day job I've been learning IBM Rhapsody and using it to generate code in C++ from the UML.

昨天,可能很酷,想想添加状态机支持我的C ++编译器,所以我在这里记下了几点注意:

Yesterday it struck me that it might be cool to think about adding state machine support to my C++ compiler, so I jotted a few notes here: http://ellcc.org/wiki/index.php/State_machines_and_Active_Classes

我的动机是:


  1. 这似乎是一个很酷的想法。

  2. 编译器可以做更好的语义检查/正常C ++编译器。

  3. 当编译器本身理解状态机结构时,有许多优化可能性。

我可以尝试将我的语法扩展到除了看看它的工作原理的建议。

I may try to extend my grammar to except something like the proposal to see how well it works.

您对建议的看法是什么?它看起来可读吗?它似乎值得吗?



编辑:

What is your opinion of the proposal? Does it seem readable? Does it seem worthwhile?


感谢您的建议的特定库做状态机,但这不是我的问题。我已经使用我写的库和代码实现了很多状态机。

Thanks for the answers recommending specific libraries to do state machines, but that wasn't my question. I've implemented many state machines using both libraries and code that I've written.

我真的在寻找关于状态设计的想法,批评等机器扩展为C ++语言,而不是这种改变是否适合添加到标准C ++。

I was really looking for ideas, criticism, etc. about the design of a state machine extension to a C++-like language, not whether this change would be appropriate for addition to standard C++. Think of it as a domain specific extension, where my my domain is real-time control applications.

我已经开始在我的编译器中实现这个扩展,如下所示:

I've started implementation of the extension in my compiler as described here: http://ellcc.org/wiki/index.php/State%5Fmachines%5Fand%5FActive%5FClasses

到目前为止,这个概念没有必要改变从提案到实现,但已经有一些更改细节,我正在提炼我对问题的语义的理解。

So far the concept hasn't had to change much going from proposal to implementation but there have been a few changes in details and I'm refining my understanding of the semantics of the problem.

但是,时间会告诉整个概念是否有任何值。 ; - )

Time will tell whether the whole concept has any value, however. ;-)

推荐答案

除了一些例外,C ++传统上使用类库扩展,而不是新的关键字。状态机可以使用这样的库轻松实现,所以我不认为你的提案有很多机会。

With a few exceptions, C++ has traditionally been extended using class libraries, not new keywords. State machines can easily be implemented using such libraries, so I don't think your proposal has much of a chance.

我在提案中看到的一个问题是使用'goto'去另一个状态。如果我想在状态转换中的自己的代码中使用goto,会发生什么?

One problem I see in your proposal is the use of 'goto' to go to another state. What happens if I want to use goto in my own code within a state transition?

这篇关于向C ++语言添加statemachine支持的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 13:52