37 lines
944 B
C
37 lines
944 B
C
/*
|
|
Main program of calculator example.
|
|
Simply invoke the parser generated by bison, and then display the output.
|
|
*/
|
|
|
|
#include "expr.h"
|
|
#include <stdio.h>
|
|
|
|
/* Clunky: Declare the parse function generated from parser.bison */
|
|
extern int yyparse(struct stmt *parser_result);
|
|
|
|
/* Clunky: Declare the result of the parser from parser.bison */
|
|
|
|
struct stmt *parser_result;
|
|
|
|
int main(int argc, char *argv[]) {
|
|
printf("Lab 6 Example Interpreter Compiler\n");
|
|
printf(
|
|
"Enter an infix expression using the operators +-*/() ending with ;\n\n");
|
|
|
|
if (yyparse(parser_result) == 0) {
|
|
printf("Parse successful: ");
|
|
if (parser_result != NULL) {
|
|
stmt_print(parser_result);
|
|
printf("\n");
|
|
printf("Running the program, results in: ");
|
|
stmt_evaluate(parser_result);
|
|
printf("\n");
|
|
}
|
|
printf("parser_result is %p\n", parser_result);
|
|
return 0;
|
|
} else {
|
|
printf("Parse failed!\n");
|
|
return 1;
|
|
}
|
|
}
|