Regex Based Parser and Virtual Machine

/
0 Comments
With Visual Studio 2012 Microsoft dumped the DirectX SDK, and the effects library with it( along other things), which I needed for my engine.
To compensate for that, I wrote some code to load an xml file that describes the outputs and inputs of the shaders, just like the .fx files used to do.
Having that working, I realized xml is a bit too cumbersome for that use, and coming up with some small language will speed up development time, plus, I've always wanted to write a parser/compiler/vm.
Before starting with it, I decided to try to do something smaller first, something to parse/execute a kind of assembly code meant to run embedded in an application.
So after a lot of coding, and messing with regular expressions, I finally managed to get it working. 
The parser can load code like this:
and produce a memory representation that the vm can execute. The example above adds in parallel two arrays of floats, and stores the result in another array. 
The vm code runs from 10 % to 20 % slower, which isn't that bad for a simple implementation. Ok, so now some code! I won't put the VM, as it is a lot of code, but I'll put the parser.

Parser:



You may also like

No comments:

Pages

Powered by Blogger.