session1 【Objective and Requirement】 Objective: Be familiar with the creation of process and thread on Windows. Requirement: Sub Task 1: Create a console application, "child", which keeps printing out "The child is talking at [system time]" (in a loop, one per 1s). Sub Task 2: Create another console application, "parent". It create a child process to execute “child”. The "parent" process keeps printing out "The parent is talking at [system time]". (one per 1s) Execute "parent" and explain the output you see. Sub Task 3: Create a "winPS" program which can output information about all the running processes. Try to output details about each process, such as PID, executable file name and path, etc. Sub Task 4: In the "mainThread" program, use "CreateThread" to create a child thread. Both the main thread and the child thread keep printing out "[ThreadID] + [System time]". session2 Objective: Create "ps" and "kill" commands on Windows. Requirement: Sub Task 1: On Linux/Unix there are a "ps" command and a "kill" command. The "ps" command can list information about all the running processes. The "kill" command can terminate processes. Based on the tasks finished in Session 1, create "ps" and "kill" commands on Windows. Tips: using "TerminateProcess" to "kill" a process. session3 Objective: Learn how to use semaphore to solve IPC problems. Requirement: Task 3.1. Sleeping barber Use semaphores to solve the problem of sleeping barber. Task 3.2. Reader & Writer Use semaphores to solve the reader and writer problem, with the readers (and writers) have higher priority. session4 Title: Upgrade Linux/Unix commands Problem: Write a program "supershell" that takes another command as an argument and executes that command. For instance, executing: “./supershell cat /usr/greg/readme" would invoke the cat command on the file /usr/greg/readme. After execution of the specified command has completed, "supershell" should display statistics that show some of the system resources the co
1
Compiler Construction Experiment 1 Implementing a Scanner for TINY+ You are to write a lexical analyzer/scanner for the language TINY+. Goals 1The input of the scanner is a source code file and the output of the scanner is a stream of tokens. 2Your scanner should go for longest possible match i.e. a string ‘:=’ is to be identified as ‘ass-symbol’ rather than ‘:’ and ‘=’. 3Token is represented as (Kind, Value). We use the following symbols to denote different kinds of tokens KEY denotes reserved words SYM denotes special symbols ID denotes identifiers NUM denotes numeric constants STR denotes string constants 4Check lexical errors: giving meaning error messages and the lines where errors occur. The kinds of lexical errors are: Illegal character, that is, scanner may recognize a character that is not in the alphabet of TINY+, such as $ is an illegal character The right bracket of a STRING is lost, such as ' scanner The right delimiter of a comment is lost, such as: {this is an example Requirements 1Write your program in C or C++ 2This experiment must be finished in 4 periods. You will submit a report and the source code Example output for some TINY+ programs Test1 or and int bool char while do if then else end repeat until read write , ; := + - * / ( ) = a2c 123 'EFG' The scanner should give the outputs: (KEY, or) (KEY, and) (KEY, int) (KEY, bool) (KEY, char) (KEY, while) (KEY, do) (KEY, if) (KEY, then) (KEY, else) (KEY, end) (KEY, repeat) (KEY, until) (KEY, read) (KEY, write) (SYM, ,) (SYM, ;) (SYM, :=) (SYM, +) (SYM, -) (SYM, *) (SYM, /) (SYM, ( ) (SYM, )) (SYM, ) (SYM, =) (ID, a2c) (NUM, 123) (STR, EFG) Test2 {this is an example} int A,B; bool C1, C2, C3; char D; D:= 'scanner'; while A<=B do A:=A*2 end The scanner should give the outputs: (KEY, int) (ID, A) (SYM, ,) (ID, B) (SYM, ;) (KEY, bool) (ID, C1) (SYM, ,) (ID, C2) (SYM, ,) (ID, C3
1