PL/0 Completed?
Brave words! Can it really be completed? There are still things I would like to add but I need to move on. The current state of play is:
- Recognises most PL/0 dialects.
- Tolerant to redundant ";"
- One dimensional arrays
- Pascal strings
To do:
Would like to add an ASM instruction (pass through to the target CPU).
Rework the error messages to provide better hints.
Here is an example program:
{ Program Test String }
var Str[16],Prompt[16];
procedure ReadStr;
var i,test;
{ Read a Pascal string, uses Str }
begin
i:=1;
test:=1;
while test=1 do begin
getc Str[i];
if Str[i]<32 then begin
Str:=i-1; { Str == Str[0] }
test:=0
end else begin
if i=16 then begin
test:=0;
Str:=i
end else begin
i:=i+1
end
end
end
end;
procedure WriteStr;
var i;
{ Write a string, uses Str }
begin
i:=1;
while i<=Str do begin
putc Str[i];
i:=i+1
end
end;
procedure WritePrompt;
var i;
{ Write Prompt }
begin
i:=1;
while i<=Prompt do begin
putc Prompt[i];
i:=i+1
end
end;
begin
Prompt:="String Test";
call WritePrompt;
putc 10; { new line }
Prompt:="Enter a string: ";
call WritePrompt;
call ReadStr;
Prompt:="You wrote: ";
call WritePrompt;
call WriteStr;
putc 10; { new line }
end.
You may notice I have used redundant ":" in this example.And here is the run:
C:\AlanX\pl0>.\PLZero_Tokeniser\PLZero_Tokeniser -i test18.pl0 -o test18.token -nl C:\AlanX\pl0>.\PLZero_Compiler\PLZero_Compiler -i test18.token -o test18.code -t test18.table C:\AlanX\pl0>.\PLZero_Interpreter\PLZero_Interpreter -i test18.code -o test18.run -s test18.stack String Test Enter a string: Hello World! You wrote: Hello World! C:\AlanX\pl0>pause Press any key to continue . . .
I think that is pretty cool!
Next
The next task is to write a P-Code to Subleq translator.
AlanX
agp.cooper
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.