aldweb

Close I. aldweb

Close II. PC Freeware

Close III. Palm Freeware

Close IV. Palm Shareware

Close V. iziBasic Palm

Close VI. Palm Knowledge

Close VII. Pocket Computer

Close VIII. miniPortail

Special !



Mobile version of
the aldweb Site

m.aldweb.com


Neither French, nor English?

Try one of these flags then:
[de] [es] [it] [pt]
Search




Weather / Spam / www

Lyon Weather


aldweb against spam


Newsletter
To receive news about this website, consider subscribing to our Newsletter.
Subscribe
Unsubscribe
298 Subscribers
Family's web sites

Webmaster - Infos
Friends News
Visits

   visitors

   visitors online

Poll
What do you think of the new design of the aldweb Site?
 
Great !
Beautiful
Average
So ugly...
Results
forum.gifForum - iziBasic - Topic #1466

Forum - Forum
iziBasic - iziBasic


Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257

active  Topic # 1466  wish - improving the parser a bit

19/10/2006 @ 09:44
by Dave O\'Brien

Anonymous



I realize that iziBasic may never have a parser as sophisticated as desktop implementations, but I'd like to suggest a few improvements that should simplify programming for everyone (except aldweb, of course ;)


SELECT CASE variable arguments:

The SELECT CASE statement doesn't seem to accept variables for the individual cases. For example, it throws a syntax error for "foobar" below:

SELECT CASE %c1%
CASE -1
UPDATETEXT #%counter%, "*"
CASE %foobar%
UPDATETEXT #%counter%, "f"
(etc.)

...which means I have to replace %foobar% with a literal value, which makes my program break if I ever change the value of %foobar% elsewhere.


Referencing arrays in IF statements:

I just started using the built-in array A(n), but ran into puzzling syntax errors with this code:

FOR %counter% = 1 TO 100
IF a(%counter%) = 0 THEN
' do something
ENDIF
NEXT

Turns out that it didn't like an array reference in the IF statement. I had to copy the array reference to a non-array variable (e.g. %foobar%) and then test %foobar%. That makes the code a bit awkward.

Hey, while I'm wishing, there's always multi-dimensional arrays. I'd be very happy to be able to write a(x,y) for the mine-sweeper game I'm working on.

Hey, it's Christmas soon, right? ;D
  Post an answer  Top

[]   


Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 1
--------
19/10/2006 @ 18:50
by aldweb

Anonymous

visitor
Hello Dave,

All suggestions are highly appreciated. I got so much used to using iziBasic as it is that I sometimes/often need to be told back its limits!

The SELECT CASE statement doesn't seem to accept variables for the individual cases.
No, indeed it does not.
This is a good suggestion, I don't remember why SELECT is restricted this way. I'll have to give a look back to this part of the compiler.
You may nevertheless use imbricated IFs for solving this issue (but the code is not so nice looking as with a SELECT sequence).

Referencing arrays in IF statements
... and all other statements as well should I add!
This is because I chose to implement arrays like functions, and functions cannot be put in statements other than the LET statement (itself being facultative) in iziBasic. This was much quicker to develop for me...

Hey, while I'm wishing, there's always multi-dimensional arrays.
I know, this would really avoid translating indexes in a 1 dimension array, which is a pain I have to acknowledge it!

Hey, it's Christmas soon, right?
Do you still believe in Santa Claus?

Cheers,
aldweb
Write to aldweb   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 2
--------
19/10/2006 @ 18:57
by aldweb

Anonymous

visitor
improving the parser a bit

To be very honest with you, it would not only be a bit of improvement dear Dave!
At this stage, I would have to hack it so much to have your requests implemented that it would maybe be much wiser to redesign it from scratch with all the learnings I got from this experience of developping my first real compiler parser.
This is something that has been in my head for one year now...

Cheers,
aldweb
Write to aldweb   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 3
--------
19/10/2006 @ 20:38
by Dave O\'Brien

Anonymous

visitor
Yes, I figured these improvements might be non-trivial, esp. the arrays.

I wonder if there are open-source parsers that you could examine or even borrow code from? That might save some effort and be quite educational too. I never had the courage to take a compiler course myself, mind you. :^)
  Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 4
--------
20/10/2006 @ 17:19
by aldweb

Anonymous

visitor
Hello Dave,

I did not examine in depth some open-source parser. Programming is a hobby for me and I love to find by myself some algorythms. I had no compiler course either, developing a byte-code compiler was a great challenge for me, and this is why I really wanted when starting this iziBasic project from scratch.
Copy & Paste is another thing... maybe a job?


Now, to come back to your original requests, here are the workarounds for them.


SELECT CASE variable arguments
IF %c1% = - 1 THEN
' do something
ELSE IF %c1% = %foobar% THEN
' do something
ELSE IF (etc.)
' do something
ENDIF
ENDIF
ENDIF (whatever the number required)



Referencing arrays in IF statements
FOR %counter% = 1 TO 100
b=a(%counter%) : IF b = 0 THEN
' do something
ENDIF
NEXT



multi-dimensional arrays
Here the principle is to use the trick of translating a multi-dimensional array to a mono-dimensional array.
Then, use the provided Dim2.iBas include file provided in the iziBasic package. And code something like:
' IBDim2.iBas

' IBDim2 is a simple application
' to show how to deal with 2
' dimensions arrays in iziBasic,
' like Array(10,5), when iziBasic
' "only" offers access to the A(n)
' array (1 dimension).

{CREATORID "LDTE"}
{VERSION "1.0"}
{PARSER ON}

{INCLUDE "Dim2.iBas"}

BEGIN
'Store some values in A(10,5)
FOR I=1 TO 10
FOR J=1 TO 5
V=(RND(I)+1)*(RND(J)+1)
GOSUB _PutInArray 'A(I,J)=V
NEXT
NEXT
'Retrieve and show values in A(10,5)
FOR I=1 TO 10
FOR J=1 TO 5
GOSUB _GetFromArray 'V=A(I,J)
PRINT V USING 0;
PRINT " ";
NEXT
PRINT
NEXT
WAIT
END



These are only workarounds while waiting for a potential Christmas gift. But they still get the required job done!


Cheers,
aldweb
Write to aldweb   Post an answer  Top
active topic active   closed topic closed   Sticky Sticky   New New message   -   Correct Correct message   Close Close topic   Make sticky Make sticky
[]
Forum Topic  Forum 



 
^ Top ^