130 lines
2.5 KiB
C
130 lines
2.5 KiB
C
|
/*************/
|
||
|
/*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",
|
||
|
|
||
|
"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"
|
||
|
};
|
||
|
|
||
|
static void TokeniseFile() {
|
||
|
|
||
|
struct Token Token;
|
||
|
|
||
|
while(Tokenise(&Token)) {
|
||
|
|
||
|
printf("Token %s", TokenStrings[Token.type]);
|
||
|
if(Token.type == LI_INT) {
|
||
|
printf(", value %d", Token.value);
|
||
|
}
|
||
|
|
||
|
printf("\n");
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|