0% found this document useful (0 votes)
61 views

Syntax and Semantics

Syntax refers to the form and structure of a language, while semantics refers to the meaning. The key points are: 1. Syntax is the grammar of a language and involves rules for constructing expressions out of symbols. It focuses on structure without considering meaning. 2. Semantics is the meaning assigned to parts of a language. It relates the syntax to the model of computation to determine how a program will execute. 3. Different techniques are used to describe the syntax and semantics of programming languages, including grammars, derivation trees, and formal semantics approaches like operational and denotational semantics.

Uploaded by

Eash G.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Syntax and Semantics

Syntax refers to the form and structure of a language, while semantics refers to the meaning. The key points are: 1. Syntax is the grammar of a language and involves rules for constructing expressions out of symbols. It focuses on structure without considering meaning. 2. Semantics is the meaning assigned to parts of a language. It relates the syntax to the model of computation to determine how a program will execute. 3. Different techniques are used to describe the syntax and semantics of programming languages, including grammars, derivation trees, and formal semantics approaches like operational and denotational semantics.

Uploaded by

Eash G.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Syntax and Semantics

Languages in General

• All languages have a set of symbols, rules for constructing compound constructions
out of atomic constructions and meaning assigned to the significant units.
– E.g., the letter ‘A’ is part of English, buy not part of Hindi.
– E.g., English is a Subject-Verb-Object language, where Arabic is Subject-
Object-Verb language.
– E.g., ‘snow’ means snow in English, but ‘schnee’ means snow in German.
• Syntax :The form or structure of the expressions, statements, and program units. It is the
grammar of the language.
• Semantics: The meaning of significant parts(expressions, statements, and program
units.
Comparison Chart
BASIS FOR COMPARISON SYNTAX SEMANTICS

Basic Permitted phrases of a Interpretation of the


language. phrases.

Errors Handled at the compile Confronted at runtime.


time.

Relation Syntactic interpretation Semantic component is


must have some distinctive associated with a syntactic
meaning. representation.
Syntax
• The Syntax of a programming language is used to signify the structure of
programs without considering their meaning.
• It basically emphasizes the structure, layout of a program with their
appearance.
• It involves a collection of rules which validates the sequence of symbols
and instruction used in a program.
• The pragmatic and computation model figures these syntactic components
of a programming language.
• The tools evolved for the specification of the syntax of the programming
languages are regular, context-free and attribute grammars (AUTOMATA
THEORY)
Syntax (Grammar)
• The Grammars generally are the rewriting rules whose purpose is to recognize
and generate the programs.
• Grammar does not rely on the computation model instead used in the description
of the structure of the language.
• The grammar contains a finite set of grammatical categories (such as noun
phrase, verb phrase, article, noun, etc), solitary words (elements of the
alphabets) and the well-formed rules to specify the order within which
components of the grammatical categories should appear.
Derivation Tree --- (7+3)* (5-2)

b
a = b + const
Syntax Analysis

• Syntax analysis is a task performed by a compiler which examines whether the


program has a proper associated derivation tree or not.
• The syntax of a programming language can be interpreted using the following formal
and informal techniques:
– Lexical syntax for defining the rules for basic symbols involving
identifiers, literals, punctuators and operators.
– Concrete syntax specifies the real representation of the programs with
the help of lexical symbols like its alphabet.
– Abstract syntax conveys only the vital program information
Types of grammars
• Context-free grammar is prevalently used to figure out the whole language
structure.
• Regular expressions describe the lexical units (tokens) of a programming
language.
• Attribute grammars specify the context-sensitive part of the language.
Semantics
• Semantics term in a programming language is used to figure out the relationship
among the syntax and the model of computation.
• It emphasizes the interpretation of a program so that the programmer could understand
it in an easy way or predict the outcome of program execution.
• An approach known as syntax-directed semantics is used to map syntactical
constructs to the computational model with the help of a function.
• The programming language semantics can be described by the various techniques
» Axiomatic semantics
» Operational semantics
» Denotational semantics
» Translation semantics.
» Algebraic semantics
Semantics Techniques
• Algebraic semantics interprets the program by defining an algebra.
• Axiomatic semantics determine the meaning of a program by building assertions
about an association that detain at each point in the execution of the program (i.e.
implicitly).
• Operational semantics compares the languages to the abstract machine, and the
program is then evaluated as a sequence of the state transitions.
• Denotational semantics expresses the meaning of the program in the form of a set of
functions operating on the program state.
• Translational semantics focuses on the methods used for translating a program into
another language.

You might also like