1219019Sgabor/* $FreeBSD$ */
2219019Sgabor/* $NetBSD: lex.l,v 1.3 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#include <sys/queue.h>
34219019Sgabor#include <sys/types.h>
35219019Sgabor
36219019Sgabor#include <assert.h>
37219019Sgabor#include <errno.h>
38219019Sgabor#include <limits.h>
39219019Sgabor#include <stdio.h>
40219019Sgabor#include <stdlib.h>
41219019Sgabor#include <string.h>
42219019Sgabor
43219019Sgabor#include "ldef.h"
44219019Sgabor#include "yacc.h"
45219019Sgabor
46252582Speter#define YY_DECL int yylex(void)
47252582Speter
48250984Sedint linenumber = 1;
49219019Sgabor%}
50240365Sdim%option	noinput
51219019Sgabor%option	nounput
52219019Sgabor
53219019Sgabor%x	COMMENT
54219019Sgabor
55219019Sgabor%%
56219019Sgabor
57219019Sgabor[ \t]+	{ }
58250984Sed#.*[\n]|"//".*[\n]|[\n]	{ linenumber++; return (R_LN); }
59219019Sgabor
60219019Sgabor"/*"		{ BEGIN COMMENT; }
61219019Sgabor<COMMENT>"*/"	{ BEGIN 0; }
62250984Sed<COMMENT>[\n]	{ linenumber++; }
63219019Sgabor<COMMENT>.	{ }
64219019Sgabor<COMMENT><<EOF>>	{
65238197Seadler		yyerror("unexpected file end (unterminated comment)\n");
66219019Sgabor		exit(1);
67219019Sgabor	}
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"NAME"		{ return (R_NAME); }
75219019Sgabor"ENCODING"	{ return (R_ENCODING); }
76219019Sgabor"VARIABLE"	{ return (R_VARIABLE); }
77219019Sgabor"DEFCSID"	{ return (R_DEFCSID); }
78219019Sgabor"INVALID"	{ return (R_INVALID); }
79219019Sgabor
80219019Sgabor\"([^\"\n]*(\\\")?)*\"|\'([^\'\n]*(\\\')?)*\'	{
81219019Sgabor		size_t len;
82219019Sgabor
83219019Sgabor		len = strlen(yytext);
84219019Sgabor		yylval.s_value = malloc(len - 1);
85219019Sgabor		strlcpy(yylval.s_value, yytext + 1, len - 1);
86219019Sgabor		return (L_STRING);
87219019Sgabor	}
88219019Sgabor[^ =/\-0-9\t\n][^ \t\n]*	{
89219019Sgabor		yylval.s_value = strdup(yytext);
90219019Sgabor		return (L_STRING);
91219019Sgabor	}
92219019Sgabor
93219019Sgabor%%
94219019Sgabor
95219019Sgabor#ifndef yywrap
96219019Sgaborint
97219019Sgaboryywrap(void)
98219019Sgabor{
99219019Sgabor
100219019Sgabor	return (1);
101219019Sgabor}
102219019Sgabor#endif
103