lex.l revision 240365
1219019Sgabor/* $FreeBSD: head/usr.bin/mkcsmapper/lex.l 240365 2012-09-11 16:32:31Z dim $ */ 2219019Sgabor/* $NetBSD: lex.l,v 1.4 2006/02/09 22:03:15 dogcow Exp $ */ 3219019Sgabor 4219019Sgabor%{ 5219019Sgabor/*- 6219019Sgabor * Copyright (c)2003 Citrus Project, 7219019Sgabor * All rights reserved. 8219019Sgabor * 9219019Sgabor * Redistribution and use in source and binary forms, with or without 10219019Sgabor * modification, are permitted provided that the following conditions 11219019Sgabor * are met: 12219019Sgabor * 1. Redistributions of source code must retain the above copyright 13219019Sgabor * notice, this list of conditions and the following disclaimer. 14219019Sgabor * 2. Redistributions in binary form must reproduce the above copyright 15219019Sgabor * notice, this list of conditions and the following disclaimer in the 16219019Sgabor * documentation and/or other materials provided with the distribution. 17219019Sgabor * 18219019Sgabor * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19219019Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20219019Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21219019Sgabor * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22219019Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23219019Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24219019Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25219019Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26219019Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27219019Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28219019Sgabor * SUCH DAMAGE. 29219019Sgabor */ 30219019Sgabor 31219019Sgabor#include <sys/cdefs.h> 32219019Sgabor#include <sys/endian.h> 33219019Sgabor 34219019Sgabor#include <assert.h> 35219019Sgabor#include <errno.h> 36219019Sgabor#include <limits.h> 37219019Sgabor#include <stdio.h> 38219019Sgabor#include <stdlib.h> 39219019Sgabor#include <string.h> 40219019Sgabor 41219019Sgabor#include "ldef.h" 42219019Sgabor#include "yacc.h" 43219019Sgabor 44219019Sgaborint line_number = 1; 45219019Sgabor%} 46240365Sdim%option noinput 47219019Sgabor%option nounput 48219019Sgabor 49219019Sgabor%x COMMENT 50219019Sgabor 51219019Sgabor%% 52219019Sgabor 53219019Sgabor[ \t]+ { } 54219019Sgabor#.*[\n]|"//".*[\n]|[\n] { line_number++; return (R_LN); } 55219019Sgabor 56219019Sgabor"/*" { BEGIN COMMENT; } 57219019Sgabor<COMMENT>"*/" { BEGIN 0; } 58219019Sgabor<COMMENT>[\n] { line_number++; } 59219019Sgabor<COMMENT>. { } 60219019Sgabor<COMMENT><<EOF>> { 61238197Seadler yyerror("unexpected file end (unterminated comment)\n"); 62219019Sgabor exit(1); 63219019Sgabor } 64219019Sgabor 65219019Sgabor"="|"/"|"-" { return ((int)yytext[0]); } 66219019Sgabor 67219019Sgabor([1-9][0-9]*)|(0[0-9]*)|(0[xX][0-9A-Fa-f]+) { 68219019Sgabor yylval.i_value = strtoul(yytext, NULL, 0); 69219019Sgabor return (L_IMM); 70219019Sgabor } 71219019Sgabor 72219019Sgabor"TYPE" { return (R_TYPE); } 73219019Sgabor"NAME" { return (R_NAME); } 74219019Sgabor"SRC_ZONE" { return (R_SRC_ZONE); } 75219019Sgabor"DST_INVALID" { return (R_DST_INVALID); } 76219019Sgabor"DST_ILSEQ" { return (R_DST_ILSEQ); } 77219019Sgabor"DST_UNIT_BITS" { return (R_DST_UNIT_BITS); } 78219019Sgabor"BEGIN_MAP" { return (R_BEGIN_MAP); } 79219019Sgabor"END_MAP" { return (R_END_MAP); } 80219019Sgabor"INVALID" { return (R_INVALID); } 81219019Sgabor"ILSEQ" { return (R_ILSEQ); } 82219019Sgabor"OOB_MODE" { return (R_OOB_MODE); } 83219019Sgabor"ROWCOL" { return (R_ROWCOL); } 84219019Sgabor 85219019Sgabor\"([^\"\n]*(\\\")?)*\"|\'([^\'\n]*(\\\')?)*\' { 86219019Sgabor size_t len; 87219019Sgabor 88219019Sgabor len = strlen(yytext); 89219019Sgabor yylval.s_value = malloc(len - 1); 90219019Sgabor strlcpy(yylval.s_value, yytext + 1, len - 1); 91219019Sgabor return (L_STRING); 92219019Sgabor } 93219019Sgabor[^ =/\-0-9\t\n][^ \t\n]* { 94219019Sgabor yylval.s_value = strdup(yytext); 95219019Sgabor return (L_STRING); 96219019Sgabor } 97219019Sgabor 98219019Sgabor%% 99219019Sgabor 100219019Sgabor#ifndef yywrap 101219019Sgaborint 102219019Sgaboryywrap(void) 103219019Sgabor{ 104219019Sgabor 105219019Sgabor return (1); 106219019Sgabor} 107219019Sgabor#endif 108