In a saucepan, combine the sugar, water, and lemon juice. Bring to a boil over medium heat.
Reduce the heat and let it simmer for about 10 minutes until it slightly thickens.
Remove from heat and stir in the vanilla extract and rose water (if using). Allow the syrup to cool.
Preheat your oven to 350°F (175°C).
In a large bowl, combine the semolina flour and sugar. Slowly add the milk while stirring to avoid lumps. Mix until smooth.
Pour the mixture into a saucepan and cook over medium heat, stirring constantly until it thickens and becomes a custard-like consistency, about 10-15 minutes. Stir in the vanilla extract and remove from heat.
In a large bowl, toss the shredded phyllo dough with the melted butter until evenly coated.
Grease a 9x13 inch (23x33 cm) baking dish or similar size with butter.
Spread half of the shredded phyllo dough evenly in the bottom of the baking dish. Press down gently.
Pour the semolina custard over the phyllo dough and spread it evenly.
Top with the remaining shredded phyllo dough, pressing down gently.
Bake in the preheated oven for 30-40 minutes, or until the top is golden brown and crispy.
Remove from the oven and immediately pour the cooled syrup evenly over the hot knafeh.
Let it cool for at least 30 minutes before cutting into squares or diamonds.
Garnish with chopped pistachios before serving.
Enjoy your meal!