Commit 4755a935 authored by Sergio Costas's avatar Sergio Costas

Now shows better when there is a syntax error in the C code

parent f07a295e
......@@ -76,6 +76,7 @@ class crusty(object):
super().__init__()
self.errors = []
self.debug = []
with open(headerpath,"r") as header:
do_process = False
......@@ -448,6 +449,7 @@ class crusty(object):
continue
if node.type == "CRUSTY_DEBUG":
print("Debug: '{:s}'".format(str(var_container)))
self.debug.append(self._copy_container(var_container))
continue
return var_container,function_container
......
......@@ -69,6 +69,8 @@ struct AST {
struct AST *for_ch3;
};
extern char *previous_data_line;
extern char *current_data_line;
extern int current_line;
extern char* current_file;
extern struct AST *types_list;
......
......@@ -20,6 +20,9 @@ void comment(void);
void error(char *);
void count();
void set_current_line();
char *previous_data_line = NULL;
char *current_data_line = NULL;
int current_data_length = 0;
%}
......@@ -27,7 +30,7 @@ void set_current_line();
%%
"/*" { comment(); }
"//"[^\n]* { current_line++; /* consume //-comment */ }
"#pragma"[^\n]* { }
"#pragma"[^\n]* { count(); }
\#{WS2}+[0-9]+{WS2}+\".+\"({WS2}+[0-9]+)* { set_current_line(); }
"auto" { return prepare_leaf(0,0.0,AUTO); }
......@@ -68,13 +71,13 @@ void set_current_line();
"volatile" { return prepare_leaf(0,0.0,VOLATILE); }
"while" { return prepare_leaf(0,0.0,WHILE); }
"NULL" { return prepare_leaf(0,0.0,T_NULL); }
"__extension__" { }
"__prog__" { }
"__restrict" { }
"__inline" { }
"__attribute__"{WS}*"((".*"))" { }
"__asm__"{WS}*"(".*")" { }
"__asm__"{WS}*"volatile"{WS}*"(".*")" { }
"__extension__" { count(); }
"__prog__" { count(); }
"__restrict" { count(); }
"__inline" { count(); }
"__attribute__"{WS}*"((".*"))" { count(); }
"__asm__"{WS}*"(".*")" { count(); }
"__asm__"{WS}*"volatile"{WS}*"(".*")" { count(); }
"__crust_t__" { return prepare_leaf(0,0.0,CRUSTY_T); }
"__crust_borrow__" { return prepare_leaf(0,0.0,CRUSTY_BORROW); }
"__crust_recycle__" { return prepare_leaf(0,0.0,CRUSTY_RECYCLE); }
......@@ -179,7 +182,7 @@ L?\"(\\.|[^\\"\n])*\" { return prepare_leaf(0,0.0,STRING_LITERAL); }
"|" { return prepare_leaf(0,0.0,'|'); }
"?" { return prepare_leaf(0,0.0,'?'); }
[ \t\v\n\f] { count();}
[ \t\v\n\f] { count(); }
. { /* Add code to complain about unmatched characters */ }
%%
......@@ -231,10 +234,24 @@ void count() {
int i;
int j = current_data_length + strlen(yytext);
if (current_data_line == NULL) {
current_data_line = malloc(j + 1);
current_data_line[0] = 0;
} else {
current_data_line = realloc(current_data_line, j + 1);
}
current_data_length = j;
strcat(current_data_line,yytext);
for (i = 0; yytext[i] != '\0'; i++)
if (yytext[i] == '\n') {
column = 0;
current_line++;
free(previous_data_line);
previous_data_line = current_data_line;
current_data_line = NULL;
current_data_length = 0;
} else if (yytext[i] == '\t')
column += 8 - (column % 8);
else
......
......@@ -704,5 +704,11 @@ extern int column;
void yyerror(char const *s)
{
fflush(stdout);
printf("\n%*s\n%*s\n", column, "^", column, s);
printf("\n\n");
if (previous_data_line != NULL) {
printf(previous_data_line);
}
printf(current_data_line);
printf("\n%*s\n%*s\n", column, "^\n", column, s);
printf("Line: %d\n\n",current_line);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment