Skip to content

CS606 - Compiler Construction

8 Topics 68 Posts
  • 0 Votes
    3 Posts
    266 Views
    Uzma noorU

    @laiba-javed said in CS606 GDB 1 Solution and Discussion:

    Do you think intermediate code generation is extra and time consuming step while translating or it is necessary or beneficial in some way?

    Stack Allocation
    We now need to access the ARs from the stack. The key distinction is that the location of the current AR is not known at compile time. Instead a pointer to the stack must be maintained dynamically.

    We dedicate a register, call it SP, for this purpose. In this chapter we let SP point to the bottom of the current AR, that is the entire AR is above the SP. Since we are not supporting varargs, there is no advantage to having SP point to the middle of the AR as in the previous chapter.

    The main procedure (or the run-time library code called before any user-written procedure) must initialize SP with
    LD SP, #stackStart
    where stackStart is a known-at-compile-time constant.

    The caller increments SP (which now points to the beginning of its AR) to point to the beginning of the callee’s AR. This requires an increment by the size of the caller’s AR, which of course the caller knows.

    Is this size a compile-time constant?

    The book treats it as a constant. The only part that is not known at compile time is the size of the dynamic arrays. Strictly speaking this is not part of the AR, but it must be skipped over since the callee’s AR starts after the caller’s dynamic arrays.

    Perhaps for simplicity we are assuming that there are no dynamic arrays being stored on the stack. If there are arrays, their size must be included in some way.

  • 0 Votes
    2 Posts
    162 Views
    zareenZ

    Discussion is right way to get Solution of the every assignment, Quiz and GDB.
    We are always here to discuss and Guideline, Please Don’t visit Cyberian only for Solution.
    Cyberian Team always happy to facilitate to provide the idea solution. Please don’t hesitate to contact us!
    NOTE: Don’t copy or replicating idea solutions.

  • 0 Votes
    3 Posts
    204 Views
    zareenZ

    @zareen said in CS606 Assignment 2 Solution and Discussion:

    Assignment Marks 20
    Question:
    X -> aZ
    X -> c
    Y -> bX
    Z -> Ya
    Z -> XbY
    a) Find First sets for above grammar. (10 Marks)
    b) Find Follow sets for above grammar. (10 Marks)

    Solution:

    a) Find First sets for above grammar. (10 Marks)

    First (X)= a, c
    First (Y)= b
    First (Z)= a, b, c

    b) Find Follow sets for above grammar. (10 Marks)

    Follow (X)= a, b, $
    Follow (Y)= a, b, $
    Follow(Z)= a, b, $

  • 0 Votes
    2 Posts
    150 Views
    zaasmiZ

    @zaasmi said in CS606 Assignment 1 Solution and Discussion:

    Task 1:
    For regular expression below, construct an NFA using Thompson’s construction. (10 Marks)
    R.E. = (y* xy* x)* y*

    43407e94-3b07-4a76-ad67-3af3f378f29b-image.png

  • 0 Votes
    2 Posts
    1k Views
    zareenZ

    Solution Idea:

    Yes its useful idea to develop online compiler for C. Cloud computing is a model for enabling convenient, on-demand network access to a shared pool of configurable computing resources that can be rapidly provisioned and released with minimal management effort. The paper aims to describe an online compiler which helps to reduce the problems of portability and storage space by making use of the concept of cloud computing. The ability to use different compilers allows a programmer to pick up the fastest or the most convenient tool to compile the code and remove the errors.

  • 0 Votes
    48 Posts
    2k Views
    zareenZ

    The FIRST of a sentential form is the set of terminal symbols that lead any sentential from derived from the very first sentential form. In this particular case X and Y only derive the empty string and as a result the empty string is the FIRST set of both non-terminal symbols X and Y. The FIRST of S, however, includes “a” as in the first production once can derive a sentential form that starts with an “a” given that X can be replaced by the empty string. X similar reasoning allows you to include “b” in the FIRST(S).
    summary: FIRST(X) = {e}, FIRST(Y) = {e}, FIRST(S) = {a, b}

    The FOLLOW set of a non-terminal symbol is the set of terminals that can appear after that non-terminal symbol in any sentential form derived from the grammar’s start symbol. By definition the follow of the start symbol will automatically include the $ sign which represents the end of the input string. In this particular case by looking at the productions of S one can determine right away that the follow of X includes the terminal “a” and “b” and that the FOLLOW of Y includes the terminal “b”. Given that the non-terminal S does not appear in any productions, not even in its own productions, the FOLLOW of S is only $.
    summary: FOLLOW(S) = {$}, FOLLOW(X) = {a, b}, FOLLOW(Y) = {b}.

    b) YES, because the intersection of the FIRST for every non-terminal symbol in empty. This leads to the parsing table for this LL method as indicated below. As there is no conflict in entry then grammar is clearly LL (1).
    [23/01, 21:33] Waqas Ahmad: a b $
    S S→XaXb S → Yb
    A X→ε X→ε
    B Y→ε

  • 0 Votes
    2 Posts
    371 Views
    zareenZ

    Ideas Solution
    Q No 01
    Solution:
    NP -> Adj NP
    The draw parse trees for above given grammar:
    3ed24217-a089-4cd3-85e7-56389d10ccf9-image.png
    The above given grammar have only one parse tree so it is non-ambiguous grammar.
    NP -> NP Conj NP
    The draw parse trees for above given grammar:
    1c473269-1c88-4ba5-84d6-ab5169f94657-image.png
    The above grammar has two different parse trees therefore the given grammar is ambiguous.

    NP -> Adj N
    The draw parse trees for above given grammar:
    ee704f9a-b021-483a-864b-b72abc0a1c4a-image.png
    The above given grammar have only one parse tree so it is non-ambiguous grammar.
    NP ->N
    The draw parse trees for above given grammar:
    fe99c1ab-1959-4c17-b112-e347d177268b-image.png
    The above given grammar have only one parse tree so it is non-ambiguous grammar.
    Adj -> Young
    The draw parse trees for above given grammar:
    3bfc0b07-1dc1-4f40-ace6-49718f09b14f-image.png
    The above given grammar have only one parse tree so it is non-ambiguous grammar.

    Conj -> and
    The draw parse trees for above given grammar:
    bb56b34a-9ec9-4499-bd8e-d0b877b19b93-image.png
    The above given grammar have only one parse tree so it is non-ambiguous grammar.

    N -> Boys | Girls
    The draw parse trees for above given grammar:
    68e9888e-bc35-4ba4-9f60-2c46a8fa81f5-image.png
    The above given grammar have only one parse tree so it is non-ambiguous grammar.
    Q No 02
    Solution:
    The given grammar is
    S -> S + S | S / S | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19
    The draw parse trees for above given grammar:
    Parse Trees:
    a4b787fc-27a6-401d-ab7a-5b97e4399d99-image.png

    The above grammar has two different parse trees therefore the given grammar is ambiguous.

    THE END!

  • 0 Votes
    3 Posts
    561 Views
    zareenZ

    @zareen said in CS606 Assignment 1 Solution and Discussion:

    Use Subset Construction algorithm to find DFA for the NFA constructed in Task 1.

    The resulting DFA is
    5e73f087-480c-4f02-a861-cdcd3f44b9b3-image.png