diff options
author | David Gibson <dgibson@sneetch.(none)> | 2005-10-19 16:00:31 +1000 |
---|---|---|
committer | David Gibson <dgibson@sneetch.(none)> | 2005-10-19 16:00:31 +1000 |
commit | 86dbcbd1e421700feeae2fc83db9e464f7964262 (patch) | |
tree | f9cfdffed86b3a3eb297964a5cd423aa76085431 /dtc-lexer.l | |
parent | b4ac04952a2d8489cb28c5d0a3872d4a35dc58d2 (diff) | |
download | dtc-86dbcbd1e421700feeae2fc83db9e464f7964262.tar.gz |
Rudimentary support for reporting the line number of syntax errors.
Diffstat (limited to 'dtc-lexer.l')
-rw-r--r-- | dtc-lexer.l | 19 |
1 files changed, 18 insertions, 1 deletions
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; } <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}|[/@]) } <MEMRESERVE>";" { + yylloc.first_line = yylineno; DPRINT("/MEMRESERVE\n"); BEGIN(INITIAL); return ';'; } <CELLDATA>[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}|[/@]) } <CELLDATA>">" { + yylloc.first_line = yylineno; DPRINT("/CELLDATA\n"); BEGIN(INITIAL); return '>'; } <CELLDATA>\&{REFCHAR}* { + yylloc.first_line = yylineno; DPRINT("Ref: %s\n", yytext+1); yylval.str = strdup(yytext+1); return DT_REF; } <BYTESTRING>[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; } <BYTESTRING>"]" { + 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"); |