1 //**********************************************************
2 //   CR_PARSE.CPP
3 //   Coco/R C++ Support Library.
4 //   Author: Frankie Arzu <farzu@uvg.edu.gt>
5 //
6 //   Jun 12, 1996  Version 1.06
7 //      Many fixes and suggestions thanks to
8 //      Pat Terry <p.terry@.ru.ac.za>
9 //**********************************************************
10 
11 #include "cr_parse.hpp"
12 #include "cr_error.hpp"
13 #include <stdio.h>
14 
15 const int NSETBITS = 16;
16 
CRParser(AbsScanner * S,CRError * E)17 CRParser::CRParser(AbsScanner *S, CRError *E)
18 {
19   if (!E || !S) {
20     fprintf(stderr, "CRParser::CRParser: No Scanner or No Error Mgr\n");
21     exit(1);
22   }
23   Scanner = S;
24   Error = E;
25   Sym = 0;
26 }
27 
Parse()28 void CRParser::Parse()
29 {
30   printf("Abstract CRParser::Parse() called\n"); exit(1);
31 }
32 
GenError(int ErrorNo)33 void CRParser::GenError(int ErrorNo)
34 //++++ GenError is supposed to be "private" for Coco/R only.  If a user calls
35 //++++ it directly, that is fine, but there is no consistency check performed
36 {
37   Error->StoreErr(ErrorNo, Scanner->NextSym);
38 }
39 
SynError(int ErrorNo)40 void CRParser::SynError(int ErrorNo)
41 //++++ SynError is for users.  Note that we check for error number
42 //++++ clashes.  If the numbers are too small, we simply make them bigger!
43 {
44   if (ErrorNo <= Error->MinUserError) ErrorNo = Error->MinUserError;
45   Error->StoreErr(ErrorNo, Scanner->NextSym);
46 }
47 
SemError(int ErrorNo)48 void CRParser::SemError(int ErrorNo)
49 //++++ SemError is for users.  Note that we check for error number
50 //++++ clashes.  If the numbers are too small, we simply make them bigger!
51 {
52   if (ErrorNo <= Error->MinUserError) ErrorNo = Error->MinUserError;
53   Error->StoreErr(ErrorNo, Scanner->CurrSym);
54 }
55 
In(unsigned short int * SymbolSet,int i)56 int CRParser::In(unsigned short int *SymbolSet, int i)
57 {
58   return SymbolSet[i / NSETBITS] & (1 << (i % NSETBITS));
59 }
60 
Expect(int n)61 void CRParser::Expect(int n)
62 {
63   if (Sym == n) Get(); else GenError(n);
64 }
65