Skip to content

Commit

Permalink
Merge pull request #47 from adamhutchings/parse
Browse files Browse the repository at this point in the history
Add parser framework
  • Loading branch information
JakeRoggenbuck authored Jun 30, 2024
2 parents 78017c1 + 336bee1 commit 3056da3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lexer/lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int real_lex(Lexer *l, Token *t) {
// return./
if (starts_operator(init)) {
while (valid_operator_sequence(t->contents)) {
t->contents[pos++] = (c = lexer_getchar(l->fp));
t->contents[pos++] = (c = lexer_getchar(l));
}
// We've ended!
// Can we reduce this code duplication from above in a smart way?
Expand Down
2 changes: 1 addition & 1 deletion src/parser/cst.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include "list.h"
#include <util/list.h>

// A list of all node types.
typedef enum {
Expand Down
35 changes: 32 additions & 3 deletions src/parser/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
*
*/

#include <codegen/x86/codegen.h>
#include <lexer/lex.h>
#include <lexer/token.h>
#include <stdlib.h> // calloc
#include <string.h> // strcmp
#include <ctype.h> // isdigit

#include <codegen/x86/codegen.h>
#include <lexer/lex.h>
#include <lexer/token.h>
#include <parser/cst.h>
#include <util/out.h>

int parse(const char *filename) {
Expand Down Expand Up @@ -95,3 +97,30 @@ int parse(const char *filename) {
}

int parse_simple_main_func() {}

/**
* Proper parsing code below -- producing a concrete syntax tree from a file.
* Each of these functions will probably reference the others numerous times.
*/

int parse_expr(Lexer* l, Expression* ex) {
// TODO (just a literal or a function call for now).
}

int parse_funccall(Lexer* l, Expression* ex) {
// TODO
}

int parse_blockstmt(Lexer* l, BlockStatement* bs) {
// TODO
}

int parse_funcdecl(Lexer* l, FunctionDeclaration* fd) {
// TODO
}

// Parse function -- takes a lexer and produces a concrete syntax tree. Fill the
// struct which we have given with the data.
int make_cst(Lexer* l, ConcreteFileTree* tree) {
// TODO
}

0 comments on commit 3056da3

Please sign in to comment.