2 * fmd_scanner.l, scanner generator for flashmap descriptor language
4 * Copyright (C) 2015 Google, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
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
13 * GNU General Public License for more details.
17 #include "fmd_parser.h"
22 int parse_integer(char *src, int base);
23 int copy_string(const char *src);
32 [[:space:]]+ /* Eat whitespace. */
33 #.*$ /* Eat comments. */
34 \( BEGIN(FLAGS); return *yytext;
35 <FLAGS>\) BEGIN(INITIAL); return *yytext;
36 <FLAGS>CBFS return FLAG_CBFS;
37 <FLAGS>PRESERVE return FLAG_PRESERVE;
39 [1-9][0-9]*{MULTIPLIER}? return parse_integer(yytext, 10);
40 0[0-9]+{MULTIPLIER}? return OCTAL;
41 0[xX][0-9a-fA-F]+{MULTIPLIER}? return parse_integer(yytext + 2, 16);
42 [^#@{}()[:space:]]* return copy_string(yytext);
47 int parse_integer(char *src, int base)
49 char *multiplier = NULL;
50 unsigned val = strtoul(src, &multiplier, base);
61 val *= 1024*1024*1024;
64 // If we ever get here, the MULTIPLIER regex is allowing
65 // multiplier suffixes not handled by this code.
74 int copy_string(const char *src)
76 yylval.strval = strdup(src);