-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
159 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
# Regex to DFA Converter | ||
|
||
Este projeto converte expressões regulares em Autômatos Finitos Determinísticos (DFA) e permite testar sentenças com o DFA gerado. | ||
|
||
## Arquivos no Projeto | ||
|
||
- `FA.java`: Implementa a classe Finite Automaton (FA) que manipula a conversão de expressões regulares para autômatos finitos e outras operações relacionadas. | ||
- `RegexToDFA.java`: Contém a lógica principal para ler a expressão regular e as sentenças a partir de arquivos, converter a expressão para DFA, testar as sentenças e salvar o DFA em formato JFLAP. | ||
- `run_tests.sh`: Script de shell para criar arquivos de teste e executar testes automaticamente. | ||
|
||
## Pré-requisitos | ||
|
||
- JDK 11 ou superior. | ||
|
||
## Compilação | ||
|
||
Para compilar o projeto, use o comando `javac`: | ||
|
||
```sh | ||
javac FA.java RegexToDFA.java | ||
``` | ||
|
||
Este comando irá gerar os arquivos `.class` necessários para executar o programa. | ||
|
||
## Execução | ||
|
||
### Ajuda | ||
|
||
Para ver a ajuda e os detalhes do uso: | ||
|
||
```sh | ||
java RegexToDFA --help | ||
``` | ||
|
||
### Uso | ||
|
||
Para executar o programa, forneça o caminho para o arquivo de sentenças e o arquivo de regex: | ||
|
||
```sh | ||
java RegexToDFA <arquivo-de-sentencas> <arquivo-de-regex> | ||
``` | ||
|
||
### Exemplo | ||
|
||
```sh | ||
java RegexToDFA sentences.txt regex.txt | ||
``` | ||
|
||
## Testes Automáticos | ||
|
||
Um script `run_tests.sh` está incluído para criar arquivos de teste e executar testes automaticamente. Para usá-lo: | ||
|
||
1. Navegue até a pasta do script. | ||
2. Execute o script: | ||
|
||
```sh | ||
./run_tests.sh | ||
``` | ||
|
||
## Estrutura dos Arquivos de Entrada | ||
|
||
### Arquivo de Regex | ||
|
||
O arquivo de regex deve conter uma única linha com a expressão regular a ser convertida. | ||
|
||
Exemplo (`regex.txt`): | ||
|
||
```plaintext | ||
(a+b)c | ||
``` | ||
|
||
### Arquivo de Sentenças | ||
|
||
O arquivo de sentenças deve conter uma sentença por linha. | ||
|
||
Exemplo (`sentences.txt`): | ||
|
||
```plaintext | ||
ac | ||
bc | ||
abac | ||
``` | ||
|
||
## Saída | ||
|
||
O programa exibirá no console se cada sentença foi aceita ou rejeitada pelo DFA gerado a partir da expressão regular. Além disso, um arquivo `.jff` (JFLAP) será gerado contendo a definição do DFA. | ||
|
||
## Releases | ||
|
||
Você pode baixar o arquivo JAR na seção de releases do repositório no GitHub. [Seção de Releases](https://github.com/ravixr/regex-to-dfa/releases) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/bash | ||
|
||
# Array of regular expressions | ||
expressions=( | ||
"(a+b)*c" | ||
"a(b+c)d" | ||
"(ab)*+(cd)*" | ||
"a(bc)*d+ef" | ||
"a*b*+c" | ||
"(a+b+c)*" | ||
"a(b+c)*d" | ||
"(a+b)*a(a+b)*" | ||
"ab+c(de+f)" | ||
"((a+b)(c+d))*" | ||
) | ||
|
||
# Array of sentences | ||
sentences=( | ||
"c\nac\nbc\nabac\nbabc\n" | ||
"abd\nacd\nabcd\nad\naabdc\n" | ||
"\nab\ncd\nababcd\ncdcdcd\n" | ||
"ad\nabcd\nabcbd\nef\na\n" | ||
"\na\nb\naaabbb\nc\n" | ||
"\nabc\naabbcc\ncab\nbcaacb\n" | ||
"ad\nabcd\nabbbd\nabcbcbcbcd\nacd\n" | ||
"a\nba\nabaa\nbaba\nbbbbba\n" | ||
"abcde\nabcf\nabcdef\nab\ncde\n" | ||
"ac\nbd\nacbd\nacacac\nbdac\n" | ||
) | ||
|
||
# Create and populate the test files | ||
for i in {0..9}; do | ||
regex_file="regex-$((i+1)).txt" | ||
sentence_file="sentence-$((i+1)).txt" | ||
|
||
# Write the regular expression to the regex file | ||
echo -e "${expressions[i]}" > "$regex_file" | ||
|
||
# Write the sentences to the sentence file | ||
echo -e "${sentences[i]}" > "$sentence_file" | ||
|
||
# Run the tests | ||
cd .. | ||
|
||
for i in {0..9}; do | ||
java -jar RegexToDFA ../tests/sentence-$((i+1)).txt ../tests/regex-$((i+1)).txt | ||
done |
This file was deleted.
Oops, something went wrong.