diff --git a/dtc-lexer.l b/dtc-lexer.l index 438d7d2..c082228 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -18,7 +18,7 @@ * USA */ -%option noyywrap nounput +%option noyywrap nounput yylineno %x CELLDATA %x BYTESTRING @@ -43,24 +43,30 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@]) #define DPRINT(fmt, ...) do { } while (0) #endif + + %} %% \"[^"]*\" { + yylloc.first_line = yylineno; DPRINT("String: %s\n", yytext); yylval.data = data_copy_escape_string(yytext+1, yyleng-2); + yylloc.first_line = yylineno; return DT_STRING; } "/memreserve/" { + yylloc.first_line = yylineno; DPRINT("Keyword: /memreserve/\n"); BEGIN(MEMRESERVE); return DT_MEMRESERVE; } [0-9a-fA-F]+ { + yylloc.first_line = yylineno; if (yyleng > 2*sizeof(yylval.addr)) { fprintf(stderr, "Address value %s too large\n", yytext); @@ -72,12 +78,14 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@]) } ";" { + yylloc.first_line = yylineno; DPRINT("/MEMRESERVE\n"); BEGIN(INITIAL); return ';'; } [0-9a-fA-F]+ { + yylloc.first_line = yylineno; if (yyleng > 2*sizeof(yylval.cval)) { fprintf(stderr, "Cell value %s too long\n", yytext); @@ -88,36 +96,42 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@]) } ">" { + yylloc.first_line = yylineno; DPRINT("/CELLDATA\n"); BEGIN(INITIAL); return '>'; } \&{REFCHAR}* { + yylloc.first_line = yylineno; DPRINT("Ref: %s\n", yytext+1); yylval.str = strdup(yytext+1); return DT_REF; } [0-9a-fA-F]{2} { + yylloc.first_line = yylineno; yylval.byte = strtol(yytext, NULL, 16); DPRINT("Byte: %02x\n", (int)yylval.byte); return DT_BYTE; } "]" { + yylloc.first_line = yylineno; DPRINT("/BYTESTRING\n"); BEGIN(INITIAL); return ']'; } {PROPCHAR}+ { + yylloc.first_line = yylineno; DPRINT("PropName: %s\n", yytext); yylval.str = strdup(yytext); return DT_PROPNAME; } {PROPCHAR}+(@{UNITCHAR}+)? { + yylloc.first_line = yylineno; DPRINT("NodeName: %s\n", yytext); yylval.str = strdup(yytext); return DT_NODENAME; @@ -125,6 +139,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@]) [a-zA-Z_][a-zA-Z0-9_]*: { + yylloc.first_line = yylineno; DPRINT("Label: %s\n", yytext); yylval.str = strdup(yytext); yylval.str[yyleng-1] = '\0'; @@ -134,6 +149,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@]) <*>{WS}+ /* eat whitespace */ <*>"/*"([^*]|\*+[^*/])*\*+"/" { + yylloc.first_line = yylineno; DPRINT("Comment: %s\n", yytext); /* eat comments */ } @@ -141,6 +157,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@]) <*>"//".*\n /* eat line comments */ <*>. { + yylloc.first_line = yylineno; switch (yytext[0]) { case '<': DPRINT("CELLDATA\n"); diff --git a/dtc-parser.y b/dtc-parser.y index 66e243d..1bfbfa3 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -18,6 +18,9 @@ * USA */ +%glr-parser +%locations + %{ #include "dtc.h" @@ -69,8 +72,6 @@ extern struct boot_info *the_boot_info; %type label %type nodename -%glr-parser - %% sourcefile: memreserves devicetree { @@ -160,5 +161,5 @@ label: DT_LABEL { $$ = $1; } void yyerror (char const *s) { - fprintf (stderr, "%s\n", s); + fprintf (stderr, "%s at line %d\n", s, yylloc.first_line); }