Question: Please 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

Please 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 | LCURLY list RCURLY

exp exp PLUS exp | exp LESS exp | exp EQUALS exp | ID | BOOLLITERAL | INTLITERAL

Question :

Please write a syntax-directed translation for the CFG given above to extract all the boolean literals and integer literals.

Translation rules should use the following notation:

{ } is an empty set

{ BOOLLITERAL.value } is a set containing the value of the BOOLLITERAL token

{ ID.value } is a set containing the value of the ID token

S1 S2 is the intersection of sets S1 and S2

S1 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 and in the on-line readings; 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.

Please note that there might be similar questions of this kind, but they are not the same.

Thank you!

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!