lexer.l revision 162128
1226584Sdim%{ 2226584Sdim/* 3226584Sdim * lexer.l 4226584Sdim */ 5226584Sdim 6226584Sdim/*- 7226584Sdim * Copyright (c) 2006 Maksim Yevmenkin <m_evmenkin@yahoo.com> 8226584Sdim * All rights reserved. 9226584Sdim * 10226584Sdim * Redistribution and use in source and binary forms, with or without 11226584Sdim * modification, are permitted provided that the following conditions 12226584Sdim * are met: 13226584Sdim * 1. Redistributions of source code must retain the above copyright 14226584Sdim * notice, this list of conditions and the following disclaimer. 15226584Sdim * 2. Redistributions in binary form must reproduce the above copyright 16226584Sdim * notice, this list of conditions and the following disclaimer in the 17226584Sdim * documentation and/or other materials provided with the distribution. 18226584Sdim * 19226584Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20226584Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21226584Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22226584Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23226584Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24226584Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25226584Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26226584Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27226584Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28226584Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29226584Sdim * SUCH DAMAGE. 30226584Sdim * 31226584Sdim * $Id: lexer.l,v 1.3 2006/09/07 21:06:53 max Exp $ 32226584Sdim * $FreeBSD: head/usr.sbin/bluetooth/bthidd/lexer.l 162128 2006-09-07 21:47:49Z emax $ 33226584Sdim */ 34226584Sdim 35226584Sdim#include <bluetooth.h> 36226584Sdim#include <stdlib.h> 37226584Sdim#include "parser.h" 38226584Sdim 39226584Sdim int yylex (void); 40226584Sdim%} 41226584Sdim 42226584Sdim%option yylineno noyywrap nounput 43226584Sdim 44226584Sdimdelim [ \t\n] 45226584Sdimws {delim}+ 46226584Sdimempty {delim}* 47226584Sdimcomment \#.* 48226584Sdim 49226584Sdimhexdigit [0-9a-fA-F] 50226584Sdimhexbyte {hexdigit}{hexdigit}? 51226584Sdim 52226584Sdimdevice_word device 53226584Sdimbdaddr_word bdaddr 54226584Sdimcontrol_psm_word control_psm 55interrupt_psm_word interrupt_psm 56reconnect_initiate_word reconnect_initiate 57battery_power_word battery_power 58normally_connectable_word normally_connectable 59hid_descriptor_word hid_descriptor 60true_word true 61false_word false 62 63bdaddrstring {hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte} 64hexbytestring 0x{hexbyte} 65 66%% 67 68\; return (';'); 69\: return (':'); 70\{ return ('{'); 71\} return ('}'); 72 73{ws} ; 74{empty} ; 75{comment} ; 76 77{device_word} return (T_DEVICE); 78{bdaddr_word} return (T_BDADDR); 79{control_psm_word} return (T_CONTROL_PSM); 80{interrupt_psm_word} return (T_INTERRUPT_PSM); 81{reconnect_initiate_word} return (T_RECONNECT_INITIATE); 82{battery_power_word} return (T_BATTERY_POWER); 83{normally_connectable_word} return (T_NORMALLY_CONNECTABLE); 84{hid_descriptor_word} return (T_HID_DESCRIPTOR); 85{true_word} return (T_TRUE); 86{false_word} return (T_FALSE); 87 88{bdaddrstring} { 89 return (bt_aton(yytext, &yylval.bdaddr)? 90 T_BDADDRSTRING : T_ERROR); 91 } 92 93{hexbytestring} { 94 char *ep; 95 96 yylval.num = strtoul(yytext, &ep, 16); 97 98 return (*ep == '\0'? T_HEXBYTE : T_ERROR); 99 } 100 101. return (T_ERROR); 102 103%% 104 105