Compiler CH-1
Compiler CH-1
Chapter One:
Introduction to Programming
Languages
Contents
Definitions of programming languages
The lexical and syntactic structure of a language
Evolution of Programming Languages
High-level programming languages
Elements of Programming languages:
– Data elements, Data structures, Operators, Assignment,
Statements, Program units, Data environments, Parameter
transmission, Storage management.
Programming Language basics
Programming Languages
Programming languages are notations for describing
computations to people and to machines.
The world as we know it depends on programming languages,
because all the software running on all the computers was written
in some programming language.
But, before a program can be run, first it must be translated into a
form in which it can be executed by a computer.
The software systems that do this translation are
called compilers.
Con…
The study of compiler touches upon programming languages,
machine architecture, language theory, algorithms, and
software engineering.
In this preliminary course,
– We introduce the different forms of language translators, give a high
level overview of the structure of a typical compiler, and
– The trends in programming languages and machine architecture that
are shaping compilers.
The Lexical and Syntactic Structure of a
Language
Language is a complex system with various levels of structure.
The lexical and syntactic structure are fundamental
components of language.
In computer science, a lexical grammar or lexical structure is a
formal grammar defining the syntax of tokens.
The program is written using characters that are defined by the
lexical structure of the language used.
The lexical and syntactic structure of a
language
Lexical Structure
Lexicon
– The lexicon is the mental dictionary of words and their meanings.
– It includes all the words, their forms, and their meanings in a language.
– Lexemes are the basic units of the lexicon.
Syntactic Structure
Syntax
– Syntax is the study of sentence structure and how words are combined
to create meaningful sentences.
– It involves the arrangement of words and phrases to convey meaning.
Evolution of Programming Languages
The evolution of programming languages continues with
ongoing advancements and new languages emerging to address
specific needs in various domains.
These languages have shaped the way software is developed,
making it more accessible, efficient, and powerful.
The first step towards more people-friendly programming
languages was the development of mnemonic assembly
languages in the early 1950's.
Evolution of Programming Languages
The key milestones in the evolution of programming
languages:
1. Machine Language (1940s-1950s):
15. C# (2000):
– C#, developed by Microsoft, was designed for Windows application
development and integrated with the .NET framework.
1. Based on Generation
First-generation languages are the machine languages,
Second -generation the assembly languages
Third -generation the higher-level languages like Fortran,
Cobol, Lisp, C, C++, C#, and Java.
Evolution of Programming Languages
Fourth-generation languages are languages designed for
specific applications like
– NOMAD(Novel Materials Discovery) for report generation,
– SQL for database queries, and
– Postscript for text formatting.
Languages such as C++, C#, Java, and Ruby are more recent object-
oriented languages.
Scripting languages are interpreted languages with high-level operators
designed for " gluing together" computations.
Awk, JavaScript, Perl, PHP, Python, Ruby, and Tcl are popular examples of
scripting languages.
High-level programming languages
High-level programming languages are computer programming
languages that are designed to be easier for humans to understand
and use compared to low-level languages.
These languages provide abstractions and a higher level of
functionality, making it more straightforward for programmers to
write code and solve complex problems.
Key Characteristics of High-level Programming Languages:
Abstraction
– High-level languages provide a level of abstraction that
allows programmers to work with concepts and operations
that are closer to human thought processes, rather than
dealing with the intricacies of a computer's hardware.
Readability
– High-level languages use human-readable syntax, making
it easier for programmers to write, read, and understand
code.
Assignment:
Assignment is the process of storing a value in a variable.
– It typically involves using the assignment operator (=) to assign a value to
a variable.
Statements:
Statements are the individual instructions or commands that
make up a program.
Statements can include
– Assignment Statements
– Control Flow Statements (If, While, For)
– Function Calls.
Program Units:
Program units are larger organizational structures within a
program.
They can be;
– Functions
– Methods
– Classes
– Modules, or procedures, depending on the programming
language.
Program units help break down a program into manageable and
reusable components.
Data Environments:
The data environment refers to the scope and lifetime of
variables and data elements in a program.
It determines where variables are visible and how long they
exist.
Variables can have
– Local Scope (only accessible in a specific function or block)
– Global Scope (accessible throughout the entire program).
Parameter Transmission:
Parameter transmission refers to how data is passed to functions or
methods.
It includes concepts like pass by value and pass by reference.
Storage Management:
– Storage management is the process of allocating and deallocating
memory for data structures.
– It ensures that memory is efficiently used and released when no longer
needed.
– Garbage collection is a common technique for managing memory in
languages like Java and Python.
Programming Language basics
Programming languages are used to instruct computers to
perform specific tasks.
They consist of a set of rules and syntax that programmers use
to write code.
Some fundamental concepts and terms related to programming
languages are:
Syntax: refers to the set of rules that dictate how a program must be
written in a particular programming language.
It includes rules for keywords, Punctuation, and structure.
Con…
Variables: Variables are used to store data.
They have a name and a data type (e.g., integers, floating-point numbers,
strings).
These can save you time and effort when developing software.
Error Handling:
Most languages provide mechanisms to catch and handle errors,
Paradigms:
Different programming languages support various programming
Logic Programming.