lexer.l revision 137868
1%{ 2/* 3 * lexer.l 4 * 5 * Copyright (c) 2004 Maksim Yevmenkin <m_evmenkin@yahoo.com> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $Id: lexer.l,v 1.2 2004/02/13 21:46:20 max Exp $ 30 * $FreeBSD: head/usr.sbin/bluetooth/bthidd/lexer.l 128080 2004-04-10 00:18:00Z emax $ 31 */ 32 33#include <bluetooth.h> 34#include <stdlib.h> 35#include "parser.h" 36%} 37 38%option yylineno noyywrap nounput 39 40delim [ \t\n] 41ws {delim}+ 42empty {delim}* 43comment \#.* 44 45hexdigit [0-9a-fA-F] 46hexbyte {hexdigit}{hexdigit}? 47 48device_word device 49bdaddr_word bdaddr 50control_psm_word control_psm 51interrupt_psm_word interrupt_psm 52reconnect_initiate_word reconnect_initiate 53battery_power_word battery_power 54normally_connectable_word normally_connectable 55hid_descriptor_word hid_descriptor 56true_word true 57false_word false 58 59bdaddrstring {hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte} 60hexbytestring 0x{hexbyte} 61 62%% 63 64\; return (';'); 65\: return (':'); 66\{ return ('{'); 67\} return ('}'); 68 69{ws} ; 70{empty} ; 71{comment} ; 72 73{device_word} return (T_DEVICE); 74{bdaddr_word} return (T_BDADDR); 75{control_psm_word} return (T_CONTROL_PSM); 76{interrupt_psm_word} return (T_INTERRUPT_PSM); 77{reconnect_initiate_word} return (T_RECONNECT_INITIATE); 78{battery_power_word} return (T_BATTERY_POWER); 79{normally_connectable_word} return (T_NORMALLY_CONNECTABLE); 80{hid_descriptor_word} return (T_HID_DESCRIPTOR); 81{true_word} return (T_TRUE); 82{false_word} return (T_FALSE); 83 84{bdaddrstring} { 85 return (bt_aton(yytext, &yylval.bdaddr)? 86 T_BDADDRSTRING : T_ERROR); 87 } 88 89{hexbytestring} { 90 char *ep = NULL; 91 92 yylval.num = strtoul(yytext, &ep, 16); 93 94 return (*ep == '\0'? T_HEXBYTE : T_ERROR); 95 } 96 97. return (T_ERROR); 98 99%% 100 101