That sounds... fun. I would start by getting more requirements and considering the possibilities.
Questions to ask:
Will there always be a from and a where?
Are you guarenteed by the spec to have a where clause in all SQL queries passed in?
What are you supposed to do if there isn't one?
Things to think about:
What are the possible ways that a from clause can look like?
from ((myfoo inner join mybar on myfoo.a=mybar.a) inner join thisbar on myfoo.a=thisbar.a) ... to infinity
from foo f, bar b
from foo, bar
from foo
I am no expert at SQL queries so I know that I am missing some. Get more requirements and pound out all of the possible situations that you could see first. From there you just write a recursive parser.