001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of AutomataLib, http://www.automatalib.net/. 003 * 004 * AutomataLib is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Lesser General Public 006 * License version 3.0 as published by the Free Software Foundation. 007 * 008 * AutomataLib is distributed in the hope that it will be useful, 009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 011 * Lesser General Public License for more details. 012 * 013 * You should have received a copy of the GNU Lesser General Public 014 * License along with AutomataLib; if not, see 015 * http://www.gnu.de/documents/lgpl.en.html. 016 */ 017package net.automatalib.examples.brics; 018 019import java.io.IOException; 020import java.io.Writer; 021import java.util.Arrays; 022import java.util.List; 023 024import net.automatalib.brics.AbstractBricsAutomaton; 025import net.automatalib.brics.BricsNFA; 026import net.automatalib.commons.dotutil.DOT; 027import net.automatalib.util.graphs.dot.GraphDOT; 028import net.automatalib.words.Word; 029import dk.brics.automaton.Automaton; 030import dk.brics.automaton.RegExp; 031 032public class SimpleBricsExample { 033 034 public static void main(String[] args) throws IOException { 035 // Create a BRICS automaton from a regular expression ... 036 RegExp r = new RegExp("ab+(c|d)*e?"); 037 Automaton a = r.toAutomaton(); 038 // ... and wrap it into the AutomataLib interfaces 039 AbstractBricsAutomaton ba = new BricsNFA(a); 040 041 // Then, display a DOT representation of this automaton 042 Writer w = DOT.createDotWriter(true); 043 GraphDOT.write(ba, w); 044 w.close(); 045 046 // Test whether the following words are accepted 047 List<Word<Character>> testWords = Arrays.asList( 048 Word.fromString("abd"), 049 Word.fromString("abbc"), 050 Word.fromString("abbbbbde"), 051 Word.fromString("ade")); 052 053 for(Word<Character> tw : testWords) 054 System.out.println("Output for " + tw + " is " + ba.computeOutput(tw)); 055 } 056 057}