First off,I don't study Computer Science, I'm just interested in the subject.
A parser basically does this right:
- reading the input
- create tokens
- actually parse tokens and create an AST
So I thought that in order to decide whether a word is in a regular language, you use a FSM and for CF languages you need a parser because of the recursive structures that may exist. Hence, scanner generators exist for regular languages and parser generators for CF languages.
But now I read that you can build a recursive decent parser for regular expressions:
http://matt.might.net/articles/parsing-regex-with-recursive-descent/
So how does this all go togther?
Why do I need to parse regular languages? I thought a finite state machine was enough?
If, e.g. I want to recognize block comments in a java programme (i.e. /* .. */
), I only need to write a FSM, so basically a switch-case-statement. I dont need a parser for this...
Thanks for help and clarification!