Srinivas Sampath

from t in myThoughts where myThoughts.Thoughts = "Technology" select t
Simple MGrammar

MGrammar is part of the Oslo SDK and allows the definition of grammar files that can be used to thus define textual domain specific languages. For example, you can write a mgrammar file to understand musical notes in a given format (which is also one of the example that is present in MSDN). I wanted to see how a typical mgrammar file might look like (with not too much frills).

I wanted to write a mgrammar file to understand complex numbers. Complex numbers consist of a real number and an impaginary number and is of the form: x + yi. You can read more about complex numbers from this location. I also wanted to ensure that I have one complex number per line of input.

To begin writing this grammar:

·    Start Intellipad with samples enabled

·    First create a file called ComplexNumbers.mg and then save the same

·    I had to restart Intellipad at this time and then press Ctrl+Shift+T to open the tree view mode

·    Choose the file created above

·    You will now see 3 panes: an input pane, a grammar pane and a treeview pane

You can now author the grammar file. Here is the grammar that I wrote:

module ComplexNumbers {
    language myComplexNumbers {
        // Allow 1 or more complex numbers to be defined
        syntax Main = complexNumber+;
       
        // Define the structure of a typical complex number
        syntax complexNumber = realPart "+" imaginaryPart "i";
       
        // Define the various tokens that make up the complex number
        token realPart = Digits#1..2;
        token imaginaryPart = Digits#1..2;
        token Digits = "0".."9";
       
        // Ignore any noise characters
        interleave whiteSpace = " " | " " | " ";
    }
}

You can take a structured approach to build a grammar file. In our case, the following logic will help us arrive at the grammar file:

·         A complex number is made up of a real part and an imaginary part. This definition is present in the line:

// Define the structure of a typical complex number
syntax complexNumber = realPart "+" imaginaryPart "i";

·         The realPart and imaginaryPart references are tokens which are defined in the next line as follows:

// Define the various tokens that make up the complex number
token realPart = Digits#1..2;
token imaginaryPart = Digits#1..2;
token Digits = "0".."9";

·         We have specified that the token Digits further define the real part and imaginary part. The Digits token indicates that it is a sequence of 2 numbers ranging from 0 to 9

·         Finally, we want the user to enter arbitrary white space characters in the representation. The interleave command allows us to specify characters that need to be ignored

Once you type this grammar, you can specify different types of inputs in the leftmost pane. Some examples are:

1.     3 + 4i

2.     2+3i

3.     13 + 17 i

As you keep entering these valid sequences, the rightmost pane will display a directed graph type of output of the results as shown:

Main[

  [

    complexNumber[

      "17",

      "+",

      "13",

      "i"

    ]

  ]

]

 

If you enter anything invalid, for example: A + Bi, you will see that an error is raised in the error pane below.

 

This was an example of a very simple MGrammar for parsing complex numbers. In subsequent posts, we will go deeper into some more features. Have fun!

Oslo

The first thing that I started understanding about was Oslo. Oslo is a platform for model driven applications. There are a host of sessions around Olso and a web site at MSDN dedicated for the same: http://msdn.microsoft.com/hi-in/oslo/default(en-us).aspx. From here, you can download the Oslo SDK.

The first step in getting over Oslo was the installation of the M language. I had written an earlier blog post about single letter languages making a come back and here is another one :-) Before poking around the M language (which I will write in another post), I had to install the SDK.

As all installations tend to fail, my first attempt at installing the SDK failed by not creating the repository for the models in the SQL Server. I had a named instance of SQL Server 2008. Some poking around in the forums for Oslo revealed that this was a common issue, but finally, I managed to sift through all of them and address my specific issue, which I will explain here.

Basically, during installation, because of the named instance of SQL Server, the installer was not able to create the default model repository database and upload some files into it. When I started doing this manually, although I had given a custom connection string, it still tried to reach the domain controller for authenticating logon and this failed, as I was working offline. Thus, the creation of the database manually also failed.So it looks like I needed to be on the network. The manual commands for creating the repository look like the following:

CreateRepository /cs:"Server=<your server>;User Id=user;Password=pass" /db:<instance name>

Thus successfully creates a database by name Repository and puts in a whole host of stuff into it. Next was to upload a model image and this command worked well.

Mx /i <image file.mx> -db:<database name> -s:<instance> -u:user -p:password

So after both these, I was up and running.

Oslo also comes with a new text editor called Intellipad that allows you to create models. Not sure why the team did not just integrate it into Visual Studio, but the editor today is quite primitive. So in the long run, it may get sophisticated.

Now, for creating some models....

PDC 2008

Recently, I was browsing all the recordings of the various sessions from PDC 2008 and few of them are really interesting and am spending some time learning more about them. They are:

  • Windows Azure
  • Velocity
  • Oslo
  • CCR and DSS Toolkit

I will be blogging about some of these as I get to try them and see their usage.

The D Language

Today, as I was browsing my online book collection, I ran into a book that talked about the D language. Intrigued, I searched for this and ran into this web site: http://www.digitalmars.com/d/. There is a good example of a Hello, World reloaded and the syntax reminds me of C and C++. In fact, D is a statically typed language for systems programming.

Looking at these single letter language evolutions, I remember that In my college days, we learnt the B language was the predecessor for the C language. C was overloaded with C++ (derivations off C++ into the world of object oriented languages is a history by itself and there, I ran into a language called BOO). Now, we have D that aims at merging C and C++. I don't think we have an E language yet, but there is already F# by Microsoft Research: http://research.microsoft.com/fsharp/fsharp.aspx

Its totally cool to see this evolution and one day (possibly before my lifetime), I think we would have covered all the 26 letters of the alphabets, each, as a language.

Excel Add-ins

Each week, I normally submit a report to my management that contains details of people's utilization etc. I had an Excel sheet that connected to a SQL Store and populated a table in the sheet from which I had a pivot table. From this pivot table, I used to cut and paste data into my actual report.

It was tedious work and as the team size grew (more than 100), it was difficult to do this manually. Wanting to automate it, I looked at options like VSTO, Macros in Excel. Sometime back, I ran into this great tutorial put together by the Swiss MSDN team on Office Business Applications. You can download the tutorial here. Suffice to say that it was one of the best tutorials that I've ever read.

I quickly created a C# Excel Add-in that allowed me to get the data that I want from the database and then populate my template Excel. There was also a tutorial on creating Office Ribbons in the same document and in 2 minutes I had one up and running. Too cool!

Some excerpts of the code that I used:

// this code allows you to get a range and manipulate it as a whole

Excel.Range rng = Globals.ThisAddIn.Application.get_Range("LoggedHours",    Type.Missing);

rng.Value2 = "";

// this snippet gets a value in a cell. Note how everything is treated as

// a range

string cellValue = (rng.get_Item(i, 1) as Excel.Range).Value2.ToString();

int key = Int16.Parse(cellValue.Length > 0 ? cellValue : "0");

I also managed to experiment with one other new feature in C#, which is extension methods. I had to mimic the Right function to get at the rightmost characters of a string and it was tedious to use SubString all the time. By implementing an extension method on the String datatype, it became a breeze. You can see how I'm using it here:

toDate = dtToDate.Value.Year.ToString() +

        ("0" + dtToDate.Value.Month.ToString()).Right(2) +

        ("0" + dtToDate.Value.Day.ToString()).Right(2);

 At the end, I'm happy now that what used to take me 30 or so minutes to complete now takes me 30 seconds!

 

JavaFX

Recently, one of my collegues introduced me to JavaFX, the RIA scripting language from Sun. At first sight, it looked similar to SilverLight (which I'm also experimenting with), but I'm yet to dig deeper into both of these.

I wrote my first JavaFX script from Eclipse. I did have some teething issues to get it to run in Eclipse. For one, I read a blog post that mentioned that JRE 6+ would work fine, but it worked for me only with JRE 5+. Here is the simple program that I wrote. I did not like the fact that I had to create a run configuration in Eclipse for each project. I would have liked just a simple Run command for JavaFX. Maybe it will come down the line...

import javafx.ui.*;

 

Frame {

      title: "Hello World, JavaFX"

      width: 200

      height: 50

     

      content: Label {

            text: "Hello World, JavaFX"

      }

     

      visible: true

}

What have I been up to?

Well, its tough to answer :-) Been quite busy with my regular work, but have been keeping touch with a few technologies over the last few months. They are: LINQ, SilverLight 2, Eclipse Modeling Framework, Windows Communication Foundation, DSL Toolkit.

That's actually quite a handfull! Will be blogging about some of these soon.

Strange Uninstall Request - VSTO 2005 for 2007 Office
I was installing VSTO 2005 Tools for Office 2007 and while the setup was running, it came-up with a strange uninstall request. I was asked to uninstall Visual Studio Team Explorer - ENU. Not sure why! However, I uninstalled the same and the rest of the install went ahead just fine. But any ideas?
SOA Widget

Interested in keeping yourself up to date on the latest happenings in the SOA world? Why search web sites, feeds etc when you can have all that delivered to your desktop!

Download the IBM SOA Widget and have all of SOA related content delivered to your desktop so that you can keep yourself up to date. You can download the widget here: http://www-306.ibm.com/software/solutions/soa/widget.html

Interestingly, I was not able to download from the site listed in the above link. It is an FTP site and was not reachable. Maybe you will have more luck :-)

=Rand() in Microsoft Word

Saw this feature while I was watching a demo and it was quite cool.

The presenter was demonstrating the new blogging feature in Sharepoint 2007 and as part of this demo, Microsoft Word 2007 was used as the blogging editor. To insert some sample text into the block, the presenter typed =rand(3) in the document and some text appeared magically! I was suprised as to what was actually happening and to test this out I launched Word 2007 and typed in =rand(3) and voila, I got some random text.

Looks like this feature has been there from earlier versions too. I searched the internet and found this post: Inserting Random Text and it was interesting to see that you can control the number of paras and sentences in the paras as part of this syntax.

Interesting!

What's happening now

So what have I been doing now? Outside my regular work activities which takes around 80% of my work day away, I just got my hands on the VS 2008 Beta 2 VPC and got it functioning. I got some errors while launching the application which I fixed finally. It was also my first Vista experience and frankly, I'm not yet floored :-)

I'm waiting for the new Katmai release which is due soon and wanted to try out some new features in that too.

I'm keen on following-up on LINQ and ADO.NET Entity Framework and just finished installing all of these and got my first sample running. Planning the spend the rest of this week and next on playing around LINQ.

How did I suddenly get time now? Well, right now am in the US and in-between strategic meetings, there is a lot of time and thus, I can play around technology without having to worry about my regular work (someone back home is taking care of it for me now ;-)). I'm off to Seattle next week for the 2007 Platform Strategy Meeting and am hoping to learn a lot there on Data Access technologies, OBA etc. Am returning back to India around the 21st of this month and hopefully will continue my learning's into LINQ etc.

We recently started a Microsoft Forum at our office back in India and I wanted to present some of this material back in that forum. So I should be back in action!

Its been a long time
Yup, its been really a while since I have blogged (almost 9 months). Life is been quite hectic and in my role, I was removed from a lot of hands-on technical reading that I used to do earlier-on and blog about. Fact is, I'm back to doing some technical reading now / playing-around now, so hopefully, I will start blogging again.
Microsoft and Domain Specific Languages
For the last few days, I've been working on the new Domain Specific Language (DSL) tools in Microsoft Visual Studio 2005. To say the least, it looks quite good and promising to invest some time exploring it! However, as I was trying to understand how a DSL differed from a UML profile, I ran into this interesting blog post from Grady Booch that explains why the term Software Factories that Microsoft choose is not apt. The blog post also compares UML profiles to DSL's and is an interesting read.
JDeveloper Production Version Released

The production version of JDeveloper has been released. You can download it from the Oracle site. Post installing this release, all my hang-up issues went away.

One really nice thing that I like about JDeveloper is that you can just delete the directory where it was installed and then copy over a new version. No need to fire-up un-installation utilities, registry cleanups etc. Wish that Visual Studio 2005 was as simple as this! :-)

Oracle Application Development Framework (ADF)

For the past few days, I've been playing with the Oracle SOA suite and trying to develop small applications in the new JDeveloper IDE using the Oracle ADF framework. On first impressions, its really good! Oracle has done a great job in the UI and the productivity features that I was able to write a small application (master / detail type of web application) in under 1 hour (given the fact that I had to learn ADF in the process also)! That's truly impressive! The best thing was, in this entire process, I did not have to write one single line of code.

A typical development process using ADF looks like the following:

  1. Define the entities of your application visually by dragging them from the database. This sets up entity POJO type of classes
  2. You can then create views out of these entities by combining them together in different combinations depending on the use case that you are trying to solve
  3. You can then drop these views into what are called application modules which are service endpoints for your application
  4. Once the above 3 steps are done, you can create a web page and then drop the different entities in the application module (which is wrapped into a binding object) into the web page and JDeveloper automatically figures out the UI required and puts everything in place
  5. Just run the UI and everything works like magic!

Few things that I liked in the above sequence was the ability to define UI labels as part of your view definition so that the web layer is able to take these out of the entity objects itself. You can also define simple validation rules on the attributes of the entities (like email format etc) graphically and these are enforced uniformly.

I'm still continuing to play around with ADF and will write more blog posts on things that I find interesting. One initial hitch that I had was trying to use SQL Server as the datasource in JDeveloper for my project (I should have guessed that it might not be easy ;-)). Finally, I installed Oracle Xpress Edition (another cool product) and everything worked well. One other irritant was that periodically JDeveloper decided to freeze up and eat 100% of my CPU. Don't know why...

More Posts Next page »