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

C++ style comments

Compiler version: 10.2017

What I like about C++ style comments: they need not be terminated, that is: you can start them by two slashes and they terminate automatically at the end of the line.

In my money job, I am coding in C and PL/1 most of the time, and the C compilers today most often have a compiler option that allows C++ style comments on C programs, too, and this is used by me and my co-workers all the time.

The new scanner PASSCAN was introduced with the idea in mind, that C++ style comments should be possible in Stanford Pascal, too.

When I started working on the details, I soon discovered that it would be better to let the scanner only handle the comment starting symbol and to do the other comment handling manually. Well, that's not quite right: the comment handling is done by hand-written logic, but inside the skeleton which is used by the scanner generator, so it is generated logic, too - after all.

Here you have some relevant parts of PASSCAN.PAS:


begin SCB . SYMBOL [ SCB . LSYMBOL ] := ' ' ; SCB . LSYMBOL := SCB . LSYMBOL - 1 ; SCANNER2 ( ALTZUST , SCB ) ; case SCB . SYMBOLNR of COMMENT1 : COMMENT ( SCANINP , SCANOUT , SCB , 1 ) ; COMMENT2 : COMMENT ( SCANINP , SCANOUT , SCB , 2 ) ; COMMENT3 : COMMENT ( SCANINP , SCANOUT , SCB , 3 ) ; COMMENT4 : COMMENT ( SCANINP , SCANOUT , SCB , 4 ) ; COMMENT5 : COMMENT ( SCANINP , SCANOUT , SCB , 5 ) ; otherwise end (* case *) end (* else *)

this is just after the finite state machine, which is at the core of the scanner procedure, has terminated. The final state (German: Endzustand) is in the variable ALTZUST, and the procedure SCANNER2 computes the SYMBOLNR from the ALTZUST. If the SYMBOLNR is one of the five comment starting symbols, the routine COMMENT is called, which reads characters from the source program until the comment terminates.

Of course, the routine COMMENT has to take care of line ends, "page full" conditions, and: comments may be nested, so there are recursive calls of COMMENT, too. For more detail, you may look at the source of PASSCAN.

COMMENT type 5 is the new C++ style comment.

Here an example:


program TESTXB ( OUTPUT ) ; //********************************************************** //$A+ // // Testprogramm fuer hexadezimale und binaere Codierung // von Integers und Strings // //********************************************************** const CC = 'A' ; CHEX = X'67' ; CSET = [ 'a' .. 'e' ] ; CSETHEX = [ 'a' .. X'66' ] ; // hier Problem bei IBM //**************************************************** //* verschiedene tests, z.B. wird diese konstante //* csethex auf IBM nicht funktionieren, da 'a' schon //* groesser ist als x'66' //**************************************************** type SET_CHAR = set of CHAR ; ALPHA = array [ 1 .. 20 ] of CHAR ; var C : CHAR ; S1 : SET_CHAR ; S2 : SET_CHAR ; S3 : SET_CHAR ; S4 : SET_CHAR ; S5 : SET_CHAR ; S6 : SET_CHAR ; I : INTEGER ; testf : text ;

Problem with PASFORM

At the moment, the source program formatter PASFORM does not work with C++ style comments !!

I would like to rework PASFORM in such a way, that is uses the scanner PASSCAN, too; this way solving all the problems that PASFORM currently has (no good reaction on syntax errors etc.). And, of course, the new version of PASFORM will handle C++ comments correctly.

Back to Compiler main page