CS253: Software Development with C++

Fall 2020

HW 1

CS253 HW1: Tokens!

Changes

Stress that input comes from cin.                 

Description

To compile any programming language (e.g., C++, Java, Python), the first step is tokenizing, turning the “words” of the input into tokens. For example, in C++, some tokens are: while, int, ++, *=, 12, 34.567, "hello". The process of breaking a source stream into tokens is called Lexical Analysis.                 

For this assignment, you will write a C++ program called hw1 that will read from standard input, and writes the corresponding tokens to standard output, one per line.                 

Your program does not open a file. It reads from standard intput via cin. It does not use <fstream> or ifstream.                 

Input Format

The input will be any number of lines, containing tokens. Here are the valid tokens:                 

Sample Run

Here is a sample run, where % is my prompt.                 

% cat data
# Celsius to Fahrenheit converter
# °F = °C × 9/5 + 32
# 212°F = 100°C
#  32°F =   0°C

    # Input: A contains Celsius temperature

A *= 9      # °C × 9
A /= 5      # °C × 9/5
A += 32     # °C × 9/5 + 32
f = a       # Put it in F for Fahrenheit

Z = 0       # Constants have no sign, so compute a negative number.
Z-=459      # absolute zero (should really be −459.67°F)

iFF<=ZF=ZfI#If temperature is too low, make it absolute zero.

print F

% cmake .
… cmake output appears here …
% make
… make output appears here …
% ./hw1 <data
a
*=
9
a
/=
5
a
+=
32
f
=
a
z
=
0
z
-=
459
if
f
<=
z
f
=
z
fi
print
f

Hints

Debugging

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements

If you have any questions about the requirements, ask. In the real world, your programming tasks will almost always be vague and incompletely specified. Same here.                 

Tar file

    cmake . && make

How to submit your work:

In Canvas, check in the file hw1.tar to the assignment “HW1”.                 

How to receive negative points:

Turn in someone else’s work.