sqlite3源码学习——parseonetoken()函数有限状态机

在parseonetoken()函数中解析parse.y文件,并将解析的内容保存到pstate结构体中。解析过程中使用有限状态机来依次将parse.y文件中的内容提取出来。我使用graphviz将状态机画出来,由于图片太大显示效果不好,将dot程序记录下来,如果要看图片,直接将下面的代码拷贝到graphviz中执行即可生成图片。

digraph G{
    INITIALIZE -> WAITING_FOR_DECL_OR_RULE;
    
    WAITING_FOR_DECL_OR_RULE -> WAITING_FOR_DECL_KEYWORD    [label = "%"];
    WAITING_FOR_DECL_OR_RULE -> WAITING_FOR_ARROW           [label = "ISLOWER"];
    WAITING_FOR_DECL_OR_RULE -> WAITING_FOR_DECL_OR_RULE    [label = "'{'"];
    WAITING_FOR_DECL_OR_RULE -> PRECEDENCE_MARK_1           [label = "'['"];
    
    PRECEDENCE_MARK_1 -> PRECEDENCE_MARK_2                  [label = "ISUPPER && prevrule==0"];
    PRECEDENCE_MARK_2 -> WAITING_FOR_DECL_OR_RULE           [label = "']'"];
    
    WAITING_FOR_ARROW -> IN_RHS                             [label = "::="];
    WAITING_FOR_ARROW -> LHS_ALIAS_1                        [label = "'('"];
    LHS_ALIAS_1 -> LHS_ALIAS_2                              [label = "ISALPHA"];
    LHS_ALIAS_2 -> LHS_ALIAS_3                              [label = "')'"];
    LHS_ALIAS_3 -> IN_RHS                                   [label = "::="];
    
    IN_RHS -> WAITING_FOR_DECL_OR_RULE                      [label = "'.'"];
    IN_RHS -> IN_RHS                                        [label = "ISALPHA"];
    IN_RHS -> RHS_ALIAS_1                                   [label = "'('"];
    RHS_ALIAS_1 -> RHS_ALIAS_2                              [label = "ISALPHA"];
    RHS_ALIAS_2 -> IN_RHS                                   [label = "')'"];
    
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "name"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "include"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "code"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "token_destructor"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "default_destructor"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "token_prefix"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "syntax_error"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "parse_accept"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "parse_failure"];    
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "stack_overflow"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "extra_argument"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "extra_context"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "token_type"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "default_type"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "stack_size"];    
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DECL_ARG        [label = "start_symbol"];    
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_PRECEDENCE_SYMBOL [label = "left"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_PRECEDENCE_SYMBOL [label = "right"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_PRECEDENCE_SYMBOL [label = "nonassoc"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DESTRUCTOR_SYMBOL [label = "destructor"];    
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_DATATYPE_SYMBOL     [label = "type"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_FALLBACK_ID         [label = "fallback"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_TOKEN_NAME          [label = "token"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_WILDCARD_ID         [label = "wildcard"];
    WAITING_FOR_DECL_KEYWORD -> WAITING_FOR_CLASS_ID            [label = "token_class"];
    
    WAITING_FOR_DESTRUCTOR_SYMBOL -> WAITING_FOR_DECL_ARG       [label = "ISALPHA"];
    WAITING_FOR_DATATYPE_SYMBOL -> WAITING_FOR_DECL_ARG         [label = "ISALPHA && new symbol"];
    
    WAITING_FOR_PRECEDENCE_SYMBOL -> WAITING_FOR_DECL_OR_RULE       [label = "'.'"];
    WAITING_FOR_PRECEDENCE_SYMBOL -> WAITING_FOR_PRECEDENCE_SYMBOL  [label = "ISUPPER"];
    
    WAITING_FOR_DECL_ARG -> WAITING_FOR_DECL_OR_RULE                [label = "'{' or ISALNUM"];
    
    WAITING_FOR_FALLBACK_ID -> WAITING_FOR_DECL_OR_RULE             [label = "'.'"];
    WAITING_FOR_FALLBACK_ID -> WAITING_FOR_FALLBACK_ID              [label = "ISUPPER"];
    
    WAITING_FOR_TOKEN_NAME -> WAITING_FOR_DECL_OR_RULE              [label = "'.'"];
    WAITING_FOR_TOKEN_NAME -> WAITING_FOR_TOKEN_NAME                [label = "ISUPPER"];
    
    WAITING_FOR_WILDCARD_ID -> WAITING_FOR_DECL_OR_RULE             [label = "'.'"];
    WAITING_FOR_WILDCARD_ID -> WAITING_FOR_WILDCARD_ID              [label = "ISUPPER"];
    
    WAITING_FOR_CLASS_ID -> WAITING_FOR_CLASS_TOKEN                 [label = "ISLOWER && new symbol"];
    WAITING_FOR_CLASS_TOKEN -> WAITING_FOR_DECL_OR_RULE             [label = "'.'"];
    WAITING_FOR_CLASS_TOKEN -> WAITING_FOR_CLASS_TOKEN              [label = "ISUPPER"];
}

 

你可能感兴趣的:(2019.07)