kmalloc: Avoid code duplication.
[dragonfly.git] / usr.bin / m4 / parser.y
blob12cd84e54343fb88bc462481c414b530a007f2b7
1 %{
2 /* $OpenBSD: parser.y,v 1.6 2008/08/21 21:00:14 espie Exp $ */
3 /*
4 * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * $FreeBSD: src/usr.bin/m4/parser.y,v 1.6 2012/11/17 01:54:24 svnexp Exp $
21 #include <math.h>
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <stdint.h>
25 #include <sys/param.h>
27 #include "mdef.h"
28 #include "extern.h"
30 #define YYSTYPE int32_t
32 extern int yylex(void);
33 extern int yyerror(const char *);
35 %token NUMBER
36 %token ERROR
37 %left LOR
38 %left LAND
39 %left '|'
40 %left '^'
41 %left '&'
42 %left EQ NE
43 %left '<' LE '>' GE
44 %left LSHIFT RSHIFT
45 %left '+' '-'
46 %left '*' '/' '%'
47 %right EXPONENT
48 %right UMINUS UPLUS '!' '~'
52 top : expr { end_result = $1; }
54 expr : expr '+' expr { $$ = $1 + $3; }
55 | expr '-' expr { $$ = $1 - $3; }
56 | expr EXPONENT expr { $$ = pow($1, $3); }
57 | expr '*' expr { $$ = $1 * $3; }
58 | expr '/' expr {
59 if ($3 == 0) {
60 yyerror("division by zero");
61 exit(1);
63 $$ = $1 / $3;
65 | expr '%' expr {
66 if ($3 == 0) {
67 yyerror("modulo zero");
68 exit(1);
70 $$ = $1 % $3;
72 | expr LSHIFT expr { $$ = $1 << $3; }
73 | expr RSHIFT expr { $$ = $1 >> $3; }
74 | expr '<' expr { $$ = $1 < $3; }
75 | expr '>' expr { $$ = $1 > $3; }
76 | expr LE expr { $$ = $1 <= $3; }
77 | expr GE expr { $$ = $1 >= $3; }
78 | expr EQ expr { $$ = $1 == $3; }
79 | expr NE expr { $$ = $1 != $3; }
80 | expr '&' expr { $$ = $1 & $3; }
81 | expr '^' expr { $$ = $1 ^ $3; }
82 | expr '|' expr { $$ = $1 | $3; }
83 | expr LAND expr { $$ = $1 && $3; }
84 | expr LOR expr { $$ = $1 || $3; }
85 | '(' expr ')' { $$ = $2; }
86 | '-' expr %prec UMINUS { $$ = -$2; }
87 | '+' expr %prec UPLUS { $$ = $2; }
88 | '!' expr { $$ = !$2; }
89 | '~' expr { $$ = ~$2; }
90 | NUMBER