From 1ecee352f5844b0809d7ae66df52e34f42b44c8e Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 6 Mar 2025 20:33:27 +1300 Subject: Rewrite entire assembler The language is now more general, the code is better structured, error reporting is more detailed, and many new language features have been implemented: - conditional blocks - first-class strings - more expression operators - binary literals - negative values - invocations in constant expressions --- src/tokens/expression.rs | 78 ------------------------------------------------ 1 file changed, 78 deletions(-) delete mode 100644 src/tokens/expression.rs (limited to 'src/tokens/expression.rs') diff --git a/src/tokens/expression.rs b/src/tokens/expression.rs deleted file mode 100644 index 1d8a336..0000000 --- a/src/tokens/expression.rs +++ /dev/null @@ -1,78 +0,0 @@ -use crate::*; - - -#[derive(Clone)] -pub struct Expression { - pub source: SourceSpan, - pub tokens: Vec, -} - -#[derive(Clone)] -pub struct ExpressionToken { - pub source: SourceSpan, - pub variant: ExpressionTokenVariant, -} - -#[derive(Clone)] -pub enum ExpressionTokenVariant { - Invocation(String), - Literal(isize), - Operator(Operator), - Error(ExpressionParseError), -} - -#[derive(Clone, Copy, Debug)] -pub enum Operator { - Equal, - NotEqual, - LessThan, - GreaterThan, - LessThanEqual, - GreaterThanEqual, - Add, - Subtract, - LeftShift, - RightShift, - And, - Or, - Xor, - Not, -} - -#[derive(Clone)] -pub enum ExpressionParseError { - InvalidHexadecimalLiteral(String), -} - -impl std::fmt::Debug for Expression { - fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - for (i, token) in self.tokens.iter().enumerate() { - let string = match &token.variant { - ExpressionTokenVariant::Invocation(name) => name, - ExpressionTokenVariant::Literal(value) => &value.to_string(), - ExpressionTokenVariant::Operator(operator) => match operator { - Operator::Equal => "=", - Operator::NotEqual => "!=", - Operator::LessThan => "<", - Operator::GreaterThan => ">", - Operator::LessThanEqual => "<=", - Operator::GreaterThanEqual => ">=", - Operator::Add => "+", - Operator::Subtract => "-", - Operator::LeftShift => "<<", - Operator::RightShift => ">>", - Operator::And => "&", - Operator::Or => "|", - Operator::Xor => "^", - Operator::Not => "~", - } - ExpressionTokenVariant::Error(_) => "", - }; - match i { - 0 => write!(f, "{string}")?, - _ => write!(f, " {string}")?, - } - } - return Ok(()); - } -} -- cgit v1.2.3-70-g09d2