sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* Header READER.CPP
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "READER.H"
|
sl@0
|
21 |
|
sl@0
|
22 |
Reader::Reader()
|
sl@0
|
23 |
{
|
sl@0
|
24 |
iLexAnal = NULL;
|
sl@0
|
25 |
}
|
sl@0
|
26 |
|
sl@0
|
27 |
boolean Reader::Open(const String& aFilename)
|
sl@0
|
28 |
{
|
sl@0
|
29 |
boolean state;
|
sl@0
|
30 |
String string = aFilename;
|
sl@0
|
31 |
if (iLexAnal != NULL)
|
sl@0
|
32 |
delete iLexAnal;
|
sl@0
|
33 |
iLexAnal = new LexAnal(string.Text());
|
sl@0
|
34 |
|
sl@0
|
35 |
if (iLexAnal)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
state = etrue;
|
sl@0
|
38 |
iLex =& (iLexAnal->iLex);
|
sl@0
|
39 |
iLexAnal->Read(); // reads first lexical
|
sl@0
|
40 |
}
|
sl@0
|
41 |
else
|
sl@0
|
42 |
state = efalse;
|
sl@0
|
43 |
|
sl@0
|
44 |
return state;
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
Reader::~Reader()
|
sl@0
|
48 |
{
|
sl@0
|
49 |
if (iLexAnal != NULL)
|
sl@0
|
50 |
delete iLexAnal;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
boolean Reader::_EOF()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
return ((iLex->iType) == ELexEOF);
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
boolean Reader::NewLine()
|
sl@0
|
59 |
{
|
sl@0
|
60 |
boolean state;
|
sl@0
|
61 |
if (iLex->iType == ELexNL)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
iLexAnal->Read();
|
sl@0
|
64 |
state = etrue;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
else
|
sl@0
|
67 |
{
|
sl@0
|
68 |
Error(String("Newline expected"));
|
sl@0
|
69 |
state = efalse;
|
sl@0
|
70 |
}
|
sl@0
|
71 |
return state;
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
boolean Reader::Number(int& aNumber)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
boolean state;
|
sl@0
|
77 |
if (iLex->iType == ELexNumber)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
aNumber = iLex->iNumber;
|
sl@0
|
80 |
iLexAnal->Read();
|
sl@0
|
81 |
state = etrue;
|
sl@0
|
82 |
}
|
sl@0
|
83 |
else
|
sl@0
|
84 |
{
|
sl@0
|
85 |
Error(String("Number expected"));
|
sl@0
|
86 |
state = efalse;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
return state;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
boolean Reader::IdentComp(const String& aIdent)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
boolean state;
|
sl@0
|
94 |
if (iLex->iType == ELexIdent)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
if (aIdent == iLex->iText)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
iLexAnal->Read();
|
sl@0
|
99 |
state = etrue;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
else
|
sl@0
|
102 |
state = efalse;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
else
|
sl@0
|
105 |
{
|
sl@0
|
106 |
state = efalse;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
return state;
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
boolean Reader::IdentCopy(String& aIdent)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
boolean state;
|
sl@0
|
114 |
if (iLex->iType == ELexIdent)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
aIdent = iLex->iText;
|
sl@0
|
117 |
iLexAnal->Read();
|
sl@0
|
118 |
state = etrue;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
else
|
sl@0
|
121 |
{
|
sl@0
|
122 |
Error(String("Identifier expected"));
|
sl@0
|
123 |
state = efalse;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
return state;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
boolean Reader::StringCopy(String& aString)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
boolean state;
|
sl@0
|
131 |
if (iLex->iType == ELexString)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
aString = iLex->iText;
|
sl@0
|
134 |
iLexAnal->Read();
|
sl@0
|
135 |
state = etrue;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
else
|
sl@0
|
138 |
{
|
sl@0
|
139 |
Error(String("String expected"));
|
sl@0
|
140 |
state = efalse;
|
sl@0
|
141 |
}
|
sl@0
|
142 |
return state;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
boolean Reader::Operator(char& aCh)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
boolean state;
|
sl@0
|
148 |
if (iLex->iType == ELexOperator)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
aCh = iLex->iText[0];
|
sl@0
|
151 |
iLexAnal->Read();
|
sl@0
|
152 |
state = etrue;
|
sl@0
|
153 |
}
|
sl@0
|
154 |
else
|
sl@0
|
155 |
{
|
sl@0
|
156 |
Error(String("Operator expected"));
|
sl@0
|
157 |
state = efalse;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
return state;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
EXPORT_C void Reader::Error(const String& aString)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
cerr << "Error: " << aString;
|
sl@0
|
165 |
iLexAnal->Report();
|
sl@0
|
166 |
while ((iLex->iType != ELexNL) && (iLex->iType != ELexEOF))
|
sl@0
|
167 |
iLexAnal->Read();
|
sl@0
|
168 |
}
|