It’s been a while since I’ve written anything here, I’ve been working on my master project like crazy, have a 6 month old baby and so haven’t had much time for programming pet projects. Tonight I spent a half hour making perhaps the most useless application I’ll ever make. It’s based on the single-serving website http://instantrimshot.com which only has one huge red button, if you press it a rimshot sound is played. I thought it might be fun to have that available as a keyboard shortcut in windows, and then I started wondering how it could be done in C#.
(more…)
I’ve blogged before about the excellent Coco/R parser generator. I’m using it a lot in my masters project and I’m happy with it but there were a few things I wished worked differently. The main thing was that I wanted better Visual Studio integration. I had set up a pre-build event that generated the parser and scanner before every build. However there is obviously no need to re-generate the files unless the grammar file has changed. Generating on every build also had the effect that Visual Studio kept prompting me about reloading changed files and I had to build to see if there were any errors in my grammar. So, I decided to create a Visual Studio plugin for Coco/R myself. (more…)
Lately I have been doing some COM automation stuff on Windows. I’ve been using JScript (Microsoft’s JavaScript implementation) since that’s available on all Windows machines, and the other option, VBScript, is horrible. Normally I would use Python and the win32com package, but I needed to make some scripts that could work on any box without installing Python first. JScript is a pretty nice language, but it doesn’t come with a REPL built in, which is very handy when you’re doing experimental stuff (REPL = Read-Execute-Print-Loop). Now, writing your own REPL in a dynamic language with an eval statement is pretty easy, so I did just that. It took about 30 lines, of which about 10 are just about printing evaluated expressions nicely. (more…)
My masters project at DTU involves writing compilers for the .NET platform and since I had never written a compiler before I decided to start by writing a compiler for a simple language called While. This language is used in the Program Analysis course that is taught at DTU and has integer and boolean expressions, read and write commands, an if branching statement and a while looping statement. The compiler compiles this language and the programs can be run with the .NET CLR or Mono. The programs can also be debugged using a free graphical .NET debugger. I put the project up on Google Code, I think it is a fairly nice example of a simple compiler for .NET. It is currently written in Boo but will soon be rewritten in C#. The compiler and its source code is available at http://while-language.googlecode.com.
I’m currently doing my masters thesis, and as part of it I needed to implement a simple compiler for the .NET runtime, the CLR. I just recently started playing around with the Boo language, which is a statically typed .NET language with very similar syntax to Python and many of its features, while still being statically typed and offering some nice extra features such as regular expression literals and string interpolation. I wanted to try the language out on a small project so I decided to use it to write my little compiler. The only problem was that as far as I could tell there were no available parser generators for Boo. (There might well be some, I must admit I didn’t really look very hard). The only parser generator I’m used to using is Coco/R, which is nice and simple to use, and available for many languages, although not for Boo. It is however available for C# so I decided to modify it myself to make it output Boo code.
(more…)
I recently started playing around with ASP.NET MVC to build a small website. I’m pretty impressed, I like working with MVC a lot better than the web forms model. One thing that ASP.NET MVC offers is to have “pretty urls” similar to frameworks like Ruby on Rails or Django, that is, instead of urls that look like http://example.com/index.aspx?car=Ford&year=1990 you get urls like http://example.com/cars/Ford/1990. This works flawlessly in Visual Studio using the development webserver but there can be some complications when deploying to IIS. The new IIS 7 has support for this built in when using integrated mode, however my webhost is still on IIS 6 and there are problems there. Essentially there are two ways that can be used with IIS 6. The first way is to map all requests to the ASP.NET engine, even ones for images, css etc. That works but has some performance implications. The other way is to use a file extension in all urls, so our example url might have to be something like http://example.com/cars.aspx/Ford/1990/. That’s not horrible but not the way I want it either. So, I came up with another way. (more…)
The last few weeks my hobby project has been creating a cardgame in Javascript. I’ve always wanted to create a cardgame and I decided to use simple Javascript so I could make it available online since no-one wants to bother to download small games. I figured there were thousands of blackjacks and solitaires out there so I decided to create my favorite cardgame, Idiot. (more…)
I was watching a movie on my computer the other day and I had gotten the subtitles for it off the internet, I think from http://opensubtitles.com or something like that. The only problem was that they were a bit out of sync with the picture, about 2 seconds too late. Using a good media player, such as VLC you can add an offset to the subtitles every time you watch the movie but I figured I could probably whip up a small script to do it for me so I could just do it once and then have the subtitles correct every time I watched the movie. (more…)
I have an old ASP.NET 1.1 application that I have to maintain and which for reasons beyond my control can’t be updated to a later .net version. I hadn’t touched it in a few months but recently I had to make some small changes and realized I didn’t even have Visual Studio 2003 anymore. I got a new computer a few months ago and I have Visual Studio 2008 and IIS 7 on it but no VS 2003. I didn’t really want to install it, it’s pretty old at this point and not very well supported in Vista, and like most programmers I like to play with the shiny new toys, not the old obsolete ones. So I decided to try to maintain this application in Visual Studio 2008. Now, VS 2008 can target different versions of the .NET framework, but only 2.0, 3.0 and 3.5 so I was out of luck. But, thanks to a nice article I found by Jomo Fisher on compiling .NET 1.1 in VS2005 and some extra hacking I got it working pretty well. My setup was IIS 7 on Windows Vista, IIS 6 on Windows XP is pretty much the same although some of the options I point to may be located in different places. So, here’s what you need to do to develop ASP.NET 1.1 in Visual Studio 2008:
(more…)
Recently I had a school project where we needed to parse a certain grammar into a syntax tree and do some analysis on the code. Everytime I’ve had to work with trees (which has only been for school projects actually) I’ve been frustrated because it can be hard to visualize the tree, especially when it starts getting large. I’ve pretty much done two things in that situation, either draw the tree on a piece of paper, which takes a lot of time and is very boring, or try to look through the structure in the debugger, which gives you some idea but is not really very convenient. So, when I was working on this new project I figured I could probably come up with some simple way of displaying the tree while I was working on it. I wanted the solution to be re-usable so I could pull it out again the next time I have to work with binary trees without having to change it to match the new project. So, here’s what I came up with.
(more…)