Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions