Closed mewmew closed 8 years ago
If we were to postpone the type checking to the semantic analysis phase, it should be possible to merge VarDecl
and ParamDecl
production rules, and let the type checker validate their uses within function signatures and bodies.
If we were to postpone the type checking to the semantic analysis phase, it should be possible to merge VarDecl and ParamDecl production rules, and let the type checker validate their uses within function signatures and bodies.
I experimented with this and an initial implementation is available in commit ee9cebb. Lets see where we end up and which approach feels like the right one.
We ended up taking this route, so the syntactic analysis phase is more permissive with types, which will be validated during the type checker of the semantic analysis phase.
The type-checker is now implemented.
To simplify the design of the parser and the parser generator, I suggest we postpone the type checking to the semantic analysis phase. This design decision would be supported by the KISS mentality, let each component focus on one thing, and do it well.
Alex, what are your thoughts? We could go either direction, and for uC it would be trivial to enforce type checking already in the parser. My main concern is that such an approach could make the parser sufficiently more complex in the future, once we start supporting a larger subset of C.
Below is an example of how array type declarations may be simplified by this design decision (extracts taken from the
ast/astx
package).Note that several production rules would make use of the
NewType
function, which is also more generic and allows more types than those specifically valid for array types, thus mandating a subsequent type check in the semantic analysis phase.