This commit is contained in:
2017-09-03 22:57:21 +02:00
commit 52186de3a7
6 changed files with 71 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
bin/

16
Makefile Normal file
View File

@@ -0,0 +1,16 @@
TARGET=sc
BUILDDIR=bin/
PREFIX=/usr/local/bin/
SOURCES=$(wildcard src/*.c)
MAIN=main.c
override CFLAGS+=-Werror -Wall -g -fPIC -O2 -DNDEBUG -ftrapv -Wfloat-equal -Wundef -Wwrite-strings -Wuninitialized -pedantic -std=c11
all: main.c
mkdir -p $(BUILDDIR)
$(CC) $(MAIN) $(SOURCES) -o $(BUILDDIR)$(TARGET) $(CFLAGS) $(LDFLAGS)
install: all
install $(BUILDDIR)$(TARGET) $(PREFIX)$(TARGET)
uninstall:
rm -rf $(PREFIX)$(TARGET)

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
# sc
A simple Scheme to C compiler, in C.

34
main.c Normal file
View File

@@ -0,0 +1,34 @@
#include <stdio.h>
#include "src/parser.h"
int main(int argc, char** argv) {
char* inp;
long size;
if (argc != 2) {
printf("usage: %s FILE\n", argv[0]);
return 1;
}
FILE* f = fopen(argv[1], "r");
if (!f) {
puts("Error while opening the file.");
return 1;
}
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);
inp = malloc(size+1);
fread(inp, size, 1, f);
fclose(f);
inp[size] = '\0';
printf("%p\n", (void*) parse(inp));
return 0;
}

5
src/parser.c Normal file
View File

@@ -0,0 +1,5 @@
#include "parser.h"
sc_ast* parse(char* input) {
return NULL;
}

12
src/parser.h Normal file
View File

@@ -0,0 +1,12 @@
#include <stdlib.h>
typedef struct sc_ast {
short tag;
char* value;
int n_children;
struct sc_ast** children;
} sc_ast;
sc_ast* parse(char*);