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 %left '&'
457c478bd9Sstevel@tonic-gate %nonassoc EQ NE
467c478bd9Sstevel@tonic-gate %nonassoc LE GE LT GT
477c478bd9Sstevel@tonic-gate %left LSHIFT RSHIFT
487c478bd9Sstevel@tonic-gate %left '+' '-'
497c478bd9Sstevel@tonic-gate %left '*' '/' '%'
507c478bd9Sstevel@tonic-gate %right POWER
517c478bd9Sstevel@tonic-gate %right '!' '~' UMINUS
527c478bd9Sstevel@tonic-gate %%
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate s : e = { evalval = $1; }
557c478bd9Sstevel@tonic-gate | = { evalval = 0; }
567c478bd9Sstevel@tonic-gate ;
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate e : e OROR e = { $$ = ($1 != 0 || $3 != 0) ? 1 : 0; }
597c478bd9Sstevel@tonic-gate | e ANDAND e = { $$ = ($1 != 0 && $3 != 0) ? 1 : 0; }
607c478bd9Sstevel@tonic-gate | '!' e = { $$ = $2 == 0; }
617c478bd9Sstevel@tonic-gate | '~' e = { $$ = ~$2; }
627c478bd9Sstevel@tonic-gate | e EQ e = { $$ = $1 == $3; }
637c478bd9Sstevel@tonic-gate | e NE e = { $$ = $1 != $3; }
647c478bd9Sstevel@tonic-gate | e GT e = { $$ = $1 > $3; }
657c478bd9Sstevel@tonic-gate | e GE e = { $$ = $1 >= $3; }
667c478bd9Sstevel@tonic-gate | e LT e = { $$ = $1 < $3; }
677c478bd9Sstevel@tonic-gate | e LE e = { $$ = $1 <= $3; }
687c478bd9Sstevel@tonic-gate | e LSHIFT e = { $$ = $1 << $3; }
697c478bd9Sstevel@tonic-gate | e RSHIFT 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 '-' e = { $$ = ($1 - $3); }
757c478bd9Sstevel@tonic-gate | e '*' e = { $$ = ($1 * $3); }
767c478bd9Sstevel@tonic-gate | e '/' e = { $$ = ($1 / $3); }
777c478bd9Sstevel@tonic-gate | e '%' e = { $$ = ($1 % $3); }
787c478bd9Sstevel@tonic-gate | '(' e ')' = { $$ = ($2); }
797c478bd9Sstevel@tonic-gate | e POWER e = { for ($$ = 1; $3-- > 0; $$ *= $1); }
807c478bd9Sstevel@tonic-gate | '-' e %prec UMINUS = { $$ = $2-1; $$ = -$2; }
817c478bd9Sstevel@tonic-gate | '+' e %prec UMINUS = { $$ = $2-1; $$ = $2; }
827c478bd9Sstevel@tonic-gate | DIGITS = { $$ = evalval; }
837c478bd9Sstevel@tonic-gate ;
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate %%
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate #include "m4.h"
887c478bd9Sstevel@tonic-gate extern wchar_t *pe;
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate static int peek(char c, int r1, int r2);
917c478bd9Sstevel@tonic-gate static int peek3(char c1, int rc1, char c2, int rc2, int rc3);
927c478bd9Sstevel@tonic-gate
93*9fb11590Smike_s int
yylex(void)94*9fb11590Smike_s yylex(void)
95*9fb11590Smike_s {
967c478bd9Sstevel@tonic-gate while (*pe == ' ' || *pe == '\t' || *pe == '\n')
977c478bd9Sstevel@tonic-gate pe++;
987c478bd9Sstevel@tonic-gate switch (*pe) {
997c478bd9Sstevel@tonic-gate case '\0':
1007c478bd9Sstevel@tonic-gate case '+':
1017c478bd9Sstevel@tonic-gate case '-':
1027c478bd9Sstevel@tonic-gate case '/':
1037c478bd9Sstevel@tonic-gate case '%':
1047c478bd9Sstevel@tonic-gate case '^':
1057c478bd9Sstevel@tonic-gate case '~':
1067c478bd9Sstevel@tonic-gate case '(':
1077c478bd9Sstevel@tonic-gate case ')':
1087c478bd9Sstevel@tonic-gate return (*pe++);
1097c478bd9Sstevel@tonic-gate case '*':
1107c478bd9Sstevel@tonic-gate return (peek('*', POWER, '*'));
1117c478bd9Sstevel@tonic-gate case '>':
1127c478bd9Sstevel@tonic-gate return (peek3('=', GE, '>', RSHIFT, GT));
1137c478bd9Sstevel@tonic-gate case '<':
1147c478bd9Sstevel@tonic-gate return (peek3('=', LE, '<', LSHIFT, LT));
1157c478bd9Sstevel@tonic-gate case '=':
1167c478bd9Sstevel@tonic-gate return (peek('=', EQ, EQ));
1177c478bd9Sstevel@tonic-gate case '|':
1187c478bd9Sstevel@tonic-gate return (peek('|', OROR, '|'));
1197c478bd9Sstevel@tonic-gate case '&':
1207c478bd9Sstevel@tonic-gate return (peek('&', ANDAND, '&'));
1217c478bd9Sstevel@tonic-gate case '!':
1227c478bd9Sstevel@tonic-gate return (peek('=', NE, '!'));
1237c478bd9Sstevel@tonic-gate default: {
124*9fb11590Smike_s int base;
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate evalval = 0;
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate if (*pe == '0') {
1297c478bd9Sstevel@tonic-gate if (*++pe == 'x' || *pe == 'X') {
1307c478bd9Sstevel@tonic-gate base = 16;
1317c478bd9Sstevel@tonic-gate ++pe;
1327c478bd9Sstevel@tonic-gate } else
1337c478bd9Sstevel@tonic-gate base = 8;
1347c478bd9Sstevel@tonic-gate } else
1357c478bd9Sstevel@tonic-gate base = 10;
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate for (;;) {
138*9fb11590Smike_s int c, dig;
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate c = *pe;
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate if (is_digit(c))
1437c478bd9Sstevel@tonic-gate dig = c - '0';
1447c478bd9Sstevel@tonic-gate else if (c >= 'a' && c <= 'f')
1457c478bd9Sstevel@tonic-gate dig = c - 'a' + 10;
1467c478bd9Sstevel@tonic-gate else if (c >= 'A' && c <= 'F')
1477c478bd9Sstevel@tonic-gate dig = c - 'A' + 10;
1487c478bd9Sstevel@tonic-gate else
1497c478bd9Sstevel@tonic-gate break;
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate evalval = evalval*base + dig;
1527c478bd9Sstevel@tonic-gate ++pe;
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate return (DIGITS);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate static int
peek(char c,int r1,int r2)1607c478bd9Sstevel@tonic-gate peek(char c, int r1, int r2)
1617c478bd9Sstevel@tonic-gate {
1627c478bd9Sstevel@tonic-gate if (*++pe != c)
1637c478bd9Sstevel@tonic-gate return (r2);
1647c478bd9Sstevel@tonic-gate ++pe;
1657c478bd9Sstevel@tonic-gate return (r1);
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate static int
peek3(char c1,int rc1,char c2,int rc2,int rc3)1697c478bd9Sstevel@tonic-gate peek3(char c1, int rc1, char c2, int rc2, int rc3)
1707c478bd9Sstevel@tonic-gate {
1717c478bd9Sstevel@tonic-gate ++pe;
1727c478bd9Sstevel@tonic-gate if (*pe == c1) {
1737c478bd9Sstevel@tonic-gate ++pe;
1747c478bd9Sstevel@tonic-gate return (rc1);
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate if (*pe == c2) {
1777c478bd9Sstevel@tonic-gate ++pe;
1787c478bd9Sstevel@tonic-gate return (rc2);
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate return (rc3);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate
183*9fb11590Smike_s /*ARGSUSED*/
1847c478bd9Sstevel@tonic-gate static void
yyerror(YYCONST char * msg)185*9fb11590Smike_s yyerror(YYCONST char *msg)
1867c478bd9Sstevel@tonic-gate {
1877c478bd9Sstevel@tonic-gate }
188