[BangPypers] Language Parsing and output generation

Gopalakrishnan Subramani gopalakrishnan.subramani at gmail.com
Mon Aug 22 21:09:19 CEST 2011


I have interesting problem to solve. We have a language called "Description
Language" less widely known outside but used very much in automation domain.
The examples are given below.
By definition, language is readable and I could could not provide the
language spec due to restriction (really close source in this way).

The idea is to convert the 'Description Language' code to Lua code using
Python. This involves 2 things. One is parsing and another is generation. In
between 2, I need to make a tree as a output from parser, kind of AST.

The generated Lua source base shall be used in mobile phones, Desktop etc.

The following are few example code, extracted and modified. Otherwise they
will sue us..

--------------------------------------------------------------------
#include "constant.dl"

#define MY_DEF  1
#define WIDGET_TYPE 1

WIDGET mywidget
{
    TITLE "My widget";
    TYPE WIDGET_TYPE;
    ELEMENTS
    {
        element1,
        element2,
        element3
    }
}

IMPORT  WIDGET mywidget
{
    REFINE widget_name{
        REDEFINE TITLE "Your widget";
    }
}

#ifdef YOUR_WIDGET_ALLOWED
WIDGET yourwidget
{
    TITLE "Your widget";
    TYPE WIDGET_TYPE;
    ELEMENTS
    {
        element1,
        element2,
        element3
    }
}
#endif

For Loop but needs pre-declaration of loop variable

int x;

for ( x=0; x < 8; x++)
{
   if ( something_true )
       do_this(argument1, argument2);
}

supports

do
{
    statements;
}while(condition);

supports

while(condition)
{
    statements;
}

switch statement also supported

--------------------------------------------------------------------

I prefer Python for this conversion. Any idea is appreciated.

Regards,

Gopalakrishnan


More information about the BangPypers mailing list