lab1
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
# 批量测试所有.sy文件的语法解析
|
||||
|
||||
test_dir="/home/lingli/nudt-compiler-cpp/test/test_case/functional"
|
||||
test_dir="/home/lingli/nudt-compiler-cpp/test/test_case"
|
||||
compiler="/home/lingli/nudt-compiler-cpp/build/bin/compiler"
|
||||
|
||||
if [ ! -f "$compiler" ]; then
|
||||
@@ -21,14 +21,16 @@ echo "="
|
||||
for test_file in $(find "$test_dir" -name "*.sy" | sort); do
|
||||
echo "测试: $(basename "$test_file")"
|
||||
|
||||
# 运行解析测试,将输出重定向到/dev/null
|
||||
"$compiler" --emit-parse-tree "$test_file" > /dev/null 2>&1
|
||||
# 运行解析测试,捕获输出
|
||||
output=$("$compiler" --emit-parse-tree "$test_file" 2>&1)
|
||||
exit_code=$?
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ $exit_code -eq 0 ]; then
|
||||
echo " ✓ 成功"
|
||||
((success_count++))
|
||||
else
|
||||
echo " ✗ 失败"
|
||||
echo " 错误信息: $output"
|
||||
((failed_count++))
|
||||
failed_tests+=($(basename "$test_file"))
|
||||
fi
|
||||
|
||||
@@ -75,17 +75,19 @@ FLITERAL
|
||||
;
|
||||
|
||||
fragment DECIMAL_FLOAT
|
||||
: (('+' | '-')? (DIGIT+ '.' DIGIT* | '.' DIGIT+ | DIGIT+)
|
||||
: ((DIGIT+ '.' DIGIT* | '.' DIGIT+)
|
||||
(('E' | 'e') ('+' | '-')? DIGIT+)?)
|
||||
| (('+' | '-')? '0' [0-7]+ '.' [0-7]*
|
||||
| ((DIGIT+ '.' DIGIT* | '.' DIGIT+ | DIGIT+)
|
||||
(('E' | 'e') ('+' | '-')? DIGIT+))
|
||||
| ('0' [0-7]+ '.' [0-7]*
|
||||
(('E' | 'e') ('+' | '-')? DIGIT+)?)
|
||||
;
|
||||
|
||||
fragment HEX_FLOAT
|
||||
: ('+' | '-')? '0' ('x' | 'X')
|
||||
: '0' ('x' | 'X')
|
||||
(HEXDIGIT* '.' HEXDIGIT+ | HEXDIGIT+ '.')
|
||||
(('P' | 'p') ('+' | '-')? DIGIT+)
|
||||
| ('+' | '-')? '0' ('x' | 'X')
|
||||
| '0' ('x' | 'X')
|
||||
HEXDIGIT+
|
||||
(('P' | 'p') ('+' | '-')? DIGIT+)
|
||||
;
|
||||
@@ -104,13 +106,14 @@ LINECOMMENT: '//' ~[\r\n]* -> skip;
|
||||
BLOCKCOMMENT: '/*' .*? '*/' -> skip;
|
||||
|
||||
/*===-------------------------------------------===*/
|
||||
/* Parser rules */
|
||||
/* Syntax rules */
|
||||
/*===-------------------------------------------===*/
|
||||
|
||||
compUnit
|
||||
: (decl | funcDef)* EOF
|
||||
;
|
||||
|
||||
// 声明
|
||||
decl
|
||||
: constDecl
|
||||
| varDecl
|
||||
@@ -143,6 +146,7 @@ initValue
|
||||
| LBRACE (initValue (COMMA initValue)*)? RBRACE
|
||||
;
|
||||
|
||||
// 函数定义
|
||||
funcDef
|
||||
: funcType ID LPAREN (funcFParams)? RPAREN blockStmt
|
||||
;
|
||||
@@ -161,6 +165,7 @@ funcFParam
|
||||
: btype ID (LBRACK (exp)? RBRACK)*
|
||||
;
|
||||
|
||||
// 语句
|
||||
blockStmt
|
||||
: LBRACE blockItem* RBRACE
|
||||
;
|
||||
@@ -245,4 +250,3 @@ number
|
||||
: ILITERAL
|
||||
| FLITERAL
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user