mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-30 06:51:04 +00:00
37 lines
779 B
Rust
37 lines
779 B
Rust
use std::fmt::{Debug, Formatter, Error};
|
|
|
|
pub enum Expr {
|
|
Number(i32),
|
|
Op(Box<Expr>, Opcode, Box<Expr>),
|
|
}
|
|
|
|
#[derive(Copy, Clone)]
|
|
pub enum Opcode {
|
|
Mul,
|
|
Div,
|
|
Add,
|
|
Sub,
|
|
}
|
|
|
|
impl Debug for Expr {
|
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
|
use self::Expr::*;
|
|
match *self {
|
|
Number(n) => write!(fmt, "{:?}", n),
|
|
Op(ref l, op, ref r) => write!(fmt, "({:?} {:?} {:?})", l, op, r),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Debug for Opcode {
|
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
|
use self::Opcode::*;
|
|
match *self {
|
|
Mul => write!(fmt, "*"),
|
|
Div => write!(fmt, "/"),
|
|
Add => write!(fmt, "+"),
|
|
Sub => write!(fmt, "-"),
|
|
}
|
|
}
|
|
}
|