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