Updated framework for semantic analysis. Needs a lot of refactoring.