![]() |
The CONVECS team is pleased to announce that version 3.0 of the TRAIAN compiler for LOTOS NT is available.
During the last two years, TRAIAN has been entirely rewritten by Hubert Garavel, Frederic Lang, and Wendelin Serwe.
The main limitation of TRAIAN was that it was a 20-year- old compiler, which was increasingly difficult to maintain. TRAIAN was built using the FNC-2 compiler generation system, which was no longer supported. For this reason, TRAIAN only existed in 32-bit versions, and sometimes hit the 4 GB RAM limit when processing large compiler specifications, such as those of LNT2LOTOS or EVALUATOR 5.
Therefore, a major version TRAIAN 3.0 was developed, with three main design decisions: (i) getting rid of FNC-2; (ii) supporting (most of) the LOTOS NT features accepted by TRAIAN 2.9, also introducing some features belonging to LNT, to prepare a future convergence between LOTOS NT and LNT; (iii) writing TRAIAN 3.0 in LOTOS NT itself, so that the previous version 2.9 of TRAIAN can be used to build the next one (i.e., compiler bootstrapping).
The internal architecture of TRAIAN 3.0 is totally different from that of TRAIAN 2.9, whereas both compilers nearly have the same size of source code: 31,614 lines of code for TRAIAN 3.0 (72% of LNT code, 11% of SYNTAX code, and 17% of C code) vs 33,210 lines of code for TRAIAN 2.9 (85% of FNC2 code, 7% of SYNTAX code, and 8% of C code).
The lexer and parser of TRAIAN 3.0 have been developed using the SYNTAX compiler-generation system developed at INRIA Paris. This work triggered various enhancements of the programming interfaces of SYNTAX.
The abstract syntax tree of LOTOS NT, the library of predefined LOTOS NT types and functions, the static semantics checking (identifier binding, type checking, dataflow analysis, etc.), and the C code generation have been redesigned: previously specified as FNC-2 attribute grammars, in the functional style, they have been written in LOTOS NT, in the imperative style.
Test bases gathering thousands of correct and incorrect LOTOS NT programs (920,000 lines of LOTOS NT code in total) have been set up and systematically used for non-regression testing.
Compared to TRAIAN 2.9, TRAIAN 3.0 brings major enhancements:
Concerning its input, TRAIAN 3.0 remains largely compatible with TRAIAN 2.9, apart from a few changes detailed below.
Concerning its outputs, TRAIAN 3.0 takes great care to generate exactly the same C files as TRAIAN 2.9, except when changes are necessary to fix bugs and, sometimes, in presence of recursive data structures, for which TRAIAN 3.0 may generate the same C code as TRAIAN 2.9 but in a different order.
The TRAIAN manual page, the LOTOS NT user manual, the mode files for
the various editors, and the demo examples contained in the TRAIAN
distribution have been updated to reflect the changes brought to the
language and its compiler.
In TRAIAN 3.0, all keywords must be written in lower case (with an exception for six infix operators "and", "andthen", "implies", "or", "orelse", and "xor", which can also be written entirely in upper case, for backward compatibility reasons).
It becomes therefore possible for users to define identifiers such as "TYPE", "FUNCTION", etc.
Users may have to update their LOTOS NT programs to rename a few keywords written in upper case; in practice, this mostly concerns "NULL" and "ANY", which must now be written "null" and "any".
Similarly, the pragmas ("!implementedby", "!comparedby", "!pointer", "!external", etc.) must now be written in lower case exclusively.
For identifiers, the lower and upper cases are still considered to be equivalent in TRAIAN 3.0, but users are warned not to rely on such equivalence, which is likely to be removed in a future version of the compiler.
In TRAIAN 3.0, this set was restricted by removing the characters ".", "{", and "}", which are no longer allowed in special identifiers, removing several conflicts in the grammar. This also allows spaces between "." and "{" in the field update operator, whereas such spaces were forbidden by TRAIAN 2.9. Users may have to update their LOTOS NT programs that use these characters in special identifiers.
function F (, B:Bool) is ... function F (B:Bool) raises [ ] is ... function F (B:Bool) raises [ , X:none, Y:none] var in ... end var -- no variable declaration V.{V1, ..., Vn} -- meaningless field update, without "=>" function F is end function -- no function bodyTRAIAN 3.0 has a much stricter parser, which forbids all these questionable code fragments. In the latter example, an empty function must either have a "null" body or an "!external" pragma.
var X : T := E in ... end varwith
var X : T in X := E ; ... end var
function F (...) : ... raises [toolow:nat, zdiv:bool]From now on, all exceptions have to be declared with the special type "none", which means "no parameter".
trap exception X[:T] is ... in ...becomes
trap exception X is ... in ...
raise X (1.23)Only the syntax without parameters is now supported:
raise XNotice that TRAIAN 2.9 did not detect the situation where an exception declared with a parameter was raised without parameter, and generated incorrect C code in such case.
break L (1.23)or
break (false)but did not generate C code for this parameter.
TRAIAN 3.0 now distinguishes between "raise" and "break" instructions. Exception names and loop names now belong to two different name spaces, making it impossible to raise an exception using "break" or to break a loop using "raise". For instance, the following code fragment was accepted by TRAIAN 2.9 but is now rejected by TRAIAN 3.0.
function F() raises [X : none] is break X end functionUnfortunately, a few code fragments are valid for both TRAIAN 2.9 and TRAIAN 3.0, but yield different results:
function F (X : Nat) : Nat is trap exception E is return 1 in loop E in if X == 0 then raise E end if end loop; return 0 end trap end functionIndeed, the call F (0) returned 0 with TRAIAN 2.9 (since "raise E" breaks loop E) but now returns 1 with TRAIAN 3.0 (since "raise E" raises exception E).
type T is !implementedby "else" ... end type
!implementedby S1 !comparedby S2 !comparedby S3
With TRAIAN 3.0, the LOTOS NT grammar now forbids attaching pragma "!external" to constructors. Therefore, all the constructors of a type T will be external iff T is declared "!external". Users may have to update their LOTOS NT source files to remove "!external" pragmas for constructors.
trap exception EZ1 is return 1 in ...with an obscure error message
Unexpected natural or integer constant: expression of incorrect typeOne had to write
trap exception EZ1 is return 1 of Nat in ...to get the program accepted. This problem was solved in TRAIAN 3.0, which properly handles function overloading.
improper pointer/integer combination: op "=" assignment makes pointer from integer without a castand possibly causing crashes at run-time. This problem was solved in TRAIAN 3.0.
TRAIAN 3.0 implements a finer analysis and does not assume that an exception can be raised if all the constructors of T have a field X. In such case, TRAIAN 3.0 considers that the exception cannot occur and even raises a warning if a superfluous "raises" clause is present.
TRAIAN 3.0 can be freely downloaded from the TRAIAN Web Page located at: