syntax analysis
TRANSCRIPT
CONTENTS
o Syntax
o Syntax Terminology
o Syntatic element of the Language
o Syntax Analysis
o Formal Methods of Describing Syntax
Grammar
Parts of Grammars
Parse Tree
Syntax Diagram
1
Syntax
“The arrangement of words as elements in a sentence to show their relationship” describes the sequence of symbols that make up valid programs.
Form of expressions, statements and program units.
2
Syntax Terminology A sentence is a string of characters over some alphabet
A language is a set of sentences
A lexeme is the lowest level syntactic unit of a language (e.g., *, sum, begin)
A token is a category of lexemes (e.g., identifier)
3
Syntactic elements of the Language
Keywords and reserved words – is an identifier used as a fixed part of the syntax of a statement. It is a reserved word if it may not be used as a programmer-chosen identifier.
Noise words – optional words that are inserted in a statements to improved readability.
4
Syntactic elements of the Language
Comments – important part of the documentation. REM, /* */, or //
Blank (spaces)
Delimiters – a syntactic element used simply to mark the beginning or end of some syntactic unit such as a statement or expression. “begin”…”end”, or { }.
5
Syntactic Analysis
Determines if the program being compiled is a valid sentence in the syntactic model programming language.
6
Grammars
Formal definition of the syntax of a programming language.
Collection of rules that define, mathematically, which strings of symbols are valid sentences.
8
Parts of Grammar
Set of tokens/terminal symbols
symbols that are atomic / non-divisible
can be combined to form valid constructs in the language
Set of non-terminal symbols
symbols used to represent intermediate definitions within the language
defined by productions
syntactic classes or categories
9
Parse Tree
Parse trees are trees level by symbols of a particular context free grammar(CFG).
Leaves : level by a terminal.
Interior nodes: level by a variable.
Root: must be level by the start symbol.
10