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

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

问题描述

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

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 代码
  • (此代码是随机生成的,仅供参考):

    (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 :

    • 如果操作 1 失败,我会执行操作 2 否则操作 3.
    • 重复操作 4 10 次.

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

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

    我希望我说的很清楚:)

    I hope I'm being clear :)

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

    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天全站免登陆