Professional Documents
Culture Documents
PART I: Overview Material: 2 Language Processors (Tombstone Diagrams, Bootstrapping) 3 Architecture of A Compiler
PART I: Overview Material: 2 Language Processors (Tombstone Diagrams, Bootstrapping) 3 Architecture of A Compiler
parse
// a dummy statement
parse X Y
parse X
parse Y
parse X | Y
switch (currentToken.kind) {
cases in starters[X]:
parse X
break;
cases in starters[Y]:
parse Y
break;
default:
if neither X nor Y generates then report syntax error
}
Syntax Analysis (Chapter 4) 14
Example: “Generation” of parseCommand
For example:
single-Command
::= V-name := Expression
| Identifier ( Expression )
| ...
V-name ::= Identifier
Starters[V-name := Expression]
= Starters[V-name] = Starters[Identifier]
Starters[Identifier ( Expression )]
= Starters[Identifier] NOT DISJOINT!
Syntax Analysis (Chapter 4) 19
LL 1 grammars: left factorization
What happens when we generate a RD parser from a non LL 1 grammar?
single-Command
::= V-name := Expression
| Identifier ( Expression )
| ...
single-Command
::= V-name := Expression
| Identifier ( Expression )
| ...
single-Command
::= Identifier
( := Expression | ( Expression ) )
| ...