Post by Tom Mulgrew on Jul 11, 2010 19:34:43 GMT -5
I'd like your opinion on a proposed new language syntax for Basic4GL. This would be enabled by a "language traditional_suffix" compiler directive at the top, or by a "default language" setting that can be set from the options menu.
The intention is to change a few things about the syntax to make it more similar to other BASIC dialects.
Here's an example (from the "do not fear the vector" tutorial on the Wiki):
In the example none of the OpenGL commands return any value, so they don't require brackets around their parameters. However SyncTimer, KeyDown, ScanKeyDown, MatrixRotateY etc all return values, and so must have their parameters surrounded by brackets.
(The reasoning is so that the compiler knows what to do with expressions like "sqrt 5 + 3". Without brackets, it doesn't know if you meant "sqrt(5 + 3) or sqrt(5) + 3).
With this syntax you can also write:
Instead of:
But I'm wondering if the rules are a little too complicated for a "Basic" language.
The alternatives would be:
I'm keen to hear what you all think.
-Tom
The intention is to change a few things about the syntax to make it more similar to other BASIC dialects.
Here's an example (from the "do not fear the vector" tutorial on the Wiki):
language traditional_suffix
' Data
dim cam(2), camAng, camXAng, offset(2) ' Camera position and direction
dim x as integer, z as integer ' Working variables
cam(0) = 135
cam(2) = 50
' Main loop
while true
' Clear screen
glClear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
glLoadIdentity
' Position camera
glRotatef -camXAng, 1, 0, 0: glRotatef -camAng, 0, 1, 0
glTranslatef -cam(0), -cam(1), -cam(2)
' Draw a city of pyramids
for z = 1 to 10
glPushMatrix
for x = 1 to 10
glBegin GL_TRIANGLE_FAN
glColor3f 0,.5, 1: glVertex3f 0, 10, 0
glColor3f 1, 0, 0: glVertex3f -10,-10, 10
glColor3f 1, 1, 1: glVertex3f 10,-10, 10
glColor3f 0, 0, 1: glVertex3f 10,-10,-10
glColor3f 0, 1, 0: glVertex3f -10,-10,-10
glColor3f 1, 0, 0: glVertex3f -10,-10, 10
glEnd
glTranslatef 30, 0, 0
next
glPopMatrix
glTranslatef 0, 0, -30
next
SwapBuffers
' Move camera
while SyncTimer(10)
if ScanKeyDown(VK_LEFT) then camAng = camAng + 1
if ScanKeyDown(VK_RIGHT) then camAng = camAng - 1
if ScanKeyDown(VK_UP) then camXAng = camXAng + 1
if ScanKeyDown(VK_DOWN) then camXAng = camXAng - 1
offset = vec3(0, 0, 0)
if KeyDown("W") then offset(2) = offset(2) - 1
if KeyDown("S") then offset(2) = offset(2) + 1
if KeyDown("A") then offset(0) = offset(0) - 1
if KeyDown("D") then offset(0) = offset(0) + 1
cam = cam + MatrixRotateY(camAng) * MatrixRotateX(camXAng) * offset *.5
wend
wend
The main differences between default Basic4GL syntax:- Variables are floating point by default, unless suffixed with '%' or "as integer". (# suffix is still available).
- Brackets are only required when calling functions that have parameters and return a value.
- Shorthand support for "if" "then" statements. If the "then" part is supplied on the same line, then the "endif" can be omitted.
In the example none of the OpenGL commands return any value, so they don't require brackets around their parameters. However SyncTimer, KeyDown, ScanKeyDown, MatrixRotateY etc all return values, and so must have their parameters surrounded by brackets.
(The reasoning is so that the compiler knows what to do with expressions like "sqrt 5 + 3". Without brackets, it doesn't know if you meant "sqrt(5 + 3) or sqrt(5) + 3).
With this syntax you can also write:
dim dice% = rnd % 6 + 1
Instead of:
dim dice% = rnd() % 6 + 1
But I'm wondering if the rules are a little too complicated for a "Basic" language.
The alternatives would be:
- Always require brackets
- Require brackets for all functions that return a value
I'm keen to hear what you all think.
-Tom