File: Tokenizer.h

package info (click to toggle)
structure-synth 1.5.0-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,268 kB
  • ctags: 1,966
  • sloc: cpp: 10,209; python: 164; makefile: 71; sh: 15
file content (65 lines) | stat: -rw-r--r-- 1,645 bytes parent folder | download | duplicates (10)
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
#pragma once

#include <QString>
#include <QList>

#include "../../SyntopiaCore/Exceptions/Exception.h"

namespace StructureSynth {
	namespace Parser {	

		class ParseError : public SyntopiaCore::Exceptions::Exception {
		public:
			ParseError(QString message, int position) :  Exception(message), position(position) {};
			int getPosition() { return position; }
		private:
			int position;
		};

		struct Symbol {
			enum SymbolType { Undefined, LeftBracket, RightBracket, MoreThan, End, Number, Multiply, UserString, Rule, Set, Operator } ;

			

			Symbol() :  floatValue(0), intValue(0),  isInteger(false),pos(-1), type(Undefined) { 	};
			Symbol(int pos, SymbolType s, QString original) : text(original),floatValue(0), intValue(0),isInteger(false), pos(pos),    type(s) { 	};

			
			/// yes, yes, it is a bloated representation. (I don't like unions...)
			QString text;         // The original text-string we parsed. Notice userstrings are converted to lower-case
			double floatValue;
			int    intValue;
			bool   isInteger;
			int pos;              // the position (char-index) of the original text parsed.
			SymbolType type;


			double getNumerical() {
				if (isInteger) return intValue;
				return floatValue;
			}
		};

		/// The Tokenizer divides an input stream into distinct symbols,
		/// for subsequent parsing.
		class Tokenizer {

		public:
			/// Constructor. 
			Tokenizer(QString input);

			/// Destructor
			~Tokenizer();

			/// Returns the next symbol
			Symbol getSymbol();

		private:
		
			QList<Symbol> symbols;
			int currentSymbol;
		};

	}
}