Skip to content

Commit

Permalink
add: Clearer task delineation for steps 1-3
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobjwalters authored Dec 6, 2024
1 parent 9a7cff0 commit 65fb874
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
14 changes: 11 additions & 3 deletions pages/resources/lisp-workshop/step1.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@ You might be familiar with this concept from other languages: the JavaScript con

Write a program that reads a line of input from the user, and responds by repeating the input back to the user.

Examples:
You may want to implement this by storing the user's input into a variable, and then passing that variable into your language's `print` function.

This program should work in a loop; in other words, once the string has been printed, the program should return to its initial state, asking the user for their input once again.

## Tests

Here's some test cases that you can use to check if your implementation is along the right lines:

```plaintext
Hello, world! // this line is user input
Hello, world! // this line is program output
```

```plaintext
TypeSig <3 you! // this line is user input
TypeSig <3 you! // this line is program output
TypeSig <3 you! // this line is user input
TypeSig <3 you! // this line is program output
https://discord.gg/dnXzHRkJww // this line is user input
https://discord.gg/dnXzHRkJww // this line is program output
```

## Extra Challenges
Expand Down
12 changes: 10 additions & 2 deletions pages/resources/lisp-workshop/step2.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ We've implemented a parser, and a pretty printer. It's time to update our REPL f

## Task

Implement a data structure for an AST, and a parser to match the following grammar:
Implement a data structure for an AST.
If you're using a functional-style language, you may want to use an algebraic data type to do this; if you're in an OOP-style language, you may want to use classes instead.

Next, you should write the lexer, which converts an input string into a list of tokens.

Once the lexer is complete, write a parser that converts a list of tokens into the corresponding syntax tree, represented by your AST data structure.
It should match the following grammar:

```ebnf
INTEGER ::= /[0-9]+/
Expand All @@ -212,7 +218,9 @@ Expr ::= Literal | '(' Expr* ')'
Program ::= Expr*
```

You should also implement a pretty printer that converts the AST back into a string. Hook these both into the REPL from the previous step, by parsing the user's input, and pretty printing the result.
Your language of choice likely has built in functions to convert a string to an integer (Python has `int`, Haskell has `read`, Rust has `string.parse::<i32>()`). You'll probably want to use one of these functions to determine if a literal is a symbol or an integer.

Finally, you should also implement a pretty printer that converts the AST back into a string. Hook these both into the REPL from the previous step, by parsing the user's input, and pretty printing the result.

### Hints

Expand Down
5 changes: 4 additions & 1 deletion pages/resources/lisp-workshop/step3.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,17 @@ We've finally defined everything we need to implement an evaluator!
## Task

Choose a set of arithmetic operations to be your primitives, and define a data structure that represents values in your language (literals and primitives).
This should look something like the following Haskell type:
This might look something like the following Haskell type:

```hs
data Prim = Plus | Minus | Mult | ...
data Value = VInt Integer
| VPrim Prim
```

You should also write a pretty printer for this type, so you can print values.
Call this function `print`.

Next, define a function called `eval`, which takes an AST as its only parameter, and reduces any redexes, returning the resultant value.

Update your REPL function, by running `eval` on the parsed input, and passing the resulting value into `print`. You now have a fancy calculator!
Expand Down

0 comments on commit 65fb874

Please sign in to comment.