void factor(void) { if (match(INT)) { printf("INT: %s\n", getLexeme()); advance(); } else if (match(ADDSUB)) { printf("ADDSUB: %s\n", getLexeme()); advance(); if (match(INT)) { printf("INT: %s\n", getLexeme()); advance(); } else if (match(ID)) { printf("ID: %s\n", getLexeme()); advance(); } } else if (match(ID)) { printf("ID: %s\n", getLexeme()); advance(); if (match(ASSIGN)) { printf("ASSIGN: %s\n", getLexeme()); advance(); expr(); } } else if (match(LPAREN)) { printf("LPAREN: %s\n", getLexeme()); advance(); expr(); if (match(RPAREN)) { printf("RPAREN: %s\n", getLexeme()); advance(); } else { printf("Parenthesis mismatched\n"); } } }
void term(void) { factor(); while (match(MULDIV)) { printf("MULDIV: %s\n", getLexeme()); advance(); factor(); } }
void expr(void) { term(); while (match(ADDSUB)){ printf("ADDSUB: %s\n", getLexeme()); advance(); term(); } }
lexicalAnalyzer:: lexicalAnalyzer( char * file ) { ifstream fin; fin.open( file ); while( getline( fin, line ) ) { lines.push_back(line + '\n'); } getLexeme(); }