Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / loglan96 / loglan93 / instr.h
1 //****************************************************************
2 //*                                                              *
3 //*    Instr.h : Header file for the object class hierarchy for  *
4 //*              the instructions.                               *
5 //*                                                              *
6 //* (c) LITA, university of PAU (France), summer 1993.           *
7 //****************************************************************
8
9 //***************************************
10 //**                                   **
11 //**  Objects decribing an instruction **
12 //**  inside an abstract tree.         **
13 //**                                   **
14 //***************************************
15
16 /*
17                         Instruction
18
19              Single_Instruction                Complex_Instruction
20
21
22                            Single_Instruction
23
24  :=       job        io       signal        control      object
25
26         Attach      Put       Raise         Return       Wind  
27         Resume      Get                     Call         Inner
28         Stop        Read                    Exit         Kill
29         Detach      ReadLn                               Generator
30         Terminate   Write
31                     WriteLn
32
33
34                            Complex_instructions
35
36    Loop                         Block                  Condition
37
38    For                        Pref Block               If
39    While                                               Case
40 */
41
42 class Instruction
43 {
44   public:
45   String kind;
46   Location *place;
47
48   Instruction( String TheStr, Location *TheLoc ) :
49   kind( TheStr ), place( TheLoc )
50   {}
51
52   virtual void Print( ostream& );
53
54   friend ostream& operator << ( ostream& , Instruction );
55 } ;
56
57 class OneArgInstr : public Instruction
58 {
59   public:
60   Expression *argument;
61
62   OneArgInstr( Expression * , String, Location * );
63   virtual void Print( ostream& );
64 } ;
65
66 class TwoArgInstr : public Instruction
67 {
68   public:
69   Expression *arg1,*arg2;
70
71   TwoArgInstr( Expression *, Expression *, String, Location *);
72   virtual void Print( ostream& );
73 } ;
74
75 class Affectation : public TwoArgInstr
76 {
77   public:
78   Affectation( Expression *, Expression * );
79   void Print( ostream& );
80 } ;
81
82 typedef enum
83 {
84   AttachInstr,
85   ResumeInstr,
86   StopInstr
87 } OneArgJob;
88
89 class Attach : public OneArgInstr
90 {
91   public:
92   Attach( Expression *, Location * );
93 } ;
94
95 class Resume : public OneArgInstr
96 {
97   public:
98   Resume( Expression *, Location * );
99 } ;
100
101 class Detach : public Instruction
102 {
103   public:
104   Detach( Location *TheLoc ) : Instruction( String( "Detach" ), TheLoc ) {}
105 } ;
106
107 class Terminate : public Instruction
108 {
109   public:
110   Terminate( Location *TheLoc ) : Instruction( String( "Terminate" ), TheLoc ) {}
111 } ;
112
113 class Stop : public OneArgInstr
114 {
115   public:
116   Stop( Expression *, Location * );
117   Stop( Location * );
118   void Print( ostream& );
119 } ;
120
121 //**
122 //** These class describes the I/O instructions of LOGLAN
123 //**
124 //** Each Instruction taking a variable argument number
125 //** for example "writeln( output,a,b )"
126 //** is simplified into the following Instructions :
127 //**   write( output, a );
128 //**   write( output, b );
129 //**   writeln( output );
130 //**
131
132 class Read : public OneArgInstr
133 {
134   public:
135   Read( Expression *, Location * );
136 } ;
137
138 class Readln : public Instruction
139 {
140   public:
141   Readln( Location * );
142 } ;
143
144 class Write : public OneArgInstr
145 {
146   public:
147   Write( Expression *, Location * );
148 } ;
149
150 class Writeln : public Instruction
151 {
152   public:
153   Writeln( Location * );
154 } ;
155
156 class Get : public OneArgInstr
157 {
158   public:
159   Expression *TheFile, *TheArg;
160   Get( Expression *, Location * );
161 } ;
162
163 class Put : public OneArgInstr
164 {
165   public:
166   Expression *TheFile, *TheArg;
167   Put( Expression *, Location * );
168 } ;
169
170 //**
171 //** This is the only Instruction concerning signals.
172 //**
173
174 class Raise : public OneArgInstr
175 {
176   public:
177   Raise( Expression *TheExpr, Location *TheLoc ) :
178        OneArgInstr( TheExpr, String("Raise"), TheLoc ) {}
179 } ;
180
181 //**
182 //**  Class container for a set of Instructions. We call it a block.
183 //**  Tool class for containing several instructions and manipulate them.
184 //**
185
186 class ListOfInstr
187 {
188   Instruction *Instruct;
189   ListOfInstr *NextInst;
190   public:
191   friend ListOfInstr& operator += ( ListOfInstr& , Instruction * );
192   ListOfInstr( Instruction *TheInstr );
193   void Print( ostream& );
194 } ;
195
196 class Block : public Instruction
197 {
198   ListOfInstr InstrList;
199   public:
200   Block( Instruction *FirstInstr, Location *TheLoc );
201   friend Block& operator += ( Block& TheBlock, Instruction *TheInstr );
202   void Print( ostream& );
203 } ;
204
205 //**
206 //** Class conditionnal If : A class with 2 Blocks conditionnaly executed.
207 //**
208
209 class ConditionIf : public Instruction
210 {
211   Block      *BlockThen, *BlockElse;
212   Expression *Condition;
213   public:
214   ConditionIf( Expression *, Block *, Block *, Location * );
215   void Print( ostream & );
216 } ;
217
218 //**
219 //** Class Loop : A class for hanling loop construction
220 //**
221
222 class Loop : public Instruction
223 {
224   Block *Body;
225   public:
226   Loop( Block *TheBlock, String TheName ) :
227       Instruction( TheName, TheBlock->place ), Body( TheBlock ) {};
228   void Print( ostream& );
229 } ;
230
231 class While : public Loop
232 {
233   Expression *Condition;
234   public:
235   While( Expression *, Block *, Location * );
236   void Print( ostream& );
237 } ;
238
239 class For : public Loop
240 {
241   Expression *Counter;
242   Expression *CounterInit;
243   Expression *CounterStop;
244   Expression *CounterStep;
245   public:
246   For( Expression *,Expression *, Expression *, Expression *, Block *,Location * );
247   void Print( ostream& );
248 } ;