04-semantics - Semantic Analysis The compilation process is...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Semantic Analysis The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the program based on its syntactic structure two purposes: finish analysis by deriving context-sensitive information begin synthesis by generating the IR or target code associated with individual productions of a context free grammar or subtrees of a syntax tree Copyright c circlecopyrt 2010 by Antony L. Hosking. Copyright c circlecopyrt 2010 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and full citation on the first page. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior specific permission and/or fee. Request permission to publish from [email protected] 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Context-sensitive analysis What context-sensitive questions might the compiler ask? 1. Is x scalar, an array, or a function? 2. Is x declared before it is used? 3. Are any names declared but not used? 4. Which declaration of x does this reference? 5. Is an expression type-consistent ? 6. Does the dimension of a reference match the declaration? 7. Where can x be stored? (heap, stack, ... ) 8. Does *p reference the result of a malloc()? 9. Is x defined before it is used? 10. Is an array reference in bounds ? 11. Does function foo produce a constant value? 12. Can p be implemented as a memo-function ? These cannot be answered with a context-free grammar 2
Image of page 2
Context-sensitive analysis Why is context-sensitive analysis hard? answers depend on values, not syntax questions and answers involve non-local information answers may involve computation Several alternatives: abstract syntax tree specify non-local computations ( attribute grammars ) automatic evaluators symbol tables central store for facts express checking code language design simplify language avoid problems 3
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern