Skip to content
Discussion options

You must be logged in to vote

Thanks! egg requires pretty much total control over your AST, since it needs to be able to put stuff in the e-graph. So it's pretty common to have an "algebraic" version of your AST that you'll work with and and egg version that's flatter.

So yours might look like

enum Expr {
  Add(Box<Self>, Box<Self>),
  Num(i32),
}

But the egg version will look like

define_language! {
    enum SimpleLanguage {
        "+" = Add([Id; 2]),
        Num(i32),
    }
}

where basically every instance of recursion in the AST is replaced with an Id.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@LegNeato
Comment options

@mwillsey
Comment options

Answer selected by LegNeato
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants