Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parser framework #47

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading