lex.l revision 219019
1219019Sgabor/* $FreeBSD: head/usr.bin/mkcsmapper/lex.l 219019 2011-02-25 00:04:39Z gabor $ */ 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%} 46219019Sgabor%option nounput 47219019Sgabor 48219019Sgabor%x COMMENT 49219019Sgabor 50219019Sgabor%% 51219019Sgabor 52219019Sgabor[ \t]+ { } 53219019Sgabor#.*[\n]|"//".*[\n]|[\n] { line_number++; return (R_LN); } 54219019Sgabor 55219019Sgabor"/*" { BEGIN COMMENT; } 56219019Sgabor<COMMENT>"*/" { BEGIN 0; } 57219019Sgabor<COMMENT>[\n] { line_number++; } 58219019Sgabor<COMMENT>. { } 59219019Sgabor<COMMENT><<EOF>> { 60219019Sgabor yyerror("unexpected file end (unterminate comment)\n"); 61219019Sgabor exit(1); 62219019Sgabor } 63219019Sgabor 64219019Sgabor"="|"/"|"-" { return ((int)yytext[0]); } 65219019Sgabor 66219019Sgabor([1-9][0-9]*)|(0[0-9]*)|(0[xX][0-9A-Fa-f]+) { 67219019Sgabor yylval.i_value = strtoul(yytext, NULL, 0); 68219019Sgabor return (L_IMM); 69219019Sgabor } 70219019Sgabor 71219019Sgabor"TYPE" { return (R_TYPE); } 72219019Sgabor"NAME" { return (R_NAME); } 73219019Sgabor"SRC_ZONE" { return (R_SRC_ZONE); } 74219019Sgabor"DST_INVALID" { return (R_DST_INVALID); } 75219019Sgabor"DST_ILSEQ" { return (R_DST_ILSEQ); } 76219019Sgabor"DST_UNIT_BITS" { return (R_DST_UNIT_BITS); } 77219019Sgabor"BEGIN_MAP" { return (R_BEGIN_MAP); } 78219019Sgabor"END_MAP" { return (R_END_MAP); } 79219019Sgabor"INVALID" { return (R_INVALID); } 80219019Sgabor"ILSEQ" { return (R_ILSEQ); } 81219019Sgabor"OOB_MODE" { return (R_OOB_MODE); } 82219019Sgabor"ROWCOL" { return (R_ROWCOL); } 83219019Sgabor 84219019Sgabor\"([^\"\n]*(\\\")?)*\"|\'([^\'\n]*(\\\')?)*\' { 85219019Sgabor size_t len; 86219019Sgabor 87219019Sgabor len = strlen(yytext); 88219019Sgabor yylval.s_value = malloc(len - 1); 89219019Sgabor strlcpy(yylval.s_value, yytext + 1, len - 1); 90219019Sgabor return (L_STRING); 91219019Sgabor } 92219019Sgabor[^ =/\-0-9\t\n][^ \t\n]* { 93219019Sgabor yylval.s_value = strdup(yytext); 94219019Sgabor return (L_STRING); 95219019Sgabor } 96219019Sgabor 97219019Sgabor%% 98219019Sgabor 99219019Sgabor#ifndef yywrap 100219019Sgaborint 101219019Sgaboryywrap(void) 102219019Sgabor{ 103219019Sgabor 104219019Sgabor return (1); 105219019Sgabor} 106219019Sgabor#endif 107