YCP Logo Assignment 3: CFG for a Subset of Scheme

Due: Tuesday, Oct 12th by 11:59 PM

Updated 10/12 - fixed the fourth example string

Your Task

Your task for this assignment is to specify a context-free grammar for a subset of the Scheme programming language. The subset is described below.

See the section "Deliverables" below for information on what you should submit as your solution to the assignment.

Terminal symbols

The scheme subset has the following terminal symbols


In the rest of this assignment description, words and symbols in bold refer to terminal symbols. You will recognize these terminal symbols as the token types your lexical analyzer recognized in Assignment 1.


Two important constructs appear in many syntax rules, so we will define them here once and refer to them later.

Primitive Literals

A primitive-literal is one of the following

  1. an integer_literal
  2. a boolean_literal
  3. a string_literal


An atom is one of the following

  1. a primitive-literal
  2. an identifier


A list has the form

( list-items )

where list-items is a sequence of zero or more of the following (in any combination):

  1. an atom
  2. a list


An expression is one of the following:

  1. an atom
  2. a list-literal
  3. an if-expression
  4. a let-expression
  5. a lambda-expression
  6. a function-application

List literals

A list-literal has the form

( quote list-or-atom )

If expressions

An if-expression has the form

( if expression expression expression )

Let expressions

A let-expression has the form

( let ( let-pair-list ) expression )

A let-pair-list is a sequence of zero or more occurrences of let-pair. A let-pair has the form

( identifier expression )

Lambda expressions

A lambda-expression has the form

( lambda ( formals-list ) expression )

A formals-list is a sequence of zero or more occurrences of identifier.

Function application

A function application has the form

( expression arg-list )

An arg-list is a sequence of zero or more occurrences of expression.

Top-level items

A top-level-item is one of the following:

  1. an expression
  2. a definition

A definition has the form

( define identifier expression )


A program is a sequence of one or more occurrences of top-level-item.

Example strings

Updated 10/12 - fixed the fourth example

The following strings are all in the language your grammar should generate. Try deriving them (starting with your grammar's start symbol, which should generate a program).

( define identifier ( lambda ( identifier ) ( identifier identifier int_literal ) ) )
( if ( let ( ( identifier boolean_literal ) ) ( identifer identifier ) ) boolean_literal identifier )
( define identifier ( identifier ) ) ( identifier int_literal ) string_literal
( quote ( identifier int_literal ( int_literal boolean literal ) ) )


Submit a text document containing your grammar which derives a program from its start symbol. Make sure you clearly indicate which nonterminal symbol is the start symbol.

You should use italics to denote nonterminal symbols.


Upload your grammar as a plain text, MS Word, OpenOffice Writer, or PDF file as assign3. The URL of the submission server is:


IMPORTANT: after uploading, you should download a copy of your submission and double-check it to make sure that it contains the correct files. You are responsible for making sure your submission is correct. You may receive a grade of 0 for an incorrectly submitted assignment.