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

Maximum length of string constants is now 254 (was 64)

Char arrays can be defined larger than 64 or even 254, of course. But before this extension, it was not possible to initialize char arrays larger than 64 to blank by simply assigning one blank (which IS possible for strings shorter than 64 since my extension concerning shorter string constants from september 2016). This is because the shorter string has to be extended internally to the corresponding target length, but that is (or was) not possible if the target length exceeds 64.

Of course, "true" string constants of length more than 64 were not very interesting in the past, because string constants were not allowed to span lines, and the lines are limited to 80 chars in the most common case.

So the first thing I did: I changed the source code scanner (INSYMBOL) in a way that it allowed for more than one string constant in sequence in place of one single string constant. So the Pascal programmer can simply terminate the string constant on one line and restart it on the next. See the following example:


program TESTLSTR ( OUTPUT ) ; (********) (*$A+ *) (********) var ZEILE : array [ 1 .. 200 ] of CHAR ; I : INTEGER ; begin (* HAUPTPROGRAMM *) ZEILE := 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' 'cccccccccccccccccccccccccccccccccccc' 'dddddddddddddddddddddddddddddddddddd' 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' ; WRITELN ( ZEILE ) ; MEMSET ( ADDR ( ZEILE ) , 'b' , 200 ) ; WRITELN ( ZEILE ) ; for I := 1 to 200 do ZEILE [ I ] := '=' ; WRITELN ( ZEILE ) ; end (* HAUPTPROGRAMM *) .

Of course, this didn't compile in the first place, because the resulting string and the target were both longer than 64. I changed the limit to 254 (which is a kind of arbitrary limit, but I believed that it would be better to stay below the MVC limit). The compiler had no problem, but the generated P-Code was not accepted by the P-Code translator, due to long string constants (on LCA/M and DFC instructions, as it turned out).

I changed the compiler, so that long string constants are split and written on several lines. Furthermore, I put a length field in front of the string constants; maybe later the string constant can be trimmed to the right, so that trailing blanks need not be written to the P-code file. The length field is optional; if it is not present (that is, there is a quote immediately following the comma), it works the same as before.

Here is an example of a long LCA/M instruction (from the example above):


LOC 16 LCA M,200,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'aaaaaabbbbbbbbbbbbbbbbbbbbbbbbb', 'bbbbbbbbbbbcccccccccccccccccccc', 'ccccccccccccccccdddddddddddddd', 'ddddddddddddddddddddddeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeee ', ' ' MOV 200

see the length information (200); the commas at the end (after the string constants) indicate that there is a continuation on the following line.

Of course, the P-Code translator (PASCAL2) had to be changed to accept this continuation, too.

Apart from those changes, there were no more changes necessary to the code generator. All worked well.

Back to Compiler main page