捕获错误并继续返回调用函数
Catching the error and continue back to the calling function
我正在 flex/lex 工具中使用 decaf 语言构建 scanner/lexical_analyser。
为了检查标识符,我实现了正则表达式 id [A-Za-z][A-Za-z0-9_]*
{id} { matchedID(); return T_Identifier; }
我也喜欢检查错误的标识符,所以我写了一个方法来处理它:
* Checking ID validness */
static void matchedID()
{
strncpy(yylval.identifier,yytext,MaxIdentLen);
if (yyleng > MaxIdentLen)
{
ReportError::LongIdentifier(&yylloc,yytext);
return;
}
}
现在,当我 运行 我的扫描仪扫描 test_file 时,其中包含:
vari.able
,
3variable
,
variable/123
,
var-123
,
variable_whose_name_is_much_too_long
扫描器逃避检查所有变量并报告关于最后一个 long 变量的错误(decaf var max_size_is 31 所以它 t运行 相应地对其进行分类)。
如果我取出长名称的变量,扫描器会完美地扫描文件的其余部分!
谁能告诉我如何修复它,以便当扫描器发现一个长变量并报告错误时,它还应该扫描文件中的其他语句?
所以我注意到扫描器脚本以某种方式没有与我的服务器同步,我所做的更改仅在客户端本地进行,一旦服务器开始与客户端文件同步,一切都开始恢复正常。
我想删除我的问题,但后来我想以后可能会有其他人遇到同样的问题:)
我正在 flex/lex 工具中使用 decaf 语言构建 scanner/lexical_analyser。
为了检查标识符,我实现了正则表达式 id [A-Za-z][A-Za-z0-9_]*
{id} { matchedID(); return T_Identifier; }
我也喜欢检查错误的标识符,所以我写了一个方法来处理它:
* Checking ID validness */
static void matchedID()
{
strncpy(yylval.identifier,yytext,MaxIdentLen);
if (yyleng > MaxIdentLen)
{
ReportError::LongIdentifier(&yylloc,yytext);
return;
}
}
现在,当我 运行 我的扫描仪扫描 test_file 时,其中包含:
vari.able
,
3variable
,
variable/123
,
var-123
,
variable_whose_name_is_much_too_long
扫描器逃避检查所有变量并报告关于最后一个 long 变量的错误(decaf var max_size_is 31 所以它 t运行 相应地对其进行分类)。 如果我取出长名称的变量,扫描器会完美地扫描文件的其余部分! 谁能告诉我如何修复它,以便当扫描器发现一个长变量并报告错误时,它还应该扫描文件中的其他语句?
所以我注意到扫描器脚本以某种方式没有与我的服务器同步,我所做的更改仅在客户端本地进行,一旦服务器开始与客户端文件同步,一切都开始恢复正常。
我想删除我的问题,但后来我想以后可能会有其他人遇到同样的问题:)