Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Keep these headers */
- #include <stdbool.h>
- #include <stddef.h>
- #include <stdint.h>
- #include <tice.h>
- /* Standard headers (recommended) */
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fileioc.h>
- #define TYPE_NUMBER 0
- typedef uint24_t num_t;
- typedef uint8_t vari_t;
- typedef uint8_t op_t;
- typedef struct {
- uint8_t function;
- uint8_t function2;
- uint8_t amountOfArgs;
- } func_t;
- typedef union {
- num_t num;
- vari_t var;
- op_t op;
- func_t func;
- } operand_t;
- typedef struct {
- uint8_t isString;
- uint8_t type;
- uint8_t mask;
- operand_t operand;
- } element_t;
- typedef struct node {
- element_t data;
- struct node *prev;
- struct node *child;
- struct node *sibling;
- } NODE;
- NODE *push(NODE *top, element_t data) {
- NODE *tempNode = (NODE*)malloc(sizeof(NODE));
- tempNode->data = data;
- tempNode->prev = top;
- top->sibling = tempNode;
- return tempNode;
- }
- NODE *insertNode(NODE *top, element_t data, uint8_t index) {
- NODE *tempNode = (NODE*)calloc(1, sizeof(NODE));
- uint8_t temp;
- tempNode->data = data;
- for (temp = 1; temp < index; temp++) {
- top = top->prev;
- if (top == NULL) {
- return NULL;
- }
- }
- if (top == NULL) {
- return NULL;
- }
- top->prev->sibling = tempNode;
- tempNode->child = top;
- return tempNode;
- }
- int _getc(void) {
- return 0;
- }
- uint8_t getIndexOfOperator(uint8_t tok) {
- return 0;
- }
- uint8_t parseExpression(int token) {
- NODE *outputNode = (NODE*)calloc(1, sizeof(NODE));
- NODE *stackNode = (NODE*)calloc(1, sizeof(NODE));
- uint8_t tok;
- element_t tempElement;
- while (token != EOF && (tok = (uint8_t)token) != tEnter && tok != tColon) {
- uint8_t index;
- // Parse number
- if (tok >= t0 && tok <= t9) {
- uint24_t output = token - t0;
- while ((uint8_t)(token = _getc()) >= t0 && (uint8_t)token <= t9) {
- output = output * 10 + token - t0;
- }
- tempElement.type = TYPE_NUMBER;
- tempElement.operand.num = output;
- outputNode = push(outputNode, tempElement);
- // Don't grab a new token
- continue;
- }
- // Parse operator
- else if ((index = getIndexOfOperator(tok))) {
- while (stackNode->prev) {
- if (stackNode->prev.data.type == TYPE_OPERATOR) {
- if (insertNode(outputNode, stackNode->prev, 2) == NULL) {
- return E_SYNTAX;
- }
- } else {
- break;
- }
- }
- }
- token = _getc();
- }
- free(tempElement);
- }
- void main(void) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement