view src/tokenizer.h @ 5:276c4edc8521

initial coding
author carl
date Fri, 02 Dec 2005 17:52:44 -0800
parents 551433a01cab
children d76f9ff42487
line wrap: on
line source

 *	 Copyright (C) 2005 by 510 Software Group							   *
 *																		   *
 *																		   *
 *	 This program 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 2 of the License, or	   *
 *	 (at your option) any later version.								   *
 *																		   *
 *	 This program is distributed in the hope that it will be useful,	   *
 *	 but WITHOUT ANY WARRANTY; without even the implied warranty of 	   *
 *	 GNU General Public License for more details.						   *
 *																		   *
 *	 You should have received a copy of the GNU General Public License	   *
 *	 along with this program; if not, write to the						   *
 *	 Free Software Foundation, Inc.,									   *
 *	 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.			   *

#ifndef tokenizer_include
#define tokenizer_include

#include <fstream>
#include <list>
#include <set>
#include <stdio.h>
#include <ctype.h>

using namespace std;

struct ltstr {
	bool operator()(char* s1, char* s2) const {
		return strcmp(s1, s2) < 0;

typedef list<ifstream *>	stream_list;
typedef list<char *>		string_list;
typedef set<char *, ltstr>	string_set;
typedef list<int>			line_list;

class TOKEN {
	stream_list streams;
	string_list filenames;
	string_set	filenamess;
	line_list	linenumbers;
	string_list pending_tokens;
	string_set	*include_files;
	bool		pushed;
	u_char		pushed_char;

	void pop();
	bool next_char(u_char &c);
	void push_char(u_char c);

	TOKEN(char *fn, string_set *includes);
	bool		include(char *fn);
	char		*next();			// return next token
	int 		nextint();
	void		skipeol();			// skip to eol
	void		push(char *token)			{pending_tokens.push_front(token);};
	const char	*cur_fn()					{return filenames.empty()	? "" : filenames.front();};
	int 		cur_line()					{return linenumbers.empty() ? 0  : linenumbers.front();};
	void		token_error(const char *err);
	void		token_error(const char *fmt, int d, const char *s);
	void		token_error(const char *fmt, const char *t, const char *h);
	void		token_error(const char *want, const char *have);
	void		token_error();