0% found this document useful (0 votes)
1K views23 pages

Programming Language Translation Issues: Chapter - 02

The document discusses programming language translation issues. It covers key concepts related to syntax like readability, writeability, and lack of ambiguity. It also describes basic syntactic concepts such as identifiers, operators, keywords, and statements. Additionally, it discusses the overall program structure, including separate definitions for subprograms, data, and interfaces to improve modularity and enable compilation.

Uploaded by

Gebru Gurmessa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views23 pages

Programming Language Translation Issues: Chapter - 02

The document discusses programming language translation issues. It covers key concepts related to syntax like readability, writeability, and lack of ambiguity. It also describes basic syntactic concepts such as identifiers, operators, keywords, and statements. Additionally, it discusses the overall program structure, including separate definitions for subprograms, data, and interfaces to improve modularity and enable compilation.

Uploaded by

Gebru Gurmessa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

CHAPTER -02

Programming Language
Translation issues
Language Translation issues

• Programming language Syntax


– Key criteria concerning syntax
– Basic syntactic concepts
– Overall Program-Subprogram structure
• Stages in Translation
– Analysis of the source program
– Synthesis of the object program
– Bootstrapping
What is Syntax
The syntax of a programming language
describes the structure of programs without any
consideration of their meaning.
The primary purpose of syntax is to provide a
notation for communication between
the programmer and the programming language
processor.
What is Semantics

Non-syntax attributes of a programming


language.
Includes declarations, operations, sequence
control, etc
Key criteria concerning
syntax

 Readability

 Writeability

 Verifiability

 Translatability

 Lack of ambiguity
Key criteria concerning
syntax
Readability
A program is readable if data/algorithm is apparent by
inspection of program text
A readable program is said to be self-documenting
The following features enhance program readability:
 natural statement formats
 structured statements
 liberal use of keywords and noise words
 embedded comments
 unrestricted length identifiers
 mnemonic operator symbols
 free-field formats
 complete data declarations
Key criteria concerning
syntax
Writeability
Syntax features that make programs easy to write usually make
them hard to read
 Writability enhanced by concise and few syntax structures
 Readability enhanced by verbose and varied syntax structures
Implicit syntax (allowing declarations/operations to be
unspecified) make programs shorter and easier to write but harder to
read.
A syntax is redundant if it can say the same thing in more than one
way
 Sometimes this is useful
 Sometimes this makes programs harder to write
Key criteria concerning
syntax
Ease of verifiability
Program correctness
 Also known as program verification
Understanding programming statements is easy, but producing
correct programs is hard.
Key criteria concerning
syntax
Ease of translation

Another goal is making programs easy to translate into executable


form
Readability / writeability directed at programmer needs, ease of
translation directed at the program translator.
 Lisp is not very readable or writable but is very easy to
translate
 COBOL is hard to translate due to number of statement forms
allowed
Key criteria concerning
syntax
Lack of ambiguity
Ambiguity is a central problem in every language design
A language ideally provides a unique meaning for every syntax
construct
Problems of ambiguity usually arise in interplay between different
structures
Basic syntactic concepts
• Character set – The alphabet of the language. Several
different character sets are used: ASCII, EBCDIC, Unicode

• Identifiers – strings of letters and digits usually


beginning with a letter
– Variations between languages include :
inclusion of special characters (such as . and _) to
improve readability.
length restrictions
Basic syntactic concepts
• Operator Symbols: +-*/

• Keywords or Reserved Words:


– Keyword An identifier used as a fixed part of the
syntax of a statement ("if" beginning a conditional
or "for" beginning an iteration)
– may not be used as a programmer-chosen
identifier. A keyword is a reserved word if it may
not also be used as a programmer-chosen
identifier.
Basic syntactic concepts
• Noise words – optional words inserted into
statements to improve program readability.
– Example: COBOL ,"GO TO"
GO required,
TO optional. it carries no information and is used
only to improve readability.
• Comments – used to improve readability and for
documentation purposes. Comments are usually
enclosed by special markers
Basic syntactic concepts
• Blanks – rules vary from language to language.
Usually only significant in literal strings
– In C, blanks are not significant except in string
literals
– Some languages use blanks as separators, so they are
important
SNOBOL4, concatenation represented by a blank
Basic syntactic concepts
• Delimiters – used to denote the beginning and the
end of syntactic constructs
– Brackets are paired delimiters
Parentheses
begin...end pairs
(), {}, and [] are all called brackets. () are called round
brackets or parentheses, {} called curly brackets or
braces and [] are the square brackets
– Usually serve the purpose of removing ambiguities by defining
explicit boundaries
Basic syntactic concepts
• Free and fixed-field formats
– free-field: A syntax is free-field if program statements may
be written anywhere on an input line without regard for
positioning on the line.

– fixed-field: A syntax is fix field if the positioning on an


input line conveys information.
Fixed field syntaxes are a remnant of the punch-card era
Fixed-field syntax is increasingly rare today
Basic syntactic concepts
Expressions: An expression is a function that accesses
data objects in a program and returns some value
•The basic syntactic building block from which statements
are built
•In imperative languages, expressions form the operations
that allow for the machine state to be changed by each
statement.
•In applicative (functional) languages, expressions form the
basic sequence control that drives execution.
Basic syntactic concepts

Statements – these are the sentences of the language, they


describe a task to be performed
•Statement syntax has critical effect on regularity, readability,
writability
•Most programming language provide different syntax structures for
different statement types
•Different types of statements:
– A simple statement contains no other statements
– A structured(nested) statement may contain embedded
statements
Overall Program-
Subprogram Structure
Separate subprogram definitions:

C has each subprogram definition treated as a


separate syntax unit
 Each program compiled separately
 Compiled programs linked at load time
Object orientation requires information to be
passed among the separately compiled units
 Inheritance requires the compiler to process
some of the subprogram issues
Overall Program-
Subprogram Structure
Separate data definitions
Group together all operations that manipulate a data object
 Subprogram may consist of all operations that create/print data
object
 The general approach of the class mechanism of Java, C++,
Smalltalk
Nested subprogram definitions
Important for building modular programs during period of
ALGOL, FORTRAN, and Pascal.
In Pascal, subprogram definitions appeared within main program
 May contain other subprograms nested within their definitions
This type of subprogram allows for static type checking.
Overall Program-
Subprogram Structure
Separate interface definitions:
C/C++ header files: the approach is to include certain
operating system file operations into the language by allowing
the program to include files that contain these interface
definitions.
FORTRAN permits easy compilation of subprograms, but data used
across subprograms may have different definitions
 compiler will not be able to detect this at compile time
Pascal allows compiler to have access to all these definitions to aid
in finding errors
 However, the entire program must be recompiled at the slightest
change
C and Ada use aspects of both techniques to improve compilation
Overall Program-
Subprogram Structure
Data descriptions separated from
executable statements.
COBOL contains early form of component structure
 Data declarations/statements divided into data and
procedure "divisions"
 The environment division consists of declarations
involving the external operating environment.
Overall Program-
Subprogram Structure
Unseparated subprogram definitions:
SNOBOL4 represents extreme in program organization
 No syntactic distinction made between main
program and subprogram statements (Lack of
Organization)
In SNOBOL4, statements simply execute:
 Where subprograms begin and end are not different
in syntax
 Execution of a function starts a new subprogram
 RETURN function ends a subprogram
Very chaotic! Only useful in allowing run-time
translation.

You might also like