Need help with semantic actions & type checking for my LL(1) Mini-Pascal compiler (following professor’s slides)
Hi everyone,
I’m working on a compiler for a small Pascal-like language. I have already finished the grammar, removed left recursion and left factoring, and turned it into an LL(1) grammar with embedded semantic actions (translation scheme style).
The problem is that I’m struggling with semantic actions and type checking. My professor uses a very specific style from his slides (Chapter 5 & 6):
Every Statement has a .type attribute (void or type_error)
Expressions use inherited attribute .in and synthesized .type
Declarations use addtype() and list handling
I have the full grammar with some actions already written, but many parts still feel confusing to me (especially the tail productions like Expression', SimpleExpression', Term' and how to pass the left operand type using .in).
Here is my current grammar (with embedded actions):
yacc
Program → Header Declarations Block . { } ... (I can paste the full grammar if needed)
I would really appreciate any help, examples, or explanations on how to correctly implement the semantic actions and type checking according to the standard Dragon Book / professor’s slide convention.
Any guidance, small examples, or links to similar student projects would be very helpful.
Thank you!