Due: Tuesday, Oct 12th by 11:59 PM
Updated 10/12 - fixed the fourth example string
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.
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.
A primitive-literal is one of the following
- an integer_literal
- a boolean_literal
- a string_literal
An atom is one of the following
- a primitive-literal
- 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):
- an atom
- a list
An expression is one of the following:
- an atom
- a list-literal
- an if-expression
- a let-expression
- a lambda-expression
- a function-application
A list-literal has the form
( quote list-or-atom )
An if-expression has the form
( if expression expression expression )
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 )
A lambda-expression has the form
( lambda ( formals-list ) expression )
A formals-list is a sequence of zero or more occurrences of identifier.
A function application has the form
( expression arg-list )
An arg-list is a sequence of zero or more occurrences of expression.
A top-level-item is one of the following:
- an expression
- a definition
A definition has the form
( define identifier expression )
A program is a sequence of one or more occurrences of top-level-item.
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.