首页 > 解决方案 > 有人可以在 flex-lexer 中解释 NFA 到 DFA 的转换吗?

问题描述

我有一个非常简单的 test.l 文件,如下所示:

...
    %%
    
    [aeiou]+ {printf("aeiou");}
    ^r {printf("^r");}
    
    %%
...

我使用 flex-2.6.0 从中创建了 lex.yy.c。我跟踪了 flex-2.6.0 的源代码,一切都很好,直到 ntod 函数(在 dfa.c 中)。它主要将NFA状态转换为DFA状态。让我困惑的是:

  1. sympartition 函数是做什么用的?(根据我的理解,.l 规范创建了三个等价类:aeiou、r、and . for any other. ccltbl 已转换为它们的等价类编号。那么为什么它使用 mkeccl 函数来获取 duplist,以及duplist 用于什么?和 cclng ?你能解释一下 sympartition 的细节吗?)
  2. 为什么 duplist[sym] == NIL 意味着符号具有唯一的输出过渡?至于symfollowset,我想如果我完全了解sympartition,我就会理解它。

NFA状态如下图:

********** beginning dump of nfa with start state 11
state #    1    257:     0,    0
state #    2    257:     0,    0
state #    3     -1:     4,    0
state #    4    257:     3,    0  [1]
state #    5    257:     1,    3
state #    6    114:     7,    0
state #    7    257:     0,    0  [2]
state #    8    257:     2,    6
state #    9     -2:    10,    0
state #   10    257:     0,    0  [3]
state #   11    257:     5,    9
********** end of dump

标签: flex-lexerlexical-analysisfinite-automatadfanfa

解决方案


推荐阅读