Просмотр исходного кода

Add "goto" keyword and made the lexer/parser recognize (including labels) and ignore then for now.

mingodad 9 лет назад
Родитель
Сommit
9bc71a8ccb
3 измененных файлов с 37 добавлено и 12 удалено
  1. 25 2
      SquiLu/squirrel/sqcompiler.cpp
  2. 11 10
      SquiLu/squirrel/sqcompiler.h
  3. 1 0
      SquiLu/squirrel/sqlexer.cpp

+ 25 - 2
SquiLu/squirrel/sqcompiler.cpp

@@ -745,16 +745,34 @@ public:
 		    goto start_again;
 		    break;
 
-        case TK_IDENTIFIER:
+		case TK_GOTO:
+		    Warning(_SC("%s:%d:%d warning goto is only parsed right now\n"),
+                        _stringval(_sourcename), _lex.data->currentline, _lex.data->currentcolumn);
+		    Lex(); //ignore for now
+		    id = Expect(TK_IDENTIFIER);
+		    Expect(_SC(';'));
+		    break;
+
+        case TK_IDENTIFIER:{
+            SQInteger lhtk = _lex.LookaheadLex();
+            if(lhtk == _SC(':'))
+            {
+                Warning(_SC("%s:%d:%d warning labels are only parsed right now\n"),
+                        _stringval(_sourcename), _lex.data->currentline, _lex.data->currentcolumn);
+                LabelDeclStatement();
+                Lex();
+                break;
+            }
             id = _fs->CreateString(_lex.data->svalue);
             if(CheckTypeName(id)) //C/C++ type declaration;
             {
-                if(_lex.LookaheadLex() != _SC('.'))
+                if(lhtk != _SC('.'))
                 {
                     LocalDeclStatement();
                     break;
                 }
             }
+        }
 
 		default:
 			CommaExpr();
@@ -1649,6 +1667,11 @@ function_params_decl:
 	    LocalDeclStatement();
 	    _is_parsing_extern = false;
 	}
+	void LabelDeclStatement()
+	{
+	    Lex();
+	    return; //ignore for now
+	}
 	#define CHECK_REF_DECLARATION(tk) if(tk == _SC('&')){is_reference_declaration = true;Lex();}
 	void LocalDeclStatement()
 	{

+ 11 - 10
SquiLu/squirrel/sqcompiler.h

@@ -1,8 +1,8 @@
-/*	see copyright notice in squirrel.h */
-#ifndef _SQCOMPILER_H_
-#define _SQCOMPILER_H_
-
-struct SQVM;
+/*	see copyright notice in squirrel.h */
+#ifndef _SQCOMPILER_H_
+#define _SQCOMPILER_H_
+
+struct SQVM;
 
 #define SQ_KEYWORDS_LIST() \
     ENUM_TK(3WAYSCMP)\
@@ -50,6 +50,7 @@ struct SQVM;
     ENUM_TK(__FUNCTION__)\
     ENUM_TK(FUNCTION)\
     ENUM_TK(GE)\
+    ENUM_TK(GOTO)\
     ENUM_TK(IDENTIFIER)\
     ENUM_TK(IF)\
     ENUM_TK(IGNORE)\
@@ -129,7 +130,7 @@ struct SQVM;
     //ENUM_TK(VARGV)
 
 #define ENUM_TK(tk) TK_##tk,
-enum SQKeywordsEnum {
+enum SQKeywordsEnum {
     TK_FIRST_ENUM_TOKEN = 258,
     /*
     the above token is only for internal purposes
@@ -143,8 +144,8 @@ enum SQKeywordsEnum {
     TK_LAST_ENUM_TOKEN
 };
 #undef ENUM_TK
-
-typedef void(*CompilerErrorFunc)(void *ud, const SQChar *s);
+
+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, bool show_warnings, SQInteger max_nested_includes=10);
-#endif //_SQCOMPILER_H_
+             bool raiseerror, bool lineinfo, bool show_warnings, SQInteger max_nested_includes=10);
+#endif //_SQCOMPILER_H_

+ 1 - 0
SquiLu/squirrel/sqlexer.cpp

@@ -89,6 +89,7 @@ SQTable * SQLexer::GetKeywords()
 	ADD_KEYWORD(friend, TK_FRIEND);
 	ADD_KEYWORD(function, TK_FUNCTION);
 	ADD_KEYWORD(__FUNCTION__,TK___FUNCTION__);
+	ADD_KEYWORD(goto, TK_GOTO);
 	ADD_KEYWORD(if, TK_IF);
 	ADD_KEYWORD(instanceof,TK_INSTANCEOF);
 	ADD_KEYWORD(int16_t, TK_LOCAL_INT16_T);