Code archives/Algorithms/Simple Compiler
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
A very simple compiler, with 2 commands. | |||||
Function compLine(file, command$) firstspace=Instr(command," ",1) If firstspace <> 0 func$=Left(command$,firstspace-1) params$=Mid$(command$,firstspace+1) Else func$ = command$ EndIf Select func$ Case "print" WriteByte(file, 1) WriteString(file, params$) Case "read" WriteByte(file, 2) WriteString(file, params$) End Select End Function Function ExecFile(file) While Not Eof(file) opcode = ReadByte(file) Select opcode Case 1 Print ReadString$(file) Case 2 gur$ = ReadString$(file) If FileType(gur$) = 1 redfile = ReadFile(gur$) While Not Eof(redfile) Print ReadLine(redfile) Wend CloseFile(redfile) Else Print "File not found!" EndIf End Select Wend End Function |
Comments
| ||
This would be considered an interpreter because you are not able to build the source code into an executable. |
| ||
Yep, that's an interpreter if I've ever seen one... Nice job there! :) Heres one I wrote donkeys ago:- http://www.blitzbasic.com/codearcs/codearcs.php?code=1542 I had a little mini hobby writing small interpreters, though that one above was my very first... Bless its cotton socks! :) Dabz |
Code Archives Forum