10Sstevel@tonic-gate %{
20Sstevel@tonic-gate /*
30Sstevel@tonic-gate * CDDL HEADER START
40Sstevel@tonic-gate *
50Sstevel@tonic-gate * The contents of this file are subject to the terms of the
60Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
70Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
80Sstevel@tonic-gate * with the License.
90Sstevel@tonic-gate *
100Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
110Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
120Sstevel@tonic-gate * See the License for the specific language governing permissions
130Sstevel@tonic-gate * and limitations under the License.
140Sstevel@tonic-gate *
150Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
160Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
170Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
180Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
190Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
200Sstevel@tonic-gate *
210Sstevel@tonic-gate * CDDL HEADER END
220Sstevel@tonic-gate */
230Sstevel@tonic-gate %}
24*291Smike_s
25*291Smike_s /*
26*291Smike_s * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27*291Smike_s * Use is subject to license terms.
28*291Smike_s */
29*291Smike_s
300Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
310Sstevel@tonic-gate /* All Rights Reserved */
320Sstevel@tonic-gate
330Sstevel@tonic-gate %{
340Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
350Sstevel@tonic-gate extern long evalval;
360Sstevel@tonic-gate #define YYSTYPE long
370Sstevel@tonic-gate %}
380Sstevel@tonic-gate
390Sstevel@tonic-gate %term DIGITS
400Sstevel@tonic-gate %left OROR
410Sstevel@tonic-gate %left ANDAND
420Sstevel@tonic-gate %left '|' '^'
430Sstevel@tonic-gate %left '&'
440Sstevel@tonic-gate %right '!' '~'
450Sstevel@tonic-gate %nonassoc GT GE LT LE NE EQ
460Sstevel@tonic-gate %left '+' '-'
470Sstevel@tonic-gate %left '*' '/' '%'
480Sstevel@tonic-gate %right POWER
490Sstevel@tonic-gate %right UMINUS
500Sstevel@tonic-gate %%
510Sstevel@tonic-gate
520Sstevel@tonic-gate s : e = { evalval = $1; }
530Sstevel@tonic-gate | = { evalval = 0; }
540Sstevel@tonic-gate ;
550Sstevel@tonic-gate
560Sstevel@tonic-gate e : e OROR e = { $$ = ($1 != 0 || $3 != 0) ? 1 : 0; }
570Sstevel@tonic-gate | e ANDAND e = { $$ = ($1 != 0 && $3 != 0) ? 1 : 0; }
580Sstevel@tonic-gate | '!' e = { $$ = $2 == 0; }
590Sstevel@tonic-gate | '~' e = { $$ = ~$2; }
600Sstevel@tonic-gate | e EQ e = { $$ = $1 == $3; }
610Sstevel@tonic-gate | e NE e = { $$ = $1 != $3; }
620Sstevel@tonic-gate | e GT e = { $$ = $1 > $3; }
630Sstevel@tonic-gate | e GE e = { $$ = $1 >= $3; }
640Sstevel@tonic-gate | e LT e = { $$ = $1 < $3; }
650Sstevel@tonic-gate | e LE e = { $$ = $1 <= $3; }
660Sstevel@tonic-gate | e '|' e = { $$ = ($1 | $3); }
670Sstevel@tonic-gate | e '&' e = { $$ = ($1 & $3); }
680Sstevel@tonic-gate | e '^' e = { $$ = ($1 ^ $3); }
690Sstevel@tonic-gate | e '+' e = { $$ = ($1 + $3); }
700Sstevel@tonic-gate | e '-' e = { $$ = ($1 - $3); }
710Sstevel@tonic-gate | e '*' e = { $$ = ($1 * $3); }
720Sstevel@tonic-gate | e '/' e = { $$ = ($1 / $3); }
730Sstevel@tonic-gate | e '%' e = { $$ = ($1 % $3); }
740Sstevel@tonic-gate | '(' e ')' = { $$ = ($2); }
750Sstevel@tonic-gate | e POWER e = { for ($$ = 1; $3-- > 0; $$ *= $1); }
760Sstevel@tonic-gate | '-' e %prec UMINUS = { $$ = $2-1; $$ = -$2; }
770Sstevel@tonic-gate | '+' e %prec UMINUS = { $$ = $2-1; $$ = $2; }
780Sstevel@tonic-gate | DIGITS = { $$ = evalval; }
790Sstevel@tonic-gate ;
800Sstevel@tonic-gate
810Sstevel@tonic-gate %%
820Sstevel@tonic-gate
830Sstevel@tonic-gate #include "m4.h"
840Sstevel@tonic-gate extern wchar_t *pe;
850Sstevel@tonic-gate static int peek(int c, int r1, int r2);
860Sstevel@tonic-gate
87*291Smike_s int
yylex(void)88*291Smike_s yylex(void)
89*291Smike_s {
900Sstevel@tonic-gate while (*pe == ' ' || *pe == '\t' || *pe == '\n')
910Sstevel@tonic-gate pe++;
920Sstevel@tonic-gate switch (*pe) {
930Sstevel@tonic-gate case '\0':
940Sstevel@tonic-gate case '+':
950Sstevel@tonic-gate case '-':
960Sstevel@tonic-gate case '/':
970Sstevel@tonic-gate case '%':
980Sstevel@tonic-gate case '^':
990Sstevel@tonic-gate case '~':
1000Sstevel@tonic-gate case '(':
1010Sstevel@tonic-gate case ')':
1020Sstevel@tonic-gate return (*pe++);
1030Sstevel@tonic-gate case '*':
1040Sstevel@tonic-gate return (peek('*', POWER, '*'));
1050Sstevel@tonic-gate case '>':
1060Sstevel@tonic-gate return (peek('=', GE, GT));
1070Sstevel@tonic-gate case '<':
1080Sstevel@tonic-gate return (peek('=', LE, LT));
1090Sstevel@tonic-gate case '=':
1100Sstevel@tonic-gate return (peek('=', EQ, EQ));
1110Sstevel@tonic-gate case '|':
1120Sstevel@tonic-gate return (peek('|', OROR, '|'));
1130Sstevel@tonic-gate case '&':
1140Sstevel@tonic-gate return (peek('&', ANDAND, '&'));
1150Sstevel@tonic-gate case '!':
1160Sstevel@tonic-gate return (peek('=', NE, '!'));
1170Sstevel@tonic-gate default: {
118*291Smike_s int base;
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate evalval = 0;
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate if (*pe == '0') {
1230Sstevel@tonic-gate if (*++pe == 'x' || *pe == 'X') {
1240Sstevel@tonic-gate base = 16;
1250Sstevel@tonic-gate ++pe;
1260Sstevel@tonic-gate } else
1270Sstevel@tonic-gate base = 8;
1280Sstevel@tonic-gate } else
1290Sstevel@tonic-gate base = 10;
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate for (;;) {
132*291Smike_s int c, dig;
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate c = *pe;
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate if (is_digit(c))
1370Sstevel@tonic-gate dig = c - '0';
1380Sstevel@tonic-gate else if (c >= 'a' && c <= 'f')
1390Sstevel@tonic-gate dig = c - 'a' + 10;
1400Sstevel@tonic-gate else if (c >= 'A' && c <= 'F')
1410Sstevel@tonic-gate dig = c - 'A' + 10;
1420Sstevel@tonic-gate else
1430Sstevel@tonic-gate break;
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate evalval = evalval*base + dig;
1460Sstevel@tonic-gate ++pe;
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate return (DIGITS);
1490Sstevel@tonic-gate }
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate }
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate static int
peek(int c,int r1,int r2)1540Sstevel@tonic-gate peek(int c, int r1, int r2)
1550Sstevel@tonic-gate {
1560Sstevel@tonic-gate if (*++pe != c)
1570Sstevel@tonic-gate return (r2);
1580Sstevel@tonic-gate ++pe;
1590Sstevel@tonic-gate return (r1);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate
162*291Smike_s /*ARGSUSED*/
1630Sstevel@tonic-gate static void
yyerror(YYCONST char * msg)164*291Smike_s yyerror(YYCONST char *msg)
1650Sstevel@tonic-gate {
1660Sstevel@tonic-gate }
167