Update Makefile
This commit is contained in:
parent
4b08e74c3a
commit
21c264c0a1
3 changed files with 78 additions and 79 deletions
13
Makefile
13
Makefile
|
@ -1,7 +1,6 @@
|
||||||
.POSIX:
|
.POSIX:
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
|
|
||||||
CC = cc
|
|
||||||
VERSION = 1.0
|
VERSION = 1.0
|
||||||
TARGET = slr
|
TARGET = slr
|
||||||
MANPAGE = $(TARGET).1
|
MANPAGE = $(TARGET).1
|
||||||
|
@ -9,14 +8,12 @@ PREFIX ?= /usr/local
|
||||||
BINDIR = $(PREFIX)/bin
|
BINDIR = $(PREFIX)/bin
|
||||||
MANDIR = $(PREFIX)/share/man/man1
|
MANDIR = $(PREFIX)/share/man/man1
|
||||||
|
|
||||||
# Flags
|
CFLAGS = -O3 -march=native -mtune=native -pipe -s -std=c99 -pedantic -Wall
|
||||||
LDFLAGS =
|
|
||||||
CFLAGS = -O3 -march=native -mtune=native -pipe -s -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600
|
|
||||||
|
|
||||||
SRC = slr.c lexer.c parser.c
|
SRC = slr.c lexer.c parser.c
|
||||||
|
|
||||||
$(TARGET): $(SRC)
|
$(TARGET): $(SRC)
|
||||||
$(CC) $(SRC) -o $@ $(CFLAGS) $(LDFLAGS)
|
$(CC) $(SRC) -o $@ $(CFLAGS)
|
||||||
|
|
||||||
dist:
|
dist:
|
||||||
mkdir -p $(TARGET)-$(VERSION)
|
mkdir -p $(TARGET)-$(VERSION)
|
||||||
|
@ -34,11 +31,11 @@ install: $(TARGET)
|
||||||
chmod 644 $(DESTDIR)$(MANDIR)/$(MANPAGE)
|
chmod 644 $(DESTDIR)$(MANDIR)/$(MANPAGE)
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
$(RM) $(DESTDIR)$(BINDIR)/$(TARGET)
|
rm $(DESTDIR)$(BINDIR)/$(TARGET)
|
||||||
$(RM) $(DESTDIR)$(MANDIR)/$(MANPAGE)
|
rm $(DESTDIR)$(MANDIR)/$(MANPAGE)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(TARGET)
|
rm $(TARGET)
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
|
140
parser.c
140
parser.c
|
@ -6,97 +6,97 @@
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
INT_LIT,
|
INT_LIT,
|
||||||
STATEMENT,
|
STATEMENT,
|
||||||
EXTRA,
|
EXTRA,
|
||||||
BEGINNING,
|
BEGINNING,
|
||||||
} NodeTypes;
|
} NodeTypes;
|
||||||
|
|
||||||
typedef struct Node {
|
typedef struct Node {
|
||||||
char *value;
|
char *value;
|
||||||
NodeTypes type;
|
NodeTypes type;
|
||||||
struct Node *right;
|
struct Node *right;
|
||||||
struct Node *left;
|
struct Node *left;
|
||||||
} Node;
|
} Node;
|
||||||
|
|
||||||
void print_tree(Node *node){
|
void print_tree(Node *node){
|
||||||
if(node == NULL){
|
if(node == NULL){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(size_t i = 0; node->value[i] != '\0'; i++){
|
for(size_t i = 0; node->value[i] != '\0'; i++){
|
||||||
printf("%c", node->value[i]);
|
printf("%c", node->value[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
print_tree(node->left);
|
print_tree(node->left);
|
||||||
print_tree(node->right);
|
print_tree(node->right);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *init_node(Node *node, char *value, NodeTypes type){
|
Node *init_node(Node *node, char *value, NodeTypes type){
|
||||||
node = malloc(sizeof(Node));
|
node = malloc(sizeof(Node));
|
||||||
node->value = malloc(sizeof(char) * 2);
|
node->value = malloc(sizeof(char) * 2);
|
||||||
node->type = (int)type;
|
node->type = (int)type;
|
||||||
node->value = value;
|
node->value = value;
|
||||||
node->left = NULL;
|
node->left = NULL;
|
||||||
node->right = NULL;
|
node->right = NULL;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
Token *parser(Token *tokens){
|
Token *parser(Token *tokens){
|
||||||
Token *current_token = &tokens[0];
|
Token *current_token = &tokens[0];
|
||||||
Node *root = malloc(sizeof(Node));
|
Node *root = malloc(sizeof(Node));
|
||||||
Node *left = malloc(sizeof(Node));
|
Node *left = malloc(sizeof(Node));
|
||||||
Node *right = malloc(sizeof(Node));
|
Node *right = malloc(sizeof(Node));
|
||||||
root = init_node(root, "PROGRAM", BEGINNING);
|
root = init_node(root, "PROGRAM", BEGINNING);
|
||||||
|
|
||||||
print_tree(root);
|
print_tree(root);
|
||||||
|
|
||||||
Node *current = root;
|
Node *current = root;
|
||||||
|
|
||||||
while(current_token->type != END_OF_TOKENS){
|
while(current_token->type != END_OF_TOKENS){
|
||||||
if(current == NULL){
|
if(current == NULL){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(current == root){
|
if(current == root){
|
||||||
//;
|
//;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(current_token->type == KEYWORD && strcmp(current_token->value, "exit")){
|
if(current_token->type == KEYWORD && strcmp(current_token->value, "exit")){
|
||||||
Node *exit_node = malloc(sizeof(Node));
|
Node *exit_node = malloc(sizeof(Node));
|
||||||
exit_node = init_node(exit_node, current_token->value, STATEMENT);
|
exit_node = init_node(exit_node, current_token->value, STATEMENT);
|
||||||
root->right = exit_node;
|
root->right = exit_node;
|
||||||
current = exit_node;
|
current = exit_node;
|
||||||
current_token++;
|
current_token++;
|
||||||
if(current_token->type != SEPARATOR){
|
if(current_token->type != SEPARATOR){
|
||||||
printf("ERROR\n");
|
printf("ERROR\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
Node *open_paren_node = malloc(sizeof(Node));
|
Node *open_paren_node = malloc(sizeof(Node));
|
||||||
open_paren_node = init_node(open_paren_node, current_token->value, EXTRA);
|
open_paren_node = init_node(open_paren_node, current_token->value, EXTRA);
|
||||||
current->left = open_paren_node;
|
current->left = open_paren_node;
|
||||||
|
|
||||||
current_token++;
|
current_token++;
|
||||||
|
|
||||||
Node *expr_node = malloc(sizeof(Node));
|
Node *expr_node = malloc(sizeof(Node));
|
||||||
expr_node = init_node(expr_node, current_token->value, INT_LIT);
|
expr_node = init_node(expr_node, current_token->value, INT_LIT);
|
||||||
current->left->left = expr_node;
|
current->left->left = expr_node;
|
||||||
|
|
||||||
current_token++;
|
current_token++;
|
||||||
|
|
||||||
Node *close_paren_node = malloc(sizeof(Node));
|
Node *close_paren_node = malloc(sizeof(Node));
|
||||||
close_paren_node = init_node(close_paren_node, current_token->value, EXTRA);
|
close_paren_node = init_node(close_paren_node, current_token->value, EXTRA);
|
||||||
current->left->right = close_paren_node;
|
current->left->right = close_paren_node;
|
||||||
|
|
||||||
current_token++;
|
current_token++;
|
||||||
|
|
||||||
Node *semi_node = malloc(sizeof(Node));
|
Node *semi_node = malloc(sizeof(Node));
|
||||||
semi_node = init_node(semi_node, current_token->value, EXTRA);
|
semi_node = init_node(semi_node, current_token->value, EXTRA);
|
||||||
current->right = semi_node;
|
current->right = semi_node;
|
||||||
|
|
||||||
printf("EXIT\n");
|
printf("EXIT\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current_token++;
|
current_token++;
|
||||||
}
|
}
|
||||||
print_tree(root);
|
print_tree(root);
|
||||||
return current_token;
|
return current_token;
|
||||||
}
|
}
|
||||||
|
|
2
slr.c
2
slr.c
|
@ -35,3 +35,5 @@ int main(int argc, char **argv)
|
||||||
print_token(tokens[i]);
|
print_token(tokens[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* https://github.com/CobbCoding1/unnamed-lang/commit/10ecba484a0b47110c19b2604500c9ae49f84c52 */
|
||||||
|
|
Loading…
Reference in a new issue