Thursday, July 06, 2006

Operators and some examples

Yesterday I finished the unary operators, so the binary operators remain to be completed. I know that there are tools, that can be used to automate the creation of a parser, but I prefer to write my own parser by hand. It is more fun that way (am I crazy, because I like writing parsers?)

OK, time to start with some examples. How about building a draw file in DScript? First some macros:

Macro Header prog xl yl xh yh
NTString 4 "draw"
2 Word 201 1 ! version
NTString 12 prog
4 Word xl yl xh yh

Macro Text textcol backcol font xsize ysize xc yc str bb_xl bb_yl bb_xh bb_yh size
Word 1 ! Text
Word size ! total size of text object (future versions of DScript will be
! able to calculate this value automatically)
4 Word bb_xl bb_yl bb_xh bb_yh
2 Word textcol backcol
FlagWord ! little trick to ensure only lower 8 bits are set
! (upper 24 are reserved)
8 Flag font
2 Word xsize ysize
2 Word xc yc
String str
And now a draw file:
Header "draw" 0 0 1000 1000
Text 0 255 0 16 16 0 0 "test" 0 0 1000 1000 60
The given values are more or less arbitrary. Not sure if they would give reasonable results, but that doesn't matter since it is only an (untested) example.

These macros have pretty large argument lists. We could improve them by putting some values in variables, that could be modified by other macros, e.g. the colours:
Header "draw" 0 0 1000 1000
SetTextColour 0 255
Text 0 16 16 0 0 "test" 0 0 1000 1000 60
Text 0 16 32 0 0 "test2" 0 0 1000 1000 60
Since I am running out of time, I won't give you the SetTextColour and the modified Text macro here. You can try writing them yourself, when DScript is released ;)


Post a Comment

<< Home