Added upstream from http://ftp.icm.edu.pl/pub/loglan/
[loglan.git] / sources / pass1 / ml3.c
1      /* Loglan82 Compiler&Interpreter
2      Copyright (C) 1981-1993 Institute of Informatics, University of Warsaw
3      Copyright (C)  1993, 1994 LITA, Pau
4      
5      This program is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published by
7      the Free Software Foundation; either version 2 of the License, or
8      (at your option) any later version.
9      
10      This program is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13      GNU General Public License for more details.
14      
15
16 =======================================================================
17 */
18
19 #include <stdio.h>
20
21 #if WSIZE==4
22         typedef long word;
23 #elif WSIZE==2
24         typedef short word;
25 #else
26  Define WSIZE to 2 or 4 !
27 #endif
28
29 extern FILE *file_arr[];
30
31
32 #ifndef NO_PROTOTYPES
33 static char *find_msg( int );
34 #else
35 static char *find_msg();
36 #endif
37
38
39 void listing_error_line__( lun, line, nr, errno, nameid )
40    word *lun,*line,*nr,*errno;
41    char *nameid;
42 {
43    FILE *f=stdout;
44    if( *lun != 0L )  f=file_arr[*lun];
45    fprintf(f,"*** %6d ERROR %6d %s %8.8s\n",(int)(*line),(int)(*nr),find_msg((int)(*errno)),nameid);
46 }
47
48
49
50 static char declaration_part_overloaded[]={"***DECLARATION PART OVERLOADED"};
51 static char class_identifier_expected[]={"CLASS IDENTIFIER  EXPECTED"};
52 static char null_program[]={"NULL PROGRAM"};
53 static char too_many_prototypes[]={"***TOO MANY PROTOTYPES"};
54 static char undeclared_identifier[]={"UNDECLARED IDENTIFIER"};
55 static char diff_lengths[]={"DIFFERENT LENGTHS OF THE 2ND PARAMETERS LISTS"};
56 static char incompat_kinds[]={"INCOMPATIBLE KINDS OF THE 2ND LEVEL PARAMETERS"};
57
58
59 static struct { int errno; char *errmsg; }  err_tab[]={
60
61 {   0,declaration_part_overloaded       },
62 {  10,"***TOO MANY ERRORS"      },
63 {  41,declaration_part_overloaded       },
64 { 101,"\":=\"  EXPECTED"        },
65 { 102,"\";\"  EXPECTED" },
66 { 103,"\"THEN\"  EXPECTED"      },
67 { 104,"\"FI\"/\"ELSE\"  EXPECTED"       },
68 { 105,"\"OD\"  EXPECTED"        },
69 { 106,"\"(\"  EXPECTED" },
70 { 107,"\")\"  EXPECTED" },
71 { 108,"\"DO\"  EXPECTED"        },
72 { 109,"IDENTIFIER  EXPECTED"    },
73 { 110,"TOO MANY EXITS"  },
74 { 111,"ILLEGAL CHARACTER"       },
75 { 112,"WRONG STRUCTURE OF \"IF\"-STATEMENT"     },
76 { 113,"\"END\"  MISSING"        },
77 { 114,"\".\"  EXPECTED" },
78 { 115,"ILLEGAL CONSTANT IN EXPRESSION"  },
79 { 116,"\"=\"  EXPECTED" },
80 { 117,"CONSTANT  EXPEXCTED"     },
81 { 118,"\":\"  EXPECTED" },
82 { 119,"UNIT KIND SPECIFICATION  EXPECTED"       },
83 { 120,"\"HIDDEN\" OR \"CLOSE\" OCCURRED TWICE"  },
84 { 121,"HIDDEN OR CLOSE OUT OF A CLASS"  },
85 { 122,"\"BLOCK\"  EXPECTED"     },
86 { 123,"OBJECT EXPRESSION IS NOT A GENERATOR"    },
87 { 124,"\"DIM\"  EXPECTED"       },
88 { 125,"\"TO\"/\"DOWNTO\"  EXPECTED"     },
89 { 126,"ILLEGAL ARITHMETIC OPERATOR"     },
90 { 127,"DECLARATION PART  EXPECTED"      },
91 { 128,"INCORRECT IDENTIFIER AT \"END\"" },
92 { 129,"WRONG STRUCTURE OF \"CASE\"-STATEMENT"   },
93 { 130,"WRONG STRUCTURE OF \"DO\"-STATEMENT"     },
94 { 131,"ILLEGAL USE OF \"MAIN\"" },
95 { 132,"\"WHEN\"  EXPECTED"      },
96 { 133,"TOO MANY BRANCHES IN \"CASE\"-STATEMENT" },
97 { 134,"\"BEGIN\" MISSING"       },
98 { 135,"BAD OPTION"      },
99 { 136,"IS IT REALLY A LOGLAN PROGRAM ???"       },
100 { 137,"\"BLOCK\" MISSING -PARSING BEGAN"        },
101 { 138,"\"REPEAT\" OUT OF A LOOP"        },
102 { 139,"THERE IS NO PATH TO THIS STATEMENT"      },
103 { 140,"\"ANDIF\"/\"ORIF\" MIXED"        },
104 { 141,"ARRAY OF \"SEMAPHORE\" IS ILLEGAL"       },
105 { 142,"WRONG HANDLER END"       },
106 { 143,"LASTWILL INSIDE A STRUCTURED STATEMENT"  },
107 { 144,"REPEATED LASTWILL"       },
108 { 145,"NO PARAMETER SPECIFICATION"      },
109 { 146,"WRONG REGISTER SPECIFICATION"    },
110 { 147,"\",\" EXPECTED"  },
111 { 191,null_program      },
112 { 196,"***TOO MANY IDENTIFIERS" },
113 { 197,"***TOO MANY FORMAL PARAMETERS"   },
114 { 198,"***PARSER STACK OVERLOADED"      },
115 { 199,too_many_prototypes       },
116 { 201,"WRONG REAL CONSTANT"     },
117 { 202,"WRONG COMMENT"   },
118 { 203,"WRONG CHARACTER CONSTANT"        },
119 { 204,"WRONG INTEGER CONSTANT"  },
120 { 205,"INTEGER OVERFLOW"        },
121 { 206,"REAL OVERFLOW"   },
122 { 211,"IDENTIFIER TOO LONG"     },
123 { 212,"STRING TOO LONG" },
124 { 301,"PREFIX IS NOT A CLASS"   },
125 { 303,"COROUTINE/PROCESS ILLEGAL HERE AS PREFIX"        },
126 { 304,"HIDDEN IDENTIFIER CANNOT BE TAKEN"       },
127 { 305,undeclared_identifier     },
128 { 306,"UNDECLARED TYPE IDENTIFIER"      },
129 { 307,"TYPE IDENTIFIER  EXPECTED"       },
130 { 308,"UNDECLARED PREFIX IDENTIFIER"    },
131 { 309,"DECLARED MORE THAN ONCE" },
132 { 310,"TAKEN LIST IN UNPREFIXED UNIT"   },
133 { 316,"FORMAL TYPE SPECIFICATION AFTER USING"   },
134 { 317,"HIDDEN TYPE IDENTIFIER"  },
135 { 318,"TYPE IDENTIFIER NOT TAKEN"       },
136 { 319,"HIDDEN IDENTIFIER IN THE LIST"   },
137 { 320,"IDENTIFIER IN THE LIST NOT TAKEN"        },
138 { 321,"IDENTIFIER CANNOT BE TAKEN"      },
139 { 322,"HIDDEN PREFIX IDENTIFIER"        },
140 { 323,"PREFIX IDENTIFIER NOT TAKEN"     },
141 { 329,"ONLY PROCEDURE AND FUNCTION MAY BE VIRTUAL"      },
142 { 330,"VIRTUAL IN UNPREFIXED BLOCK/PROCEDURE/FUNCTION"  },
143 { 331,"INCOMPATIBLE KINDS OF VIRTULS"   },
144 { 332,"INCOMPATIBLE TYPES OF VIRTUALS"  },
145 { 333,"DIFFERENT LENGTH OF FORM. PARAM. LISTS IN VIRTUALS"      },
146 { 334,"INCOMPATIBLE KINDS OF THE 1ST LEVEL PARAMETERS"  },
147 { 335,"INCOMPATIBLE TYPES OF THE 1ST LEVEL PARAMETERS"  },
148 { 336,diff_lengths      },
149 { 337,incompat_kinds    },
150 { 338,"INCOMPATIBLE TYPES OF THE 2ND LEVEL PARAMETERS"  },
151 { 341,"***DECLARATION PART OVERLOADED"  },
152 { 342,"***TOO MANY CLASSES DECLARED"    },
153 { 343,too_many_prototypes       },
154 { 350,"UNDECLARED SIGNAL IDENTIFIER"    },
155 { 351,"HIDDEN SIGNAL IDENTIFIER"        },
156 { 352,"SIGNAL IDENTIFIER NOT TAKEN"     },
157 { 353,"SIGNAL IDENTIFIER  EXPECTED"     },
158 { 354,"DIFFERENT TYPES OF PARAMETERS"   },
159 { 355,"INCOMPATIBLE KINDS OF THE PARAMETERS"    },
160 { 356,"DIFFERENT IDENTIFIERS OF PARAMETERS"     },
161 { 357,incompat_kinds    },
162 { 358,"DIFFERENT TYPES OF THE 2ND LEVEL PARAMETERS"     },
163 { 359,diff_lengths      },
164 { 360,"DIFFERENT LENGTHS OF FORM. PARAM. LISTS IN SIGNALS"      },
165 { 361,"NON-LOCAL FORMAL TYPE CANNOT BE USED"    },
166 { 362,"REPEATED HANDLER FOR SIGNAL"     },
167 { 370,"ONLY \"INPUT\" IS LEGAL HERE"    },
168 { 398,"CLASS PREFIXED BY ITSELF"        },
169 { 399,"CYCLE IN PREFIX SEQUENCE"        },
170 { 401,"WRONG LABEL IN \"CASE\"" },
171 { 402,"\"CASE\"-STATEMENT NESTED TOO DEEPLY"    },
172 { 403,"TOO LONG SPAN OF \"CASE\" LABELS"        },
173 { 404,"REPEATED LABEL IN \"CASE\"-STATEMENT"    },
174 { 405,"ILLEGAL TYPE OF \"CASE\" EXPRESSION"     },
175 { 406,"DIFFERENT TYPES OF LABELS AND \"CASE\" EXPRESSION"       },
176 { 407,"NON-LOGICAL EXPRESSION AFTER \"IF\"/\"WHILE\""   },
177 { 408,"REAL CONSTANT OUT OF INTEGER RANGE"      },
178 { 410,"SIMPLE VARIABLE  EXPECTED"       },
179 { 411,"NON-INTEGER CONTROL VARIABLE"    },
180 { 412,"NON-INTEGER EXPRESSION"  },
181 { 413,"FILE EXPRESSION EXPECTED"        },
182 { 414,"STRING EXPRESSION EXPECTED"      },
183 { 415,"REFERENCE EXPRESSION EXPECTED"   },
184 { 416,"ARRAY EXPRESSION EXPECTED"       },
185 { 417,"BOOLEAN EXPRESSION EXPECTED"     },
186 { 418,"SEMAPHORE VARIABLE  EXPECTED"    },
187 { 419,"ILLEGAL TYPE IN \"OPEN\""        },
188 { 420,"VARIABLE  EXPECTED"      },
189 { 421,"CLASS IDENTIFIER AFTER \"NEW\" EXPECTED" },
190 { 422,"PROCEDURE IDENTIFIER AFTER \"CALL\" EXPECTED"    },
191 { 423,"\"NEW\"  MISSING"        },
192 { 424,"\"CALL\"  MISSING"       },
193 { 425,"\"INNER\" OUT OF A CLASS"        },
194 { 426,"\"INNER\" OCCURRED MORE THAN ONCE"       },
195 { 427,"\"WIND\"/\"TERMINATE\" OUT OF A HANDLER" },
196 { 428,"\"INNER\" INSIDE LASTWILL"       },
197 { 429,"DEFINITION CANNOT BE REDUCED TO CONSTANT"        },
198 { 430,"UNDEFINED CONSTANT IN THE DEFINITION"    },
199 { 431,"WRONG NUMBER OF INDICES" },
200 { 432,"INDEX OUT OF RANGE"      },
201 { 433,"UPPER BOUND LESS THAN LOWER BOUND"       },
202 { 434,"TOO MANY SUBSCRIPTS"     },
203 { 435,"VARIABLE IS NOT ARRAY"   },
204 { 440,"TYPE IDENTIFIER EXPECTED AFTER \"ARRAYOF\""      },
205 { 441,"INCORRECT FORMAT IN \"WRITE\""   },
206 { 442,"ILLEGAL EXPRESSION IN \"WRITE\"" },
207 { 443,"ILLEGAL TYPE OF VARIABLE IN \"READ\""    },
208 { 444,"NO DATA FOR I/O TRANSFER"        },
209 { 445,"ILLEGAL EXPRESSION IN \"PUT\""   },
210 { 446,"ILLEGAL TYPE OF VARIABLE IN \"GET\""     },
211 { 448,"\"RAISE\" MISSING"       },
212 { 449,"SIGNAL IDENTIFIER AFTER \"RAISE\" EXPECTED"      },
213 { 450,"ILLEGAL PROCEDURE OCCURRENCE"    },
214 { 451,"ILLEGAL CLASS OCCURRENCE"        },
215 { 452,"ILLEGAL TYPE OCCURRENCE" },
216 { 453,"ILLEGAL SIGNAL OCCURRENCE"       },
217 { 454,"ILLEGAL OPERATOR OCCURRENCE"     },
218 { 455,"WRONG NUMBER OF OPERANDS"        },
219 { 460,"DIVIDED BY ZERO" },
220 { 469,"WRONG REGISTER NUMBER"   },
221 { 470,"ILLEGAL INPUT PARAMETER" },
222 { 471,"ILLEGAL OUTPUT PARAMETER"        },
223 { 472,"ILLEGAL TYPE PARAMETER"  },
224 { 473,"ILLEGAL PROCEDURE PARAMETER"     },
225 { 474,"ILLEGAL FUNCTION PARAMETER"      },
226 { 475,"ILLEGAL LEFT SIDE OF \"IS\"/\"IN\""      },
227 { 476,"ILLEGAL RIGHT SIDE OF \"IS\"/\"IN\""     },
228 { 477,"ILLEGAL PARAMETER OF \"ATTACH\"" },
229 { 478,"ILLEGAL TYPE OF EXPRESSION"      },
230 { 479,"NEGATIVE STEP VALUE"     },
231 { 500,"***PROGRAM UNEXPECTEDLY HARD"    },
232 { 550,"***STACK OVERLOADED"     },
233 { 551,"***TOO MANY AUXILIARY VARIABLES NEEDED"  },
234 { 552,"***TOO MANY AUXILIARY REFERENCE VARIABLES NEEDED"        },
235 { 553,"***STATEMENT SEQUENCE TOO LONG OR TOO COMPLICATED"       },
236 { 554,"***REAL CONSTANTS DICTIONARY OVERFOW"    },
237 { 600,undeclared_identifier     },
238 { 601,"ILLEGAL TYPE BEFORE \".\""       },
239 { 602,"CLOSE IDENTIFIER AFTER \".\""    },
240 { 603,"UNDECLARED IDENTIFIER AFTER \".\""       },
241 { 604,"ILLEGAL OPERAND TYPE"    },
242 { 605,"ILLEGAL TYPE IN \"DIV\"/\"MOD\" TERM"    },
243 { 606,"INCOMPATIBLE TYPES IN COMPARISON"        },
244 { 607,"UNRELATED CLASS TYPES IN COMPARISON"     },
245 { 608,"STRINGS CANNOT BE COMPARED"      },
246 { 609,"INCOMPATIBLE TYPES IN ASSIGNMENT/TRANSMISSION"   },
247 { 610,"UNRELATED CLASS TYPES IN ASSIGNMENT/TRANSMISSION"        },
248 { 611,"CONSTANT AFTER \".\""    },
249 { 612,"THIS CLASS DOES NOT OCCUR IN SL-CHAIN"   },
250 { 613,class_identifier_expected },
251 { 614,class_identifier_expected },
252 { 615,"ILLEGAL TYPE BEFORE \"QUA\""     },
253 { 616,"ILLEGAL TYPE AFTER \"QUA\""      },
254 { 617,"ILLEGAL TYPE AFTER \"QUA\""      },
255 { 618,"UNRELATED TYPES IN \"QUA\"-EXPRESSION"   },
256 { 619,"HIDDEN IDENTIFIER"       },
257 { 620,"NON-TAKEN IDENTIFIER"    },
258 { 621,"INVISIBLE IDENTIFIER AFTER \".\""        },
259 { 622,"FORMAL PARAMETER LIST SHORTER"   },
260 { 623,"FORMAL PARAMETER LIST LONGER"    },
261 { 624,"ACTUAL PARAMETER IS NOT A REFERENCE TYPE"        },
262 { 625,"ACTUAL PARAMETER IS NOT A TYPE"  },
263 { 626,"PROCEDURE-FUNCTION CONFLICT BETWEEN PARAMETERS"  },
264 { 627,"UNMATCHED HEADS -  WRONG KINDS OF PARAMETERS"    },
265 { 628,"UNMATCHED HEADS-INCOMPATIBLE TYPES IN LISTS"     },
266 { 629,"UNMATCHED HEADS-UNRELATED CLASS TYPES IN LISTS"  },
267 { 630,"UNMATCHED HEADS-DIFFERENT NUMBERS OF PARAMETERS" },
268 { 631,"INCOMPATIBLE TYPES OF FUNCTION PARAMETERS"       },
269 { 632,"FUNCTION/PROCEDURE  EXPECTED"    },
270 { 633,null_program      },
271 { 634,"UNMATCHED HEADS-TOO WEAK TYPE IN ACTUAL LIST"    },
272 { 635,"STANDARD FUNCTION/PROCEDURE CANNOT BE ACTUAL PAR."       },
273 { 636,"ILLEGAL USE OF SEMAPHORE"        },
274 { 637,"\"SEMAPHORE\" TYPE CANNOT BE USED"       }
275
276 };
277
278
279 static char *find_msg( errno )  int errno;{
280    int l=0;
281    int u=sizeof(err_tab)/sizeof(err_tab[0]);
282    while( l!=u ){
283       int m= ( l+u )/2 ;
284       if( errno > err_tab[m].errno )  l=m;
285       else
286       if( errno < err_tab[m].errno )  u=m;
287       else
288       l=u=m;
289    }
290    if( err_tab[l].errno != errno )
291       return "UNKNOWN ERROR MESSAGE NUBER - INTERNAL COMPILER ERROR";
292    return err_tab[l].errmsg;
293 }
294