2008-10-12 20:53:28 -04:00
|
|
|
#ifndef PICOC_H
|
|
|
|
#define PICOC_H
|
|
|
|
|
2008-10-14 07:18:43 -04:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2008-10-12 20:53:28 -04:00
|
|
|
/* configurable options */
|
|
|
|
#define USE_MALLOC
|
|
|
|
#define GLOBAL_TABLE_SIZE 199
|
2008-10-14 07:18:43 -04:00
|
|
|
#define LARGE_INT_POWER_OF_TEN 1000000000 /* the largest power of ten which fits in an int on this architecture */
|
2008-10-12 20:53:28 -04:00
|
|
|
|
|
|
|
/* 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,
|
2008-11-21 21:56:08 -05:00
|
|
|
TokenUnaryNot,
|
2008-10-12 20:53:28 -04:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2008-11-21 21:56:08 -05:00
|
|
|
enum ValueType
|
|
|
|
{
|
|
|
|
TypeInt,
|
|
|
|
TypeString
|
|
|
|
};
|
|
|
|
|
2008-10-14 07:46:42 -04:00
|
|
|
union AnyValue
|
|
|
|
{
|
|
|
|
int Integer;
|
|
|
|
Str String;
|
|
|
|
};
|
2008-10-12 20:53:28 -04:00
|
|
|
|
2008-11-21 21:56:08 -05:00
|
|
|
struct Value
|
|
|
|
{
|
|
|
|
enum ValueType Typ;
|
|
|
|
union AnyValue Val;
|
|
|
|
};
|
|
|
|
|
2008-10-12 20:53:28 -04:00
|
|
|
/* lexer state - so we can lex nested files */
|
|
|
|
struct LexState
|
|
|
|
{
|
|
|
|
int Line;
|
|
|
|
const char *Pos;
|
|
|
|
const char *End;
|
2008-10-13 06:53:25 -04:00
|
|
|
const Str *FileName;
|
2008-10-14 07:46:42 -04:00
|
|
|
union AnyValue Value;
|
2008-10-12 20:53:28 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* 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);
|
2008-10-13 06:53:25 -04:00
|
|
|
void StrPrintf(const char *Format, ...);
|
2008-10-14 07:18:43 -04:00
|
|
|
void vStrPrintf(const char *Format, va_list Args);
|
2008-10-12 20:53:28 -04:00
|
|
|
|
|
|
|
/* picoc.c */
|
|
|
|
void Fail(const char *Message, ...);
|
|
|
|
void ProgramError(const Str *FileName, int Line, const char *Message, ...);
|
2008-11-21 21:56:08 -05:00
|
|
|
void ProgramFail(struct LexState *Lexer, const char *Message, ...);
|
2008-10-12 20:53:28 -04:00
|
|
|
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 */
|
2008-10-13 06:53:25 -04:00
|
|
|
void LexInit(struct LexState *Lexer, const Str *Source, const Str *FileName, int Line);
|
|
|
|
enum LexToken LexGetToken(struct LexState *Lexer);
|
2008-11-21 21:56:08 -05:00
|
|
|
enum LexToken LexPeekToken(struct LexState *Lexer);
|
2008-10-12 20:53:28 -04:00
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
|