fixed location issues for error messages and scoping. Used location macros and the percent location as defined in guides to track location. Code may warrant cleanup as we don't need to manually keep track of locations ourselves any more through our line and column number variables
This commit is contained in:
28
src/runner.c
28
src/runner.c
@ -57,6 +57,22 @@ int check_flag(char *arg, char *alpha) {
|
||||
}
|
||||
}
|
||||
|
||||
void incr(int lnum,int cnum, int tok){
|
||||
//if (tok == COMMENT) {
|
||||
for (int i = 0; i < yyleng; i++) {
|
||||
if (yytext[i] == '\n') {
|
||||
line_number++;
|
||||
column_number = 0;
|
||||
}
|
||||
column_number++;
|
||||
}
|
||||
// }else{
|
||||
// column_number += yyleng;
|
||||
// }
|
||||
}
|
||||
void print_tok(int tok){
|
||||
fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number,tok, yytext);
|
||||
}
|
||||
int run(FILE *alpha) {
|
||||
int token;
|
||||
cur = CreateScope(NULL, 1, 1);
|
||||
@ -71,11 +87,11 @@ int run(FILE *alpha) {
|
||||
// TOK FLAG
|
||||
if (tok_flag != NULL) {
|
||||
while (0 != (token = yylex())) {
|
||||
if (tok_flag != NULL) {
|
||||
fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number,
|
||||
token, yytext);
|
||||
}
|
||||
if (token == COMMENT) {
|
||||
//if (tok_flag != NULL) {
|
||||
// fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number,
|
||||
// token, yytext);
|
||||
//}
|
||||
/*if (token == COMMENT) {
|
||||
for (int i = 0; i < yyleng; i++) {
|
||||
if (yytext[i] == '\n') {
|
||||
line_number++;
|
||||
@ -91,7 +107,7 @@ int run(FILE *alpha) {
|
||||
"character:%s\n",
|
||||
line_number, column_number, yytext);
|
||||
}
|
||||
column_number += yyleng;
|
||||
column_number += yyleng; */
|
||||
}
|
||||
fclose(tok_flag);
|
||||
|
||||
|
Reference in New Issue
Block a user