C | Homework 2 – Scanner Implementation

Homework 2 – Scanner Implementation

Abstract
The task of this assignment is to implement a DFA-based scanner for the C-minus language.
1 Introduction
A scanner is a part of a compiler, which obtains a sequence of tokens from the source file. The design of this homework is partly designed by two textbooks written by Louden and Appel respectively [2] [1].

————————————————————————————————————————————————————————————————————————————————————————————–

A picture of a mechanical watch. Making a watch is similar to making a compiler.

2 Preparation
Download the provided code files for this homework from the ftp site.
Read and understand the provided files. The code folder contains the following:
– cm : A folder containing some source code programs, which will be used to test your scanner.
– DFA_graph : A folder containing the jflaps file (.jff) of the DFA that is designed as the scanner. The screeshots (.jpg) of the jflap windows are also included. These DFA graphs are not complete, but should have shown the ideas. You are supposed to understand how to complete the full DFA graph.
– linux : A folder containing the .o files and makefile for compiling the scanner program on linux using gcc. A sample executable file is also provided. The provided .o files are existing tools, you need to compile the .c files to generate other needed .o files to link them into an executable file.
To compile the program, or remove generated files, we can use the commands:
make all
or,
make clean
respectively.
– mac : A folder containing the .o files and the makefile for compiling the scanner program on linux using gcc. A sample executable file is also provided.
– windows : A folder containing two folders:
gcc : The .o and files and makefile for compiling the scanner program on windows using gcc. A sample executable file is also provided.
cl : The .obj files and the makefile for compiling the scanner using cl. A sample executable file is also provided.
– .c and .h files: The provided source code of this program. You need to provide the missing code in some .c files. Details are described in Section 4.
Try the provided sample executable file to see how the scanner runs and how it can be used.
3 Tasks to do
1. Provide the missing code of the following parts in the program. You can see the special comments in the files marking the places that you need to provide code.
In the file util.c : the function clone_string_section() .
In the file scan.c : the function scan()
In the file cminus_dfa.c :
– The definitions of the transition functions for the states from 6 to 55, that are the functions t6() to t55() .
– The initialization statement of the array states .
2. Bonus (+10 points): Modify the provided DFA file to handle the logical operators of C: && , || , and ! . Modify the code so that these logical operators can be processed by your scanner. Test your scanner with a C-minus program where the logical operators are used.
4 Submitting your homework
At the top of the every file that you changed or provided content (maybe just the three .c files), record your name and student ID and date as comments.
Attach the following files as attachments to an email:
– The three .c files that you have changed or provided code with.
– Optional, the bonus part: The flap file of the DFA that you changed made for handling the logical operators,
– All the other related document files. You are welcome to write some textual file to record your ideas, experiences of solving prob-lems, and so on.
– If you implement the DFA by your own design, or if you have changed some other source code files, please attach all of them to the email, possibly zip them into a single file. Any information about how to run your code will be helpful.
Attention: Do not attach any binary files (.o, .obj, .exe, excecuta-bles), since google will consider them virus. Just send the source code and textual documents.
Send your email to:
The title (subject) of your email should be like:
[name][studentID][hmkNum info]
For example, if a student want to submit homework 1, whose name Shan Li, whose student ID is 123-45, then the title of the email should be:
[Li, Shan][123-45][hmk2 scanner]
References
[1] Andrew W. Appel. Modern Compiler Implementation in C: Basic Tech-niques. Cambridge University Press, New York, NY, USA, 1997.
[2] Kenneth C. Louden. Compiler Construction Principles and Practice.
PWS Publishing Company, 1997. ISBN 0-534-93972-4
http://www.cs.sjsu.edu/ ~ louden/cmptext/.

2017-01-01
The task of this assignment is to implement a DFA-based scanner for the C-minus language.

Java

physics

LINUX

C++

Python

Processing

sas

ios

maths

maple

C语言

Internet and World Wide Web

Principles of Programming Languages

sql

scheme

prolog

JavaScript

Haskell

essay

Finance

Accounting

Rust

Economics

算法分析(Algorithm analysis)

MATLAB

Ethics

Chemistry

LaTeX

OCaml

SPSS

Project

ASP

Stata

FORTRAN

Information system

SDLC

Basic

Digital Media

Biological

Android

ruby

HTML/CSS

Scala

PHP语言

C#

R语言

发表评论

了解 KJESSAY历史案例 的更多信息

立即订阅以继续阅读并访问完整档案。

继续阅读