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

Wayne Campbell asa.rand at gmail.com
Wed Dec 30 21:56:36 EST 2009


I was beginning with simply parsing an expression. I felt that if I could
accomplish this, the rest would be easier to figure out. The problem with
RUN is that it specifically launches a subroutine module (Basic09 I-Code or
6809 object code), passing to it whatever parameters are required. This
means that the eval() function , in the statement RUN eval(<string>), is a
subroutine that does whatever parsing is necessary to evaluate the
"expression". The parameter, in this case, would be the string to parse.

Wayne


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



>I don't understand where you are heading to with this. You would need more

>than an expression evaluator in order to program a server that can generate

>dynamic content. In JavaScript, for instance, the eval() function parses

>the string it is given as a parameter, looking for JavaScript code. If it

>finds any JavaScript code, it will be executed. If you want to simulate the

>same behaviour in BASIC09, you will end up writing a complete BASIC09

>interpreter on top of the underlying one, unless you find a way to inject

>an arbitrary string in the latter.

>

> Hint: Use RUN.

>

>

>

> Wayne Campbell wrote:

>> 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

>>

>>

>> --

>> Coco mailing list

>> Coco at maltedmedia.com

>> http://five.pairlist.net/mailman/listinfo/coco

>>

>

>

> --

> Coco mailing list

> Coco at maltedmedia.com

> http://five.pairlist.net/mailman/listinfo/coco





More information about the Coco mailing list