如何绘制自动机图? [英] how to draw an automaton diagram?

查看:226
本文介绍了如何绘制自动机图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我根据许多人给我的建议使用了graphviz,但遇到了问题.我想使用Format.moduleocaml中写一个点,并且我有一条记录,其中包含五个字段,这些字段定义了一个自动机,该自动机包括由int*char*int列表表示的过渡和由列表.第一个字段是初始状态,它是一个int.我还定义了一个函数成员,该成员接受一个参数并测试它是否是给定列表的成员.我该如何做才能写出一个完整的点来识别初始状态,并用节点[shape = point]start ; start -> x表示该点,而其他过渡用圆圈表示,而最终状态则用双圆圈表示?我尝试这样做,但是在编译时遇到了问题

I used graphviz based on the recommendation given to me by many people but I ran into a problem. I want to write a dot in ocaml using the Format.module and I have a record with five fields that define an automaton including the transitions which are represented by a list of int*char*int and final states which are represented by an int list. The first field is the initial state which is one int. I also defined a function member that takes a parameter and tests if it is a member of a given list. How can I do so that I can write a full dot that recognizes the initial state and represent it with node [shape = point]start ; start -> x and the other transitions with circles and the final states with doublecircles? I tried doing it but I ran into problems When I compile it, it says

文件"automatagraphicstest1.ml",第44行,字符22-37:错误: 该表达式具有类型 自动化-> Format.formatter-> int * char * int-> unit 但是期望使用Format.formatter->'a-> unit类型的表达式 自动类型与Format.formatter类型不兼容

File "automatagraphicstest1.ml", line 44, characters 22-37: Error: This expression has type automate -> Format.formatter -> int * char * int -> unit but an expression was expected of type Format.formatter -> 'a -> unit Type automate is not compatible with type Format.formatter

推荐答案

要解决您的类型错误,只需将fmt_transitions函数替换为:

To fix your type error, just replace the fmt_transitions function by this:

let fmt_transitions fmt auto =
  Format.fprintf fmt "@[<v 2>digraph output {@,%a@,@]}@,@."
    (Format.pp_print_list (fmt_transition1 auto)) auto.transitions

您的问题是pp_print_list需要类型为Format.formatter -> 'a -> unit的东西.您的函数fmt_automaton1将自动机作为额外的第一个参数,因此我们需要先部分应用它,然后才能提供转换列表.

Your issue is that pp_print_list expects something of type Format.formatter -> 'a -> unit. Your function fmt_automaton1 takes the automaton as extra first argument, so we need to partially apply it first, then we can provide the list of transitions.

这篇关于如何绘制自动机图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆