Transformation of Applicative Specifications into Imperative ...

Transformation of Applicative Specifications into Imperative ... Transformation of Applicative Specifications into Imperative ...

26.09.2013 Views

APPENDIX F. SOURCE CODE System . e x i t ( 1 ) ; } try { + f i l e n a m e + " . r s l not found ! " ) ; System . out . p r i n t l n ( " S t a r t i n g : " + f i l e n a m e ) ; System . out . p r i n t l n ( " S t a r t i n g p a r s i n g " ) ; RSLLexer l e x e r = new RSLLexer ( f r ) ; RSLParser p a r s e r = new RSLParser ( l e x e r ) ; RSLAst a r s l a s t = p a r s e r . r s l a s t ( ) ; i f ( a r s l a s t == null ) { System . out . p r i n t l n ( " Tree not c r e a t e d ! " ) ; System . e x i t ( 1 ) ; } System . out . p r i n t l n ( "Ending p a r s i n g \n" ) ; try { StringRSLAstVisitor a r s l A s t V i s i t o r = new StringRSLAstVisitor ( ) ; a r s l a s t . accept ( a r s l A s t V i s i t o r ) ; } catch ( NullPointerException npe ) { System . out . p r i n t l n ( " Tree not c r e a t e d " + " c o r r e c t ! \ n" + "The RSL " + " s p e c i f i c a t i o n " + " i s not " + " within the " + " subset o f RSL" ) ; System . e x i t ( 1 ) ; } F i l e f i l e = new F i l e ( f i l e n a m e ) ; try { TRResult r e s u l t = TransformerRSL1 . TRRSLAst( a r s l a s t , newFilename , new TRANS( v a r i a b l e s ) ) ; i f ( r e s u l t instanceof RSLast_transformable ) { System . out . p r i n t l n ( " Transformable " ) ; 510

} F.1. RSLRUNNER RSLast_transformable r e s u l t a s t = ( RSLast_transformable ) r e s u l t ; RSLAst i r s l a s t = r e s u l t a s t . r e s u l t ( ) ; StringRSLAstVisitor i r s l A s t V i s i t o r = new StringRSLAstVisitor ( ) ; i r s l a s t . accept ( i r s l A s t V i s i t o r ) ; System . out . p r i n t l n ( "RSL: \ n" + i r s l A s t V i s i t o r . g e t R e s u l t ( ) ) ; System . out . p r i n t l n ( "Ending : " + f i l e n a m e ) ; try { i f ( f i l e . getParent ( ) ! = null ) { newFilename = f i l e . getParent ( ) + f i l e . s e p a r a t o r + newFilename ; } F i l e W r i t e r fw = new F i l e W r i t e r ( newFilename + " . r s l " , f a l s e ) ; fw . w r i t e ( "/∗" + DateFormat . getDateTimeInstance ( DateFormat . LONG, DateFormat . LONG, Locale .UK) . format (new Date ( ) ) + "∗/\n" ) ; fw . w r i t e ( i r s l A s t V i s i t o r . g e t R e s u l t ( ) . t o S t r i n g ( ) ) ; fw . f l u s h ( ) ; fw . c l o s e ( ) ; } catch ( IOException i o e ) { i o e . printStackTrace ( ) ; System . e x i t ( 1 ) ; } } else { System . out . p r i n t l n ( "The f i l e : " + f i l e n a m e + " . r s l cannot " + "be transformed " ) ; } 511

}<br />

F.1. RSLRUNNER<br />

RSLast_transformable r e s u l t a s t =<br />

( RSLast_transformable ) r e s u l t ;<br />

RSLAst i r s l a s t = r e s u l t a s t . r e s u l t ( ) ;<br />

StringRSLAstVisitor i r s l A s t V i s i t o r =<br />

new StringRSLAstVisitor ( ) ;<br />

i r s l a s t . accept ( i r s l A s t V i s i t o r ) ;<br />

System . out . p r i n t l n ( "RSL: \ n"<br />

+ i r s l A s t V i s i t o r .<br />

g e t R e s u l t ( ) ) ;<br />

System . out . p r i n t l n ( "Ending : " + f i l e n a m e ) ;<br />

try {<br />

i f ( f i l e . getParent ( ) ! = null ) {<br />

newFilename = f i l e . getParent ( )<br />

+ f i l e . s e p a r a t o r<br />

+ newFilename ;<br />

}<br />

F i l e W r i t e r fw =<br />

new F i l e W r i t e r ( newFilename<br />

+ " . r s l " , f a l s e ) ;<br />

fw . w r i t e ( "/∗"<br />

+ DateFormat .<br />

getDateTimeInstance ( DateFormat .<br />

LONG,<br />

DateFormat .<br />

LONG,<br />

Locale .UK) .<br />

format (new Date ( ) )<br />

+ "∗/\n" ) ;<br />

fw . w r i t e ( i r s l A s t V i s i t o r . g e t R e s u l t ( ) .<br />

t o S t r i n g ( ) ) ;<br />

fw . f l u s h ( ) ;<br />

fw . c l o s e ( ) ;<br />

}<br />

catch ( IOException i o e ) {<br />

i o e . printStackTrace ( ) ;<br />

System . e x i t ( 1 ) ;<br />

}<br />

}<br />

else {<br />

System . out . p r i n t l n ( "The f i l e : "<br />

+ f i l e n a m e<br />

+ " . r s l cannot "<br />

+ "be transformed " ) ;<br />

}<br />

511

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!