picoc/picoc.h

171 lines
3.3 KiB
C
Raw Normal View History

#ifndef PICOC_H
#define PICOC_H
#include <stdarg.h>
/* configurable options */
#define USE_MALLOC
#define GLOBAL_TABLE_SIZE 199
#define LARGE_INT_POWER_OF_TEN 1000000000 /* the largest power of ten which fits in an int on this architecture */
/* handy definitions */
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif
#ifndef min
#define min(x,y) (((x)<(y))?(x):(y))
#endif
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
/* lexical tokens */
enum LexToken
{
TokenNone,
TokenEOF,
TokenIdentifier,
TokenIntegerConstant,
TokenStringConstant,
TokenCharacterConstant,
TokenType,
TokenOpenBracket,
TokenCloseBracket,
TokenAssign,
TokenPlus,
TokenMinus,
TokenAsterisk,
TokenSlash,
TokenEquality,
TokenLessThan,
TokenGreaterThan,
TokenLessEqual,
TokenGreaterEqual,
TokenSemicolon,
TokenArrow,
TokenAmpersand,
TokenLeftBrace,
TokenRightBrace,
TokenLeftAngleBracket,
TokenRightAngleBracket,
TokenLogicalAnd,
TokenLogicalOr,
TokenArithmeticOr,
TokenArithmeticExor,
TokenUnaryExor,
TokenUnaryNot,
TokenComma,
TokenDot,
TokenAddAssign,
TokenSubtractAssign,
TokenIncrement,
TokenDecrement,
TokenIntType,
TokenCharType,
TokenVoidType,
TokenDo,
TokenElse,
TokenFor,
TokenIf,
TokenWhile
};
/* string type so we can use source file strings */
typedef struct _Str
{
int Len;
const char *Str;
} Str;
/* hash table data structure */
struct TableEntry
{
Str Key;
void *Value;
};
struct Table
{
const char *Name;
short Size;
struct TableEntry *HashTable;
};
/* function definition - really just where it is in the source file */
struct FuncDef
{
Str Source;
Str FileName;
int StartLine;
};
enum ValueType
{
TypeInt,
TypeString
};
union AnyValue
{
int Integer;
Str String;
};
struct Value
{
enum ValueType Typ;
union AnyValue Val;
};
/* lexer state - so we can lex nested files */
struct LexState
{
int Line;
const char *Pos;
const char *End;
const Str *FileName;
union AnyValue Value;
};
/* str.c */
void StrToC(char *Dest, int DestSize, const Str *Source);
void StrFromC(Str *Dest, const char *Source);
int StrEqual(const Str *Str1, const Str *Str2);
int StrEqualC(const Str *Str1, const char *Str2);
void StrPrintf(const char *Format, ...);
void vStrPrintf(const char *Format, va_list Args);
/* picoc.c */
void Fail(const char *Message, ...);
void ProgramError(const Str *FileName, int Line, const char *Message, ...);
void ProgramFail(struct LexState *Lexer, const char *Message, ...);
void ScanFile(const Str *FileName);
/* table.c */
void TableInit(struct Table *Tbl, struct TableEntry *HashTable, const char *Name, int Size);
void TableSet(struct Table *Tbl, const Str *Key, void *Value);
void *TableLookup(struct Table *Tbl, const Str *Key);
/* lex.c */
void LexInit(struct LexState *Lexer, const Str *Source, const Str *FileName, int Line);
enum LexToken LexGetToken(struct LexState *Lexer);
enum LexToken LexPeekToken(struct LexState *Lexer);
/* parse.c */
void ParseInit(void);
void ParseScan(const Str *FileName, const Str *Source);
void ParseCallFunction(const Str *FuncIdent, int argc, char **argv);
#endif /* PICOC_H */