SYNTAX ANALYSER Flashcards
what is the job of the syntax analyzer
Syntax Analyzer creates the syntactic structure of the given source program.
This syntactic structure is mostly a parse tree. A syntax analyzer is also known as parser.
The syntax analyzer (parser) checks whether a given source program satisfies the rules implied by a context-free grammar or not.
The syntax of a programming is described by a ?
context-free grammar (CFG).
Classifications of errors
Lexical errors
Syntactic errors
Semantic errors
Logical errors
Describe lexical error
These errors are mainly spelling mistakes and accidental insertion of foreign characters, for e.g.. ‘$’, if the language does not allow it. They are mostly caught by the lexical analyzer.
Describe syntactic errors
Syntactic error: These are grammatical mistakes , such as unbalanced parentheses in arithmetic expressions.
Describe semantic errors
Semantic error: involve errors due to undefined variables, incompatible operands to an operator etc.
Describe logical errors
These are errors such as infinite loops. There is not any way to catch the logical error automatically.
Goals of the error handler
- It should report the presence or error cleanly & accurately.
- It should recover from each error quickly enough to be able to detect subsequent errors.
- It should not significantly slow down the processing of the correct program.
What is a terminal?
A terminal is a discrete symbol that can appear in the language, otherwise known as a token. Examples of terminals are keywords, operators, and identifiers. We will use lower-case letters to represent terminals.
E.g a,b,c,+,-,punc,0,1,…,9,
What is a non-terminal
A non-terminal represents a structure that can occur in a language, but is not a literal symbol. Example of non-terminals are declarations, statements, and expressions.
We will use upper-case letters to represent non-terminals: P for program, S for statement, E for expression, etc.
E.g A,B,C,S,
What is a CFG
A context-free grammar (CFG) is a list of rules that formally describe the allowable sentences in a language.
The left-hand side of each rule is always a single non-terminal.
The right-hand side of a rule is a sentential form that describes an allowable form of that non-terminal.
E.g the rule A -> xXy indicates that the non-terminal A represents a terminal x followed by a non-terminal X and a terminal y.
A Context Free Grammar, CFG, is described by T, NT, S, PR, where:
T: Terminals / tokens of the language
NT: Non-terminals to denote sets of strings generated by the grammar & in the language
S: Start symbol, SNT, which defines all strings of the language
PR: Production rules to indicate how T and NT are combined to generate valid strings of the language.
They are two approaches to parsing
top-down and bottom-up.
What is a sentence?
A sentence is a valid sequence of terminals in a language,