error fixing

This commit is contained in:
afonya 2025-06-16 22:11:01 +02:00
parent 52b2e6fcc0
commit de8a3c655b
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC
4 changed files with 18 additions and 4 deletions

View file

@ -233,9 +233,9 @@ fn nerd_kerek(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemor
}
};
let rounded = match mode.as_str() {
"up" => num.ceil(),
"down" => num.floor(),
"nearest" => num.round(),
"fel" => num.ceil(),
"le" => num.floor(),
"közel" => num.round(),
_ => {
error(format!("Unknown rounding mode: {}", mode), machine, op);
return VMMemory::Null(VMMemoryNull { variable_id: 0 });

View file

@ -25,6 +25,7 @@ pub enum ErrorSubType {
VariableAlreadyExists,
ArgumentDuplication,
TooManyArguments,
NoExpression,
//Machine errors
RegisterNotFound,
MemoryOutOfBounds,
@ -107,6 +108,7 @@ fn convert_subtypes_to_string(stype: &ErrorSubType) -> String {
ErrorSubType::TooManyArguments => String::from("Too many arguments"),
ErrorSubType::FileError => String::from("File error"),
ErrorSubType::RuntimeError => String::from("Runtime error"),
ErrorSubType::NoExpression => String::from("No expression found"),
}
}
fn convert_subtypes_to_short(stype: &ErrorSubType) -> String {
@ -135,6 +137,7 @@ fn convert_subtypes_to_short(stype: &ErrorSubType) -> String {
ErrorSubType::TooManyArguments => String::from("TA:"),
ErrorSubType::FileError => String::from("FE:"),
ErrorSubType::RuntimeError => String::from("RE:"),
ErrorSubType::NoExpression => String::from("NE:"),
}
}
pub fn reverse_subtype_short(str: String) -> ErrorSubType {
@ -163,6 +166,7 @@ pub fn reverse_subtype_short(str: String) -> ErrorSubType {
"TA" => ErrorSubType::TooManyArguments,
"FE" => ErrorSubType::FileError,
"RE" => ErrorSubType::RuntimeError,
"NE" => ErrorSubType::NoExpression,
_ => panic!("Unknown error subtype short: {}", str),
}
}

View file

@ -306,6 +306,11 @@ fn shunt(input: Vec<ASTPart>, ctx: &Context) -> ASTPart {
}
}
}
if output.len() == 0 {
let err = create_error(&format!("No expressions found after applying order of operations"), 0, ErrorType::SemanticError, ErrorSubType::NoExpression);
print_error(&err, &ctx);
process::exit(1);
}
return output[0].clone();
}
fn read_function(input: &Vec<Token>, pos: &mut usize, with_args: bool, ctx: &Context) -> ASTPart {

View file

@ -1 +1,6 @@
ugass(3.3)
gethelj a = -6.5
ugass(nerd.abs(a))
ugass(nerd.kerek(a, szaft"fel"szaft))
ugass(nerd.sqrt(16))
ugass(nerd.legnagyobb(3,56,66,1,12,55,6))
ugass(nerd.legkisebb(3,56,66,1,12,55,6))