Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 2: Language Design Principle (Part 1) - Coggle Diagram
Chapter 2: Language
Design Principle (Part 1)
Describing
Syntax
Language: Set of string of
characters from some alphabet.
- Sentence : string of a language aka statements
Lexeme: basic lexical unit of
a language. Includes of identifier, literals,
operator, special word
Token: Category of its
lexeme. Example identifier.
Grammar
Grammars are commonly used to describe the syntax of programming languages.
The context-free grammar (Type 2
Grammar) is useful for describing the syntax of programming languages.
BNF is a popular method for
describing programming language syntax.
Parse tree
Also known as derivation tree
Naturally describe the syntactic
structure of the language define.
Every internal node labeled as non-
terminal symbol.
Every leaf is labeled with a terminal
symbol.
Every subtree describes one
abstraction instances.
Describing semantic
reveals the meaning of the syntax or grammar.
Semantics can be categorized into two types:
Lexical analysis
Lexical analyzer is the first
phase of a compiler.
Part of syntax analysis.
Its main task is to read input
character and process as output a sequence of tokens that parser uses for syntax analysis.
Syntax analysis
Often called parsing.
Syntax analyzer is a parser.
must
check the input program to determine whether it is
syntactically correct .
produce complete
parse tree, or at least trace the structure of the
complete parse tree, for syntactically correct input.
Names
Names/identifier : String of characters used to identify some entity in
a program.
Variables
Programmers often think of variables as names for memory locations, but there is
much more to a variable than just a name.
Data Types
Defines the collection of data values and the set of predefined operations on those values
Binding
Static binding
Early binding
Binds attribute at compile
Dynamic binding
Binds attribute at run time
Type of variable is not specified at declaration
statement
Bind when it is assigned to a value
Type checking
• The compiler must perform static type checking.
• Static type checking is done at the compile time.
• Example: Compiler will report an error if operator is applied to incompatible operand.
Scopes
• The scope of a variable is the range of statements over which it is
visible: Variable yyy is visible in statement st1 if yyy can be referenced in st1.
Static scoping
• Also known as lexical scoping.
• Definition is resolved by searching it containing block or function. If
that fail, then searching the outer containing block and so on.
Dynamic scoping
the definition of the variable is resolved by
searching it containing block and if it is not found, then searching its calling function and if it still not found then the function which called
that calling function will be such will be searched and so on.