11use std::str::FromStr;
22use num_bigint::BigInt;
3- use analytic_engine::core::{TypedConst, BasicBinOp, BinOp, BasicUnaryOp, UnaryOp, Expr, NumRep};
3+ use analytic_engine::core::{TypedConst, BasicBinOp, BinOp, BasicUnaryOp, UnaryOp, Expr, NumRep, MachineRep };
44
55grammar;
66
@@ -10,7 +10,7 @@ pub Tree: Expr = {
1010 #[precedence(level="1")]
1111 <op:Op0> <t:Tree> => Expr::UnaryOp(op, Box::new(t)),
1212 #[precedence(level="2")]
13- <t:Tree> "as" <r:Rep > => Expr::Cast(r , Box::new(t)),
13+ <t:Tree> "as" <mr:MRep > => Expr::Cast(mr , Box::new(t)),
1414 #[precedence(level="3")] #[assoc(side="left")]
1515 <l:Tree> <op:Op1> <r:Tree> => Expr::BinOp(op, Box::new(l), Box::new(r)),
1616 #[precedence(level="4")] #[assoc(side="left")]
@@ -39,18 +39,18 @@ OpCode2: BasicBinOp = {
3939}
4040
4141Op0: UnaryOp = {
42- <op:OpCode0> <r:Rep > => UnaryOp::new(op, Some(r)),
42+ <op:OpCode0> <r:MRep > => UnaryOp::new(op, Some(r)),
4343 <op:OpCode0> => UnaryOp::new(op, None),
4444}
4545
4646Op1: BinOp = {
47- <op:OpCode1> <r:Rep > => BinOp::new(op, Some(r)),
47+ <op:OpCode1> <r:MRep > => BinOp::new(op, Some(r)),
4848 <op:OpCode1> => BinOp::new(op, None),
4949}
5050
5151Op2: BinOp = {
52- <op:OpCode2> <r:Rep > => BinOp::new(op, Some(r)),
53- <op: OpCode2> => BinOp::new(op , None),
52+ <op:OpCode2> <r:MRep > => BinOp::new(op, Some(r)),
53+ OpCode2 => BinOp::new(<> , None),
5454}
5555
5656Const: TypedConst = {
@@ -59,14 +59,20 @@ Const: TypedConst = {
5959}
6060
6161Rep: NumRep = {
62- "u8" => NumRep::U8,
63- "u16" => NumRep::U16,
64- "u32" => NumRep::U32,
65- "u64" => NumRep::U64,
66- "i8" => NumRep::I8,
67- "i16" => NumRep::I16,
68- "i32" => NumRep::I32,
69- "i64" => NumRep::I64,
62+ "?" => NumRep::AUTO,
63+ MRep => NumRep::Concrete(<>),
64+ }
65+
66+
67+ MRep: MachineRep = {
68+ "u8" => MachineRep::U8,
69+ "u16" => MachineRep::U16,
70+ "u32" => MachineRep::U32,
71+ "u64" => MachineRep::U64,
72+ "i8" => MachineRep::I8,
73+ "i16" => MachineRep::I16,
74+ "i32" => MachineRep::I32,
75+ "i64" => MachineRep::I64,
7076}
7177
7278Num: BigInt = <s:r"-?[0-9]+"> => BigInt::from_str(s).unwrap();
0 commit comments