The ZINC Programming LanguageCOSC 4316, Spring 2018IntroductionZINC (for ZINC Is Not C) is a language that is similar to Ada. It is designed to provide you the experience writing a compiler without getting burdened by all of the complexities and details of a complete, standard programming language. (ZINC is adapted from an instructional language formerly used by Michael Franz in his CS241 course at University of California, Irvine.)Example ZINC Program 1 program
2 var N : integer;
3 var SQRT : integer;
4 begin
5 N := readInt;
6 SQRT := 0;
7
8 -- go until SQRT exceeds the square root of N }
9 while SQRT * SQRT ", "", less than "" | "" | "Keywords:· IF = "if"· THEN = "then"· ELSE = "else"· BEGIN = "begin"· END = "end"· ENDIF = "endif"· ENDWHILE = "endwhile"· WHILE = "while"· LOOP = "loop"· PROGRAM = "program"· VAR = "var"· INT = "integer"Built-in Procedures:· WRITEINT = "writeInt"· READINT = "readInt" BNF Grammar ::= PROGRAM BEGIN END ::= VAR ident COLON SC | ε ::= INT ::= SC | ε ::= | | | | ε ::= ident ASGN | ident ASGN READINT ::= IF THEN ENDIF ::= ELSE | ε ::= WHILE LOOP ENDWHILE ::= WRITEINT ::= | COMPARE ::= ADDITIVE | ::= MULTIPLICATIVE | ::= POWER | ::= ident
| num
| LP RPOperator Precedence and AssociativityThe order of precedence among the operators is:1. The POWER operator.2. The MULTIPLICATIVE operators.3. The ADDITIVE operators.4. The COMPARE operators.All binary operators are left-associative.Type Rules1. The operands of all MULTIPLICATIVE, ADDITIVE, and COMPARE operators must be integers2. The MULTIPLICATIVE and ADDITIVE operators create an integer result.3. The COMPARE operators create integer results (0 = “false”, non-zero = “true”);4. All variables must be declared, and may be declared only once.5. The left-hand of assignment must be a variable, and the right-hand side must be an expression of the variables type.Semantics· Only those variables which have been declared can be assigned to or used.o All integer variables and array elements are considered to have initial values of "0".· All binary operators operate on signed integer operands:o "x * y" results in the product of x and y.o "x div y" which results in the integer quotient of x divided by y. The behavior. is not defined if y is 0.o "x mod y" results in the remainder of x divided by y when x is non-negative and y is positive. Otherwise, the result is undefined.o “x ** y” results in x being raised to the power of y when y is non-negative. Otherwise, the result is undefined.o "x + y" results in the sum of x and y.o "x - y" is the difference of y subtracted from x.o "x = y" is true if x and y are the same, otherwise it is false.o "x y" is false if x and y are the same, otherwise it is true.o "x y" is true if x is greater than y, otherwise it is false.o "x o Computations on ZINC integers should be done using a 32-bit 2s complement representation. Overflowing computations should simply "wrap around"; that is, the result of all integer operations should be the integer that is not less than -231, not more than 231-1, and congruent modulus 232 with the result of performing the normal mathematical operation on actual mathematical integers. · "if" statements evaluate their expression; if the expression is true, then the "then-statements" are executed, if it is false, the "else-statements" are executed.· "while" statements first evaluates its expression. If it is false, execution continues after the end of the "while" statement. If it is true, the statements in the body of the "while" loop are executed. After they finish executing, the expression is re-evaluated. As long as the expression is true, the process repeats itself, alternatively evaluating the expression and executing the statements in the body. Once the expression is false, execution continues after the end of the "while" loop.· "writeInt" evaluates its expression and outputs the result to the console and causes the cursor to move to the beginning of the next line.· "readInt" reads an integer from the console and updates an integer variable to hold that value.Write a program which contains a lexical analyzer for the ZinC programming language described in the document posted on Blackboard. The input to the program is a ZinC program. The output will be a sequence ofif, while, etc.) is up to you. You can preload the symbol table with them, OR you can have the lexical analyzer handle them as a special case. When the lexical analysis is finished, you should print out the contents of the symbol table you generated.For example if your program file starts: 1 program
2 var N : integer;
3 var SQRT : integer;
4 begin
5 N := readInt;Then your output would be:Your program should be able to determine if an input source file (such as myprog.znc) has been passed as a shell argument. If no valid argument is given then a usage message should be printed and the use allowed to input the filname of a ZinC language program. Output should go to standard outpu