Syntax Semantics Lexical
Syntax Semantics Lexical
DESCRIBING
SYNTAX AND
SEMANTICS
Presented By : Group 2
OVERVIEW
3.1 Introduction
LEXEMES TOKENS
index identifier
= equal_sign
2 int_literal
* mult_op
count identifier
+ plus_op
17 int_literal
; semicolon
FLOW OF LEXEMES AND
TOKENS
In general, languages can be formally defined in two distinct ways:
by recognition and by generation (although neither provides a
definition that is practical by itself for people trying to learn or use
a programming language).
3.2.1 LANGUAGE RECOGNIZERS
Language recognizers are mechanisms or algorithms used to
determine whether a given string of characters belongs to a
specific language.
To formally define a language using the recognition method, a
mechanism called a recognition device is constructed. This
device is capable of reading input strings of characters from
the language's alphabet and indicating whether a given input
string is in the language or not. Essentially, the recognition
device acts as a filter, separating valid strings (those
belonging to the language) from invalid ones.
3.2.2 LANGUAGE GENERATORS
A language generator is a device that can be used to generate
the sentences of a language. We can think of the generator as
having a button that produces a sentence of the language
every time it is pushed. Because the particular sentence that is
produced by a generator when its button is pushed is
unpredictable, a generator seems to be a device of limited
usefulness as a language descriptor.
LANGUAGE RECOGNIZER LANGUAGAE GENERATOR
Outputs a binary result (accept or reject) Outputs strings that belong to the
for each input string. language.
C
3.3.1.7 AMBIGUITY
EBNF:
<expr> → <term> {(+ | -) <term>}
ident = var
ident = ident + 1
ident = ident – 1
goto label
if var relop var goto label
3.5.1.1 BASIC PROCESS
The statement consists of relational operators relop, ident, and var,
which are easy to understand and implement. A slight generalization
allows for more general arithmetic expressions and assignment
statements.
The Vienna Definition Language (VDL) was the first significant use of
formal operational semantics to describe the semantics of PL/I, an
abstract machine designed by IBM. This method is effective for language
users and implementors, but can lead to circularities. More formal
methods, based on mathematics and logic, are discussed in subsequent
sections.
3.5.2 DENOTATIONAL
SEMANTICS
Denotational semantics is a formal method for describing the meaning
of programs, based on recursive function theory. It involves defining
mathematical objects and functions for each language entity, mapping
instances of that entity onto mathematical objects. These objects model
the exact meaning of their corresponding entities. Denotational
semantics is related to operational semantics, which translate
programming language constructs into simpler ones. However, unlike
operational semantics, denotational semantics does not model the step-
by-step computational processing of programs. The process of
constructing a denotational semantics specification for a programming
language is complex and requires rigorous manipulation of
mathematical objects.
3.5.2.1 TWO SIMPLE EXAMPLES
<bin_num> → '0'
|'1'
| <bin_num> '0'
| <bin_num> '1'
3.5.2.1 TWO SIMPLE EXAMPLES
Variable names and associated values are represented by v's, with undef
values indicating undefined variables. VARMAP, a function with two
parameters, maps states to states to define program meanings. Some
language constructs, like expressions, are mapped to values.
3.5.2.3 EXPRESSIONS
LEXICAL AND
SYNTAX
ANALYSIS
Presented By : Group 2
OVERVIEW
4.1 Introduction