<bgsound src="http://images.jian2587.multiply.com/playlist/3/1/full/U2FsdGVkX192IlbpiMF8r3F2BmqRKJ,Ik7F0cyknCak=/infernal%20affairs.m3u" type="audio/mpeg">

Thursday, September 01, 2005

My first experience with creating a programming language

Creating a programming language is not as hard as it sounds. First, you define your programming syntax, then the basic keywords, the conversion from high-level to low-level(or to obj files first, then linked with libraries, finally executables, thus your concern includes which OS it runs on).
I don't have to learn the EXE Image format(is it PSP or something? I forgot), because I'm directly translating high-level to asm codes. That's right, assembly codes. I don't have time to think up a new syntax, so I take BASIC's, because it's so "basic" and easy. I'm trying to inject new capabilities to the BASIC language, which includes very very advanced functions as accessing the hardware and memory directly, as well as manipulating them. Data types will be as fundamental and simple as is possible. The string may be just like an array of chars, instead of a long train with a string descriptor in front.
Most importantly, I put in the OOP capability into this ancient language. Hardware, memory, Video memory, Library APIs, etc blah blah will all be created and used that way, that is OOP. So I actually have to define an object's structure, and how could it serve as the base that accomodate to all kinds of objects, not to mention interface inheritance and polymorphism, all of which I've to take in account.
And yes, though it's a variant of Basic, I don't call it Basic. I call it S language. S for small, smooth, swift... and the list goes on.
Finally, after much talking, I actually had only done the data declaration and math expression parsing part. Math expression is done using the stack data structure, which is a FILO or LIFO structure. First I convert them from infix to postfix, and then rearrange them according to the operator's precedence level. When that's done, I convert them to asm codes using a table.
Guess what? It actually work! I can use this parser thing to convert complex math formula into fast and small asm codes! Then I can inject them into VB or any slow language for that matter. Too bad I don't know how to use the math co-processor, otherwise I could do floating points :)

0 Comments:

Post a Comment

<< Home

.