2019-07-22 20:32:33 +00:00
|
|
|
#ifndef SCANNER_H
|
|
|
|
#define SCANNER_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2019-07-27 04:14:26 +00:00
|
|
|
#include <stdbool.h>
|
2019-07-22 20:32:33 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
EMPTY
|
|
|
|
#ifndef __cplusplus
|
|
|
|
, STRING, FLOAT, INT, OPERATOR, LIDENT, FIDENT, LOCATION, EEK
|
|
|
|
#endif
|
|
|
|
} Type;
|
|
|
|
|
2019-07-25 13:05:24 +00:00
|
|
|
extern const char *Type_Name[];
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
typedef enum { PLUS, MINUS, MUL, DIV, OP, CP, COMMA, LT, LE, GE, GT, ISEQUAL, ABOUTEQ, NE, POW, MOD } Operator;
|
|
|
|
|
2019-07-27 04:14:26 +00:00
|
|
|
typedef int Location[3]; /* NOTE: Locations are passed by REFERENCE not value */
|
|
|
|
/* I.e., to accapt a Location argument, declare the parameter to be of type
|
|
|
|
const Location*
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef enum { X=0, Y=1, Z=2, HYPER} Dimensions;
|
|
|
|
|
|
|
|
#define OLOCATION(loc) ((void)memset(loc, 0, sizeof(Location)))
|
|
|
|
#define IN_OCTANT(loc) (loc[X]>=0 && loc[Y]>=0 && loc[Z]>=0)
|
|
|
|
#define LOCATION_GETS(la,lb) ((void)memcpy(la, lb, sizeof(Location)))
|
|
|
|
#define SAME_LOC(la,lb) (memcmp(la,lb,sizeof(Location))==0)
|
|
|
|
#define LOCATION_SUB(la,lb) (la)[X]-=(lb)[X]; (la)[Y]-=(lb)[Y]; (la)[Z]-=(lb)[Z];
|
|
|
|
|
|
|
|
bool loc_in_box(const Location test,
|
|
|
|
const Location b, const Location c);
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Type type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
char *string;
|
|
|
|
double flt;
|
|
|
|
long integer;
|
|
|
|
Operator op;
|
|
|
|
char *lident;
|
|
|
|
int fident;
|
2019-07-27 04:14:26 +00:00
|
|
|
Location location;
|
2019-07-22 20:32:33 +00:00
|
|
|
char *err;
|
|
|
|
} u;
|
|
|
|
} Token;
|
|
|
|
|
Prevent phantom values when clocking, resetting, and clocking again
In the end it turned out that the cause of the phantom values was
short-cutting in getvalue() when the contents of a cell were empty,
preventing the update of the internal cache of the value of the cell.
However, tracking this down (and getting the associated memory management
correct) necessitated implementing a debugging mode in which I could
dump the internal states of cells and print various other stuff to standard
output. It also involved understanding the meaning of various pointers in
the code, in the process of which I renamed some commonly used macros,
particularly the former SHEET(s,x,y,z) which was not returning a Sheet at
all but rather a pointer to a Cell. So this macro is now called CELL_AT. I
also replaced several very repeatedly used patterns of checking the validity
of locations and pointers with macros, now defined in sheet.h.
Therefore, unfortunately the (relatively small in the end) bugfix for this
major issue is entangled with numerous textual changes to the code made
in tracking it down.
Fixes #18.
Closes #19.
2019-07-24 17:47:39 +00:00
|
|
|
#define NULLTOKEN ((Token*)0)
|
|
|
|
#define EMPTY_TVEC ((Token**)0)
|
|
|
|
|
2019-07-22 20:32:33 +00:00
|
|
|
int identcode(const char *s, size_t len);
|
|
|
|
Token **scan(const char **s);
|
Prevent phantom values when clocking, resetting, and clocking again
In the end it turned out that the cause of the phantom values was
short-cutting in getvalue() when the contents of a cell were empty,
preventing the update of the internal cache of the value of the cell.
However, tracking this down (and getting the associated memory management
correct) necessitated implementing a debugging mode in which I could
dump the internal states of cells and print various other stuff to standard
output. It also involved understanding the meaning of various pointers in
the code, in the process of which I renamed some commonly used macros,
particularly the former SHEET(s,x,y,z) which was not returning a Sheet at
all but rather a pointer to a Cell. So this macro is now called CELL_AT. I
also replaced several very repeatedly used patterns of checking the validity
of locations and pointers with macros, now defined in sheet.h.
Therefore, unfortunately the (relatively small in the end) bugfix for this
major issue is entangled with numerous textual changes to the code made
in tracking it down.
Fixes #18.
Closes #19.
2019-07-24 17:47:39 +00:00
|
|
|
size_t printtok(char* dest, size_t size, size_t field_width,
|
|
|
|
int quote_strings, int use_scientific,
|
|
|
|
int precision, int verbose_error, Token *tok);
|
2019-07-22 20:32:33 +00:00
|
|
|
void print(char *s, size_t size, size_t chars, int quote, int scientific, int precision, Token **n);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|