Commit 347b957a authored by Michaël Cadilhac's avatar Michaël Cadilhac
Browse files

Add TAF-Kit for Z weighted automata.

- taf-kit/src/ratexp_commands.hh: New. RatExp specific commands. Not
common because RatExp are not handled for every type of automata.
- taf-kit/src/common_commands.hh: Update accordingly.
- taf-kit/src/interface.hh,
- taf-kit/src/interface.cc: New. Interface to choose a command and to
list them.
- taf-kit/src/commands.hh,
- taf-kit/src/b_commands.cc: Update accordingly.
- taf-kit/src/z_commands.cc: New. Z weighted automata support.
- taf-kit/src/Makefile.am: Add `vcsn-z'.
parent b5f7579c
2006-07-19 Michal Cadilhac <michael.cadilhac@lrde.epita.fr>
Add TAF-Kit for Z weighted automata.
* taf-kit/src/ratexp_commands.hh: New. RatExp specific commands. Not
common because RatExp are not handled for every type of automata.
* taf-kit/src/common_commands.hh: Update accordingly.
* taf-kit/src/interface.hh,
* taf-kit/src/interface.cc: New. Interface to choose a command and to
list them.
* taf-kit/src/commands.hh,
* taf-kit/src/b_commands.cc: Update accordingly.
* taf-kit/src/z_commands.cc: New. Z weighted automata support.
* taf-kit/src/Makefile.am: Add `vcsn-z'.
2006-07-19 Akim Demaille <akim@lrde.epita.fr>
Factor a bit in composition.
......
......@@ -17,7 +17,7 @@ include $(top_srcdir)/src/vaucanson.mk
AM_CPPFLAGS += $(CXXFLAGS_OPTIMIZE)
AM_LDFLAGS = $(TERMLIBS)
Progs = vcsn-b
Progs = vcsn-b vcsn-z
if VCSN_TAF_KIT
bin_PROGRAMS = $(Progs)
......@@ -33,6 +33,8 @@ COMMON_SOURCES = commands.hh \
edit_automaton.hxx \
getters.hh \
getters.hxx \
interface.cc \
interface.hh \
main.cc \
predefined_alphabets.hh
......@@ -41,9 +43,16 @@ vcsn_b_CPPFLAGS = $(AM_CPPFLAGS) \
-DCONTEXT_HEADER="<vaucanson/boolean_automaton.hh>" \
-DCONTEXT_NAMESPACE="vcsn::boolean_automaton"
vcsn_z_CPPFLAGS = $(AM_CPPFLAGS) \
-DCONTEXT_HEADER="<vaucanson/z_automaton.hh>" \
-DCONTEXT_NAMESPACE="vcsn::z_automaton"
vcsn_b_SOURCES = $(COMMON_SOURCES) \
b_commands.cc
ratexp_commands.hh b_commands.cc
vcsn_z_SOURCES = $(COMMON_SOURCES) \
ratexp_commands.hh z_commands.cc
## ------ ##
## argp. ##
......
// b_commands.cc: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
......@@ -24,6 +25,7 @@
*/
#include "commands.hh"
#include "ratexp_commands.hh"
#include "common_commands.hh"
/*-------------------.
......@@ -44,11 +46,17 @@ DEFINE_ONE_ARG_COMMAND_TWO_ALGOS (NAME (determinize)
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (complement));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (minimization_hopcroft));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (minimization_moore));
/*-----------------------------.
| Define the set of commands. |
`-----------------------------*/
static const command_t command_map[] =
const command_t command_map[] =
{
COMMAND_GROUP (
"Input/output work with automata:",
......@@ -128,68 +136,3 @@ static const command_t command_map[] =
"Give the Thompson automaton of `exp'.")),
{0, 0, 0, 0, 0}
};
/*----------.
| Interface |
`----------*/
/// List all the commands.
void list_commands ()
{
echo ("List of available commands:");
for (const command_t* command = command_map; command->docstring; ++command)
if (command->name)
echo (" - " << command->name << " " << command->params
<< ": " << command->docstring);
else
echo (" * " << command->docstring);
}
/// Tell if two strings are equal, modulo dashes and underscores.
bool equal_without_dashes (const char* s, const char* t)
{
#define skip_dashes_and_underscores() \
while (*s == '-' or *s == '_') \
++s; \
while (*t == '-' or *t == '_') \
++t;
skip_dashes_and_underscores ();
while (*s and *t)
{
if (*s++ != *t++)
return false;
skip_dashes_and_underscores ();
};
return *s == 0 and *t == 0;
#undef skip_dashes_and_underscores
}
/**
* Execute an command according to the program's arguments.
*
* @param args Arguments.
*
* @return -1 on wrong number of args, -2 on inexistent algo,
* the result of the command otherwise.
*/
int execute_command (const arguments_t& args)
{
for (const command_t* command = command_map; command->docstring; ++command)
if (command->name && equal_without_dashes (command->name, args.args[0]))
{
if (command->n_params != args.n_args - 1)
{
warn (args.progname << ": wrong number of arguments for `"
<< command->name << " " << command->params << "' (should be "
<< command->n_params << ").");
warn ("Try `" << args.progname << " --list-commands'"
<< " for more information.");
return -1;
}
return command->command (args);
}
warn (args.progname << ": command `" << args.args[0] << "' doesn't exist.");
return -2;
}
......@@ -26,11 +26,6 @@
# include "common.hh"
int execute_command (const arguments_t&);
void list_commands ();
struct command_t
{
const char* name;
......@@ -40,4 +35,6 @@ struct command_t
const char* docstring;
};
extern const command_t command_map[];
#endif /* !COMMANDS_HH */
......@@ -46,9 +46,9 @@ using vcsn::xml::XML;
# include "commands_macros.hh"
/*-------------------.
| Command definition |
`-------------------*/
/*---------------------------------------.
| Command definition (RatExp excluded). |
`---------------------------------------*/
DEFINE_IS_PROPERTY_COMMAND (ambiguous);
......@@ -58,12 +58,6 @@ DEFINE_IS_PROPERTY_COMMAND (realtime);
DEFINE_IS_PROPERTY_COMMAND (standard);
DEFINE_ONE_ARG_COMMAND (ARG_KIND (exp)
ALGO (standard_of));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (exp)
ALGO (thompson_of));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (trim));
......@@ -82,13 +76,6 @@ DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (normalize));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (minimization_hopcroft));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (aut)
ALGO (minimization_moore));
DEFINE_ONE_ARG_COMMAND_TWO_ALGOS (NAME (quotient)
ARG_KIND (aut)
ALGOS (quotient, realtime));
......@@ -108,20 +95,6 @@ DEFINE_TWO_ARGS_COMMAND (ARG_KIND (aut)
ALGO (concatenate));
DEFINE_COMMAND (NAME (derived_term_automaton)
CODE (
rat_exp_t e = get_exp (args.args[1]);
automaton_t a = make_automaton (get_alphabet (args.alphabet));
derived_term_automaton (a, e))
OUTPUT (automaton_saver (a, string_out (), XML ()))
RETURNVALUE (0));
DEFINE_COMMAND (NAME (aut_to_exp)
CODE (/* Empty */)
OUTPUT (aut_to_exp (get_aut (args.args[1]), DMChooser ())
<< std::endl)
RETURNVALUE (0));
DEFINE_COMMAND (NAME (are_isomorphic)
CODE (bool b = are_isomorphic (get_aut (args.args[1]),
get_aut (args.args[2])))
......@@ -155,11 +128,6 @@ DEFINE_COMMAND (NAME (power)
OUTPUT (automaton_saver (p, string_out (), XML ()))
RETURNVALUE (0));
DEFINE_COMMAND (NAME (expand)
CODE (/* Empty */)
OUTPUT (expand (get_exp (args.args[1])))
RETURNVALUE (0));
DEFINE_COMMAND (NAME (info)
CODE (automaton_t a = get_aut (args.args[1]))
OUTPUT (
......
// interface.cc: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
/**
* @file interface.cc
* @author Michaël Cadilhac <michael.cadilhac@lrde.org>
*
* Interface for TAF-Kit.
*/
#include "interface.hh"
#include "commands.hh"
/*----------.
| Interface |
`----------*/
/// List all the commands.
void list_commands ()
{
echo ("List of available commands:");
for (const command_t* command = command_map; command->docstring; ++command)
if (command->name)
echo (" - " << command->name << " " << command->params
<< ": " << command->docstring);
else
echo (" * " << command->docstring);
}
/// Tell if two strings are equal, modulo dashes and underscores.
static bool equal_without_dashes (const char* s, const char* t)
{
for (; *s and *t; ++s, ++t)
if (*s != *t
and *s != '-' and *s != '_'
and *t != '-' and *t != '_')
return false;
return *s == 0 and *t == 0;
}
/**
* Execute an command according to the program's arguments.
*
* @param args Arguments.
*
* @return -1 on wrong number of args, -2 on inexistent algo,
* the result of the command otherwise.
*/
int execute_command (const arguments_t& args)
{
for (const command_t* command = command_map; command->docstring; ++command)
if (command->name && equal_without_dashes (command->name, args.args[0]))
{
if (command->n_params != args.n_args - 1)
{
warn (args.progname << ": wrong number of arguments for `"
<< command->name << " " << command->params << "' (should be "
<< command->n_params << ").");
warn ("Try `" << args.progname << " --list-commands'"
<< " for more information.");
return -1;
}
return command->command (args);
}
warn (args.progname << ": command `" << args.args[0] << "' doesn't exist.");
return -2;
}
// interface.hh: this file is part of Vaucanson.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#ifndef INTERFACE_HH
# define INTERFACE_HH
/**
* @file interface.hh
* @author Michaël Cadilhac <michael.cadilhac@lrde.org>
*
* Interface for TAF-Kit.
*/
# include "common.hh"
int execute_command (const arguments_t&);
void list_commands ();
#endif /* !INTERFACE_HH */
......@@ -30,6 +30,7 @@
#include "common.hh"
#include "predefined_alphabets.hh"
#include "commands.hh"
#include "interface.hh"
/**
* Base info for the program.
......
// ratexp_commands.hh: this file is part of Vaucanson.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
#ifndef RATEXP_COMMANDS_HH
# define RATEXP_COMMANDS_HH
/**
* @file ratexp_commands.hh
* @author Michaël Cadilhac <michael.cadilhac@lrde.org>
*
* Commands declaration and definition for all type of automata.
*/
# include "common.hh"
# include CONTEXT_HEADER
# include <vaucanson/xml/XML.hh>
# include <vaucanson/tools/dot_display.hh>
# include <vaucanson/tools/dot_dump.hh>
using namespace CONTEXT_NAMESPACE;
using namespace vcsn;
using namespace vcsn::io;
using vcsn::xml::XML;
# include <cstdlib>
# include <iostream>
# include "getters.hh"
# include "commands.hh"
# include "commands_macros.hh"
/*---------------------------------------------------.
| Command definition of RatExp specific algorithms. |
`---------------------------------------------------*/
DEFINE_ONE_ARG_COMMAND (ARG_KIND (exp)
ALGO (standard_of));
DEFINE_ONE_ARG_COMMAND (ARG_KIND (exp)
ALGO (thompson_of));
DEFINE_COMMAND (NAME (derived_term_automaton)
CODE (
rat_exp_t e = get_exp (args.args[1]);
automaton_t a = make_automaton (get_alphabet (args.alphabet));
derived_term_automaton (a, e))
OUTPUT (automaton_saver (a, string_out (), XML ()))
RETURNVALUE (0));
DEFINE_COMMAND (NAME (aut_to_exp)
CODE (/* Empty */)
OUTPUT (aut_to_exp (get_aut (args.args[1]), DMChooser ())
<< std::endl)
RETURNVALUE (0));
DEFINE_COMMAND (NAME (expand)
CODE (/* Empty */)
OUTPUT (expand (get_exp (args.args[1])))
RETURNVALUE (0));
#endif /* !RATEXP_COMMANDS_HH */
// z_commands.cc: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
//
// Copyright (C) 2006 The Vaucanson Group.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// The complete GNU General Public Licence Notice can be found as the
// `COPYING' file in the root directory.
//
// The Vaucanson Group consists of people listed in the `AUTHORS' file.
//
/**
* @file z_commands.c
* @author Michaël Cadilhac <michael.cadilhac@lrde.org>
*
* Commands declaration and definition for Z weighted automata.
*/
#include "commands.hh"
#include "ratexp_commands.hh"
#include "common_commands.hh"
/*-----------------------------.
| Define the set of commands. |
`-----------------------------*/
const command_t command_map[] =
{
COMMAND_GROUP (
"Input/output work with automata:",
COMMAND_ENTRY_CN (define-automaton, define_automaton, File,
"Define an automaton from scratch."),
COMMAND_ENTRY (display, Aut, "Display `aut'."),
COMMAND_ENTRY_CN (dot-dump, dot_dump, Aut,
"Dump dot output of `aut'."),
COMMAND_ENTRY_CN (edit-automaton, edit_automaton, File,
"Edit an existing automaton."),
COMMAND_ENTRY (info, Aut, "Print useful infos about `aut'.")),
COMMAND_GROUP (
"Tests and evaluation on automata:",
COMMAND_ENTRY_CN (are-isomorphic, are_isomorphic, AutAut,
"Return whether `aut1' and `aut2' are isomorphic."),
COMMAND_ENTRY (eval, AutWord, "Evaluate `word' on `aut'."),
COMMAND_ENTRY_CN (is-ambiguous, is_ambiguous, Aut,
"Return whether `aut' is ambiguous."),
COMMAND_ENTRY_CN (is-empty, is_empty, Aut,
"Return whether trimed `aut' is empty."),
COMMAND_ENTRY_CN (is-normalized, is_normalized, Aut,
"Return whether `aut' is normalized."),
COMMAND_ENTRY_CN (is-realtime, is_realtime, Aut,
"Return whether `aut' is realtime."),
COMMAND_ENTRY_CN (is-standard, is_standard, Aut,
"Return whether `aut' is standard.")),
COMMAND_GROUP (
"Generic algorithms for automata:",
COMMAND_ENTRY (accessible, Aut,
"Give the maximal accessible subautomaton of `aut'."),
COMMAND_ENTRY (closure, Aut,
"Give `aut' closed over epsilon transitions."),
COMMAND_ENTRY_CN (co-accessible, coaccessible, Aut,
"Give the maximal coaccessible subautomaton of `aut'."),
COMMAND_ENTRY (concatenate, AutAut, "Concatenate `aut1' and `aut2'."),
COMMAND_ENTRY (normalize, Aut,
"Give the Thompson-normalized automaton of `aut'."),
COMMAND_ENTRY (power, AutInt, "Give the power of `aut' by `n'."),
COMMAND_ENTRY (product, AutAut, "Give the product of `aut1' by `aut2'." ),
COMMAND_ENTRY (quotient, Aut, "Give the quotient of `aut'."),
COMMAND_ENTRY (realtime, Aut, "Give the realtime version of `aut'."),
COMMAND_ENTRY (standardize, Aut, "Give the standard automaton of `aut'."),
COMMAND_ENTRY (sum, AutAut, "Give the sum of `aut1' and `aut2'."),
COMMAND_ENTRY (transpose, Aut, "Transpose the automaton `aut'."),
COMMAND_ENTRY (trim, Aut, "Trim the automaton `aut'.")),
COMMAND_GROUP (
"Conversion between automata and expressions:",
COMMAND_ENTRY_CN (aut-to-exp, aut_to_exp, Aut,
"Give the automaton associated to `aut'."),
COMMAND_ENTRY_CN (derived-term, derived_term_automaton, Exp,
"Use derivative to compute the automaton of `exp'."),
COMMAND_ENTRY_CN (exp-to-aut, standard_of, Exp,
"Alias of `stardard-of'."),
COMMAND_ENTRY (expand, Exp, "Expand `exp'."),
COMMAND_ENTRY_CN (standard, standard_of, Exp,
"Give the standard automaton of `exp'."),
COMMAND_ENTRY_CN (thompson, thompson_of, Exp,
"Give the Thompson automaton of `exp'.")),
{0, 0, 0, 0, 0}
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment