munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
9.02k stars 1.06k forks source link

Chapter 8 Challenge Suggestion #475

Closed jptemplin closed 5 years ago

jptemplin commented 5 years ago

A "small" challenge for Chapter 8. Change the grammar for print statements to

printStmt → "print" expression? ";" ;

which would implement printing blank lines by simply saying

print;

My printStatement() in Parser.java:


private Stmt printStatement() {  
  Expr value;
  if (match(SEMICOLON)) {
    value = new Expr.Literal("");
  }            
  else {
    value = expression();                    
    consume(SEMICOLON, "Expect ';' after value.");
  }
  return new Stmt.Print(value);                 
} 
munificent commented 5 years ago

That's not a bad idea, and I always like seeing people tweak Lox, but I feel like it's a little too small scale to be challenging enough to put in the book. Thanks, though!

jptemplin commented 5 years ago

I thought as much. Was just a fun thing.

Sending you some love here…

I’ve been really enjoying working through “Crafting”. Jlox is done and I’m working on clox. I find your explanations very clear, and your sidebars very insightful and, frankly, entertaining.

“Crafting” has pointed me to your game book, and I found your cache locality writing (and its echo in “Crafting”) illuminating. I’m a retired MS in CS grad and now I’m wishing I done some things differently in projects from my past career. ;-)

I never wrote compilers outside school (reading the Dragon book as an undergrad), but I’ve have always loved the subject (I love your term “language hacker”). I was a last-century, old-school unix C++ developer using text editors and command line compilers. I recently learned C# and Visual Studio (Roslyn is amazing) to work on a fun project I give away for free (livingcookbookrescue.com). I used a DFA to parse cooking recipe ingredient quantities. My C# learning journey is what pointed me to “Crafting”.

Looking forward to your finishing the clox chapters.

Jon T.

From: Bob Nystrom [mailto:notifications@github.com] Sent: Saturday, August 3, 2019 12:08 AM To: munificent/craftinginterpreters < craftinginterpreters@noreply.github.com> Cc: jptemplin jon@twinpalmshome.com; Author author@noreply.github.com Subject: Re: [munificent/craftinginterpreters] Chapter 8 Challenge Suggestion (#475)

That's not a bad idea, and I always like seeing people tweak Lox, but I feel like it's a little too small scale to be challenging enough to put in the book. Thanks, though!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/munificent/craftinginterpreters/issues/475?email_source=notifications&email_token=AMH75FPB2MYXQ422OPBJU2DQCUABNA5CNFSM4IHOFM7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3PGRYA#issuecomment-517892320, or mute the thread https://github.com/notifications/unsubscribe-auth/AMH75FNYGXZBG4PFGTL5EGLQCUABNANCNFSM4IHOFM7A .