PreviousUpNext

15.4.28  src/app/future-lex/src/backends/dump/dump-output.pkg

## dump-output.pkg
## John Reppy (http://www.cs.uchicago.edu/~jhr)
## Aaron Turon (adrassi@gmail.com)
## All rights reserved.

# Compiled by:
#     src/app/future-lex/src/lexgen.lib




# Dump (to stdout) the complete DFA

package dump_output: (weak)  Output {           # Output        is from   src/app/future-lex/src/backends/output.api

    package re= regular_expression;             # regular_expression    is from   src/app/future-lex/src/regular-expression.pkg
    package lo= lex_output_spec;                # lex_output_spec       is from   src/app/future-lex/src/backends/lex-output-spec.pkg

    fun name_of (lo::STATE { id, ... } )
        =
        "Q" + int::to_string id;

    fun pr_state (s as lo::STATE { id, label, final, next, ... } )
        =
        {   name = case final
                     
                        []     =>  name_of s;
                        id ! _ =>  cat [name_of s, " (act ", int::to_string id, ")"];
                   esac;

            fun pr_edge (symbol_set, st)
                =
                print (cat [
                    "  -- ", re::to_string (re::make_symbol_set symbol_set), " --> ", name_of st, "\n"
                  ]);

            fun pr_re re
                =
                print (cat [" ", re::to_string re, "\n"]);

            print (cat [name, ": "/*, re::to_string label*/, "\n"]);
            vector::apply pr_re label;
            list::apply pr_edge *next;
            print "\n";
        };

    fun dump_dfa states
        = 
        {   list::apply pr_state states;
            print (int::to_string (list::length states));
            print " states\n\n";
        };


    fun out_ss (label, ss)
        =
        {   print "Start state: ";
            print label; print " => "; print (name_of ss);
            print "\n";
        };

    fun output (spec, _)
        =
        {   my lo::SPEC { dfa, start_states, ... }
                =
                spec;
          
            dump_dfa dfa;
            print "\n";
            list::apply out_ss start_states;
        };
};


## COPYRIGHT (c) 2005 
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext