17c478bd9Sstevel@tonic-gate %{
27c478bd9Sstevel@tonic-gate /*
37c478bd9Sstevel@tonic-gate * CDDL HEADER START
47c478bd9Sstevel@tonic-gate *
57c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
67c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
77c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
87c478bd9Sstevel@tonic-gate * with the License.
97c478bd9Sstevel@tonic-gate *
107c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
117c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
127c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
137c478bd9Sstevel@tonic-gate * and limitations under the License.
147c478bd9Sstevel@tonic-gate *
157c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
167c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
177c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
187c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
197c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
207c478bd9Sstevel@tonic-gate *
217c478bd9Sstevel@tonic-gate * CDDL HEADER END
227c478bd9Sstevel@tonic-gate */
237c478bd9Sstevel@tonic-gate %}
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
26*9fb11590Smike_s * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
277c478bd9Sstevel@tonic-gate * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
30*9fb11590Smike_s /* Copyright (c) 1988 AT&T */
31*9fb11590Smike_s /* All Rights Reserved */
32*9fb11590Smike_s
337c478bd9Sstevel@tonic-gate %{
347c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
357c478bd9Sstevel@tonic-gate extern long evalval;
367c478bd9Sstevel@tonic-gate #define YYSTYPE long
377c478bd9Sstevel@tonic-gate %}
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate %term DIGITS
407c478bd9Sstevel@tonic-gate %left OROR
417c478bd9Sstevel@tonic-gate %left ANDAND
427c478bd9Sstevel@tonic-gate %left '|' '^'
437c478bd9Sstevel@tonic-gate %left '&'
447c478bd9Sstevel@tonic-gate %right '!' '~'
457c478bd9Sstevel@tonic-gate %nonassoc GT GE LT LE NE EQ
467c478bd9Sstevel@tonic-gate %left '+' '-'
477c478bd9Sstevel@tonic-gate %left '*' '/' '%'
487c478bd9Sstevel@tonic-gate %right POWER
497c478bd9Sstevel@tonic-gate %right UMINUS
507c478bd9Sstevel@tonic-gate %%
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate s : e = { evalval = $1; }
537c478bd9Sstevel@tonic-gate | = { evalval = 0; }
547c478bd9Sstevel@tonic-gate ;
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate e : e OROR e = { $$ = ($1 != 0 || $3 != 0) ? 1 : 0; }
577c478bd9Sstevel@tonic-gate | e ANDAND e = { $$ = ($1 != 0 && $3 != 0) ? 1 : 0; }
587c478bd9Sstevel@tonic-gate | '!' e = { $$ = $2 == 0; }
597c478bd9Sstevel@tonic-gate | '~' e = { $$ = ~$2; }
607c478bd9Sstevel@tonic-gate | e EQ e = { $$ = $1 == $3; }
617c478bd9Sstevel@tonic-gate | e NE e = { $$ = $1 != $3; }
627c478bd9Sstevel@tonic-gate | e GT e = { $$ = $1 > $3; }
637c478bd9Sstevel@tonic-gate | e GE e = { $$ = $1 >= $3; }
647c478bd9Sstevel@tonic-gate | e LT e = { $$ = $1 < $3; }
657c478bd9Sstevel@tonic-gate | e LE e = { $$ = $1 <= $3; }
667c478bd9Sstevel@tonic-gate | e '|' e = { $$ = ($1 | $3); }
677c478bd9Sstevel@tonic-gate | e '&' e = { $$ = ($1 & $3); }
687c478bd9Sstevel@tonic-gate | e '^' e = { $$ = ($1 ^ $3); }
697c478bd9Sstevel@tonic-gate | e '+' e = { $$ = ($1 + $3); }
707c478bd9Sstevel@tonic-gate | e '-' e = { $$ = ($1 - $3); }
717c478bd9Sstevel@tonic-gate | e '*' e = { $$ = ($1 * $3); }
727c478bd9Sstevel@tonic-gate | e '/' e = { $$ = ($1 / $3); }
737c478bd9Sstevel@tonic-gate | e '%' e = { $$ = ($1 % $3); }
747c478bd9Sstevel@tonic-gate | '(' e ')' = { $$ = ($2); }
757c478bd9Sstevel@tonic-gate | e POWER e = { for ($$ = 1; $3-- > 0; $$ *= $1); }
767c478bd9Sstevel@tonic-gate | '-' e %prec UMINUS = { $$ = $2-1; $$ = -$2; }
777c478bd9Sstevel@tonic-gate | '+' e %prec UMINUS = { $$ = $2-1; $$ = $2; }
787c478bd9Sstevel@tonic-gate | DIGITS = { $$ = evalval; }
797c478bd9Sstevel@tonic-gate ;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate %%
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate #include "m4.h"
847c478bd9Sstevel@tonic-gate extern wchar_t *pe;
857c478bd9Sstevel@tonic-gate static int peek(int c, int r1, int r2);
867c478bd9Sstevel@tonic-gate
87*9fb11590Smike_s int
yylex(void)88*9fb11590Smike_s yylex(void)
89*9fb11590Smike_s {
907c478bd9Sstevel@tonic-gate while (*pe == ' ' || *pe == '\t' || *pe == '\n')
917c478bd9Sstevel@tonic-gate pe++;
927c478bd9Sstevel@tonic-gate switch (*pe) {
937c478bd9Sstevel@tonic-gate case '\0':
947c478bd9Sstevel@tonic-gate case '+':
957c478bd9Sstevel@tonic-gate case '-':
967c478bd9Sstevel@tonic-gate case '/':
977c478bd9Sstevel@tonic-gate case '%':
987c478bd9Sstevel@tonic-gate case '^':
997c478bd9Sstevel@tonic-gate case '~':
1007c478bd9Sstevel@tonic-gate case '(':
1017c478bd9Sstevel@tonic-gate case ')':
1027c478bd9Sstevel@tonic-gate return (*pe++);
1037c478bd9Sstevel@tonic-gate case '*':
1047c478bd9Sstevel@tonic-gate return (peek('*', POWER, '*'));
1057c478bd9Sstevel@tonic-gate case '>':
1067c478bd9Sstevel@tonic-gate return (peek('=', GE, GT));
1077c478bd9Sstevel@tonic-gate case '<':
1087c478bd9Sstevel@tonic-gate return (peek('=', LE, LT));
1097c478bd9Sstevel@tonic-gate case '=':
1107c478bd9Sstevel@tonic-gate return (peek('=', EQ, EQ));
1117c478bd9Sstevel@tonic-gate case '|':
1127c478bd9Sstevel@tonic-gate return (peek('|', OROR, '|'));
1137c478bd9Sstevel@tonic-gate case '&':
1147c478bd9Sstevel@tonic-gate return (peek('&', ANDAND, '&'));
1157c478bd9Sstevel@tonic-gate case '!':
1167c478bd9Sstevel@tonic-gate return (peek('=', NE, '!'));
1177c478bd9Sstevel@tonic-gate default: {
118*9fb11590Smike_s int base;
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate evalval = 0;
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate if (*pe == '0') {
1237c478bd9Sstevel@tonic-gate if (*++pe == 'x' || *pe == 'X') {
1247c478bd9Sstevel@tonic-gate base = 16;
1257c478bd9Sstevel@tonic-gate ++pe;
1267c478bd9Sstevel@tonic-gate } else
1277c478bd9Sstevel@tonic-gate base = 8;
1287c478bd9Sstevel@tonic-gate } else
1297c478bd9Sstevel@tonic-gate base = 10;
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate for (;;) {
132*9fb11590Smike_s int c, dig;
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate c = *pe;
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate if (is_digit(c))
1377c478bd9Sstevel@tonic-gate dig = c - '0';
1387c478bd9Sstevel@tonic-gate else if (c >= 'a' && c <= 'f')
1397c478bd9Sstevel@tonic-gate dig = c - 'a' + 10;
1407c478bd9Sstevel@tonic-gate else if (c >= 'A' && c <= 'F')
1417c478bd9Sstevel@tonic-gate dig = c - 'A' + 10;
1427c478bd9Sstevel@tonic-gate else
1437c478bd9Sstevel@tonic-gate break;
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate evalval = evalval*base + dig;
1467c478bd9Sstevel@tonic-gate ++pe;
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate return (DIGITS);
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate static int
peek(int c,int r1,int r2)1547c478bd9Sstevel@tonic-gate peek(int c, int r1, int r2)
1557c478bd9Sstevel@tonic-gate {
1567c478bd9Sstevel@tonic-gate if (*++pe != c)
1577c478bd9Sstevel@tonic-gate return (r2);
1587c478bd9Sstevel@tonic-gate ++pe;
1597c478bd9Sstevel@tonic-gate return (r1);
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate
162*9fb11590Smike_s /*ARGSUSED*/
1637c478bd9Sstevel@tonic-gate static void
yyerror(YYCONST char * msg)164*9fb11590Smike_s yyerror(YYCONST char *msg)
1657c478bd9Sstevel@tonic-gate {
1667c478bd9Sstevel@tonic-gate }
167