1 /* 2 * Scanner for a simple interface description language. 3 * 4 * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 %{ 23 #include <string.h> 24 #include "types.h" 25 #include "y.tab.h" 26 %} 27 28 BEGINCOMMENT "/*" 29 ENDCOMMENT "*/" 30 WS [ \t\n]+ 31 32 %x comment 33 34 %% 35 36 {BEGINCOMMENT} BEGIN(comment); 37 38 <comment>{ENDCOMMENT} BEGIN(INITIAL); 39 <comment>[^*]+ /* discard */ 40 <comment>"*"[^/] /* discard */ 41 42 {WS} /* discard */ 43 44 ^"#include" return INCLUDE; 45 "<"[^>]*">" yylval.str = strdup(yytext); return PHEADER; 46 \"[^"]*\" yylval.str = strdup(yytext); return QHEADER; 47 48 "import" return IMPORT; 49 "interface" return INTERFACE; 50 51 "in" yylval.num = IN_PARAMETER; return IN; 52 "inout" yylval.num = INOUT_PARAMETER; return INOUT; 53 "out" yylval.num = OUT_PARAMETER; return OUT; 54 55 "cap" yylval.num = CAP_ITEM; return CAP; 56 "fpage" yylval.num = FPAGE_ITEM; return FPAGE; 57 58 "(" return LPAR; 59 ")" return RPAR; 60 61 "[" return LBRACE; 62 "]" return RBRACE; 63 64 "," return SEP; 65 ";" return TERM; 66 67 "{" return BEGINSECTION; 68 "}" return ENDSECTION; 69 70 "composes" return COMPOSES; 71 72 [_[:alpha:]][_[:alnum:]]* yylval.str = strdup(yytext); return IDENTIFIER; 73 [[:digit:]]+ yylval.str = strdup(yytext); return DECIMAL; 74 "0"[xX][[:xdigit:]]+ yylval.str = strdup(yytext); return HEXADECIMAL; 75 76 %%