Write a program that takes from the user the name of a file and a "field-number", and then reads that file and for each line in that file prints on the terminal word at position "field-number". For example if there are the following lines in the specified file -
C is a programming language.and if the field-number specified is 4, then the output of the program is -
lex produces a lexical analyser
cc is a compiler
programming
lexical
(NULL)
compiler
This exercise should enable the student to deal with individual words in a text file.
Asignment 2
For the assembly language discussed in the theory class, write a program that reads a file containing an assembly language program, and for each statement in the assembly program it prints on the terminal the numeric opcode. Also it should build the symbol table that contains each symbol encountered in the assembly program along with the line number in which that symbol is defined. After analysing all the lines and printing the opcodes, the symbol table should be printed on the terminal.
Asignment 3
For the assembly language discussed in the theory class, create a lexical analyser using flex utility of Linux. Use this lexical analyser in a program that detects the following errors along with corresponding line numbers in input assembly language programs-
Asignment 4
Assume that in the assembly language discussed in the theory class, there is a statement -
DEFINE name replace-patternThe meaning of the statement is that afterwards in the program wherever the pattern name occurs, it will be replaced by replace-pattern. For example if there is the statement DEFINE TRUE 1, then everywhere in the subsequent part in the program if there is the word TRUE, it will be replaced by 1. An input program may contain several such define statements. Write a program to implement this feature.
[This is a very simple macro pre-processor]
Asignment 5
For the assembly language discussed in the theory class, write a program that reads a file containing an assembly language program, processes the different types of statements (imperative statements, declarative statments and assembler directives) appropriately, and produces a relocation table for the program. The program should write this table in a file as binary data (i.e., non-ASCII format) as well as print this table on the terminal in readable format.
[Appropriate location counter processing is very important in this exercise. The size of each instruction is to be maintained in the mnemonic opcode table. The ideas/routines developed for the previous assignments may be used in this assignment]