- massive refactoring

Sun, 20 Jul 2014 17:25:36 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 20 Jul 2014 17:25:36 +0300
changeset 134
eca2fc0acaa2
parent 133
dbbdb870c835
child 135
8b9132fea327

- massive refactoring

src/botStuff.h file | annotate | diff | comparison | revisions
src/dataBuffer.cpp file | annotate | diff | comparison | revisions
src/dataBuffer.h file | annotate | diff | comparison | revisions
src/events.cpp file | annotate | diff | comparison | revisions
src/expression.cpp file | annotate | diff | comparison | revisions
src/expression.h file | annotate | diff | comparison | revisions
src/format.cpp file | annotate | diff | comparison | revisions
src/lexer.cpp file | annotate | diff | comparison | revisions
src/lexer.h file | annotate | diff | comparison | revisions
src/lexerScanner.cpp file | annotate | diff | comparison | revisions
src/lexerScanner.h file | annotate | diff | comparison | revisions
src/list.h file | annotate | diff | comparison | revisions
src/macros.h file | annotate | diff | comparison | revisions
src/main.cpp file | annotate | diff | comparison | revisions
src/parser.cpp file | annotate | diff | comparison | revisions
src/parser.h file | annotate | diff | comparison | revisions
src/string.cpp file | annotate | diff | comparison | revisions
src/stringTable.cpp file | annotate | diff | comparison | revisions
src/tokens.h file | annotate | diff | comparison | revisions
--- a/src/botStuff.h	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/botStuff.h	Sun Jul 20 17:25:36 2014 +0300
@@ -34,92 +34,95 @@
 
 #include "main.h"
 
-static const int gMaxStates			= 256;
-static const int gMaxEvents			= 32;
-static const int gMaxGlobalEvents	= 32;
-static const int gMaxGlobalVars		= 128;
-static const int gMaxGlobalArrays	= 16;
-static const int gMaxArraySize		= 65536;
-static const int gMaxStateVars		= 16;
-static const int gMaxStringlistSize	= 128;
-static const int gMaxStringLength	= 256;
-static const int gMaxReactionTime	= 52;
-static const int gMaxStoredEvents	= 64;
+struct Limits
+{
+	static const int MaxStates			= 256;
+	static const int MaxEvents			= 32;
+	static const int MaxGlobalEvents	= 32;
+	static const int MaxGlobalVars		= 128;
+	static const int MaxGlobalArrays	= 16;
+	static const int MaxArraySize		= 65536;
+	static const int MaxStateVars		= 16;
+	static const int MaxStringlistSize	= 128;
+	static const int MaxStringLength	= 256;
+	static const int MaxReactionTime	= 52;
+	static const int MaxStoredEvents	= 64;
+};
 
-named_enum DataHeader
+named_enum class DataHeader
 {
-	DH_Command,
-	DH_StateIndex,
-	DH_StateName,
-	DH_OnEnter,
-	DH_MainLoop,
-	DH_OnExit,
-	DH_Event,
-	DH_EndOnEnter,
-	DH_EndMainLoop,
-	DH_EndOnExit,
-	DH_EndEvent,
-	DH_IfGoto,
-	DH_IfNotGoto,
-	DH_Goto,
-	DH_OrLogical,
-	DH_AndLogical,
-	DH_OrBitwise,
-	DH_EorBitwise,
-	DH_AndBitwise,
-	DH_Equals,
-	DH_NotEquals,
-	DH_LessThan,
-	DH_AtMost,
-	DH_GreaterThan,
-	DH_AtLeast,
-	DH_NegateLogical,
-	DH_LeftShift,
-	DH_RightShift,
-	DH_Add,
-	DH_Subtract,
-	DH_UnaryMinus,
-	DH_Multiply,
-	DH_Divide,
-	DH_Modulus,
-	DH_PushNumber,
-	DH_PushStringIndex,
-	DH_PushGlobalVar,
-	DH_PushLocalVar,
-	DH_DropStackPosition,
-	DH_ScriptVarList,
-	DH_StringList,
-	DH_IncreaseGlobalVar,
-	DH_DecreaseGlobalVar,
-	DH_AssignGlobalVar,
-	DH_AddGlobalVar,
-	DH_SubtractGlobalVar,
-	DH_MultiplyGlobalVar,
-	DH_DivideGlobalVar,
-	DH_ModGlobalVar,
-	DH_IncreaseLocalVar,
-	DH_DecreaseLocalVar,
-	DH_AssignLocalVar,
-	DH_AddLocalVar,
-	DH_SubtractLocalVar,
-	DH_MultiplyLocalVar,
-	DH_DivideLocalVar,
-	DH_ModLocalVar,
-	DH_CaseGoto,
-	DH_Drop,
-	DH_IncreaseGlobalArray,
-	DH_DecreaseGlobalArray,
-	DH_AssignGlobalArray,
-	DH_AddGlobalArray,
-	DH_SubtractGlobalArray,
-	DH_MultiplyGlobalArray,
-	DH_DivideGlobalArray,
-	DH_ModGlobalArray,
-	DH_PushGlobalArray,
-	DH_Swap,
-	DH_Dup,
-	DH_ArraySet,
-	numDataHeaders
+	Command,
+	StateIndex,
+	StateName,
+	OnEnter,
+	MainLoop,
+	OnExit,
+	Event,
+	EndOnEnter,
+	EndMainLoop,
+	EndOnExit,
+	EndEvent,
+	IfGoto,
+	IfNotGoto,
+	Goto,
+	OrLogical,
+	AndLogical,
+	OrBitwise,
+	EorBitwise,
+	AndBitwise,
+	Equals,
+	NotEquals,
+	LessThan,
+	AtMost,
+	GreaterThan,
+	AtLeast,
+	NegateLogical,
+	LeftShift,
+	RightShift,
+	Add,
+	Subtract,
+	UnaryMinus,
+	Multiply,
+	Divide,
+	Modulus,
+	PushNumber,
+	PushStringIndex,
+	PushGlobalVar,
+	PushLocalVar,
+	DropStackPosition,
+	ScriptVarList,
+	StringList,
+	IncreaseGlobalVar,
+	DecreaseGlobalVar,
+	AssignGlobalVar,
+	AddGlobalVar,
+	SubtractGlobalVar,
+	MultiplyGlobalVar,
+	DivideGlobalVar,
+	ModGlobalVar,
+	IncreaseLocalVar,
+	DecreaseLocalVar,
+	AssignLocalVar,
+	AddLocalVar,
+	SubtractLocalVar,
+	MultiplyLocalVar,
+	DivideLocalVar,
+	ModLocalVar,
+	CaseGoto,
+	Drop,
+	IncreaseGlobalArray,
+	DecreaseGlobalArray,
+	AssignGlobalArray,
+	AddGlobalArray,
+	SubtractGlobalArray,
+	MultiplyGlobalArray,
+	DivideGlobalArray,
+	ModGlobalArray,
+	PushGlobalArray,
+	Swap,
+	Dup,
+	ArraySet,
+	NumDataHeaders
 };
 
 #endif	// BOTC_BOTSTUFF_H
--- a/src/dataBuffer.cpp	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/dataBuffer.cpp	Sun Jul 20 17:25:36 2014 +0300
@@ -28,16 +28,14 @@
 
 #include "dataBuffer.h"
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
 //
-DataBuffer::DataBuffer (int size)
-{
-	setBuffer (new char[size]);
-	setPosition (&buffer()[0]);
-	setAllocatedSize (size);
-}
+DataBuffer::DataBuffer (int size) :
+	m_buffer (new char[size]),
+	m_position (&buffer()[0]),
+	m_allocatedSize (size) {}
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 DataBuffer::~DataBuffer()
 {
@@ -46,7 +44,10 @@
 	delete buffer();
 }
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Copies the contents of the given buffer into this buffer. The other buffer's marks and 
+//	references will be moved along and the buffer is then destroyed.
 //
 void DataBuffer::mergeAndDestroy (DataBuffer* other)
 {
@@ -61,10 +62,10 @@
 	delete other;
 }
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
 //
-// Clones this databuffer to a new one and returns it. Note that the original
-// transfers its marks and references and loses them in the process.
+//	Clones this databuffer to a new one and returns it. Note that the original transfers its marks
+//	and references and loses them in the process.
 //
 DataBuffer* DataBuffer::clone()
 {
@@ -105,7 +106,9 @@
 	m_references.clear();
 }
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Adds a new mark to the current position with the given name
 //
 ByteMark* DataBuffer::addMark (const String& name)
 {
@@ -116,7 +119,10 @@
 	return mark;
 }
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Adds a new reference to the given mark at the current position. This function will write 4 
+//	bytes to the buffer whose value will be determined at final output writing.
 //
 MarkReference* DataBuffer::addReference (ByteMark* mark)
 {
@@ -131,29 +137,38 @@
 	return ref;
 }
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Moves the given mark to the current bytecode position.
 //
 void DataBuffer::adjustMark (ByteMark* mark)
 {
 	mark->pos = writtenSize();
 }
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Shifts the given mark by the amount of bytes
 //
-void DataBuffer::offsetMark (ByteMark* mark, int position)
+void DataBuffer::offsetMark (ByteMark* mark, int bytes)
 {
-	mark->pos += position;
+	mark->pos += bytes;
 }
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Writes a push of the index of the given string. 8 bytes will be written and the string index
+//	will be pushed to stack.
 //
 void DataBuffer::writeStringIndex (const String& a)
 {
-	writeDWord (DH_PushStringIndex);
+	writeDWord (DataHeader::PushStringIndex);
 	writeDWord (getStringTableIndex (a));
 }
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Prints the buffer to stdout.
 //
 void DataBuffer::dump()
 {
@@ -161,7 +176,10 @@
 		printf ("%d. [0x%X]\n", i, buffer()[i]);
 }
 
-// ============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+// Ensures there's at least the given amount of bytes left in the buffer. Will resize if necessary,
+// no-op if not. On resize, 512 extra bytes are allocated to reduce the amount of resizes.
 //
 void DataBuffer::checkSpace (int bytes)
 {
@@ -191,7 +209,9 @@
 	delete copy;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Writes the given byte into the buffer.
 //
 void DataBuffer::writeByte (int8_t data)
 {
@@ -199,7 +219,9 @@
 	*m_position++ = data;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Writes the given word into the buffer. 2 bytes will be written.
 //
 void DataBuffer::writeWord (int16_t data)
 {
@@ -209,7 +231,9 @@
 		*m_position++ = (data >> (i * 8)) & 0xFF;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Writes the given dword into the buffer. 4bytes will be written.
 //
 void DataBuffer::writeDWord (int32_t data)
 {
@@ -219,7 +243,10 @@
 		*m_position++ = (data >> (i * 8)) & 0xFF;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Writes the given string to the databuffer. The string will be written as-is without using string
+//	indices. This will write 4 + length bytes. No header will be written.
 //
 void DataBuffer::writeString (const String& a)
 {
@@ -230,14 +257,17 @@
 		writeByte (c);
 }
 
-
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
+//
+//	Tries to locate the mark by the given name. Returns null if not found.
 //
 ByteMark* DataBuffer::findMarkByName (const String& name)
 {
 	for (ByteMark* mark : marks())
+	{
 		if (mark->name == name)
 			return mark;
+	}
 
 	return null;
 }
--- a/src/dataBuffer.h	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/dataBuffer.h	Sun Jul 20 17:25:36 2014 +0300
@@ -34,124 +34,64 @@
 #include "main.h"
 #include "stringTable.h"
 
-/**
- *    @class DataBuffer
- *    @brief Stores a buffer of bytecode
- *
- *    The DataBuffer class stores a section of bytecode. Buffers are allocated on
- *    the heap and written to using the @c write* functions. Buffers can be cut and
- *    pasted together with @c mergeAndDestroy, note that this function destroys the
- *    parameter buffer in the process
- *
- *    A mark is a "pointer" to a particular position in the bytecode. The actual
- *    permanent position cannot be predicted in any way or form, thus these things
- *    are used to "bookmark" a position like that for future use.
- *
- *    A reference acts as a pointer to a mark. The reference is four bytes in the
- *    bytecode which will be replaced with its mark's position when the bytecode
- *    is written to the output file.
- *
- *    This mark/reference system is used to know bytecode offset values when
- *    compiling, even though actual final positions cannot be known.
- */
+// ------------------------------------------------------------------------------------------------
+//
+//	The DataBuffer class stores a section of bytecode. Buffers are allocated on
+//	the heap and written to using the @c write* functions. Buffers can be cut and
+//	pasted together with @c mergeAndDestroy, note that this function destroys the
+//	parameter buffer in the process
+//
+//	A mark is a "pointer" to a particular position in the bytecode. The actual
+//	permanent position cannot be predicted in any way or form, thus these things
+//	are used to "bookmark" a position like that for future use.
+//
+//	A reference acts as a pointer to a mark. The reference is four bytes in the
+//	bytecode which will be replaced with its mark's position when the bytecode
+//	is written to the output file.
+//
+//	This mark/reference system is used to know bytecode offset values when
+//	compiling, even though actual final positions cannot be known.
+//
 class DataBuffer
 {
-	//! @
 	PROPERTY (private, char*,					buffer,			setBuffer,			STOCK_WRITE)
 	PROPERTY (private, int,						allocatedSize,	setAllocatedSize,	STOCK_WRITE)
 	PROPERTY (private, char*,					position,		setPosition,		STOCK_WRITE)
 	PROPERTY (private, List<ByteMark*>,			marks,			setMarks,			STOCK_WRITE)
 	PROPERTY (private, List<MarkReference*>,	references,		setReferences,		STOCK_WRITE)
 
-	public:
-		//! Constructs a new databuffer with @c size bytes.
-		DataBuffer (int size = 128);
-
-		//! Destructs the databuffer.
-		~DataBuffer();
-
-		//! Adds a new mark to the current position with the name @c name.
-		//! @param name the name of the new mark
-		//! @return a pointer to the new mark
-		ByteMark*		addMark (const String& name);
-
-		//! Adds a new reference to @c mark at the current position. This
-		//! function will write 4 bytes to the buffer whose value will
-		//! be determined at final output writing.
-		//! @param mark the mark which the new reference will attach to
-		//! @return a pointer to the new reference
-		MarkReference*	addReference (ByteMark* mark);
-
-		//! Moves @c mark to the current bytecode position.
-		//! @param mark the mark to adjust
-		void			adjustMark (ByteMark* mark);
-
-		//! Ensures there's at least @c bytes left in the buffer. Will resize
-		//! if necessary, no-op if not. On resize, 512 extra bytes are allocated
-		//! to reduce the amount of resizes.
-		//! @param bytes the amount of space in bytes to ensure allocated
-		void			checkSpace (int bytes);
-
-		//! Creates a clone of this data buffer.
-		//! @note All marks will be moved into the new databuffer as marks are
-		//! @note never duplicated.
-		//! @return The newly cloned databuffer.
-		DataBuffer*		clone();
-
-		//! Prints the buffer to stdout. Useful for debugging.
-		void			dump();
-
-		//! Finds the given mark by name.
-		//! @param name the name of the mark to find
-		ByteMark*		findMarkByName (const String& name);
+public:
+	DataBuffer (int size = 128);
+	~DataBuffer();
 
-		//! Merge another data buffer into this one.
-		//! Note: @c other is destroyed in the process.
-		//! @param other the buffer to merge in
-		void			mergeAndDestroy (DataBuffer* other);
-
-		//! Moves @c mark to the given bytecode position.
-		//! @param mark the mark to adjust
-		//! @param position where to adjust the mark
-		void			offsetMark (ByteMark* mark, int position);
-
-		//! Transfers all marks of this buffer to @c other.
-		//! @param other the data buffer to transfer marks to
-		void			transferMarksTo (DataBuffer* other);
-
-		//! Writes the index of the given string to the databuffer.
-		//! 4 bytes will be written to the bytecode.
-		//! @param a the string whose index to write
-		void			writeStringIndex (const String& a);
-
-		//! Writes the given string as-is into the databuffer.
-		//! @c a.length + 4 bytes will be written to the buffer.
-		//! @param a the string to write
-		void			writeString (const String& a);
+	ByteMark*		addMark (const String& name);
+	MarkReference*	addReference (ByteMark* mark);
+	void			adjustMark (ByteMark* mark);
+	void			checkSpace (int bytes);
+	DataBuffer*		clone();
+	void			dump();
+	ByteMark*		findMarkByName (const String& name);
+	void			mergeAndDestroy (DataBuffer* other);
+	void			offsetMark (ByteMark* mark, int position);
+	void			transferMarksTo (DataBuffer* other);
+	void			writeStringIndex (const String& a);
+	void			writeString (const String& a);
+	void			writeByte (int8_t data);
+	void			writeWord (int16_t data);
+	void			writeDWord (int32_t data);
+	inline int		writtenSize() const;
 
-		//! Writes the given byte to the buffer. 1 byte will be written.
-		//! @c data the byte to write
-		void			writeByte (int8_t data);
-
-		//! Writes the given word to the buffer. 2 byte will be written.
-		//! @c data the word to write
-		void			writeWord (int16_t data);
-
-		//! Writes the given double word to the buffer. 4 bytes will be written.
-		//! @c data the double word to write
-		void			writeDWord (int32_t data);
-
-		//! @return the amount of bytes written to this buffer.
-		inline int		writtenSize() const
-		{
-			return position() - buffer();
-		}
-
-	protected:
-		//! Writes the buffer's contents from @c buf.
-		//! @c buf.writtenSize() bytes will be written.
-		//! @param buf the buffer to copy
-		void			copyBuffer (const DataBuffer* buf);
+private:
+	void			copyBuffer (const DataBuffer* buf);
 };
 
+// ------------------------------------------------------------------------------------------------
+//
+//	Returns the amount of bytes written into the buffer.
+//
+inline int DataBuffer::writtenSize() const
+{
+	return position() - buffer();
+}
+
 #endif // BOTC_DATABUFFER_H
--- a/src/events.cpp	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/events.cpp	Sun Jul 20 17:25:36 2014 +0300
@@ -35,13 +35,13 @@
 #include "events.h"
 #include "lexer.h"
 
-static List<EventDefinition*> g_Events;
+static List<EventDefinition*> Events;
 
 // ============================================================================
 //
 void addEvent (EventDefinition* e)
 {
-	g_Events << e;
+	Events << e;
 }
 
 // ============================================================================
@@ -50,7 +50,7 @@
 //
 EventDefinition* findEventByIndex (int idx)
 {
-	return g_Events[idx];
+	return Events[idx];
 }
 
 // ============================================================================
@@ -59,9 +59,11 @@
 //
 EventDefinition* findEventByName (String a)
 {
-	for (EventDefinition* e : g_Events)
+	for (EventDefinition* e : Events)
+	{
 		if (a.toUppercase() == e->name.toUppercase())
 			return e;
+	}
 
 	return null;
 }
--- a/src/expression.cpp	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/expression.cpp	Sun Jul 20 17:25:36 2014 +0300
@@ -4,7 +4,7 @@
 
 struct OperatorInfo
 {
-	ETokenType	token;
+	Token	token;
 	int			priority;
 	int			numoperands;
 	DataHeader	header;
@@ -12,30 +12,30 @@
 
 static const OperatorInfo g_Operators[] =
 {
-	{TK_ExclamationMark,	0,		1,	DH_NegateLogical,	},
-	{TK_Minus,				0,		1,	DH_UnaryMinus,		},
-	{TK_Multiply,			10,		2,	DH_Multiply,		},
-	{TK_Divide,				10,		2,	DH_Divide,			},
-	{TK_Modulus,			10,		2,	DH_Modulus,			},
-	{TK_Plus,				20,		2,	DH_Add,				},
-	{TK_Minus,				20,		2,	DH_Subtract,		},
-	{TK_LeftShift,			30,		2,	DH_LeftShift,		},
-	{TK_RightShift,			30,		2,	DH_RightShift,		},
-	{TK_Lesser,				40,		2,	DH_LessThan,		},
-	{TK_Greater,			40,		2,	DH_GreaterThan,		},
-	{TK_AtLeast,			40,		2,	DH_AtLeast,			},
-	{TK_AtMost,				40,		2,	DH_AtMost,			},
-	{TK_Equals,				50,		2,	DH_Equals			},
-	{TK_NotEquals,			50,		2,	DH_NotEquals		},
-	{TK_Amperstand,			60,		2,	DH_AndBitwise		},
-	{TK_Caret,				70,		2,	DH_EorBitwise		},
-	{TK_Bar,				80,		2,	DH_OrBitwise		},
-	{TK_DoubleAmperstand,	90,		2,	DH_AndLogical		},
-	{TK_DoubleBar,			100,	2,	DH_OrLogical		},
-	{TK_QuestionMark,		110,	3,	(DataHeader) 0		},
+	{Token::ExclamationMark,	0,		1,	DataHeader::NegateLogical,	},
+	{Token::Minus,				0,		1,	DataHeader::UnaryMinus,		},
+	{Token::Multiply,			10,		2,	DataHeader::Multiply,		},
+	{Token::Divide,				10,		2,	DataHeader::Divide,			},
+	{Token::Modulus,			10,		2,	DataHeader::Modulus,		},
+	{Token::Plus,				20,		2,	DataHeader::Add,			},
+	{Token::Minus,				20,		2,	DataHeader::Subtract,		},
+	{Token::LeftShift,			30,		2,	DataHeader::LeftShift,		},
+	{Token::RightShift,			30,		2,	DataHeader::RightShift,		},
+	{Token::Lesser,				40,		2,	DataHeader::LessThan,		},
+	{Token::Greater,			40,		2,	DataHeader::GreaterThan,	},
+	{Token::AtLeast,			40,		2,	DataHeader::AtLeast,		},
+	{Token::AtMost,				40,		2,	DataHeader::AtMost,			},
+	{Token::Equals,				50,		2,	DataHeader::Equals			},
+	{Token::NotEquals,			50,		2,	DataHeader::NotEquals		},
+	{Token::Amperstand,			60,		2,	DataHeader::AndBitwise		},
+	{Token::Caret,				70,		2,	DataHeader::EorBitwise		},
+	{Token::Bar,				80,		2,	DataHeader::OrBitwise		},
+	{Token::DoubleAmperstand,	90,		2,	DataHeader::AndLogical		},
+	{Token::DoubleBar,			100,	2,	DataHeader::OrLogical		},
+	{Token::QuestionMark,		110,	3,	DataHeader::NumDataHeaders	},
 };
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 Expression::Expression (BotscriptParser* parser, Lexer* lx, DataType reqtype) :
 	m_parser (parser),
@@ -58,7 +58,7 @@
 	evaluate();
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 Expression::~Expression()
 {
@@ -66,7 +66,7 @@
 		delete sym;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 // Try to parse an expression symbol (i.e. an operator or operand or a colon)
 // from the lexer.
@@ -76,19 +76,21 @@
 	int pos = m_lexer->position();
 	ExpressionValue* op = null;
 
-	if (m_lexer->next (TK_Colon))
+	if (m_lexer->next (Token::Colon))
 		return new ExpressionColon;
 
 	// Check for operator
 	for (const OperatorInfo& op : g_Operators)
+	{
 		if (m_lexer->next (op.token))
 			return new ExpressionOperator ((ExpressionOperatorType) (&op - &g_Operators[0]));
+	}
 
 	// Check sub-expression
-	if (m_lexer->next (TK_ParenStart))
+	if (m_lexer->next (Token::ParenStart))
 	{
 		Expression expr (m_parser, m_lexer, m_type);
-		m_lexer->mustGetNext (TK_ParenEnd);
+		m_lexer->mustGetNext (Token::ParenEnd);
 		return expr.getResult()->clone();
 	}
 
@@ -99,7 +101,7 @@
 	{
 		m_lexer->skip();
 
-		if (m_type != TYPE_Unknown && comm->returnvalue != m_type)
+		if (m_type != TYPE_Unknown and comm->returnvalue != m_type)
 			error ("%1 returns an incompatible data type", comm->name);
 
 		op->setBuffer (m_parser->parseCommand (comm));
@@ -107,39 +109,43 @@
 	}
 
 	// Check for variables
-	if (m_lexer->next (TK_DollarSign))
+	if (m_lexer->next (Token::DollarSign))
 	{
-		m_lexer->mustGetNext (TK_Symbol);
+		m_lexer->mustGetNext (Token::Symbol);
 		Variable* var = m_parser->findVariable (getTokenString());
 
 		if (var == null)
 			error ("unknown variable %1", getTokenString());
 
 		if (var->type != m_type)
+		{
 			error ("expression requires %1, variable $%2 is of type %3",
 				dataTypeName (m_type), var->name, dataTypeName (var->type));
+		}
 
 		if (var->isarray)
 		{
-			m_lexer->mustGetNext (TK_BracketStart);
+			m_lexer->mustGetNext (Token::BracketStart);
 			Expression expr (m_parser, m_lexer, TYPE_Int);
 			expr.getResult()->convertToBuffer();
 			DataBuffer* buf = expr.getResult()->buffer()->clone();
-			buf->writeDWord (DH_PushGlobalArray);
+			buf->writeDWord (DataHeader::PushGlobalArray);
 			buf->writeDWord (var->index);
 			op->setBuffer (buf);
-			m_lexer->mustGetNext (TK_BracketEnd);
+			m_lexer->mustGetNext (Token::BracketEnd);
 		}
 		elif (var->writelevel == WRITE_Constexpr)
+		{
 			op->setValue (var->value);
+		}
 		else
 		{
 			DataBuffer* buf = new DataBuffer (8);
 
-			if (var->IsGlobal())
-				buf->writeDWord (DH_PushGlobalVar);
+			if (var->isGlobal())
+				buf->writeDWord (DataHeader::PushGlobalVar);
 			else
-				buf->writeDWord (DH_PushLocalVar);
+				buf->writeDWord (DataHeader::PushLocalVar);
 
 			buf->writeDWord (var->index);
 			op->setBuffer (buf);
@@ -154,23 +160,24 @@
 		case TYPE_Void:
 		case TYPE_Unknown:
 		{
-			error ("unknown identifier `%1` (expected keyword, function or variable)", getTokenString());
+			error ("unknown identifier `%1` (expected keyword, function or variable)",
+				getTokenString());
 			break;
 		}
 
 		case TYPE_Bool:
 		{
-			if (m_lexer->next (TK_True) || m_lexer->next (TK_False))
+			if (m_lexer->next (Token::True) or m_lexer->next (Token::False))
 			{
-				ETokenType tt = m_lexer->tokenType();
-				op->setValue (tt == TK_True ? 1 : 0);
+				Token tt = m_lexer->tokenType();
+				op->setValue (tt == Token::True ? 1 : 0);
 				return op;
 			}
 		}
 
 		case TYPE_Int:
 		{
-			if (m_lexer->next (TK_Number))
+			if (m_lexer->next (Token::Number))
 			{
 				op->setValue (getTokenString().toLong());
 				return op;
@@ -179,7 +186,7 @@
 
 		case TYPE_String:
 		{
-			if (m_lexer->next (TK_String))
+			if (m_lexer->next (Token::String))
 			{
 				op->setValue (getStringTableIndex (getTokenString()));
 				return op;
@@ -193,11 +200,11 @@
 	return null;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 // The symbol parsing process only does token-based checking for operators.
 // Thus ALL minus operators are actually unary minuses simply because both
-// have TK_Minus as their token and the unary minus is prior to the binary minus
+// have Token::Minus as their token and the unary minus is prior to the binary minus
 // in the operator table. Now that we have all symbols present, we can
 // correct cases like this.
 //
@@ -212,12 +219,12 @@
 
 		// Unary minus with a value as the previous symbol cannot really be
 		// unary; replace with binary minus.
-		if (op->id() == OPER_UnaryMinus && (*(it - 1))->type() == EXPRSYM_Value)
+		if (op->id() == OPER_UnaryMinus and (*(it - 1))->type() == EXPRSYM_Value)
 			op->setID (OPER_Subtraction);
 	}
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 // Verifies a single value. Helper function for Expression::verify.
 //
@@ -225,7 +232,7 @@
 {
 	// If it's an unary operator we skip to its value. The actual operator will
 	// be verified separately.
-	if ((*it)->type() == EXPRSYM_Operator &&
+	if ((*it)->type() == EXPRSYM_Operator and
 			g_Operators[static_cast<ExpressionOperator*> (*it)->id()].numoperands == 1)
 	{
 		++it;
@@ -240,7 +247,7 @@
 	verified[i] = true;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 // Ensures the expression is valid and well-formed and not OMGWTFBBQ. Throws an
 // error if this is not the case.
@@ -283,8 +290,8 @@
 				// -	neither symbol overlaps with something already verified
 				tryVerifyValue (verified, it + 1);
 
-				if (it == last || verified[i] == true)
-					error ("malformed expression");
+				if (it == last or verified[i] == true)
+					error ("ill-formed expression");
 
 				verified[i] = true;
 				break;
@@ -298,8 +305,8 @@
 				// -	none of the three tokens are already verified
 				//
 				// Basically similar logic as above.
-				if (it == first || it == last || verified[i] == true)
-					error ("malformed expression");
+				if (it == first or it == last or verified[i] == true)
+					error ("ill-formed expression");
 
 				tryVerifyValue (verified, it + 1);
 				tryVerifyValue (verified, it - 1);
@@ -327,13 +334,13 @@
 				tryVerifyValue (verified, it + 1);
 				tryVerifyValue (verified, it + 3);
 
-				if (it == first ||
-					it >= m_symbols.end() - 3 ||
-					verified[i] == true ||
-					verified[i + 2] == true ||
-					(*(it + 2))->type() != EXPRSYM_Colon)
+				if (it == first
+					or it >= m_symbols.end() - 3
+					or verified[i] == true
+					or verified[i + 2] == true
+					or (*(it + 2))->type() != EXPRSYM_Colon)
 				{
-					error ("malformed expression");
+					error ("ill-formed expression");
 				}
 
 				verified[i] = true;
@@ -347,14 +354,16 @@
 	}
 
 	for (int i = 0; i < m_symbols.size(); ++i)
+	{
 		if (verified[i] == false)
 			error ("malformed expression: expr symbol #%1 is was left unverified", i);
+	}
 
 	delete verified;
 }
 
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 // Which operator to evaluate?
 //
@@ -381,7 +390,7 @@
 	return best;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 // Process the given operator and values into a new value.
 //
@@ -392,19 +401,22 @@
 	bool isconstexpr = true;
 	ASSERT_EQ (values.size(), info->numoperands)
 
+	// See whether the values are constexpr
 	for (ExpressionValue* val : values)
 	{
-		if (val->isConstexpr() == false)
+		if (not val->isConstexpr())
 		{
 			isconstexpr = false;
 			break;
 		}
 	}
 
-	// If not all of the values are constant expressions, none of them shall be.
-	if (isconstexpr == false)
+	// If not all of the values are constexpr, none of them shall be.
+	if (not isconstexpr)
+	{
 		for (ExpressionValue* val : values)
 			val->convertToBuffer();
+	}
 
 	ExpressionValue* newval = new ExpressionValue (m_type);
 
@@ -417,10 +429,8 @@
 
 		if (op->id() == OPER_Ternary)
 		{
-			// There isn't a dataheader for ternary operator. Instead, we use DH_IfNotGoto
-			// to create an "if-block" inside an expression.
-			// Behold, big block of writing madness! :P
-			//
+			// There isn't a dataheader for ternary operator. Instead, we use DataHeader::IfNotGoto
+			// to create an "if-block" inside an expression. Behold, big block of writing madness!
 			DataBuffer* buf = newval->buffer();
 			DataBuffer* b0 = values[0]->buffer();
 			DataBuffer* b1 = values[1]->buffer();
@@ -428,10 +438,10 @@
 			ByteMark* mark1 = buf->addMark (""); // start of "else" case
 			ByteMark* mark2 = buf->addMark (""); // end of expression
 			buf->mergeAndDestroy (b0);
-			buf->writeDWord (DH_IfNotGoto); // if the first operand (condition)
+			buf->writeDWord (DataHeader::IfNotGoto); // if the first operand (condition)
 			buf->addReference (mark1); // didn't eval true, jump into mark1
 			buf->mergeAndDestroy (b1); // otherwise, perform second operand (true case)
-			buf->writeDWord (DH_Goto); // afterwards, jump to the end, which is
+			buf->writeDWord (DataHeader::Goto); // afterwards, jump to the end, which is
 			buf->addReference (mark2); // marked by mark2.
 			buf->adjustMark (mark1); // move mark1 at the end of the true case
 			buf->mergeAndDestroy (b2); // perform third operand (false case)
@@ -442,6 +452,8 @@
 		}
 		else
 		{
+			ASSERT_NE (info->header, DataHeader::NumDataHeaders);
+
 			// Generic case: write all arguments and apply the operator's
 			// data header.
 			for (ExpressionValue* val : values)
@@ -484,8 +496,8 @@
 			case OPER_BitwiseAnd:			a = nums[0] & nums[1];					break;
 			case OPER_BitwiseOr:			a = nums[0] | nums[1];					break;
 			case OPER_BitwiseXOr:			a = nums[0] ^ nums[1];					break;
-			case OPER_LogicalAnd:			a = (nums[0] && nums[1]) ? 1 : 0;		break;
-			case OPER_LogicalOr:			a = (nums[0] || nums[1]) ? 1 : 0;		break;
+			case OPER_LogicalAnd:			a = (nums[0] and nums[1]) ? 1 : 0;		break;
+			case OPER_LogicalOr:			a = (nums[0] or nums[1]) ? 1 : 0;		break;
 			case OPER_Ternary:				a = (nums[0] != 0) ? nums[1] : nums[2];	break;
 
 			case OPER_Division:
@@ -518,7 +530,7 @@
 	return newval;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 ExpressionValue* Expression::evaluate()
 {
@@ -585,41 +597,41 @@
 	return val;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 ExpressionValue* Expression::getResult()
 {
 	return static_cast<ExpressionValue*> (m_symbols.first());
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 String Expression::getTokenString()
 {
 	return m_lexer->token()->text;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 ExpressionOperator::ExpressionOperator (ExpressionOperatorType id) :
 	ExpressionSymbol (EXPRSYM_Operator),
 	m_id (id) {}
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 ExpressionValue::ExpressionValue (DataType valuetype) :
 	ExpressionSymbol (EXPRSYM_Value),
 	m_buffer (null),
 	m_valueType (valuetype) {}
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 ExpressionValue::~ExpressionValue()
 {
 	delete m_buffer;
 }
 
-// =============================================================================
+// -------------------------------------------------------------------------------------------------
 //
 void ExpressionValue::convertToBuffer()
 {
@@ -632,15 +644,15 @@
 	{
 		case TYPE_Bool:
 		case TYPE_Int:
-			buffer()->writeDWord (DH_PushNumber);
+			buffer()->writeDWord (DataHeader::PushNumber);
 			buffer()->writeDWord (abs (value()));
 
 			if (value() < 0)
-				buffer()->writeDWord (DH_UnaryMinus);
+				buffer()->writeDWord (DataHeader::UnaryMinus);
 			break;
 
 		case TYPE_String:
-			buffer()->writeDWord (DH_PushStringIndex);
+			buffer()->writeDWord (DataHeader::PushStringIndex);
 			buffer()->writeDWord (value());
 			break;
 
--- a/src/expression.h	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/expression.h	Sun Jul 20 17:25:36 2014 +0300
@@ -45,40 +45,40 @@
 
 class Expression final
 {
-	public:
-		using SymbolList = List<ExpressionSymbol*>;
+public:
+	using SymbolList = List<ExpressionSymbol*>;
 
-		Expression (BotscriptParser* parser, Lexer* lx, DataType reqtype);
-		~Expression();
-		ExpressionValue*		getResult();
+	Expression (BotscriptParser* parser, Lexer* lx, DataType reqtype);
+	~Expression();
+	ExpressionValue*		getResult();
 
-	private:
-		BotscriptParser*		m_parser;
-		Lexer*					m_lexer;
-		SymbolList				m_symbols;
-		DataType				m_type;
-		String					m_badTokenText;
+private:
+	BotscriptParser*		m_parser;
+	Lexer*					m_lexer;
+	SymbolList				m_symbols;
+	DataType				m_type;
+	String					m_badTokenText;
 
-		ExpressionValue*		evaluate(); // Process the expression and yield a result
-		ExpressionSymbol*		parseSymbol();
-		String					getTokenString();
-		void					adjustOperators();
-		void					verify(); // Ensure the expr is valid
-		void					tryVerifyValue (bool* verified, SymbolList::Iterator it);
-		ExpressionValue*		evaluateOperator (const ExpressionOperator* op,
-												  const List<ExpressionValue*>& values);
-		SymbolList::Iterator	findPrioritizedOperator();
+	ExpressionValue*		evaluate(); // Process the expression and yield a result
+	ExpressionSymbol*		parseSymbol();
+	String					getTokenString();
+	void					adjustOperators();
+	void					verify(); // Ensure the expr is valid
+	void					tryVerifyValue (bool* verified, SymbolList::Iterator it);
+	ExpressionValue*		evaluateOperator (const ExpressionOperator* op,
+												const List<ExpressionValue*>& values);
+	SymbolList::Iterator	findPrioritizedOperator();
 };
 
 // =============================================================================
 //
 class ExpressionSymbol
 {
-	public:
-		ExpressionSymbol (ExpressionSymbolType type) :
-			m_type (type) {}
+	PROPERTY (private, ExpressionSymbolType, type, setType, STOCK_WRITE)
 
-	PROPERTY (private, ExpressionSymbolType, type, setType, STOCK_WRITE)
+public:
+	ExpressionSymbol (ExpressionSymbolType type) :
+		m_type (type) {}
 };
 
 // =============================================================================
@@ -87,8 +87,8 @@
 {
 	PROPERTY (public, ExpressionOperatorType, id, setID, STOCK_WRITE)
 
-	public:
-		ExpressionOperator (ExpressionOperatorType id);
+public:
+	ExpressionOperator (ExpressionOperatorType id);
 };
 
 // =============================================================================
@@ -99,21 +99,21 @@
 	PROPERTY (public, DataBuffer*,	buffer,		setBuffer,		STOCK_WRITE)
 	PROPERTY (public, DataType,		valueType,	setValueType,	STOCK_WRITE)
 
-	public:
-		ExpressionValue (DataType valuetype);
-		~ExpressionValue();
+public:
+	ExpressionValue (DataType valuetype);
+	~ExpressionValue();
 
-		void					convertToBuffer();
+	void					convertToBuffer();
 
-		inline ExpressionValue* clone() const
-		{
-			return new ExpressionValue (*this);
-		}
+	inline ExpressionValue* clone() const
+	{
+		return new ExpressionValue (*this);
+	}
 
-		inline bool isConstexpr() const
-		{
-			return buffer() == null;
-		}
+	inline bool isConstexpr() const
+	{
+		return buffer() == null;
+	}
 };
 
 // =============================================================================
@@ -124,9 +124,9 @@
 //
 class ExpressionColon final : public ExpressionSymbol
 {
-	public:
-		ExpressionColon() :
-			ExpressionSymbol (EXPRSYM_Colon) {}
+public:
+	ExpressionColon() :
+		ExpressionSymbol (EXPRSYM_Colon) {}
 };
 
 #endif // BOTC_EXPRESSION_H
--- a/src/format.cpp	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/format.cpp	Sun Jul 20 17:25:36 2014 +0300
@@ -70,7 +70,7 @@
 		char mod = '\0';
 
 		// handle modifiers
-		if (fmt[pos + ofs] == 's' || fmt[pos + ofs] == 'x' || fmt[pos + ofs] == 'd')
+		if (fmt[pos + ofs] == 's' or fmt[pos + ofs] == 'x' or fmt[pos + ofs] == 'd')
 		{
 			mod = fmt[pos + ofs];
 			ofs++;
@@ -111,7 +111,7 @@
 	Lexer* lx = Lexer::getCurrentLexer();
 	String fileinfo;
 
-	if (lx != null && lx->hasValidToken())
+	if (lx != null and lx->hasValidToken())
 	{
 		Lexer::TokenInfo* tk = lx->token();
 		fileinfo = format ("%1:%2:%3: ", tk->file, tk->line, tk->column);
--- a/src/lexer.cpp	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/lexer.cpp	Sun Jul 20 17:25:36 2014 +0300
@@ -63,13 +63,13 @@
 	while (sc.getNextToken())
 	{
 		// Preprocessor commands:
-		if (sc.getTokenType() ==TK_Hash)
+		if (sc.getTokenType() ==Token::Hash)
 		{
-			mustGetFromScanner (sc,TK_Symbol);
+			mustGetFromScanner (sc,Token::Symbol);
 
 			if (sc.getTokenText() == "include")
 			{
-				mustGetFromScanner (sc,TK_String);
+				mustGetFromScanner (sc,Token::String);
 				String fileName = sc.getTokenText();
 
 				if (gFileNameStack.contains (fileName))
@@ -110,7 +110,7 @@
 
 	StringList tokens = header.split (" ");
 
-	if (tokens.size() != 2 || tokens[0] != "#!botc" || tokens[1].isEmpty())
+	if (tokens.size() != 2 or tokens[0] != "#!botc" or tokens[1].isEmpty())
 		return false;
 
 	StringList nums = tokens[1].split (".");
@@ -125,7 +125,7 @@
 	long minor = nums[1].toLong (&okB);
 	long patch = nums[2].toLong (&okC);
 
-	if (!okA || !okB || !okC)
+	if (!okA or !okB or !okC)
 		return false;
 
 	if (VERSION_NUMBER < MAKE_VERSION_NUMBER (major, minor, patch))
@@ -145,7 +145,7 @@
 
 // =============================================================================
 //
-bool Lexer::next (ETokenType req)
+bool Lexer::next (Token req)
 {
 	Iterator pos = m_tokenPosition;
 
@@ -154,7 +154,7 @@
 
 	m_tokenPosition++;
 
-	if (isAtEnd() || (req !=TK_Any && tokenType() != req))
+	if (isAtEnd() or (req !=Token::Any and tokenType() != req))
 	{
 		m_tokenPosition = pos;
 		return false;
@@ -165,24 +165,24 @@
 
 // =============================================================================
 //
-void Lexer::mustGetNext (ETokenType tok)
+void Lexer::mustGetNext (Token tok)
 {
 	if (!next())
 		error ("unexpected EOF");
 
-	if (tok !=TK_Any)
+	if (tok !=Token::Any)
 		tokenMustBe (tok);
 }
 
 // =============================================================================
 // eugh..
 //
-void Lexer::mustGetFromScanner (LexerScanner& sc, ETokenType tt)
+void Lexer::mustGetFromScanner (LexerScanner& sc, Token tt)
 {
 	if (sc.getNextToken() == false)
 		error ("unexpected EOF");
 
-	if (tt != TK_Any && sc.getTokenType() != tt)
+	if (tt != Token::Any and sc.getTokenType() != tt)
 	{
 		// TODO
 		TokenInfo tok;
@@ -199,18 +199,18 @@
 
 // =============================================================================
 //
-void Lexer::mustGetAnyOf (const List<ETokenType>& toks)
+void Lexer::mustGetAnyOf (const List<Token>& toks)
 {
 	if (!next())
 		error ("unexpected EOF");
 
-	for (ETokenType tok : toks)
+	for (Token tok : toks)
 		if (tokenType() == tok)
 			return;
 
 	String toknames;
 
-	for (const ETokenType& tokType : toks)
+	for (const Token& tokType : toks)
 	{
 		if (&tokType == &toks.last())
 			toknames += " or ";
@@ -230,7 +230,7 @@
 	if (!next())
 		error ("unexpected EOF");
 
-	if (tokenType() ==TK_Symbol)
+	if (tokenType() ==Token::Symbol)
 	{
 		for (int i = 0; i < syms.size(); ++i)
 		{
@@ -245,7 +245,7 @@
 
 // =============================================================================
 //
-void Lexer::tokenMustBe (ETokenType tok)
+void Lexer::tokenMustBe (Token tok)
 {
 	if (tokenType() != tok)
 		error ("expected %1, got %2", describeTokenType (tok),
@@ -254,17 +254,17 @@
 
 // =============================================================================
 //
-String Lexer::describeTokenPrivate (ETokenType tokType, Lexer::TokenInfo* tok)
+String Lexer::describeTokenPrivate (Token tokType, Lexer::TokenInfo* tok)
 {
 	if (tokType <gLastNamedToken)
-		return "\"" + LexerScanner::getTokenString (tokType) + "\"";
+		return "\"" + LexerScanner::GetTokenString (tokType) + "\"";
 
 	switch (tokType)
 	{
-		case TK_Symbol:	return tok ? tok->text : "a symbol";
-		case TK_Number:	return tok ? tok->text : "a number";
-		case TK_String:	return tok ? ("\"" + tok->text + "\"") : "a string";
-		case TK_Any:	return tok ? tok->text : "any token";
+		case Token::Symbol:	return tok ? tok->text : "a symbol";
+		case Token::Number:	return tok ? tok->text : "a number";
+		case Token::String:	return tok ? ("\"" + tok->text + "\"") : "a string";
+		case Token::Any:	return tok ? tok->text : "any token";
 		default: break;
 	}
 
@@ -278,7 +278,7 @@
 	Iterator pos = m_tokenPosition;
 	bool r = next();
 
-	if (r && tk != null)
+	if (r and tk != null)
 		*tk = *m_tokenPosition;
 
 	m_tokenPosition = pos;
@@ -287,12 +287,12 @@
 
 // =============================================================================
 //
-bool Lexer::peekNextType (ETokenType req)
+bool Lexer::peekNextType (Token req)
 {
 	Iterator pos = m_tokenPosition;
 	bool result = false;
 
-	if (next() && tokenType() == req)
+	if (next() and tokenType() == req)
 		result = true;
 
 	m_tokenPosition = pos;
@@ -338,7 +338,7 @@
 //
 void Lexer::mustGetSymbol (const String& a)
 {
-	mustGetNext (TK_Any);
+	mustGetNext (Token::Any);
 	if (token()->text != a)
 		error ("expected \"%1\", got \"%2\"", a, token()->text);
 }
--- a/src/lexer.h	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/lexer.h	Sun Jul 20 17:25:36 2014 +0300
@@ -37,7 +37,7 @@
 public:
 	struct TokenInfo
 	{
-		ETokenType	type;
+		Token	type;
 		String		text;
 		String		file;
 		int			line;
@@ -52,14 +52,14 @@
 	~Lexer();
 
 	void	processFile (String fileName);
-	bool	next (ETokenType req = TK_Any);
-	void	mustGetNext (ETokenType tok);
-	void	mustGetAnyOf (const List<ETokenType>& toks);
+	bool	next (Token req = Token::Any);
+	void	mustGetNext (Token tok);
+	void	mustGetAnyOf (const List<Token>& toks);
 	void	mustGetSymbol (const String& a);
 	int		getOneSymbol (const StringList& syms);
-	void	tokenMustBe (ETokenType tok);
+	void	tokenMustBe (Token tok);
 	bool	peekNext (TokenInfo* tk = null);
-	bool	peekNextType (ETokenType req);
+	bool	peekNextType (Token req);
 	String	peekNextString (int a = 1);
 	String	describeCurrentPosition();
 	String	describeTokenPosition();
@@ -68,7 +68,7 @@
 
 	inline bool hasValidToken() const
 	{
-		return (m_tokenPosition < m_tokens.end() && m_tokenPosition >= m_tokens.begin());
+		return (m_tokenPosition < m_tokens.end() and m_tokenPosition >= m_tokens.begin());
 	}
 
 	inline TokenInfo* token() const
@@ -82,7 +82,7 @@
 		return m_tokenPosition == m_tokens.end();
 	}
 
-	inline ETokenType tokenType() const
+	inline Token tokenType() const
 	{
 		return token()->type;
 	}
@@ -103,7 +103,7 @@
 	}
 
 	// If @tok is given, describes the token. If not, describes @tok_type.
-	static inline String describeTokenType (ETokenType toktype)
+	static inline String describeTokenType (Token toktype)
 	{
 		return describeTokenPrivate (toktype, null);
 	}
@@ -118,10 +118,10 @@
 	Iterator		m_tokenPosition;
 
 	// read a mandatory token from scanner
-	void mustGetFromScanner (LexerScanner& sc, ETokenType tt =TK_Any);
+	void mustGetFromScanner (LexerScanner& sc, Token tt =Token::Any);
 	void checkFileHeader (LexerScanner& sc);
 
-	static String describeTokenPrivate (ETokenType tok_type, TokenInfo* tok);
+	static String describeTokenPrivate (Token tok_type, TokenInfo* tok);
 };
 
 #endif // BOTC_LEXER_H
--- a/src/lexerScanner.cpp	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/lexerScanner.cpp	Sun Jul 20 17:25:36 2014 +0300
@@ -48,8 +48,8 @@
 	">>",
 	">=",
 	"<=",
-	"&&",
-	"||",
+	"and",
+	"or",
 	"++",
 	"--",
 	"'",
@@ -144,11 +144,11 @@
 	bool r = strncmp (m_position, c, strlen (c)) == 0;
 
 	// There is to be a non-symbol character after words
-	if (r && (flags & FCheckWord) && isSymbolChar (m_position[strlen (c)], true))
+	if (r and (flags & FCheckWord) and IsSymbolCharacter (m_position[strlen (c)], true))
 		r = false;
 
 	// Advance the cursor unless we want to just peek
-	if (r && !(flags & FCheckPeek))
+	if (r and !(flags & FCheckPeek))
 		m_position += strlen (c);
 
 	return r;
@@ -198,7 +198,7 @@
 		if (checkString (gTokenStrings[i], flags))
 		{
 			m_tokenText = gTokenStrings[i];
-			m_tokenType = (ETokenType) i;
+			m_tokenType = (Token) i;
 			return true;
 		}
 	}
@@ -232,7 +232,7 @@
 			m_tokenText += *m_position++;
 		}
 
-		m_tokenType =TK_String;
+		m_tokenType =Token::String;
 		skip(); // skip the final quote
 		return true;
 	}
@@ -242,17 +242,17 @@
 		while (isdigit (*m_position))
 			m_tokenText += *m_position++;
 
-		m_tokenType =TK_Number;
+		m_tokenType =Token::Number;
 		return true;
 	}
 
-	if (isSymbolChar (*m_position, false))
+	if (IsSymbolCharacter (*m_position, false))
 	{
-		m_tokenType =TK_Symbol;
+		m_tokenType =Token::Symbol;
 
 		do
 		{
-			if (!isSymbolChar (*m_position, true))
+			if (!IsSymbolCharacter (*m_position, true))
 				break;
 
 			m_tokenText += *m_position++;
@@ -288,7 +288,7 @@
 
 // =============================================================================
 //
-String LexerScanner::getTokenString (ETokenType a)
+String LexerScanner::GetTokenString (Token a)
 {
 	ASSERT_LT_EQ (a, gLastNamedToken);
 	return gTokenStrings[a];
--- a/src/lexerScanner.h	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/lexerScanner.h	Sun Jul 20 17:25:36 2014 +0300
@@ -48,13 +48,13 @@
 		FCheckPeek = (1 << 1),   // don't advance cursor
 	};
 
-	static inline bool isSymbolChar (char c, bool allownumbers)
+	static inline bool IsSymbolCharacter (char c, bool allownumbers)
 	{
-		if (allownumbers && (c >= '0' && c <= '9'))
+		if (allownumbers and (c >= '0' and c <= '9'))
 			return true;
 
-		return (c >= 'a' && c <= 'z') ||
-				(c >= 'A' && c <= 'Z') ||
+		return (c >= 'a' and c <= 'z') or
+				(c >= 'A' and c <= 'Z') or
 				(c == '_');
 	}
 
@@ -78,12 +78,12 @@
 		return m_position - m_lineBreakPosition;
 	}
 
-	inline ETokenType getTokenType() const
+	inline Token getTokenType() const
 	{
 		return m_tokenType;
 	}
 
-	static String getTokenString (ETokenType a);
+	static String GetTokenString (Token a);
 
 private:
 	char*			m_data;
@@ -91,7 +91,7 @@
 	char*			m_lineBreakPosition;
 	String			m_tokenText,
 					m_lastToken;
-	ETokenType		m_tokenType;
+	Token		m_tokenType;
 	int				m_line;
 
 	bool			checkString (const char* c, int flags = 0);
--- a/src/list.h	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/list.h	Sun Jul 20 17:25:36 2014 +0300
@@ -45,7 +45,7 @@
 
 	List();
 	List (const std::deque<T>& a);
-	List (std::initializer_list<T>&& a);
+	List (std::initializer_list<T>and a);
 
 	inline T&						append (const T& value);
 	inline Iterator					begin();
@@ -101,7 +101,7 @@
 	_deque (other) {}
 
 template<typename T>
-List<T>::List (std::initializer_list<T>&& a) :
+List<T>::List (std::initializer_list<T>and a) :
 	_deque (a) {}
 
 template<typename T>
--- a/src/macros.h	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/macros.h	Sun Jul 20 17:25:36 2014 +0300
@@ -29,7 +29,7 @@
 #ifndef BOTC_MACROS_H
 #define BOTC_MACROS_H
 
-#if !defined (__cplusplus) || __cplusplus < 201103L
+#if !defined (__cplusplus) or __cplusplus < 201103L
 # error botc requires a C++11-compliant compiler to be built
 #endif
 
@@ -46,7 +46,7 @@
 #define VERSION_NUMBER MAKE_VERSION_NUMBER (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
 
 // On Windows, files are case-insensitive
-#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)
+#if (defined(WIN32) or defined(_WIN32) or defined(__WIN32)) and !defined(__CYGWIN__)
 # define FILE_CASEINSENSITIVE
 #endif
 
@@ -64,7 +64,7 @@
 template<typename... argtypes>
 void error (const char* fmtstr, const argtypes&... args);
 
-#ifdef DEBUG
+#ifndef RELEASE
 # define BOTC_GENERIC_ASSERT(A,B,OP,COMPLAINT) ((A OP B) ? (void) 0 : \
 	error ("assertion failed at " __FILE__ ":" MACRO_TO_STRING(__LINE__) ": " #A " (%1) " COMPLAINT " " #B " (%2)", A, B));
 #else
--- a/src/main.cpp	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/main.cpp	Sun Jul 20 17:25:36 2014 +0300
@@ -42,7 +42,7 @@
 		// Intepret command-line parameters:
 		// -l: list commands
 		// I guess there should be a better way to do this.
-		if (argc == 2 && String (argv[1]) == "-l")
+		if (argc == 2 and String (argv[1]) == "-l")
 		{
 			print ("Begin list of commands:\n");
 			print ("------------------------------------------------------\n");
@@ -115,10 +115,10 @@
 		int globalcount = parser->getHighestVarIndex (true) + 1;
 		int statelocalcount = parser->getHighestVarIndex (false) + 1;
 		int stringcount = countStringsInTable();
-		print ("%1 / %2 strings\n", stringcount, gMaxStringlistSize);
-		print ("%1 / %2 global variable indices\n", globalcount, gMaxGlobalVars);
-		print ("%1 / %2 state variable indices\n", statelocalcount, gMaxGlobalVars);
-		print ("%1 / %2 events\n", parser->numEvents(), gMaxEvents);
+		print ("%1 / %2 strings\n", stringcount, Limits::MaxStringlistSize);
+		print ("%1 / %2 global variable indices\n", globalcount, Limits::MaxGlobalVars);
+		print ("%1 / %2 state variable indices\n", statelocalcount, Limits::MaxStateVars);
+		print ("%1 / %2 events\n", parser->numEvents(), Limits::MaxEvents);
 		print ("%1 state%s1\n", parser->numStates());
 
 		parser->writeToFile (outfile);
@@ -198,11 +198,11 @@
 //
 String versionString (bool longform)
 {
-#if defined(GIT_DESCRIPTION) && defined (DEBUG)
+#if defined(GIT_DESCRIPTION) and defined (DEBUG)
 	String tag (GIT_DESCRIPTION);
 	String version = tag;
 
-	if (longform && tag.endsWith ("-pre"))
+	if (longform and tag.endsWith ("-pre"))
 		version += "-" + String (GIT_HASH).mid (0, 8);
 
 	return version;
--- a/src/parser.cpp	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/parser.cpp	Sun Jul 20 17:25:36 2014 +0300
@@ -97,91 +97,91 @@
 	while (m_lexer->next())
 	{
 		// Check if else is potentically valid
-		if (tokenIs (TK_Else) && m_isElseAllowed == false)
+		if (tokenIs (Token::Else) and m_isElseAllowed == false)
 			error ("else without preceding if");
 
-		if (tokenIs (TK_Else) == false)
+		if (tokenIs (Token::Else) == false)
 			m_isElseAllowed = false;
 
 		switch (m_lexer->token()->type)
 		{
-			case TK_State:
+			case Token::State:
 				parseStateBlock();
 				break;
 
-			case TK_Event:
+			case Token::Event:
 				parseEventBlock();
 				break;
 
-			case TK_Mainloop:
+			case Token::Mainloop:
 				parseMainloop();
 				break;
 
-			case TK_Onenter:
-			case TK_Onexit:
+			case Token::Onenter:
+			case Token::Onexit:
 				parseOnEnterExit();
 				break;
 
-			case TK_Var:
+			case Token::Var:
 				parseVar();
 				break;
 
-			case TK_If:
+			case Token::If:
 				parseIf();
 				break;
 
-			case TK_Else:
+			case Token::Else:
 				parseElse();
 				break;
 
-			case TK_While:
+			case Token::While:
 				parseWhileBlock();
 				break;
 
-			case TK_For:
+			case Token::For:
 				parseForBlock();
 				break;
 
-			case TK_Do:
+			case Token::Do:
 				parseDoBlock();
 				break;
 
-			case TK_Switch:
+			case Token::Switch:
 				parseSwitchBlock();
 				break;
 
-			case TK_Case:
+			case Token::Case:
 				parseSwitchCase();
 				break;
 
-			case TK_Default:
+			case Token::Default:
 				parseSwitchDefault();
 				break;
 
-			case TK_Break:
+			case Token::Break:
 				parseBreak();
 				break;
 
-			case TK_Continue:
+			case Token::Continue:
 				parseContinue();
 				break;
 
-			case TK_BraceEnd:
+			case Token::BraceEnd:
 				parseBlockEnd();
 				break;
 
-			case TK_Eventdef:
+			case Token::Eventdef:
 				parseEventdef();
 				break;
 
-			case TK_Funcdef:
+			case Token::Funcdef:
 				parseFuncdef();
 				break;
 
-			case TK_Semicolon:
+			case Token::Semicolon:
 				break;
 
-			case TK_Using:
+			case Token::Using:
 				parseUsing();
 				break;
 
@@ -193,7 +193,7 @@
 				if (comm)
 				{
 					currentBuffer()->mergeAndDestroy (parseCommand (comm));
-					m_lexer->mustGetNext (TK_Semicolon);
+					m_lexer->mustGetNext (Token::Semicolon);
 					continue;
 				}
 
@@ -208,13 +208,12 @@
 				}
 
 				currentBuffer()->mergeAndDestroy (b);
-				m_lexer->mustGetNext (TK_Semicolon);
+				m_lexer->mustGetNext (Token::Semicolon);
 				break;
 			}
 		}
 	}
 
-	// ===============================================================================
 	// Script file ended. Do some last checks and write the last things to main buffer
 	if (m_currentMode != PARSERMODE_TopLevel)
 		error ("script did not end at top level; a `}` is missing somewhere");
@@ -246,7 +245,7 @@
 void BotscriptParser::parseStateBlock()
 {
 	checkToplevel();
-	m_lexer->mustGetNext (TK_String);
+	m_lexer->mustGetNext (Token::String);
 	String statename = getTokenString();
 
 	// State name must be a word.
@@ -259,16 +258,16 @@
 		m_isStateSpawnDefined = true;
 
 	// Must end in a colon
-	m_lexer->mustGetNext (TK_Colon);
+	m_lexer->mustGetNext (Token::Colon);
 
 	// write the previous state's onenter and
 	// mainloop buffers to file now
 	if (m_currentState.isEmpty() == false)
 		writeMemberBuffers();
 
-	currentBuffer()->writeDWord (DH_StateName);
+	currentBuffer()->writeDWord (DataHeader::StateName);
 	currentBuffer()->writeString (statename);
-	currentBuffer()->writeDWord (DH_StateIndex);
+	currentBuffer()->writeDWord (DataHeader::StateIndex);
 	currentBuffer()->writeDWord (m_numStates);
 
 	m_numStates++;
@@ -281,16 +280,16 @@
 void BotscriptParser::parseEventBlock()
 {
 	checkToplevel();
-	m_lexer->mustGetNext (TK_String);
+	m_lexer->mustGetNext (Token::String);
 
 	EventDefinition* e = findEventByName (getTokenString());
 
 	if (e == null)
 		error ("bad event, got `%1`\n", getTokenString());
 
-	m_lexer->mustGetNext (TK_BraceStart);
+	m_lexer->mustGetNext (Token::BraceStart);
 	m_currentMode = PARSERMODE_Event;
-	currentBuffer()->writeDWord (DH_Event);
+	currentBuffer()->writeDWord (DataHeader::Event);
 	currentBuffer()->writeDWord (e->number);
 	m_numEvents++;
 }
@@ -300,10 +299,10 @@
 void BotscriptParser::parseMainloop()
 {
 	checkToplevel();
-	m_lexer->mustGetNext (TK_BraceStart);
+	m_lexer->mustGetNext (Token::BraceStart);
 
 	m_currentMode = PARSERMODE_MainLoop;
-	m_mainLoopBuffer->writeDWord (DH_MainLoop);
+	m_mainLoopBuffer->writeDWord (DataHeader::MainLoop);
 }
 
 // ============================================================================
@@ -311,11 +310,11 @@
 void BotscriptParser::parseOnEnterExit()
 {
 	checkToplevel();
-	bool onenter = (tokenIs (TK_Onenter));
-	m_lexer->mustGetNext (TK_BraceStart);
+	bool onenter = (tokenIs (Token::Onenter));
+	m_lexer->mustGetNext (Token::BraceStart);
 
 	m_currentMode = onenter ? PARSERMODE_Onenter : PARSERMODE_Onexit;
-	currentBuffer()->writeDWord (onenter ? DH_OnEnter : DH_OnExit);
+	currentBuffer()->writeDWord (onenter ? DataHeader::OnEnter : DataHeader::OnExit);
 }
 
 // ============================================================================
@@ -325,20 +324,28 @@
 	Variable* var = new Variable;
 	var->origin = m_lexer->describeCurrentPosition();
 	var->isarray = false;
-	const bool isconst = m_lexer->next (TK_Const);
-	m_lexer->mustGetAnyOf ({TK_Int,TK_Str,TK_Void});
+	bool isconst = m_lexer->next (Token::Const);
+	m_lexer->mustGetAnyOf ({Token::Int,Token::Str,Token::Void});
+
+	DataType vartype = (tokenIs (Token::Int)) ? TYPE_Int
+					 : (tokenIs (Token::Str)) ? TYPE_String
+					 : TYPE_Bool;
 
-	DataType vartype =	(tokenIs (TK_Int)) ? TYPE_Int :
-					(tokenIs (TK_Str)) ? TYPE_String :
-					TYPE_Bool;
+	if (m_lexer->next (Token::Const))
+	{
+		if (isconst)
+			error ("duplicate const in variable declaration");
 
-	m_lexer->mustGetNext (TK_DollarSign);
-	m_lexer->mustGetNext (TK_Symbol);
+		isconst = true;
+	}
+
+	m_lexer->mustGetNext (Token::DollarSign);
+	m_lexer->mustGetNext (Token::Symbol);
 	String name = getTokenString();
 
-	if (m_lexer->next (TK_BracketStart))
+	if (m_lexer->next (Token::BracketStart))
 	{
-		m_lexer->mustGetNext (TK_BracketEnd);
+		m_lexer->mustGetNext (Token::BracketEnd);
 		var->isarray = true;
 
 		if (isconst)
@@ -348,8 +355,10 @@
 	for (Variable* var : SCOPE(0).globalVariables + SCOPE(0).localVariables)
 	{
 		if (var->name == name)
+		{
 			error ("Variable $%1 is already declared on this scope; declared at %2",
 				var->name, var->origin);
+		}
 	}
 
 	var->name = name;
@@ -362,7 +371,7 @@
 	}
 	else
 	{
-		m_lexer->mustGetNext (TK_Assign);
+		m_lexer->mustGetNext (Token::Assign);
 		Expression expr (this, m_lexer, vartype);
 
 		// If the expression was constexpr, we know its value and thus
@@ -375,7 +384,7 @@
 		else
 		{
 			// TODO: might need a VM-wise oninit for this...
-			error ("const variables must be constexpr");
+			error ("const variables must be constexpr (deductible at compile-time)");
 		}
 	}
 
@@ -387,8 +396,8 @@
 		bool isglobal = isInGlobalState();
 		var->index = isglobal ? SCOPE(0).globalVarIndexBase++ : SCOPE(0).localVarIndexBase++;
 
-		if ((isglobal == true && var->index >= gMaxGlobalVars) ||
-			(isglobal == false && var->index >= gMaxStateVars))
+		if ((isglobal == true and var->index >= Limits::MaxGlobalVars) or
+			(isglobal == false and var->index >= Limits::MaxStateVars))
 		{
 			error ("too many %1 variables", isglobal ? "global" : "state-local");
 		}
@@ -400,7 +409,7 @@
 		SCOPE(0).localVariables << var;
 
 	suggestHighestVarIndex (isInGlobalState(), var->index);
-	m_lexer->mustGetNext (TK_Semicolon);
+	m_lexer->mustGetNext (Token::Semicolon);
 	print ("Declared %3 variable #%1 $%2\n", var->index, var->name, isInGlobalState() ? "global" : "state-local");
 }
 
@@ -412,22 +421,22 @@
 	pushScope();
 
 	// Condition
-	m_lexer->mustGetNext (TK_ParenStart);
+	m_lexer->mustGetNext (Token::ParenStart);
 
 	// Read the expression and write it.
 	DataBuffer* c = parseExpression (TYPE_Int);
 	currentBuffer()->mergeAndDestroy (c);
 
-	m_lexer->mustGetNext (TK_ParenEnd);
-	m_lexer->mustGetNext (TK_BraceStart);
+	m_lexer->mustGetNext (Token::ParenEnd);
+	m_lexer->mustGetNext (Token::BraceStart);
 
 	// Add a mark - to here temporarily - and add a reference to it.
 	// Upon a closing brace, the mark will be adjusted.
 	ByteMark* mark = currentBuffer()->addMark ("");
 
-	// Use DH_IfNotGoto - if the expression is not true, we goto the mark
+	// Use DataHeader::IfNotGoto - if the expression is not true, we goto the mark
 	// we just defined - and this mark will be at the end of the scope block.
-	currentBuffer()->writeDWord (DH_IfNotGoto);
+	currentBuffer()->writeDWord (DataHeader::IfNotGoto);
 	currentBuffer()->addReference (mark);
 
 	// Store it
@@ -440,8 +449,8 @@
 void BotscriptParser::parseElse()
 {
 	checkNotToplevel();
-	m_lexer->mustGetNext (TK_BraceStart);
-	pushScope (eNoReset);
+	m_lexer->mustGetNext (Token::BraceStart);
+	pushScope (true);
 
 	if (SCOPE (0).type != SCOPE_If)
 		error ("else without preceding if");
@@ -451,7 +460,7 @@
 	SCOPE (0).mark2 = currentBuffer()->addMark ("");
 
 	// Instruction to jump to the end after if block is complete
-	currentBuffer()->writeDWord (DH_Goto);
+	currentBuffer()->writeDWord (DataHeader::Goto);
 	currentBuffer()->addReference (SCOPE (0).mark2);
 
 	// Move the ifnot mark here and set type to else
@@ -474,16 +483,16 @@
 	ByteMark* mark2 = currentBuffer()->addMark (""); // end
 
 	// Condition
-	m_lexer->mustGetNext (TK_ParenStart);
+	m_lexer->mustGetNext (Token::ParenStart);
 	DataBuffer* expr = parseExpression (TYPE_Int);
-	m_lexer->mustGetNext (TK_ParenEnd);
-	m_lexer->mustGetNext (TK_BraceStart);
+	m_lexer->mustGetNext (Token::ParenEnd);
+	m_lexer->mustGetNext (Token::BraceStart);
 
 	// write condition
 	currentBuffer()->mergeAndDestroy (expr);
 
 	// Instruction to go to the end if it fails
-	currentBuffer()->writeDWord (DH_IfNotGoto);
+	currentBuffer()->writeDWord (DataHeader::IfNotGoto);
 	currentBuffer()->addReference (mark2);
 
 	// Store the needed stuff
@@ -500,13 +509,13 @@
 	pushScope();
 
 	// Initializer
-	m_lexer->mustGetNext (TK_ParenStart);
+	m_lexer->mustGetNext (Token::ParenStart);
 	DataBuffer* init = parseStatement();
 
 	if (init == null)
 		error ("bad statement for initializer of for");
 
-	m_lexer->mustGetNext (TK_Semicolon);
+	m_lexer->mustGetNext (Token::Semicolon);
 
 	// Condition
 	DataBuffer* cond = parseExpression (TYPE_Int);
@@ -514,7 +523,7 @@
 	if (cond == null)
 		error ("bad statement for condition of for");
 
-	m_lexer->mustGetNext (TK_Semicolon);
+	m_lexer->mustGetNext (Token::Semicolon);
 
 	// Incrementor
 	DataBuffer* incr = parseStatement();
@@ -522,8 +531,8 @@
 	if (incr == null)
 		error ("bad statement for incrementor of for");
 
-	m_lexer->mustGetNext (TK_ParenEnd);
-	m_lexer->mustGetNext (TK_BraceStart);
+	m_lexer->mustGetNext (Token::ParenEnd);
+	m_lexer->mustGetNext (Token::BraceStart);
 
 	// First, write out the initializer
 	currentBuffer()->mergeAndDestroy (init);
@@ -534,7 +543,7 @@
 
 	// Add the condition
 	currentBuffer()->mergeAndDestroy (cond);
-	currentBuffer()->writeDWord (DH_IfNotGoto);
+	currentBuffer()->writeDWord (DataHeader::IfNotGoto);
 	currentBuffer()->addReference (mark2);
 
 	// Store the marks and incrementor
@@ -550,7 +559,7 @@
 {
 	checkNotToplevel();
 	pushScope();
-	m_lexer->mustGetNext (TK_BraceStart);
+	m_lexer->mustGetNext (Token::BraceStart);
 	SCOPE (0).mark1 = currentBuffer()->addMark ("");
 	SCOPE (0).type = SCOPE_Do;
 }
@@ -574,10 +583,10 @@
 
 	checkNotToplevel();
 	pushScope();
-	m_lexer->mustGetNext (TK_ParenStart);
+	m_lexer->mustGetNext (Token::ParenStart);
 	currentBuffer()->mergeAndDestroy (parseExpression (TYPE_Int));
-	m_lexer->mustGetNext (TK_ParenEnd);
-	m_lexer->mustGetNext (TK_BraceStart);
+	m_lexer->mustGetNext (Token::ParenEnd);
+	m_lexer->mustGetNext (Token::BraceStart);
 	SCOPE (0).type = SCOPE_Switch;
 	SCOPE (0).mark1 = currentBuffer()->addMark (""); // end mark
 	SCOPE (0).buffer1 = null; // default header
@@ -593,13 +602,15 @@
 
 	// Get a literal value for the case block. Zandronum does not support
 	// expressions here.
-	m_lexer->mustGetNext (TK_Number);
+	m_lexer->mustGetNext (Token::Number);
 	int num = m_lexer->token()->text.toLong();
-	m_lexer->mustGetNext (TK_Colon);
+	m_lexer->mustGetNext (Token::Colon);
 
 	for (const CaseInfo& info : SCOPE(0).cases)
+	{
 		if (info.number == num)
 			error ("multiple case %1 labels in one switch", num);
+	}
 
 	// Write down the expression and case-go-to. This builds
 	// the case tree. The closing event will write the actual
@@ -612,7 +623,7 @@
 	// We null the switch buffer for the case-go-to statement as
 	// we want it all under the switch, not into the case-buffers.
 	m_switchBuffer = null;
-	currentBuffer()->writeDWord (DH_CaseGoto);
+	currentBuffer()->writeDWord (DataHeader::CaseGoto);
 	currentBuffer()->writeDWord (num);
 	addSwitchCase (null);
 	SCOPE (0).casecursor->number = num;
@@ -628,19 +639,19 @@
 	if (SCOPE (0).buffer1 != null)
 		error ("multiple default labels in one switch");
 
-	m_lexer->mustGetNext (TK_Colon);
+	m_lexer->mustGetNext (Token::Colon);
 
 	// The default header is buffered into buffer1, since
 	// it has to be the last of the case headers
 	//
 	// Since the expression is pushed into the switch
 	// and is only popped when case succeeds, we have
-	// to pop it with DH_Drop manually if we end up in
+	// to pop it with DataHeader::Drop manually if we end up in
 	// a default.
 	DataBuffer* buf = new DataBuffer;
 	SCOPE (0).buffer1 = buf;
-	buf->writeDWord (DH_Drop);
-	buf->writeDWord (DH_Goto);
+	buf->writeDWord (DataHeader::Drop);
+	buf->writeDWord (DataHeader::Goto);
 	addSwitchCase (buf);
 }
 
@@ -651,7 +662,7 @@
 	if (m_scopeCursor == 0)
 		error ("unexpected `break`");
 
-	currentBuffer()->writeDWord (DH_Goto);
+	currentBuffer()->writeDWord (DataHeader::Goto);
 
 	// switch and if use mark1 for the closing point,
 	// for and while use mark2.
@@ -659,47 +670,43 @@
 	{
 		case SCOPE_If:
 		case SCOPE_Switch:
-		{
 			currentBuffer()->addReference (SCOPE (0).mark1);
-		} break;
+			break;
 
 		case SCOPE_For:
 		case SCOPE_While:
-		{
 			currentBuffer()->addReference (SCOPE (0).mark2);
-		} break;
+			break;
 
 		default:
-		{
 			error ("unexpected `break`");
-		} break;
+			break;
 	}
 
-	m_lexer->mustGetNext (TK_Semicolon);
+	m_lexer->mustGetNext (Token::Semicolon);
 }
 
 // ============================================================================
 //
 void BotscriptParser::parseContinue()
 {
-	m_lexer->mustGetNext (TK_Semicolon);
+	m_lexer->mustGetNext (Token::Semicolon);
 
 	int curs;
 	bool found = false;
 
 	// Fall through the scope until we find a loop block
-	for (curs = m_scopeCursor; curs > 0 && !found; curs--)
+	for (curs = m_scopeCursor; curs > 0 and !found; curs--)
 	{
 		switch (m_scopeStack[curs].type)
 		{
 			case SCOPE_For:
 			case SCOPE_While:
 			case SCOPE_Do:
-			{
-				currentBuffer()->writeDWord (DH_Goto);
+				currentBuffer()->writeDWord (DataHeader::Goto);
 				currentBuffer()->addReference (m_scopeStack[curs].mark1);
 				found = true;
-			} break;
+				break;
 
 			default:
 				break;
@@ -745,7 +752,7 @@
 			}
 			case SCOPE_While:
 			{	// write down the instruction to go back to the start of the loop
-				currentBuffer()->writeDWord (DH_Goto);
+				currentBuffer()->writeDWord (DataHeader::Goto);
 				currentBuffer()->addReference (SCOPE (0).mark1);
 
 				// Move the closing mark here since we're at the end of the while loop
@@ -755,15 +762,15 @@
 
 			case SCOPE_Do:
 			{
-				m_lexer->mustGetNext (TK_While);
-				m_lexer->mustGetNext (TK_ParenStart);
+				m_lexer->mustGetNext (Token::While);
+				m_lexer->mustGetNext (Token::ParenStart);
 				DataBuffer* expr = parseExpression (TYPE_Int);
-				m_lexer->mustGetNext (TK_ParenEnd);
-				m_lexer->mustGetNext (TK_Semicolon);
+				m_lexer->mustGetNext (Token::ParenEnd);
+				m_lexer->mustGetNext (Token::Semicolon);
 
 				// If the condition runs true, go back to the start.
 				currentBuffer()->mergeAndDestroy (expr);
-				currentBuffer()->writeDWord (DH_IfGoto);
+				currentBuffer()->writeDWord (DataHeader::IfGoto);
 				currentBuffer()->addReference (SCOPE (0).mark1);
 				break;
 			}
@@ -784,8 +791,8 @@
 					currentBuffer()->mergeAndDestroy (SCOPE (0).buffer1);
 				else
 				{
-					currentBuffer()->writeDWord (DH_Drop);
-					currentBuffer()->writeDWord (DH_Goto);
+					currentBuffer()->writeDWord (DataHeader::Drop);
+					currentBuffer()->writeDWord (DataHeader::Goto);
 					currentBuffer()->addReference (SCOPE (0).mark1);
 				}
 
@@ -811,10 +818,11 @@
 		return;
 	}
 
-	int dataheader =	(m_currentMode == PARSERMODE_Event) ? DH_EndEvent :
-						(m_currentMode == PARSERMODE_MainLoop) ? DH_EndMainLoop :
-						(m_currentMode == PARSERMODE_Onenter) ? DH_EndOnEnter :
-						(m_currentMode == PARSERMODE_Onexit) ? DH_EndOnExit : -1;
+	int dataheader = (m_currentMode == PARSERMODE_Event) ? DataHeader::EndEvent
+				   : (m_currentMode == PARSERMODE_MainLoop) ? DataHeader::EndMainLoop
+				   : (m_currentMode == PARSERMODE_Onenter) ? DataHeader::EndOnEnter
+				   : (m_currentMode == PARSERMODE_Onexit) ? DataHeader::EndOnExit
+				   : -1;
 
 	if (dataheader == -1)
 		error ("unexpected `}`");
@@ -824,7 +832,7 @@
 	// the closing data headers into said buffers too.
 	currentBuffer()->writeDWord (dataheader);
 	m_currentMode = PARSERMODE_TopLevel;
-	m_lexer->next (TK_Semicolon);
+	m_lexer->next (Token::Semicolon);
 }
 
 // =============================================================================
@@ -833,14 +841,14 @@
 {
 	EventDefinition* e = new EventDefinition;
 
-	m_lexer->mustGetNext (TK_Number);
+	m_lexer->mustGetNext (Token::Number);
 	e->number = getTokenString().toLong();
-	m_lexer->mustGetNext (TK_Colon);
-	m_lexer->mustGetNext (TK_Symbol);
+	m_lexer->mustGetNext (Token::Colon);
+	m_lexer->mustGetNext (Token::Symbol);
 	e->name = m_lexer->token()->text;
-	m_lexer->mustGetNext (TK_ParenStart);
-	m_lexer->mustGetNext (TK_ParenEnd);
-	m_lexer->mustGetNext (TK_Semicolon);
+	m_lexer->mustGetNext (Token::ParenStart);
+	m_lexer->mustGetNext (Token::ParenEnd);
+	m_lexer->mustGetNext (Token::Semicolon);
 	addEvent (e);
 }
 
@@ -852,48 +860,48 @@
 	comm->origin = m_lexer->describeCurrentPosition();
 
 	// Return value
-	m_lexer->mustGetAnyOf ({TK_Int,TK_Void,TK_Bool,TK_Str});
+	m_lexer->mustGetAnyOf ({Token::Int,Token::Void,Token::Bool,Token::Str});
 	comm->returnvalue = getTypeByName (m_lexer->token()->text); // TODO
 	ASSERT_NE (comm->returnvalue, -1);
 
 	// Number
-	m_lexer->mustGetNext (TK_Number);
+	m_lexer->mustGetNext (Token::Number);
 	comm->number = m_lexer->token()->text.toLong();
-	m_lexer->mustGetNext (TK_Colon);
+	m_lexer->mustGetNext (Token::Colon);
 
 	// Name
-	m_lexer->mustGetNext (TK_Symbol);
+	m_lexer->mustGetNext (Token::Symbol);
 	comm->name = m_lexer->token()->text;
 
 	// Arguments
-	m_lexer->mustGetNext (TK_ParenStart);
+	m_lexer->mustGetNext (Token::ParenStart);
 	comm->minargs = 0;
 
-	while (m_lexer->peekNextType (TK_ParenEnd) == false)
+	while (m_lexer->peekNextType (Token::ParenEnd) == false)
 	{
 		if (comm->args.isEmpty() == false)
-			m_lexer->mustGetNext (TK_Comma);
+			m_lexer->mustGetNext (Token::Comma);
 
 		CommandArgument arg;
-		m_lexer->mustGetAnyOf ({TK_Int,TK_Bool,TK_Str});
+		m_lexer->mustGetAnyOf ({Token::Int,Token::Bool,Token::Str});
 		DataType type = getTypeByName (m_lexer->token()->text); // TODO
 		ASSERT_NE (type, -1)
 		ASSERT_NE (type, TYPE_Void)
 		arg.type = type;
 
-		m_lexer->mustGetNext (TK_Symbol);
+		m_lexer->mustGetNext (Token::Symbol);
 		arg.name = m_lexer->token()->text;
 
 		// If this is an optional parameter, we need the default value.
-		if (comm->minargs < comm->args.size() || m_lexer->peekNextType (TK_Assign))
+		if (comm->minargs < comm->args.size() or m_lexer->peekNextType (Token::Assign))
 		{
-			m_lexer->mustGetNext (TK_Assign);
+			m_lexer->mustGetNext (Token::Assign);
 
 			switch (type)
 			{
 				case TYPE_Int:
 				case TYPE_Bool:
-					m_lexer->mustGetNext (TK_Number);
+					m_lexer->mustGetNext (Token::Number);
 					break;
 
 				case TYPE_String:
@@ -912,8 +920,8 @@
 		comm->args << arg;
 	}
 
-	m_lexer->mustGetNext (TK_ParenEnd);
-	m_lexer->mustGetNext (TK_Semicolon);
+	m_lexer->mustGetNext (Token::ParenEnd);
+	m_lexer->mustGetNext (Token::Semicolon);
 	addCommandDefinition (comm);
 }
 
@@ -927,19 +935,20 @@
 	m_lexer->mustGetSymbol ("zandronum");
 	String versionText;
 
-	while (m_lexer->next() && (m_lexer->tokenType() == TK_Number || m_lexer->tokenType() == TK_Dot))
+	while (m_lexer->next() and (m_lexer->tokenType() == Token::Number or m_lexer->tokenType() == Token::Dot))
 		versionText += getTokenString();
 
 	// Note: at this point the lexer's pointing at the token after the version.
 	if (versionText.isEmpty())
 		error ("expected version string, got `%1`", getTokenString());
+
 	if (g_validZandronumVersions.contains (versionText) == false)
 		error ("unknown version string `%2`: valid versions: `%1`\n", g_validZandronumVersions, versionText);
 
 	StringList versionTokens = versionText.split (".");
 	m_zandronumVersion = versionTokens[0].toLong() * 10000 + versionTokens[1].toLong() * 100;
 	m_defaultZandronumVersion = false;
-	m_lexer->tokenMustBe (TK_Semicolon);
+	m_lexer->tokenMustBe (Token::Semicolon);
 }
 
 // ============================================================================/
@@ -950,21 +959,23 @@
 {
 	DataBuffer* r = new DataBuffer (64);
 
-	if (m_currentMode == PARSERMODE_TopLevel && comm->returnvalue == TYPE_Void)
+	if (m_currentMode == PARSERMODE_TopLevel and comm->returnvalue == TYPE_Void)
 		error ("command call at top level");
 
-	m_lexer->mustGetNext (TK_ParenStart);
-	m_lexer->mustGetNext (TK_Any);
+	m_lexer->mustGetNext (Token::ParenStart);
+	m_lexer->mustGetNext (Token::Any);
 
 	int curarg = 0;
 
 	for (;;)
 	{
-		if (tokenIs (TK_ParenEnd))
+		if (tokenIs (Token::ParenEnd))
 		{
 			if (curarg < comm->minargs)
+			{
 				error ("too few arguments passed to %1\n\tusage is: %2",
 					comm->name, comm->signature());
+			}
 
 			break;
 		}
@@ -974,25 +985,25 @@
 				comm->name, comm->signature());
 
 		r->mergeAndDestroy (parseExpression (comm->args[curarg].type, true));
-		m_lexer->mustGetNext (TK_Any);
+		m_lexer->mustGetNext (Token::Any);
 
 		if (curarg < comm->minargs - 1)
 		{
-			m_lexer->tokenMustBe (TK_Comma);
-			m_lexer->mustGetNext (TK_Any);
+			m_lexer->tokenMustBe (Token::Comma);
+			m_lexer->mustGetNext (Token::Any);
 		}
 		else if (curarg < comm->args.size() - 1)
 		{
 			// Can continue, but can terminate as well.
-			if (tokenIs (TK_ParenEnd))
+			if (tokenIs (Token::ParenEnd))
 			{
 				curarg++;
 				break;
 			}
 			else
 			{
-				m_lexer->tokenMustBe (TK_Comma);
-				m_lexer->mustGetNext (TK_Any);
+				m_lexer->tokenMustBe (Token::Comma);
+				m_lexer->mustGetNext (Token::Any);
 			}
 		}
 
@@ -1002,12 +1013,12 @@
 	// If the script skipped any optional arguments, fill in defaults.
 	while (curarg < comm->args.size())
 	{
-		r->writeDWord (DH_PushNumber);
+		r->writeDWord (DataHeader::PushNumber);
 		r->writeDWord (comm->args[curarg].defvalue);
 		curarg++;
 	}
 
-	r->writeDWord (DH_Command);
+	r->writeDWord (DataHeader::Command);
 	r->writeDWord (comm->number);
 	r->writeDWord (comm->args.size());
 
@@ -1018,15 +1029,15 @@
 //
 String BotscriptParser::parseFloat()
 {
-	m_lexer->tokenMustBe (TK_Number);
+	m_lexer->tokenMustBe (Token::Number);
 	String floatstring = getTokenString();
 	Lexer::TokenInfo tok;
 
 	// Go after the decimal point
-	if (m_lexer->peekNext (&tok) && tok.type ==TK_Dot)
+	if (m_lexer->peekNext (&tok) and tok.type ==Token::Dot)
 	{
 		m_lexer->skip();
-		m_lexer->mustGetNext (TK_Number);
+		m_lexer->mustGetNext (Token::Number);
 		floatstring += ".";
 		floatstring += getTokenString();
 	}
@@ -1040,30 +1051,30 @@
 //
 AssignmentOperator BotscriptParser::parseAssignmentOperator()
 {
-	const List<ETokenType> tokens =
+	const List<Token> tokens =
 	{
-		TK_Assign,
-		TK_AddAssign,
-		TK_SubAssign,
-		TK_MultiplyAssign,
-		TK_DivideAssign,
-		TK_ModulusAssign,
-		TK_DoublePlus,
-		TK_DoubleMinus,
+		Token::Assign,
+		Token::AddAssign,
+		Token::SubAssign,
+		Token::MultiplyAssign,
+		Token::DivideAssign,
+		Token::ModulusAssign,
+		Token::DoublePlus,
+		Token::DoubleMinus,
 	};
 
 	m_lexer->mustGetAnyOf (tokens);
 
 	switch (m_lexer->tokenType())
 	{
-		case TK_Assign:			return ASSIGNOP_Assign;
-		case TK_AddAssign:		return ASSIGNOP_Add;
-		case TK_SubAssign:		return ASSIGNOP_Subtract;
-		case TK_MultiplyAssign:	return ASSIGNOP_Multiply;
-		case TK_DivideAssign:	return ASSIGNOP_Divide;
-		case TK_ModulusAssign:	return ASSIGNOP_Modulus;
-		case TK_DoublePlus:		return ASSIGNOP_Increase;
-		case TK_DoubleMinus:	return ASSIGNOP_Decrease;
+		case Token::Assign:			return ASSIGNOP_Assign;
+		case Token::AddAssign:		return ASSIGNOP_Add;
+		case Token::SubAssign:		return ASSIGNOP_Subtract;
+		case Token::MultiplyAssign:	return ASSIGNOP_Multiply;
+		case Token::DivideAssign:	return ASSIGNOP_Divide;
+		case Token::ModulusAssign:	return ASSIGNOP_Modulus;
+		case Token::DoublePlus:		return ASSIGNOP_Increase;
+		case Token::DoubleMinus:	return ASSIGNOP_Decrease;
 		default: break;
 	}
 
@@ -1083,14 +1094,22 @@
 
 const AssignmentDataHeaderInfo gAssignmentDataHeaders[] =
 {
-	{ ASSIGNOP_Assign,		DH_AssignLocalVar,		DH_AssignGlobalVar,		DH_AssignGlobalArray },
-	{ ASSIGNOP_Add,			DH_AddLocalVar,			DH_AddGlobalVar,		DH_AddGlobalArray },
-	{ ASSIGNOP_Subtract,	DH_SubtractLocalVar,	DH_SubtractGlobalVar,	DH_SubtractGlobalArray },
-	{ ASSIGNOP_Multiply,	DH_MultiplyLocalVar,	DH_MultiplyGlobalVar,	DH_MultiplyGlobalArray },
-	{ ASSIGNOP_Divide,		DH_DivideLocalVar,		DH_DivideGlobalVar,		DH_DivideGlobalArray },
-	{ ASSIGNOP_Modulus,		DH_ModLocalVar,			DH_ModGlobalVar,		DH_ModGlobalArray },
-	{ ASSIGNOP_Increase,	DH_IncreaseLocalVar,	DH_IncreaseGlobalVar,	DH_IncreaseGlobalArray },
-	{ ASSIGNOP_Decrease,	DH_DecreaseLocalVar,	DH_DecreaseGlobalVar,	DH_DecreaseGlobalArray },
+	{ ASSIGNOP_Assign,		DataHeader::AssignLocalVar,		DataHeader::AssignGlobalVar,		
+DataHeader::AssignGlobalArray },
+	{ ASSIGNOP_Add,			DataHeader::AddLocalVar,			DataHeader::AddGlobalVar,		
+DataHeader::AddGlobalArray },
+	{ ASSIGNOP_Subtract,	DataHeader::SubtractLocalVar,	DataHeader::SubtractGlobalVar,	
+DataHeader::SubtractGlobalArray },
+	{ ASSIGNOP_Multiply,	DataHeader::MultiplyLocalVar,	DataHeader::MultiplyGlobalVar,	
+DataHeader::MultiplyGlobalArray },
+	{ ASSIGNOP_Divide,		DataHeader::DivideLocalVar,		DataHeader::DivideGlobalVar,		
+DataHeader::DivideGlobalArray },
+	{ ASSIGNOP_Modulus,		DataHeader::ModLocalVar,			DataHeader::ModGlobalVar,		
+DataHeader::ModGlobalArray },
+	{ ASSIGNOP_Increase,	DataHeader::IncreaseLocalVar,	DataHeader::IncreaseGlobalVar,	
+DataHeader::IncreaseGlobalArray },
+	{ ASSIGNOP_Decrease,	DataHeader::DecreaseLocalVar,	DataHeader::DecreaseGlobalVar,	
+DataHeader::DecreaseGlobalArray },
 };
 
 DataHeader BotscriptParser::getAssigmentDataHeader (AssignmentOperator op, Variable* var)
@@ -1103,7 +1122,7 @@
 		if (var->isarray)
 			return a.array;
 
-		if (var->IsGlobal())
+		if (var->isGlobal())
 			return a.global;
 
 		return a.local;
@@ -1129,11 +1148,11 @@
 
 	if (var->isarray)
 	{
-		m_lexer->mustGetNext (TK_BracketStart);
+		m_lexer->mustGetNext (Token::BracketStart);
 		Expression expr (this, m_lexer, TYPE_Int);
 		expr.getResult()->convertToBuffer();
 		arrayindex = expr.getResult()->buffer()->clone();
-		m_lexer->mustGetNext (TK_BracketEnd);
+		m_lexer->mustGetNext (Token::BracketEnd);
 	}
 
 	// Get an operator
@@ -1146,7 +1165,7 @@
 		retbuf->mergeAndDestroy (arrayindex);
 
 	// Parse the right operand
-	if (oper != ASSIGNOP_Increase && oper != ASSIGNOP_Decrease)
+	if (oper != ASSIGNOP_Increase and oper != ASSIGNOP_Decrease)
 	{
 		DataBuffer* expr = parseExpression (var->type);
 		retbuf->mergeAndDestroy (expr);
@@ -1156,11 +1175,12 @@
 	// <<= and >>= do not have data headers. Solution: expand them.
 	// a <<= b -> a = a << b
 	// a >>= b -> a = a >> b
-	retbuf->WriteDWord (var->IsGlobal() ? DH_PushGlobalVar : DH_PushLocalVar);
+	retbuf->WriteDWord (var->IsGlobal() ? DataHeader::PushGlobalVar : DataHeader::PushLocalVar);
 	retbuf->WriteDWord (var->index);
 	retbuf->MergeAndDestroy (expr);
-	retbuf->WriteDWord ((oper == OPER_ASSIGNLEFTSHIFT) ? DH_LeftShift : DH_RightShift);
-	retbuf->WriteDWord (var->IsGlobal() ? DH_AssignGlobalVar : DH_AssignLocalVar);
+	retbuf->WriteDWord ((oper == OPER_ASSIGNLEFTSHIFT) ? DataHeader::LeftShift : 
+DataHeader::RightShift);
+	retbuf->WriteDWord (var->IsGlobal() ? DataHeader::AssignGlobalVar : DataHeader::AssignLocalVar);
 	retbuf->WriteDWord (var->index);
 #endif
 
@@ -1172,7 +1192,7 @@
 
 // ============================================================================
 //
-void BotscriptParser::pushScope (EReset reset)
+void BotscriptParser::pushScope (bool noreset)
 {
 	m_scopeCursor++;
 
@@ -1180,10 +1200,10 @@
 	{
 		ScopeInfo newscope;
 		m_scopeStack << newscope;
-		reset = SCOPE_Reset;
+		noreset = false;
 	}
 
-	if (reset == SCOPE_Reset)
+	if (not noreset)
 	{
 		ScopeInfo* info = &SCOPE (0);
 		info->type = SCOPE_Unknown;
@@ -1210,7 +1230,7 @@
 DataBuffer* BotscriptParser::parseExpression (DataType reqtype, bool fromhere)
 {
 	// hehe
-	if (fromhere == true)
+	if (fromhere)
 		m_lexer->skip (-1);
 
 	Expression expr (this, m_lexer, reqtype);
@@ -1226,9 +1246,9 @@
 DataBuffer* BotscriptParser::parseStatement()
 {
 	// If it's a variable, expect assignment.
-	if (m_lexer->next (TK_DollarSign))
+	if (m_lexer->next (Token::DollarSign))
 	{
-		m_lexer->mustGetNext (TK_Symbol);
+		m_lexer->mustGetNext (Token::Symbol);
 		Variable* var = findVariable (getTokenString());
 
 		if (var == null)
@@ -1267,7 +1287,7 @@
 
 // ============================================================================
 //
-bool BotscriptParser::tokenIs (ETokenType a)
+bool BotscriptParser::tokenIs (Token a)
 {
 	return (m_lexer->tokenType() == a);
 }
@@ -1310,8 +1330,8 @@
 	// If there was no mainloop defined, write a dummy one now.
 	if (m_gotMainLoop == false)
 	{
-		m_mainLoopBuffer->writeDWord (DH_MainLoop);
-		m_mainLoopBuffer->writeDWord (DH_EndMainLoop);
+		m_mainLoopBuffer->writeDWord (DataHeader::MainLoop);
+		m_mainLoopBuffer->writeDWord (DataHeader::EndMainLoop);
 	}
 
 	// Write the onenter and mainloop buffers, in that order in particular.
@@ -1339,7 +1359,7 @@
 		return;
 
 	// Write header
-	m_mainBuffer->writeDWord (DH_StringList);
+	m_mainBuffer->writeDWord (DataHeader::StringList);
 	m_mainBuffer->writeDWord (stringcount);
 
 	// Write all strings
@@ -1360,8 +1380,10 @@
 
 	// First, resolve references
 	for (MarkReference* ref : m_mainBuffer->references())
+	{
 		for (int i = 0; i < 4; ++i)
 			m_mainBuffer->buffer()[ref->pos + i] = (ref->target->pos >> (8 * i)) & 0xFF;
+	}
 
 	// Then, dump the main buffer to the file
 	fwrite (m_mainBuffer->buffer(), 1, m_mainBuffer->writtenSize(), fp);
--- a/src/parser.h	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/parser.h	Sun Jul 20 17:25:36 2014 +0300
@@ -108,7 +108,7 @@
 	String			origin;
 	bool			isarray;
 
-	inline bool IsGlobal() const
+	inline bool isGlobal() const
 	{
 		return statename.isEmpty();
 	}
@@ -151,108 +151,102 @@
 {
 	PROPERTY (public, bool, isReadOnly, setReadOnly, STOCK_WRITE)
 
-	public:
-		enum EReset
-		{
-			eNoReset,
-			SCOPE_Reset,
-		};
+public:
+	BotscriptParser();
+	~BotscriptParser();
+	void					parseBotscript (String fileName);
+	DataBuffer*				parseCommand (CommandInfo* comm);
+	DataBuffer*				parseAssignment (Variable* var);
+	AssignmentOperator		parseAssignmentOperator();
+	String					parseFloat();
+	void					pushScope (bool noreset = false);
+	DataBuffer*				parseStatement();
+	void					addSwitchCase (DataBuffer* b);
+	void					checkToplevel();
+	void					checkNotToplevel();
+	bool					tokenIs (Token a);
+	String					getTokenString();
+	String					describePosition() const;
+	void					writeToFile (String outfile);
+	Variable*				findVariable (const String& name);
+	bool					isInGlobalState() const;
+	void					suggestHighestVarIndex (bool global, int index);
+	int						getHighestVarIndex (bool global);
 
-		BotscriptParser();
-		~BotscriptParser();
-		void					parseBotscript (String fileName);
-		DataBuffer*				parseCommand (CommandInfo* comm);
-		DataBuffer*				parseAssignment (Variable* var);
-		AssignmentOperator		parseAssignmentOperator();
-		String					parseFloat();
-		void					pushScope (EReset reset = SCOPE_Reset);
-		DataBuffer*				parseStatement();
-		void					addSwitchCase (DataBuffer* b);
-		void					checkToplevel();
-		void					checkNotToplevel();
-		bool					tokenIs (ETokenType a);
-		String					getTokenString();
-		String					describePosition() const;
-		void					writeToFile (String outfile);
-		Variable*				findVariable (const String& name);
-		bool					isInGlobalState() const;
-		void					suggestHighestVarIndex (bool global, int index);
-		int						getHighestVarIndex (bool global);
+	inline ScopeInfo& scope (int offset)
+	{
+		return m_scopeStack[m_scopeCursor - offset];
+	}
+
+	inline int numEvents() const
+	{
+		return m_numEvents;
+	}
 
-		inline ScopeInfo& scope (int offset)
-		{
-			return m_scopeStack[m_scopeCursor - offset];
-		}
-
-		inline int numEvents() const
-		{
-			return m_numEvents;
-		}
+	inline int numStates() const
+	{
+		return m_numStates;
+	}
 
-		inline int numStates() const
-		{
-			return m_numStates;
-		}
+private:
+	// The main buffer - the contents of this is what we
+	// write to file after parsing is complete
+	DataBuffer*		m_mainBuffer;
 
-	private:
-		// The main buffer - the contents of this is what we
-		// write to file after parsing is complete
-		DataBuffer*		m_mainBuffer;
+	// onenter buffer - the contents of the onenter {} block
+	// is buffered here and is merged further at the end of state
+	DataBuffer*		m_onenterBuffer;
 
-		// onenter buffer - the contents of the onenter {} block
-		// is buffered here and is merged further at the end of state
-		DataBuffer*		m_onenterBuffer;
+	// Mainloop buffer - the contents of the mainloop {} block
+	// is buffered here and is merged further at the end of state
+	DataBuffer*		m_mainLoopBuffer;
+
+	// Switch buffer - switch case data is recorded to this
+	// buffer initially, instead of into main buffer.
+	DataBuffer*		m_switchBuffer;
 
-		// Mainloop buffer - the contents of the mainloop {} block
-		// is buffered here and is merged further at the end of state
-		DataBuffer*		m_mainLoopBuffer;
-
-		// Switch buffer - switch case data is recorded to this
-		// buffer initially, instead of into main buffer.
-		DataBuffer*		m_switchBuffer;
+	Lexer*			m_lexer;
+	int				m_numStates;
+	int				m_numEvents;
+	ParserMode		m_currentMode;
+	String			m_currentState;
+	bool			m_isStateSpawnDefined;
+	bool			m_gotMainLoop;
+	int				m_scopeCursor;
+	bool			m_isElseAllowed;
+	int				m_highestGlobalVarIndex;
+	int				m_highestStateVarIndex;
+	int				m_numWrittenBytes;
+	List<ScopeInfo>	m_scopeStack;
+	int				m_zandronumVersion;
+	bool			m_defaultZandronumVersion;
 
-		Lexer*			m_lexer;
-		int				m_numStates;
-		int				m_numEvents;
-		ParserMode		m_currentMode;
-		String			m_currentState;
-		bool			m_isStateSpawnDefined;
-		bool			m_gotMainLoop;
-		int				m_scopeCursor;
-		bool			m_isElseAllowed;
-		int				m_highestGlobalVarIndex;
-		int				m_highestStateVarIndex;
-		int				m_numWrittenBytes;
-		List<ScopeInfo>	m_scopeStack;
-		int				m_zandronumVersion;
-		bool			m_defaultZandronumVersion;
-
-		DataBuffer*		currentBuffer();
-		void			parseStateBlock();
-		void			parseEventBlock();
-		void			parseMainloop();
-		void			parseOnEnterExit();
-		void			parseVar();
-		void			parseGoto();
-		void			parseIf();
-		void			parseElse();
-		void			parseWhileBlock();
-		void			parseForBlock();
-		void			parseDoBlock();
-		void			parseSwitchBlock();
-		void			parseSwitchCase();
-		void			parseSwitchDefault();
-		void			parseBreak();
-		void			parseContinue();
-		void			parseBlockEnd();
-		void			parseLabel();
-		void			parseEventdef();
-		void			parseFuncdef();
-		void			parseUsing();
-		void			writeMemberBuffers();
-		void			writeStringTable();
-		DataBuffer*		parseExpression (DataType reqtype, bool fromhere = false);
-		DataHeader		getAssigmentDataHeader (AssignmentOperator op, Variable* var);
+	DataBuffer*		currentBuffer();
+	void			parseStateBlock();
+	void			parseEventBlock();
+	void			parseMainloop();
+	void			parseOnEnterExit();
+	void			parseVar();
+	void			parseGoto();
+	void			parseIf();
+	void			parseElse();
+	void			parseWhileBlock();
+	void			parseForBlock();
+	void			parseDoBlock();
+	void			parseSwitchBlock();
+	void			parseSwitchCase();
+	void			parseSwitchDefault();
+	void			parseBreak();
+	void			parseContinue();
+	void			parseBlockEnd();
+	void			parseLabel();
+	void			parseEventdef();
+	void			parseFuncdef();
+	void			parseUsing();
+	void			writeMemberBuffers();
+	void			writeStringTable();
+	DataBuffer*		parseExpression (DataType reqtype, bool fromhere = false);
+	DataHeader		getAssigmentDataHeader (AssignmentOperator op, Variable* var);
 };
 
 #endif // BOTC_PARSER_H
--- a/src/string.cpp	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/string.cpp	Sun Jul 20 17:25:36 2014 +0300
@@ -71,7 +71,7 @@
 
 	for (char& c : newstr)
 	{
-		if (c >= 'a' && c <= 'z')
+		if (c >= 'a' and c <= 'z')
 			c -= 'a' - 'A';
 	}
 
@@ -86,7 +86,7 @@
 
 	for (char& c : newstr)
 	{
-		if (c >= 'A' && c <= 'Z')
+		if (c >= 'A' and c <= 'Z')
 			c += 'a' - 'A';
 	}
 
@@ -214,11 +214,11 @@
 //
 int String::lastIndexOf (const char* c, int a) const
 {
-	if (a == -1 || a >= length())
+	if (a == -1 or a >= length())
 		a = length() - 1;
 
 	for (; a > 0; a--)
-		if (_string[a] == c[0] && strncmp (_string.c_str() + a, c, strlen (c)) == 0)
+		if (_string[a] == c[0] and strncmp (_string.c_str() + a, c, strlen (c)) == 0)
 			return a;
 
 	return -1;
@@ -244,7 +244,7 @@
 	long i = strtol (_string.c_str(), &endptr, base);
 
 	if (ok)
-		*ok = (errno == 0 && *endptr == '\0');
+		*ok = (errno == 0 and *endptr == '\0');
 
 	return i;
 }
@@ -258,7 +258,7 @@
 	float i = strtof (_string.c_str(), &endptr);
 
 	if (ok)
-		*ok = (errno == 0 && *endptr == '\0');
+		*ok = (errno == 0 and *endptr == '\0');
 
 	return i;
 }
@@ -272,7 +272,7 @@
 	double i = strtod (_string.c_str(), &endptr);
 
 	if (ok)
-		*ok = (errno == 0 && *endptr == '\0');
+		*ok = (errno == 0 and *endptr == '\0');
 
 	return i;
 }
@@ -304,17 +304,17 @@
 	for (const char & c : _string)
 	{
 		// Allow leading hyphen for negatives
-		if (&c == &_string[0] && c == '-')
+		if (&c == &_string[0] and c == '-')
 			continue;
 
 		// Check for decimal point
-		if (!gotDot && c == '.')
+		if (!gotDot and c == '.')
 		{
 			gotDot = true;
 			continue;
 		}
 
-		if (c >= '0' && c <= '9')
+		if (c >= '0' and c <= '9')
 			continue; // Digit
 
 		// If the above cases didn't catch this character, it was
@@ -413,7 +413,7 @@
 				return true;
 
 			// Skip to the end character
-			while (*sptr != end && *sptr != '\0')
+			while (*sptr != end and *sptr != '\0')
 				sptr++;
 
 			// String ended while the mask still had stuff
--- a/src/stringTable.cpp	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/stringTable.cpp	Sun Jul 20 17:25:36 2014 +0300
@@ -59,12 +59,14 @@
 	}
 
 	// Must not be too long.
-	if (a.length() >= gMaxStringLength)
+	if (a.length() >= Limits::MaxStringLength)
+	{
 		error ("string `%1` too long (%2 characters, max is %3)\n",
-			   a, a.length(), gMaxStringLength);
+			   a, a.length(), Limits::MaxStringLength);
+	}
 
 	// Check if the table is already full
-	if (g_StringTable.size() == gMaxStringlistSize - 1)
+	if (g_StringTable.size() == Limits::MaxStringlistSize - 1)
 		error ("too many strings!\n");
 
 	// Now, dump the string into the slot
--- a/src/tokens.h	Sat Jul 12 23:04:46 2014 +0300
+++ b/src/tokens.h	Sun Jul 20 17:25:36 2014 +0300
@@ -33,99 +33,99 @@
 #include "macros.h"
 
 // =======================================================
-named_enum ETokenType
+named_enum Token
 {
 	// Non-word tokens
-	TK_LeftShiftAssign,
-	TK_RightShiftAssign,
-	TK_Equals,
-	TK_NotEquals,
-	TK_AddAssign,
-	TK_SubAssign,
-	TK_MultiplyAssign,
-	TK_DivideAssign,
-	TK_ModulusAssign,
-	TK_LeftShift,
-	TK_RightShift,
-	TK_AtLeast,
-	TK_AtMost,
-	TK_DoubleAmperstand,
-	TK_DoubleBar,
-	TK_DoublePlus,
-	TK_DoubleMinus,
-	TK_SingleQuote,
-	TK_DollarSign,
-	TK_ParenStart,
-	TK_ParenEnd,
-	TK_BracketStart,
-	TK_BracketEnd,
-	TK_BraceStart,
-	TK_BraceEnd,
-	TK_Assign,
-	TK_Plus,
-	TK_Minus,
-	TK_Multiply,
-	TK_Divide,
-	TK_Modulus,
-	TK_Comma,
-	TK_Lesser,
-	TK_Greater,
-	TK_Dot,
-	TK_Colon,
-	TK_Semicolon,
-	TK_Hash,
-	TK_ExclamationMark,
-	TK_Amperstand,
-	TK_Bar,
-	TK_Caret,
-	TK_QuestionMark,
-	TK_Arrow,
+	LeftShiftAssign,
+	RightShiftAssign,
+	Equals,
+	NotEquals,
+	AddAssign,
+	SubAssign,
+	MultiplyAssign,
+	DivideAssign,
+	ModulusAssign,
+	LeftShift,
+	RightShift,
+	AtLeast,
+	AtMost,
+	DoubleAmperstand,
+	DoubleBar,
+	DoublePlus,
+	DoubleMinus,
+	SingleQuote,
+	DollarSign,
+	ParenStart,
+	ParenEnd,
+	BracketStart,
+	BracketEnd,
+	BraceStart,
+	BraceEnd,
+	Assign,
+	Plus,
+	Minus,
+	Multiply,
+	Divide,
+	Modulus,
+	Comma,
+	Lesser,
+	Greater,
+	Dot,
+	Colon,
+	Semicolon,
+	Hash,
+	ExclamationMark,
+	Amperstand,
+	Bar,
+	Caret,
+	QuestionMark,
+	Arrow,
 
 	// --------------
 	// Named tokens
-	TK_Bool,
-	TK_Break,
-	TK_Case,
-	TK_Continue,
-	TK_Const,
-	TK_Constexpr,
-	TK_Default,
-	TK_Do,
-	TK_Else,
-	TK_Event,
-	TK_Eventdef,
-	TK_For,
-	TK_Funcdef,
-	TK_If,
-	TK_Int,
-	TK_Mainloop,
-	TK_Onenter,
-	TK_Onexit,
-	TK_State,
-	TK_Switch,
-	TK_Str,
-	TK_Using,
-	TK_Var,
-	TK_Void,
-	TK_While,
-	TK_True,
-	TK_False,
+	Bool,
+	Break,
+	Case,
+	Continue,
+	Const,
+	Constexpr,
+	Default,
+	Do,
+	Else,
+	Event,
+	Eventdef,
+	For,
+	Funcdef,
+	If,
+	Int,
+	Mainloop,
+	Onenter,
+	Onexit,
+	State,
+	Switch,
+	Str,
+	Using,
+	Var,
+	Void,
+	While,
+	True,
+	False,
 
 	// These ones aren't implemented yet but I plan to do so, thus they are
 	// reserved. Also serves as a to-do list of sorts for me. >:F
-	TK_Enum,
-	TK_Func,
-	TK_Return,
+	Enum,
+	Func,
+	Return,
 
 	// --------------
 	// Generic tokens
-	TK_Symbol,
-	TK_Number,
-	TK_String,
-	TK_Any,
+	Symbol,
+	Number,
+	String,
+	Any,
+
+	FirstNamedToken = Bool,
+	LastNamedToken = Token (int (Symbol) - 1)
 };
 
-static const int gFirstNamedToken		= TK_Bool;
-static const int gLastNamedToken		= (int) TK_Symbol - 1;
-
 #endif

mercurial