Custom Language Interpretation

I need to develop an application that will read and understand a text file in which I will find a special language that describes a list of operations (for example, a cooking recipe). This language has not yet been defined, but it will probably take one of the following forms:

  • C ++ as code

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

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

(This code is randomly generated, for example, for the 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>

Regardless of which language is selected, you have to handle simple conditions, cycles.

I have never done this, but at first glance it occurs to me that describing these operations in XML will be simpler and less powerful.

StackOverFlow ANTLR... "The Definitive ANTLR Reference", , , , ...

, , #. , :

  • 1 , operation2 else3.
  • 4 .

(XML, )? ?

, :)

!

+3
4

XML . , , .

/, , , ? :

LUA

Python

+3

, XML, XML XML /.

/ "" . . C/++.

XML lexer " ++" .

, , / lexer.

, ANTLR , . , . , , , , , .

+2

F #. xmls, Pattern Matching Active Patterns.

C F # ( F # )

XML #/F # + XmlDocument.

:

  • YourLanguage

, .

+1

: S-

C XML - . . C-like , - , , , , . XML , . , - , , , , ?

S- , XML, , C. . . Parsers .

, . , MerickOWA , ANTLR , , , . . programers.stackexchange , .

+1

Source: https://habr.com/ru/post/1784103/


All Articles