Created
July 12, 2016 07:43
-
-
Save 5hirish/2217b1cb7d01b2aaa395a0888124c763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
E --> nT | |
T --> *nT | @ | |
""" | |
def non_terminal_E(input_token, lookahead): | |
if input_token == "n": | |
lookahead = match(input_token,"n", lookahead) | |
non_terminal_T(input_token, lookahead) | |
else: | |
error() | |
def non_terminal_T(input_token, lookahead): | |
if input_token == "*": | |
lookahead = match(input_token,"*", lookahead) | |
if input_token == "n": | |
lookahead = match(input_token,"n", lookahead) | |
non_terminal_T(input_token, lookahead) | |
else: | |
error() | |
else: | |
error() | |
def match(input_token, token, lookahead): | |
if input_token != token: | |
error() | |
else: | |
lookahead += 1 | |
return lookahead | |
def error(): | |
print "Error. Parsing Failed..." | |
string = input("Enter the string:") | |
input_token = list(string) | |
print "Your input:"input_token | |
non_terminal_E(input_token, 0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment