aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dtc/dtc-lexer.l
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dtc/dtc-lexer.l')
-rw-r--r--scripts/dtc/dtc-lexer.l65
1 files changed, 62 insertions, 3 deletions
diff --git a/scripts/dtc/dtc-lexer.l b/scripts/dtc/dtc-lexer.l
index e866ea5166ac..254d5af88956 100644
--- a/scripts/dtc/dtc-lexer.l
+++ b/scripts/dtc/dtc-lexer.l
@@ -29,6 +29,7 @@ PROPNODECHAR [a-zA-Z0-9,._+*#?@-]
29PATHCHAR ({PROPNODECHAR}|[/]) 29PATHCHAR ({PROPNODECHAR}|[/])
30LABEL [a-zA-Z_][a-zA-Z0-9_]* 30LABEL [a-zA-Z_][a-zA-Z0-9_]*
31STRING \"([^\\"]|\\.)*\" 31STRING \"([^\\"]|\\.)*\"
32CHAR_LITERAL '([^']|\\')*'
32WS [[:space:]] 33WS [[:space:]]
33COMMENT "/*"([^*]|\*+[^*/])*\*+"/" 34COMMENT "/*"([^*]|\*+[^*/])*\*+"/"
34LINECOMMENT "//".*\n 35LINECOMMENT "//".*\n
@@ -70,6 +71,27 @@ static int pop_input_file(void);
70 push_input_file(name); 71 push_input_file(name);
71 } 72 }
72 73
74<*>^"#"(line)?{WS}+[0-9]+{WS}+{STRING}({WS}+[0-9]+)? {
75 char *line, *tmp, *fn;
76 /* skip text before line # */
77 line = yytext;
78 while (!isdigit(*line))
79 line++;
80 /* skip digits in line # */
81 tmp = line;
82 while (!isspace(*tmp))
83 tmp++;
84 /* "NULL"-terminate line # */
85 *tmp = '\0';
86 /* start of filename */
87 fn = strchr(tmp + 1, '"') + 1;
88 /* strip trailing " from filename */
89 tmp = strchr(fn, '"');
90 *tmp = 0;
91 /* -1 since #line is the number of the next line */
92 srcpos_set_line(xstrdup(fn), atoi(line) - 1);
93 }
94
73<*><<EOF>> { 95<*><<EOF>> {
74 if (!pop_input_file()) { 96 if (!pop_input_file()) {
75 yyterminate(); 97 yyterminate();
@@ -96,6 +118,26 @@ static int pop_input_file(void);
96 return DT_MEMRESERVE; 118 return DT_MEMRESERVE;
97 } 119 }
98 120
121<*>"/bits/" {
122 DPRINT("Keyword: /bits/\n");
123 BEGIN_DEFAULT();
124 return DT_BITS;
125 }
126
127<*>"/delete-property/" {
128 DPRINT("Keyword: /delete-property/\n");
129 DPRINT("<PROPNODENAME>\n");
130 BEGIN(PROPNODENAME);
131 return DT_DEL_PROP;
132 }
133
134<*>"/delete-node/" {
135 DPRINT("Keyword: /delete-node/\n");
136 DPRINT("<PROPNODENAME>\n");
137 BEGIN(PROPNODENAME);
138 return DT_DEL_NODE;
139 }
140
99<*>{LABEL}: { 141<*>{LABEL}: {
100 DPRINT("Label: %s\n", yytext); 142 DPRINT("Label: %s\n", yytext);
101 yylval.labelref = xstrdup(yytext); 143 yylval.labelref = xstrdup(yytext);
@@ -103,12 +145,19 @@ static int pop_input_file(void);
103 return DT_LABEL; 145 return DT_LABEL;
104 } 146 }
105 147
106<V1>[0-9]+|0[xX][0-9a-fA-F]+ { 148<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
107 yylval.literal = xstrdup(yytext); 149 yylval.literal = xstrdup(yytext);
108 DPRINT("Literal: '%s'\n", yylval.literal); 150 DPRINT("Literal: '%s'\n", yylval.literal);
109 return DT_LITERAL; 151 return DT_LITERAL;
110 } 152 }
111 153
154<*>{CHAR_LITERAL} {
155 yytext[yyleng-1] = '\0';
156 yylval.literal = xstrdup(yytext+1);
157 DPRINT("Character literal: %s\n", yylval.literal);
158 return DT_CHAR_LITERAL;
159 }
160
112<*>\&{LABEL} { /* label reference */ 161<*>\&{LABEL} { /* label reference */
113 DPRINT("Ref: %s\n", yytext+1); 162 DPRINT("Ref: %s\n", yytext+1);
114 yylval.labelref = xstrdup(yytext+1); 163 yylval.labelref = xstrdup(yytext+1);
@@ -134,9 +183,10 @@ static int pop_input_file(void);
134 return ']'; 183 return ']';
135 } 184 }
136 185
137<PROPNODENAME>{PROPNODECHAR}+ { 186<PROPNODENAME>\\?{PROPNODECHAR}+ {
138 DPRINT("PropNodeName: %s\n", yytext); 187 DPRINT("PropNodeName: %s\n", yytext);
139 yylval.propnodename = xstrdup(yytext); 188 yylval.propnodename = xstrdup((yytext[0] == '\\') ?
189 yytext + 1 : yytext);
140 BEGIN_DEFAULT(); 190 BEGIN_DEFAULT();
141 return DT_PROPNODENAME; 191 return DT_PROPNODENAME;
142 } 192 }
@@ -150,6 +200,15 @@ static int pop_input_file(void);
150<*>{COMMENT}+ /* eat C-style comments */ 200<*>{COMMENT}+ /* eat C-style comments */
151<*>{LINECOMMENT}+ /* eat C++-style comments */ 201<*>{LINECOMMENT}+ /* eat C++-style comments */
152 202
203<*>"<<" { return DT_LSHIFT; };
204<*>">>" { return DT_RSHIFT; };
205<*>"<=" { return DT_LE; };
206<*>">=" { return DT_GE; };
207<*>"==" { return DT_EQ; };
208<*>"!=" { return DT_NE; };
209<*>"&&" { return DT_AND; };
210<*>"||" { return DT_OR; };
211
153<*>. { 212<*>. {
154 DPRINT("Char: %c (\\x%02x)\n", yytext[0], 213 DPRINT("Char: %c (\\x%02x)\n", yytext[0],
155 (unsigned)yytext[0]); 214 (unsigned)yytext[0]);