Created the skeleton for the parser.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#include "../includes/parser.h"
|
||||
#include "../includes/lexer.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static List* SymbolsTable;
|
||||
static unsigned int program_counter = 0;
|
||||
void ProcessDirective(List*);
|
||||
void ProcessVariableDeclaration(List*);
|
||||
|
||||
void ParseTokens(List* tokens) {
|
||||
for(int i = 0; i < tokens->size; i++) {
|
||||
if (((Token *) tokens->content[i])->type == TK_Directive){
|
||||
ProcessDirective(tokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessDirective(List* tokens) {
|
||||
if (tokens->size < 2) {
|
||||
printf("Directives failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Token* directive = (Token *) tokens->content[0];
|
||||
|
||||
if (strcmp(".org", directive->value) == 0) {
|
||||
Token* address_start = (Token*) tokens->content[1];
|
||||
if (address_start->type == TK_Number) {
|
||||
long address = strtol(address_start->value, NULL, 10);
|
||||
printf("Address starting at '%ld'\n", address);
|
||||
}
|
||||
else if (address_start->type == TK_Hex) {
|
||||
long address = strtol(address_start->value, NULL, 16);
|
||||
printf("Setting address to '%ld'\n", address);
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(".db", directive->value) == 0) {
|
||||
ProcessVariableDeclaration(tokens);
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessVariableDeclaration(List* tokens) {
|
||||
if (tokens->size < 3) {
|
||||
printf("Invalid variable delcaration\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Token* symbol_token = (Token*) tokens->content[1];
|
||||
Token* string_literal = (Token*) tokens->content[2];
|
||||
|
||||
printf("Found string literal.\n");
|
||||
printf("Name '%s' value: '%s'\n", symbol_token->value, string_literal->value);
|
||||
}
|
||||
Reference in New Issue
Block a user