Updated readme
This commit is contained in:
parent
837b302d0f
commit
3de17daa74
|
@ -8,6 +8,7 @@ class parser():
|
||||||
def __init__(self, grammar):
|
def __init__(self, grammar):
|
||||||
self.grammar = grammar
|
self.grammar = grammar
|
||||||
def parse(self, inp):
|
def parse(self, inp):
|
||||||
|
print("Parsing input " + inp)
|
||||||
self.tokens = lexer.lex(inp)
|
self.tokens = lexer.lex(inp)
|
||||||
self.tokens = [t for t in self.tokens if not t.type == "whitespace_nfa"]
|
self.tokens = [t for t in self.tokens if not t.type == "whitespace_nfa"]
|
||||||
self.tokens_ptr = 0
|
self.tokens_ptr = 0
|
||||||
|
@ -16,7 +17,7 @@ class parser():
|
||||||
def term(self, t_type, literal = False):
|
def term(self, t_type, literal = False):
|
||||||
this_token = self.tokens[self.tokens_ptr]
|
this_token = self.tokens[self.tokens_ptr]
|
||||||
self.tokens_ptr += 1
|
self.tokens_ptr += 1
|
||||||
print("attempting to match '" + str(literal) + "' ("+t_type+") to " + this_token.matched_string + " at position " + str(self.tokens_ptr - 1))
|
#print("attempting to match '" + str(literal) + "' ("+t_type+") to " + this_token.matched_string + " at position " + str(self.tokens_ptr - 1))
|
||||||
if t_type != this_token.type:
|
if t_type != this_token.type:
|
||||||
return False
|
return False
|
||||||
if not literal:
|
if not literal:
|
||||||
|
@ -40,6 +41,7 @@ class parser():
|
||||||
for f in grammar[nterm]:
|
for f in grammar[nterm]:
|
||||||
self.tokens_ptr = save
|
self.tokens_ptr = save
|
||||||
if self.match_syms(f):
|
if self.match_syms(f):
|
||||||
|
print("Matched term " + str([k[1] for k in f]))
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,6 @@ COOL is the Classroom Object Oriented Language. I'm going to get at least partwa
|
||||||
|
|
||||||
This is what the lexical analyzer looks like now
|
This is what the lexical analyzer looks like now
|
||||||
![](http://i.imgur.com/ZzrVRWG.png)
|
![](http://i.imgur.com/ZzrVRWG.png)
|
||||||
|
|
||||||
|
This is what the parser looks like so far
|
||||||
|
![](http://i.imgur.com/vq3DkmY.png)
|
||||||
|
|
Loading…
Reference in New Issue