I had the privilege of speaking at the Microsoft Innovation Day. Unfortunately it was a small session that cannot fit to even go very quickly on everything on Oslo.
We're going to get started with a small real life scenario as an example: I really want log my daily expenses as I go. I don't want to wait till I go home to start adding those expenses & trying to remember them.
So What we'll do is pretty simple, we're going to record some data like "I spent $10 on food" at my mobile, send it through SMS , email it then i have the same processor on the other end to "understand" and save it to a database.
What's DSL ?
DSL or Domain Specific Language means as you read it. It is some sort of language for a specific domain , could be music, medicine, economy or even a system analysis language.
Just before we get started, this is a pretty simple demo that was made specifically for short presentations, it would give you a sneak peak about what Oslo is, but this is like 10% of what Oslo does, so have a look at the resources paragraph at the end.
1. Download Oslo SDK
You can download January 09 CTP from here.
2. Add your Domain Specific Language Text

3. Open a template.
a. Create a new file and name it Expenses.mg.
b. Press CTRL+ALT+T to open the template pick window & open the Expenses.mg file.
c. The Window turns to a 3 panes mode.
4. Start Building MGrammar
a. Everything should start with a module
b. Inside the module we can define a new language, import other languages, create queries & relations & lots of stuff I'll talk about on other posts.
c. We'll start by defining the module & naming the Language. Languages always start with syntax Main syntax
d. Now I am telling the computer that my "Expenses Language" consists entirely of only one sentence "I spent 400 LE on Taxi". The computer understands it & displays on the preview pane what it understood.
5. "Tokenize" the syntax
a. We'll start tokenizing the syntax, so we can extract the useful information from the raw data.
b. We'll ignore the whitespaces for now , interleave keyword instructing the parser to ignore those characters/syntax. We'll ignore spaces, dots , Carriage & Line Feeds.
6. Generalizing the tokenized text
a. If i tried to replace "400" with "300" it won't work. So we need to generalize the variable data. We'll create "tokens" that represent the data we want so we can accept variables.
7. Project extracted information to "data stores"
a. After Extracting the data , we'll project these data to data stores. Data stores is just a name came by my mind to simplify the concept of Projection is "redirecting" or "reformatting" these data to a whole new schema that would be used to generate the M file.
b. I meant to change the names of the projected value to show you the difference (i.e. Person -> Name, Amount -> Money, etc...)
8. Accept multiple entries
a. Now, It's not practical to insert only one item each time , I want to say I spent X on this & Y on that at the same time. Here's how can we can we accept multiple entries and how to project them.
9. Running M commands
Save the files, I save the DSL pane contents as "expenses.dsl".
The commands you can find at "C:\Program Files\Microsoft Oslo SDK 1.0\Bin" I always add that path to the Environment Variable %PATH%. We'll use four commands that takes the dsl input file and saves it to a SQL database as the following:
Compile the Model using MG Tool. It generates a expenses.mgx file at the same directory
mg expenses.mg
Use the Language Utility to Generate M File by referencing the generated mgx file from the previous step. This step generates a expenses.m file.
mgx expenses.dsl /r:expenses.mgx
Compile the M generated file to an Image using M utility.
m expenses.m /p:image
Load the Compile File to the database... (Use /c to create a new DB & /s if you are not using the default SQL instance)
mx /i:expenses.mx /d:NEW_DB /s:(local)\MY_SQL_INSTANCE /c
10. Check the extracted information in the database
Open your SQL Server, you'll find the database crated (I used demo db instead of NEW_DB db)
So you can now run reporting, use excel data feature, do whatever you want on expenses we just wrote on a regular file.
Here's the final grammar file:
module Finance
{
language Expenses
{
syntax Main = s:Spending* //* means a collection of Spendings
//valuesof keyword projects multiple values from a collection
=> Spendings {valuesof(s)};
syntax Spending = p:Person "spent" a:Amount c:Currency "on" i:Item
=> {Name = p, Money = a, Currency = c , Description = i};
//Read Characters from A to Z Case Insensitive
token Person = ('a'..'z' | 'A'..'Z')+;
//Accept only numbers from 0 to 9
token Amount = ('0'..'9')+;
token Currency = ('a'..'z' | 'A'..'Z')+;
token Item = ('a'..'z' | 'A'..'Z')+;
//Eliminate the white spaces & trivial characters
interleave Whitespaces = ' ' | '\r' | '\n' | '.';
}
}
Please contact me at remon.zakaria { a t } dashsoft.com if you need more information.