1 %{ 2 /* 3 * lexer.l 4 */ 5 6 /*- 7 * SPDX-License-Identifier: BSD-2-Clause 8 * 9 * Copyright (c) 2006 Maksim Yevmenkin <m_evmenkin@yahoo.com> 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * $Id: lexer.l,v 1.3 2006/09/07 21:06:53 max Exp $ 34 */ 35 #define L2CAP_SOCKET_CHECKED 36 #include <bluetooth.h> 37 #include <stdlib.h> 38 #include "parser.h" 39 40 int yylex (void); 41 42 #define YY_DECL int yylex(void) 43 %} 44 45 %option yylineno noyywrap nounput noinput 46 47 delim [ \t\n] 48 ws {delim}+ 49 empty {delim}* 50 comment \#.* 51 52 hexdigit [0-9a-fA-F] 53 hexbyte {hexdigit}{hexdigit}? 54 hexword {hexdigit}{hexdigit}?{hexdigit}?{hexdigit}? 55 56 device_word device 57 bdaddr_word bdaddr 58 name_word name 59 vendor_id_word vendor_id 60 product_id_word product_id 61 version_word version 62 control_psm_word control_psm 63 interrupt_psm_word interrupt_psm 64 reconnect_initiate_word reconnect_initiate 65 battery_power_word battery_power 66 normally_connectable_word normally_connectable 67 hid_descriptor_word hid_descriptor 68 true_word true 69 false_word false 70 71 bdaddrstring {hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte} 72 hexbytestring 0x{hexbyte} 73 hexwordstring 0x{hexword} 74 string \".+\" 75 76 %% 77 78 \; return (';'); 79 \: return (':'); 80 \{ return ('{'); 81 \} return ('}'); 82 83 {ws} ; 84 {empty} ; 85 {comment} ; 86 87 {device_word} return (T_DEVICE); 88 {bdaddr_word} return (T_BDADDR); 89 {name_word} return (T_NAME); 90 {vendor_id_word} return (T_VENDOR_ID); 91 {product_id_word} return (T_PRODUCT_ID); 92 {version_word} return (T_VERSION); 93 {control_psm_word} return (T_CONTROL_PSM); 94 {interrupt_psm_word} return (T_INTERRUPT_PSM); 95 {reconnect_initiate_word} return (T_RECONNECT_INITIATE); 96 {battery_power_word} return (T_BATTERY_POWER); 97 {normally_connectable_word} return (T_NORMALLY_CONNECTABLE); 98 {hid_descriptor_word} return (T_HID_DESCRIPTOR); 99 {true_word} return (T_TRUE); 100 {false_word} return (T_FALSE); 101 102 {bdaddrstring} { 103 return (bt_aton(yytext, &yylval.bdaddr)? 104 T_BDADDRSTRING : T_ERROR); 105 } 106 107 {hexbytestring} { 108 char *ep; 109 110 yylval.num = strtoul(yytext, &ep, 16); 111 112 return (*ep == '\0'? T_HEXBYTE : T_ERROR); 113 } 114 115 {hexwordstring} { 116 char *ep; 117 118 yylval.num = strtoul(yytext, &ep, 16); 119 120 return (*ep == '\0'? T_HEXWORD : T_ERROR); 121 } 122 123 {string} { 124 yytext[strlen(yytext) - 1] = 0; 125 yylval.string = &yytext[1]; 126 return (T_STRING); 127 } 128 129 . return (T_ERROR); 130 131 %% 132 133