Say I have two deterministic finite state automata represented by the following transition diagrams:
FSA for keyword IF: IF
___ ___ _
/ \ I / \ F // \\
>| 0 |----->| 1 |----->||2||
\___/ \___/ \\_//
FSA for an ID: [A-Z][A-Z0-9]*
------------
___ | _ LET |
/ \ LET // \\<------
>| 0 |----->||1||
\___/ \\_//<------
| NUM |
------------
What algorithm may I use to combine them into a single deterministic finite state automata with three final states, represented by the following transition diagram:
-----------------------
| LETTER BUT F OR NUM | --------
___ | _ _ LET v _ | LET |
/ \ I // \\ F // \\----->// \\<------
>| 0 |----->||1||----->||2|| ||3||<--------
\___/ \\_// \\_//----->\\_//<------ |
| NUM | NUM | |
| ANY LETTER OTHER THAN I ------------ |
---------------------------------------------
1: ID
2: IF (IT'S ALSO AN ID, BUT THE KEYWORD IF HAS A HIGHER PRECEDENCE)
3: ID