Faqts : Computers : Programming : Languages : Bbcbasic

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

BBCBASIC: Windows: Interpreter: Command: Line: How to create a simple command line interpreter? 1

Feb 1st, 2006 14:03
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 01 February 2021 - 07:21 pm -------------------
BBCBASIC: Windows: Interpreter: Command: Line: How to create a simple 
command line interpreter? 1
---
You can use a REPEAT UNTIL loop,
containing
 1. -Some input mechanism for commands
 2. -Zero or more IF or CASE test statements
     1. -If the inputted commands are recognized,
         do something (e.g. call a function or
         procedure)
===
In general
--- cut here: begin --------------------------------------------------
REPEAT
 PRINT "command = ";
 INPUT s$
 IF s$ = command1$ THEN PROCInterpreterRunCommand1( s$ )
 IF s$ = command2$ THEN PROCInterpreterRunCommand2( s$ )
 IF s$ = command3$ THEN PROCInterpreterRunCommand3( s$ )
 ...
 IF s$ = commandLast$ THEN PROCInterpreterRunCommandLast( s$ )
UNTIL quitB%
:
END
:
DEF PROCInterpreterRunCommand1( s$ )
 REM do something 1
ENDPROC
:
DEF PROCInterpreterRunCommand2( s$ )
 REM do something 2
ENDPROC
:
DEF PROCInterpreterRunCommand3( s$ )
 REM do something 3
ENDPROC
:
...
DEF PROCInterpreterRunCommandLast( s$ )
 REM do something last
ENDPROC
:
--- cut here: end ----------------------------------------------------
===
Steps: Overview:
 1. -Create e.g. the following program
--- cut here: begin --------------------------------------------------
quitB% = FALSE
:
REPEAT
 PRINT "command = ";
 INPUT s$
 IF s$ = "cls" THEN PROCInterpreterRunClearScreen( s$ )
 IF s$ = "beep" THEN PROCInterpreterRunBeep( s$ )
 IF s$ = "quit" THEN quitB% = TRUE
UNTIL quitB%
:
END
:
:
:
DEF PROCInterpreterRunClearScreen( s$ )
 CLS
ENDPROC
:
DEF PROCInterpreterRunBeep( s$ )
 VDU 7
ENDPROC
:
--- cut here: end ----------------------------------------------------
 2. -If you run this program it will ask for inputting a command
 3. -If this command is lower case cls, beep or quit
     it will do something (e.g. clear the screen)
---
---
Internet: see also:
---
BBCBASIC: Windows: Interpreter: Link: Overview: Can you give an 
overview of links?
http://www.faqts.com/knowledge_base/view.phtml/aid/39385/fid/768
----------------------------------------------------------------------