XAML as DSL

Sunday, May 5, 2013

About 3 years ago, when .NET 4 and Visual Studio 2010 were just released, I’ve blogged (part 1, part 2) about the changes that took XAML from its WPF inception to the System.Xaml namespace and System.Xaml.Dll assembly, to be available more generally, not just for WPF. I’ve shown that XAML is just a declarative way of creating objects, setting their properties – sometimes in interesting ways. I did promise at the end of that second post that I’d show how to use attached properties, but never did have the time to deliver. 3 years later, it’s high time I...
one comment

Console Calculator with Roslyn (Part 2)

Wednesday, August 8, 2012

In the first part we created a simple enough calculator, but it lacked two features I wanted to have:1. work with degrees or radians in trigonometric functions.2. allow simple variables to be used without first declaring them.Let’s see how we can implement these features, starting with the first.Trigonometric functions work in radians, which is sometimes inconvenient.What we need is a way to change the parameter to the trigonometric functions by multiplying it by PI/180 if degrees was requested.First, we’ll create a simple state managing class for the calculator with just one property: class CalculatorOptions {     public...
no comments

Console Calculator with Roslyn (Part 1)

Monday, August 6, 2012

A while back I create a Console Calculator project (on CodePlex) that used manual expression parsing to “understand” a mathematical expression and resolve it. As parsing was involved, this wasn’t a trivial undertaking. What about implementing something similar with Roslyn?Roslyn is Microsoft’s “Compiler as a Service” initiative, now in its second CTP. It provides a powerful framework for examining and manipulating code (among other services). Roslyn can be installed on VS 2010 SP1 or VS 2012 RC. Let’s create our simple calculator.Fist, install Roslyn. Next, open Visual Studio 2010 or 2012 and create a new Roslyn Console project (snapshot...
no comments

System.Xaml in .NET 4 Part 2

Thursday, May 13, 2010

This wasn’t meant to be a multi-part series, but it seems to turn out that way… In the first part, I’ve shown how we can leverage some of the new System.Xaml namespace functionality to construct an object tree from a XAML text. This was pretty easy with methods like XamlServices.Load or XamlServices.Parse. However, these methods return the top level (root) object, with all sub objects constructed already, without any way to intervene, or do something with the sub-objects, as they’re being constructed. To gain access to the sub-objects (and their assigned properties) during the parsing process, we’ll...
no comments

Compilers and Parsing

Thursday, April 22, 2010

I’ve always been fascinated by compilers. They seem almost magical, translating some source language to a target language or object code. And even though I understand how they work, it’s still looks like magic. Compilation relies on parsing, which is one of the more difficult parts of a typical compiler. There are several ways to do parsing, most of them using some automated code generation tools (the classics being lex (techinally the scanner, or tokenizer) and yacc (the parser), with later versions fondly named flex and bison). One way to write a parser is known as a...
9 comments

Free, Multi-language Parsing System

Sunday, March 2, 2008

  כל מי שניסה לכתוב Parser (למשל לשפת תכנות פרטית או איזשהי מערכת SCRIPT  פנימית) יודע שהדבר אינו טריביאלי, בלשון המעטה. השיטה הקלאסית (אבל המיושנת) היא להשתמש בכלים LEX ו-YACC המיתולוגיים ליצירת tokenizer ו-parser או בגרסאת המחודשות שלהם FLEX ו-BISON (משחק מילים שכזה, יאק הוא בעל חיים...). ניתן לכתוב PARSER בשתי מתודולוגיות עיקריות:  (recursive descent parser (top-down parsing ו-(LALR (Look-Ahead Left-to Right, bottom-up parsing. השיטה הראשונה מתאימה לכתיבת PARSER ידנית ללא עזרה חיצונית מכיוון שהשיטה אינטואיטיבית למדי. השיטה השניה מתאימה לעבודה עם כלים אוטומטיים (כגון YACC. (YACC מייצר קוד C טהור ולא ממש קריא. כלי נחמד המאפשר לכתוב PARSING יחסית בקלות נקרא GOLD (עובד ב-LALR)....
tags: ,
2 comments