Report sytax errors
This commit is contained in:
parent
236a9c296b
commit
df772ec737
@ -1,6 +1,7 @@
|
||||
use std::io::{self, Write};
|
||||
|
||||
use crate::symbol_table::SymbolTable;
|
||||
use crate::token::Token;
|
||||
|
||||
use super::lexic;
|
||||
use super::syntax;
|
||||
@ -12,11 +13,7 @@ fn compile(input: &String) {
|
||||
|
||||
match _tokens {
|
||||
Ok(tokens) => {
|
||||
let mut ast = syntax::construct_ast(&tokens).unwrap();
|
||||
let mut table = SymbolTable::new();
|
||||
semantic::check_ast(&mut ast, &mut table);
|
||||
let js_code = codegen::codegen(&ast);
|
||||
println!("{}", js_code)
|
||||
build_ast(tokens);
|
||||
},
|
||||
Err(error) => {
|
||||
eprintln!("Error scanning.\n{} at pos {}", error.reason, error.position)
|
||||
@ -25,6 +22,22 @@ fn compile(input: &String) {
|
||||
|
||||
}
|
||||
|
||||
fn build_ast(tokens: Vec<Token>) {
|
||||
let ast = syntax::construct_ast(&tokens);
|
||||
|
||||
match ast {
|
||||
Ok(mut ast) => {
|
||||
let mut table = SymbolTable::new();
|
||||
semantic::check_ast(&mut ast, &mut table);
|
||||
let js_code = codegen::codegen(&ast);
|
||||
println!("{}", js_code)
|
||||
}
|
||||
Err(reason) => {
|
||||
eprintln!("Syntax error.\n{}", reason)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run() -> io::Result<()> {
|
||||
let stdin = io::stdin();
|
||||
let mut buffer = String::new();
|
||||
|
@ -1,7 +1,6 @@
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
pub enum TokenType {
|
||||
Identifier,
|
||||
Comment,
|
||||
Number,
|
||||
String,
|
||||
Operator,
|
||||
|
Loading…
Reference in New Issue
Block a user