Skip to main content
gamedev.net
🔒 Locked

BASIC and language specification

Started by Max_Payne May 5, 2004 at 1:16 PM 5 replies 450+ views
Original Post
Max_Payne
Max_Payne
Does anyone know where I could get an actual spefication for the BASIC language (or some more evolved form of BASIC, excluding QBasic). I am asking this because I would like to implement a compiler for my VM, and I thought that I should start with a simple language. I already have an ASM compiler working, which is quite simplistic, but programming in it is a Payne.

Looking for a serious game project?
www.xgameproject.com

Looking for a serious game project?
www.xgameproject.com
teamonkey
teamonkey
Why not make up your own derivative language from what you already know about BASIC?
[teamonkey] [blog] [tinyminions]
Max_Payne
Max_Payne
quote:
Original post by teamonkey
Why not make up your own derivative language from what you already know about BASIC?


Probably because it would end up looking too much like C/C++ I was also hoping to find infos on how to simplify the parsing...

Anyhow, I suppose I can do the exercise, and you can give me feedback, the requirements I am looking for are:

1. No line numbers
2. Named labels
3. Conditional branching
4. Sub-routine calls

I suppose the best way to ease the parsing is sort of, to prefix each line with something... And let expressions take up one line only. So an example program could look somewhat like:


// Declare an integer for the age

int age

// Input the dude''s age

print "enter your age"
input age

// Test if the age is over 18

if age > 18
print "You are an adult"
else
print "You are not an adult"
endif

// End this program

end


Labels could begin with "label", assignments and calculations with "let", and other keywords should always be at the line start.

Looking for a serious game project?
www.xgameproject.com
Puzzler183
Puzzler183
I would guess that C is easier to parse than basic. Semi-colons end every lines, braces indicate code blocks, etc. It''s much more well formed, in my opinion.

And besides, if C++ is your language, you''ll have a better time coding in your scripting language that way.

NOTE: Do NOT try to make a C(++) clone, you will probably fail.
merlin9x9
merlin9x9
Maybe try B. It''s even simpler than C.
(No, this is not a joke.)
PeterTarkus
PeterTarkus
I don''t think there is a BASIC standard description, as everyone sort of takes the basics (snicker) and implements there own way of doing things.

DIM dimensions vars
var$ is a string
var# is a double
var() is an array

if expr then statements
else if ...
else ...
endif

for var = (number) to (number) [STEP number]
statements
next var

while(expr)
statements
wend

statement : statement : statment for multiple line statements.

a label is identifed by a colon: LABEL:

gosub _label; is the old school way of calling functions
goto LABEL; JMP to label

_label:
statements ...


If you want to get a feel for a modern basic look at Basic4GL it is a nice implementation and pretty much a modern basic. Also check out the source code lots of goodies in there :-) I love that program it''s great :-)

Or of course play around with VB and steal it''s syntax :-) Old school VB, not vb.net which is a total destruction of everything VB was once good for.

The only thing really hard about basic is it has about a zillion built in functions and keywords so you have to spend alot of time implementing them all into it. In comparison C has very little built in keywords but it has a lot of operator precedences which are hard to work out. Basic is really simple to build your own parser by hand, C is too hard you need Yacc or some tool to do it. You could probably build one by hand but the parsers become to complicated to understand after a while and full of a zillion hacks.

Good luck!
iMalc
iMalc
quote:
Original post by Puzzler183
I would guess that C is easier to parse than basic.


Hahahaha, yeah good one. I needed a good laugh.
Your guess couldn''t be any more wrong.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/vbSpecStart.asp
... should be more than you need to know.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.