def parseFunction(parser): parser.check(expected="function defenition, def", lexeme=keywords['DEF']) lineo = parser.currentToken[2] ## parse identifier parser.next(tokensort=NAME) name = parser.currentToken[1] parser.next() ## parse formals if parser.matchLexeme('('): arguments = parseArguments(parser) function = Function(name, arguments, lineo=lineo) else: function = Function(name, lineo=lineo) ## parser statements. while (parser.hasnext()): if parser.matchLexeme(keywords['END']): parser.next() return function function.addStatement(parseStatement(parser)) if parser.matchLexeme(keywords['END']): #empty function! return function raise SyntaxError(parser.currentToken, expected="END, Missing function ending END")
def parseFunction(parser): parser.check(expected="function defenition, def", lexeme=keywords['DEF']) lineo = parser.currentToken[2] ## parse identifier parser.next(tokensort=NAME) name = parser.currentToken[1] parser.next() ## parse formals if parser.matchLexeme('('): arguments = parseArguments(parser) function = Function(name,arguments, lineo=lineo) else: function = Function(name, lineo=lineo) ## parser statements. while(parser.hasnext()): if parser.matchLexeme(keywords['END']): parser.next() return function function.addStatement(parseStatement(parser)) if parser.matchLexeme(keywords['END']): #empty function! return function raise SyntaxError(parser.currentToken, expected="END, Missing function ending END")