sl@0: /* sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Header READER.CPP sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "READER.H" sl@0: sl@0: Reader::Reader() sl@0: { sl@0: iLexAnal = NULL; sl@0: } sl@0: sl@0: boolean Reader::Open(const String& aFilename) sl@0: { sl@0: boolean state; sl@0: String string = aFilename; sl@0: if (iLexAnal != NULL) sl@0: delete iLexAnal; sl@0: iLexAnal = new LexAnal(string.Text()); sl@0: sl@0: if (iLexAnal) sl@0: { sl@0: state = etrue; sl@0: iLex =& (iLexAnal->iLex); sl@0: iLexAnal->Read(); // reads first lexical sl@0: } sl@0: else sl@0: state = efalse; sl@0: sl@0: return state; sl@0: } sl@0: sl@0: Reader::~Reader() sl@0: { sl@0: if (iLexAnal != NULL) sl@0: delete iLexAnal; sl@0: } sl@0: sl@0: boolean Reader::_EOF() sl@0: { sl@0: return ((iLex->iType) == ELexEOF); sl@0: } sl@0: sl@0: boolean Reader::NewLine() sl@0: { sl@0: boolean state; sl@0: if (iLex->iType == ELexNL) sl@0: { sl@0: iLexAnal->Read(); sl@0: state = etrue; sl@0: } sl@0: else sl@0: { sl@0: Error(String("Newline expected")); sl@0: state = efalse; sl@0: } sl@0: return state; sl@0: } sl@0: sl@0: boolean Reader::Number(int& aNumber) sl@0: { sl@0: boolean state; sl@0: if (iLex->iType == ELexNumber) sl@0: { sl@0: aNumber = iLex->iNumber; sl@0: iLexAnal->Read(); sl@0: state = etrue; sl@0: } sl@0: else sl@0: { sl@0: Error(String("Number expected")); sl@0: state = efalse; sl@0: } sl@0: return state; sl@0: } sl@0: sl@0: boolean Reader::IdentComp(const String& aIdent) sl@0: { sl@0: boolean state; sl@0: if (iLex->iType == ELexIdent) sl@0: { sl@0: if (aIdent == iLex->iText) sl@0: { sl@0: iLexAnal->Read(); sl@0: state = etrue; sl@0: } sl@0: else sl@0: state = efalse; sl@0: } sl@0: else sl@0: { sl@0: state = efalse; sl@0: } sl@0: return state; sl@0: } sl@0: sl@0: boolean Reader::IdentCopy(String& aIdent) sl@0: { sl@0: boolean state; sl@0: if (iLex->iType == ELexIdent) sl@0: { sl@0: aIdent = iLex->iText; sl@0: iLexAnal->Read(); sl@0: state = etrue; sl@0: } sl@0: else sl@0: { sl@0: Error(String("Identifier expected")); sl@0: state = efalse; sl@0: } sl@0: return state; sl@0: } sl@0: sl@0: boolean Reader::StringCopy(String& aString) sl@0: { sl@0: boolean state; sl@0: if (iLex->iType == ELexString) sl@0: { sl@0: aString = iLex->iText; sl@0: iLexAnal->Read(); sl@0: state = etrue; sl@0: } sl@0: else sl@0: { sl@0: Error(String("String expected")); sl@0: state = efalse; sl@0: } sl@0: return state; sl@0: } sl@0: sl@0: boolean Reader::Operator(char& aCh) sl@0: { sl@0: boolean state; sl@0: if (iLex->iType == ELexOperator) sl@0: { sl@0: aCh = iLex->iText[0]; sl@0: iLexAnal->Read(); sl@0: state = etrue; sl@0: } sl@0: else sl@0: { sl@0: Error(String("Operator expected")); sl@0: state = efalse; sl@0: } sl@0: return state; sl@0: } sl@0: sl@0: EXPORT_C void Reader::Error(const String& aString) sl@0: { sl@0: cerr << "Error: " << aString; sl@0: iLexAnal->Report(); sl@0: while ((iLex->iType != ELexNL) && (iLex->iType != ELexEOF)) sl@0: iLexAnal->Read(); sl@0: }