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
46219019Sgaborint line_number = 1;
47219019Sgabor%}
48240537Sdim%option	noinput
49219019Sgabor%option	nounput
50219019Sgabor
51219019Sgabor%x	COMMENT
52219019Sgabor
53219019Sgabor%%
54219019Sgabor
55219019Sgabor[ \t]+	{ }
56219019Sgabor#.*[\n]|"//".*[\n]|[\n]	{ line_number++; return (R_LN); }
57219019Sgabor
58219019Sgabor"/*"		{ BEGIN COMMENT; }
59219019Sgabor<COMMENT>"*/"	{ BEGIN 0; }
60219019Sgabor<COMMENT>[\n]	{ line_number++; }
61219019Sgabor<COMMENT>.	{ }
62219019Sgabor<COMMENT><<EOF>>	{
63240537Sdim		yyerror("unexpected file end (unterminated comment)\n");
64219019Sgabor		exit(1);
65219019Sgabor	}
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"NAME"		{ return (R_NAME); }
73219019Sgabor"ENCODING"	{ return (R_ENCODING); }
74219019Sgabor"VARIABLE"	{ return (R_VARIABLE); }
75219019Sgabor"DEFCSID"	{ return (R_DEFCSID); }
76219019Sgabor"INVALID"	{ return (R_INVALID); }
77219019Sgabor
78219019Sgabor\"([^\"\n]*(\\\")?)*\"|\'([^\'\n]*(\\\')?)*\'	{
79219019Sgabor		size_t len;
80219019Sgabor
81219019Sgabor		len = strlen(yytext);
82219019Sgabor		yylval.s_value = malloc(len - 1);
83219019Sgabor		strlcpy(yylval.s_value, yytext + 1, len - 1);
84219019Sgabor		return (L_STRING);
85219019Sgabor	}
86219019Sgabor[^ =/\-0-9\t\n][^ \t\n]*	{
87219019Sgabor		yylval.s_value = strdup(yytext);
88219019Sgabor		return (L_STRING);
89219019Sgabor	}
90219019Sgabor
91219019Sgabor%%
92219019Sgabor
93219019Sgabor#ifndef yywrap
94219019Sgaborint
95219019Sgaboryywrap(void)
96219019Sgabor{
97219019Sgabor
98219019Sgabor	return (1);
99219019Sgabor}
100219019Sgabor#endif
101