Oppolzer - Informatik / Stanford Pascal Compiler

Home       Lebenslauf       Schwerpunkte       Kenntnisse       Seminare       Kunden       Projekte       Produkte       Blog       Stanford Pascal       Kontakt

The Stanford Pascal Compiler / Evolution Steps

Back to Compiler main page

New keywords BREAK, CONTINUE, RETURN - still in 2011

The next extensions that I did - still in 2011 - was to add some new keywords and new instructions for loop control. This was inspired from my C experience, where I found those instructions very useful, and IMO they don't compromise the structured programming style (much).

And: they are very easy to implement, because all work can be done at the P-Code level.

To make things transparent: the Pascal compiler consists of two passes; the first one is considered to be portable across platforms (which is not true in detail), and it builds code for an abstract stack oriented machine. This code is called P-Code. This P-Code is then translated by the second pass (which is a Pascal program, too) to 370 object code (files with CMS filetype TEXT, RECFM fixed, record length 80).

The changes mentioned above are all done to the first pass; there are no extensions to the P-Code, so the second pass needs not to be touched. All three extensions (BREAK, CONTINUE, LEAVE) are in fact some branches (jumps) to some place inside or outside the loop or to a certain place at the end of a procedure or function. If a branch target at the needed position didn't yet exist in the P-Code, a new one had to be built.

These extensions were done within hours, and this gave me some confidence that I will be able to do further - and more ambitioned - extensions - in the future. But anyway it lasted 5 years before I started again to do significant work on this compiler project - until 2016.

Example for the RETURN statement:

procedure CHARSET_ADD ( var X : CHARSET ; VON : CHAR ; BIS : CHAR ) ; var CH : CHAR ; begin (* CHARSET_ADD *) for CH := VON to BIS do begin if CH = 'F' then RETURN ; X (. CH .) := 'J' end (* for *) end (* CHARSET_ADD *) ;

Example for BREAK and CONTINUE:

F := 'BERND ' ; for I := 1 to 6 do begin if F (. I .) = 'D' then BREAK ; if F (. I .) = 'E' then CONTINUE ; WRITELN ( 'FOR-SCHLEIFE: I = ' , I : 3 , ' F(I) = ' , F (. I .) ) ; end (* for *) ;

BREAK and CONTINUE work with all loop types, of course, that is: FOR loops, WHILE loops, and REPEAT ... UNTIL loops.

Back to Compiler main page