2020-09-10 00:56:16 +00:00
|
|
|
/*************/
|
|
|
|
/*GEMWIRE */
|
|
|
|
/* ERYTHRO*/
|
|
|
|
/*************/
|
|
|
|
|
|
|
|
#pragma once
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
2021-01-17 06:37:39 +00:00
|
|
|
#include <stdbool.h>
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ARithmetic tokens are prefixed AR.
|
|
|
|
* LIteral tokens are prefixed LI.
|
|
|
|
* KeyWords are prefixed KW.
|
|
|
|
* TYpes are prefixed TY.
|
|
|
|
* CoMParisons are prefixed CMP.
|
2020-11-23 20:01:36 +00:00
|
|
|
* BOOLean maths is prefixed BOOL.
|
|
|
|
* BITwise maths is prefixed BIT.
|
|
|
|
* Arithmetic SHifts are prefixed SH.
|
|
|
|
* PlusPlusMinusMinus operators are prefixed PPMM.
|
2020-09-10 00:56:16 +00:00
|
|
|
*
|
2020-09-13 01:26:49 +00:00
|
|
|
*
|
2020-09-10 00:56:16 +00:00
|
|
|
* NOTE: Tokens are different from Syntax Operations!
|
|
|
|
*
|
|
|
|
* Tokens should represent the characters that invoke them,
|
|
|
|
* not the actions they perform.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
enum TokenTypes {
|
|
|
|
LI_EOF,
|
2020-11-15 06:36:25 +00:00
|
|
|
LI_EQUAL, // =
|
2020-09-10 00:56:16 +00:00
|
|
|
|
2020-11-23 20:01:36 +00:00
|
|
|
BOOL_OR, // Boolean OR (||)
|
|
|
|
BOOL_AND, // Boolean AND (&&)
|
|
|
|
|
|
|
|
BIT_OR, // Bitwise OR (|)
|
|
|
|
BIT_XOR, // Bitwise XOR (^)
|
|
|
|
BIT_AND, // Bitwise AND (&)
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
CMP_EQUAL, // =?
|
|
|
|
CMP_INEQ, // !=
|
|
|
|
CMP_LT, // <
|
|
|
|
CMP_GT, // >
|
|
|
|
CMP_LTE, // <=
|
|
|
|
CMP_GTE, // =>
|
|
|
|
|
2020-11-23 20:01:36 +00:00
|
|
|
SH_LEFT, // Left Shift (<<)
|
|
|
|
SH_RIGHT, // Right Shift (>>)
|
|
|
|
|
|
|
|
AR_PLUS, // Arithmetic +
|
|
|
|
AR_MINUS, // Arithmetic -
|
|
|
|
AR_STAR, // Arithmetic *
|
|
|
|
AR_SLASH, // Arithmetic /
|
|
|
|
|
|
|
|
PPMM_PLUS, // PPMM Increment (++)
|
|
|
|
PPMM_MINUS, // PPMM Decrement (--)
|
|
|
|
|
|
|
|
BOOL_INVERT, // Boolean Invert (!)
|
|
|
|
|
2020-11-23 21:42:32 +00:00
|
|
|
BIT_NOT, // Bitwise NOT (~)
|
2020-11-23 20:01:36 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
LI_INT, // Integer literal
|
2020-11-22 00:42:13 +00:00
|
|
|
LI_STR, // String literal
|
2020-09-10 00:56:16 +00:00
|
|
|
LI_SEMIC, // ;
|
|
|
|
|
|
|
|
LI_LBRAC, // {
|
|
|
|
LI_RBRAC, // }
|
|
|
|
|
2020-11-18 20:49:08 +00:00
|
|
|
LI_LBRAS, // [
|
|
|
|
LI_RBRAS, // ]
|
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
LI_LPARE, // (
|
|
|
|
LI_RPARE, // )
|
|
|
|
|
2020-09-13 22:41:46 +00:00
|
|
|
LI_COM, // ,
|
2021-07-04 23:07:04 +00:00
|
|
|
LI_DOT, // .
|
|
|
|
LI_ARROW, // ->
|
2020-09-13 01:26:49 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
TY_IDENTIFIER, // Identifier name. Variable, function, etc.
|
|
|
|
TY_NONE, // No return type. Literal void.
|
|
|
|
TY_CHAR, // "char" type keyword
|
|
|
|
TY_INT, // "int" type keyword
|
|
|
|
TY_LONG, // "long" type keyword
|
|
|
|
TY_VOID, // "void" type keyword
|
|
|
|
|
|
|
|
KW_FUNC, // :: function name incoming
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
KW_PRINT,
|
|
|
|
KW_IF,
|
|
|
|
KW_ELSE,
|
|
|
|
KW_WHILE,
|
|
|
|
KW_FOR,
|
2021-01-20 19:22:15 +00:00
|
|
|
KW_RETURN,
|
2022-03-03 02:44:07 +00:00
|
|
|
KW_STRUCT,
|
2022-03-04 01:11:04 +00:00
|
|
|
KW_UNION,
|
|
|
|
KW_ENUM,
|
|
|
|
KW_ALIAS
|
2020-09-10 00:56:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All Syntax Operations are prefixed OP.
|
|
|
|
* Terminal Operations are prefixed TERM.
|
|
|
|
* L-Values are prefixed LV.
|
|
|
|
* Reference Operations are prefixed REF.
|
|
|
|
*
|
|
|
|
* These represent the actions that a token will perform.
|
|
|
|
* These are used exclusively in AST construction.
|
|
|
|
*
|
|
|
|
* It is important that Tokens and Operations are logically separated,
|
|
|
|
* but that the Operation's index is the same as the Token that invokes it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum SyntaxOps {
|
2020-11-21 02:07:44 +00:00
|
|
|
OP_ASSIGN = 1, // Assign an l-value
|
2020-09-10 00:56:16 +00:00
|
|
|
|
2020-11-23 20:01:36 +00:00
|
|
|
OP_BOOLOR, // Boolean OR two statements
|
|
|
|
OP_BOOLAND, // Boolean AND two statements
|
|
|
|
OP_BITOR, // Bitwise OR a number
|
2022-03-03 00:05:10 +00:00
|
|
|
OP_BITXOR = 5, // Bitwise XOR a number
|
2020-11-23 20:01:36 +00:00
|
|
|
OP_BITAND, // Bitwise AND a number
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
OP_EQUAL, // Compare equality
|
|
|
|
OP_INEQ, // Compare inequality
|
|
|
|
OP_LESS, // Less than?
|
2022-03-03 00:05:10 +00:00
|
|
|
OP_GREAT = 10, // Greater than?
|
2020-09-10 00:56:16 +00:00
|
|
|
OP_LESSE, // Less than or Equal to?
|
|
|
|
OP_GREATE, // Greater than or Equal to?
|
|
|
|
|
2020-11-23 20:01:36 +00:00
|
|
|
OP_SHIFTL, // Arithmetic Shift Left (Multiply by 2)
|
|
|
|
OP_SHIFTR, // Arithmetic Shift Right (Divide by 2)
|
2020-09-10 00:56:16 +00:00
|
|
|
|
2022-03-03 00:05:10 +00:00
|
|
|
OP_ADD = 15, // Add two numbers.
|
2020-11-23 20:01:36 +00:00
|
|
|
OP_SUBTRACT, // Subtract two numbers.
|
|
|
|
OP_MULTIPLY, // Multiply two numbers.
|
|
|
|
OP_DIVIDE, // Divide two numbers.
|
|
|
|
|
2020-11-23 21:42:32 +00:00
|
|
|
OP_PREINC, // Increment var before reference.
|
2022-03-03 00:05:10 +00:00
|
|
|
OP_PREDEC = 20, // Decrement var before reference.
|
2020-11-23 21:42:32 +00:00
|
|
|
OP_POSTINC, // Increment var after reference.
|
|
|
|
OP_POSTDEC, // Decrement var after reference.
|
2020-11-23 20:01:36 +00:00
|
|
|
|
|
|
|
OP_BITNOT, // Invert a number bitwise
|
2020-11-24 13:17:01 +00:00
|
|
|
OP_BOOLNOT, // Invert a statement logically
|
2022-03-03 00:05:10 +00:00
|
|
|
OP_NEGATE = 25, // Negate a number (turn a positive number negative)
|
2020-11-24 00:21:08 +00:00
|
|
|
|
|
|
|
OP_BOOLCONV, // Convert an expression to a boolean.s
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-13 01:26:49 +00:00
|
|
|
OP_ADDRESS, // Fetch the address of a var
|
|
|
|
OP_DEREF, // Get the value of the address in a pointer
|
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
TERM_INTLITERAL, // Integer Literal. This is a virtual operation, so it's a terminal.
|
2022-03-03 00:05:10 +00:00
|
|
|
TERM_STRLITERAL = 30, // String Literal. Also terminal.
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
REF_IDENT, // Reference (read) an identifier (variable).
|
|
|
|
|
|
|
|
OP_WIDEN, // Something contains a type that needs to be casted up
|
2020-09-14 01:05:24 +00:00
|
|
|
OP_SCALE, // We have a pointer that needs to be scaled!
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
OP_CALL, // Call a function
|
2022-03-03 00:05:10 +00:00
|
|
|
OP_RET = 35, // Return from a function
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
OP_COMP, // Compound statements need a way to be "glued" together. This is one of those mechanisms
|
|
|
|
OP_IF, // If statement
|
|
|
|
OP_LOOP, // FOR, WHILE
|
|
|
|
OP_PRINT, // Print statement
|
|
|
|
|
2022-03-03 00:05:10 +00:00
|
|
|
OP_FUNC = 40, // Define a function
|
2020-09-10 00:56:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A node in a Binary Tree that forms the syntax of Erythro
|
|
|
|
struct ASTNode {
|
2020-11-14 22:26:12 +00:00
|
|
|
int Operation; // SyntaxOps Index
|
2020-09-10 00:56:16 +00:00
|
|
|
int ExprType; // Value->IntValue's DataType
|
2020-11-15 06:36:25 +00:00
|
|
|
int RVal; // True if this node is an Rval, false if Lval
|
2020-09-10 00:56:16 +00:00
|
|
|
struct ASTNode* Left;
|
|
|
|
struct ASTNode* Middle;
|
|
|
|
struct ASTNode* Right;
|
2021-01-20 01:05:41 +00:00
|
|
|
struct SymbolTableEntry* Symbol;
|
2020-09-10 00:56:16 +00:00
|
|
|
union {
|
2020-09-14 01:05:24 +00:00
|
|
|
int Size; // OP_SCALE's linear representation
|
2020-09-10 00:56:16 +00:00
|
|
|
int IntValue; // TERM_INTLIT's Value
|
2021-01-20 01:05:41 +00:00
|
|
|
};
|
2020-09-10 00:56:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Token {
|
|
|
|
int type;
|
|
|
|
int value;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The Symbol Table, used for variables, functions and
|
|
|
|
* assorted goodies.
|
|
|
|
*/
|
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
struct SymbolTableEntry {
|
2020-09-10 00:56:16 +00:00
|
|
|
char* Name;
|
|
|
|
int Type; // An entry in DataTypes, referring to the type of this data
|
2021-01-20 01:05:41 +00:00
|
|
|
struct SymbolTableEntry* CompositeType; // A pointer to the start of a Symbol Table list that represents a certain Composite type
|
2020-09-10 00:56:16 +00:00
|
|
|
int Structure; // An entry in StructureType - metadata on how to process the data
|
2020-11-25 02:11:09 +00:00
|
|
|
int Storage; // The scope of this symbol - decides when it is discarded.
|
2021-01-20 01:05:41 +00:00
|
|
|
union {
|
|
|
|
int EndLabel; // For a function - The number of the label to jump to, in order to exit this function (if applicable)
|
|
|
|
int Length; // For an array - The length of the symbol in units of 1 element -- the size of an array, for example.
|
|
|
|
int IntValue; // For an enum - The value of an Enum entry
|
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
|
|
|
int SinkOffset; // For a variable - How many times must we sink the rbp to get to this symbol in the stack?
|
|
|
|
int Elements; // For a function - How many parameters?
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SymbolTableEntry* NextSymbol; // The next symbol in a list
|
|
|
|
struct SymbolTableEntry* Start; // The first member in a list
|
2020-11-25 02:11:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum StorageScope {
|
|
|
|
SC_GLOBAL = 1, // Global Scope
|
2021-01-20 19:22:15 +00:00
|
|
|
SC_STRUCT, // Struct Definitions
|
2022-03-03 02:44:07 +00:00
|
|
|
SC_UNION, // Union Definitions
|
2021-01-20 19:22:15 +00:00
|
|
|
SC_ENUM, // Enum Definitions
|
2022-03-04 01:11:04 +00:00
|
|
|
SC_ENUMENTRY, // Enum Entry Names
|
|
|
|
SC_ALIAS, // Typedef aliases
|
|
|
|
SC_MEMBER, // The members of Structs or Unions
|
2022-03-03 00:05:10 +00:00
|
|
|
//SC_CLASS, // Class-local definitions
|
|
|
|
//SC_STATIC, // Static storage definitions
|
2021-01-17 06:37:39 +00:00
|
|
|
SC_PARAM, // Function parameters
|
2020-11-25 02:11:09 +00:00
|
|
|
SC_LOCAL // Function-local scope.
|
2022-03-03 00:05:10 +00:00
|
|
|
// There is no deeper scope than function.
|
2020-09-10 00:56:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2021-01-20 01:05:41 +00:00
|
|
|
* The types of data being held in memory.
|
|
|
|
* The lowest 4 bits of these enum values
|
|
|
|
* encode a nested pointer type.
|
|
|
|
*
|
|
|
|
* This meaning, a single enum can hold
|
|
|
|
* ****************int types.
|
|
|
|
* Should be enough for everyone, right?
|
2020-09-10 00:56:16 +00:00
|
|
|
*/
|
|
|
|
enum DataTypes {
|
2021-01-20 01:05:41 +00:00
|
|
|
RET_NONE, // No return type. Literal void.
|
|
|
|
RET_CHAR = 16, // "char" type keyword
|
|
|
|
RET_INT = 32, // "int" type keyword
|
|
|
|
RET_LONG = 48, // "long" type keyword
|
|
|
|
RET_VOID = 64, // "void" type keyword
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
DAT_STRUCT = 80, // Struct Data
|
|
|
|
DAT_UNION, // Union Data
|
2022-03-04 01:11:04 +00:00
|
|
|
DAT_ENUM = -1, // Enum Data
|
2020-09-10 00:56:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The type of the structure of data being examined
|
|
|
|
* //TODO: move into TokenTypes?
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum StructureType {
|
|
|
|
ST_VAR, // This is variable
|
2020-11-18 20:49:08 +00:00
|
|
|
ST_FUNC, // This is a function
|
2021-07-04 23:07:04 +00:00
|
|
|
ST_ARR, // This is an array
|
2022-03-04 01:11:04 +00:00
|
|
|
ST_RUCT, // This is a struct
|
|
|
|
ST_ENUM, // This is an enum
|
2022-03-03 00:05:10 +00:00
|
|
|
// This is a typedef
|
2020-09-10 00:56:16 +00:00
|
|
|
};
|
|
|
|
|
2021-01-18 01:47:42 +00:00
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* * * * * * * A R G U M E N T S * * * * * * *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
char* Suffixate(char* String, char Suffix);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-18 01:47:42 +00:00
|
|
|
char* Compile(char* InputFile);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-18 01:47:42 +00:00
|
|
|
char* Assemble(char* InputFile);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-18 01:47:42 +00:00
|
|
|
void Link(char* Output, char* Objects[]);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-18 01:47:42 +00:00
|
|
|
void DisplayUsage(char* ProgName);
|
|
|
|
|
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* * * * * * * * * L E X I N G * * * * * * * * *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
|
2021-01-20 19:22:15 +00:00
|
|
|
void Tokenise();
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
void VerifyToken(int Type, char* TokenExpected);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
void RejectToken(struct Token* Token);
|
|
|
|
|
|
|
|
static int ReadIdentifier(int Char, char* Buffer, int Limit);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
static int ReadKeyword(char* Str);
|
|
|
|
|
2020-09-14 01:05:24 +00:00
|
|
|
/* * * * * * * * * * * * * * * * * * * *
|
|
|
|
* * * * * T Y P E S * * * * * *
|
|
|
|
* * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
struct ASTNode* MutateType(struct ASTNode* Tree, int RightType, int Operation);
|
|
|
|
|
|
|
|
int TypeIsInt(int Type);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-14 01:05:24 +00:00
|
|
|
int TypeIsPtr(int Type);
|
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
char* TypeNames(int Type);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-22 01:01:53 +00:00
|
|
|
int TypeSize(int Type, struct SymbolTableEntry* Composite);
|
2021-01-20 01:05:41 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* * * * * * S Y N T A X T R E E * * * * * *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
|
|
|
|
struct ASTNode* ConstructASTNode(int Operation, int Type,
|
|
|
|
struct ASTNode* Left,
|
|
|
|
struct ASTNode* Middle,
|
|
|
|
struct ASTNode* Right,
|
2021-01-20 01:05:41 +00:00
|
|
|
struct SymbolTableEntry* Symbol,
|
2020-09-10 00:56:16 +00:00
|
|
|
int IntValue);
|
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
struct ASTNode* ConstructASTLeaf(int Operation, int Type, struct SymbolTableEntry* Symbol, int IntValue);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
2022-03-03 00:05:10 +00:00
|
|
|
struct ASTNode*
|
|
|
|
ConstructASTBranch(int Operation, int Type, struct ASTNode* Left, struct SymbolTableEntry* Symbol, int IntValue);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* * * * * * * * * P A R S I N G * * * * * * * * *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
struct ASTNode* ParsePrecedenceASTNode(int PreviousTokenPrecedence);
|
|
|
|
|
|
|
|
|
2020-09-13 01:26:49 +00:00
|
|
|
struct ASTNode* ParsePrimary(void);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
struct ASTNode* ParseStatement(void);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-13 01:26:49 +00:00
|
|
|
struct ASTNode* PrefixStatement();
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-23 21:42:32 +00:00
|
|
|
struct ASTNode* PostfixStatement();
|
2020-09-10 00:56:16 +00:00
|
|
|
|
2020-09-13 22:41:46 +00:00
|
|
|
void ParseGlobals();
|
|
|
|
|
|
|
|
struct ASTNode* ParseFunction(int Type);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
struct ASTNode* ParseCompound();
|
|
|
|
|
2022-03-03 02:44:07 +00:00
|
|
|
struct SymbolTableEntry* BeginCompositeDeclaration(int Type);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2022-03-04 01:11:04 +00:00
|
|
|
void BeginEnumDeclaration();
|
|
|
|
|
2021-01-17 21:56:37 +00:00
|
|
|
struct ASTNode* GetExpressionList();
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
struct ASTNode* CallFunction();
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
struct ASTNode* ReturnStatement();
|
|
|
|
|
2021-03-15 01:22:47 +00:00
|
|
|
int ParseOptionalPointer(struct SymbolTableEntry** Composite);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-13 01:26:49 +00:00
|
|
|
int ValueAt(int Type);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-13 01:26:49 +00:00
|
|
|
int PointerTo(int Type);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
2020-11-19 02:31:40 +00:00
|
|
|
struct ASTNode* AccessArray();
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-07-04 23:07:04 +00:00
|
|
|
struct ASTNode* AccessMember(bool Deref);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
int ParseTokenToOperation(int Token);
|
|
|
|
|
|
|
|
struct ASTNode* PrintStatement(void);
|
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* * * * * * S Y M B O L T A B L E * * * * * *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2021-03-15 01:22:47 +00:00
|
|
|
void DumpAllLists();
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-03-15 01:22:47 +00:00
|
|
|
void DumpList(struct SymbolTableEntry* List);
|
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
struct SymbolTableEntry* FindSymbol(char* Symbol);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
struct SymbolTableEntry* FindLocal(char* Symbol);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
struct SymbolTableEntry* FindGlobal(char* Symbol);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 19:22:15 +00:00
|
|
|
struct SymbolTableEntry* FindStruct(char* Symbol);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2022-03-04 01:11:04 +00:00
|
|
|
struct SymbolTableEntry* FindEnum(char* Symbol);
|
|
|
|
|
|
|
|
struct SymbolTableEntry* FindEnumMember(char* Symbol);
|
|
|
|
|
2022-03-03 02:44:07 +00:00
|
|
|
struct SymbolTableEntry* FindUnion(char* Symbol);
|
|
|
|
|
2021-01-20 19:22:15 +00:00
|
|
|
struct SymbolTableEntry* FindMember(char* Symbol);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
void AppendSymbol(struct SymbolTableEntry** Head, struct SymbolTableEntry** Tail, struct SymbolTableEntry* Node);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
2021-01-17 06:37:39 +00:00
|
|
|
void FreeLocals();
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
void ClearTables();
|
|
|
|
|
2022-03-03 00:05:10 +00:00
|
|
|
struct SymbolTableEntry* AddSymbol(char* Name, int Type, int Structure, int Storage, int Length, int SinkOffset,
|
|
|
|
struct SymbolTableEntry* CompositeType);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* * * * C O N T R O L S T A T U S * * * *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
void Die(char* Error);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
void DieMessage(char* Error, char* Reason);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
void DieDecimal(char* Error, int Number);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
void DieChar(char* Error, int Char);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-03-15 15:59:15 +00:00
|
|
|
void DieBinary(char* Error, int Number);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* * * * C O D E G E N E R A T I O N * * * *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
int AssembleTree(struct ASTNode* Node, int Register, int ParentOp);
|
|
|
|
|
|
|
|
void DeallocateAllRegisters();
|
|
|
|
|
|
|
|
int RetrieveRegister();
|
|
|
|
|
|
|
|
void DeallocateRegister(int Register);
|
|
|
|
|
|
|
|
int PrimitiveSize(int Type);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-22 01:01:53 +00:00
|
|
|
int AsAlignMemory(int Type, int Offset, int Direction);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
int AsLoad(int Value);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsAdd(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsMul(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsSub(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsDiv(int Left, int Right);
|
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
int AsLdGlobalVar(struct SymbolTableEntry* Entry, int Operation);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
int AsLdLocalVar(struct SymbolTableEntry* Entry, int Operation);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
int AsStrGlobalVar(struct SymbolTableEntry* Entry, int Register);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
int AsStrLocalVar(struct SymbolTableEntry* Entry, int Register);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
2021-01-17 06:37:39 +00:00
|
|
|
int AsCalcOffset(int Type);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-27 21:16:50 +00:00
|
|
|
void AsNewStackFrame();
|
2020-11-15 06:36:25 +00:00
|
|
|
|
2020-09-13 01:26:49 +00:00
|
|
|
int AsDeref(int Reg, int Type);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-15 06:36:25 +00:00
|
|
|
int AsStrDeref(int Register1, int Register2, int Type);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
int AsAddr(struct SymbolTableEntry* Entry);
|
2020-09-13 01:26:49 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
void AsGlobalSymbol(struct SymbolTableEntry* Entry);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
|
|
|
int AsNewString(char* Value);
|
2020-11-22 01:44:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
int AsLoadString(int ID);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
int AsEqual(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsIneq(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsLess(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsGreat(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsLessE(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsGreatE(int Left, int Right);
|
|
|
|
|
2020-11-24 13:17:01 +00:00
|
|
|
int AsBitwiseAND(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-24 13:17:01 +00:00
|
|
|
int AsBitwiseOR(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-24 13:17:01 +00:00
|
|
|
int AsBitwiseXOR(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-24 13:17:01 +00:00
|
|
|
int AsNegate(int Register);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-24 13:17:01 +00:00
|
|
|
int AsInvert(int Register);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-24 13:17:01 +00:00
|
|
|
int AsBooleanNOT(int Register);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-24 13:17:01 +00:00
|
|
|
int AsShiftLeft(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-24 13:17:01 +00:00
|
|
|
int AsShiftRight(int Left, int Right);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-24 13:17:01 +00:00
|
|
|
int AsBooleanConvert(int Register, int Operation, int Label);
|
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsCompareJmp(int Operation, int RegisterLeft, int RegisterRight, int Label);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsCompare(int Operation, int RegisterLeft, int RegisterRight);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int AsIf(struct ASTNode* Node);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
int NewLabel(void);
|
|
|
|
|
|
|
|
void AsJmp(int Label);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
void AsLabel(int Label);
|
|
|
|
|
2020-09-14 01:05:24 +00:00
|
|
|
int AsShl(int Register, int Val);
|
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
int AsReturn(struct SymbolTableEntry* Entry, int Register);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-17 21:56:37 +00:00
|
|
|
int AsCallWrapper(struct ASTNode* Node);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-17 21:56:37 +00:00
|
|
|
void AsCopyArgs(int Register, int Position);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
int AsCall(struct SymbolTableEntry* Entry, int Args);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
int AsWhile(struct ASTNode* Node);
|
|
|
|
|
|
|
|
void AssemblerPrint(int Register);
|
|
|
|
|
|
|
|
void AssemblerPreamble();
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
void AsFunctionPreamble(struct SymbolTableEntry* Entry);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2021-01-20 01:05:41 +00:00
|
|
|
void AsFunctionEpilogue(struct SymbolTableEntry* Entry);
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* * * * D E C L A R A T I O N * * * *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2021-01-20 19:22:15 +00:00
|
|
|
struct SymbolTableEntry* BeginVariableDeclaration(int Type, struct SymbolTableEntry* Composite, int Scope);
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
struct ASTNode* ParseIdentifier(void);
|
|
|
|
|
|
|
|
struct ASTNode* IfStatement();
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
struct ASTNode* WhileStatement();
|
2022-03-03 00:05:10 +00:00
|
|
|
|
2020-11-15 06:36:25 +00:00
|
|
|
struct ASTNode* ForStatement();
|
|
|
|
|
|
|
|
|
|
|
|
void DumpTree(struct ASTNode* node, int level);
|