步骤1:VAR_TEMP 词法+语法支持(token/关键字/VarSection::Temp/保留字放行)+ 测试

This commit is contained in:
2026-08-26 17:53:25 +08:00
parent 6fa4eda020
commit aa0c66780c
6 changed files with 51 additions and 5 deletions
+11
View File
@@ -197,7 +197,18 @@ static bool test_line1() {
return true;
}
static bool test_var_temp_kw() {
using namespace compiler;
std::vector<Token> ts;
std::string err;
CHECK(lex("t.st", "VAR_TEMP", &ts, &err));
CHECK(!ts.empty());
CHECK(ts[0].type == Tok::VAR_TEMP);
return true;
}
int main() {
if (!test_var_temp_kw()) return 1;
if (!test_basic()) return 1;
if (!test_case()) return 1;
if (!test_symbols()) return 1;
+31
View File
@@ -289,7 +289,38 @@ static bool test_negative() {
return true;
}
// ---- VAR_TEMP 段:解析为 VarSection::Temp ----
static bool test_var_temp() {
using namespace compiler;
Unit u;
std::string err;
CHECK(parse_pous("t.st",
"FUNCTION_BLOCK Foo\n"
"VAR_INPUT\n in : BOOL;\nEND_VAR\n"
"VAR_OUTPUT\n out : BOOL;\nEND_VAR\n"
"VAR\n state : BOOL;\nEND_VAR\n"
"VAR_TEMP\n tmp : INT;\nEND_VAR\n"
" out := tmp > 0;\n"
"END_FUNCTION_BLOCK",
&u, &err));
CHECK(u.pous.size() == 1);
const POU& p = u.pous[0];
CHECK(p.kind == PouKind::FunctionBlock);
CHECK(p.blocks.size() == 4);
CHECK(p.blocks[0].section == VarSection::Input);
CHECK(p.blocks[1].section == VarSection::Output);
CHECK(p.blocks[2].section == VarSection::Local);
CHECK(p.blocks[3].section == VarSection::Temp);
CHECK(p.blocks[3].vars.size() == 1);
CHECK(p.blocks[3].vars[0].name == "tmp");
CHECK(p.blocks[3].vars[0].type.kind == TypeKind::Scalar);
CHECK(p.blocks[3].vars[0].type.name == "int");
return true;
}
int main() {
if (!test_var_temp()) return 1;
if (!test_gvl_file()) return 1;
if (!test_fb()) return 1;
if (!test_program()) return 1;