2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 %option noyywrap nounput noinput never-interactive
28 PROPNODECHAR [a-zA-Z0-9,._+*#?@-]
29 PATHCHAR ({PROPNODECHAR}|[/])
30 LABEL [a-zA-Z_][a-zA-Z0-9_]*
31 STRING \"([^\\"]|\\.)*\"
33 COMMENT "/*"([^*]|\*+[^*/])*\*+"/"
39 #include "dtc-parser.tab.h"
43 /* CAUTION: this will stop working if we ever use yyless() or yyunput() */
44 #define YY_USER_ACTION \
46 srcpos_update(&yylloc, yytext, yyleng); \
49 /*#define LEXDEBUG 1*/
52 #define DPRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
54 #define DPRINT(fmt, ...) do { } while (0)
57 static int dts_version = 1;
59 #define BEGIN_DEFAULT() DPRINT("<V1>\n"); \
62 static void push_input_file(const char *filename);
63 static int pop_input_file(void);
67 <*>"/include/"{WS}*{STRING} {
68 char *name = strchr(yytext, '\"') + 1;
69 yytext[yyleng-1] = '\0';
70 push_input_file(name);
74 if (!pop_input_file()) {
80 DPRINT("String: %s\n", yytext);
81 yylval.data = data_copy_escape_string(yytext+1,
87 DPRINT("Keyword: /dts-v1/\n");
94 DPRINT("Keyword: /memreserve/\n");
100 DPRINT("Label: %s\n", yytext);
101 yylval.labelref = xstrdup(yytext);
102 yylval.labelref[yyleng-1] = '\0';
106 <V1>[0-9]+|0[xX][0-9a-fA-F]+ {
107 yylval.literal = xstrdup(yytext);
108 DPRINT("Literal: '%s'\n", yylval.literal);
112 <*>\&{LABEL} { /* label reference */
113 DPRINT("Ref: %s\n", yytext+1);
114 yylval.labelref = xstrdup(yytext+1);
118 <*>"&{/"{PATHCHAR}+\} { /* new-style path reference */
119 yytext[yyleng-1] = '\0';
120 DPRINT("Ref: %s\n", yytext+2);
121 yylval.labelref = xstrdup(yytext+2);
125 <BYTESTRING>[0-9a-fA-F]{2} {
126 yylval.byte = strtol(yytext, NULL, 16);
127 DPRINT("Byte: %02x\n", (int)yylval.byte);
132 DPRINT("/BYTESTRING\n");
137 <PROPNODENAME>{PROPNODECHAR}+ {
138 DPRINT("PropNodeName: %s\n", yytext);
139 yylval.propnodename = xstrdup(yytext);
141 return DT_PROPNODENAME;
145 DPRINT("Binary Include\n");
149 <*>{WS}+ /* eat whitespace */
150 <*>{COMMENT}+ /* eat C-style comments */
151 <*>{LINECOMMENT}+ /* eat C++-style comments */
154 DPRINT("Char: %c (\\x%02x)\n", yytext[0],
155 (unsigned)yytext[0]);
156 if (yytext[0] == '[') {
157 DPRINT("<BYTESTRING>\n");
160 if ((yytext[0] == '{')
161 || (yytext[0] == ';')) {
162 DPRINT("<PROPNODENAME>\n");
170 static void push_input_file(const char *filename)
174 srcfile_push(filename);
176 yyin = current_srcfile->f;
178 yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
182 static int pop_input_file(void)
184 if (srcfile_pop() == 0)
187 yypop_buffer_state();
188 yyin = current_srcfile->f;