[Coco] The Coco's first webserver, written in Basic09

Wayne Campbell asa.rand at gmail.com
Wed Dec 30 19:49:21 EST 2009


OK. I did a little. I really don't know what I'm doing here, but this is 
what I got for a start. There are many problems. First, Basic09's precedence 
ordering acts on the expression as follows:

2*3+5/2

is evaluated as

2*3/2+5, yielding a result of 8

To get the result of 5 (what we're looking for), it would have to be written 
as

(2*3+5)/2 (the remainder of 1 is dropped)

Because I am parsing the string "as I go", I am getting incorrect results. 
Not just 8 iunstead of 5, I am getting wierd numbers. It also does not 
account for numbers greater than 1 digit in length. Hopefully someone else 
can make the necessary corrections/modifications. I simply don't understand 
enough to do it right.

Wayne

PROCEDURE eval
DIM a,b,c,d,e,f:INTEGER
DIM mul,div,add,sub:BOOLEAN
DIM inputStr:STRING
a:=0 \b:=0 \c:=0 \d:=0 \e:=0 \f:=0
mul:=FALSE \div:=FALSE \add:=FALSE \sub:=FALSE
inputStr:="2*3+5/2"
REM a:=(2*3+5)/2
FOR b:=1 TO LEN(inputStr)
  IF MID$(inputStr,b,1)>="0" AND MID$(inputStr,b,1)<="9" THEN
    IF c=0 THEN
      c:=VAL(MID$(inputStr,b,1))
    ELSE IF d=0 THEN
      d:=VAL(MID$(inputStr,b,1))
      GOSUB 10
    ELSE IF e=0 THEN
      e:=VAL(MID$(inputStr,b,1))
      GOSUB 10
    ELSE IF f=0 THEN
      f:=VAL(MID$(inputStr,b,1))
      GOSUB 10
    ENDIF \ENDIF \ENDIF \ENDIF
  ELSE
    IF MID$(inputStr,b,1)="*" THEN
      mul:=TRUE
    ELSE IF MID$(inputStr,b,1)="/" THEN
      div:=TRUE
    ELSE IF MID$(inputStr,b,1)="+" THEN
      add:=TRUE
    ELSE IF MID$(inputStr,b,1)="-" THEN
      sub:=TRUE
    ENDIF \ENDIF \ENDIF \ENDIF
  ENDIF
NEXT b
PRINT a
END
10 IF mul THEN
  a:=a+c*d
  mul:=FALSE
ELSE IF div THEN
  a:=a/e
  div:=FALSE
ELSE IF add THEN
  a:=a+f
  add:=FALSE
ENDIF \ENDIF \ENDIF
RETURN

----- Original Message ----- 
From: "Christian Lesage" <hyperfrog at gmail.com>
To: "CoCoList for Color Computer Enthusiasts" <coco at maltedmedia.com>
Sent: Wednesday, December 30, 2009 7:44 AM
Subject: Re: [Coco] The Coco's first webserver, written in Basic09


> If BASIC09 has an EVAL statement (I can't remember), you could easily 
> program an ASP-like server. That would be pretty cool. I did that using 
> another BASIC-like language a few years ago. I started from scratch, and 
> the server was small, but good enough for small projects.
>
> Christian
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco 




More information about the Coco mailing list