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