From 810673ee2ef3547480ed21e7af5d6ce96e133278 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Mon, 28 Sep 2020 19:36:27 -0700 Subject: [PATCH] [#24] New language: Flex --- backend/src/langs.ts | 25 +++++++++++++++++++++++++ backend/src/test-runner.ts | 4 +++- scripts/docker-install-phase3b.bash | 4 ++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/backend/src/langs.ts b/backend/src/langs.ts index 69c7283..2c5ede8 100644 --- a/backend/src/langs.ts +++ b/backend/src/langs.ts @@ -1132,6 +1132,31 @@ USE: io input: `echo $x`, }, template: `echo "Hello, world!" +`, + }, + flex: { + aliases: ["lex"], + name: "Flex", + main: "main.lex", + compile: "lex -o main.c main.lex && clang main.c -o main", + run: "echo 'Reading from stdin, ctrl+D to end input...' >&2 && ./main", + helloInput: "EOF", + template: `%{ +#include +%} + +%% +%% + +int yywrap() { + printf("Hello, world!\\n"); + return 1; +} + +int main() { + yylex(); + return 0; +} `, }, forth: { diff --git a/backend/src/test-runner.ts b/backend/src/test-runner.ts index 4cfb26c..95417cd 100644 --- a/backend/src/test-runner.ts +++ b/backend/src/test-runner.ts @@ -31,7 +31,9 @@ function findPosition(str: string, idx: number) { async function sendInput(send: (msg: any) => any, input: string) { for (const line of input.split("\n")) { - if (line.startsWith("DELAY:")) { + if (line === "EOF") { + send({ event: "terminalInput", input: "\u0004" }); + } else if (line.startsWith("DELAY:")) { const delay = parseFloat(line.replace(/DELAY: */, "")); if (Number.isNaN(delay)) continue; await new Promise((resolve) => diff --git a/scripts/docker-install-phase3b.bash b/scripts/docker-install-phase3b.bash index 9e46d98..f01ff5a 100755 --- a/scripts/docker-install-phase3b.bash +++ b/scripts/docker-install-phase3b.bash @@ -35,6 +35,10 @@ fsharp # Fish fish +# Flex +flex +flex-doc + # FORTRAN flang