931af90789
- implemented type parsing including custom types and generics (useless for now as we do no semantic analysis) - implemented struct literal parsing - implemented struct definition parsing (no generics yet) - implemented tuple parsing - registers are now allocated starting from zero - updated to-dos
39 lines
1.0 KiB
Rust
39 lines
1.0 KiB
Rust
use common::logging::log;
|
|
|
|
use crate::model::{CompilerError, Program};
|
|
use parser::{ParseResult, Parser};
|
|
// use semantic_analyser::Analyser;
|
|
|
|
pub mod lexer;
|
|
pub mod parser;
|
|
// pub mod semantic_analyser;
|
|
|
|
pub fn generate_ast(input: &str) -> Result<Program, CompilerError> {
|
|
log("Tokenising Input...");
|
|
|
|
let lexer = lexer::Lexer::new(&input);
|
|
let tokens = lexer.collect::<Vec<_>>();
|
|
println!("{tokens:#?}");
|
|
|
|
log(&format!("Parsing {} Tokens...", tokens.len()));
|
|
|
|
let mut parser = Parser::new(tokens);
|
|
let ast = match parser.parse() {
|
|
ParseResult::Accept(ast) => ast,
|
|
ParseResult::Reject(e) => return Err(e),
|
|
ParseResult::Deny => {
|
|
return Err(CompilerError::Generic("Parser used ::Deny".to_string()));
|
|
}
|
|
};
|
|
// println!("{ast:#?}");
|
|
|
|
log("Analyzing AST...");
|
|
log("Checking Type Information...");
|
|
|
|
// let mut analyser = Analyser::new();
|
|
// analyser.analyse(ast.clone()).unwrap();
|
|
|
|
log("Type Checking Complete...");
|
|
Ok(ast)
|
|
}
|