annotate intl/plural.y @ 2120:1d67cf383e32 trunk

[svn] - dynamically allocate the playlist at startup and fix some lingering improper uses of playlist_get()
author nenolod
date Fri, 15 Dec 2006 07:20:41 -0800
parents 705d4c089fce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 %{
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 /* Expression parsing for plural form selection.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify it
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 under the terms of the GNU Library General Public License as published
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 by the Free Software Foundation; either version 2, or (at your option)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 Library General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 You should have received a copy of the GNU Library General Public
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 License along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 USA. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 /* The bison generated parser uses alloca. AIX 3 forces us to put this
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 declaration at the beginning of the file. The declaration in bison's
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 skeleton file comes too late. This must come before <config.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 because <config.h> may include arbitrary system headers. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #if defined _AIX && !defined __GNUC__
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #pragma alloca
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 # include <config.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #include <stddef.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 #include "plural-exp.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 /* The main function generated by the parser is called __gettextparse,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 but we want it to be called PLURAL_PARSE. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 #ifndef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 # define __gettextparse PLURAL_PARSE
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 #define YYLEX_PARAM &((struct parse_args *) arg)->cp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 #define YYPARSE_PARAM arg
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 %}
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 %pure_parser
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 %expect 7
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 %union {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 unsigned long int num;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 enum operator op;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 struct expression *exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 %{
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 /* Prototypes for local functions. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 static struct expression *new_exp PARAMS ((int nargs, enum operator op,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 struct expression * const *args));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 static inline struct expression *new_exp_0 PARAMS ((enum operator op));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 static inline struct expression *new_exp_1 PARAMS ((enum operator op,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 struct expression *right));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 static struct expression *new_exp_2 PARAMS ((enum operator op,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 struct expression *left,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 struct expression *right));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 static inline struct expression *new_exp_3 PARAMS ((enum operator op,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 struct expression *bexp,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 struct expression *tbranch,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 struct expression *fbranch));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 static int yylex PARAMS ((YYSTYPE *lval, const char **pexp));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 static void yyerror PARAMS ((const char *str));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 /* Allocation of expressions. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 static struct expression *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 new_exp (nargs, op, args)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 int nargs;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 enum operator op;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 struct expression * const *args;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 struct expression *newp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 /* If any of the argument could not be malloc'ed, just return NULL. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 for (i = nargs - 1; i >= 0; i--)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 if (args[i] == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 goto fail;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 /* Allocate a new expression. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 newp = (struct expression *) malloc (sizeof (*newp));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 if (newp != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 newp->nargs = nargs;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 newp->operation = op;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 for (i = nargs - 1; i >= 0; i--)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 newp->val.args[i] = args[i];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 return newp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 fail:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 for (i = nargs - 1; i >= 0; i--)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 FREE_EXPRESSION (args[i]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 static inline struct expression *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 new_exp_0 (op)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 enum operator op;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 return new_exp (0, op, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 static inline struct expression *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 new_exp_1 (op, right)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 enum operator op;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 struct expression *right;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 struct expression *args[1];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 args[0] = right;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 return new_exp (1, op, args);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 static struct expression *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 new_exp_2 (op, left, right)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 enum operator op;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 struct expression *left;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 struct expression *right;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 struct expression *args[2];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 args[0] = left;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 args[1] = right;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 return new_exp (2, op, args);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 static inline struct expression *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 new_exp_3 (op, bexp, tbranch, fbranch)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 enum operator op;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 struct expression *bexp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 struct expression *tbranch;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 struct expression *fbranch;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 struct expression *args[3];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 args[0] = bexp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 args[1] = tbranch;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 args[2] = fbranch;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 return new_exp (3, op, args);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 %}
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 /* This declares that all operators have the same associativity and the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 precedence order as in C. See [Harbison, Steele: C, A Reference Manual].
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 There is no unary minus and no bitwise operators.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 Operators with the same syntactic behaviour have been merged into a single
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 token, to save space in the array generated by bison. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 %right '?' /* ? */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 %left '|' /* || */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 %left '&' /* && */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 %left EQUOP2 /* == != */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 %left CMPOP2 /* < > <= >= */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 %left ADDOP2 /* + - */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 %left MULOP2 /* * / % */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 %right '!' /* ! */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 %token <op> EQUOP2 CMPOP2 ADDOP2 MULOP2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 %token <num> NUMBER
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 %type <exp> exp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 %%
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 start: exp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 if ($1 == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 YYABORT;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 ((struct parse_args *) arg)->res = $1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 ;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 exp: exp '?' exp ':' exp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 $$ = new_exp_3 (qmop, $1, $3, $5);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 | exp '|' exp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 $$ = new_exp_2 (lor, $1, $3);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 | exp '&' exp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 $$ = new_exp_2 (land, $1, $3);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 | exp EQUOP2 exp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 $$ = new_exp_2 ($2, $1, $3);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 | exp CMPOP2 exp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 $$ = new_exp_2 ($2, $1, $3);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 | exp ADDOP2 exp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 $$ = new_exp_2 ($2, $1, $3);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 | exp MULOP2 exp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 $$ = new_exp_2 ($2, $1, $3);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 | '!' exp
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 $$ = new_exp_1 (lnot, $2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 | 'n'
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 $$ = new_exp_0 (var);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 | NUMBER
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 if (($$ = new_exp_0 (num)) != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 $$->val.num = $1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 | '(' exp ')'
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 $$ = $2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 ;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 %%
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 internal_function
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 FREE_EXPRESSION (exp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 struct expression *exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 if (exp == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 /* Handle the recursive case. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 switch (exp->nargs)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 case 3:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 FREE_EXPRESSION (exp->val.args[2]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 /* FALLTHROUGH */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 case 2:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 FREE_EXPRESSION (exp->val.args[1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 /* FALLTHROUGH */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 case 1:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 FREE_EXPRESSION (exp->val.args[0]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 /* FALLTHROUGH */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 free (exp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 static int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 yylex (lval, pexp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 YYSTYPE *lval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 const char **pexp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 const char *exp = *pexp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 int result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 while (1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 if (exp[0] == '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 *pexp = exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 return YYEOF;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 if (exp[0] != ' ' && exp[0] != '\t')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 ++exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 result = *exp++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 switch (result)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 case '0': case '1': case '2': case '3': case '4':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 case '5': case '6': case '7': case '8': case '9':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 unsigned long int n = result - '0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 while (exp[0] >= '0' && exp[0] <= '9')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 n *= 10;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 n += exp[0] - '0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 ++exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 lval->num = n;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 result = NUMBER;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 case '=':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 if (exp[0] == '=')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 ++exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 lval->op = equal;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 result = EQUOP2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 result = YYERRCODE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 case '!':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 if (exp[0] == '=')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 ++exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 lval->op = not_equal;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 result = EQUOP2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 case '&':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 case '|':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 if (exp[0] == result)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 ++exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 result = YYERRCODE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 case '<':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 if (exp[0] == '=')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 ++exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 lval->op = less_or_equal;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 lval->op = less_than;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 result = CMPOP2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 case '>':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 if (exp[0] == '=')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 ++exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 lval->op = greater_or_equal;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 lval->op = greater_than;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 result = CMPOP2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 case '*':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 lval->op = mult;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 result = MULOP2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 case '/':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 lval->op = divide;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 result = MULOP2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 case '%':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 lval->op = module;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 result = MULOP2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 case '+':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 lval->op = plus;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 result = ADDOP2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 case '-':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 lval->op = minus;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 result = ADDOP2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 case 'n':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 case '?':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 case ':':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 case '(':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 case ')':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 /* Nothing, just return the character. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 case ';':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383 case '\n':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 case '\0':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 /* Be safe and let the user call this function again. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 --exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 result = YYEOF;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391 result = YYERRCODE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 #if YYDEBUG != 0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 --exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 *pexp = exp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 return result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405 yyerror (str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 const char *str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408 /* Do nothing. We don't print error messages here. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
409 }