Advertisement
PT_

Untitled

PT_
Jul 14th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. /* Keep these headers */
  2. #include <stdbool.h>
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #include <tice.h>
  6.  
  7. /* Standard headers (recommended) */
  8. #include <math.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #include <fileioc.h>
  14.  
  15. #define TYPE_NUMBER 0
  16.  
  17. typedef uint24_t num_t;
  18. typedef uint8_t vari_t;
  19. typedef uint8_t op_t;
  20.  
  21. typedef struct {
  22. uint8_t function;
  23. uint8_t function2;
  24. uint8_t amountOfArgs;
  25. } func_t;
  26.  
  27. typedef union {
  28. num_t num;
  29. vari_t var;
  30. op_t op;
  31. func_t func;
  32. } operand_t;
  33.  
  34. typedef struct {
  35. uint8_t isString;
  36. uint8_t type;
  37. uint8_t mask;
  38. operand_t operand;
  39. } element_t;
  40.  
  41. typedef struct node {
  42. element_t data;
  43. struct node *prev;
  44. struct node *child;
  45. struct node *sibling;
  46. } NODE;
  47.  
  48. NODE *push(NODE *top, element_t data) {
  49. NODE *tempNode = (NODE*)malloc(sizeof(NODE));
  50.  
  51. tempNode->data = data;
  52. tempNode->prev = top;
  53. top->sibling = tempNode;
  54.  
  55. return tempNode;
  56. }
  57.  
  58. NODE *insertNode(NODE *top, element_t data, uint8_t index) {
  59. NODE *tempNode = (NODE*)calloc(1, sizeof(NODE));
  60. uint8_t temp;
  61.  
  62. tempNode->data = data;
  63. for (temp = 1; temp < index; temp++) {
  64. top = top->prev;
  65.  
  66. if (top == NULL) {
  67. return NULL;
  68. }
  69. }
  70. if (top == NULL) {
  71. return NULL;
  72. }
  73. top->prev->sibling = tempNode;
  74. tempNode->child = top;
  75.  
  76. return tempNode;
  77. }
  78.  
  79. int _getc(void) {
  80. return 0;
  81. }
  82.  
  83. uint8_t getIndexOfOperator(uint8_t tok) {
  84. return 0;
  85. }
  86.  
  87. uint8_t parseExpression(int token) {
  88. NODE *outputNode = (NODE*)calloc(1, sizeof(NODE));
  89. NODE *stackNode = (NODE*)calloc(1, sizeof(NODE));
  90. uint8_t tok;
  91. element_t tempElement;
  92.  
  93. while (token != EOF && (tok = (uint8_t)token) != tEnter && tok != tColon) {
  94. uint8_t index;
  95.  
  96. // Parse number
  97. if (tok >= t0 && tok <= t9) {
  98. uint24_t output = token - t0;
  99.  
  100. while ((uint8_t)(token = _getc()) >= t0 && (uint8_t)token <= t9) {
  101. output = output * 10 + token - t0;
  102. }
  103. tempElement.type = TYPE_NUMBER;
  104. tempElement.operand.num = output;
  105. outputNode = push(outputNode, tempElement);
  106.  
  107. // Don't grab a new token
  108. continue;
  109. }
  110.  
  111. // Parse operator
  112. else if ((index = getIndexOfOperator(tok))) {
  113. while (stackNode->prev) {
  114. if (stackNode->prev.data.type == TYPE_OPERATOR) {
  115. if (insertNode(outputNode, stackNode->prev, 2) == NULL) {
  116. return E_SYNTAX;
  117. }
  118. } else {
  119. break;
  120. }
  121. }
  122. }
  123.  
  124. token = _getc();
  125. }
  126.  
  127. free(tempElement);
  128. }
  129.  
  130. void main(void) {
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement