1 This is the first trial line in the file,Try the problem once using fgetc() function and once using fgets() function for reading the input. Why is fread() not suitable for this purpose?
2 and this is the second line.
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
Asignment 2
Write a lexical analyser for the assembly language discussed in the theory class. The program should take as input a text file containing an assembly program and print the stream of token values corresponding to the items in the input file. For identifiers and numbers the actual input item should also appear within brackets along with the token value. e.g. the output may look like:
17 20(100) 21(AGAIN) 14 20(3) 21(TERM) ....
Write the program once in plain C, and once using flex utility.
[Create the file token.h to put the token definitions. In the plain C implementation, you should also define the mnemonic table containing the mnemonic strings and the corresponding numeric token values.]
Asignment 3
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 the numeric opcode on the terminal in
readable format, and in an output file in binary format. 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.
[You will have to define a mnemonic-table for this program]
Asignment 4
For the assembly language discussed in the theory class, write a program that
reads a file containing an assembly language program, and prints the message
"CORRECT" if the program is (syntactically) correct and "ERROR n" if the
program is correct only upto line number n-1 (i.e., if there is an error in
line number n).
[Use a Finite State Machine for this exercise]
Asignment 5
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 6
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 7
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]