File: FAUhdlScanner.hpp

package info (click to toggle)
fauhdlc 20130704-1.1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 2,840 kB
  • ctags: 3,840
  • sloc: cpp: 23,179; ansic: 6,077; yacc: 825; lex: 761; makefile: 607; python: 465; xml: 403; sh: 61
file content (75 lines) | stat: -rw-r--r-- 2,020 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* $Id: FAUhdlScanner.hpp 4323 2009-01-27 13:48:12Z potyra $ 
 *
 * Copyright (C) 2007-2009 FAUmachine Team <info@faumachine.org>.
 * This program is free software. You can redistribute it and/or modify it
 * under the terms of the GNU General Public License, either version 2 of
 * the License, or (at your option) any later version. See COPYING.
 */

#ifndef __FAUHDLSCANNER_HPP_INCLUDED
#define __FAUHDLSCANNER_HPP_INCLUDED

/* make sure that yyFlexLexer will not get declared more than once */
#undef yyFlexLexer
#include <FlexLexer.h>
#include <string>

namespace yy {

/** custom lexer class with a overloaded yylex function
 */
class FAUhdlScanner : public yyFlexLexer {
public:
	// arg_yyin and arg_yyout default to the cin and cout, but we
	// only make that assignment when initializing in yylex().
	FAUhdlScanner(
		std::istream* arg_yyin = 0, 
		std::ostream* arg_yyout = 0
		) : 	yyFlexLexer(arg_yyin, arg_yyout),
			bracesCtr(0),
			isAssociation(false),
			backup(std::string()),
			scannedForAssociation(false) {}

	virtual ~FAUhdlScanner() {}

	/* defined from flex via mangling in ParserDriver.hpp for *this* 
   	 * class */
	virtual FAUhdlParser::token_type 
	yylex(
		yy::FAUhdlParser::semantic_type* yylval, 
		FAUhdlParser::location_type* yylloc,
		ParserDriver& driver
	);

private:
	/** unput all characters stored in backup */
	void putBack(void) {
		for (std::string::reverse_iterator i = this->backup.rbegin();
			i != this->backup.rend(); i++) {

			/* evil: copied definition of macro unput */
			this->yyunput(*i, yytext);
		}
	}

	/** reset bracesCtr, isAssociation and backup */
	void reset(void) {
		this->bracesCtr = 0;
		this->isAssociation = false;
		this->backup = "";
	}

	/** braces counter (e.g. association list checking ) */
	int bracesCtr;
	/** is an association? */
	bool isAssociation;
	/** backup stack for lookahead scanning. */
	std::string backup;
	/** already scanned for an association? */
	bool scannedForAssociation;
};

}

#endif /* __FAUHDLSCANNER_HPP_INCLUDED */