/* @(#)Copyright (c), 1987, 1996 StatSci, Inc.  All rights reserved. */
/* @(#)S_tokens.h version 3.5 created 5/12/96 */
/***
   NAME S_tokens
   PURPOSE
     Split of part of S.h that deals with token types of input. Note that
     this file is "public" (e.g. included via S+API public header files),
     so many tokens have the prefix S_ added to them.  To get the previous
     unprefixed token names, define _S_private_symbols.
   NOTES
     -Need to include a y_tab.h file for some of this to be useful.
***/
#ifndef S_tokensINCLUDED
#define S_tokensINCLUDED 1

/* Pre-requisite includes go here. */
#include <ansi_things.h>
SCCS_ID_C(S_tokensDotH,@(#)S_tokens.h 3.5 last edit 5/12/96 StatSci)

#ifdef _S_private_symbols  /*(*/
/* NOTE: These symbols are "normally" defined in a y_tab.h file.  The
         unprefixed (with S_MODE_) versions come from the y_tab.h file
         generated during the S build process.  The prefixed versions
         are present (at least) in the S+API Sapi_y_tab.h header file
         generated from the S version. */
#define S_MODE_NAME NAME
#define S_MODE_LVALUE LVALUE
#define S_MODE_PARSE PARSE
#define S_MODE_UNKNOWN UNKNOWN

/* some compilers <math.h> do '#define complex _complex' when not strict
   ANSI in order to use _complex in strict ANSI mode. */
#undef complex
#define S_complex complex

#ifndef S_atomic_types    /*(*/
#define S_atomic_types atomic_types
#endif /* ) S_atomic_types */

#ifndef S_token_info    /*(*/
#define S_token_info token_info
#endif /* ) S_atomic_types */

#endif /* ) _S_private_symbols */

#include <S_types.h>

#ifdef S_tokensDEFINE
#define INIT(x) = x
#define vextern
#else
#define INIT(x)
#define vextern extern
#endif /* S_tokensDEFINE */

#undef TRUE
#undef FALSE
#undef NULL

#define TRUE 1
#define FALSE 0
#define NULL 0
#define NULL_STRING (char *)NULL
#define IS_NULL_STRING(p)	((p)==NULL_STRING || *(p)=='\0')

/*
 * The atomic type definitions assume that yacc does not
 * generate these values as token types.  See y.tab.h
 */

#define S_MODE_NULL 0   /* added this (like S verion 4) -- mclark */
#define S_NULL_MODE S_MODE_NULL
#define S_MODE_LGL 1
#define S_MODE_INT 2
#define S_MODE_REAL 3
#define S_MODE_DOUBLE 4
#define S_MODE_CHAR 5
#define S_MODE_LIST 6
#define S_MODE_COMPLEX 7
#define S_MODE_ANY 11
#define S_MODE_STRUCTURE 21
#define S_MODE_MAX_ATOMIC 20

/*
 * macro to identify an atomic type: this depends slightly on
 * the implementation of yacc; viz, that yacc generates token
 * types in increasing numerical value
 */
#define S_atomic_type(t) ((t) <= S_MODE_MAX_ATOMIC ? S_atomic_types[t] : FALSE)

#undef PI
#define PI	3.1415926535897932384626433832795028841971693993751
#define DEG2RD	0.01745329251994329576923690768488612713442871888541

/*
 * markers for the range of token types:
 * must have y.tab.h included to use;
 * just not ENTRY_TYPE
 */
#define S_FIRST_TOKEN		S_MODE_NAME
#define S_LAST_TOKEN		S_MODE_LVALUE
#define S_FREED_TYPE		S_MODE_UNKNOWN
#define S_LANGUAGE_TYPE(mode)	(mode>=S_FIRST_TOKEN &&\
				 mode<=S_LAST_TOKEN &&\
				(S_token_info[mode-S_FIRST_TOKEN]&1))
#define S_NOT_RECURSIVE(mode)	(mode<S_FIRST_TOKEN\
				?(mode!=S_MODE_LIST && mode!=S_MODE_STRUCTURE)\
				:(mode<=S_LAST_TOKEN && (S_token_info[mode-S_FIRST_TOKEN]&2)))

#define S_MODE_EXPRESSION S_MODE_PARSE

#undef INIT
#undef vextern

/* Initialization taken from $QPE/pars_util.c */
#ifdef pars_utilDEFINE
int S_token_info[] = {
    1 | 2 | 0,	/* NAME */
    1 | 2 | 0,	/* STRING */
    1 | 2 | 0,	/* LITERAL */
    1 | 0 | 4,	/* COMPILED */
    1 | 0 | 0,	/* LPAR */
    1 | 2 | 0,	/* RPAR */
    1 | 0 | 0,	/* LBRACK */
    1 | 2 | 0,	/* RBRACK */
    1 | 0 | 0,	/* LBRACE */
    1 | 2 | 0,	/* RBRACE */
    1 | 2 | 0,	/* COMMA */
    1 | 2 | 0,	/* EQUAL */
    1 | 2 | 0,	/* NOT */
    1 | 2 | 0,	/* COLON */
    1 | 2 | 0,	/* ADDOP */
    1 | 2 | 0,	/* MULOP */
    1 | 2 | 0,	/* LIST_SEP */
    1 | 2 | 0,	/* UARROW */
    1 | 2 | 0,	/* UMINUS */
    1 | 2 | 0,	/* DOLLAR */
    1 | 2 | 0,	/* LOGOP */
    1 | 2 | 0,	/* ANDOR */
    1 | 0 | 4,	/* LARROW */
    1 | 2 | 0,	/* RARROW */
    1 | 2 | 0,	/* SPOP */
    1 | 2 | 0,	/* TBLANK */
    1 | 0 | 4,	/* REPEAT */
    1 | 0 | 4,	/* IF */
    1 | 0 | 4,	/* ELSE */
    1 | 2 | 0,	/* BREAK */
    1 | 2 | 0,	/* SEMI */
    1 | 2 | 0,	/* NEXT */
    1 | 0 | 4,	/* WHILE */
    1 | 0 | 4,	/* FOR */
    1 | 2 | 0,	/* IN */
    1 | 2 | 0,	/* REC_RETURN */
    1 | 0 | 4,	/* RETURN */
    1 | 0 | 4,	/* ARGUMENT */
    1 | 2 | 0,	/* SYSTEM */
    1 | 2 | 0,	/* END_OF_FILE */
    1 | 0 | 0,	/* PARSE */
    1 | 0 | 0,	/* SYS_FUN */
    0 | 2 | 0,	/* MISSING */
    1 | 0 | 4,	/* FUN_CALL */
    0 | 0 | 4,	/* FUN_DEF */
    1 | 2 | 0,	/* QUESTION */
    1 | 2 | 0,	/* UNBALANCED */
    1 | 0 | 4,	/* DOUBLE_LBRACK */
    0 | 2 | 0,	/* UNKNOWN */
    1 | 2 | 0,	/* DOUBLE_RBRACK */
    1 | 2 | 0,	/* QUIT */
    1 | 2 | 0,	/* CONTINUE */
    1 | 0 | 0,	/* COMMENT_EXPR */
    1 | 2 | 0,	/* ENTRY_TYPE */
    1 | 0 | 4,	/* FLEX_CALL */
    1 | 0 | 4,	/* DBLEARROW */
    0 | 0 | 0,	/* GRAPHICS */
    1 | 0 | 0,	/* ARG_LVALUE */
    1 | 0 | 4,	/* INTERNAL */
    1 | 0 | 4,	/* S_FUN_CALL */
    1 | 0 | 4,	/* S_DATA */
    1 | 0 | 0,	/* SIMILAR */
    1 | 0 | 0,	/* COMMENT */
    1 | 0 | 4,	/* LEFT_COMMENT */
    1 | 0 | 4,	/* FRAME */
    1 | 0 | 4,	/* LVALUE */
    -1};
#else
extern int S_token_info[];
#endif /* pars_utilDEFINE */

/* Initialization taken from $QPE/c_support.c */
#ifdef c_supportDEFINE
int S_atomic_types[S_MODE_MAX_ATOMIC+1] = {TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,TRUE};
#else
extern int S_atomic_types[];
#endif /* c_supportDEFINE */

#ifdef _S_private_symbols  /*(*/
#define NULL_MODE S_MODE_NULL
#define LGL S_MODE_LGL
#define INT S_MODE_INT
#define REAL S_MODE_REAL
#define DOUBLE S_MODE_DOUBLE
#define CHAR S_MODE_CHAR
#define LIST S_MODE_LIST
#define COMPLEX S_MODE_COMPLEX
#define ANY S_MODE_ANY
#define STRUCTURE S_MODE_STRUCTURE
#define MAX_ATOMIC S_MODE_MAX_ATOMIC

#ifndef atomic_type    /*(*/
#define atomic_type(t) S_atomic_type(t)
#endif /* ) atomic_type */

#define FIRST_TOKEN S_FIRST_TOKEN
#define LAST_TOKEN S_LAST_TOKEN
#define FREED_TYPE S_FREED_TYPE
#define LANGUAGE_TYPE(mode) S_LANGUAGE_TYPE(mode)
#define NOT_RECURSIVE(mode) S_NOT_RECURSIVE(mode)

#define EXPRESSION S_MODE_EXPRESSION
#endif /* ) _S_private_symbols */

#endif /* S_tokensINCLUDED */
