An open API service indexing awesome lists of open source software.

https://github.com/ppcamp/compiler-class

Diretório para a linguagem MINI
https://github.com/ppcamp/compiler-class

Last synced: about 1 year ago
JSON representation

Diretório para a linguagem MINI

Awesome Lists containing this project

README

          

# Compila^Iterpreta := :hammer_and_pick: Mini

versão: 0.1

_Projeto configurado em VScode._

_Muitas informações estão contidas nos comentários, dá uma conferida lá_: [#Link](#Comentários)

## Gramática da Linguagem Mini (a ser desenvolvida):


program ::= program identifier body
body ::= [declare decl-list] begin stmt-list end
decl-list ::= decl {";" decl}
decl ::= type ident-list
ident-list ::= identifier {"," identifier}
type ::= integer
stmt-list ::= stmt {";" stmt}
stmt ::= assign-stmt | if-stmt | while-stmt
| read-stmt | write-stmt
assign-stmt ::= identifier ":=" simple_expr
if-stmt ::= if condition then stmt-list end
| if condition then stmt-list else stmt-list end
condition ::= expression
while-stmt ::= do stmt-list stmt-suffix
stmt-suffix ::= while condition
read-stmt ::= read "(" identifier ")"
write-stmt ::= write "(" writable ")"
writable ::= simple-expr | literal
expression ::= simple-expr | simple-expr relop simple-expr
simple-expr ::= term | simple-expr addop term
| "(" simple-expr ")" ? simple-expr ":" simple-expr
term ::= factor-a | term mulop factor-a
fator-a ::= factor | not factor | "-" factor
factor ::= identifier | constant | "(" expression ")"
relop ::= "=" | ">" | ">=" | "<" | "<=" | "<>"
addop ::= "+" | "-" | or
mulop ::= "*" | "/" | mod | and
shiftop ::= "<<" | ">>" | "<<<" | ">>>"
constant ::= digit {digit}
literal ::= " “" {caractere} "”"
identifier ::= letter {letter | digit}
letter ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J"
| "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T"
| "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d"
| "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n"
| "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x"
| "y" | "z"
digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
caractere ::= um dos 256 caracteres do conjunto ASCII, exceto "



**Outras características de Mini**

- As palavras-chave de Mini são reservadas.

- Toda variável deve ser declarada antes do seu uso.

- A semântica dos demais comandos e expressões é a tradicional do Pascal.

- Entrada e saída de Mini estão limitadas ao teclado e à tela de seu computador.

- Comentários de uma linha em Mini começam com %


**# Testes:**


Teste 1:
program teste1
declare
integer a, b, c;
integer result;
begin
read (a);
read (c);
b := 10;
result := (a * c)/(b + 5 % 345 -3) ;
write(result)
end

Teste 2:
program teste2
declarando
integer a;
integer b;
integer c;
begin
read (a);
b := a * a;
c := b + a/2 * (3 + 5);
write(c)
end;

Teste 3:
program teste3
declare
integer id, qtd, cont, soma;
begin
qtd := 5;
cont := 5;
soma := 0;
do
write(“Idade: ”);
read (id);
soma := soma # id;
cont := cont – 1;
while(cont > 0);
write(“Media: ”);
write (soma / qtd);
end

Teste 4:
program teste4
declare
integer i, j, k, _var1;
begin
i := 4 * (5-3) * -50 / 10;
j := i * 10;
k := i* j / k;
k := -4 + 3 $;
write(i);
write(j);
write(k);
end

Teste 5:
program teste5
% programa com if
declare
integer j, k;
begin
read(j);
read(k);
if (k <> 0) then
result := j/k
else
result := 0
end
end

Teste 6:
program teste6
declare
integer a, b, c, maior;
begin
read(a);
read(b);
read(c);
% identifica o maior
if ( a>b and a>c ) then
maior := a
else
if (b>c) then
maior := b
else
maior := c
end
end;
write(maior);
end

Teste 7:
program teste6
declare
integer a, b, c, maior;
begin
read(a);
read(b);
read(c);
% identifica o maior
maior:= (a>b and a>c)?a:(b>c)?b:c;
write(maior);
end

---



## Comentários:

> @ppcamp
>
> O código padrão de exemplo é o codigo.mini, caso seja necessário, pode adicionar outros com outro nome e editar o nome padrão na main.

> @ppcamp
>
> Como precisamos que o código rode no replt, devemos compilar ele para uma versão mais antiga [(clique aqui)](https://stackoverflow.com/questions/47457105/class-has-been-compiled-by-a-more-recent-version-of-the-java-environment) para ver essas versões.
> ```bash
> # Para compilar/executar o Projeto
> >> cd src
> >> jflex Mini.jflex # Gera a classe léxica
> >> cd ..
> >> javac -target 11 -source 11 MiniLexicalAnalyzer.java -d bin
> >> java -classpath bin MiniLexicalAnalyzer
> ```

> @ppcamp
>
> ```bash
> # Para compilar o Jflex
> >> jflex Mini.jflex
> >> javac LexicalAnalyzer.java
> >> java LexicalAnalyzer code_samples/
> ```

> @ppcamp
>
> [Pascal ref](http://www.pascal-central.com/ppl/chapter3.html)

> @ppcamp
>
> [Jflex tutorial](https://www.youtube.com/watch?v=IV1Rwq7ERR4&ab_channel=MiftaSintaha "Vídeo")
>
> [Jflex tuto 2](https://johnidm.gitbooks.io/compiladores-para-humanos/content/part2/building-the-first-lexical-analyzer-with-JFlex.html)

> @ppcamp
>
> Links e configurações:
>
> - [Markdown](https://guides.github.com/features/mastering-markdown/)
>
> - [Jflex](https://www.youtube.com/watch?v=WLHn5JzLx6I&ab_channel=D.KAl "Como instalar")
>
> - [Chocolatey (apt para windows)](https://chocolatey.org/install)
>
> - Java (no choco): digite `choco install openjdk` no powershell como adm.

> @ppcamp
>
> **Instale as extensões recomendadas:** `@recommended`. Modificações sempre em stack.

```

```