Chapt. 3 Language Translation - PowerPoint PPT Presentation

Loading...

PPT – Chapt. 3 Language Translation PowerPoint presentation | free to download - id: 5cc4c3-MDk5M



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Chapt. 3 Language Translation

Description:

... (generator) such as YACC can automatically generate parser from BNF Good syntax criteria Assist in Readability COBOL as self documenting Comments Length of ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 17
Provided by: FDU
Learn more at: http://alpha.fdu.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Chapt. 3 Language Translation


1
Chapt. 3 Language Translation
  • Syntax and Semantics
  • Translation phases
  • Formal translation models

2
Syntax
  • What is a valid string of the language?
  • First pass of a compiler
  • Error messages (are they helpful?)
  • Compiler compiler (generator) such as YACC can
    automatically generate parser from BNF

3
Good syntax criteria
  • Assist in Readability
  • COBOL as self documenting
  • Comments
  • Length of identifiers
  • Overloading of names
  • Examples of poor features for readability
  • blank as concatenation operation in SNOBOL
  • Identifier names in Basic
  • X1, Y
  • Implicit typing
  • Late binding

4
Good syntax criteria(cont.)
  • Assist in Writeability
  • Few and concise statements
  • Rich librarycreated by language and user
  • Support of abstraction
  • Orthogonality
  • Examples of poor features for writeability
  • Large number of constructs
  • Lack of necessary constructs
  • Redundancy
  • Ambiguity
  • Ex if statement
  • Case sensitivity??

5
Syntactic elements
  • Character set
  • 5, 6, 7, 8, 16 bit encoding schemes
  • Identifiers
  • Symbols such as letters, digits, , _, blank
  • Length limitation
  • Operation symbols various examples
  • LISP prefix identifiers (ex PLUS)
  • APL special Greek characters
  • FORTRAN - .EQ., .GT.
  • C - ,
  • Java and , and

6
Syntactic elements (cont.)
  • Keyword
  • identifier used as part of primitive program unit
    (ex if, then, else, case)
  • Reserved word
  • Keyword that cannot be assigned by programmer
  • READ is not a reserved word in Pascal
  • Adding new reserved words to an update of a
    language can make old programs incorrect (upward
    compatability)

7
Syntactic elements (cont.)
  • Noise words
  • Used to improve readability-optional
  • Ex perform 5 times
  • Comments
  • Used for documentation readability
  • Blanks
  • Completely ignored in FORTRAN
  • Do 10 I 1.5
  • Delimiters and brackets
  • Spaces, , paired () begin end
  • Fixed format vs free format

8
Program Structure
  • Expression
  • Precedence rules
  • Statements
  • structured programming
  • Modules/ functions/ subprograms/ classes
  • Nested units
  • Static checks, efficient code for nonlocal
    references
  • Separate unit compilation.
  • Data and operations are compiled as a unit in
    classes
  • Interface issues function specification to
    allow static checks (prototypes)
  • Specifications (.h files) separate from
    implementations

9
Translation I- Lexical Analysis
  • Byte stream organized into lexemes, each of which
    is identified (tagged)
  • Numbers may be converted to binary
  • Identifiers are stored in symbol table
  • Tokens are output for syntactic analysis

10
Translation II parsing syntactic analysis
  • Tokens organized into expressions, statements,
    etc.
  • Is the input a valid string in the language?
  • Generates parse tree, tables
  • Produces error messages for invalid strings

11
Translation III semantic analysis
  • Produces error messages for invalid constructs
  • Ex identifier not declared type mismatch
  • Compiled languages use and discard symbol table
  • Reference to variable as offset from data
    sections
  • Information must be stored together with
    identifier (ex type, range limitations)
  • Macro substitutions
  • Compiler directives
  • define
  • ifndef
  • Pragma suppress range_checks

12
Translation IV optimization
  • Semantic analysis output is typically one
    statement at a time
  • Compiler can optimize code to optain results as
    efficient as assembly code
  • ExSave intermediate results in registers
  • remove constant operations from loop
  • Change 2-dimensional array storage
  • Code generations
  • Linking and Loading

13
BNF (Backus Normal/Naur Form)
  • Metalanguage
  • defined as
  • alternative
  • ltgt nonterminal
  • later introduced for iteration
  • for optional
  • sequence is implicit
  • ex
  • ltunsigned integergt ltdigitgtltunsigned integergt
    ltdigitgt
  • ltdigitgt 0123456789

14
Context Free Grammars
  • For balanced parenthesis
  • S ? SS (S) ()
  • Problem generate a parse tree for a string
    such as (()(()))((())()) from above
  • Some language definition issues are context
    sensitive, such as each identifier must be
    declared before use
  • Implementation issues such as
  • Pass by value or reference

15
Syntax Charts
  • Term at top left is defined by the following
    graph
  • Graph branches for alternative
  • Empty branch for optional
  • Box around string for nonterminal
  • Circle for terminal
  • Arrow back for iteration
  • ex p. 96 in text
  • Sequence is explicit

16
Finite-State Automata
  • Table used for lexical analysis
  • Ex valid floating point number
  • (note that limitations on range and precision are
    not specified)
  • (whole part)? (decimal) ? (fractional) ?
  • (exp) ? (exp value)
  • Where whole part, fractional, and exp value have
    a looping arrow
  • Digit is input to whole part
  • . is input leading to decimal
  • Digit leads from decimal to fractional
  • E leads from fractional to exp
  • Digit leads from exp to exp value
About PowerShow.com