/*
   littlec.h - Declarations for Little C interpreter
*/

#ifndef _LITTLEC_H
#define _LITTLEC_H

/* Interpreter limits */
#define NUM_FUNC        100
#define NUM_GLOBAL_VARS 100
#define NUM_LOCAL_VARS  200
#define NUM_BLOCK       100
#define ID_LEN          31
#define FUNC_CALLS      31
#define NUM_PARAMS      31
#define PROG_SIZE       20000
#define TOK_SIZE        80
#define STRING_SIZE     80
#define LOOP_NEST       31

/* Enumerations used by interpreter */

enum tok_types {DELIMITER, IDENTIFIER, NUMBER, KEYWORD,
                TEMP, STRING, BLOCK};

/* add additional C keyword tokens here */
enum tokens {ARG, CHAR, INT, IF, ELSE, FOR, DO, WHILE,
             SWITCH, RETURN, EOL, FINISHED, END};

/* add additional double operators here (such as ->) */
enum double_ops {LT=1, LE, GT, GE, EQ, NE};

/* These are the constants used to call sntx_err() when
   a syntax error occurs. Add more if you like.
   NOTE: SYNTAX is a generic error message used when
   nothing else seems appropriate.
*/
enum error_msg
     {SYNTAX, UNBAL_PARENS, NO_EXP, EQUALS_EXPECTED,
      NOT_VAR, PARAM_ERR, SEMI_EXPECTED,
      UNBAL_BRACES, FUNC_UNDEF, TYPE_EXPECTED,
      NEST_FUNC, RET_NOCALL, PAREN_EXPECTED,
      WHILE_EXPECTED, QUOTE_EXPECTED, NOT_TEMP,
      TOO_MANY_LVARS, DIV_BY_ZERO};

/* Structures used by interpreter */

/* Info associated with global variables */
struct var_type {
  char var_name[ID_LEN];
  int v_type;
  int value;
};

struct func_type {
  char func_name[ID_LEN];
  int ret_type; 
  char *loc;  /* location of entry point in file */
};

/* Keyword lookup structure */
struct commands {
  char command[20];
  char tok;
};

struct intern_func_type {
  char *f_name; /* function name */
  int (*p)();   /* pointer to the function */
};

/* Functions for parsing function arguments */
int get_token(void);
void get_first_token(void), get_last_token(void);
void sntx_err(int error), eval_exp(int *result), putback(void);

/* "Standard library" functions are declared here so
   they can be put into the internal function table that
   follows.
 */
int call_getche(void), call_putch(void);
int call_puts(void), print(void), getnum(void);
int call_sleep(void);

#if defined(BOARD)
#include "libbd.h"
#else
/* Internal funtion table */
#define INTERN_FUNC_TABLE {"getche", call_getche}, \
    {"putch", call_putch}, \
    {"puts", call_puts}, \
    {"print", print}, \
    {"getnum", getnum}, \
    {"sleep", call_sleep},

#endif

#endif /* _LITTLEC_H */
