Jim's
Tutorials

Spring 2019
course
site

Nick says...

To get used to the syntax of racket, I tackled euler problem 1, the fizzbuzz problem. Here's my little racket fizzbuzz :)

#lang racket
;fizzbuzz: print fizz if x is a multiple of 3,
;          print buzz if x is a multiple of 5,
;          print fizzbuzz if x is a multiple of both 3 and 5
;          else print the number

(define TOP 1000)
(define fizzbuzz_input (range 1 (add1 TOP)))

(define (fizzbuzz x)
  (cond
    [(and (= (modulo x 3) 0) (= (modulo x 5) 0)) (and (print "fizzbuzz") (newline))]
    [(= (modulo x 5) 0) (and (print "buzz") (newline))]
    [(= (modulo x 3) 0) (and (print "fizz") (newline))]
    [ else (and (print (number->string x))(newline))]))

(for ([i fizzbuzz_input]) (fizzbuzz i))

I also read matt might's article Lexical analysis in Racket and chapter 2 of Basics of Compiler Design to get an idea of what a lexer/lexical analysis is.

Jim says

All sounds good.

I tried to give an overview of some of the coming ideas in my office :

What's a grammar? I showed some BNF and extended-BNF versions of what a grammar is for example python grammar.

You should understand using a grammar to "generate" sentences as opposed to "parsing" a sentence into a "parse tree" using a grammar.

I mentioned Damian Conway's Parse::RecDescent cool paper with Abbot & Costello parsers ("The man(1) of descent").

The Context Free Art site is an example of grammars generating trees (images in this case). You might want to take some of their code and turn it into (something like) EBNF as an exercise.

So : continue on with Racket. Don't get too bogged down in the DFA/NFA stuff.

https://cs.marlboro.college /cours /spring2019 /jims_tutorials /ncreel /jan24
last modified Sat April 27 2024 4:40 pm