xref: /dragonfly/usr.bin/mkcsmapper/lex.l (revision 38b930d0)
1 /* $FreeBSD: head/usr.bin/mkcsmapper/lex.l 252582 2013-07-03 18:25:27Z peter $ */
2 /* $NetBSD: lex.l,v 1.4 2006/02/09 22:03:15 dogcow Exp $	*/
3 
4 %{
5 /*-
6  * Copyright (c)2003 Citrus Project,
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #pragma GCC diagnostic ignored "-Wsign-compare"
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