So I'm trying to write my typical calculator program I typically write when 
learning any language, and I'm having troubles with representing the expression 
as an AST (by making object which represent each node type, such as BinOp, 
Number, etc), but am having troubles with the recursive nature of it. Here's 
basically what I have
    
    
    type
      Node = ref object of RootObj
      
      Number = object of Node
        value: int
      
      BinOp = object of Node
        left: Node
        op: string
        right: Node
    
    
    Run

The problem is I want the BinOp object to either take a Number node or another 
BinOp node as it's left and right fields. How can I achieve this? Should I just 
abandon using objects and try to use perhaps a tuple instead? (For background, 
I have light experience with C, Rust, but am much more capable with Python)

Reply via email to