xref: /freebsd/usr.bin/mkesdb/lex.l (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
1ad30f8e7SGabor Kovesdan /* $NetBSD: lex.l,v 1.3 2006/02/09 22:03:15 dogcow Exp $	*/
2ad30f8e7SGabor Kovesdan 
3ad30f8e7SGabor Kovesdan %{
4ad30f8e7SGabor Kovesdan /*-
5*1de7b4b8SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause
6*1de7b4b8SPedro F. Giffuni  *
7ad30f8e7SGabor Kovesdan  * Copyright (c)2003 Citrus Project,
8ad30f8e7SGabor Kovesdan  * All rights reserved.
9ad30f8e7SGabor Kovesdan  *
10ad30f8e7SGabor Kovesdan  * Redistribution and use in source and binary forms, with or without
11ad30f8e7SGabor Kovesdan  * modification, are permitted provided that the following conditions
12ad30f8e7SGabor Kovesdan  * are met:
13ad30f8e7SGabor Kovesdan  * 1. Redistributions of source code must retain the above copyright
14ad30f8e7SGabor Kovesdan  *    notice, this list of conditions and the following disclaimer.
15ad30f8e7SGabor Kovesdan  * 2. Redistributions in binary form must reproduce the above copyright
16ad30f8e7SGabor Kovesdan  *    notice, this list of conditions and the following disclaimer in the
17ad30f8e7SGabor Kovesdan  *    documentation and/or other materials provided with the distribution.
18ad30f8e7SGabor Kovesdan  *
19ad30f8e7SGabor Kovesdan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20ad30f8e7SGabor Kovesdan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ad30f8e7SGabor Kovesdan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22ad30f8e7SGabor Kovesdan  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23ad30f8e7SGabor Kovesdan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24ad30f8e7SGabor Kovesdan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25ad30f8e7SGabor Kovesdan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26ad30f8e7SGabor Kovesdan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27ad30f8e7SGabor Kovesdan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28ad30f8e7SGabor Kovesdan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29ad30f8e7SGabor Kovesdan  * SUCH DAMAGE.
30ad30f8e7SGabor Kovesdan  */
31ad30f8e7SGabor Kovesdan 
32ad30f8e7SGabor Kovesdan #include <sys/cdefs.h>
33ad30f8e7SGabor Kovesdan #include <sys/endian.h>
34ad30f8e7SGabor Kovesdan #include <sys/queue.h>
35ad30f8e7SGabor Kovesdan #include <sys/types.h>
36ad30f8e7SGabor Kovesdan 
37ad30f8e7SGabor Kovesdan #include <assert.h>
38ad30f8e7SGabor Kovesdan #include <errno.h>
39ad30f8e7SGabor Kovesdan #include <limits.h>
40ad30f8e7SGabor Kovesdan #include <stdio.h>
41ad30f8e7SGabor Kovesdan #include <stdlib.h>
42ad30f8e7SGabor Kovesdan #include <string.h>
43ad30f8e7SGabor Kovesdan 
44ad30f8e7SGabor Kovesdan #include "ldef.h"
45ad30f8e7SGabor Kovesdan #include "yacc.h"
46ad30f8e7SGabor Kovesdan 
4733e7ec3eSPeter Wemm #define YY_DECL int yylex(void)
4833e7ec3eSPeter Wemm 
49af8e44c8SEd Schouten int linenumber = 1;
50ad30f8e7SGabor Kovesdan %}
51620a62e0SDimitry Andric %option	noinput
52ad30f8e7SGabor Kovesdan %option	nounput
53ad30f8e7SGabor Kovesdan 
54ad30f8e7SGabor Kovesdan %x	COMMENT
55ad30f8e7SGabor Kovesdan 
56ad30f8e7SGabor Kovesdan %%
57ad30f8e7SGabor Kovesdan 
58ad30f8e7SGabor Kovesdan [ \t]+	{ }
59af8e44c8SEd Schouten #.*[\n]|"//".*[\n]|[\n]	{ linenumber++; return (R_LN); }
60ad30f8e7SGabor Kovesdan 
61ad30f8e7SGabor Kovesdan "/*"		{ BEGIN COMMENT; }
62ad30f8e7SGabor Kovesdan <COMMENT>"*/"	{ BEGIN 0; }
63af8e44c8SEd Schouten <COMMENT>[\n]	{ linenumber++; }
64ad30f8e7SGabor Kovesdan <COMMENT>.	{ }
65ad30f8e7SGabor Kovesdan <COMMENT><<EOF>>	{
66e43ecd2bSEitan Adler 		yyerror("unexpected file end (unterminated comment)\n");
67ad30f8e7SGabor Kovesdan 		exit(1);
68ad30f8e7SGabor Kovesdan 	}
69ad30f8e7SGabor Kovesdan 
70ad30f8e7SGabor Kovesdan ([1-9][0-9]*)|(0[0-9]*)|(0[xX][0-9A-Fa-f]+)	{
71ad30f8e7SGabor Kovesdan 		yylval.i_value = strtoul(yytext, NULL, 0);
72ad30f8e7SGabor Kovesdan 		return (L_IMM);
73ad30f8e7SGabor Kovesdan 	}
74ad30f8e7SGabor Kovesdan 
75ad30f8e7SGabor Kovesdan "NAME"		{ return (R_NAME); }
76ad30f8e7SGabor Kovesdan "ENCODING"	{ return (R_ENCODING); }
77ad30f8e7SGabor Kovesdan "VARIABLE"	{ return (R_VARIABLE); }
78ad30f8e7SGabor Kovesdan "DEFCSID"	{ return (R_DEFCSID); }
79ad30f8e7SGabor Kovesdan "INVALID"	{ return (R_INVALID); }
80ad30f8e7SGabor Kovesdan 
81ad30f8e7SGabor Kovesdan \"([^\"\n]*(\\\")?)*\"|\'([^\'\n]*(\\\')?)*\'	{
82ad30f8e7SGabor Kovesdan 		size_t len;
83ad30f8e7SGabor Kovesdan 
84ad30f8e7SGabor Kovesdan 		len = strlen(yytext);
85ad30f8e7SGabor Kovesdan 		yylval.s_value = malloc(len - 1);
86ad30f8e7SGabor Kovesdan 		strlcpy(yylval.s_value, yytext + 1, len - 1);
87ad30f8e7SGabor Kovesdan 		return (L_STRING);
88ad30f8e7SGabor Kovesdan 	}
89ad30f8e7SGabor Kovesdan [^ =/\-0-9\t\n][^ \t\n]*	{
90ad30f8e7SGabor Kovesdan 		yylval.s_value = strdup(yytext);
91ad30f8e7SGabor Kovesdan 		return (L_STRING);
92ad30f8e7SGabor Kovesdan 	}
93ad30f8e7SGabor Kovesdan 
94ad30f8e7SGabor Kovesdan %%
95ad30f8e7SGabor Kovesdan 
96ad30f8e7SGabor Kovesdan #ifndef yywrap
97ad30f8e7SGabor Kovesdan int
98ad30f8e7SGabor Kovesdan yywrap(void)
99ad30f8e7SGabor Kovesdan {
100ad30f8e7SGabor Kovesdan 
101ad30f8e7SGabor Kovesdan 	return (1);
102ad30f8e7SGabor Kovesdan }
103ad30f8e7SGabor Kovesdan #endif
104