1 | %option never-interactive
|
---|
2 | %option noyywrap
|
---|
3 | %option noinput
|
---|
4 | %option nounput
|
---|
5 | %option noyyget_out
|
---|
6 | %option noyy_push_state
|
---|
7 | %option noyy_pop_state
|
---|
8 | %option noyy_top_state
|
---|
9 | %option noyy_scan_buffer
|
---|
10 | %option noyy_scan_bytes
|
---|
11 | %option noyy_scan_string
|
---|
12 | %option noyyget_extra
|
---|
13 | %option noyyset_extra
|
---|
14 | %option noyyget_leng
|
---|
15 | %option noyyget_text
|
---|
16 | %option noyyget_lineno
|
---|
17 | %option noyyset_lineno
|
---|
18 | %option noyyget_in
|
---|
19 | %option noyyset_in
|
---|
20 | %option noyyget_out
|
---|
21 | %option noyyset_out
|
---|
22 | %option noyyget_lval
|
---|
23 | %option noyyset_lval
|
---|
24 | %option noyyget_lloc
|
---|
25 | %option noyyset_lloc
|
---|
26 | %option noyyget_debug
|
---|
27 | %option noyyset_debug
|
---|
28 | %option noyyalloc
|
---|
29 | %option noyyrealloc
|
---|
30 | %option noyyfree
|
---|
31 | /** @todo %option reentrant */
|
---|
32 | %{
|
---|
33 | /* $NetBSD: arith_lex.l,v 1.13 2005/03/21 22:37:09 dsl Exp $ */
|
---|
34 |
|
---|
35 | /*-
|
---|
36 | * Copyright (c) 1993
|
---|
37 | * The Regents of the University of California. All rights reserved.
|
---|
38 | *
|
---|
39 | * This code is derived from software contributed to Berkeley by
|
---|
40 | * Kenneth Almquist.
|
---|
41 | *
|
---|
42 | * Redistribution and use in source and binary forms, with or without
|
---|
43 | * modification, are permitted provided that the following conditions
|
---|
44 | * are met:
|
---|
45 | * 1. Redistributions of source code must retain the above copyright
|
---|
46 | * notice, this list of conditions and the following disclaimer.
|
---|
47 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
48 | * notice, this list of conditions and the following disclaimer in the
|
---|
49 | * documentation and/or other materials provided with the distribution.
|
---|
50 | * 3. Neither the name of the University nor the names of its contributors
|
---|
51 | * may be used to endorse or promote products derived from this software
|
---|
52 | * without specific prior written permission.
|
---|
53 | *
|
---|
54 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
55 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
56 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
64 | * SUCH DAMAGE.
|
---|
65 | */
|
---|
66 |
|
---|
67 | #if 0
|
---|
68 | #ifndef lint
|
---|
69 | static char sccsid[] = "@(#)arith_lex.l 8.3 (Berkeley) 5/4/95";
|
---|
70 | #else
|
---|
71 | __RCSID("$NetBSD: arith_lex.l,v 1.13 2005/03/21 22:37:09 dsl Exp $");
|
---|
72 | #endif /* not lint */
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | #include <stdio.h>
|
---|
76 | #include "arith.h"
|
---|
77 | #include "error.h"
|
---|
78 | #include "expand.h"
|
---|
79 | #include "var.h"
|
---|
80 | #include "shinstance.h"
|
---|
81 |
|
---|
82 | extern int yylval;
|
---|
83 | extern shinstance *arith_psh;
|
---|
84 | extern char *arith_buf, *arith_startbuf;
|
---|
85 | #undef YY_INPUT
|
---|
86 | #define YY_INPUT(buf,result,max) \
|
---|
87 | result = (*buf = *arith_buf++) ? 1 : YY_NULL;
|
---|
88 | #define YY_NO_UNPUT
|
---|
89 |
|
---|
90 | /* Avoid unnecessary libc bits. */
|
---|
91 | #undef ECHO
|
---|
92 | #define ECHO \
|
---|
93 | do {} while (0)
|
---|
94 | #undef stdin
|
---|
95 | #define stdin \
|
---|
96 | NULL
|
---|
97 | #undef stdout
|
---|
98 | #define stdout \
|
---|
99 | NULL
|
---|
100 | #undef fprintf
|
---|
101 | #define fprintf(a, b, c) \
|
---|
102 | ((void)0)
|
---|
103 | #undef exit
|
---|
104 | #define exit(rc) \
|
---|
105 | do {} while (0)
|
---|
106 | #define YY_FATAL_ERROR(msg) \
|
---|
107 | error(arith_psh, "arith: fatal error: %s", msg)
|
---|
108 | %}
|
---|
109 |
|
---|
110 | %%
|
---|
111 | [ \t\n] { ; }
|
---|
112 | 0x[0-9a-fA-F]+ { yylval = strtol(yytext, 0, 0); return(ARITH_NUM); }
|
---|
113 | 0[0-7]* { yylval = strtol(yytext, 0, 0); return(ARITH_NUM); }
|
---|
114 | [1-9][0-9]* { yylval = strtol(yytext, 0, 0); return(ARITH_NUM); }
|
---|
115 | [A-Za-z_][A-Za-z_0-9]* { char *v = lookupvar(arith_psh, yytext);
|
---|
116 | if (v) {
|
---|
117 | yylval = strtol(v, &v, 0);
|
---|
118 | if (*v == 0)
|
---|
119 | return ARITH_NUM;
|
---|
120 | }
|
---|
121 | error(arith_psh, "arith: syntax error: \"%s\"", arith_startbuf);
|
---|
122 | }
|
---|
123 | "(" { return(ARITH_LPAREN); }
|
---|
124 | ")" { return(ARITH_RPAREN); }
|
---|
125 | "||" { return(ARITH_OR); }
|
---|
126 | "&&" { return(ARITH_AND); }
|
---|
127 | "|" { return(ARITH_BOR); }
|
---|
128 | "^" { return(ARITH_BXOR); }
|
---|
129 | "&" { return(ARITH_BAND); }
|
---|
130 | "==" { return(ARITH_EQ); }
|
---|
131 | "!=" { return(ARITH_NE); }
|
---|
132 | ">" { return(ARITH_GT); }
|
---|
133 | ">=" { return(ARITH_GE); }
|
---|
134 | "<" { return(ARITH_LT); }
|
---|
135 | "<=" { return(ARITH_LE); }
|
---|
136 | "<<" { return(ARITH_LSHIFT); }
|
---|
137 | ">>" { return(ARITH_RSHIFT); }
|
---|
138 | "*" { return(ARITH_MUL); }
|
---|
139 | "/" { return(ARITH_DIV); }
|
---|
140 | "%" { return(ARITH_REM); }
|
---|
141 | "+" { return(ARITH_ADD); }
|
---|
142 | "-" { return(ARITH_SUB); }
|
---|
143 | "~" { return(ARITH_BNOT); }
|
---|
144 | "!" { return(ARITH_NOT); }
|
---|
145 | . { error(arith_psh, "arith: syntax error: \"%s\"", arith_startbuf); }
|
---|
146 | %%
|
---|
147 |
|
---|
148 | void
|
---|
149 | arith_lex_reset() {
|
---|
150 | #ifdef YY_NEW_FILE
|
---|
151 | YY_NEW_FILE;
|
---|
152 | #endif
|
---|
153 | }
|
---|
154 |
|
---|
155 | void *
|
---|
156 | yyalloc(yy_size_t cb)
|
---|
157 | {
|
---|
158 | return sh_malloc(NULL, cb);
|
---|
159 | }
|
---|
160 |
|
---|
161 | void *
|
---|
162 | yyrealloc(void *pv, yy_size_t cb)
|
---|
163 | {
|
---|
164 | return sh_realloc(NULL, pv, cb);
|
---|
165 | }
|
---|
166 |
|
---|
167 | void
|
---|
168 | yyfree(void *pv)
|
---|
169 | {
|
---|
170 | sh_free(NULL, pv);
|
---|
171 | }
|
---|
172 |
|
---|