Tutorial 4

1 0 0
Tutorial 4

Đang tải... (xem toàn văn)

Thông tin tài liệu

Exercise 3 COMPILER CONSTRUCTION Week 9 Tutorial Questions Syntax Directed Translation 1 Write a syntax directed definition based on the following grammars to calculate the value of a binary number a[.]

COMPILER CONSTRUCTION Week Tutorial Questions Syntax-Directed Translation Write a syntax-directed definition based on the following grammars to calculate the value of a binary number a B → B | B | | b B → B | B | | Given the following grammar for an assignment expression, write a syntaxdirected definition to check if the LHS of an assignment is id Otherwise, print out “error” E→T=E|T T→T+F|F F → id | num | ( E ) Let a constant expression be an expression whose operands are constants or constant expressions Given the following grammar for an expression, construct a translation scheme to print out “Divide by zero” if the denominator in a divide expression is a constant-expression and its value is E → T E’ E’ → - T E’ | / T E’ | ∈ T → id | num | ( E ) Transform the following translation scheme such that the attributes of its nonterminals can be evaluated by a top-down parser A → A1 B { A.a = f(A1.a, B.b) } A → C { A.a = g(C.c) } Transform the following translation scheme such that its semantic actions can be performed by a bottom-up parser D → T { L.in = T.type } L D → T [ ] { L.in = new ArrayType(T.type) } L T → int { T.type = new IntType() } T → float { T.type = new FloatType() } L → { L1.in = L.in } L1 , id { addtype(id.entry,L.in) } L → id { addtype(id.entry,L.in) } Hint: Read pages 311-315 of text book

Ngày đăng: 11/04/2023, 11:05

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan