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