The basic pretty printer

We define the basic pretty printer will be defined in the file: contrib/Exp/pprinters/basic/Exp-basic.ppml

The file name reflects the name of the formalism and the name of the pretty printer. Other files created by the Ppml compiler will be generated in this same directory, according to resource specifications. A pretty printer should be viewed not as a handful of files, but as a module that is loaded into Le-Lisp and that may be compiled for efficiency reasons.

Here, once again, is the Metal abstract syntax of Exp:


abstract syntax
   exp_s  -> EXP + ... ;
   assign  -> VAR EXP ;
   plus  -> EXP EXP ;
   minus  -> EXP EXP ;
   prod  -> EXP EXP ;
   uminus -> EXP ;
   variable  -> implemented as IDENTIFIER ;
   integer  -> implemented as INTEGER;

   EXP_S  ::= exp_s ;
   EXP  ::= assign plus minus prod uminus variable integer ;
   VAR  ::= variable ;
   INTEGER  ::= integer ;

and here is a proposed first shot at the basic printer:


prettyprinter basic of Exp is
   
rules
  *x !0 -> [<h> "..."] ;
   
  exp_s(**exps,*exp)  -> [<v 0,0> ([<h 0> **exps ";"]) *exp] ;
   
  plus(*exp1, *exp2)  -> [<hv 1,2,0> *exp1  "+" *exp2] ;
  minus(*exp1, *exp2) -> [<hv 1,2,0> *exp1  "-" *exp2] ;
  prod(*exp1, *exp2)  -> [<hv 1,2,0> *exp1  "*" *exp2] ; 
   
  uminus(*exp)        -> [<h 0> "-" *exp] ;      
   
  assign(*var, *exp2) -> [<hv 1,2,0> *var ":=" *exp2] ;
end prettyprinter
Note that:



Tutorial