├── OUTPUT-Recursive-descent-parser.JPG ├── README.md └── Recursive-descent-parser.py /OUTPUT-Recursive-descent-parser.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abhishekmishra-17/Recursive-Descent-Parser-using-python/HEAD/OUTPUT-Recursive-descent-parser.JPG -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Recursive-Descent-Parser-using-python 2 | This is program of recursive descent parser using Python programming language. 3 | 4 | # Recursive Descent Parser: 5 | It is a kind of Top-Down Parser. A top-down parser builds the parse tree from the top to down, starting with the start non-terminal. A Predictive Parser is a special case of Recursive Descent Parser, where no Back Tracking is required. 6 | By carefully writing a grammar means eliminating left recursion and left factoring from it, the resulting grammar will be a grammar that can be parsed by a recursive descent parser. 7 | 8 | 9 | **Here 'i' is Epsilon or any terminals symbol.** 10 | 11 | For Recursive Descent Parser, we are going to write one program for every variable. 12 | 13 | 14 | **Any suggestion regarding this program is helpful for me** 15 | -------------------------------------------------------------------------------- /Recursive-descent-parser.py: -------------------------------------------------------------------------------- 1 | print("Recursive Desent Parsing For following grammar\n") 2 | print("E->TE'\nE'->+TE'/@\nT->FT'\nT'->*FT'/@\nF->(E)/i\n") 3 | print("Enter the string want to be checked\n") 4 | global s 5 | s=list(input()) 6 | global i 7 | i=0 8 | def match(a): 9 | global s 10 | global i 11 | if(i>=len(s)): 12 | return False 13 | elif(s[i]==a): 14 | i+=1 15 | return True 16 | else: 17 | return False 18 | def F(): 19 | if(match("(")): 20 | if(E()): 21 | if(match(")")): 22 | return True 23 | else: 24 | return False 25 | else: 26 | return False 27 | elif(match("i")): 28 | return True 29 | else: 30 | return False 31 | def Tx(): 32 | if(match("*")): 33 | if(F()): 34 | if(Tx()): 35 | return True 36 | else: 37 | return False 38 | else: 39 | return False 40 | else: 41 | return True 42 | def T(): 43 | if(F()): 44 | if(Tx()): 45 | return True 46 | else: 47 | return False 48 | else: 49 | return False 50 | def Ex(): 51 | if(match("+")): 52 | if(T()): 53 | if(Ex()): 54 | return True 55 | else: 56 | return False 57 | else: 58 | return False 59 | else: 60 | return True 61 | def E(): 62 | if(T()): 63 | if(Ex()): 64 | return True 65 | else: 66 | return False 67 | else: 68 | return False 69 | if(E()): 70 | if(i==len(s)): 71 | print("String is accepted") 72 | else: 73 | print("String is not accepted") 74 | 75 | else: 76 | print("string is not accepted") 77 | --------------------------------------------------------------------------------