1 18 19 package org.sablecc.sablecc.automaton.external; 20 21 import static org.junit.Assert.assertEquals; 22 23 import org.junit.Test; 24 import org.sablecc.sablecc.alphabet.AdjacencyRealm; 25 import org.sablecc.sablecc.alphabet.Realms; 26 import org.sablecc.sablecc.automaton.Dfa; 27 import org.sablecc.sablecc.automaton.MinimalDfa; 28 import org.sablecc.sablecc.automaton.Nfa; 29 30 public class CommentTest { 33 34 @Test 44 public void commentTest() { 45 46 AdjacencyRealm<Character > charRealm = Realms.getCharacter(); 47 48 Nfa<Character > any = new Nfa<Character >(charRealm.createInterval( 50 (char) 0, (char) 255)); 51 Nfa<Character > slash = new Nfa<Character >(charRealm.createInterval('/')); 52 Nfa<Character > star = new Nfa<Character >(charRealm.createInterval('*')); 53 Nfa<Character > notStar = new Nfa<Character >(any.subtract(star)); 54 Nfa<Character > notStarSlash = new Nfa<Character >(notStar 55 .subtract(slash)); 56 57 MinimalDfa<Character > shortestComment = new MinimalDfa<Character >(slash 59 .concatenateWith(star).concatenateWith(any.zeroOrMore()) 60 .concatenateWith(star).concatenateWith(slash).shortest()); 61 62 64 Nfa<Character > part1 = notStarSlash.concatenateWith(notStar 66 .zeroOrMore()); 67 68 Nfa<Character > part2 = star.concatenateWith(part1.zeroOrOne()); 70 71 Nfa<Character > constructionCommentNfa = slash.concatenateWith(star) 73 .concatenateWith(notStar.zeroOrMore()).concatenateWith( 74 part2.zeroOrMore()).concatenateWith(star) 75 .concatenateWith(slash); 76 MinimalDfa<Character > constructionComment = new MinimalDfa<Character >( 77 new Dfa<Character >(constructionCommentNfa)); 78 79 assertEquals("The two minimal Dfa instances must be equal.", 81 shortestComment.toString(), constructionComment.toString()); 82 } 83 } 84 | Popular Tags |