Преглед изворни кода

Add new tokens for make bitwise operations shorter "|=", "&=", "^=", but not implement then yet.
Some white space has gone.

mingodad пре 13 година
родитељ
комит
84de4fb182
2 измењених фајлова са 28 додато и 17 уклоњено
  1. 5 0
      squirrel/sqcompiler.h
  2. 23 17
      squirrel/sqlexer.cpp

+ 5 - 0
squirrel/sqcompiler.h

@@ -97,6 +97,11 @@ struct SQVM;
 #define	TK_LOCAL_DOUBLE_T	344
 #define	TK_LOCAL_LONG_DOUBLE_T	345
 
+#define	TK_BIT_AND_EQ	346
+#define	TK_BIT_OR_EQ	347
+#define	TK_BIT_XOR_EQ	348
+#define	TK_BIT_SHIFT_LEFT_EQ	349
+#define	TK_BIT_SHIFT_RIGHT_EQ	350
 
 typedef void(*CompilerErrorFunc)(void *ud, const SQChar *s);
 bool Compile(SQVM *vm, SQLEXREADFUNC rg, SQUserPointer up, const SQChar *sourcename, SQObjectPtr &out, bool raiseerror, bool lineinfo);

+ 23 - 17
squirrel/sqlexer.cpp

@@ -170,7 +170,7 @@ SQInteger SQLexer::Lex()
 			case _SC('*'):
 				NEXT();
 				LexBlockComment();
-				continue;	
+				continue;
 			case _SC('/'):
 				LexLineComment();
 				continue;
@@ -193,12 +193,12 @@ SQInteger SQLexer::Lex()
 			NEXT();
 			switch(CUR_CHAR) {
 			case _SC('='):
-				NEXT(); 
+				NEXT();
 				if(CUR_CHAR == _SC('>')) {
 					NEXT();
-					RETURN_TOKEN(TK_3WAYSCMP); 
+					RETURN_TOKEN(TK_3WAYSCMP);
 				}
-				RETURN_TOKEN(TK_LE) 
+				RETURN_TOKEN(TK_LE)
 				break;
 			case _SC('-'): NEXT(); RETURN_TOKEN(TK_NEWSLOT); break;
 			case _SC('<'): NEXT(); RETURN_TOKEN(TK_SHIFTL); break;
@@ -208,8 +208,8 @@ SQInteger SQLexer::Lex()
 		case _SC('>'):
 			NEXT();
 			if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_GE);}
-			else if(CUR_CHAR == _SC('>')){ 
-				NEXT(); 
+			else if(CUR_CHAR == _SC('>')){
+				NEXT();
 				if(CUR_CHAR == _SC('>')){
 					NEXT();
 					RETURN_TOKEN(TK_USHIFTR);
@@ -241,7 +241,7 @@ SQInteger SQLexer::Lex()
 			Error(_SC("error parsing the string"));
 			}
 		case _SC('{'): case _SC('}'): case _SC('('): case _SC(')'): case _SC('['): case _SC(']'):
-		case _SC(';'): case _SC(','): case _SC('?'): case _SC('^'): case _SC('~'):
+		case _SC(';'): case _SC(','): case _SC('?'): case _SC('~'):
 			{
 			    SQInteger ret = CUR_CHAR;
                 NEXT();
@@ -262,12 +262,18 @@ SQInteger SQLexer::Lex()
 			if (CUR_CHAR != _SC('.')){ Error(_SC("invalid token '..'")); }
 			NEXT();
 			RETURN_TOKEN(TK_VARPARAMS);
+		case _SC('^'):
+			NEXT();
+			//if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_BIT_XOR_EQ);}
+			RETURN_TOKEN('^');
 		case _SC('&'):
 			NEXT();
+			//if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_BIT_AND_EQ);}
 			if (CUR_CHAR != _SC('&')){ RETURN_TOKEN('&') }
 			else { NEXT(); RETURN_TOKEN(TK_AND); }
 		case _SC('|'):
-			NEXT();
+			NEXT();
+			//if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_BIT_OR_EQ);}
 			if (CUR_CHAR != _SC('|')){ RETURN_TOKEN('|') }
 			else { NEXT(); RETURN_TOKEN(TK_OR); }
 		case _SC(':'):
@@ -308,15 +314,15 @@ SQInteger SQLexer::Lex()
 					SQInteger c = CUR_CHAR;
 					if (sciscntrl((int)c)) Error(_SC("unexpected character(control)"));
 					NEXT();
-					RETURN_TOKEN(c);  
+					RETURN_TOKEN(c);
 				}
 				RETURN_TOKEN(0);
 			}
 		}
 	}
-	return 0;    
+	return 0;
 }
-	
+
 SQInteger SQLexer::GetIDType(SQChar *s)
 {
 	SQObjectPtr t;
@@ -356,20 +362,20 @@ SQInteger SQLexer::ReadString(SQInteger ndelim,bool verbatim)
 			case SQUIRREL_EOB:
 				Error(_SC("unfinished string"));
 				return -1;
-			case _SC('\n'): 
-				if(!verbatim) Error(_SC("newline in a constant")); 
-				APPEND_CHAR(CUR_CHAR); NEXT(); 
+			case _SC('\n'):
+				if(!verbatim) Error(_SC("newline in a constant"));
+				APPEND_CHAR(CUR_CHAR); NEXT();
 				_currentline++;
 				break;
 			case _SC('\\'):
 				if(verbatim) {
-					APPEND_CHAR('\\'); NEXT(); 
+					APPEND_CHAR('\\'); NEXT();
 				}
 				else {
 					NEXT();
 					switch(CUR_CHAR) {
 					case _SC('x'): NEXT(); {
-						if(!isxdigit(CUR_CHAR)) Error(_SC("hexadecimal number expected")); 
+						if(!isxdigit(CUR_CHAR)) Error(_SC("hexadecimal number expected"));
 						const SQInteger maxdigits = 4;
 						SQChar temp[maxdigits+1];
 						SQInteger n = 0;
@@ -531,7 +537,7 @@ SQInteger SQLexer::ReadNumber()
 				}
 				if(!scisdigit(CUR_CHAR)) Error(_SC("exponent expected"));
 			}
-			
+
 			APPEND_CHAR(CUR_CHAR);
 			NEXT();
 		}