CS 241 Tutorial 1
Rob Schluntz
January 13, 2012
The Fibonacci numbers are a sequence of integers in which each number in the sequence is
derived from the recursive formula
fn = fn1 + fn2
Where f0 = 0 and f1 = 1 and n 2
1
Introduction
If you have a proble
CS 241 Tutorial 7
Semantic Analysis
Week 10, Fall 2011
Tutorial Topics
Checking for declaration errors
Checking for type errors in expressions
Checking for other type errors
Declaration Errors
For each WLPP program below, point out the error in the pro
CS 241 Tutorial 1
Week 3, Fall 2011
The Fibonacci numbers are a sequence of integers in which each number in
the sequence is derived from the recursive formula
fn = fn1 + fn2
Where f0 = 0 and f1 = 1 and n 2
1
Introduction
If you have a problem that you w
CS 241 Tutorial 8
Code Generation & Extending WLPP
Week 11, Fall 2011
Code Generation Conventions and Tips
These are not mandatory, but following them might make it easier to write your compiler.
All expressions should store their result in $3. Being con
CS 241 Tutorial 6
LL and LR Parsing
Week 9, Fall 2011
Tutorial Topics
Parsing LL(1) languages (topdown)
Parsing LR(1) languages (bottomup)
Denitions
LL(1) stands for Lefttoright scan of input, Leftcanonical derivation, 1 symbol of lookahead.
LR(1
CS 241 Tutorial 5
Regular Expressions, Scanning, and Context Free Grammars
Week 8, Fall 2011
Tutorial Topics
Specifying languages with regular expressions
Scanning with Maximal Munch (simplied and nonsimplied)
Derivations with contextfree grammars
Sc
WLPP Programming Language Tutorial
WLPP in a nutshell for Java or C+ Programmers
A WLPP program is a C+ function named wain that has two parameters. The type of the first parameter
is either int or int*. The type of the second parameter is int. The type o
WLPP Programming Language Specification
The WLPP programming language contains a strict subset of the features of C+. A WLPP source file
contains exactly one procedure definition.
Lexical Syntax
A procedure definition is a sequence of tokens optionally se
CS 241 Tutorial 2
CS 241
Week 3
1
Problem 1a
Given the following MIPS assembly code, create a symbol table containing all of the labels used.
; Assume program is to be run with mips.twoints
; $1  first integer
; $2  second integer
lis $3
.word 100
bound
CS 241 Tutorial 3
Rob Schluntz
Winter 2012
1
Loading
Loading is the process of taking a program from disk or other forms
of secondary storage into main memory. It is typically provided by
the operating system.
Memory
Load
Mips
Program
1
=?
2
Relocation
Re
CS 241 Tutorial 4
CS 241 Tutor
February 3, 2012
1
Formal Languages Denitions
Alphabet
An alphabet (denoted ) is a nite set of symbols.
Example
cfw_a, b, c
cfw_b
cfw_to, be, or, not
cfw_0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Word
A word (over an alphabet ) is
CS 241 Tutorial 7 Solution
Rob Schluntz
February 17, 2012
1
Context Free Grammar
Formal Denition
A contextfree grammar is a 4tuple (V, , S, R) where:
V a nite set of nonterminals (variables)
a nite set of terminals (alphabet symbols)
S V the starting
CS 241 Tutorial 5
CS 241 Tutor
February 10, 2012
1
Regular Expression (RE)
The empty word. NOTE: this is dierent from .
R1 R2 where R1 RE and R2 RE
words matched by R1 followed by words matched by R2
R1 R2 where R1 RE and R2 RE
words matched by R1 OR b
CS 241
Section
001
002
003
Foundations of Sequential Programs
Time
2:30 3:20 MWF
8:30 9:20 MWF
4:30 5:20 MWF
Location
MC 1085
MC 1056
MC 2054
Instructor
Ondej Lhotk
r
a
Jason Hinek
Ondej Lhotk
r
a
Oce
DC 2520
DC 3322
DC 2520
Phone
x36654
x37520
x36654
Fal
CS 241 Tutorial 2
Assemblers and Assembling
Week 4, Fall 2011
Tutorial Topics
Keeping track of labels with the symbol table
Assembling and outputting MIPS instructions
Recognizing invalid assembly programs
Problem 1
What should the symbol table contain fo
CS 241 Tutorial 3
Relocation and Linking
Week 5, Fall 2011
Tutorial Topics
Adding relocation information to a MIPS program
Linking two MERL les together
Relocation
Given the program below, answer the following questions:
Which lines contain values that
; Example 6b: A procedure
; sumOneToN: sum the integers from 1 to N
; input: $2 is N
; output: $3 is the sum
sumOneToN:
sw $1, 4($30)
; save $1 on stack
sw $2, 8($30)
; save $2 on stack
lis $1
.word 8
sub $30, $30, $1
add $3, $0,
beginLoop:
add $3, $3,
li
Example 3.
$1 is the address of the beginning of an array of 32bit integers.
$2 is the number of elements in the array.
Read element 5 of the array into $3, and return.
MIPS Machine code:
binary

hex
 location meaning


 ; load 5 into $5
00000000 000
CS 241
Fall 2011 Midterm Review
October 26th, 2011
Topics
Bits, bytes and words
MIPS assembly language programming
Assembler concepts
Loading, relocation and linking
Formal languages and nite automata
Any problem labelled exercise may be briey discus
The Assembler
The Assembler
the assembler consumes assembly code and generates equivalent
machine code (and some other things as we'll see later)
it translates assembly into machine language
this translation consists of two parts
Analysis understanding w
Machine Language
previously, in cs241.
put 201 into $3 (load immediate and skip)
put 200 into $19 (load immediate and skip)
put $19  $3 into $1 (subtract)
return (jump register)
machine language looks like
Mem
000
004
008
012
016
020
Instruction/Data
000
ContextFree Languages
A
contextfree grammar
is a 4tuple (V , , P , S ), where
V is a nite set of nonterminals
(variables/symbols)
is a nite set of terminals
(alphabet symbols)
P is a nite set of productions
(rules)
S V is the start nonterminal
(star
ContextSensitive Analysis
WLPP
Use parse tree (from parser) to.
1 Build symbol table
used to detect duplicate declarations
used to detect undeclared variables
2 Check that all types are correct
compute types for everything
check that everything is wellt
Using Scheme in CS 241 (F08) 1 Purpose
This is a guide to using PLT Scheme v4.0 for assignments in CS 241. We will assume that students know the basics of Scheme from CS 135 and CS 136. Useful references include the Guide and Reference in DrSchemes Help D
begin 0
label 0
after 8
abc0 16
abc1 16
loadStore 20
end 28

unsigned int w = .;
/ print_byte range is 0 . 0xFF
void print_word(unsigned int w) cfw_
print_byte (w > 24); / 0x0000000B
print_byte ( (w > 16) & 0xFF); / 0x000000AD
print_byte ( (w > 8) & 0
Using Racket in CS 241
1
Purpose
This is a guide to using Racket 5.3 for assignments in CS 241. We will assume that students know
the basics of Racket from CS 135 and CS 136. Useful references include the Guide and Reference
in DrRackets Help Desk, the R5
CS 241 Fall 2016 Assignment 9
Assignment 8
Thursday, November 17, 2016 at
7:00 pm
Assignments for CS 241
Assignment 9
Assignment 10
Thursday, November 24, 2015 at Monday, December 5, 2016 at 11:59
7:00 pm
pm
P1 P2 P3 P4 P5 P6 P7 P8
In assignments 9 and 1
CS 241 Fall 2016 Assignment 8
Assignments for CS 241
Assignment 7
Assignment 8
Thursday, November 10, 2016 at Thursday, November 17, 2016 at
7:00 pm
7:00 pm
P1 P2 P3 P4 P5 P6
Assignment 9
Thursday, November 24, 2016 at
7:00 pm
In Assignment 8, you will
CS 241  WLP4 Programming Language Specification
The WLP4 programming language contains a strict subset of the features of C+. A WLP4 source file contains a
sequence of procedure definitions, ending with the main procedure wain.
Lexical Syntax
A procedure