private AstItem ReadFuncDecl(TokenIterator tokens) { //Skip "fn" tokens.Pop(); var next = tokens.Current(); if (next.Kind == TokenKind.Ext) { return(ReadExternFuncDecl(tokens)); } var name = tokens.PopExpected(TokenKind.Word); tokens.PopExpected(TokenKind.RoundBracketOpen); var parameters = ReadFuncParameters(tokens); DataType returnType = DataType.VOID; next = tokens.Pop(); if (next.Kind == TokenKind.TypeOperator) { returnType = ReadDataType(tokens); next = tokens.Pop(); } if (next.Kind != TokenKind.CurlyBracketOpen) { throw new Exception("Expected ':' or '{', found " + next); } var statements = ReadStatements(tokens); tokens.PopExpected(TokenKind.CurlyBracketClose); return(AstItem.FunctionDecl(name.Value, returnType, parameters, statements)); }