|
Packit |
400c17 |
/*
|
|
Packit |
400c17 |
Copyright(C) 2016, Red Hat, Inc., Jerome Marchand
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
This program is free software: you can redistribute it and/or modify
|
|
Packit |
400c17 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
400c17 |
the Free Software Foundation, either version 3 of the License, or
|
|
Packit |
400c17 |
(at your option) any later version.
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
400c17 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
400c17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
400c17 |
GNU General Public License for more details.
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
You should have received a copy of the GNU General Public License
|
|
Packit |
400c17 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
400c17 |
*/
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
NUM [0-9]
|
|
Packit |
400c17 |
ALPHA [a-zA-Z]
|
|
Packit |
400c17 |
IDENT_FIRST [a-zA-Z_]
|
|
Packit |
400c17 |
IDENT [a-zA-Z0-9_]
|
|
Packit |
400c17 |
FILECHAR [a-zA-Z0-9_/<>\-\.]
|
|
Packit |
400c17 |
HEX [a-fA-F0-9]
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
%{
|
|
Packit |
400c17 |
#include "parser.h"
|
|
Packit |
400c17 |
#include "parser.tab.h"
|
|
Packit |
400c17 |
%}
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
%option nounput
|
|
Packit |
400c17 |
%option noyywrap
|
|
Packit |
400c17 |
%s SYMBOL
|
|
Packit |
400c17 |
%x IN_STRING UNKNOWN_FIELD
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
%%
|
|
Packit |
400c17 |
static int last_sc = INITIAL;
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
<SYMBOL>{ /* Keywords used by symbol declaration */
|
|
Packit |
400c17 |
"const" { return(CONST); }
|
|
Packit |
400c17 |
"enum" { return(ENUM); }
|
|
Packit |
400c17 |
"struct" { return(STRUCT); }
|
|
Packit |
400c17 |
"typedef" { return(TYPEDEF); }
|
|
Packit |
400c17 |
"union" { return(UNION); }
|
|
Packit |
400c17 |
"volatile" { return(VOLATILE); }
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
"..." { return(ELLIPSIS); }
|
|
Packit |
400c17 |
}
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
<INITIAL,UNKNOWN_FIELD>{ /* keywords used only in the header */
|
|
Packit |
400c17 |
"Version:" { BEGIN(INITIAL); return(VERSION_KW); }
|
|
Packit |
400c17 |
"CU:" { BEGIN(INITIAL); return(CU_KW); }
|
|
Packit |
400c17 |
"File:" { BEGIN(INITIAL); return(FILE_KW); }
|
|
Packit |
400c17 |
"Stack:" { BEGIN(INITIAL); return(STACK_KW); }
|
|
Packit |
400c17 |
"Symbol:\n" { BEGIN(SYMBOL); return(SYMBOL_KW_NL); }
|
|
Packit |
400c17 |
{IDENT}+":" { BEGIN(UNKNOWN_FIELD); }
|
|
Packit |
400c17 |
}
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
<UNKNOWN_FIELD>{ /* Ignore unknown fields. */
|
|
Packit |
400c17 |
[^\n:]*"\n" { ; }
|
|
Packit |
400c17 |
/* A line that doesn't start with {IDENT}+":", i.e. not a valid field */
|
|
Packit |
400c17 |
{IDENT}*[^a-zA-Z0-9_\n:]+{IDENT}*[^\n]*"\n" { ; }
|
|
Packit |
400c17 |
}
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
"->" { return(ARROW); }
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
{FILECHAR}+"."[chS]|"<built-in>" { yylval.str = strdup(yytext);
|
|
Packit |
400c17 |
debug("Source file: %s\n", yylval.str);
|
|
Packit |
400c17 |
return(SRCFILE);
|
|
Packit |
400c17 |
}
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
{IDENT_FIRST}{IDENT}* { yylval.str = strdup(yytext);
|
|
Packit |
400c17 |
debug("Identifier: %s\n", yylval.str);
|
|
Packit |
400c17 |
return(IDENTIFIER);
|
|
Packit |
400c17 |
}
|
|
Packit |
400c17 |
"(NULL)" { yylval.str = NULL;
|
|
Packit |
400c17 |
debug("Identifier: (NULL)\n");
|
|
Packit |
400c17 |
return(IDENTIFIER);
|
|
Packit |
400c17 |
}
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
0[xX]{HEX}+ { yylval.ul = strtoul(yytext, NULL, 16);
|
|
Packit |
400c17 |
debug("Constant: 0x%lx\n", yylval.ul);
|
|
Packit |
400c17 |
return(CONSTANT);
|
|
Packit |
400c17 |
}
|
|
Packit |
400c17 |
{NUM}+ { yylval.ul = strtoul(yytext, NULL, 10);
|
|
Packit |
400c17 |
debug("Constant: %li\n", yylval.ul);
|
|
Packit |
400c17 |
return(CONSTANT);
|
|
Packit |
400c17 |
}
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
[{}()\[\];:,.*@=-] { return(yytext[0]); }
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
"\n" { return(NEWLINE); }
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
[ \t\v\f] { ; }
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
"\"" { last_sc = YY_START; BEGIN(IN_STRING); }
|
|
Packit |
400c17 |
<IN_STRING>[^"]* { yylval.str = strdup(yytext);
|
|
Packit |
400c17 |
debug("String: %s\n", yylval.str);
|
|
Packit |
400c17 |
return(STRING);
|
|
Packit |
400c17 |
}
|
|
Packit |
400c17 |
<IN_STRING>"\"" { BEGIN(last_sc); }
|
|
Packit |
400c17 |
. { printf("Unexpected entry \"%c\"\n", *yytext); }
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
/* Get back to initial condition or we'll start the next file in SYMBOL */
|
|
Packit |
400c17 |
<<EOF>> { BEGIN(INITIAL); yyterminate(); }
|
|
Packit |
400c17 |
|
|
Packit |
400c17 |
%%
|