Programming Language

BlitzMax Forums/BlitzMax Programming/Programming Language

Azathoth(Posted 2009) [#1]
Anyone made one in Blitzmax?
What did you use for the parser, handwritten or generated?


CS_TBL(Posted 2009) [#2]
If you see a 'programming language' as: 'giving instructions to a computer' or 'giving instructions to its host program' then I made a simple script parser, years ago. I think it's in the archives somewhere. It's basically command, value, command, value, command, value etc. Very simple, but adequate for what I wanted (a texture generator).


Tommo(Posted 2009) [#3]
http://www.blitzbasic.com/Community/posts.php?topic=77298
MicroC. This is written in pure bmax.


Azathoth(Posted 2009) [#4]
I was more talking about something that can evaluate expressions, like: a*2+10


mic_pringle(Posted 2009) [#5]
@Azathoth

I believe Brucey has a module that parses mathematical expressions such as the example you gave

-Mic


Brucey(Posted 2009) [#6]
It's like deja vu all over again :-)


ziggy(Posted 2009) [#7]
I did this small script language on BlitzMax. It's not been very well tested, but it seems to work...

http://www.blitzbasic.com/codearcs/codearcs.php?code=2103


Yasha(Posted 2009) [#8]
There's no shortage of these written in Blitz3D. If you're feeling adventurous you could always rewrite this or this or even this in BlitzMax?


Azathoth(Posted 2009) [#9]
muParser isn't really what I'm looking for, and I've written something similar in C++ (although no where near as many features as muParser). There doesn't appear to be anyway to get the bytecode or redefine operators.

MicroC and ziggy's look interesting.

The only thing like a parser generator seems to be this by grable, but doesn't appear to have been updated since 2 years ago.


Warpy(Posted 2009) [#10]
I've got an unconventional parser/interpreter system that I've been using for a lot of my things lately. What kind of thing is it you're looking for? Making something which can parse mathematical expressions is pretty easy, and I think mark's posted a bmax one somewhere previously.


markcw(Posted 2009) [#11]
Would the JSON readers by Warpy and/or by grable do this?


ImaginaryHuman(Posted 2009) [#12]
I haven't done expressions yet but I am working on a scriptable engine. Similar to CS_TBL I basically have a `command` followed by a number of `paremeters`, in an array. Very simple, similar to assembly language where you basically just issue one simple instruction with a few (or no) parameters to move data around, do math on it, etc. Very easy to implement and pretty fast to `run` it.


Azathoth(Posted 2009) [#13]
Really wanted to see how people implemented things like structures, functions and compile time expressions; for example MicroC will evaluate the whole expression: a+2+1 at run time when it could evaluate '2+1' at compile time.

Also checking if there was any other parser generators.


ImaginaryHuman(Posted 2009) [#14]
What I'm thinking to do, to handle expressions, is to require the strict use of pairs of brackets to isolate things, and to otherwise evaluate from left to right. ie a+(4/2) is different to a+4/2. You can recursively count the brackets until you get to a right bracket and then do whatever is between them, and work your way back up.


Azathoth(Posted 2009) [#15]
a+4/2 and a+(4/2) should be the same, / has a higher operator precedence than +. My parsers I've written had no problem there, it was expressions that should be evaluated at compile time rather than run time I've had trouble with.


beanage(Posted 2009) [#16]
Looks like theres some people working on scriptable engines atm; Skully, IH, Leadwerks, me included. I'm just having something with full-blown function definition, classes, constants, variables, pragmas, expressions - plain bmax -but unfortnately its bound to a whitebox framework so it wont realy serve you i presume. in addition its type-free (string based local vars) so it will be too slow in most peoples eyes.


Azathoth(Posted 2009) [#17]
Is it interpreted or compiles to bytecode?


beanage(Posted 2009) [#18]
Its compiled into a hierarchy of expression objects, where an expression object may have a function or a modificator or a set operator plus an operator and subexpressions.Those get recursively evaluated on running an expression.

sample syntax (obviously a little messy atm):
define__
MyConstant:=2.7174;
include__
MyConstantsAndFunctionsCollection;

MyFunction( MyParameter )
[
 return MyReturnVar;
 local MyVar;
 \\{this is a comment on the senseless stuff done below}
 {(
  if( (\%MyParameter=MyConstant)
   then((\%MyVar):=(\%MyConstant^2))
   else((\%MyVar):=(mystring))
  )
  (\%MyReturnVar:=\%parent.MyFunction.MyVar)
 )}
 \parent.MyFunction{ (myConstant) } \\{lets have the function call itself to crash the application!}
]


I think, its pretty much the easiest way to let a scripting language behave in a way one may call 'professional'. The actual downside of that object-based compilation might be the higher mem-consumption.
The language itself is actually just the 'visible part' of a whole nodegraph based virtual machine. if i get work done today, i showcase that tomorrow. Its completely free, so the code for the compiler will be included and you can check out whether it fits your purposes.