2020-09-10 00:56:16 +00:00
|
|
|
/*************/
|
|
|
|
/*GEMWIRE */
|
|
|
|
/* ERYTHRO*/
|
|
|
|
/*************/
|
|
|
|
|
|
|
|
#include <Defs.h>
|
|
|
|
#define extern_
|
|
|
|
#include <Data.h>
|
|
|
|
#undef extern_
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
char* TokenStrings[] = { "+", "-", "*", "/", "int" };
|
|
|
|
char* TokenNames[] = {
|
|
|
|
"End of file",
|
|
|
|
|
|
|
|
"Addition",
|
|
|
|
"Subtraction",
|
|
|
|
"Multiplication",
|
|
|
|
"Division",
|
|
|
|
|
|
|
|
"Equality Check",
|
|
|
|
"Inequality Check",
|
|
|
|
"Less Than",
|
|
|
|
"Greater Than",
|
|
|
|
"Less Than or Equal",
|
|
|
|
"Greater Than or Equal",
|
|
|
|
|
|
|
|
"Assignment",
|
|
|
|
"Integer literal",
|
|
|
|
"Statement End",
|
|
|
|
|
|
|
|
"Compound Block Start",
|
|
|
|
"Compound Block End",
|
|
|
|
|
|
|
|
"Logical Block Start",
|
|
|
|
"Logical Block End",
|
|
|
|
|
2020-09-13 01:26:49 +00:00
|
|
|
"Dereference operator",
|
|
|
|
|
2020-09-10 00:56:16 +00:00
|
|
|
"Identifier",
|
|
|
|
"None Type",
|
|
|
|
"Char Type",
|
|
|
|
"Int Type",
|
|
|
|
"Long Type",
|
|
|
|
"Void Type",
|
|
|
|
|
|
|
|
"Function keyword",
|
|
|
|
"Print Keyword",
|
|
|
|
"If keyword",
|
|
|
|
"Else keyword",
|
|
|
|
"While keyword",
|
|
|
|
"For keyword",
|
|
|
|
|
|
|
|
"Return keyword"
|
|
|
|
};
|
|
|
|
|
2020-09-13 01:26:49 +00:00
|
|
|
char* TypeNames[9] = { "none", "char", "int", "long", "void", "charptr", "intptr", "longptr", "voidptr"};
|
2020-09-10 00:56:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
Line = 1;
|
|
|
|
Overread = '\n';
|
|
|
|
struct ASTNode* Node;
|
|
|
|
|
|
|
|
|
|
|
|
if((SourceFile = fopen(argv[1], "r")) == NULL) {
|
|
|
|
fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if((OutputFile = fopen(argv[2], "w")) == NULL) {
|
|
|
|
fprintf(stderr, "Unable to open %s: %s\n", argv[2], strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddFunctionSymbol("PrintInteger", RET_CHAR, ST_FUNC, 0);
|
|
|
|
|
|
|
|
Tokenise(&CurrentToken);
|
|
|
|
|
|
|
|
AssemblerPreamble();
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
Node = ParseFunction();
|
|
|
|
printf("\nBeginning assembler creation of new function %s\n", Symbols[Node->Value.ID].Name);
|
|
|
|
AssembleTree(Node, -1, 0);
|
|
|
|
|
|
|
|
if(CurrentToken.type == LI_EOF)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Node = ParsePrecedenceASTNode();
|
|
|
|
//printf("%d\n", ParseAST(Node));
|
|
|
|
|
|
|
|
//AssembleNode(Node);
|
|
|
|
|
|
|
|
fclose(OutputFile);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Die(char* Error) {
|
|
|
|
fprintf(stderr, "%s on line %d\n", Error, Line);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DieMessage(char* Error, char* Reason) {
|
|
|
|
fprintf(stderr, "%s:%s on line %d\n", Error, Reason, Line);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DieDecimal(char* Error, int Number) {
|
|
|
|
fprintf(stderr, "%s:%d on line %d\n", Error, Number, Line);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DieChar(char* Error, int Char) {
|
|
|
|
fprintf(stderr, "%s:%c on line %d\n", Error, Char, Line);
|
|
|
|
exit(1);
|
|
|
|
}
|