Mathematica-like environment on the mbed using USB keyboard input, VGA output, and a thermal printer.

Dependencies:   mbed Thermal 4DGL-uLCD-SE USBHost_Modified uVGAIII

Committer:
zrussell3
Date:
Thu Dec 13 20:27:21 2018 +0000
Revision:
6:646d22295054
Implemented parsing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zrussell3 6:646d22295054 1 #ifndef TREE_H
zrussell3 6:646d22295054 2 #define TREE_H
zrussell3 6:646d22295054 3
zrussell3 6:646d22295054 4 /* The type of any binary or unary operators */
zrussell3 6:646d22295054 5 enum token_type {
zrussell3 6:646d22295054 6 TOKEN_NUM,
zrussell3 6:646d22295054 7 TOKEN_ADD,
zrussell3 6:646d22295054 8 TOKEN_SUB,
zrussell3 6:646d22295054 9 TOKEN_MUL,
zrussell3 6:646d22295054 10 TOKEN_DIV,
zrussell3 6:646d22295054 11 TOKEN_EXP,
zrussell3 6:646d22295054 12 TOKEN_VAR,
zrussell3 6:646d22295054 13 TOKEN_FUN,
zrussell3 6:646d22295054 14 TOKEN_LPA,
zrussell3 6:646d22295054 15 TOKEN_RPA
zrussell3 6:646d22295054 16 };
zrussell3 6:646d22295054 17
zrussell3 6:646d22295054 18
zrussell3 6:646d22295054 19 /* The type of any binary or unary operators */
zrussell3 6:646d22295054 20 enum op_type {
zrussell3 6:646d22295054 21 OP_ADD,
zrussell3 6:646d22295054 22 OP_SUB,
zrussell3 6:646d22295054 23 OP_MUL,
zrussell3 6:646d22295054 24 OP_DIV,
zrussell3 6:646d22295054 25 OP_EXP
zrussell3 6:646d22295054 26 };
zrussell3 6:646d22295054 27
zrussell3 6:646d22295054 28 /* The type of each node */
zrussell3 6:646d22295054 29 enum node_type {
zrussell3 6:646d22295054 30 NODE_NUMBER, /* Holds one number in data.fval, no children */
zrussell3 6:646d22295054 31 NODE_VAR, /* Holds the name of the var in data.name */
zrussell3 6:646d22295054 32 NODE_BINOP, /* Has the operator in op and both left and right children*/
zrussell3 6:646d22295054 33 NODE_FUNC /* Has the function name in data.name and a left child */
zrussell3 6:646d22295054 34 };
zrussell3 6:646d22295054 35
zrussell3 6:646d22295054 36
zrussell3 6:646d22295054 37
zrussell3 6:646d22295054 38 /* The structure that holds the parse tree */
zrussell3 6:646d22295054 39 struct node{
zrussell3 6:646d22295054 40 enum node_type type;
zrussell3 6:646d22295054 41 union data{
zrussell3 6:646d22295054 42 float fval;
zrussell3 6:646d22295054 43 char *name;
zrussell3 6:646d22295054 44 enum op_type op;
zrussell3 6:646d22295054 45 } data;
zrussell3 6:646d22295054 46 struct node *left;
zrussell3 6:646d22295054 47 struct node *right;
zrussell3 6:646d22295054 48 struct node *parent;
zrussell3 6:646d22295054 49 };
zrussell3 6:646d22295054 50
zrussell3 6:646d22295054 51 /* Prints a tree of nodes, indenting as it descends the tree */
zrussell3 6:646d22295054 52 void print_node(struct node*);
zrussell3 6:646d22295054 53 /* Creates a new node of number type */
zrussell3 6:646d22295054 54 struct node* new_number_node(float num);
zrussell3 6:646d22295054 55 /* Creates a new node of var type */
zrussell3 6:646d22295054 56 struct node* new_var_node(char* str);
zrussell3 6:646d22295054 57 /* Creates a new node for a binary operator, with left and right children */
zrussell3 6:646d22295054 58 struct node* new_binop_node(enum op_type, struct node* left, struct node *right);
zrussell3 6:646d22295054 59 struct node* new_func_node(char* name, struct node* left);
zrussell3 6:646d22295054 60
zrussell3 6:646d22295054 61
zrussell3 6:646d22295054 62 #endif