You are on page 1of 1

 MIDTERM TEST

COMPILER CONSTRUCTION
(90 minutes- Open book)
Question 1

a/ Write a program in KPL to read n integers (n  10) into array A , print the input values from last to
first, then print the sum of the elements.

b/ Change yoủ code so that it causes error “Invalid term”. Explain why.

Question 2 .
Note: The functions you are required to build are parts of project Parser used in practice exercise No 2.
You must use the data structures declared in project Parser.

a/Rewrite function void compileArguments(void) and relevant functions to match the


following syntax rules:
Arguments ::= SB_LPAR Arguments1 SB_RPAR
Arguments1 ::= Expression Arguments2
Arguments1 ::= 
Expression Arguments2
Arguments2::= SB_COMMA Expression Arguments2
Arguments2::= e

b/ Write function void readIdentKeyword (void) satisfying the following rules:


 Identifiers are made up of letters and digit;
 Upper and lower case letters are not distinct
 Only the first 15 characters are significant.
 Keywords are reserved: you can’t use them as variable names.
 All the keyword must use upper letters.

You might also like