diff --git a/pages/resources/lisp-workshop/step1.md b/pages/resources/lisp-workshop/step1.md index 35fe1b8..a836e7f 100644 --- a/pages/resources/lisp-workshop/step1.md +++ b/pages/resources/lisp-workshop/step1.md @@ -15,7 +15,13 @@ 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 @@ -23,8 +29,10 @@ 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 diff --git a/pages/resources/lisp-workshop/step2.md b/pages/resources/lisp-workshop/step2.md index 6af2a06..8b1c657 100644 --- a/pages/resources/lisp-workshop/step2.md +++ b/pages/resources/lisp-workshop/step2.md @@ -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]+/ @@ -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::()`). 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 diff --git a/pages/resources/lisp-workshop/step3.md b/pages/resources/lisp-workshop/step3.md index 694ef32..024a03c 100644 --- a/pages/resources/lisp-workshop/step3.md +++ b/pages/resources/lisp-workshop/step3.md @@ -180,7 +180,7 @@ 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 | ... @@ -188,6 +188,9 @@ 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!