Select Git revision
Forked from
Per Lindgren / D7050E
Source project has a limited visibility.
main3.rs 8.78 KiB
use nom::{branch, bytes::complete::tag, character::complete::digit1, error, Err};
use nom_locate::LocatedSpan;
const INPUT: &str = "-2+3**2*3/5-4";
//const INPUT: &str = "2+-3";
//const INPUT: &str = "2+30000000000000000000000";
//const INPUT: &str = "2";
//const INPUT: &str = "30000000000000000000000";
//const INPUT: &str = "3+2a";
const UNARYS: [Funcmap; 1] = [Funcmap {
keyword: "-",
prec: 4,
ass: Ass::Right,
func: Function::UnSub,
}];
const INFIXS: [Funcmap; 5] = [
Funcmap {
keyword: "**",
prec: 3,
ass: Ass::Right,
func: Function::Pow,
},
Funcmap {
keyword: "*",
prec: 2,
ass: Ass::Left,
func: Function::Mult,
},
Funcmap {
keyword: "/",
prec: 2,
ass: Ass::Left,
func: Function::Div,
},
Funcmap {
keyword: "+",
prec: 1,
ass: Ass::Left,
func: Function::Add,
},
Funcmap {
keyword: "-",
prec: 1,
ass: Ass::Left,
func: Function::Sub,
},
];
struct Expr<'a> {
span: Span<'a>,
val: Value<'a>,
}
enum Value<'a> {
Int(i32),
UnFunc(Function, Box<Expr<'a>>),
Func(Function, Box<Expr<'a>>, Box<Expr<'a>>),
}
#[derive(Clone, Copy)]
enum Function {
UnSub,
Pow,
Mult,
Div,
Add,
Sub,
}