CSCI351-Week 2-Lecture 1
CSCI351-Week 2-Lecture 1
and Semantics
3.3.1.3 Fundamentals
• Implementers
Lexeme Token
index identifier
= equal_sign
2 int_literal
* mult_operator
count identifier
+ plus_operator
17 int_literal
; semicolon
CSCI351 - Concepts of Programming
1-5
Languages
The General Problem of Describing
Syntax (3/3)
• Recognizers
– Read a string and decide whether it follows the rules for the
language
– Example: syntax analysis part of a compiler (Chapter 4) (Not
included in the course)
• Generators
– A device that generates sentences of a language (BNF)
(Chapter 3)
– More useful for specifying the language than for checking a
string
Type Characteristics
0 Unrestricted
1 Context-sensitive
2 Context-free
3 Regular
<stmt> <single_stmt>
| begin <stmt_list> end
CSCI351 - Concepts of Programming
1-9
Languages
Backus-Naur Form and Context-Free
Grammars (3/9)
• Fundamentals (2/2)
– A rule has a left-hand side (LHS) and a right-hand side (RHS),
and consists of terminal and nonterminal symbols
<ident_list> → <ident>
| <ident>, <ident_list>
<arg_list> → <expr>
Example:
| <expr>, <arg_list>
<digit> 0|1|2|3|4
<param_list> → <param> |5|6|7|8|9
| param, <param_list>
<integer> <digit>
<stmt_list> → <stmt> | <digit> <integer>
| <stmt>; <stmt_list>
CSCI351 - Concepts of Programming
1-11
Languages
Backus-Naur Form and Context-
Free Grammars (5/9)
• Grammars and Derivations (1/5)
– A Grammar for a Small Language
begin A = B + C; B = C end