سؤال

I've designed a very simple domain specific language(DSL) to specify and execute full-screen interactive behavior on devices. It's event based action language with XML as the carrier syntax. Example of it is here:

<state no="15000" >
    <timeout>30</timeout>
    <backgroundactions>
      <as3function name="hideImages">
      </as3function>
    </backgroundactions>
    <screen>
      <components>
        <textfield x="50" y="120" width="924" textsize="50" background="1" border="1">
          <text say="1">
            <part type="text">Who would you like to call?</part>
          </text>          
        </textfield>
        <button label="MENU" width="80" height="30" x="920" y="10" textsize="14" icon="none" adjtext="-5">
          <event name="clicked">
            <action preconditions="no" name="transition">
              <parameter>
                <type>state</type>
                <name>n</name>
                <value>800</value>
              </parameter>
            </action>
          </event>
        </button>
        <button label="My contacts" width="250" height="200" x="212" y="500" textsize="40" icon="iconRight2.png" iconx="65" icony="20" adjtext="35">
          <event name="clicked">
            <action preconditions="no" name="transition">
              <parameter>
                <type>state</type>
                <name>n</name>
                <value>15007</value>
              </parameter>
            </action>
          </event>
        </button>
        <button label="Other" width="250" height="200" x="562" y="500" textsize="40" icon="iconWrong2.png" iconx="65" icony="20" adjtext="35">
          <event name="clicked">
            <action preconditions="no" name="transition">
              <parameter>
                <type>state</type>
                <name>n</name>
                <value>15100</value>
              </parameter>
            </action>
          </event>
        </button>
      </components>
    </screen>
  </state>

It semantically means the following: Semantic interpretation of the DSL

It's a state transition language where the programmer declaratively describes the UI layout and the events to which the program should react to and the actions flowing the events. The DSL is designed for readability. Here's a short description of the nodes:

  • timeout: The duration of a state timer while executing each state
  • backgroundactions:these represent the actions executed on-entering a state
  • state screen: screen components and events associated with them
  • expectedevents: Events expected by the current state. these are async events

Is there a way to represent this particular language in a more formal description as a grammar or meta-model(i am not familiar with language modeling techniques). My idea is to write a language specifications for this DSL so that other programmers in my team can generate scripts in other languages of their choice such as python or lua from this specifications. Possibly even code-generate this XML as well? What would be the best way to represent this? I have been going through lots of language tools and dsl tools, but i can't figure out what would be most efficient for this langauge? someone with expertise can help me in the right direction and give a headstart on the steps that need to be done.

هل كانت مفيدة؟

المحلول 2

Use of DSLs to get close to the actual problem domain (UI and related events) makes perfectly sense. I’m aware of several metamodels specified for a certain UI, such as: mobile phones, sports computers, automotive infotainment systems, various touchscreen devices and web apps (see some public languages at http://www.metacase.com/cases/dsm_examples-ui.html). The generators can then be used to produce actual code, prototypes or test scripts.

To define these domain-specific modeling languages you specify first the metamodel including concepts (e.g. button, transition, state) and related rules (e.g. pressing button triggers a transition) followed by some notation. Then you can test the language to define a sample models like you did with the XML, and finally having some models ready, you can define the generators producing the expected results. With this appraoch companies like Panasonic, Polar and EADS have reported about better quality and increase speed. I’ve been personally involved is several such cases providing assistance, and wrote an article on the language definition at http://www.devx.com/enterprise/Article/30550. Hope this helps.

نصائح أخرى

XML is OK for experimentation, but its verbosity makes it terrible for a DSL (and contrary to the purpose of a DSL, I would say).

Invent the simplest and most readable language that can describe what you want, and then use a tool like ANTLR, PEGjs, PyParsing, PyPEG, or Grako to write a grammar and generate a parser for it.

Programs in other languages will be able to invoke your runtime by passing a string with a program written in the DSL.

BTW: there is already a DSL toolchain based on pyPEG and outputting XML – it is YML, http://fdik.org/yml

Maybe this matches your needs. Convering automatically with yml2proc -Y it is:

state no="15000" {
    timeout > 30
    backgroundactions
        as3function name="hideImages";
    screen {
        components {
            textfield x="50", y="120", width="924", textsize="50", background="1", border="1" {
                text say="1" {
                    part type="text" > Who would you like to call?
                }
            }
            button label="MENU", width="80", height="30", x="920", y="10", textsize="14", icon="none", adjtext="-5" {
                event name="clicked" {
                    action preconditions="no", name="transition" {
                        parameter {
                            type > state
                            name > n
                            value > 800
                        }
                    }
                }
            }
            button label="My contacts", width="250", height="200", x="212", y="500", textsize="40", icon="iconRight2.png", iconx="65", icony="20", adjtext="35" {
                event name="clicked" {
                    action preconditions="no", name="transition" {
                        parameter {
                            type > state
                            name > n
                            value > 15007
                        }
                    }
                }
            }
            button label="Other", width="250", height="200", x="562", y="500", textsize="40", icon="iconWrong2.png", iconx="65", icony="20", adjtext="35" {
                event name="clicked" {
                    action preconditions="no", name="transition" {
                        parameter {
                            type > state
                            name > n
                            value > 15100
                        }
                    }
                }
            }
        }
    }
}

But I would write it like this (which is correct YML, too):

// this grammar could be in a header file named guidsl.yml2

decl state(no);
decl as3function @name;
decl button(icon="none"); // default value
decl event @name;
// for the click event (which is frequent) we define a shortcut
decl clicked (*to, name="clicked") alias event {
    action transition {
        parameter n {
            type state;
            value *to;
        }
    }
};
decl action @name (preconditions="no");
decl parameter *name { name *name; content; };
decl type @name;
decl part(type="text", say=1);

// here comes the model
// include guidsl.yml2

// sensible defaults for this single case

decl button is button (
    width=250,
    height=200,
    textsize=40,
    iconx=65,
    icony=20,
    adjtext=35
);

state 15000 {
    timeout 30;
    backgroundactions
        as3function hideImages;
    screen {
        components {
            textfield x=50 y=120 width=924 textsize=50 background=1 border=1 {
                part > Who would you like to call?
            }
            button label="MENU" width=80 height=30 x=920 y=10 textsize=14 adjtext=-5 {
                clicked 800;
            }
            button label="My contacts" x=212 y=500 icon="iconRight2.png" {
                clicked 15007;
            }
            button label="Other" x=562 y=500 icon="iconWrong2.png" {
                clicked 15100;
            }
        }
    }
}

YSLT (part of YML) now gives you a language to generate the code out of it.

According to your question, there is the XML Schema language to describe and check, see http://www.w3.org/XML/Schema – And, of course, there is YSchema ;-)

VB, author of pyPEG and YML

To your question about "how does semantics work": probably you're searching for Modelling Theory. It's part of Analytical Philosophy.

Because I'm missing that, too, I'm doing research in how to transfer the know-how of theoretical philosophy through informatics into computer science. There is much work to do, though. I'm sorry that I didn't publish yet what I have – I'm not working at a university but financing all myself. So I don't have written in a proper way what is usuable already :-/ Because of that this can be only a hint for you in which direction to go. I started with Gottlob Frege, but moved away from his ideas, more working with Saul Kripke's view since some years. Speech Act Theory is an eye-opener, too.

Why not one of those plain semantic tools? Because I didn't find one which works in practice beside simple cases. It's NOT possible to have one meta-model and one model, and that's it. It's just a starter. There is more needed.

I'm working on a programming language now with this paradigm. But it's too early to show, sorry again.

Just try out one of the common semantics tools in practice, and you'll see yourself what's missing.

VB.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top