Home | History | Annotate | Line # | Download | only in sh
      1 /*	$NetBSD: arith_tokens.h,v 1.3 2017/07/24 13:21:14 kre Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  * Copyright (c) 2007
      7  *	Herbert Xu <herbert (at) gondor.apana.org.au>.  All rights reserved.
      8  *
      9  * This code is derived from software contributed to Berkeley by
     10  * Kenneth Almquist.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  * From FreeBSD who obtained it from dash (modified both times.)
     37  */
     38 
     39 /*
     40  * Tokens returned from arith_token()
     41  *
     42  * Caution, values are not arbitrary.
     43  */
     44 
     45 #define	ARITH_BAD	0
     46 
     47 #define	ARITH_ASS	1
     48 
     49 #define	ARITH_OR	2
     50 #define	ARITH_AND	3
     51 #define	ARITH_NUM	5
     52 #define	ARITH_VAR	6
     53 #define	ARITH_NOT	7
     54 
     55 #define	ARITH_BINOP_MIN	8
     56 
     57 #define	ARITH_LE	8
     58 #define	ARITH_GE	9
     59 #define	ARITH_LT	10
     60 #define	ARITH_GT	11
     61 #define	ARITH_EQ	12	/* Must be ARITH_ASS + ARITH_ASS_GAP */
     62 
     63 #define	ARITH_ASS_BASE	13
     64 
     65 #define	ARITH_REM	13
     66 #define	ARITH_BAND	14
     67 #define	ARITH_LSHIFT	15
     68 #define	ARITH_RSHIFT	16
     69 #define	ARITH_MUL	17
     70 #define	ARITH_ADD	18
     71 #define	ARITH_BOR	19
     72 #define	ARITH_SUB	20
     73 #define	ARITH_BXOR	21
     74 #define	ARITH_DIV	22
     75 
     76 #define	ARITH_NE	23
     77 
     78 #define	ARITH_BINOP_MAX	24
     79 
     80 #define	ARITH_ASS_MIN	ARITH_BINOP_MAX
     81 #define	ARITH_ASS_GAP	(ARITH_ASS_MIN - ARITH_ASS_BASE)
     82 
     83 #define	ARITH_REMASS	(ARITH_ASS_GAP + ARITH_REM)
     84 #define	ARITH_BANDASS	(ARITH_ASS_GAP + ARITH_BAND)
     85 #define	ARITH_LSHIFTASS	(ARITH_ASS_GAP + ARITH_LSHIFT)
     86 #define	ARITH_RSHIFTASS	(ARITH_ASS_GAP + ARITH_RSHIFT)
     87 #define	ARITH_MULASS	(ARITH_ASS_GAP + ARITH_MUL)
     88 #define	ARITH_ADDASS	(ARITH_ASS_GAP + ARITH_ADD)
     89 #define	ARITH_BORASS	(ARITH_ASS_GAP + ARITH_BOR)
     90 #define	ARITH_SUBASS	(ARITH_ASS_GAP + ARITH_SUB)
     91 #define	ARITH_BXORASS	(ARITH_ASS_GAP + ARITH_BXOR)
     92 #define	ARITH_DIVASS	(ARITH_ASS_GAP + ARITH_BXOR)
     93 
     94 #define	ARITH_ASS_MAX	34
     95 
     96 #define	ARITH_LPAREN	34
     97 #define	ARITH_RPAREN	35
     98 #define	ARITH_BNOT	36
     99 #define	ARITH_QMARK	37
    100 #define	ARITH_COLON	38
    101 #define	ARITH_INCR	39
    102 #define	ARITH_DECR	40
    103 #define	ARITH_COMMA	41
    104 
    105 /*
    106  * Globals shared between arith parser, and lexer
    107  */
    108 
    109 extern const char *arith_buf;
    110 
    111 union a_token_val {
    112 	intmax_t val;
    113 	char *name;
    114 };
    115 
    116 extern union a_token_val a_t_val;
    117 
    118 extern int arith_lno, arith_var_lno;
    119 
    120 int arith_token(void);
    121