Challenge 1 + 2
This commit is contained in:
9
challenges/01-intro-challenges/answers.md
Normal file
9
challenges/01-intro-challenges/answers.md
Normal 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
|
||||
10
challenges/01-intro-challenges/c-env/Makefile
Normal file
10
challenges/01-intro-challenges/c-env/Makefile
Normal 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
|
||||
|
||||
|
||||
44
challenges/01-intro-challenges/c-env/linked_list.c
Normal file
44
challenges/01-intro-challenges/c-env/linked_list.c
Normal 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;
|
||||
}
|
||||
13
challenges/01-intro-challenges/c-env/linked_list.h
Normal file
13
challenges/01-intro-challenges/c-env/linked_list.h
Normal 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);
|
||||
18
challenges/01-intro-challenges/c-env/main.c
Normal file
18
challenges/01-intro-challenges/c-env/main.c
Normal 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);
|
||||
}
|
||||
5
challenges/01-intro-challenges/java-env/HelloWorld.java
Normal file
5
challenges/01-intro-challenges/java-env/HelloWorld.java
Normal file
@@ -0,0 +1,5 @@
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
}
|
||||
7
challenges/01-intro-challenges/java-env/Makefile
Normal file
7
challenges/01-intro-challenges/java-env/Makefile
Normal file
@@ -0,0 +1,7 @@
|
||||
run: HelloWorld.class
|
||||
@ java HelloWorld
|
||||
|
||||
HelloWorld.class: HelloWorld.java
|
||||
@ javac $^
|
||||
|
||||
.PHONY: run
|
||||
15
challenges/02-map-territory-challenges/answers.md
Normal file
15
challenges/02-map-territory-challenges/answers.md
Normal 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
|
||||
Reference in New Issue
Block a user