So I have this Recursive Descent Parser which outputs a Syntax Tree for arithmetic expressions.
While doing some reading, I learned that LL(1) grammars have a lookahead of 1 - I remembered using a lookahead so I grepped for it. But instead of finding it in my parser, I found it in the lexer.
case "*":
if self._peek() == "*":
self._next(2)
return Token(SyntaxKind.TWO_STAR, self.position - 2, "*")
self._next(1)
return Token(SyntaxKind.STAR, self.position - 1, "*")
I use this to differentiate between the power(**
) and multiplication operator(*
).
So is this the right way to do things? Or should this code be in my parser? And is my grammar still LL(1) if I don't actually lookahead in the parser?