解释自定义语言 [英] Interpreting custom language

查看:152
本文介绍了解释自定义语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要开发一个将读取和理解文本文件的应用程序,在该文件中,我将找到描述操作列表(即烹饪食谱)的自定义语言.该语言尚未定义,但可能采用以下形状之一:

I need to develop an application that will read and understand text file in which I'll find a custom language that describe a list of operations (ie cooking recipe). This language has not been defined yet, but it will probably take one of the following shape :

  • 类似于C ++的代码

(此代码是随机生成的,仅供参考):

(This code is randomly generated, just for example purpose) :

begin
repeat(10)
{
    bar(toto, 10, 1999, xxx);
}
result = foo(xxxx, 10);
if(foo == ok)
{
    ...
}
else
{
    ...
}
end

  • XML代码
    • XML code
    • (此代码是随机生成的,仅供参考):

      (This code is randomly generated, just for example purpose) :

      <recipe>
          <action name="foo" argument"bar, toto, xxx" repeat=10/>
          <action name="bar" argument"xxxxx;10" condition="foo == ok">
              <true>...</true>
              <false>...</false>
          </action>
      </recipe>
      

      无论选择哪种语言,都必须处理简单的条件,循环.

      No matter which language will be chosen, there will have to handle simple conditions, loops.

      我从没做过这样的事情,但是乍一看,我发现将这些操作描述为XML会更简单但功能却不那么强大.

      I never did such a thing but at first sight, it occurs to me that describing those operations into XML would be simplier yet less powerful.

      浏览StackOverFlow之后,我在一个名为"ANTLR"的工具上发现了一些聊天...我开始阅读权威ANTLR参考",但是由于我从未做过这种事情,所以我很难知道它是否是确实是我需要的那种工具...

      After browsing StackOverFlow, I've found some chats on a tool called "ANTLR"... I started reading "The Definitive ANTLR Reference" but since I never done that kind of stuff, I find it hard to know if it's really the kind of tool I need...

      换句话说,我需要什么来读取文本文件,正确解释文本文件并执行我的C#代码中的操作.这些操作将通过以下简单条件在彼此之间进行交互:

      In other words, what do I need to read a text file, interpret it properly and perform actions in my C# code. Those operations will interact between themselves by simple conditions like :

      • 如果operation1失败,则执行operation2,否则执行operation3.
      • 重复10次操作4次.

      描述这些文本文件(XML,我自己的)的最佳语言是什么?这种发展过程中的关键点是什么?

      What would be the best language to do describe those text file (XML, my own) ? What are the key points during such developments ?

      我希望我很清楚:)

      非常感谢您的帮助和建议!

      Thanks a lot for your help and advices !

      推荐答案

      XML非常适合以冗长的方式存储关系数据.但是,我认为这是编写程序之类的逻辑的可怕选择.

      XML is great for storing relational data in a verbose way. I think it is a terrible candidate for writing logic such as a program, however.

      您是否考虑过使用可以嵌入的现有语法/脚本语言,而不是编写自己的语法/脚本语言?例如:

      Have you considered using an existing grammar/scripting language that you can embed, rather than writing your own? E.g:

      LUA

      Python

      这篇关于解释自定义语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆