I have developed a compiler&interpreter using the tools: FLEX and BISON (C Language) from MIL to MIN.
The lexical analyzer should take as input a MINI-L program, parse it, and output the sequence of lexical tokens associated with the program.
The software takes a syntactically-correct MINI-L program (a program that can be parsed without any syntax errors), verify that it has no semantic errors, and then generate its corresponding intermediate code.
A source program in MINI-L will be translated by the compiler into an intermediate code program, and that intermediate code program will be the input to the interpreter which will take the intermediate code, execute it and give the final results.
The MINI-L Language has the following features:
- Integer scalar variables.
- Unidimensional arrays of integers.
- Assignment statements.
- While loops.
- If-then-else statements.
- Read/Write statements.
In MINI-L a comment is introduced by “- -” and goes to the end of the line. All tokens are separated by blanks, tabs, newlines, delimiters, operators or comments. A valid identifier begins with a letter and may be followed by additional letters, digits or underscores. The length of an identifier does not exceed 8 characters. Finally, MINI-L is case sensitive with all reserved words written in lower case.
Error Handling for the use of variables that have not been declared at the beginning of the program
Error Handling for a declaration of the same variable multiple times
Error Handling in the use of an array variable as a normal integer variable
Error Handling negative array size
Error management use of an array index greater than the maximum size declared (in the case where the index is a number)
Management error identifier with less than 8 characters long and ends with ‘_’
Management error identifier with more than 8 characters
Syntax diagrams describing the syntax of MINI-L are given to you. Your first task in this assignment
is to develop a context-free grammar from the syntax diagrams. The parser will get the necessary information about the tokens from the lexical analyzer.
Each line in the MIN file
1. contains at most one MIL instruction
2. Each line is at most 254 characters long
3. All variables are defined before they are used
Code Source Example:
a,b : array(1000) of integer;
c : array(10) of integer;
beginprogram — main program
– test op
– test if
if x>0 and n==d or a(10)>=c(n)
then d:=d*d*d*d; endif;
d:=11; d:=x; a(10):=2; a(10):=c(2);
– test if-else
– test while
while x<-10 or not c(2)!=0 loop
– test read
. a, 1000
. b, 1000
. c, 10
/ t0, 20,n
+ t4, x,t3
== p1, n,d
?:= L000 ,p5
* t11, d,d
* t12, t11,d
* t13, t12,d
/ t15, 20,n
+ t16, x,t15
– t18, x,t17
?:= L001 ,p7
?:= L002 ,p9
* t22, d,x
* t23, 20,n
< p10, x,t24
!= p11, t25,0
! p12, p11
?:= L005 ,p15