Lexical Analyzer Using Fibers
Write a table-driven lexical analyzer, using Fibers. Your lexical analyzer should perform the following translations:
|
Sequence name |
Description |
Cd output |
Vl output |
|
C name |
a sequence of letters and digits beginning with a letter |
0 |
index of this name in Sym[] |
|
C integer constant |
a sequence of digits |
1 |
decimal value |
|
string |
a sequence of characters other than '"' surrounded by '"' characters |
2 |
index of this string in Str[] |
|
comment |
a sequence of characters surrounded by the sequences '/*' and '*/" |
nothing |
nothing |
|
whitespace |
a sequence of space, tab, and new-line characters |
nothing |
nothing |
|
operator |
a single symbolic character from the set:: + - * / % & | [ ] { } ( ) < > ; |
3 |
position number (starting at 0) of this operator in the list of column 2 |
The output is thus a sequence of entries in the arrays "Cd" and "Vl", together with entries in String arrays "Sym" and "Str". Your lexical analyzer should read a sequence of characters ended with an EOF from stdin, and create the arrays above using Fibers. Actual processing of the input characters should be timed, but not Initialization of the tables. After lexical analysis is complete, the arrays should be dumped to stdout, printing one line for each (Cd, Vl) pair, and accompanying each pair representing a string or name with that string or name extracted from table Sym or Str. You need not surround these strings with '"' marks.
In a real lexical analyzer, all occurrences of a given name would be mapped to the same entry of Sym[]. That is not necessary in this version. However, as part of the report for this project, determine how a hash-table search could be added to your lexical analyzer. Consider what synchronization mechanisms would be most useful for this purpose, and give particular attention to minimizing the time during which any one fiber might have to delay, because some other fiber is using a shared variable.