Transition diagram for Identifiers in Compiler Design
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.