Challenge 1 + 2

This commit is contained in:
ctsk
2022-09-02 21:57:44 +02:00
parent 69a872fe2d
commit 1b0003e586
9 changed files with 124 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.o
*.out
*.class

View File

@@ -0,0 +1,9 @@
DSLs found in [https://github.com/munificent/craftinginterpreters]
----
1. HTML
2. Jinja2
2. CSS
3. SASS
4. Markdown
7. Makefile

View File

@@ -0,0 +1,10 @@
run: main
@ ./main
main: main.c linked_list.o
@ gcc $^ -o main
linked_list.o: linked_list.c
@ gcc -c linked_list.c

View File

@@ -0,0 +1,44 @@
#include "malloc.h"
#include "linked_list.h"
List* InitList() {
List *new = (List *) malloc(sizeof(List));
new->head = NULL;
return new;
}
int Insert(List *l, char *data) {
Item *new = (Item *) malloc(sizeof(Item));
node->data = malloc(strlen(string) + 1);
strcpy(node->data, string);
if (l->head = NULL) {
new->next = new;
new->prev = new;
l->head = new;
return;
} else {
new->next = l->head;
new->prev = l->head->prev;
l->head->prev->next = new;
l->head->prev = new;
l->head = new;
}
}
Item* Find(List *l, char *data) {
if (l->head == NULL) {
return NULL;
}
Item *cur = l->head;
do {
if (strcmp(data, cur->data) == 0) {
return cur;
}
cur = cur->next;
} while (cur != l->head);
return NULL;
}

View File

@@ -0,0 +1,13 @@
typedef struct _Item {
char *data;
struct _Item *prev;
struct _Item *next;
} Item;
typedef struct List {
Item *head;
} List;
List* InitList();
void Insert(List *l, char *data);
Item* Find(List *l, char *data);

View File

@@ -0,0 +1,18 @@
#include <stdio.h>
#include "linked_list.h"
#include <assert.h>
int main()
{
List *l = InitList();
Insert(l, "one");
Insert(l, "two");
Insert(l, "three");
int f = Find(l, "two");
assert(f > 0);
int f = Find(l, "four");
assert(f == 0);
}

View File

@@ -0,0 +1,5 @@
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}

View File

@@ -0,0 +1,7 @@
run: HelloWorld.class
@ java HelloWorld
HelloWorld.class: HelloWorld.java
@ javac $^
.PHONY: run

View File

@@ -0,0 +1,15 @@
1. Java (OpenJDK)
-> No Flex/Yacc used
-> Files:
Scanner: [jdk/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Scanner.java]
Parser: [jdk/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java]
[https://github.com/openjdk/jdk/blob/1f484dae4efaa60cf18a3d4df947c05f1497bd5b]
2. Reasons not to JIT
- Short running programs => Cost of compilation higher than gained speed
- Little repeat execution of code
- Platform-independence
3. Why do Lisps contain interpreters?
- Better interactivity
- Evaluation of Macros