What are Compilers
Compilers translate information from one representation to another. Thus, a tool that
translates, say, Russian into English could be labeled as a compiler. In this course,
however, information = program in a computer language. In this context, we will talk of
compilers such as VC, VC++, GCC, JavaC FORTRAN, Pascal, VB. Application that
convert, for example, a Word file to PDF or PDF to Postscript will be called
â€œtranslatorsâ€. In this course we will study typical compilation: from programs written in
high- level languages to low- level object code and machine code.
Issues in Compilation
The ...view middle of the document...
The front end consists of two modules:
The scanner takes a program as input and maps the character stream into â€œwordsâ€ that are the basic unit of syntax. It produces pairs â€“ a word and its part of speech. For example, the input
The Back End
alphabet and a string of the langua ge and its associated alphabet set S.
â€“Â Â Â Â Â Symbol table is a data structure containing a record for each identifier, with fields for the attributes of the identifier.
â€“Â Â Â Â Â Record the identifier used in the source program and collect information about the identifier such as,
â€¢Â Â Â Â Â Â its type, (by semantic and intermediate code)
â€¢Â Â Â Â Â Â its scope, (by semantic and intermediate code)
â€¢Â Â Â Â Â Â storage allocation, (by code generation)
â€¢Â Â Â Â Â Â number of arguments and its type for procedure, the type returned
â€¢Â Â Â Â Â Â Error Detecting and Reporting:
â€“Â Â Â Â Â Each phase encounters errors.
â€“Â Â Â Â Â Lexical phase determine the input that do not form token.
â€“Â Â Â Â Â Syntax phase determine the token that violates the syntax rule.
â€“Â Â Â Â Â Semantic phase detects the constructs that have no meaning to operand.
â€¢Â Â Â Â Â Â The Analysis Phase:
â€“Â Â Â Â Â Involves: Lexical, Syntax and Semantic phase
â€“Â Â Â Â Â As translation progresses, the compilerâ€™s internal representation of the source program changes.
â€¢Â Â Â Â Â Â Lexical Analysis Phase:
â€“Â Â Â Â Â The lexical phase reads the characters in the source program and groups them into a stream of tokens in which each token represents a logically cohesive sequence of characters, such as, An identifier, A keyword, A punctuation character.
â€“Â Â Â Â Â The character sequence forming a token is called the lexeme for the token.
â€¢Â Â Â Â Â Â Syntax Analysis Phase:
â€“Â Â Â Â Â Syntax analysis imposes a hierarchical structure on the token stream. This hierarchical structure is called syntax tree.
â€“Â Â Â Â Â A...