Transition diagram is a special kind of flowchart for language analysis. In transition diagram the boxes of flowchart are drawn as circle and called as states. States are connected by arrows called as edges. The label or weight on edge indicates the input character that can appear after that state.
Transition diagram of identifier is given below:
This transition diagram for identifier reading first letter and after that letter or digit until the next input character is delimiter for identifier, means the character that is neither letter nor digit. To turn up the transition diagram into a program we construct the program segment code for each state of transition diagram.
Program segment code for each state is given below:
C=GETCHAR(); if LETTER(C) then goto State 1 else FAIL()
C=GETCHAR(); if LETTER(C) OR DIGIT(C) then goto State 1 else if DELIMITER(C) then goto State 2 else FAIL()
RETRACT(); RETURN(ID, INSTALL())
Next character for input buffer we use GETCHAR() which return next character.
LETTER(C) is a procedure which returns the true value if and only if C is a letter.
FAIL(C) is a routine which RETRACT the look ahead pointer and start up the next transition diagram otherwise call error routine.
DIGIT(C) is a procedure which returns the true value if and only if C is a digit.
DELIMITER(C) is a procedure which returns the true value if and only if C Is a character that could follow the identifier for example blank symbol, arithmetic, logical operator, left parenthesis, right parenthesis, +, :, ; etc.
Because DELIMITER is not part of identifier therefore we must RETRACT the look ahead pointer one character for this purpose we use the RETRACT() procedure .
Because identifier has a value so to install the value of identifier in symbol table we use INSTALL() procedure.
- Compiler Theory | Set 1
- Compiler Theory | Set 2
- Compiler Design | Lexical Analysis
- Compiler Design | Introduction to Syntax Analysis
- Compiler Design | Why FIRST and FOLLOW?
- Compiler Design | FIRST Set in Syntax Analysis
- Compiler Design | FOLLOW Set in Syntax Analysis
- Compiler Design | Ambiguous Grammar
- Compiler Design | Runtime Environments
- Compiler Design | Syntax Directed Translation
- Compiler Design | Intermediate Code Generation
- Language Processors: Assembler, Compiler and Interpreter
- Compiler Design | Code Optimization
- Compiler Design | Introduction of Object Code
- Compiler Design | Introduction of Compiler design
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.