struct memorycontainer* appendLetWithOperatorStatement(char * identifier, struct memorycontainer* expressionContainer, unsigned char operator) { unsigned char token=0; if (operator == 0) { token=ADD_TOKEN; } else if (operator == 1) { token=SUB_TOKEN; } else if (operator == 2) { token=MUL_TOKEN; } else if (operator == 3 || operator == 6) { token=DIV_TOKEN; } else if (operator == 4) { token=MOD_TOKEN; } else if (operator == 5) { token=POW_TOKEN; } else { fprintf(stderr, "Can not find operator with id of %c\n", operator); } struct memorycontainer* rhs=createExpression(token, createIdentifierExpression(identifier), expressionContainer); if (operator == 6) { // Floor struct memorycontainer* mathCommand=createIntegerExpression(FLOOR_MATHS_OP); struct stack_t * argStack=getNewStack(); pushExpression(argStack, mathCommand); pushExpression(argStack, rhs); rhs=appendNativeCallFunctionStatement(NATIVE_RTL_MATH_STR, argStack, NULL); } return appendLetStatement(identifier, rhs); }
struct memorycontainer* createFloorDivExpression(struct memorycontainer* expression1, struct memorycontainer* expression2) { struct memorycontainer* divExpr=createExpression(DIV_TOKEN, expression1, expression2); struct memorycontainer* mathCommand=createIntegerExpression(FLOOR_MATHS_OP); struct stack_t * argStack=getNewStack(); pushExpression(argStack, mathCommand); pushExpression(argStack, divExpr); divExpr=appendNativeCallFunctionStatement(NATIVE_RTL_MATH_STR, argStack, NULL); return divExpr; }
/** * Parse HTML page */ char* ParseHtml(char* html) { char* story = (char *) malloc(sizeof(char)); Stack* stack = getNewStack(); // Prime remainder of algorithm char* content = strsep(&html, "<"); if (content) { // Chew threw first tag contents char* properties = strsep(&html, ">"); properties[strlen(properties)] = 0; properties = trimWhiteSpace(properties); while(properties) { // False if the tag is not properly formatted if (!processTag(properties, stack)) { // Free story and return error message free(story); return "Story not parsed correctly. Sorry :(\n"; } // Find content content = strsep(&html, "<"); content[strlen(content)] = 0; content = trimWhiteSpace(content); // Allocate space for content story = realloc(story, strlen(story) + strlen(content) + 1); if (!story) { printf("ERROR : Error reallocating memory\n"); return NULL; } // Concatenate the two together and null terminate the string // content = trimWhiteSpace(content); strcat(story, content); story[strlen(story)] = '\0'; // Get properties of next tag properties = strsep(&html, ">"); } } return story; }