1 %{ 2 /* @(#)cpy.y 1.8 19/08/29 2010-2019 J. Schilling */ 3 #include <schily/mconfig.h> 4 #ifndef lint 5 static UConst char y_sccsid[] = 6 "@(#)cpy.y 1.8 19/08/29 2010-2019 J. Schilling"; 7 #endif 8 /* 9 * This implementation is based on the UNIX 32V release from 1978 10 * with permission from Caldera Inc. 11 * 12 * Copyright (c) 2010-2019 J. Schilling 13 * All rights reserved. 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution. 23 * 3. Neither the name of the copyright holder nor the names of contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 */ 39 /* 40 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 41 * 42 * Redistribution and use in source and binary forms, with or without 43 * modification, are permitted provided that the following conditions are 44 * met: 45 * 1. Redistributions of source code and documentation must retain the above 46 * copyright notice, this list of conditions and the following 47 * disclaimer. 48 * 49 * 2. Redistributions in binary form must reproduce the above copyright 50 * notice, this list of conditions and the following disclaimer in the 51 * documentation and/or other materials provided with the distribution. 52 * 53 * 3. All advertising materials mentioning features or use of this software 54 * must display the following acknowledgement: This product includes 55 * software developed or owned by Caldera International, Inc. 56 * 57 * 4. Neither the name of Caldera International, Inc. nor the names of other 58 * contributors may be used to endorse or promote products derived from 59 * this software without specific prior written permission. 60 * 61 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 62 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 63 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 64 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 65 * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR 66 * ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 70 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 71 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 72 * POSSIBILITY OF SUCH DAMAGE. 73 */ 74 #include <schily/mconfig.h> 75 76 #include "cpp.h" 77 #include <schily/limits.h> 78 %} 79 %term number stop DEFINED 80 %term EQ NE LE GE LS RS 81 %term ANDAND OROR 82 %left ',' 83 %right '=' 84 %right '?' ':' 85 %left OROR 86 %left ANDAND 87 %left '|' '^' 88 %left '&' 89 %binary EQ NE 90 %binary '<' '>' LE GE 91 %left LS RS 92 %left '+' '-' 93 %left '*' '/' '%' 94 %right '!' '~' UMINUS 95 %left '(' '.' 96 %% 97 S: e stop {return($1);} 98 99 100 e: e '*' e 101 {$$ = $1 * $3;} 102 | e '/' e 103 { 104 if ($3 == 0) { 105 yyerror("division by zero"); 106 $$ = 0; 107 } else if ($1 == INT_MIN && $3 == -1) { 108 yyerror("division overflow"); 109 $$ = INT_MIN; 110 } else { 111 $$ = $1 / $3; 112 } 113 } 114 | e '%' e 115 { 116 if ($3 == 0) { 117 yyerror("division by zero"); 118 $$ = 0; 119 } else if ($1 == INT_MIN && $3 == -1) { 120 yyerror("division overflow"); 121 $$ = INT_MIN; 122 } else { 123 $$ = $1 % $3; 124 } 125 } 126 | e '+' e 127 {$$ = $1 + $3;} 128 | e '-' e 129 {$$ = $1 - $3;} 130 | e LS e 131 {$$ = $1 << $3;} 132 | e RS e 133 {$$ = $1 >> $3;} 134 | e '<' e 135 {$$ = $1 < $3;} 136 | e '>' e 137 {$$ = $1 > $3;} 138 | e LE e 139 {$$ = $1 <= $3;} 140 | e GE e 141 {$$ = $1 >= $3;} 142 | e EQ e 143 {$$ = $1 == $3;} 144 | e NE e 145 {$$ = $1 != $3;} 146 | e '&' e 147 {$$ = $1 & $3;} 148 | e '^' e 149 {$$ = $1 ^ $3;} 150 | e '|' e 151 {$$ = $1 | $3;} 152 | e ANDAND e 153 {$$ = $1 && $3;} 154 | e OROR e 155 {$$ = $1 || $3;} 156 | e '?' e ':' e 157 {$$ = $1 ? $3 : $5;} 158 | e ',' e 159 {$$ = $3;} 160 | term 161 {$$ = $1;} 162 term: 163 '-' term %prec UMINUS 164 {$$ = -$2;} 165 | '!' term 166 {$$ = !$2;} 167 | '~' term 168 {$$ = ~$2;} 169 | '(' e ')' 170 {$$ = $2;} 171 | DEFINED '(' number ')' 172 {$$ = $3;} 173 | DEFINED number 174 {$$ = $2;} 175 | number 176 {$$ = $1;} 177 %% 178 # include "yylex.c" 179