Reputation: 49
Sorry for the long code. I've been trying to make a function that takes in a string representation of a GCL program and produces a string representation of a program graph. I can't seem to get the compilerto read the e.label in this line as cexp (since the type Label is composed of cexp or bexp )
let edge2dot(e: Edge) : string =
e.source + " -> " + e.target + "[label=" + prettyPrint(e.label) + "]" + ";"
and was wondering if there is a way to do that?
module Graph
open Types
open Parse
open Parser
open FSharp.Text.Lexing
open System
open AST
type Input = {
determinism: Determinism
}
type Output = { dot: string }
type Node = string
type Label = C of cexp | B of bexp | S
type Edge = {
source : Node;
label : Label;
target : Node;
}
let rec edgesC(ast: cexp, qS:Node,qF:Node): List<Edge> =
match ast with
| Skip -> [{source =qS ; label = S ; target=qF}]
| Assign(_,_) -> [{source = qS; label = C ast; target =qF}]
// | C (c1,c2) -> edgesC(c1, qS, qF) @ edgesC(c2,qS,qF)
| If gc -> edgesGC(gc,qS,qF)
| Do gc -> edgesGC(gc,qS,qF)
and edgesGC (ast, qS, qF) =
match ast with
| Then(b,c) -> [{source =qS ; label = B b ; target=qF}] @ [{source =qS ; label = C c ; target=qF}]
| GC(gc1,gc2) -> edgesGC(gc1,qS,qF) @ edgesGC(gc2,qS,qF)
let ast2pg(ast): List<Edge> =
edgesC(ast,"q0","qf")
let edge2dot(e: Edge) : string =
e.source + " -> " + e.target + "[label=" + prettyPrint(e.label) + "]" + ";"
let rec edges2dot (pg : List<Edge>): string =
match pg with
| [] -> ""
| e::pg -> edge2dot(e) + edges2dot(pg)
let pg2dot (pg : List<Edge>): string =
"digraph program_graph { rankdir=LR;" + edges2dot(pg)+ " }"
Upvotes: 0
Views: 38