summaryrefslogtreecommitdiff
path: root/dtc-lexer.l
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2007-11-07 11:16:19 +1100
committerJon Loeliger <jdl@freescale.com>2007-11-08 11:14:07 -0600
commit9ed27a2aac6f7bbbb16d48854763a6d79f6a9857 (patch)
tree74fd56f0186dbc6dce42194b9e907b9ae3f78909 /dtc-lexer.l
parent53acf491e9d576519f97b62984762498f9453cb4 (diff)
downloaddevice-tree-compiler-9ed27a2aac6f7bbbb16d48854763a6d79f6a9857.tar.gz
dtc: Simplify lexing/parsing of literals vs. node/property names
The current scheme of having CELLDATA and MEMRESERVE states to recognize hex literals instead of node or property names is arse-backwards. The patch switches things around so that literals are lexed in normal states, and property/node names are only recognized in the special PROPNODENAME state, which is only entered after a { or a ;, and is left as soon as we scan a property/node name or a keyword. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Jon Loeliger <jdl@freescale.com>
Diffstat (limited to 'dtc-lexer.l')
-rw-r--r--dtc-lexer.l109
1 files changed, 29 insertions, 80 deletions
diff --git a/dtc-lexer.l b/dtc-lexer.l
index 278a96e..677abe4 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -21,9 +21,8 @@
%option noyywrap nounput yylineno
%x INCLUDE
-%x CELLDATA
%x BYTESTRING
-%x MEMRESERVE
+%x PROPNODENAME
PROPCHAR [a-zA-Z0-9,._+*#?-]
UNITCHAR [0-9a-f,]
@@ -51,7 +50,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
%%
-"/include/" BEGIN(INCLUDE);
+<*>"/include/" BEGIN(INCLUDE);
<INCLUDE>\"[^"\n]*\" {
yytext[strlen(yytext) - 1] = 0;
@@ -63,13 +62,13 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
}
-<<EOF>> {
+<*><<EOF>> {
if (!pop_input_file()) {
yyterminate();
}
}
-\"([^\\"]|\\.)*\" {
+<*>\"([^\\"]|\\.)*\" {
yylloc.filenum = srcpos_filenum;
yylloc.first_line = yylineno;
DPRINT("String: %s\n", yytext);
@@ -79,45 +78,24 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
return DT_STRING;
}
-"/memreserve/" {
+<*>"/memreserve/" {
yylloc.filenum = srcpos_filenum;
yylloc.first_line = yylineno;
DPRINT("Keyword: /memreserve/\n");
- BEGIN(MEMRESERVE);
- return DT_MEMRESERVE;
- }
-
-<MEMRESERVE>[0-9a-fA-F]+ {
- yylloc.filenum = srcpos_filenum;
- yylloc.first_line = yylineno;
- if (yyleng > 2*sizeof(yylval.addr)) {
- fprintf(stderr, "Address value %s too large\n",
- yytext);
- }
- yylval.addr = (u64) strtoull(yytext, NULL, 16);
- DPRINT("Addr: %llx\n",
- (unsigned long long)yylval.addr);
- return DT_ADDR;
- }
-
-<MEMRESERVE>";" {
- yylloc.filenum = srcpos_filenum;
- yylloc.first_line = yylineno;
- DPRINT("/MEMRESERVE\n");
BEGIN(INITIAL);
- return ';';
+ return DT_MEMRESERVE;
}
<*>[a-zA-Z_][a-zA-Z0-9_]*: {
yylloc.filenum = srcpos_filenum;
yylloc.first_line = yylineno;
DPRINT("Label: %s\n", yytext);
- yylval.str = strdup(yytext);
- yylval.str[yyleng-1] = '\0';
+ yylval.labelref = strdup(yytext);
+ yylval.labelref[yyleng-1] = '\0';
return DT_LABEL;
}
-<CELLDATA>[bodh]# {
+[bodh]# {
yylloc.filenum = srcpos_filenum;
yylloc.first_line = yylineno;
if (*yytext == 'b')
@@ -132,27 +110,19 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
return DT_BASE;
}
-<CELLDATA>[0-9a-fA-F]+ {
- yylloc.filenum = srcpos_filenum;
- yylloc.first_line = yylineno;
- yylval.str = strdup(yytext);
- DPRINT("Cell: '%s'\n", yylval.str);
- return DT_CELL;
- }
-
-<CELLDATA>">" {
+[0-9a-fA-F]+ {
yylloc.filenum = srcpos_filenum;
yylloc.first_line = yylineno;
- DPRINT("/CELLDATA\n");
- BEGIN(INITIAL);
- return '>';
+ yylval.literal = strdup(yytext);
+ DPRINT("Literal: '%s'\n", yylval.literal);
+ return DT_LITERAL;
}
-<CELLDATA>\&{REFCHAR}* {
+\&{REFCHAR}* {
yylloc.filenum = srcpos_filenum;
yylloc.first_line = yylineno;
DPRINT("Ref: %s\n", yytext+1);
- yylval.str = strdup(yytext+1);
+ yylval.labelref = strdup(yytext+1);
return DT_REF;
}
@@ -172,30 +142,13 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
return ']';
}
-, { /* Technically this is a valid property name,
- but we'd rather use it as punctuation, so detect it
- here in preference */
+<PROPNODENAME>{PROPCHAR}+(@{UNITCHAR}+)? {
yylloc.filenum = srcpos_filenum;
yylloc.first_line = yylineno;
- DPRINT("Char (propname like): %c (\\x%02x)\n", yytext[0],
- (unsigned)yytext[0]);
- return yytext[0];
- }
-
-{PROPCHAR}+ {
- yylloc.filenum = srcpos_filenum;
- yylloc.first_line = yylineno;
- DPRINT("PropName: %s\n", yytext);
- yylval.str = strdup(yytext);
- return DT_PROPNAME;
- }
-
-{PROPCHAR}+(@{UNITCHAR}+)? {
- yylloc.filenum = srcpos_filenum;
- yylloc.first_line = yylineno;
- DPRINT("NodeName: %s\n", yytext);
- yylval.str = strdup(yytext);
- return DT_NODENAME;
+ DPRINT("PropNodeName: %s\n", yytext);
+ yylval.propnodename = strdup(yytext);
+ BEGIN(INITIAL);
+ return DT_PROPNODENAME;
}
@@ -213,21 +166,17 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
<*>. {
yylloc.filenum = srcpos_filenum;
yylloc.first_line = yylineno;
- switch (yytext[0]) {
- case '<':
- DPRINT("CELLDATA\n");
- BEGIN(CELLDATA);
- break;
- case '[':
- DPRINT("BYTESTRING\n");
- BEGIN(BYTESTRING);
- break;
- default:
-
+ if (yytext[0] == '[') {
+ DPRINT("<BYTESTRING>\n");
+ BEGIN(BYTESTRING);
+ }
+ if ((yytext[0] == '{')
+ || (yytext[0] == ';')) {
+ DPRINT("<PROPNODENAME>\n");
+ BEGIN(PROPNODENAME);
+ }
DPRINT("Char: %c (\\x%02x)\n", yytext[0],
(unsigned)yytext[0]);
- break;
- }
return yytext[0];
}