-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
72 lines (58 loc) · 1.58 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* main.c - Entry point for the Recusrive Decent Parser Project
* @author Gajjan Jasani
* @version 04/08/2016
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LINE 100
#define TSIZE 20
/* Global declarations */
char expression[LINE]; /* expression entered by user */
/**
* Function prototypes
*/
void clean_input_line(char* );
extern char* get_token();
extern int bxper(char *);
/**
* Function: main
* Purpose : The entry point to this program. This function calls tokenizer
* and parser to parse and interpret the user entered expression and prints
* the result on console
* Return: 0
*/
int main() {
char* token; /* Spot to hold a token for test */
int result;
printf("Please enter expression: ");
// Reading the user input for analyzation
if (fgets(expression, LINE, stdin) != NULL){
clean_input_line(expression); // Clearing out white spaces from input line
if(expression[0] != 'q' && expression[strlen(expression)-1] != ';'){
printf("Syntax Error: Missing \";\" at the end\n");
exit(0);
}
token = get_token();
result = bxper(token);
printf("Syntax OK\n");
printf("Value is: %d\n", result);
}
return 0;
}
/**
* Function: clean_input_line
* Purpose : Remove all the white spaces from the input line
*/
void clean_input_line(char* line){
int i=0, j=0;
int len = (int)strlen(line);
while (i != len) {
if (line[i] != ' ' && line[i] != '\t' && line[i] != '\n'){
line[j++] = line[i];
}
i++;
}
line[j]=0; // making sure there is a null character at the end of line
}