Tuesday, January 6, 2009

MGrammar + MSchema example

Justin asked a question about what it means to bring MSchema nad MGrammar together. Let me do a simple example to clarify.

Today I can write my semantic model in MSchema as such:

module Contacts {
type Person { Name : Text; Age : Integer32; }
People : Person*;
}

I can then write a grammar like this to generate values like this:

module Contacts {
language PeopleLang {
{
syntax Main = p:Person* => People { valuesof(p) };
syntax Person = n:Name a:Age => { Name = n, Age = a};
// elided details
}
}

There's a bunch of things that come to mind with the MGraph produced by the DSL versus the values expected by the semantic model, such as:
Type Checking
How do we statically (or dynamically) check that the values are typed correctly. For example, I want to do something like this:

syntax Person = n:Name a:Age => { Name = n : Text, Age = a : Integer32} : Contacts.Person ;

Expression support
I can build values up in MSchema using expressions and querys. Shouldn't I be able to do that on the RHS of grammars? For example:

syntax Name = f:FirstName l:LastName=> f + " " + l;

I also want to use functions and other things in the semantic model to both construct values as well as validate structural correctness.

Constraint support
Semantic models have constraints. Shouldn't values produced by MGrammar be validated against those? This is really a superset of the type check question since typing is really a form of constraint checking the structure of a value.


So, when I talked about MSchema and MGrammar integration in previous posts, I was hinting at the idea of bringing together the semantic model with the DSL declarations to ensure that the DSL output aligns with the model.

I hope that helps.

6 comments:

startbigthinksmall said...

Great, too. Exactly what I asked for in a Forum Post.

You say, V1? Won't there be more CTPs before V1?

http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/420722da-4a94-4a51-9fbb-bd7bdae9e075

Pinky said...

Yes - we're hoping to produce a new public CTP every 3-6 months.

stay tuned :)

startbigthinksmall said...

Doo you have plans on linking with MGrammar / MSchema? I think i read something about it, but I can't remember where.

Read this for what I mean: http://blog.efftinge.de/2009/01/xtext-scopes-and-emf-index.html

Pinky said...

Yes - we want linking plus lots of semantic behavior on the right-hand-sides of grammars.

In the limit, you should be able to produce in the grammar anything that you can hand type in the schema language (e.g., 1 + 1).

Serdar ( BlackFeel said...

travesti
seslichat
seslisohbet
porno
sikiş izle
porno izle
porno
porno izle
porno izle
porno
sikiş izle
omegle
yabancı kızlarla chat

sesliyes said...

thanks for sharing perfect site ı am coming everday here
sesliserbest
sevgiadresi
seslidünya
i love here ı am comın everday because perfect web sıte
sesli chat
sesliyes
seslimazi
konya chat
seslimazi
hollanda chat sitesi
sesli siteler
seslicet
uzayseslim
esesli