|
@@ -147,6 +147,26 @@ void charMather(int p, LexMather *mather, int dest_p){
|
|
mather->status = LEXMATHER_MISTAKE;
|
|
mather->status = LEXMATHER_MISTAKE;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * 匹配空白符号
|
|
|
|
+ * @param p
|
|
|
|
+ * @param mather
|
|
|
|
+ */
|
|
|
|
+void spaceMather(int p, LexMather *mather){
|
|
|
|
+ if (mather->status == LEXMATHER_START || mather->status == LEXMATHER_ING)
|
|
|
|
+ if (isspace(p) && p != '\n'){
|
|
|
|
+ mather->str = memStrCharcpy(mather->str, 1, true, true, p);
|
|
|
|
+ mather->len ++;
|
|
|
|
+ mather->status = LEXMATHER_ING;
|
|
|
|
+ }
|
|
|
|
+ else if (mather->status == LEXMATHER_ING)
|
|
|
|
+ mather->status = LEXMATHER_END;
|
|
|
|
+ else
|
|
|
|
+ mather->status = LEXMATHER_MISTAKE;
|
|
|
|
+ else
|
|
|
|
+ mather->status = LEXMATHER_MISTAKE;
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 开始匹配,返回的int即checkoutMather返回的值(匹配成功的匹配器的索引)
|
|
* 开始匹配,返回的int即checkoutMather返回的值(匹配成功的匹配器的索引)
|
|
* @param file
|
|
* @param file
|
|
@@ -161,9 +181,9 @@ int getMatherStatus(LexFile *file, LexMathers *mathers) {
|
|
numberMather(p ,mathers->mathers[MATHER_NUMBER]);
|
|
numberMather(p ,mathers->mathers[MATHER_NUMBER]);
|
|
stringMather(p ,mathers->mathers[MATHER_STRING]);
|
|
stringMather(p ,mathers->mathers[MATHER_STRING]);
|
|
varMather(p ,mathers->mathers[MATHER_VAR]);
|
|
varMather(p ,mathers->mathers[MATHER_VAR]);
|
|
|
|
+ spaceMather(p ,mathers->mathers[MATHER_SPACE]);
|
|
charMatherMacro(MATHER_EOF, EOF);
|
|
charMatherMacro(MATHER_EOF, EOF);
|
|
charMatherMacro(MATHER_ENTER, '\n');
|
|
charMatherMacro(MATHER_ENTER, '\n');
|
|
- charMatherMacro(MATHER_SPACE, ' ');
|
|
|
|
|
|
|
|
strMatherMacro(MATHER_IF, "if"); // 条件判断
|
|
strMatherMacro(MATHER_IF, "if"); // 条件判断
|
|
strMatherMacro(MATHER_ELIF, "elif"); // 条件循环
|
|
strMatherMacro(MATHER_ELIF, "elif"); // 条件循环
|
|
@@ -248,6 +268,7 @@ int getMatherStatus(LexFile *file, LexMathers *mathers) {
|
|
strMatherMacro(MATHER_FROM, "from");
|
|
strMatherMacro(MATHER_FROM, "from");
|
|
strMatherMacro(MATHER_ASSERT, "assert");
|
|
strMatherMacro(MATHER_ASSERT, "assert");
|
|
strMatherMacro(MATHER_LAMBDA, "lambda");
|
|
strMatherMacro(MATHER_LAMBDA, "lambda");
|
|
|
|
+ strMatherMacro(MATHER_NOTENTER, "\\\n");
|
|
|
|
|
|
status = checkoutMather(mathers, MATHER_MAX);
|
|
status = checkoutMather(mathers, MATHER_MAX);
|
|
}
|
|
}
|
|
@@ -255,6 +276,14 @@ int getMatherStatus(LexFile *file, LexMathers *mathers) {
|
|
return status;
|
|
return status;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+int lexFilter(LexFile *file, int status){
|
|
|
|
+ if (status == MATHER_SPACE || status == MATHER_NOTENTER)
|
|
|
|
+ return -1;
|
|
|
|
+ if (file->filter_data.enter != 0 && status == MATHER_ENTER)
|
|
|
|
+ return -1;
|
|
|
|
+ return status;
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* getMatherStatus的高级封装,若匹配到空格则自动忽略(再次匹配)
|
|
* getMatherStatus的高级封装,若匹配到空格则自动忽略(再次匹配)
|
|
* @param file
|
|
* @param file
|
|
@@ -263,14 +292,17 @@ int getMatherStatus(LexFile *file, LexMathers *mathers) {
|
|
*/
|
|
*/
|
|
Token *getToken(LexFile *file, LexMathers *mathers) {
|
|
Token *getToken(LexFile *file, LexMathers *mathers) {
|
|
int status = MATHER_SPACE;
|
|
int status = MATHER_SPACE;
|
|
- Token *tmp;
|
|
|
|
- while (status == MATHER_SPACE)
|
|
|
|
|
|
+ int filter;
|
|
|
|
+ Token *tmp = NULL;
|
|
|
|
+
|
|
|
|
+ while ((filter = lexFilter(file, status)) == -1)
|
|
status = getMatherStatus(file, mathers);
|
|
status = getMatherStatus(file, mathers);
|
|
|
|
+
|
|
if (status == -2){
|
|
if (status == -2){
|
|
tmp = makeLexToken(MATHER_ERROR_, NULL, NULL, file->line);
|
|
tmp = makeLexToken(MATHER_ERROR_, NULL, NULL, file->line);
|
|
goto return_;
|
|
goto return_;
|
|
}
|
|
}
|
|
- tmp = makeLexToken(status, mathers->mathers[status]->str, mathers->mathers[status]->second_str, file->line);
|
|
|
|
|
|
+ tmp = makeLexToken(filter, mathers->mathers[status]->str, mathers->mathers[status]->second_str, file->line);
|
|
return_:
|
|
return_:
|
|
return tmp;
|
|
return tmp;
|
|
}
|
|
}
|