Infinity Calculator implementation for Assignment 2 in Computer Organization.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

42 lines
1.1 KiB

#ifndef EXPRH
#define EXPRH
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define EXFLAG_LEXP 0x1 // There is an expression on the left.
#define EXFLAG_REXP 0x2 // There is an expression on the right.
#define EXFLAG_LNEG 0x4 // Negate the value on the left.
#define EXFLAG_RNEG 0x8 // Negate the value on the right.
#define EXFLAG_PAREN 0x10 // Override priority due to parenthesises.
#define EXFLAG_MOD 0x20 // For differentiating same priority operations.
#define EXFLAG_HEX 0x40 // When concatinating, multiply left side by 256.
#define EXPR_NULL 0 // Needed for the initial root node.
#define EXPR_ADD 1 // MOD = 0 RNEG = 0
#define EXPR_SUB 1 // MOD = 0 RNEG = 1
#define EXPR_CONCAT 1 // MOD = 1 RNEG = 0
#define EXPR_MULT 2 // MOD = 0
#define EXPR_DIV 2 // MOD = 1
#define EXPR_IPOW 3
typedef struct expr_t {
int flags;
int opcode;
struct expr_t *par;
union {
uint8_t data;
struct expr_t *expr;
} left;
union {
uint8_t data;
struct expr_t *expr;
} right;
} expr_t;
expr_t *bubble_expr(expr_t *t, expr_t *n);
void print_expr_tree(expr_t *t, int depth);
void destroy_expr(expr_t *e);
#endif