Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
onsider the following grammar along its semantic rules and its Parsing Table.

1.E→ E+T { add value of E and T and save to a new variable}
2.E→T
3.T→id { convert id to integer}
4.T→(id) {convert id to integer}
Parsing table:
    State   +     id    (     )      $     E       T
     0            S1    S2                 4       3
     1      R3                R3     R3
     2            S1    S2                 6       3
     3      R2                R2     R2
     4      S5                       A
     5            S1    S2                         7
     6      S5                S8
     7      R1                R1     R1
     8      R4                R4     R4
Write a program that will input from input.txt, and will find potential tokens. Any token that is not part of grammar will be discarded, tokens which are part of grammar will be parsed using LR-1 parser. Program MUST print status of stack and operation performed (shift or reduce) along Token and states, on each stack operation. You are also required to perform semantic operations, in case of reduction of a production. Proper message will be displayed after parsing either it is successful of failed.


What I have tried:

i have made a LR-01 parser.... Now it became very complicated...
Posted
Updated 1-Jan-21 2:50am
Comments
Patrice T 1-Jan-21 7:26am    
You should have a talk with your teacher.
Johny Alex 1-Jan-21 7:33am    
@Patrice T i have no teacher that's why i am asking here. My teacher died of COVID-19. :(

1 solution

Quote:
Write a program that will input from input.txt
7. Input and Output — Python 3.9.1 documentation[^].

Quote:
find potential tokens
Built-in Types — Python 3.9.1 documentation[^].

etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900