• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

The first R$ Application

Started by Charles Pegge, September 29, 2007, 11:00:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

R$ has now reached the stage of being able to do something useful. The program below is a simple console which allows any R$ expression or program to be executed.

It also records the session including each line entered and its result, storing the session in a log.txt file.

For good measure there are 2 machine coded functions sqrt and pi, and 3 program calls: info and mark.

To terminate the console there are 2 commands: bye and ".". Or Ctrl-C for a forced termination.

The programming process feels totally different to Basic, It works like a conveyor belt, variables are incidental and disappear as soon as you leave the block in which they were defined.

The script looks very strange but I found that the coding and debugging speed, for me at least, is about twice as fast as coding with infix notation. ( Making a comparison between $ and R$)


|
|   R$  POSTFIX LANGUAGE
|
|   Charles E V Pegge
|
|      28 Sept 2007


machine d9 eb dd 1f 41 c3 : pi

machine dd 06 d9 fa dd 1e c3 : sqrt


"" ?
"R$ Console " ?


"" : mysession
"" : result
13 chr ( 10 chr ) , : crlf

0 : a : b : c : d : e : f

(
"<>" getline : s

"." cmp if eq exit endif
"bye" cmp if eq exit endif
"test" cmp if eq then "tests.prg" load exec "" to s endif
"info" cmp if eq then "intrinsics.prg" load exec "" to s endif
"mark" cmp if eq then "markup.prg" load exec "" to s endif
if null then repeat endif

"  0 0 0 ((( " s , " str to result ? ))) end ' ))) end $ ))) end ", ' " ))) end  ' , exec
mysession
(
  " " 30 many "( " s , " )" , 1 patch
) ,
" |:  " , |:  ",
result ,
crlf ,
to mysession
repeat
)
mysession "log.txt" save
end


Petr Schreiber

Hi Charles,

where to get latest R$ ?
I now get this output:
Quote
machine  not found
d9  not found
eb  not found
dd  not found
c3  not found
machine  not found
dd  not found
d9  not found
fa  not found
dd  not found
c3  not found

R$ Console
<>

Maybe it would be nice to create sticky topic with always latest version of R$


Thanks,
Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Charles Pegge

Coming up Petr. There was a gang of boys playing 'Sponge Bob' on my PC but now that they been summoned for lunch, I have full charge of my PC again. (I cant create ZIPs on my Linux PC for some reason).

I think the sticky topic is a good idea, so I will ZIP the update replacing the original. I also have a word list, and word list generator program for automating the documentation, when further updated versions are posted.

Petr Schreiber

Hi,

I didn't know there is Sponge Bob game :)

Thanks for creating the sticky post, now it is OK and I start to get idea how it works.


Thanks,
Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

Charles Pegge


Sponge Bob is one of the better games, I have seen them playing. It is an animated cartoon about a sponge who lives on the sea bed, only he is a bathroom sponge. It has good plot lines, hardly any violence and is very witty.

One word of warning about the console: quotes in R$ have multiline scope so an unclosed quote will swallow up the rest of the console and dump you out. So I will have to add some protection against this in the console program.

Charles Pegge

#5
Protecting the console from rogue quote marks and right brackets etc

This is a simple though somewhat esoteric solution which I have added to the code above:

Instead of:

"0 " s , " str to result ? end ", exec

Do this:

"0 0 0 ((("  s, " str to result ? ))) end '  ))) end $ ))) end ", '" ))) end', exec

Which gives greater protection, but an important part of the development process will be to ruggedise the script engine itself, and develop a set of crash tests.


Charles Pegge

#6
After Subjecting the R$ console to the nastiest expresions, I could devise, I have added some more boundary checks to the script engine, so the updated version is a lot less vulnerable to coding errors.

The most lethal expression was this:

++++++++++++++++))))))))))))))))

an insult in any computer language, but particulary to RPN, driving the stack into reverse past its origin and causing a GPF. (One of the hazards of using Assembler without boundary checking).


This is now a sticky topic:

http://www.jose.it-berater.org/smfforum/index.php?topic=1326


Here are another 2 programs, which I am using to generate the BB markup with color highlighting of the intrinsics, for display in these postings. (intrinsics.prg and markup.prg in the ZIP file). The first proram generates the info.txt from the R$ BASIC source code, the second file uses this to gather a list of reserved words and then use this to identify and highlight each intrinsic. Comments are trimmed off before parsing and replaced, at the end of the line, with green highlighting.







|   R$  POSTFIX LANGUAGE
|
|   Charles E V Pegge
|
|   5-30 Sept 2007              |



|  Extract Info from R$ Source File |

(
  0 : tal
  13 chr ( 10 chr ) , : crlf
  "r$.bas" filein : fi
  "info.txt" fileout : fo
  (
   fi eof if true then exit endif
   "" : t
   0 : wrd
   fi in : s
   "##" 1 pos : co
   if gt then
    s 'w="' 1 pos to wrd

    if gt then
     3 + : n
     s '"' n pos : e
     if null then 20 to e endif
     s n e midl : t
     incr tal
    endif
   | (wrd if null then co ?? s ? endif)

    " " 100 many t 2 patch : ot
    s co 2 + 100 mid : oc
    ot oc 16 patch rtrim crlf ,
|    ??
    fo out
   endif
   repeat
  )
  crlf crlf ,
  "                Number of intrinsic commands/functions : " ,
   ? ? fo out
   tal str ? crlf , fo out
  fi close
  fo close
)

"marktable.prg" load exec

| "                Stacks: " ?? state @1 ?? @2 ?? @3 ?
end









|  Extract reserved words from info.txt
| and use them to markup an R$ program
| with bb tags

(
  13 chr ( 10 chr ) , : crlf
  "info.txt" filein : fi
  " " : lis
  (
   fi eof if true then exit endif
   fi in 1 16 midl ltrim rtrim
   if is then
    : w
    lis w , " " , to lis
   endif
   repeat
  )
  | lis ?
  fi close

  "File to markup for Forum posting- " getline ltrim rtrim : fni
  if null then ( "Default: " ? ? ) "main.prg" ? endif
  filein : fi
  if ne then
   "Unable to open or find  " fni , ?
   0 returns
  endif
  ( "Result in 'marked.txt'" ? )
  "marked.txt" fileout : fo
  91 chr : lb
  93 chr : rb
  124 chr : vb
  13 chr ( 10 chr ) , : crlf
  lb "color=teal" , rb , crlf , fo out
  (
   0 : m 0 : n
   fi eof if true then exit endif
   fi in
   ( len to m ) ltrim : s read
   ( len to n )
   ( m n - to m )
   " " m many fo out
   "" : co
   s vb 1 pos : cp
   if gt then
    s cp 200 mid : co
    lb "color=green" , rb , co , lb , "/color" , rb , to co
   endif
   (
    word if null then exit endif
    : w
    lis " " w , " " , 1 pos
    if true then
     lb "color=navy" , rb , w , lb , "/color" , rb , to w
    endif
    w 1 asc 34 cmp
    if eq
     lb "color=brown" , rb , w , lb , "/color" , rb , to w
    endif
    w 1 asc 39 cmp
    if eq
     lb "color=brown" , rb , w , lb , "/color" , rb , to w
    endif
    w " " ,
    fo out
    repeat
   )
   co crlf , fo out
   repeat
  )
  lb "/color" , rb , crlf , fo out
  fi close
  fo close
  "done" ?
)
end