Hello! I'm very interested in compiler/language design but It's an extremely complicated topic so I've recently tried to wrap my head around and understand one of the beginning and main parts, lexical analyzation. I'm not here to ask for code or anything but I've tried thinking up various methods of implementing a simple lexical analyzer but everytime I think I have something going I realise there are so many things that could go wrong.
So my question is in the simplest and most reliable form how are lexers written and how do they work?
Thanks for any information!
(I am aware in tools such as lex/flex I'm just curious how it works)