switched to lrpar parser generator

This commit is contained in:
2025-10-23 16:15:25 +02:00
parent f9a7016dcf
commit 4c08803a54
19 changed files with 490 additions and 379 deletions

View File

@@ -1,10 +1,37 @@
use lalrpop_util::lalrpop_mod;
use crate::errors::CLIArgumentError;
use lrlex::lrlex_mod;
use lrpar::lrpar_mod;
use std::error::Error;
use std::fmt::{Display, format};
use std::io;
use std::io::ErrorKind::InvalidInput;
mod ast;
mod errors;
mod optimising;
mod tests;
lalrpop_mod!(pub expressions);
lrlex_mod!("grammar.l");
lrpar_mod!("grammar.y");
fn main() {
println!("Hello, world!");
fn main() -> Result<(), Box<dyn Error>> {
let src_path = std::env::args()
.nth(1)
.ok_or(Box::new(CLIArgumentError("Source File Not Provided")))?;
let src_string = std::fs::read_to_string(&src_path)?;
let lexerdef = grammar_l::lexerdef();
let lexer = lexerdef.lexer((src_string.as_str()));
let (res, errs) = grammar_y::parse(&lexer);
if let Some(Ok(res)) = res {
println!("{:#?}", res);
}
Ok(())
}
// fn main() {
// if let Err(ref e) = main_() {
// return e.fmt()
// }
// }