1 / 20

COMP313A Programming Languages

COMP313A Programming Languages. Overview of the Compilation Process. skeletal source program. preprocessor. source program. compiler. target assembly program. assembler. relocatable machine code. loader/link-editor. absolute machine code. source program. lexical analyser.

makani
Download Presentation

COMP313A Programming Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP313A Programming Languages Overview of the Compilation Process

  2. skeletal source program preprocessor source program compiler target assembly program assembler relocatable machine code loader/link-editor absolute machine code

  3. source program lexicalanalyser syntaxanalyser symbol table manager semanticanalyser error handler code optimiser code generator target program

  4. Type 0 Unrestricted Grammar Type 1 Context-Sensitive Grammar Type 2 Context Free Grammar Type 3 Regular Grammar Chomsky’s Grammar Hierarchy

  5. Grammars • Type 3 (regular) • A  wB, A  w (right linear) • w is a string of Terminals • A and B are Non-Terminals • Finite state automata • Type 2 (context free) • A   • A is a Non-terminal •  is a member of T  N   (can be empty) • Equivalent to a push-down automaton

  6. Grammars • Type 1 (context sensitive) •  A    B  • A becomes B in the context of  …  • Complex for computer analysis • Type 0 (unrestricted) •   , •  and  are unrestricted sequences,  is not null • languages formed from Type 0 grammars can be recognised by non-deterministic Turing machines

  7. Lexical Analysis object_position = calculate_position( robot_coordinates, robot_heading, range, error) Need to find the words i.e. tokens

  8. Lexical Analysis • Uses a regular grammar for specifying the rules for forming “words” / tokens

  9. Syntax Analysis • Hierarchical Analysis • Groups tokens into grammatical phrases • Parse Tree • Use syntax rules (context free grammars/BNF) to perform the analysis

  10. Expression ::= id Expression ::= num Expression ::= Expression + Expression Expression ::= Expression * Expression

  11. assignment statement = expression identifier position expression + expression identifier * expression expression initial identifier identifier rate 60

  12. = + position initial * rate 60

  13. Semantic Analysis • Checks source program for semantic errors • Type checking • Gathers type information for code generation

  14. = + position initial * rate inttoreal 60

  15. Symbol Table Management • Records identifiers used in source program • Collects information about various attributes of each identifier • Storage allocation • Type • Scope • Procedure names – ?????

  16. Error Detection and Reporting • Lexical errors • Syntax errors • Semantic errors

  17. Code Optimisation • Improve code so it runs faster • Where does program spend most of its time?

  18. Code generation • Generation of target code • Relocatable machine code or assembler code • Memory locations are selected for each of the variables • Assignment of variables to registers

  19. MOVF id3, R2 MULF #60.0, R2 MOVF id2, R1 ADDF R2, R1 MOVF R1, id1

  20. Analysis versus Synthesis • Back end versus front end of the compiler

More Related