# pragma once // Copyright (C) 2024 Arthur I. Schwarz // // This file is part of the Java SLIP library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation. // You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // . /** * @file SlipLexer.h * @author A. Schwarz * @date April 28, 2024 * */ #ifndef SLIPLEXER_H #define SLIPLEXER_H using namespace std; # include # include "SlipToken.h" # include "SlipInputInterface.h" # include "SlipOutputInterface.h" namespace slip { using StringBuilder = string; /** * @class LexerState * Tokenizes the input data stream. * * Each character of the input data stream is matched against the current * state of toknizer Mealy Finite State Machince (MFSM). When the MFSM * indicates that a token has been recognized a message is returned to * the parser with the token. * * The parser calls the lexer each time that a new token is needed. On * each parser call, the lexer starts with the last character read from * the input stream. If an end-of-file is detected, the lexer returns an * end-of-file indicator to the parser. * * In order to create oneness with the Universe, the lexer reads the first * charactee from the input stream during class construction. Thereafter, * each time the lexer returns to the parser, the last character read is * retained. * * The parser creates an instance of SlipLexer when the parse method is * called. There is no user interface to SlipLexer. * */ class SlipLexer { private: /** * Next character, chr. * * The processing algorithm requires that at lexer exit the next * character to be processed has been input and retained, and at * lexer re-entry this character is available as the next character * to be analyzed. This condition has the following consequences: * * * A global repository for this character is made available. * And here it is. */ /*------------------- Variables -------------------*/ char chr = '\0'; //!< next lexer character SlipToken& token; //!< token passed to parser SlipInputInterface& in; //!< Slip list source input SlipOutputInterface& out; //!< Slip logging output bool debug = false; //!< debug flag /*-------------------- Methods --------------------*/ char escapeSequenceProcessing(StringBuilder str); public: /*----------- Constructors/Destructors ------------*/ /** * Constructs a SlipRead object with both a log output and * list input interface. * * SlipLexer is created by SlipParser::parser. The Input/Output * interfaces must be supplied by SlipParser::parser, and, the * parser must prime the pump by reading the first character in * character in the input stream and retaining it for lexer use. * Thereafter, the lexer saves the last character input before * it returns to the parser. * * @param in input list source interface. * @param out printer output interface. */ SlipLexer(SlipInputInterface& in, SlipOutputInterface& out, SlipToken& token, int debug = 0) // SlipRead(SlipInput in) : in(in) , out(out) , token(token) , debug((bool)(debug & SlipRead::DEBUGLEXER)) { chr = in.getChar(); }; /** * Destructor for SlipLexer. */ ~SlipLexer() { } /*-------------------- methods --------------------*/ SlipToken& lexer(); }; // class SlipLexer }; // namespace slip # endif /* SLIPLEXER_H*/