4. Examples

These three examples are supposed to be an introduction to classgen. You can load a vcg-generated diagram representation and download the examples.

Expression

A typical example for an abstract syntax tree representing an expression.
download | view

package sample1;

attribute "int"      evalResult      with Expression;
attribute "boolean"  calculated      with Expression;

Expression  ::= {IntegerConstant} "int":value
              | {BinaryExpression} Expression:lhs "int":op Expression:rhs
              
Operator    ::= enum PLUS, MINUS, MULT

Compiler design

An example taken from the compiler design course at TUM.
download | view

package sample2;

attr "boolean" istvarParam, istformParam with Dekl;
attr DeklInfo deklinfo with Id_Seq, Var;

Prog ::= "String":ident  Proc_Dekl_Seq  Block


Proc_Dekl_Seq ::= Proc_Dekl Proc_Dekl_Seq
                | /* leere Sequenz */

Proc_Dekl     ::= "String":ident Form_Par_Seq Block

Form_Par_Seq ::= Form_Par Form_Par_Seq
               | /* leere Sequenz */

Form_Par     ::= { Param }     Var_Dekl
               |  { Var_Param } Var_Dekl
             
Var_Dekl     ::= { Variable }  Typ  Id_Seq:id_Seq
               |  { Array_Variable } "int":laenge Typ Id_Seq:id_Seq

Typ      ::=    "int":typ  
              
Block    ::= Dekl_Seq  Anw_Seq

Dekl_Seq ::= Dekl Dekl_Seq
           | /* leere Sequenz */

Dekl     ::= { Var_Dekl }   
           

Id_Seq   ::= "String":ident Id_Seq
           | "String":ident 
          

Anw_Seq ::= Anw Anw_Seq
          | Anw

Anw     ::= Ausdr   


Ausdr     ::= {BinAusdr}  Ausdr "int":op Ausdr
            | {IntAusdr}  "int":value
            | {VarAusdr}  Var

Var        ::= {IdentAusdr}   "String":ident
            |  {ArrayAusdr}   "String":ident Ausdr:index

Layout

This example describe classes that are commonly uses in box-glue layout algorithms.
download | view

package sample3;

/* Aus dem PP WS 99 WS 99 */

attr "int" boxWidth, boxHeight, boxDepth with Box, ItemList;
attr "int" actual with Item;
attr "boolean" inHBox with ItemList;
attr "int" requSize with ItemList;


Page		::= Box:content
Box			::= {HBox}
			    "int"    :requestedWidth
			    ItemList :content
		  	  | {VBox}
			    "int"    :requestedHeight HAlignment:halign
			    ItemList :content
		  	  | {EmptyBox}
			    "int" :width  "int" :height  "int" :depth
			  | {Rule}
			     "int":width  "int" :height  "int" :depth
		  	  | {TextBox}
			    String:text   "java.awt.Font" :font

ItemList	::= Item*

Item		::= {Glue}
			    "int" :natural  "int" :plus  "int" :minus
		  	  | {BoxItem} 
			    Box   :box

HAlignment	::= {Left} | {HCenter} | {Right} 



© copyright 2000, 2001, 2002 Sebastian Winter (winterse@in.tum.de) and Florian Deissenboeck (flo@deissenboeck.de)

© copyright 2000, 2001, 2002 Technical University of Munich, Germany