Question: Here, you will define a syntax-directed translation for the CFG given below, which defines a very simple programming language. program MAIN LPAREN RPAREN LCURLY list

Here, you will define a syntax-directed translation for the CFG given below, which defines a very simple programming language. program MAIN LPAREN RPAREN LCURLY list RCURLY list list oneItem | epsilon oneItem decl | stmt decl BOOL ID SEMICOLON | INT ID SEMICOLON stmt ID ASSIGN exp SEMICOLON | IF LPAREN exp RPAREN stmt | WHILE LPAREN exp RPAREN stmt | LCURLY list RCURLY exp exp TIMES exp | exp DIVIDE exp | exp PLUS exp | exp LESS exp | exp EQUALS exp | LPAREN exp RPAREN | ID |BOOLLITERAL | INTLITERAL Question 1: Write a syntax-directed translation for the CFG given above to extract all the int and bool literals. Your translation rules should use the following notation: { } is an empty set { INTLITERAL.value } is a set containing the value of the INTLITERAL token { BOOLLITERAL.value } is a set containing the value of the BOOLLITERAL token S1 S2 is the intersection of sets S1 and S2S1 S2 is the union of sets S1 and S2 S1 S2 is the set of all items that are in S1 but not in S2 Note that you should not try to use something like "{ a, b }" to mean a set with two elements; instead, use set union to combine two sets that each contain one element. Use the notation that was used in class i.e., use nonterminal.trans to mean the translation of a nonterminal, and terminal.value to mean the value of a terminal. Assume that ID.value is a String (the name of the identifier). Use subscripts for translation rules that include the same nonterminal or the same terminal more than once.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!