Skip to content
Snippets Groups Projects
Commit 86db3e13 authored by Esteban Prince, Liam (UG - Computer Science)'s avatar Esteban Prince, Liam (UG - Computer Science)
Browse files

Update parser.py

parent dbdb8ec0
No related branches found
No related tags found
No related merge requests found
lexer.py 0 → 100644
import json
def lex(raw):
tokens = {}
splitted = raw.split()
types = ['ingredients',
'units',
'utensils',
'prepositions',
'articles',
'conjunctions',
'adjectives']
with open('database/ingredients.json', 'r') as f:
ingredients = json.load(f)
with open('database/units.json', 'r') as f:
units = json.load(f)
while len(splitted):
currentToken = splitted[0]
if currentToken in ingredients:
tokenType = "Ingredient"
elif currentToken in units:
tokenType = "Unit"
elif currentToken.isdigit():
tokenType = "Digit"
else:
tokenType = "Unknown"
tokens[currentToken] = tokenType
splitted = splitted[1:]
print(tokens)
def isValid():
pass
lex("Peel 300 g of potatoes and then cut into strips")
\ No newline at end of file
def preprocess():
# Return the next token from the input
def lex(input):
tokens = []
while len(input.split()):
if input is not None:
continue
if input[0] in ingredients:
input = input[1:]
else:
raise Exception('Don\'t know what this is: {}'.format(input[0]))
def parse():
preprocess()
lex(input)
isValid()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment