Skip to content

Commit

Permalink
Adding skeleton for parser and ast implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyjose committed Jul 24, 2020
1 parent 5b65fa2 commit 9442855
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ src_files = src/main.c \
src/parser.ca \
src/scanner.c \
src/memory.c \
src/char_buffer.c
src/char_buffer.c \
src/ast.c

obj_files = main.o \
evaluator.o \
linked_List.o \
parser.o \
scanner.o \
memory.o \
char_buffer.o
char_buffer.o \
ast.o

app = beval

Expand Down
7 changes: 7 additions & 0 deletions headers/ast.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#pragma once

#ifndef _AST_H_
#define _AST_H_
#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>
#include "memory.h"

typedef struct {
bool value;
} Expression;

void print_expression(Expression*);

typedef struct {
Expression *left;
Expression *right;
Expand Down
7 changes: 4 additions & 3 deletions headers/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ extern "C" {
#include <stdlib.h>
#include <string.h>
#include "linked_list.h"
#include "memory.h"
#include "ast.h"

typedef struct {
Scanner *scanner;
LinkedList *tokens;
} Parser;

Parser *init_parser(const char*);
Parser *init_parser(LinkedList*);
void destroy_parser(Parser*);
Expression *parse(Parser*);
Expression *parser_parse(Parser*);

#ifdef __cplusplus
}
Expand Down
6 changes: 6 additions & 0 deletions src/ast.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "../headers/ast.h"

void print_expression(Expression *expr)
{

}
9 changes: 8 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char *argv[])

destroy_cb(cb);

printf("scanner test...\n");
printf("Evaluator test...\n");
char s[MAX_STR_LEN];
scanf("%[^\n]s", s);

Expand All @@ -64,7 +64,14 @@ int main(int argc, char *argv[])
LinkedList *tokens = scanner_scan(scanner);

ll_print_token(tokens);

Parser *parser = init_parser(tokens);
Expression *expr = parser_parse(parser);

print_expression(expr);

destroy_scanner(scanner);
destroy_parser(parser);

return 0;
}
21 changes: 21 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
#include "../headers/parser.h"

Parser *init_parser(LinkedList *tokens)
{
Parser *parser = allocate(sizeof(Parser));
parser->tokens = tokens;

return parser;
}

void destroy_parser(Parser *parser)
{
if (parser) {
if (parser->tokens) ll_destroy(parser->tokens);
free(parser);
}
}

Expression *parser_parse(Parser *parser)
{
return NULL;
}

0 comments on commit 9442855

Please sign in to comment.