/*	Copyright  (c)	Günter Woigk 2018 - 2021
					mailto:kio@little-bat.de

	This file is free software.

	Permission to use, copy, modify, distribute, and sell this software
	and its documentation for any purpose is hereby granted without fee,
	provided that the above copyright notice appears in all copies and
	that both that copyright notice, this permission notice and the
	following disclaimer appear in supporting documentation.

	THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY,
	NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
	A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE COPYRIGHT HOLDER
	BE LIABLE FOR ANY DAMAGES ARISING FROM THE USE OF THIS SOFTWARE,
	TO THE EXTENT PERMITTED BY APPLICABLE LAW.
*/

#pragma once
#include "kio/kio.h"
#include "Word.h"
#include "types.h"
extern uint max_errors; // globals.h


namespace vpp
{

class Tokenizer
{
	Names&  names;
	Words   words;
	Errors& errors;

	void parse_identifier (cptr a, cptr e);
	void parse_number (cptr a, cptr e) throws;
	void parse_base256_number (cptr a, cptr e) throws;
	void parse_string(cptr a, cptr e) throws;
	void append_word(cType* type, float128 value)	{ words.append(Word(spos,type,value)); }
	void append_word(cstr string)					{ words.append(Word(spos,string)); }
	void append_word(NameID idf)					{ words.append(Word(spos,idf)); }

public:
	Tokenizer(Names&, Errors&);
	Words tokenize (cstr source, uint32 offs);

private:
	cstr   source;
	uint32 spos;

	cType *tuint16, *tuint32, *tuint64, *tint16, *tint32;		// global
	cType *tshort, *tushort, *tint, *tuint, *tlong, *tulong;
	cType *tsfloat, *tfloat, *tlfloat;
	cType *tchar;
};

} // namespace















