Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# fu-1810

Flashcards and example programs for the course 1810 (Compilerbau) of Fernuni Hagen. The markdown files are designed to work with the [recall plugin](https://marketplace.visualstudio.com/items?itemName=frenya.vscode-recall)

The markdown files in `questions-mochi` are converted to work with the [Mochi App](https://mochi.cards) (available for mobiles).
The conversion is done with a lexer that can be found in `programs/recall-to-mochi`.
2 changes: 2 additions & 0 deletions programs/recall-to-mochi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lex
lex.yy.c
29 changes: 29 additions & 0 deletions programs/recall-to-mochi/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Mochi Format Wandler
Mochi App: https://mochi.cards

Eine Lex-Spezifikation, die es ermöglicht die Lernkarten in ein Markdown
Format zu wandeln, das die Mochi App versteht. Damit lassen sich die
Karten auch auf mobilen Endgeräten nutzen.

Getestet auf Mac OSX 15.3.2

*Programm kompilieren*
```
flex flex.l
cc -o lex lex.yy.c
```

*Fragen umwandeln*
```
# Gibt das gewandelte Markdown auf stdout aus
./lex < ../questions/ke01.md

# Speichert das gewandelte Markdown in einer neuen Datei
./lex < ../questions/ke01.md > ../questions-mochi/ke01.md

```

Das Bashscript `compile`kann genutzt werden um alle Markdown Datein in `../questions` in `../questions-mochi` zu wandeln.

### Import in Mochi
Auf *Import* klicken und *Markdown* auswählen. Dann die Option *Multiple cards per .md file* wählen und als delimeter `+++` eingeben.
4 changes: 4 additions & 0 deletions programs/recall-to-mochi/compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

flex flex.l
cc -o lex lex.yy.c
7 changes: 7 additions & 0 deletions programs/recall-to-mochi/convert
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

for filepath in ../../questions/*.md; do
filename="${filepath##*/}"
echo "Processing $filename"
./lex < "../../questions/$filename" > "../../questions-mochi/$filename"
done
58 changes: 58 additions & 0 deletions programs/recall-to-mochi/flex.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
%{
#define QUESTION_END "---"
#define CARD_END "+++"
#define MAX_ANSWER_LEN 1000

int questions = 0;
char answer[MAX_ANSWER_LEN] = {0};
int answer_len = 0;

void handle_question();
void handle_answer();
%}

any (.|\n)
line_end (\r\n|\n)

%%

^###.*\?{line_end} handle_question();
{any} handle_answer();

%%

void handle_question() {
if(questions) {
answer[answer_len] = 0;
printf("%s", answer);
printf(CARD_END "\n");
answer_len = 0;
}
printf("%s", yytext);
printf(QUESTION_END "\n");
++questions;
}

void handle_answer() {
if(questions) {
if(answer_len < MAX_ANSWER_LEN - 1) {
answer[answer_len++] = yytext[0];
} else {
fprintf(stderr, "Answer too long for buffer, increase MAX_ANSWER_LEN (message may repeat)\n");
}
}
}

int main(int argc, char **argv) {
yylex(); // need only be called once, because no return
fprintf(stderr, "Questions: %d\n", questions);
return 0;
}

int yywrap() {
if(questions) {
answer[answer_len] = 0;
printf("%s", answer);
}
return 1;
}
5 changes: 5 additions & 0 deletions questions-mochi/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Import in Mochi

Mochi App: https://mochi.cards

Auf *Import* klicken und *Markdown* auswählen. Dann die Option *Multiple cards per .md file* wählen und als delimeter `+++` eingeben.
Loading