1219019Sgabor/* $FreeBSD$ */
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
44252582Speter#define YY_DECL int yylex(void)
45252582Speter
46250984Sedint linenumber = 1;
47219019Sgabor%}
48240365Sdim%option	noinput
49219019Sgabor%option	nounput
50219019Sgabor
51219019Sgabor%x	COMMENT
52219019Sgabor
53219019Sgabor%%
54219019Sgabor
55219019Sgabor[ \t]+	{ }
56250984Sed#.*[\n]|"//".*[\n]|[\n]	{ linenumber++; return (R_LN); }
57219019Sgabor
58219019Sgabor"/*"		{ BEGIN COMMENT; }
59219019Sgabor<COMMENT>"*/"	{ BEGIN 0; }
60250984Sed<COMMENT>[\n]	{ linenumber++; }
61219019Sgabor<COMMENT>.	{ }
62219019Sgabor<COMMENT><<EOF>>	{
63238197Seadler		yyerror("unexpected file end (unterminated comment)\n");
64219019Sgabor		exit(1);
65219019Sgabor	}
66219019Sgabor
67219019Sgabor"="|"/"|"-"	{ return ((int)yytext[0]); }
68219019Sgabor
69219019Sgabor([1-9][0-9]*)|(0[0-9]*)|(0[xX][0-9A-Fa-f]+)	{
70219019Sgabor		yylval.i_value = strtoul(yytext, NULL, 0);
71219019Sgabor		return (L_IMM);
72219019Sgabor	}
73219019Sgabor
74219019Sgabor"TYPE"		{ return (R_TYPE); }
75219019Sgabor"NAME"		{ return (R_NAME); }
76219019Sgabor"SRC_ZONE"	{ return (R_SRC_ZONE); }
77219019Sgabor"DST_INVALID"	{ return (R_DST_INVALID); }
78219019Sgabor"DST_ILSEQ"	{ return (R_DST_ILSEQ); }
79219019Sgabor"DST_UNIT_BITS"	{ return (R_DST_UNIT_BITS); }
80219019Sgabor"BEGIN_MAP"	{ return (R_BEGIN_MAP); }
81219019Sgabor"END_MAP"	{ return (R_END_MAP); }
82219019Sgabor"INVALID"	{ return (R_INVALID); }
83219019Sgabor"ILSEQ"		{ return (R_ILSEQ); }
84219019Sgabor"OOB_MODE"	{ return (R_OOB_MODE); }
85219019Sgabor"ROWCOL"	{ return (R_ROWCOL); }
86219019Sgabor
87219019Sgabor\"([^\"\n]*(\\\")?)*\"|\'([^\'\n]*(\\\')?)*\'	{
88219019Sgabor		size_t len;
89219019Sgabor
90219019Sgabor		len = strlen(yytext);
91219019Sgabor		yylval.s_value = malloc(len - 1);
92219019Sgabor		strlcpy(yylval.s_value, yytext + 1, len - 1);
93219019Sgabor		return (L_STRING);
94219019Sgabor	}
95219019Sgabor[^ =/\-0-9\t\n][^ \t\n]*	{
96219019Sgabor		yylval.s_value = strdup(yytext);
97219019Sgabor		return (L_STRING);
98219019Sgabor	}
99219019Sgabor
100219019Sgabor%%
101219019Sgabor
102219019Sgabor#ifndef yywrap
103219019Sgaborint
104219019Sgaboryywrap(void)
105219019Sgabor{
106219019Sgabor
107219019Sgabor	return (1);
108219019Sgabor}
109219019Sgabor#endif
110