|
@@ -47,10 +47,10 @@ void freePasersMessage(ParserMessage *pm, bool self) {
|
|
* | parserCommand MATHER_EOF
|
|
* | parserCommand MATHER_EOF
|
|
*/
|
|
*/
|
|
void pasersCommandList(ParserMessage *pm, Inter *inter, bool global, Statement *st) {
|
|
void pasersCommandList(ParserMessage *pm, Inter *inter, bool global, Statement *st) {
|
|
- int token_type, command_int, stop;
|
|
|
|
|
|
+ int token_type, stop;
|
|
struct Statement *base_st = st;
|
|
struct Statement *base_st = st;
|
|
while (true){
|
|
while (true){
|
|
- readBackToken(token_type, pm);
|
|
|
|
|
|
+ token_type = readBackToken(pm);
|
|
if (token_type == MATHER_EOF){
|
|
if (token_type == MATHER_EOF){
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command List: <EOF>\n", NULL);
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command List: <EOF>\n", NULL);
|
|
delToken(pm);
|
|
delToken(pm);
|
|
@@ -68,8 +68,7 @@ void pasersCommandList(ParserMessage *pm, Inter *inter, bool global, Statement *
|
|
if (!call_success(pm)){
|
|
if (!call_success(pm)){
|
|
goto return_;
|
|
goto return_;
|
|
}
|
|
}
|
|
- readBackToken(command_int, pm);
|
|
|
|
- if (COMMAND != command_int){
|
|
|
|
|
|
+ if (COMMAND != readBackToken(pm)){
|
|
if (global){
|
|
if (global){
|
|
syntaxError(pm, "ERROR from command list(get parserCommand)", command_list_error);
|
|
syntaxError(pm, "ERROR from command list(get parserCommand)", command_list_error);
|
|
}
|
|
}
|
|
@@ -77,7 +76,7 @@ void pasersCommandList(ParserMessage *pm, Inter *inter, bool global, Statement *
|
|
}
|
|
}
|
|
popAheadToken(command_token, pm);
|
|
popAheadToken(command_token, pm);
|
|
|
|
|
|
- readBackToken(stop, pm);
|
|
|
|
|
|
+ stop = readBackToken(pm);
|
|
if (stop == MATHER_ENTER || stop == MATHER_SEMICOLON){
|
|
if (stop == MATHER_ENTER || stop == MATHER_SEMICOLON){
|
|
delToken(pm);
|
|
delToken(pm);
|
|
}
|
|
}
|
|
@@ -117,34 +116,26 @@ void pasersCommandList(ParserMessage *pm, Inter *inter, bool global, Statement *
|
|
void parserCommand(PASERSSIGNATURE){
|
|
void parserCommand(PASERSSIGNATURE){
|
|
int token_type;
|
|
int token_type;
|
|
Statement *st = NULL;
|
|
Statement *st = NULL;
|
|
- readBackToken(token_type, pm);
|
|
|
|
- if (MATHER_DEF == token_type){
|
|
|
|
- int def;
|
|
|
|
- Token *def_token = NULL;
|
|
|
|
- parserDef(CALLPASERSSIGNATURE);
|
|
|
|
- if (!call_success(pm))
|
|
|
|
- goto return_;
|
|
|
|
- readBackToken(def, pm);
|
|
|
|
- if (def != FUNCTION)
|
|
|
|
- goto return_;
|
|
|
|
- popAheadToken(def_token, pm);
|
|
|
|
- st = def_token->data.st;
|
|
|
|
- freeToken(def_token, true, false);
|
|
|
|
- }
|
|
|
|
- else{
|
|
|
|
- writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command: call operation\n", NULL);
|
|
|
|
- int command_type;
|
|
|
|
- Token *command_token = NULL;
|
|
|
|
- parserOperation(CALLPASERSSIGNATURE);
|
|
|
|
- if (!call_success(pm))
|
|
|
|
- goto return_;
|
|
|
|
- readBackToken(command_type, pm);
|
|
|
|
- if (command_type != OPERATION)
|
|
|
|
- goto return_;
|
|
|
|
- popAheadToken(command_token, pm);
|
|
|
|
- /*...do something for command...*/
|
|
|
|
- st = command_token->data.st;
|
|
|
|
- freeToken(command_token, true, false);
|
|
|
|
|
|
+ token_type = readBackToken(pm);
|
|
|
|
+ switch (token_type) {
|
|
|
|
+ case MATHER_DEF :
|
|
|
|
+ commandCallBack(pm, st, parserDef, FUNCTION, return_);
|
|
|
|
+ break;
|
|
|
|
+ case MATHER_IF :
|
|
|
|
+ commandCallBack(pm, st, parserIf, IF_BRANCH, return_);
|
|
|
|
+ break;
|
|
|
|
+ case MATHER_WHILE :
|
|
|
|
+ commandCallBack(pm, st, parserWhile, WHILE_BRANCH, return_);
|
|
|
|
+ break;
|
|
|
|
+ case MATHER_BREAK :
|
|
|
|
+ commandCallControl(pm, st, makeBreakStatement, BREAK, return_);
|
|
|
|
+ break;
|
|
|
|
+ case MATHER_CONTINUE :
|
|
|
|
+ commandCallControl(pm, st, makeContinueStatement, CONTINUE, return_);
|
|
|
|
+ break;
|
|
|
|
+ default :
|
|
|
|
+ commandCallBack(pm, st, parserOperation, OPERATION, return_);
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
addStatementToken(COMMAND, st, pm);
|
|
addStatementToken(COMMAND, st, pm);
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command: get command success\n", NULL);
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command: get command success\n", NULL);
|
|
@@ -152,45 +143,210 @@ void parserCommand(PASERSSIGNATURE){
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command: get return\n", NULL);
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command: get return\n", NULL);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void parserControl(PASERSSIGNATURE, Statement *(*callBack)(Statement *), int type){
|
|
|
|
+ Statement *times = NULL, *st = NULL;
|
|
|
|
+ delToken(pm);
|
|
|
|
+ parserOperation(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm))
|
|
|
|
+ goto return_;
|
|
|
|
+ if (readBackToken(pm) == OPERATION){
|
|
|
|
+ Token *tmp;
|
|
|
|
+ popAheadToken(tmp, pm);
|
|
|
|
+ times = tmp->data.st;
|
|
|
|
+ freeToken(tmp, true, false);
|
|
|
|
+ }
|
|
|
|
+ st = callBack(times);
|
|
|
|
+ addStatementToken(type, st, pm);
|
|
|
|
+ return_:
|
|
|
|
+ return;
|
|
|
|
+}
|
|
|
|
+
|
|
void parserIf(PASERSSIGNATURE){
|
|
void parserIf(PASERSSIGNATURE){
|
|
-// int if_type, code;
|
|
|
|
-// Token *if_token = NULL, *code_token = NULL;
|
|
|
|
-// struct Statement *st = NULL, *tmp = NULL;
|
|
|
|
-// StatementList *sl = NULL;
|
|
|
|
-//
|
|
|
|
-// checkToken(pm, MATHER_IF, return_);
|
|
|
|
-// callChild(pm, if_type, if_token, parserOperation, OPERATION, return_, error_);
|
|
|
|
-// if (if_type != OPERATION){
|
|
|
|
-// goto return_;
|
|
|
|
-// }
|
|
|
|
-// callChild(pm, code, code_token, parserCode, CODE, error_, error_);
|
|
|
|
-//
|
|
|
|
-// sl = makeConnectStatementList(sl, if_token->data.st, NULL, code_token->data.st);
|
|
|
|
-//
|
|
|
|
-// st = makeFunctionStatement(name_token->data.st, code_token->data.st);
|
|
|
|
-// addStatementToken(FUNCTION, st, pm);
|
|
|
|
-// freeToken(code_token, true, false);
|
|
|
|
-// freeToken(name_token, true, false);
|
|
|
|
-// return_: return;
|
|
|
|
-//
|
|
|
|
-// error_:
|
|
|
|
-// freeToken(if_token, true, true);
|
|
|
|
-// freeToken(code_token, true, true);
|
|
|
|
-// syntaxError(pm, "Don't get a if titile", syntax_error);
|
|
|
|
-// return;
|
|
|
|
|
|
+ Token *if_token = NULL, *code_token = NULL;
|
|
|
|
+ struct Statement *st = NULL, *else_st = NULL, *finally_st = NULL;
|
|
|
|
+ StatementList *sl = NULL;
|
|
|
|
+ bool have_if = false;
|
|
|
|
+
|
|
|
|
+ again:
|
|
|
|
+ switch (readBackToken(pm)) {
|
|
|
|
+ case MATHER_IF:
|
|
|
|
+ if (have_if)
|
|
|
|
+ goto default_;
|
|
|
|
+ else
|
|
|
|
+ have_if = true;
|
|
|
|
+ case MATHER_ELIF:
|
|
|
|
+ delToken(pm);
|
|
|
|
+ parserOperation(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm))
|
|
|
|
+ goto return_;
|
|
|
|
+ if (readBackToken(pm) != OPERATION){
|
|
|
|
+ syntaxError(pm, "Don't get a if condition", syntax_error);
|
|
|
|
+ goto return_;
|
|
|
|
+ }
|
|
|
|
+ popAheadToken(if_token, pm);
|
|
|
|
+ parserCode(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm) && readBackToken(pm) != CODE){
|
|
|
|
+ error_:
|
|
|
|
+ freeToken(if_token, true, true);
|
|
|
|
+ syntaxError(pm, "Don't get a if code", syntax_error);
|
|
|
|
+ goto return_;
|
|
|
|
+ }
|
|
|
|
+ popAheadToken(code_token, pm);
|
|
|
|
+ sl = makeConnectStatementList(sl, if_token->data.st, NULL, code_token->data.st, if_b);
|
|
|
|
+ freeToken(if_token, true, false);
|
|
|
|
+ freeToken(code_token, true, false);
|
|
|
|
+ goto again;
|
|
|
|
+ case MATHER_DO:
|
|
|
|
+ delToken(pm);
|
|
|
|
+ parserCode(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm) && readBackToken(pm) != CODE){
|
|
|
|
+ goto error_;
|
|
|
|
+ }
|
|
|
|
+ popAheadToken(code_token, pm);
|
|
|
|
+ sl = makeConnectStatementList(sl, NULL, NULL, code_token->data.st, do_b);
|
|
|
|
+ freeToken(code_token, true, false);
|
|
|
|
+ goto again;
|
|
|
|
+ case MATHER_ELSE:
|
|
|
|
+ delToken(pm);
|
|
|
|
+ parserCode(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm) && readBackToken(pm) != CODE){
|
|
|
|
+ goto error_;
|
|
|
|
+ }
|
|
|
|
+ popAheadToken(code_token, pm);
|
|
|
|
+ if (else_st != NULL)
|
|
|
|
+ freeStatement(else_st);
|
|
|
|
+ else_st = code_token->data.st;
|
|
|
|
+ freeToken(code_token, true, false);
|
|
|
|
+ goto again;
|
|
|
|
+ case MATHER_FINALLY:
|
|
|
|
+ delToken(pm);
|
|
|
|
+ parserCode(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm) && readBackToken(pm) != CODE){
|
|
|
|
+ goto error_;
|
|
|
|
+ }
|
|
|
|
+ popAheadToken(code_token, pm);
|
|
|
|
+ if (finally_st != NULL)
|
|
|
|
+ freeStatement(finally_st);
|
|
|
|
+ finally_st = code_token->data.st;
|
|
|
|
+ freeToken(code_token, true, false);
|
|
|
|
+ goto again;
|
|
|
|
+ case MATHER_ENTER:
|
|
|
|
+ delToken(pm);
|
|
|
|
+ goto again;
|
|
|
|
+ default:
|
|
|
|
+ default_: break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ st = makeIfStatement();
|
|
|
|
+ st->u.if_branch.if_list = sl;
|
|
|
|
+ st->u.if_branch.else_list = else_st;
|
|
|
|
+ st->u.if_branch.finally = finally_st;
|
|
|
|
+ addStatementToken(IF_BRANCH, st, pm);
|
|
|
|
+
|
|
|
|
+ return_:
|
|
|
|
+ return;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void parserWhile(PASERSSIGNATURE){
|
|
|
|
+ Token *while_token = NULL, *code_token = NULL;
|
|
|
|
+ struct Statement *st = NULL, *else_st = NULL, *finally_st = NULL,*do_st = NULL;
|
|
|
|
+ StatementList *sl = NULL;
|
|
|
|
+ bool have_while = false;
|
|
|
|
+
|
|
|
|
+ again:
|
|
|
|
+ switch (readBackToken(pm)) {
|
|
|
|
+ case MATHER_WHILE:
|
|
|
|
+ if (have_while)
|
|
|
|
+ goto default_;
|
|
|
|
+ else
|
|
|
|
+ have_while = true;
|
|
|
|
+
|
|
|
|
+ delToken(pm);
|
|
|
|
+ parserOperation(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm))
|
|
|
|
+ goto return_;
|
|
|
|
+ if (readBackToken(pm) != OPERATION){
|
|
|
|
+ syntaxError(pm, "Don't get a else while condition", syntax_error);
|
|
|
|
+ goto return_;
|
|
|
|
+ }
|
|
|
|
+ popAheadToken(while_token, pm);
|
|
|
|
+ parserCode(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm) && readBackToken(pm) != CODE){
|
|
|
|
+ error_:
|
|
|
|
+ freeToken(while_token, true, true);
|
|
|
|
+ syntaxError(pm, "Don't get a while code", syntax_error);
|
|
|
|
+ goto return_;
|
|
|
|
+ }
|
|
|
|
+ popAheadToken(code_token, pm);
|
|
|
|
+ if (sl != NULL)
|
|
|
|
+ freeStatementList(sl);
|
|
|
|
+ sl = makeStatementList(while_token->data.st, NULL, code_token->data.st, if_b);
|
|
|
|
+ freeToken(while_token, true, false);
|
|
|
|
+ freeToken(code_token, true, false);
|
|
|
|
+ goto again;
|
|
|
|
+ case MATHER_DO:
|
|
|
|
+ delToken(pm);
|
|
|
|
+ parserCode(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm) && readBackToken(pm) != CODE){
|
|
|
|
+ goto error_;
|
|
|
|
+ }
|
|
|
|
+ popAheadToken(code_token, pm);
|
|
|
|
+ if (do_st != NULL)
|
|
|
|
+ freeStatement(do_st);
|
|
|
|
+ do_st = code_token->data.st;
|
|
|
|
+ freeToken(code_token, true, false);
|
|
|
|
+ goto again;
|
|
|
|
+ case MATHER_ELSE:
|
|
|
|
+ delToken(pm);
|
|
|
|
+ parserCode(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm) && readBackToken(pm) != CODE){
|
|
|
|
+ goto error_;
|
|
|
|
+ }
|
|
|
|
+ popAheadToken(code_token, pm);
|
|
|
|
+ if (else_st != NULL)
|
|
|
|
+ freeStatement(else_st);
|
|
|
|
+ else_st = code_token->data.st;
|
|
|
|
+ freeToken(code_token, true, false);
|
|
|
|
+ goto again;
|
|
|
|
+ case MATHER_FINALLY:
|
|
|
|
+ delToken(pm);
|
|
|
|
+ parserCode(CALLPASERSSIGNATURE);
|
|
|
|
+ if (!call_success(pm) && readBackToken(pm) != CODE){
|
|
|
|
+ goto error_;
|
|
|
|
+ }
|
|
|
|
+ popAheadToken(code_token, pm);
|
|
|
|
+ if (finally_st != NULL)
|
|
|
|
+ freeStatement(finally_st);
|
|
|
|
+ finally_st = code_token->data.st;
|
|
|
|
+ freeToken(code_token, true, false);
|
|
|
|
+ goto again;
|
|
|
|
+ case MATHER_ENTER:
|
|
|
|
+ delToken(pm);
|
|
|
|
+ goto again;
|
|
|
|
+ default:
|
|
|
|
+ default_: break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ st = makeWhileStatement();
|
|
|
|
+ st->u.while_branch.while_list = sl;
|
|
|
|
+ st->u.while_branch.else_list = else_st;
|
|
|
|
+ st->u.while_branch.finally = finally_st;
|
|
|
|
+ st->u.while_branch.after = do_st;
|
|
|
|
+ addStatementToken(WHILE_BRANCH, st, pm);
|
|
|
|
+
|
|
|
|
+ return_:
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
void parserDef(PASERSSIGNATURE){
|
|
void parserDef(PASERSSIGNATURE){
|
|
- int name_type, code;
|
|
|
|
Token *name_token = NULL, *code_token = NULL;
|
|
Token *name_token = NULL, *code_token = NULL;
|
|
struct Statement *st = NULL;
|
|
struct Statement *st = NULL;
|
|
|
|
+ delToken(pm);
|
|
|
|
|
|
- checkToken(pm, MATHER_DEF, return_);
|
|
|
|
parserBaseValue(CALLPASERSSIGNATURE);
|
|
parserBaseValue(CALLPASERSSIGNATURE);
|
|
if (!call_success(pm))
|
|
if (!call_success(pm))
|
|
goto return_;
|
|
goto return_;
|
|
- readBackToken(name_type, pm);
|
|
|
|
- if (name_type != BASEVALUE){
|
|
|
|
|
|
+ if (readBackToken(pm) != BASEVALUE){
|
|
syntaxError(pm, "Don't get a function name", syntax_error);
|
|
syntaxError(pm, "Don't get a function name", syntax_error);
|
|
goto return_;
|
|
goto return_;
|
|
}
|
|
}
|
|
@@ -198,14 +354,15 @@ void parserDef(PASERSSIGNATURE){
|
|
|
|
|
|
checkToken(pm, MATHER_LP, error_);
|
|
checkToken(pm, MATHER_LP, error_);
|
|
checkToken(pm, MATHER_RP, error_);
|
|
checkToken(pm, MATHER_RP, error_);
|
|
|
|
+ writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "parserDef: get function title success\n", NULL);
|
|
|
|
+ writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "parserDef: call parserCode\n", NULL);
|
|
parserCode(CALLPASERSSIGNATURE);
|
|
parserCode(CALLPASERSSIGNATURE);
|
|
if (!call_success(pm)){
|
|
if (!call_success(pm)){
|
|
goto error_;
|
|
goto error_;
|
|
}
|
|
}
|
|
- readBackToken(code, pm);
|
|
|
|
- if (code != CODE){
|
|
|
|
- freeToken(name_token, true, true);
|
|
|
|
|
|
+ if (readBackToken(pm) != CODE){
|
|
error_:
|
|
error_:
|
|
|
|
+ freeToken(name_token, true, true);
|
|
syntaxError(pm, "Don't get a function code", syntax_error);
|
|
syntaxError(pm, "Don't get a function code", syntax_error);
|
|
goto return_;
|
|
goto return_;
|
|
}
|
|
}
|
|
@@ -221,24 +378,24 @@ void parserDef(PASERSSIGNATURE){
|
|
}
|
|
}
|
|
|
|
|
|
void parserCode(PASERSSIGNATURE){
|
|
void parserCode(PASERSSIGNATURE){
|
|
- int code_type;
|
|
|
|
- Token *code_token = NULL;
|
|
|
|
|
|
+ Token *code_token = NULL, *tk = NULL;
|
|
struct Statement *st = makeStatement();
|
|
struct Statement *st = makeStatement();
|
|
while (true){
|
|
while (true){
|
|
checkToken(pm, MATHER_LC, again_); // 若匹配的不是{则检查是否匹配到\n
|
|
checkToken(pm, MATHER_LC, again_); // 若匹配的不是{则检查是否匹配到\n
|
|
break; // 若匹配到{则跳出循环
|
|
break; // 若匹配到{则跳出循环
|
|
again_: checkToken(pm, MATHER_ENTER, return_); // 若不是\n则跳到return_
|
|
again_: checkToken(pm, MATHER_ENTER, return_); // 若不是\n则跳到return_
|
|
}
|
|
}
|
|
|
|
+ writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "parserCode: call pasersCommandList\n", NULL);
|
|
pasersCommandList(CALLPASERSSIGNATURE, false, st);
|
|
pasersCommandList(CALLPASERSSIGNATURE, false, st);
|
|
if (!call_success(pm)){
|
|
if (!call_success(pm)){
|
|
goto return_;
|
|
goto return_;
|
|
}
|
|
}
|
|
- readBackToken(code_type, pm);
|
|
|
|
- if (code_type != COMMANDLIST){
|
|
|
|
|
|
+ if (readBackToken(pm) != COMMANDLIST){
|
|
syntaxError(pm, "Not CommandList\n", syntax_error);
|
|
syntaxError(pm, "Not CommandList\n", syntax_error);
|
|
goto return_;
|
|
goto return_;
|
|
}
|
|
}
|
|
popAheadToken(code_token, pm);
|
|
popAheadToken(code_token, pm);
|
|
|
|
+ writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "parserCode: call pasersCommandList success\n", NULL);
|
|
checkToken(pm, MATHER_RC, error_);
|
|
checkToken(pm, MATHER_RC, error_);
|
|
|
|
|
|
return_:
|
|
return_:
|
|
@@ -258,14 +415,12 @@ void parserCode(PASERSSIGNATURE){
|
|
* | parserAssignment
|
|
* | parserAssignment
|
|
*/
|
|
*/
|
|
void parserOperation(PASERSSIGNATURE){
|
|
void parserOperation(PASERSSIGNATURE){
|
|
- int operation_type;
|
|
|
|
Token *operation_token = NULL;
|
|
Token *operation_token = NULL;
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Operation: call assignment\n", NULL);
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Operation: call assignment\n", NULL);
|
|
parserAssignment(CALLPASERSSIGNATURE);
|
|
parserAssignment(CALLPASERSSIGNATURE);
|
|
if (!call_success(pm))
|
|
if (!call_success(pm))
|
|
goto return_;
|
|
goto return_;
|
|
- readBackToken(operation_type, pm);
|
|
|
|
- if (operation_type != ASSIGNMENT){
|
|
|
|
|
|
+ if (readBackToken(pm) != ASSIGNMENT){
|
|
goto return_;
|
|
goto return_;
|
|
}
|
|
}
|
|
popAheadToken(operation_token, pm);
|
|
popAheadToken(operation_token, pm);
|
|
@@ -351,9 +506,7 @@ void parserFactor(PASERSSIGNATURE){
|
|
}
|
|
}
|
|
|
|
|
|
int tailCall(PASERSSIGNATURE, Token *left_token, Statement **st){
|
|
int tailCall(PASERSSIGNATURE, Token *left_token, Statement **st){
|
|
- int symbol;
|
|
|
|
- readBackToken(symbol, pm);
|
|
|
|
- if (symbol != MATHER_LP){
|
|
|
|
|
|
+ if (readBackToken(pm) != MATHER_LP){
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
delToken(pm);
|
|
delToken(pm);
|
|
@@ -371,21 +524,18 @@ void parserCallBack(PASERSSIGNATURE){
|
|
}
|
|
}
|
|
|
|
|
|
int getOperation(PASERSSIGNATURE, int right_type, Statement **st, char *name){
|
|
int getOperation(PASERSSIGNATURE, int right_type, Statement **st, char *name){
|
|
- int operation_type, rp;
|
|
|
|
Token *operation_token;
|
|
Token *operation_token;
|
|
|
|
|
|
parserOperation(CALLPASERSSIGNATURE);
|
|
parserOperation(CALLPASERSSIGNATURE);
|
|
if (!call_success(pm)){
|
|
if (!call_success(pm)){
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
- readBackToken(operation_type, pm);
|
|
|
|
- if (operation_type != OPERATION){
|
|
|
|
|
|
+ if (readBackToken(pm) != OPERATION){
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
popAheadToken(operation_token, pm);
|
|
popAheadToken(operation_token, pm);
|
|
|
|
|
|
- readBackToken(rp, pm);
|
|
|
|
- if (right_type != rp){
|
|
|
|
|
|
+ if (readBackToken(pm) != right_type){
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
delToken(pm);
|
|
delToken(pm);
|
|
@@ -405,7 +555,7 @@ void parserBaseValue(PASERSSIGNATURE){
|
|
int token_type;
|
|
int token_type;
|
|
Token *value_token = NULL;
|
|
Token *value_token = NULL;
|
|
struct Statement *st = NULL;
|
|
struct Statement *st = NULL;
|
|
- readBackToken(token_type, pm);
|
|
|
|
|
|
+ token_type = readBackToken(pm);
|
|
if(MATHER_NUMBER == token_type){
|
|
if(MATHER_NUMBER == token_type){
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Base Value: get number\n", NULL);
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Base Value: get number\n", NULL);
|
|
popAheadToken(value_token, pm);
|
|
popAheadToken(value_token, pm);
|
|
@@ -430,7 +580,7 @@ void parserBaseValue(PASERSSIGNATURE){
|
|
st->u.base_var.times = NULL;
|
|
st->u.base_var.times = NULL;
|
|
}
|
|
}
|
|
else if(MATHER_LB == token_type){
|
|
else if(MATHER_LB == token_type){
|
|
- int var, tmp;
|
|
|
|
|
|
+ int tmp;
|
|
Statement *tmp_st = NULL;
|
|
Statement *tmp_st = NULL;
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "base value: get operation\n", NULL);
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "base value: get operation\n", NULL);
|
|
popAheadToken(value_token, pm);
|
|
popAheadToken(value_token, pm);
|
|
@@ -446,8 +596,7 @@ void parserBaseValue(PASERSSIGNATURE){
|
|
syntaxError(pm, "Don't get ] from list/var", syntax_error);
|
|
syntaxError(pm, "Don't get ] from list/var", syntax_error);
|
|
goto return_;
|
|
goto return_;
|
|
}
|
|
}
|
|
- readBackToken(var, pm);
|
|
|
|
- if (MATHER_VAR == var){
|
|
|
|
|
|
+ if (MATHER_VAR == readBackToken(pm)){
|
|
Token *var_token;
|
|
Token *var_token;
|
|
popAheadToken(var_token, pm);
|
|
popAheadToken(var_token, pm);
|
|
st = makeStatement();
|
|
st = makeStatement();
|
|
@@ -486,20 +635,15 @@ void parserBaseValue(PASERSSIGNATURE){
|
|
|
|
|
|
inline void twoOperation(PASERSSIGNATURE, void (*callBack)(PASERSSIGNATURE), int (*getSymbol)(PASERSSIGNATURE, int symbol, Statement **st), int type, int self_type, char *call_name, char *self_name){
|
|
inline void twoOperation(PASERSSIGNATURE, void (*callBack)(PASERSSIGNATURE), int (*getSymbol)(PASERSSIGNATURE, int symbol, Statement **st), int type, int self_type, char *call_name, char *self_name){
|
|
while(true){
|
|
while(true){
|
|
- int left, symbol, right;
|
|
|
|
- Token *left_token = NULL, *symbol_token = NULL, *right_token = NULL;
|
|
|
|
|
|
+ Token *left_token = NULL, *right_token = NULL;
|
|
struct Statement *st = NULL;
|
|
struct Statement *st = NULL;
|
|
|
|
|
|
- readBackToken(left, pm);
|
|
|
|
- if (left != self_type){
|
|
|
|
|
|
+ readBackToken(pm);
|
|
|
|
+ if (readBackToken(pm) != self_type){
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "%s: call %s(left)\n", self_name, call_name);
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "%s: call %s(left)\n", self_name, call_name);
|
|
callBack(CALLPASERSSIGNATURE);
|
|
callBack(CALLPASERSSIGNATURE);
|
|
- if (!call_success(pm))
|
|
|
|
- goto return_;
|
|
|
|
- readBackToken(left, pm);
|
|
|
|
- if (left != type){
|
|
|
|
|
|
+ if (!call_success(pm) || (readBackToken(pm) != type))
|
|
goto return_;
|
|
goto return_;
|
|
- }
|
|
|
|
popAheadToken(left_token, pm);
|
|
popAheadToken(left_token, pm);
|
|
addStatementToken(self_type, left_token->data.st, pm);
|
|
addStatementToken(self_type, left_token->data.st, pm);
|
|
freeToken(left_token, true, false);
|
|
freeToken(left_token, true, false);
|
|
@@ -510,8 +654,7 @@ inline void twoOperation(PASERSSIGNATURE, void (*callBack)(PASERSSIGNATURE), int
|
|
popAheadToken(left_token, pm);
|
|
popAheadToken(left_token, pm);
|
|
|
|
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "%s: call symbol\n", self_name);
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "%s: call symbol\n", self_name);
|
|
- readBackToken(symbol, pm);
|
|
|
|
- if (getSymbol(CALLPASERSSIGNATURE, symbol, &st)){
|
|
|
|
|
|
+ if (getSymbol(CALLPASERSSIGNATURE, readBackToken(pm), &st)){
|
|
delToken(pm);
|
|
delToken(pm);
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
@@ -527,8 +670,7 @@ inline void twoOperation(PASERSSIGNATURE, void (*callBack)(PASERSSIGNATURE), int
|
|
freeStatement(st);
|
|
freeStatement(st);
|
|
goto return_;
|
|
goto return_;
|
|
}
|
|
}
|
|
- readBackToken(right, pm);
|
|
|
|
- if (right != type){ // 若非正确数值
|
|
|
|
|
|
+ if (readBackToken(pm) != type){ // 若非正确数值
|
|
char *tmp1, *tmp2;
|
|
char *tmp1, *tmp2;
|
|
tmp1 = memStrcat("ERROR from ", self_name);
|
|
tmp1 = memStrcat("ERROR from ", self_name);
|
|
tmp2 = memStrcat(tmp1, "(get right)");
|
|
tmp2 = memStrcat(tmp1, "(get right)");
|
|
@@ -550,20 +692,14 @@ inline void twoOperation(PASERSSIGNATURE, void (*callBack)(PASERSSIGNATURE), int
|
|
|
|
|
|
inline void tailOperation(PASERSSIGNATURE, void (*callBack)(PASERSSIGNATURE), int (*tailFunction)(PASERSSIGNATURE, Token *left_token, Statement **st), int type, int self_type, char *call_name, char *self_name){
|
|
inline void tailOperation(PASERSSIGNATURE, void (*callBack)(PASERSSIGNATURE), int (*tailFunction)(PASERSSIGNATURE, Token *left_token, Statement **st), int type, int self_type, char *call_name, char *self_name){
|
|
while(true){
|
|
while(true){
|
|
- int left, symbol;
|
|
|
|
- Token *left_token = NULL, *symbol_token = NULL, *right_token = NULL;
|
|
|
|
|
|
+ Token *left_token = NULL;
|
|
struct Statement *st = NULL;
|
|
struct Statement *st = NULL;
|
|
|
|
|
|
- readBackToken(left, pm);
|
|
|
|
- if (left != self_type){
|
|
|
|
|
|
+ if (readBackToken(pm) != self_type){
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "%s: call %s(left)\n", self_name, call_name);
|
|
writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "%s: call %s(left)\n", self_name, call_name);
|
|
callBack(CALLPASERSSIGNATURE);
|
|
callBack(CALLPASERSSIGNATURE);
|
|
- if (!call_success(pm))
|
|
|
|
|
|
+ if ((!call_success(pm)) || readBackToken(pm) != type)
|
|
goto return_;
|
|
goto return_;
|
|
- readBackToken(left, pm);
|
|
|
|
- if (left != type){
|
|
|
|
- goto return_;
|
|
|
|
- }
|
|
|
|
popAheadToken(left_token, pm);
|
|
popAheadToken(left_token, pm);
|
|
addStatementToken(self_type, left_token->data.st, pm);
|
|
addStatementToken(self_type, left_token->data.st, pm);
|
|
freeToken(left_token, true, false);
|
|
freeToken(left_token, true, false);
|
|
@@ -606,3 +742,16 @@ void syntaxError(ParserMessage *pm, char *message, int status){
|
|
pm->status = status;
|
|
pm->status = status;
|
|
pm->status_message = memStrcpy(message, 0, false, false);
|
|
pm->status_message = memStrcpy(message, 0, false, false);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+int readBackToken(ParserMessage *pm){
|
|
|
|
+ // TODO-szh 优化执行效果
|
|
|
|
+ writeLog(pm->grammar_debug, GRAMMAR_DEBUG, "token operation number : %d\n", pm->count);
|
|
|
|
+ writeLog(pm->paser_debug, DEBUG, "\ntoken operation number : %d\n", pm->count);
|
|
|
|
+ pm->count ++;
|
|
|
|
+ int status = safeGetToken(pm->tm, pm->paser_debug);
|
|
|
|
+ if (status == -2){
|
|
|
|
+ syntaxError(pm, "lexical make some error", lexical_error);
|
|
|
|
+ }
|
|
|
|
+ backToken(pm->tm->ts, pm->paser_debug);
|
|
|
|
+ return status;
|
|
|
|
+}
|