Advertisement
tinyevil

Untitled

Dec 27th, 2018
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. enum Expr{
  2.     case Literal{
  3.         case Int(value:bigint);
  4.         case String(value:bytearray);
  5.        
  6.         var type: *Type;
  7.     }
  8.    
  9.     case BinOp(op:Token, lhs: *Expr, rhs: *Expr);
  10.     case UnOp(op:Token, arg: *Expr);
  11.  
  12.     var loc: SourceLocation;
  13.     var meta: *MetadataNode;
  14. }
  15.  
  16. void process_expr(e:*Expr){
  17.     switch (e){
  18.     case Literal.String(value):
  19.         print("found some string!" + value.to_utf8() + " at " + e.loc);
  20.     case BinOp(_, lhs, rhs):
  21.         process_expr(lhs);
  22.         process_expr(rhs);
  23.     case UnOp(_, arg) as unop:
  24.         process_expr(arg);
  25.         work_with_unop(unop);
  26.     }
  27. }
  28.  
  29. void work_with_unop(unop:*UnOp){
  30.     if (unop.op == Token.Plus) {
  31.         unop.op = Token.Minus;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement