-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_errors.rs
More file actions
34 lines (29 loc) · 1.12 KB
/
test_errors.rs
File metadata and controls
34 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use rustc_tape4::{Lexer, Parser, SemanticAnalyzer};
fn main() {
let files = [
"tests/fixtures/error_missing_semicolon.c",
"tests/fixtures/error_undefined_var.c",
"tests/fixtures/error_type_mismatch.c",
"tests/fixtures/error_invalid_token.c",
];
for file_path in &files {
println!("\n=== Testing {} ===", file_path);
let source = std::fs::read_to_string(file_path).expect("could not read file");
// lexing
let tokens = Lexer::new(&source).collect_spanned_tokens();
// parsing
let mut parser = Parser::new(tokens);
match parser.parse_program() {
Ok(program) => {
println!("Parsing successful");
// semantic analysis
let mut analyzer = SemanticAnalyzer::new(&program);
match analyzer.analyze() {
Ok(_) => println!("Semantic analysis successful"),
Err(e) => println!("Semantic error: {:?}", e),
}
}
Err(e) => println!("Parser error: {:?}", e),
}
}
}