%{
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
%}
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
%{
#pragma ident "%Z%%M% %I% %E% SMI"
%}
/* Yacc productions for "expr" command: */
%{
typedef char *yystype;
%}
/* operators listed below in increasing precedence: */
%%
/* a single `expression' is evaluated and printed: */
}
;
| A_STRING
;
%%
#define ESIZE 256
#define RETURN(c) return(c)
#include <regexp.h>
#include <malloc.h>
#include <stdlib.h>
char **Av;
int Ac;
int Argi;
char *ltoa(long l);
char *operator[] = {
"|", "&", "+", "-", "*", "/", "%", ":",
"=", "==", "<", "<=", ">", ">=", "!=",
"match", "substr", "length", "index", "\0" };
int op[] = {
int
yylex(void)
{
char *p;
int i;
if((*p == '(' || *p == ')') && p[1] == '\0' )
return (int)*p;
for(i = 0; *operator[i]; ++i)
return op[i];
yylval = p;
return A_STRING;
}
char *
{
long i;
else
switch(oper) {
case EQ:
i = i==0;
break;
case GT:
i = i>0;
break;
case GEQ:
i = i>=0;
break;
case LT:
i = i<0;
break;
case LEQ:
i = i<=0;
break;
case NEQ:
i = i!=0;
break;
}
return i? "1": "0";
}
{
char *rv;
yyerror("non-numeric argument");
switch(oper) {
case ADD:
break;
case SUBT:
break;
case MULT:
break;
case DIV:
if (i2 == 0)
yyerror("division by zero");
break;
case REM:
if (i2 == 0)
yyerror("division by zero");
break;
}
return rv;
}
{
char *rv;
switch(oper) {
case OR:
rv = "0";
else
else
break;
case AND:
rv = "0";
rv = "0";
else
break;
}
return rv;
}
char *
substr(char *v, char *s, char *w)
{
char *res;
while(--si) if(*v) ++v;
res = v;
while(wi--) if(*v) ++v;
*v = '\0';
return res;
}
char *
index(char *s, char *t)
{
long i, j;
char *rv;
for(i = 0; s[i] ; ++i)
for(j = 0; t[j] ; ++j)
if(s[i]==t[j]) {
return rv;
}
return "0";
}
char *
length(char *s)
{
long i = 0;
char *rv;
while(*s++) ++i;
return rv;
}
char *
match(char *s, char *p)
{
char *rv;
if(nbra) {
}
return rv;
}
int
ematch(char *s, char *p)
{
char *compile();
int num;
if(nbra > 1)
yyerror("Too many '\\('s");
if(nbra == 1) {
p = braslist[0];
}
return(loc2-s);
}
return(0);
}
int
{
char *message;
switch(err) {
case 11:
message = "Range endpoint too large";
break;
case 16:
message = "Bad number";
break;
case 25:
message = "``\\digit'' out of range";
break;
case 36:
message = "Illegal or missing delimiter";
break;
case 41:
message = "No remembered search string";
break;
case 42:
message = "\\( \\) imbalance";
break;
case 43:
message = "Too many \\(";
break;
case 44:
message = "More than 2 numbers given in \\{ \\}";
break;
case 45:
message = "} expected after \\";
break;
case 46:
message = "First number exceeds second in \\{ \\}";
break;
case 49:
message = "[ ] imbalance";
break;
case 50:
message = "Regular expression too long";
break;
default:
message = "Unknown regexp error code!!";
break;
}
/* NOTREACHED */
return (0);
}
int
yyerror(char *s)
{
exit(2);
/* NOTREACHED */
return (0);
}
char *
ltoa(long l)
{
static char str[20];
char *sp;
int i;
int neg;
if(l == 0x80000000L)
return "-2147483648";
neg = 0;
if(l < 0)
++neg, l = -l;
*--sp = '\0';
do {
i = l % 10;
*--sp = '0' + i;
l /= 10;
}
while(l);
if(neg)
*--sp = '-';
return sp;
}
int
{
Argi = 1;
yyparse();
return (0);
}