TwiceAsNice  2019-02-18
Classes | Macros | Enumerations | Functions | Variables
compiler.c File Reference
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for compiler.c:

Classes

struct  Var
 

Macros

#define LPAREN   255
 
#define RPAREN   254
 
#define COMMA   253
 
#define ERR   (-1)
 
#define UNI_PREC   7 /* unary ops have highest precedence */
 
#define MAX_STACK   32
 
#define MAX_PROG   32
 
#define OP_SHIFT   8
 
#define OP_MASK   0xff
 
#define MAX_OPX   64 /* max number of operands */
 
#define MAXFLDLEN   64 /* longest allowed operand name */
 

Enumerations

enum  {
  HALT, ADD, SUB, MULT,
  DIV, AND, OR, GT,
  GE, EQ, NE, LT,
  LE, NEG, NOT, CONST,
  VAR, ABS, FLOOR, SIN,
  COS, TAN, ASIN, ACOS,
  ATAN, PITOK, DEGRAD, RADDEG,
  LOG, LOG10, EXP, SQRT,
  POW, ATAN2
}
 

Functions

static int next_token (void)
 
static int chk_funcs (void)
 
static void skip_double (void)
 
static int compile (int prec)
 
static int execute (double *result)
 
static int parse_fieldname (char name[], int len)
 
int compileExpr (char *exp, char *errbuf)
 
int evalExpr (double *vp, char *errbuf)
 
int setOperand (char *name, double valu)
 
int allOperandsSet ()
 
int getAllOperands (char ***ops)
 
int getSetOperands (char ***ops)
 
int getUnsetOperands (char ***ops)
 
void compiler_log (char *name, double value)
 
static int parse_fieldname (name, int len)
 

Variables

static int precedence [] = { 0, 5, 5, 6, 6, 2, 1, 4, 4, 3, 3, 4, 4 }
 
static double stack [MAX_STACK]
 
static double * sp
 
static int program [MAX_PROG]
 
static int * pc
 
static Var vars [MAX_OPX]
 
static int nvars
 
static double consts [MAX_OPX]
 
static int nconsts
 
static int parens_nest
 
static char * err_msg
 
static char * cexpr
 
static char * lcexpr
 

Macro Definition Documentation

◆ COMMA

#define COMMA   253

◆ ERR

#define ERR   (-1)

◆ LPAREN

#define LPAREN   255

◆ MAX_OPX

#define MAX_OPX   64 /* max number of operands */

◆ MAX_PROG

#define MAX_PROG   32

◆ MAX_STACK

#define MAX_STACK   32

◆ MAXFLDLEN

#define MAXFLDLEN   64 /* longest allowed operand name */

◆ OP_MASK

#define OP_MASK   0xff

◆ OP_SHIFT

#define OP_SHIFT   8

◆ RPAREN

#define RPAREN   254

◆ UNI_PREC

#define UNI_PREC   7 /* unary ops have highest precedence */

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
HALT 
ADD 
SUB 
MULT 
DIV 
AND 
OR 
GT 
GE 
EQ 
NE 
LT 
LE 
NEG 
NOT 
CONST 
VAR 
ABS 
FLOOR 
SIN 
COS 
TAN 
ASIN 
ACOS 
ATAN 
PITOK 
DEGRAD 
RADDEG 
LOG 
LOG10 
EXP 
SQRT 
POW 
ATAN2 

Function Documentation

◆ allOperandsSet()

int allOperandsSet ( )

◆ chk_funcs()

static int chk_funcs ( void  )
static

◆ compile()

static int compile ( int  prec)
static

◆ compileExpr()

int compileExpr ( char *  exp,
char *  errbuf 
)

◆ compiler_log()

void compiler_log ( char *  name,
double  value 
)

◆ evalExpr()

int evalExpr ( double *  vp,
char *  errbuf 
)

◆ execute()

static int execute ( double *  result)
static

◆ getAllOperands()

int getAllOperands ( char ***  ops)

◆ getSetOperands()

int getSetOperands ( char ***  ops)

◆ getUnsetOperands()

int getUnsetOperands ( char ***  ops)

◆ next_token()

static int next_token ( void  )
static

◆ parse_fieldname() [1/2]

static int parse_fieldname ( char  name[],
int  len 
)
static

◆ parse_fieldname() [2/2]

static int parse_fieldname ( name  ,
int  len 
)
static

◆ setOperand()

int setOperand ( char *  name,
double  valu 
)

◆ skip_double()

static void skip_double ( void  )
static

Variable Documentation

◆ cexpr

char* cexpr
static

◆ consts

double consts[MAX_OPX]
static

◆ err_msg

char* err_msg
static

◆ lcexpr

char * lcexpr
static

◆ nconsts

int nconsts
static

◆ nvars

int nvars
static

◆ parens_nest

int parens_nest
static

◆ pc

int * pc
static

◆ precedence

int precedence[] = { 0, 5, 5, 6, 6, 2, 1, 4, 4, 3, 3, 4, 4 }
static

◆ program

int program[MAX_PROG]
static

◆ sp

double * sp
static

◆ stack

double stack[MAX_STACK]
static

◆ vars

Var vars[MAX_OPX]
static