Ybadoo - Soluções em Software Livre
Tutoriais
Linguagens Formais e Autômatos

Desenvolva um autômato finito determinístico sobre o alfabeto Σ = {w, x, y, z} que reconheça a linguagem L = {w | w possui wxwx ou yzwx ou yzyz como prefixo, wxyz ou xxzy ou yzxw ou zzwx como subpalavra e wxxx ou xzwy ou yyzw ou zzyz como sufixo}.

 

M = ({w, x, y, z}, {q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20, q21, q22, q23, q24, q25, q26, q27, q28, q29, q30, q31, q32, q33, q34, q35, q36}, δ, q0, {q24, q28, q32, q36})

Grafo com a função de transição de M
Grafo com a função de transição de M
Tabela com a função de transição de M
δwxyz
q0q1-q4-
q1-q2--
q2q3---
q3-q9--
q4--q5-
q5q3-q6-
q6---q15
q7q8q11q14q17
q8q8q9q14q17
q9q8q12q10q17
q10q8q11q14q33
q11q8q12q14q17
q12q8q12q14q13
q13q8q11q29q18
q14q8q11q14q15
q15q16q8q14q18
q16q21q12q14q17
q17q8q11q14q18
q18q19q11q14q18
q19q22q8q14q17
q20q21q25q29q33
q21q21q22q29q33
q22q21q23q29q26
q23q21q24q29q26
q24q21q25q29q26
q25q21q25q29q26
q26q27q25q29q34
q27q21q22q28q33
q28q21q25q30q33
q29q21q25q30q33
q30q21q25q30q31
q31q32q25q29q34
q32q21q22q29q33
q33q21q25q29q34
q34q21q25q35q34
q35q21q25q30q36
q36q21q25q29q34

Terminal

ybadoo@server:~$ ./application
Implementação na linguagem de programação Java Implementação na linguagem de programação C++ Implementação na linguagem de programação C Implementação na linguagem de programação Pascal
Diagrama de classes na linguagem de programação Java State.java DeterministicFiniteAutomaton.java Application.java
Diagrama de classes na linguagem de programação Java
Diagrama de classes na linguagem de programação Java

Arquivo State.java

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  *
 *                                                                       *
 * Permission is granted to copy, distribute and/or modify this document *
 * under the terms of the GNU Free Documentation License, Version 1.3 or *
 * any later version published by the  Free Software Foundation; with no *
 * Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * OpenJDK Version "1.8.0_121"                                           *
 * OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)               *
 *************************************************************************/

package com.ybadoo.tutoriais.lfa.tutorial02.exercicio239;

import java.util.HashMap;
import java.util.Map;

/**
 * Estado do Automato Finito Deterministico
 */
public class State
{
  /**
   * Estado eh de aceitacao
   */
  private boolean accept;

  /**
   * Transicao de estados
   */
  private Map<Character, Integer> transitions;

  /**
   * Constructor
   *
   * @param accept estado eh de aceitacao
   */
  public State(boolean accept)
  {
    this.accept = accept;

    transitions = new HashMap<>();
  }

  /**
   * Retornar se o estado eh de aceitacao
   *
   * @return true se o estado eh de aceitacao,
   *   false em caso contrario
   */
  public boolean isAccept()
  {
    return accept;
  }

  /**
   * Adicionar uma transicao de estado
   *
   * @param symbol simbolo corrente
   * @param state novo estado
   */
  public void addTransition(Character symbol, Integer state)
  {
    transitions.put(symbol, state);
  }

  /**
   * Retornar o novo estado
   *
   * @param symbol simbolo corrente
   * @return novo estado
   */
  public Integer getTransition(Character symbol)
  {
    return transitions.get(symbol);
  }
}

Arquivo DeterministicFiniteAutomaton.java

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  *
 *                                                                       *
 * Permission is granted to copy, distribute and/or modify this document *
 * under the terms of the GNU Free Documentation License, Version 1.3 or *
 * any later version published by the  Free Software Foundation; with no *
 * Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * OpenJDK Version "1.8.0_121"                                           *
 * OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)               *
 *************************************************************************/

package com.ybadoo.tutoriais.lfa.tutorial02.exercicio239;

import java.util.HashMap;
import java.util.Map;

/**
 * Automato Finito Deterministico (AFD)
 */
public class DeterministicFiniteAutomaton
{
  /**
   * Estados do Automato Finito Deterministico (AFD)
   */
  private Map<Integer, State> states;

  /**
   * Constructor
   */
  public DeterministicFiniteAutomaton()
  {
    states = new HashMap<>();

    State q0 = new State(false);
    q0.addTransition('w', 1);
    q0.addTransition('y', 4);
    states.put(0, q0);

    State q1 = new State(false);
    q1.addTransition('x', 2);
    states.put(1, q1);

    State q2 = new State(false);
    q2.addTransition('w', 3);
    states.put(2, q2);

    State q3 = new State(false);
    q3.addTransition('x', 9);
    states.put(3, q3);

    State q4 = new State(false);
    q4.addTransition('y', 5);
    states.put(4, q4);

    State q5 = new State(false);
    q5.addTransition('w', 3);
    q5.addTransition('y', 6);
    states.put(5, q5);

    State q6 = new State(false);
    q6.addTransition('z', 15);
    states.put(6, q6);

    State q7 = new State(false);
    q7.addTransition('w', 8);
    q7.addTransition('x', 11);
    q7.addTransition('y', 14);
    q7.addTransition('z', 17);
    states.put(7, q7);

    State q8 = new State(false);
    q8.addTransition('w', 8);
    q8.addTransition('x', 9);
    q8.addTransition('y', 14);
    q8.addTransition('z', 17);
    states.put(8, q8);

    State q9 = new State(false);
    q9.addTransition('w', 8);
    q9.addTransition('x', 12);
    q9.addTransition('y', 10);
    q9.addTransition('z', 17);
    states.put(9, q9);

    State q10 = new State(false);
    q10.addTransition('w', 8);
    q10.addTransition('x', 11);
    q10.addTransition('y', 14);
    q10.addTransition('z', 33);
    states.put(10, q10);

    State q11 = new State(false);
    q11.addTransition('w', 8);
    q11.addTransition('x', 12);
    q11.addTransition('y', 14);
    q11.addTransition('z', 17);
    states.put(11, q11);

    State q12 = new State(false);
    q12.addTransition('w', 8);
    q12.addTransition('x', 12);
    q12.addTransition('y', 14);
    q12.addTransition('z', 13);
    states.put(12, q12);

    State q13 = new State(false);
    q13.addTransition('w', 8);
    q13.addTransition('x', 11);
    q13.addTransition('y', 29);
    q13.addTransition('z', 18);
    states.put(13, q13);

    State q14 = new State(false);
    q14.addTransition('w', 8);
    q14.addTransition('x', 11);
    q14.addTransition('y', 14);
    q14.addTransition('z', 15);
    states.put(14, q14);

    State q15 = new State(false);
    q15.addTransition('w', 16);
    q15.addTransition('x', 8);
    q15.addTransition('y', 14);
    q15.addTransition('z', 18);
    states.put(15, q15);

    State q16 = new State(false);
    q16.addTransition('w', 21);
    q16.addTransition('x', 12);
    q16.addTransition('y', 14);
    q16.addTransition('z', 17);
    states.put(16, q16);

    State q17 = new State(false);
    q17.addTransition('w', 8);
    q17.addTransition('x', 11);
    q17.addTransition('y', 14);
    q17.addTransition('z', 18);
    states.put(17, q17);

    State q18 = new State(false);
    q18.addTransition('w', 19);
    q18.addTransition('x', 11);
    q18.addTransition('y', 14);
    q18.addTransition('z', 18);
    states.put(18, q18);

    State q19 = new State(false);
    q19.addTransition('w', 22);
    q19.addTransition('x', 8);
    q19.addTransition('y', 14);
    q19.addTransition('z', 17);
    states.put(19, q19);

    State q20 = new State(false);
    q20.addTransition('w', 21);
    q20.addTransition('x', 25);
    q20.addTransition('y', 29);
    q20.addTransition('z', 33);
    states.put(20, q20);

    State q21 = new State(false);
    q21.addTransition('w', 21);
    q21.addTransition('x', 22);
    q21.addTransition('y', 29);
    q21.addTransition('z', 33);
    states.put(21, q21);

    State q22 = new State(false);
    q22.addTransition('w', 21);
    q22.addTransition('x', 23);
    q22.addTransition('y', 29);
    q22.addTransition('z', 26);
    states.put(22, q22);

    State q23 = new State(false);
    q23.addTransition('w', 21);
    q23.addTransition('x', 24);
    q23.addTransition('y', 29);
    q23.addTransition('z', 26);
    states.put(23, q23);

    State q24 = new State(true);
    q24.addTransition('w', 21);
    q24.addTransition('x', 25);
    q24.addTransition('y', 29);
    q24.addTransition('z', 26);
    q24.addTransition('$', 24);
    states.put(24, q24);

    State q25 = new State(false);
    q25.addTransition('w', 21);
    q25.addTransition('x', 25);
    q25.addTransition('y', 29);
    q25.addTransition('z', 26);
    states.put(25, q25);

    State q26 = new State(false);
    q26.addTransition('w', 27);
    q26.addTransition('x', 25);
    q26.addTransition('y', 29);
    q26.addTransition('z', 34);
    states.put(26, q26);

    State q27 = new State(false);
    q27.addTransition('w', 21);
    q27.addTransition('x', 22);
    q27.addTransition('y', 28);
    q27.addTransition('z', 33);
    states.put(27, q27);

    State q28 = new State(true);
    q28.addTransition('w', 21);
    q28.addTransition('x', 25);
    q28.addTransition('y', 30);
    q28.addTransition('z', 33);
    q28.addTransition('$', 28);
    states.put(28, q28);

    State q29 = new State(false);
    q29.addTransition('w', 21);
    q29.addTransition('x', 25);
    q29.addTransition('y', 30);
    q29.addTransition('z', 33);
    states.put(29, q29);

    State q30 = new State(false);
    q30.addTransition('w', 21);
    q30.addTransition('x', 25);
    q30.addTransition('y', 30);
    q30.addTransition('z', 31);
    states.put(30, q30);

    State q31 = new State(false);
    q31.addTransition('w', 32);
    q31.addTransition('x', 25);
    q31.addTransition('y', 29);
    q31.addTransition('z', 34);
    states.put(31, q31);

    State q32 = new State(true);
    q32.addTransition('w', 21);
    q32.addTransition('x', 22);
    q32.addTransition('y', 29);
    q32.addTransition('z', 33);
    q32.addTransition('$', 32);
    states.put(32, q32);

    State q33 = new State(false);
    q33.addTransition('w', 21);
    q33.addTransition('x', 25);
    q33.addTransition('y', 29);
    q33.addTransition('z', 34);
    states.put(33, q33);

    State q34 = new State(false);
    q34.addTransition('w', 21);
    q34.addTransition('x', 25);
    q34.addTransition('y', 35);
    q34.addTransition('z', 34);
    states.put(34, q34);

    State q35 = new State(false);
    q35.addTransition('w', 21);
    q35.addTransition('x', 25);
    q35.addTransition('y', 30);
    q35.addTransition('z', 36);
    states.put(35, q35);

    State q36 = new State(true);
    q36.addTransition('w', 21);
    q36.addTransition('x', 25);
    q36.addTransition('y', 29);
    q36.addTransition('z', 34);
    q36.addTransition('$', 36);
    states.put(36, q36);
  }

  /**
   * Formatar o estado para impressao
   *
   * @param state estado
   * @return estado formatado para impressao
   */
  private String formatState(Integer state)
  {
    if((states.size() < 100) && (state < 10))
    {
      return "\nq" + state + "  - ";
    }

    return "\nq" + state + " - ";
  }

  /**
   * Reconhecer a sentenca de entrada
   *
   * @param sentence sentenca de entrada
   * @return true caso a sentenca de entrada pertenca a linguagem,
   *   false em caso contrario
   */
  public boolean recognize(String sentence)
  {
    String input = sentence + "$";

    System.out.print("Observação: \"$\" representa o fim da sentença");

    Integer state = 0;

    int length = input.length();

    for(int symbol = 0; symbol < length; symbol++)
    {
      System.out.print(formatState(state));

      for(int index = 0; index < length; index++)
      {
        if(index != symbol)
        {
          System.out.print(" " + input.charAt(index) + " ");
        }
        else
        {
          System.out.print("[" + input.charAt(index) + "]");
        }
      }

      state = states.get(state).getTransition(input.charAt(symbol));

      if(state == null)
      {
        System.out.println(" - REJEITA");

        return false;
      }
    }

    if(states.get(state).isAccept())
    {
      System.out.println(" - ACEITA");
    }
    else
    {
      System.out.println(" - REJEITA");
    }

    return states.get(state).isAccept();
  }
}

Arquivo Application.java

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  *
 *                                                                       *
 * Permission is granted to copy, distribute and/or modify this document *
 * under the terms of the GNU Free Documentation License, Version 1.3 or *
 * any later version published by the  Free Software Foundation; with no *
 * Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * OpenJDK Version "1.8.0_121"                                           *
 * OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)               *
 *************************************************************************/

package com.ybadoo.tutoriais.lfa.tutorial02.exercicio239;

import java.util.Scanner;

/**
 * Testar o Automato Finito Deterministico (AFD)
 */
public class Application
{
  /**
   * Constructor
   */
  private Application()
  {

  }

  /**
   * Metodo principal da linguagem de programacao Java
   *
   * @param args argumentos da linha de comando (nao utilizado)
   */
  public static void main(String[] args)
  {
    Scanner scanner = new Scanner(System.in);

    System.out.print("Analise a sentença: ");
    String sentence = scanner.nextLine().trim();

    scanner.close();

    if(sentence.indexOf("$") >= 0)
    {
      System.out.println("A sentença \"" + sentence + "\" é inválida");

      return;
    }

    DeterministicFiniteAutomaton afd = new DeterministicFiniteAutomaton();

    afd.recognize(sentence);
  }
}
Diagrama de classes na linguagem de programação C++ State.hpp State.cpp DeterministicFiniteAutomaton.hpp DeterministicFiniteAutomaton.cpp Application.cpp Makefile para a linguagem de programação C++
Diagrama de classes na linguagem de programação C++
Diagrama de classes na linguagem de programação C++

Arquivo State.hpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  *
 *                                                                       *
 * Permission is granted to copy, distribute and/or modify this document *
 * under the terms of the GNU Free Documentation License, Version 1.3 or *
 * any later version published by the  Free Software Foundation; with no *
 * Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#ifndef STATE_HPP_
#define STATE_HPP_

#include <map>

/**
 * Estado do Automato Finito Deterministico
 */
class State
{
  public:

  /**
   * Constructor
   *
   * @param accept estado eh de aceitacao
   */
  State(const bool accept);

  /**
   * Destructor
   */
  virtual ~State();

  /**
   * Retornar se o estado eh de aceitacao
   *
   * @return true (1) se o estado eh de aceitacao,
   *   false (0) em caso contrario
   */
  bool isAccept() const;

  /**
   * Adicionar uma transicao de estado
   *
   * @param symbol simbolo corrente
   * @param state novo estado
   */
  void addTransition(char symbol, int state);

  /**
   * Retornar o novo estado
   *
   * @param symbol simbolo corrente
   * @return novo estado
   */
  int getTransition(char symbol) const;

  private:

  /**
   * Estado eh de aceitacao
   */
  bool accept;

  /**
   * Transicao de estados
   */
  std::map<char, int>* transitions;
};

#endif

Arquivo State.cpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  *
 *                                                                       *
 * Permission is granted to copy, distribute and/or modify this document *
 * under the terms of the GNU Free Documentation License, Version 1.3 or *
 * any later version published by the  Free Software Foundation; with no *
 * Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#include <map>

#include "State.hpp"

/**
 * Constructor
 *
 * @param accept estado eh de aceitacao
 */
State::State(const bool accept)
{
  State::accept = accept;

  transitions = new std::map<char, int>();
}

/**
 * Destructor
 */
State::~State()
{
  transitions->clear();

  delete transitions;
}

/**
 * Retornar se o estado eh de aceitacao
 *
 * @return true (1) se o estado eh de aceitacao,
 *   false (0) em caso contrario
 */
bool State::isAccept() const
{
  return accept;
}

/**
 * Adicionar uma transicao de estado
 *
 * @param symbol simbolo corrente
 * @param state novo estado
 */
void State::addTransition(char symbol, int state)
{
  transitions->insert(std::pair<char, int>(symbol, state));
}

/**
 * Retornar o novo estado
 *
 * @param symbol simbolo corrente
 * @return novo estado
 */
int State::getTransition(char symbol) const
{
  if(transitions->find(symbol) != transitions->end())
  {
    return transitions->find(symbol)->second;
  }

  return -1;
}

Arquivo DeterministicFiniteAutomaton.hpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  *
 *                                                                       *
 * Permission is granted to copy, distribute and/or modify this document *
 * under the terms of the GNU Free Documentation License, Version 1.3 or *
 * any later version published by the  Free Software Foundation; with no *
 * Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#ifndef DETERMINISTIC_FINITE_AUTOMATON_HPP_
#define DETERMINISTIC_FINITE_AUTOMATON_HPP_

#include <map>
#include <string>

#include "State.hpp"

/**
 * Automato Finito Deterministico (AFD)
 */
class DeterministicFiniteAutomaton
{
  public:

  /**
   * Constructor
   */
  DeterministicFiniteAutomaton();

  /**
   * Destructor
   */
  virtual ~DeterministicFiniteAutomaton();

  /**
   * Reconhecer a sentenca de entrada
   *
   * @param sentence sentenca de entrada
   * @return true (1) caso a sentenca de entrada pertenca a linguagem,
   *   false (0) em caso contrario
   */
  bool recognize(std::string sentence);

  private:

  /**
   * Estados do Automato Finito Deterministico (AFD)
   */
  std::map<int, State*>* states;

  /**
   * Formatar o estado para impressao
   *
   * @param state estado
   * @return estado formatado para impressao
   */
  std::string formatState(int state);
};

#endif

Arquivo DeterministicFiniteAutomaton.cpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  *
 *                                                                       *
 * Permission is granted to copy, distribute and/or modify this document *
 * under the terms of the GNU Free Documentation License, Version 1.3 or *
 * any later version published by the  Free Software Foundation; with no *
 * Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#include <iostream>
#include <map>
#include <sstream>
#include <string>

#include "DeterministicFiniteAutomaton.hpp"

/**
 * Constructor
 */
DeterministicFiniteAutomaton::DeterministicFiniteAutomaton()
{
  states = new std::map<int, State*>();

  State* q0 = new State(false);
  q0->addTransition('w', 1);
  q0->addTransition('y', 4);
  states->insert(std::pair<int, State*>(0, q0));

  State* q1 = new State(false);
  q1->addTransition('x', 2);
  states->insert(std::pair<int, State*>(1, q1));

  State* q2 = new State(false);
  q2->addTransition('w', 3);
  states->insert(std::pair<int, State*>(2, q2));

  State* q3 = new State(false);
  q3->addTransition('x', 9);
  states->insert(std::pair<int, State*>(3, q3));

  State* q4 = new State(false);
  q4->addTransition('y', 5);
  states->insert(std::pair<int, State*>(4, q4));

  State* q5 = new State(false);
  q5->addTransition('w', 3);
  q5->addTransition('y', 6);
  states->insert(std::pair<int, State*>(5, q5));

  State* q6 = new State(false);
  q6->addTransition('z', 15);
  states->insert(std::pair<int, State*>(6, q6));

  State* q7 = new State(false);
  q7->addTransition('w', 8);
  q7->addTransition('x', 11);
  q7->addTransition('y', 14);
  q7->addTransition('z', 17);
  states->insert(std::pair<int, State*>(7, q7));

  State* q8 = new State(false);
  q8->addTransition('w', 8);
  q8->addTransition('x', 9);
  q8->addTransition('y', 14);
  q8->addTransition('z', 17);
  states->insert(std::pair<int, State*>(8, q8));

  State* q9 = new State(false);
  q9->addTransition('w', 8);
  q9->addTransition('x', 12);
  q9->addTransition('y', 10);
  q9->addTransition('z', 17);
  states->insert(std::pair<int, State*>(9, q9));

  State* q10 = new State(false);
  q10->addTransition('w', 8);
  q10->addTransition('x', 11);
  q10->addTransition('y', 14);
  q10->addTransition('z', 33);
  states->insert(std::pair<int, State*>(10, q10));

  State* q11 = new State(false);
  q11->addTransition('w', 8);
  q11->addTransition('x', 12);
  q11->addTransition('y', 14);
  q11->addTransition('z', 17);
  states->insert(std::pair<int, State*>(11, q11));

  State* q12 = new State(false);
  q12->addTransition('w', 8);
  q12->addTransition('x', 12);
  q12->addTransition('y', 14);
  q12->addTransition('z', 13);
  states->insert(std::pair<int, State*>(12, q12));

  State* q13 = new State(false);
  q13->addTransition('w', 8);
  q13->addTransition('x', 11);
  q13->addTransition('y', 29);
  q13->addTransition('z', 18);
  states->insert(std::pair<int, State*>(13, q13));

  State* q14 = new State(false);
  q14->addTransition('w', 8);
  q14->addTransition('x', 11);
  q14->addTransition('y', 14);
  q14->addTransition('z', 15);
  states->insert(std::pair<int, State*>(14, q14));

  State* q15 = new State(false);
  q15->addTransition('w', 16);
  q15->addTransition('x', 8);
  q15->addTransition('y', 14);
  q15->addTransition('z', 18);
  states->insert(std::pair<int, State*>(15, q15));

  State* q16 = new State(false);
  q16->addTransition('w', 21);
  q16->addTransition('x', 12);
  q16->addTransition('y', 14);
  q16->addTransition('z', 17);
  states->insert(std::pair<int, State*>(16, q16));

  State* q17 = new State(false);
  q17->addTransition('w', 8);
  q17->addTransition('x', 11);
  q17->addTransition('y', 14);
  q17->addTransition('z', 18);
  states->insert(std::pair<int, State*>(17, q17));

  State* q18 = new State(false);
  q18->addTransition('w', 19);
  q18->addTransition('x', 11);
  q18->addTransition('y', 14);
  q18->addTransition('z', 18);
  states->insert(std::pair<int, State*>(18, q18));

  State* q19 = new State(false);
  q19->addTransition('w', 22);
  q19->addTransition('x', 8);
  q19->addTransition('y', 14);
  q19->addTransition('z', 17);
  states->insert(std::pair<int, State*>(19, q19));

  State* q20 = new State(false);
  q20->addTransition('w', 21);
  q20->addTransition('x', 25);
  q20->addTransition('y', 29);
  q20->addTransition('z', 33);
  states->insert(std::pair<int, State*>(20, q20));

  State* q21 = new State(false);
  q21->addTransition('w', 21);
  q21->addTransition('x', 22);
  q21->addTransition('y', 29);
  q21->addTransition('z', 33);
  states->insert(std::pair<int, State*>(21, q21));

  State* q22 = new State(false);
  q22->addTransition('w', 21);
  q22->addTransition('x', 23);
  q22->addTransition('y', 29);
  q22->addTransition('z', 26);
  states->insert(std::pair<int, State*>(22, q22));

  State* q23 = new State(false);
  q23->addTransition('w', 21);
  q23->addTransition('x', 24);
  q23->addTransition('y', 29);
  q23->addTransition('z', 26);
  states->insert(std::pair<int, State*>(23, q23));

  State* q24 = new State(true);
  q24->addTransition('w', 21);
  q24->addTransition('x', 25);
  q24->addTransition('y', 29);
  q24->addTransition('z', 26);
  q24->addTransition('$', 24);
  states->insert(std::pair<int, State*>(24, q24));

  State* q25 = new State(false);
  q25->addTransition('w', 21);
  q25->addTransition('x', 25);
  q25->addTransition('y', 29);
  q25->addTransition('z', 26);
  states->insert(std::pair<int, State*>(25, q25));

  State* q26 = new State(false);
  q26->addTransition('w', 27);
  q26->addTransition('x', 25);
  q26->addTransition('y', 29);
  q26->addTransition('z', 34);
  states->insert(std::pair<int, State*>(26, q26));

  State* q27 = new State(false);
  q27->addTransition('w', 21);
  q27->addTransition('x', 22);
  q27->addTransition('y', 28);
  q27->addTransition('z', 33);
  states->insert(std::pair<int, State*>(27, q27));

  State* q28 = new State(true);
  q28->addTransition('w', 21);
  q28->addTransition('x', 25);
  q28->addTransition('y', 30);
  q28->addTransition('z', 33);
  q28->addTransition('$', 28);
  states->insert(std::pair<int, State*>(28, q28));

  State* q29 = new State(false);
  q29->addTransition('w', 21);
  q29->addTransition('x', 25);
  q29->addTransition('y', 30);
  q29->addTransition('z', 33);
  states->insert(std::pair<int, State*>(29, q29));

  State* q30 = new State(false);
  q30->addTransition('w', 21);
  q30->addTransition('x', 25);
  q30->addTransition('y', 30);
  q30->addTransition('z', 31);
  states->insert(std::pair<int, State*>(30, q30));

  State* q31 = new State(false);
  q31->addTransition('w', 32);
  q31->addTransition('x', 25);
  q31->addTransition('y', 29);
  q31->addTransition('z', 34);
  states->insert(std::pair<int, State*>(31, q31));

  State* q32 = new State(true);
  q32->addTransition('w', 21);
  q32->addTransition('x', 22);
  q32->addTransition('y', 29);
  q32->addTransition('z', 33);
  q32->addTransition('$', 32);
  states->insert(std::pair<int, State*>(32, q32));

  State* q33 = new State(false);
  q33->addTransition('w', 21);
  q33->addTransition('x', 25);
  q33->addTransition('y', 29);
  q33->addTransition('z', 34);
  states->insert(std::pair<int, State*>(33, q33));

  State* q34 = new State(false);
  q34->addTransition('w', 21);
  q34->addTransition('x', 25);
  q34->addTransition('y', 35);
  q34->addTransition('z', 34);
  states->insert(std::pair<int, State*>(34, q34));

  State* q35 = new State(false);
  q35->addTransition('w', 21);
  q35->addTransition('x', 25);
  q35->addTransition('y', 30);
  q35->addTransition('z', 36);
  states->insert(std::pair<int, State*>(35, q35));

  State* q36 = new State(true);
  q36->addTransition('w', 21);
  q36->addTransition('x', 25);
  q36->addTransition('y', 29);
  q36->addTransition('z', 34);
  q36->addTransition('$', 36);
  states->insert(std::pair<int, State*>(36, q36));
}

/**
 * Destructor
 */
DeterministicFiniteAutomaton::~DeterministicFiniteAutomaton()
{
  while(!states->empty())
  {
    delete states->begin()->second;

    states->erase(states->begin());
  }

  delete states;
}

/**
 * Reconhecer a sentenca de entrada
 *
 * @param sentence sentenca de entrada
 * @return true (1) caso a sentenca de entrada seja reconhecida,
 *   false (0) em caso contrario
 */
bool DeterministicFiniteAutomaton::recognize(std::string sentence)
{
  using namespace std;

  sentence.insert(sentence.end(), '$');

  cout << "Observação: \"$\" representa o fim da sentença";

  int symbol;

  int index;

  int state = 0;

  State* actual;

  int length = sentence.length();

  for(symbol = 0; symbol < length; symbol++)
  {
    cout << formatState(state);

    for(index = 0; index < length; index++)
    {
      if(index != symbol)
      {
        cout << " " << sentence.at(index) << " ";
      }
      else
      {
        cout << "[" << sentence.at(index) << "]";
      }
    }

    actual = states->find(state)->second;

    state = actual->getTransition(sentence.at(symbol));

    if(state == -1)
    {
      cout << " - REJEITA" << endl;

      return false;
    }
  }

  actual = states->find(state)->second;

  if(actual->isAccept())
  {
    cout << " - ACEITA" << endl;
  }
  else
  {
    cout << " - REJEITA" << endl;
  }

  return actual->isAccept();
}

/**
 * Formatar o estado para impressao
 *
 * @param state estado
 * @return estado formatado para impressao
 */
std::string DeterministicFiniteAutomaton::formatState(int state)
{
  using namespace std;

  stringstream buffer;

  buffer << "\nq" << state;

  if((states->size() < 100) && (state < 10))
  {
    buffer << "  - ";
  }
  else
  {
    buffer << " - ";
  }

  return buffer.str();
}

Arquivo Application.cpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  *
 *                                                                       *
 * Permission is granted to copy, distribute and/or modify this document *
 * under the terms of the GNU Free Documentation License, Version 1.3 or *
 * any later version published by the  Free Software Foundation; with no *
 * Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#include <iostream>
#include <string>

#include "DeterministicFiniteAutomaton.hpp"

/**
 * Metodo principal da linguagem de programacao C++
 *
 * @param argc quantidade de argumentos na linha de comando (nao utilizado)
 * @param argv argumentos da linha de comando (nao utilizado)
 */
int main(int argc, char** argv)
{
  using namespace std;

  string sentence;

  cout << "Analise a sentença: ";
  cin >> sentence;

  if(sentence.find("$") != string::npos)
  {
    cout << "A sentença \"" << sentence << "\" é inválida" << endl;

    return 1;
  }

  DeterministicFiniteAutomaton* afd = new DeterministicFiniteAutomaton();

  afd->recognize(sentence);

  delete afd;

  return 0;
}

Arquivo makefile

##########################################################################
 # Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  #
 #                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  #
 #                                                                       #
 # Permission is granted to copy, distribute and/or modify this document #
 # under the terms of the GNU Free Documentation License, Version 1.3 or #
 # any later version published by the  Free Software Foundation; with no #
 # Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A #
 # A copy of the  license is included in  the section entitled "GNU Free #
 # Documentation License".                                               #
 #                                                                       #
 # Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             #
 # gcc/g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                       #
 ##########################################################################

g++ -o State.o -c State.cpp

g++ -o DeterministicFiniteAutomaton.o -c DeterministicFiniteAutomaton.cpp

g++ -o Application.o -c Application.cpp

g++ -o application State.o DeterministicFiniteAutomaton.o Application.o
DeterministicFiniteAutomaton.c Makefile para a linguagem de programação C

Arquivo DeterministicFiniteAutomaton.c

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  *
 *                                                                       *
 * Permission is granted to copy, distribute and/or modify this document *
 * under the terms of the GNU Free Documentation License, Version 1.3 or *
 * any later version published by the  Free Software Foundation; with no *
 * Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#include <stdio.h>
#include <string.h>

/**
 * Definicao das constantes
 */
#define ACEITA  1
#define REJEITA 0

/**
 * Prototipo das funcoes
 */
void console(int, int);
int q0(int);
int q1(int);
int q2(int);
int q3(int);
int q4(int);
int q5(int);
int q6(int);
int q7(int);
int q8(int);
int q9(int);
int q10(int);
int q11(int);
int q12(int);
int q13(int);
int q14(int);
int q15(int);
int q16(int);
int q17(int);
int q18(int);
int q19(int);
int q20(int);
int q21(int);
int q22(int);
int q23(int);
int q24(int);
int q25(int);
int q26(int);
int q27(int);
int q28(int);
int q29(int);
int q30(int);
int q31(int);
int q32(int);
int q33(int);
int q34(int);
int q35(int);
int q36(int);

/**
 * Sentenca
 */
char sentence[255];

/**
 * Metodo principal da linguagem de programacao C
 *
 * @param argc quantidade de argumentos na linha de comando (nao utilizado)
 * @param argv argumentos da linha de comando (nao utilizado)
 * @return saida para o sistema operacional (padrao 0)
 */
int main(int argc, char** argv)
{
  printf("Analise a sentença: ");
  fgets(sentence, 255, stdin);

  if(strchr(sentence, '$') != 0)
  {
    sentence[strlen(sentence) - 1] = '\0';
    printf("A sentença \"%s\" é inválida\n", sentence);
    return 1;
  }

  sentence[strlen(sentence) - 1] = '$';

  printf("Observação: \"$\" representa o fim da sentença");

  if(q0(0))
  {
    printf(" - ACEITA\n");
  }
  else
  {
    printf(" - REJEITA\n");
  }

  return 0;
}

/**
 * Imprimir a execucao do automato finito deterministico
 *
 * @param state estado corrente
 * @param symbol simbolo corrente
 */
void console(int state, int symbol)
{
  int i;

  int length = strlen(sentence);

  if(state < 10)
  {
    printf("\nq%i  - ", state);
  }
  else
  {
    printf("\nq%i - ", state);
  }

  for(i = 0; i < length; i++)
  {
    if(i != symbol)
    {
      printf(" %c ", sentence[i]);
    }
    else
    {
      printf("[%c]", sentence[i]);
    }
  }
}

/**
 * Estado q0 (inicial)
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q0(int symbol)
{
  console(0, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q1(symbol);
    case 'y': return q4(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q1
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q1(int symbol)
{
  console(1, symbol);

  switch(sentence[symbol++])
  {
    case 'x': return q2(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q2
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q2(int symbol)
{
  console(2, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q3(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q3
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q3(int symbol)
{
  console(3, symbol);

  switch(sentence[symbol++])
  {
    case 'x': return q9(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q4
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q4(int symbol)
{
  console(4, symbol);

  switch(sentence[symbol++])
  {
    case 'y': return q5(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q5
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q5(int symbol)
{
  console(5, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q3(symbol);
    case 'y': return q6(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q6
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q6(int symbol)
{
  console(6, symbol);

  switch(sentence[symbol++])
  {
    case 'z': return q15(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q7
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q7(int symbol)
{
  console(7, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q8(symbol);
    case 'x': return q11(symbol);
    case 'y': return q14(symbol);
    case 'z': return q17(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q8
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q8(int symbol)
{
  console(8, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q8(symbol);
    case 'x': return q9(symbol);
    case 'y': return q14(symbol);
    case 'z': return q17(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q9
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q9(int symbol)
{
  console(9, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q8(symbol);
    case 'x': return q12(symbol);
    case 'y': return q10(symbol);
    case 'z': return q17(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q10
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q10(int symbol)
{
  console(10, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q8(symbol);
    case 'x': return q11(symbol);
    case 'y': return q14(symbol);
    case 'z': return q33(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q11
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q11(int symbol)
{
  console(11, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q8(symbol);
    case 'x': return q12(symbol);
    case 'y': return q14(symbol);
    case 'z': return q17(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q12
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q12(int symbol)
{
  console(12, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q8(symbol);
    case 'x': return q12(symbol);
    case 'y': return q14(symbol);
    case 'z': return q13(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q13
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q13(int symbol)
{
  console(13, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q8(symbol);
    case 'x': return q11(symbol);
    case 'y': return q29(symbol);
    case 'z': return q18(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q14
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q14(int symbol)
{
  console(14, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q8(symbol);
    case 'x': return q11(symbol);
    case 'y': return q14(symbol);
    case 'z': return q15(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q15
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q15(int symbol)
{
  console(15, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q16(symbol);
    case 'x': return q8(symbol);
    case 'y': return q14(symbol);
    case 'z': return q18(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q16
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q16(int symbol)
{
  console(16, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q12(symbol);
    case 'y': return q14(symbol);
    case 'z': return q17(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q17
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q17(int symbol)
{
  console(17, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q8(symbol);
    case 'x': return q11(symbol);
    case 'y': return q14(symbol);
    case 'z': return q18(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q18
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q18(int symbol)
{
  console(18, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q19(symbol);
    case 'x': return q11(symbol);
    case 'y': return q14(symbol);
    case 'z': return q18(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q19
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q19(int symbol)
{
  console(19, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q22(symbol);
    case 'x': return q8(symbol);
    case 'y': return q14(symbol);
    case 'z': return q17(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q20
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q20(int symbol)
{
  console(20, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q25(symbol);
    case 'y': return q29(symbol);
    case 'z': return q33(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q21
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q21(int symbol)
{
  console(21, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q22(symbol);
    case 'y': return q29(symbol);
    case 'z': return q33(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q22
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q22(int symbol)
{
  console(22, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q23(symbol);
    case 'y': return q29(symbol);
    case 'z': return q26(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q23
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q23(int symbol)
{
  console(23, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q24(symbol);
    case 'y': return q29(symbol);
    case 'z': return q26(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q24 (final)
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q24(int symbol)
{
  console(24, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q25(symbol);
    case 'y': return q29(symbol);
    case 'z': return q26(symbol);
    case '$': return ACEITA;
    default : return REJEITA;
  }
}

/**
 * Estado q25
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q25(int symbol)
{
  console(25, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q25(symbol);
    case 'y': return q29(symbol);
    case 'z': return q26(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q26
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q26(int symbol)
{
  console(26, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q27(symbol);
    case 'x': return q25(symbol);
    case 'y': return q29(symbol);
    case 'z': return q34(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q27
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q27(int symbol)
{
  console(27, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q22(symbol);
    case 'y': return q28(symbol);
    case 'z': return q33(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q28 (final)
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q28(int symbol)
{
  console(28, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q25(symbol);
    case 'y': return q30(symbol);
    case 'z': return q33(symbol);
    case '$': return ACEITA;
    default : return REJEITA;
  }
}

/**
 * Estado q29
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q29(int symbol)
{
  console(29, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q25(symbol);
    case 'y': return q30(symbol);
    case 'z': return q33(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q30
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q30(int symbol)
{
  console(30, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q25(symbol);
    case 'y': return q30(symbol);
    case 'z': return q31(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q31
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q31(int symbol)
{
  console(31, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q32(symbol);
    case 'x': return q25(symbol);
    case 'y': return q29(symbol);
    case 'z': return q34(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q32 (final)
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q32(int symbol)
{
  console(32, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q22(symbol);
    case 'y': return q29(symbol);
    case 'z': return q33(symbol);
    case '$': return ACEITA;
    default : return REJEITA;
  }
}

/**
 * Estado q33
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q33(int symbol)
{
  console(33, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q25(symbol);
    case 'y': return q29(symbol);
    case 'z': return q34(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q34
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q34(int symbol)
{
  console(34, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q25(symbol);
    case 'y': return q35(symbol);
    case 'z': return q34(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q35
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q35(int symbol)
{
  console(35, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q25(symbol);
    case 'y': return q30(symbol);
    case 'z': return q36(symbol);
    default : return REJEITA;
  }
}

/**
 * Estado q36 (final)
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 */
int q36(int symbol)
{
  console(36, symbol);

  switch(sentence[symbol++])
  {
    case 'w': return q21(symbol);
    case 'x': return q25(symbol);
    case 'y': return q29(symbol);
    case 'z': return q34(symbol);
    case '$': return ACEITA;
    default : return REJEITA;
  }
}

Arquivo makefile

##########################################################################
 # Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  #
 #                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  #
 #                                                                       #
 # Permission is granted to copy, distribute and/or modify this document #
 # under the terms of the GNU Free Documentation License, Version 1.3 or #
 # any later version published by the  Free Software Foundation; with no #
 # Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A #
 # A copy of the  license is included in  the section entitled "GNU Free #
 # Documentation License".                                               #
 #                                                                       #
 # Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             #
 # gcc/g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                       #
 ##########################################################################

gcc -o DeterministicFiniteAutomaton.o -c DeterministicFiniteAutomaton.c

gcc -o application DeterministicFiniteAutomaton.o

Arquivo DeterministicFiniteAutomaton.pas

(*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (ybadoo.com.br)  *
 *                                                                       *
 * Permission is granted to copy, distribute and/or modify this document *
 * under the terms of the GNU Free Documentation License, Version 1.3 or *
 * any later version published by the  Free Software Foundation; with no *
 * Invariant Sections,  no Front-Cover Texts, and no Back-Cover Texts. A *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * FreePascal IDE for Linux for x86-64 (version 2.6.2-8)                 *
 *************************************************************************)

program DeterministicFiniteAutomaton;

(**
 * Definicao das constantes
 *)
const
  ACEITA  = true;
  REJEITA = false;

(**
 * Prototipo das funcoes
 *)
procedure console(state : integer; symbol : integer); forward;
function q0(symbol : integer) : boolean; forward;
function q1(symbol : integer) : boolean; forward;
function q2(symbol : integer) : boolean; forward;
function q3(symbol : integer) : boolean; forward;
function q4(symbol : integer) : boolean; forward;
function q5(symbol : integer) : boolean; forward;
function q6(symbol : integer) : boolean; forward;
function q7(symbol : integer) : boolean; forward;
function q8(symbol : integer) : boolean; forward;
function q9(symbol : integer) : boolean; forward;
function q10(symbol : integer) : boolean; forward;
function q11(symbol : integer) : boolean; forward;
function q12(symbol : integer) : boolean; forward;
function q13(symbol : integer) : boolean; forward;
function q14(symbol : integer) : boolean; forward;
function q15(symbol : integer) : boolean; forward;
function q16(symbol : integer) : boolean; forward;
function q17(symbol : integer) : boolean; forward;
function q18(symbol : integer) : boolean; forward;
function q19(symbol : integer) : boolean; forward;
function q20(symbol : integer) : boolean; forward;
function q21(symbol : integer) : boolean; forward;
function q22(symbol : integer) : boolean; forward;
function q23(symbol : integer) : boolean; forward;
function q24(symbol : integer) : boolean; forward;
function q25(symbol : integer) : boolean; forward;
function q26(symbol : integer) : boolean; forward;
function q27(symbol : integer) : boolean; forward;
function q28(symbol : integer) : boolean; forward;
function q29(symbol : integer) : boolean; forward;
function q30(symbol : integer) : boolean; forward;
function q31(symbol : integer) : boolean; forward;
function q32(symbol : integer) : boolean; forward;
function q33(symbol : integer) : boolean; forward;
function q34(symbol : integer) : boolean; forward;
function q35(symbol : integer) : boolean; forward;
function q36(symbol : integer) : boolean; forward;

var
  (**
   * Sentenca
   *)
  sentence : string;

(**
 * Imprimir a execucao do automato finito deterministico
 *
 * @param state estado corrente
 * @param symbol simbolo corrente
 *)
procedure console(state : integer; symbol : integer);
var i : integer;
begin
  writeln();

  if state < 10 then
  begin
    write('q', state, '  - ');
  end
  else
  begin
    write('q', state, ' - ');
  end;

  for i := 1 to ord(sentence[0]) do
  begin
    if i <> symbol then
    begin
      write(' ', sentence[i], ' ');
    end
    else
    begin
      write('[', sentence[i], ']');
    end;
  end;
end;

(**
 * Estado q0 (inicial)
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q0(symbol : integer) : boolean;
begin
  console(0, symbol);

  case sentence[symbol] of
    'w' : q0 := q1(symbol + 1);
    'y' : q0 := q4(symbol + 1);
    else  q0 := REJEITA;
  end;
end;

(**
 * Estado q1
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q1(symbol : integer) : boolean;
begin
  console(1, symbol);

  case sentence[symbol] of
    'x' : q1 := q2(symbol + 1);
    else  q1 := REJEITA;
  end;
end;

(**
 * Estado q2
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q2(symbol : integer) : boolean;
begin
  console(2, symbol);

  case sentence[symbol] of
    'w' : q2 := q3(symbol + 1);
    else  q2 := REJEITA;
  end;
end;

(**
 * Estado q3
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q3(symbol : integer) : boolean;
begin
  console(3, symbol);

  case sentence[symbol] of
    'x' : q3 := q9(symbol + 1);
    else  q3 := REJEITA;
  end;
end;

(**
 * Estado q4
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q4(symbol : integer) : boolean;
begin
  console(4, symbol);

  case sentence[symbol] of
    'y' : q4 := q5(symbol + 1);
    else  q4 := REJEITA;
  end;
end;

(**
 * Estado q5
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q5(symbol : integer) : boolean;
begin
  console(5, symbol);

  case sentence[symbol] of
    'w' : q5 := q3(symbol + 1);
    'y' : q5 := q6(symbol + 1);
    else  q5 := REJEITA;
  end;
end;

(**
 * Estado q6
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q6(symbol : integer) : boolean;
begin
  console(6, symbol);

  case sentence[symbol] of
    'z' : q6 := q15(symbol + 1);
    else  q6 := REJEITA;
  end;
end;

(**
 * Estado q7
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q7(symbol : integer) : boolean;
begin
  console(7, symbol);

  case sentence[symbol] of
    'w' : q7 := q8(symbol + 1);
    'x' : q7 := q11(symbol + 1);
    'y' : q7 := q14(symbol + 1);
    'z' : q7 := q17(symbol + 1);
    else  q7 := REJEITA;
  end;
end;

(**
 * Estado q8
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q8(symbol : integer) : boolean;
begin
  console(8, symbol);

  case sentence[symbol] of
    'w' : q8 := q8(symbol + 1);
    'x' : q8 := q9(symbol + 1);
    'y' : q8 := q14(symbol + 1);
    'z' : q8 := q17(symbol + 1);
    else  q8 := REJEITA;
  end;
end;

(**
 * Estado q9
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q9(symbol : integer) : boolean;
begin
  console(9, symbol);

  case sentence[symbol] of
    'w' : q9 := q8(symbol + 1);
    'x' : q9 := q12(symbol + 1);
    'y' : q9 := q10(symbol + 1);
    'z' : q9 := q17(symbol + 1);
    else  q9 := REJEITA;
  end;
end;

(**
 * Estado q10
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q10(symbol : integer) : boolean;
begin
  console(10, symbol);

  case sentence[symbol] of
    'w' : q10 := q8(symbol + 1);
    'x' : q10 := q11(symbol + 1);
    'y' : q10 := q14(symbol + 1);
    'z' : q10 := q33(symbol + 1);
    else  q10 := REJEITA;
  end;
end;

(**
 * Estado q11
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q11(symbol : integer) : boolean;
begin
  console(11, symbol);

  case sentence[symbol] of
    'w' : q11 := q8(symbol + 1);
    'x' : q11 := q12(symbol + 1);
    'y' : q11 := q14(symbol + 1);
    'z' : q11 := q17(symbol + 1);
    else  q11 := REJEITA;
  end;
end;

(**
 * Estado q12
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q12(symbol : integer) : boolean;
begin
  console(12, symbol);

  case sentence[symbol] of
    'w' : q12 := q8(symbol + 1);
    'x' : q12 := q12(symbol + 1);
    'y' : q12 := q14(symbol + 1);
    'z' : q12 := q13(symbol + 1);
    else  q12 := REJEITA;
  end;
end;

(**
 * Estado q13
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q13(symbol : integer) : boolean;
begin
  console(13, symbol);

  case sentence[symbol] of
    'w' : q13 := q8(symbol + 1);
    'x' : q13 := q11(symbol + 1);
    'y' : q13 := q29(symbol + 1);
    'z' : q13 := q18(symbol + 1);
    else  q13 := REJEITA;
  end;
end;

(**
 * Estado q14
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q14(symbol : integer) : boolean;
begin
  console(14, symbol);

  case sentence[symbol] of
    'w' : q14 := q8(symbol + 1);
    'x' : q14 := q11(symbol + 1);
    'y' : q14 := q14(symbol + 1);
    'z' : q14 := q15(symbol + 1);
    else  q14 := REJEITA;
  end;
end;

(**
 * Estado q15
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q15(symbol : integer) : boolean;
begin
  console(15, symbol);

  case sentence[symbol] of
    'w' : q15 := q16(symbol + 1);
    'x' : q15 := q8(symbol + 1);
    'y' : q15 := q14(symbol + 1);
    'z' : q15 := q18(symbol + 1);
    else  q15 := REJEITA;
  end;
end;

(**
 * Estado q16
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q16(symbol : integer) : boolean;
begin
  console(16, symbol);

  case sentence[symbol] of
    'w' : q16 := q21(symbol + 1);
    'x' : q16 := q12(symbol + 1);
    'y' : q16 := q14(symbol + 1);
    'z' : q16 := q17(symbol + 1);
    else  q16 := REJEITA;
  end;
end;

(**
 * Estado q17
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q17(symbol : integer) : boolean;
begin
  console(17, symbol);

  case sentence[symbol] of
    'w' : q17 := q8(symbol + 1);
    'x' : q17 := q11(symbol + 1);
    'y' : q17 := q14(symbol + 1);
    'z' : q17 := q18(symbol + 1);
    else  q17 := REJEITA;
  end;
end;

(**
 * Estado q18
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q18(symbol : integer) : boolean;
begin
  console(18, symbol);

  case sentence[symbol] of
    'w' : q18 := q19(symbol + 1);
    'x' : q18 := q11(symbol + 1);
    'y' : q18 := q14(symbol + 1);
    'z' : q18 := q18(symbol + 1);
    else  q18 := REJEITA;
  end;
end;

(**
 * Estado q19
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q19(symbol : integer) : boolean;
begin
  console(19, symbol);

  case sentence[symbol] of
    'w' : q19 := q22(symbol + 1);
    'x' : q19 := q8(symbol + 1);
    'y' : q19 := q14(symbol + 1);
    'z' : q19 := q17(symbol + 1);
    else  q19 := REJEITA;
  end;
end;

(**
 * Estado q20
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q20(symbol : integer) : boolean;
begin
  console(20, symbol);

  case sentence[symbol] of
    'w' : q20 := q21(symbol + 1);
    'x' : q20 := q25(symbol + 1);
    'y' : q20 := q29(symbol + 1);
    'z' : q20 := q33(symbol + 1);
    else  q20 := REJEITA;
  end;
end;

(**
 * Estado q21
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q21(symbol : integer) : boolean;
begin
  console(21, symbol);

  case sentence[symbol] of
    'w' : q21 := q21(symbol + 1);
    'x' : q21 := q22(symbol + 1);
    'y' : q21 := q29(symbol + 1);
    'z' : q21 := q33(symbol + 1);
    else  q21 := REJEITA;
  end;
end;

(**
 * Estado q22
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q22(symbol : integer) : boolean;
begin
  console(22, symbol);

  case sentence[symbol] of
    'w' : q22 := q21(symbol + 1);
    'x' : q22 := q23(symbol + 1);
    'y' : q22 := q29(symbol + 1);
    'z' : q22 := q26(symbol + 1);
    else  q22 := REJEITA;
  end;
end;

(**
 * Estado q23
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q23(symbol : integer) : boolean;
begin
  console(23, symbol);

  case sentence[symbol] of
    'w' : q23 := q21(symbol + 1);
    'x' : q23 := q24(symbol + 1);
    'y' : q23 := q29(symbol + 1);
    'z' : q23 := q26(symbol + 1);
    else  q23 := REJEITA;
  end;
end;

(**
 * Estado q24 (final)
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q24(symbol : integer) : boolean;
begin
  console(24, symbol);

  case sentence[symbol] of
    'w' : q24 := q21(symbol + 1);
    'x' : q24 := q25(symbol + 1);
    'y' : q24 := q29(symbol + 1);
    'z' : q24 := q26(symbol + 1);
    '$' : q24 := ACEITA;
    else  q24 := REJEITA;
  end;
end;

(**
 * Estado q25
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q25(symbol : integer) : boolean;
begin
  console(25, symbol);

  case sentence[symbol] of
    'w' : q25 := q21(symbol + 1);
    'x' : q25 := q25(symbol + 1);
    'y' : q25 := q29(symbol + 1);
    'z' : q25 := q26(symbol + 1);
    else  q25 := REJEITA;
  end;
end;

(**
 * Estado q26
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q26(symbol : integer) : boolean;
begin
  console(26, symbol);

  case sentence[symbol] of
    'w' : q26 := q27(symbol + 1);
    'x' : q26 := q25(symbol + 1);
    'y' : q26 := q29(symbol + 1);
    'z' : q26 := q34(symbol + 1);
    else  q26 := REJEITA;
  end;
end;

(**
 * Estado q27
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q27(symbol : integer) : boolean;
begin
  console(27, symbol);

  case sentence[symbol] of
    'w' : q27 := q21(symbol + 1);
    'x' : q27 := q22(symbol + 1);
    'y' : q27 := q28(symbol + 1);
    'z' : q27 := q33(symbol + 1);
    else  q27 := REJEITA;
  end;
end;

(**
 * Estado q28 (final)
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q28(symbol : integer) : boolean;
begin
  console(28, symbol);

  case sentence[symbol] of
    'w' : q28 := q21(symbol + 1);
    'x' : q28 := q25(symbol + 1);
    'y' : q28 := q30(symbol + 1);
    'z' : q28 := q33(symbol + 1);
    '$' : q28 := ACEITA;
    else  q28 := REJEITA;
  end;
end;

(**
 * Estado q29
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q29(symbol : integer) : boolean;
begin
  console(29, symbol);

  case sentence[symbol] of
    'w' : q29 := q21(symbol + 1);
    'x' : q29 := q25(symbol + 1);
    'y' : q29 := q30(symbol + 1);
    'z' : q29 := q33(symbol + 1);
    else  q29 := REJEITA;
  end;
end;

(**
 * Estado q30
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q30(symbol : integer) : boolean;
begin
  console(30, symbol);

  case sentence[symbol] of
    'w' : q30 := q21(symbol + 1);
    'x' : q30 := q25(symbol + 1);
    'y' : q30 := q30(symbol + 1);
    'z' : q30 := q31(symbol + 1);
    else  q30 := REJEITA;
  end;
end;

(**
 * Estado q31
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q31(symbol : integer) : boolean;
begin
  console(31, symbol);

  case sentence[symbol] of
    'w' : q31 := q32(symbol + 1);
    'x' : q31 := q25(symbol + 1);
    'y' : q31 := q29(symbol + 1);
    'z' : q31 := q34(symbol + 1);
    else  q31 := REJEITA;
  end;
end;

(**
 * Estado q32 (final)
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q32(symbol : integer) : boolean;
begin
  console(32, symbol);

  case sentence[symbol] of
    'w' : q32 := q21(symbol + 1);
    'x' : q32 := q22(symbol + 1);
    'y' : q32 := q29(symbol + 1);
    'z' : q32 := q33(symbol + 1);
    '$' : q32 := ACEITA;
    else  q32 := REJEITA;
  end;
end;

(**
 * Estado q33
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q33(symbol : integer) : boolean;
begin
  console(33, symbol);

  case sentence[symbol] of
    'w' : q33 := q21(symbol + 1);
    'x' : q33 := q25(symbol + 1);
    'y' : q33 := q29(symbol + 1);
    'z' : q33 := q34(symbol + 1);
    else  q33 := REJEITA;
  end;
end;

(**
 * Estado q34
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q34(symbol : integer) : boolean;
begin
  console(34, symbol);

  case sentence[symbol] of
    'w' : q34 := q21(symbol + 1);
    'x' : q34 := q25(symbol + 1);
    'y' : q34 := q35(symbol + 1);
    'z' : q34 := q34(symbol + 1);
    else  q34 := REJEITA;
  end;
end;

(**
 * Estado q35
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q35(symbol : integer) : boolean;
begin
  console(35, symbol);

  case sentence[symbol] of
    'w' : q35 := q21(symbol + 1);
    'x' : q35 := q25(symbol + 1);
    'y' : q35 := q30(symbol + 1);
    'z' : q35 := q36(symbol + 1);
    else  q35 := REJEITA;
  end;
end;

(**
 * Estado q36 (final)
 *
 * @param symbol simbolo corrente
 * @return ACEITA ou REJEITA
 *)
function q36(symbol : integer) : boolean;
begin
  console(36, symbol);

  case sentence[symbol] of
    'w' : q36 := q21(symbol + 1);
    'x' : q36 := q25(symbol + 1);
    'y' : q36 := q29(symbol + 1);
    'z' : q36 := q34(symbol + 1);
    '$' : q36 := ACEITA;
    else  q36 := REJEITA;
  end;
end;

(**
 * Metodo principal da linguagem de programacao Pascal
 *)
begin
  write('Analise a sentença: ');
  readln(sentence);

  if pos('$', sentence) <> 0 then
  begin
    writeln('A sentença "', sentence, '" é inválida');
    halt;
  end;

  sentence := sentence + '$';

  write('Observação: "$" representa o fim da sentença');

  if q0(1) then
  begin
    writeln(' - ACEITA');
  end
  else
  begin
    writeln(' - REJEITA');
  end;
end.