04-semantics

04-semantics - Semantic Processing The compilation process...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Semantic Processing 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: Fnish 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 ± 2007 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 proFt or commercial advantage and that copies bear this notice and full citation on the Frst page. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior speciFc permission and/or fee. Request permission to publish from hosking@cs.purdue.edu. CS502 Semantics 1 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 deFned 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 CS502 Semantics 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 CS502 Semantics 3 Alternatives for semantic processing code object code source IR IR tokens syntactic structure Scanner Routines Semantic Parser Optimizer Code Generator Table Symbol one-pass analysis and synthesis one-pass compiler plus peephole one-pass analysis & IR synthesis + code generation pass multipass analysis (MiniJava) multipass synthesis (MiniJava) language-independent and retargetable compilers (MiniJava) CS502 Semantics 4
Background image of page 1

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

View Full DocumentRight Arrow Icon
One-pass compilers interleave scanning, parsing, checking, and translation no explicit IR generates target machine code directly emit short sequences of instructions at a time on each parser action (symbol match for predictive parsing/LR reduction) little or no optimization possible (minimal context) Can add a peephole optimization pass extra pass over generated code through window ( peephole ) of a few instructions smoothes “rough edges” between segments of code emitted by one call to the code generator CS502 Semantics 5
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 16

04-semantics - Semantic Processing The compilation process...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online