An Interpreter for Pascal programming language written in Rust, that alternate the original Pascal's syntax a little bit.
[x] tests for tokenizer
[x] evaluating expressions
[] parse into some basic statements
[] add functionalities to these statements
-
It's hard to clone an enum -> Enum instance, Token::IntegerLiteral for example, only known at runtime, and cannot be seen as a type, only Token is the type
-
To evaluate expression: Expression valuated to Token type, but its type is only Token, cannot add or minus due to unknown type of literals, to solve do either:
- Use Operator Overloading,
Token + Token, match and return result - Implement trait objects for i32,f64,..., then use that as a type instead of Token, -> CANT due to no operator for that trait objects, still need implement ops like above -> Due to being at runtime, Rust doesnt know if it implements ops::Add
- Match ops in binary then match data types, pretty similar to 1, but less flexible
- Static Inference: the tokenizer can guess the type of data, Token::IntegerLiteral or Token::FloatLiteral, -> if allow changing data types of variables, then it's dynamic language -> if not, then it's a static language that has inference as feature
e.g https://craftinginterpreters.com/evaluating-expressions.html#evaluating-unary-expressions
var a = 1; statement if () then begin end else begin end while (exp) do statements for (expr) do statements function_call(expr)