├── lib ├── sablecc.jar ├── autocomplete.jar └── rsyntaxtextarea.jar ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── sablecc.sh ├── sablecc └── .gitkeep ├── src ├── br │ └── com │ │ └── vinyanalista │ │ └── portugol │ │ ├── ide │ │ ├── icones │ │ │ ├── copy.png │ │ │ ├── cut.png │ │ │ ├── paste.png │ │ │ ├── redo.png │ │ │ ├── undo.png │ │ │ ├── brasil.png │ │ │ ├── console.png │ │ │ ├── delete.png │ │ │ ├── folder.png │ │ │ ├── zoom-in.png │ │ │ ├── edit-find.png │ │ │ ├── help-about.png │ │ │ ├── selectall.png │ │ │ ├── user-away.png │ │ │ ├── zoom-out.png │ │ │ ├── arrow-right.png │ │ │ ├── document-new.png │ │ │ ├── user-online.png │ │ │ ├── dialog-cancel.png │ │ │ ├── document-open.png │ │ │ ├── document-print.png │ │ │ ├── document-save.png │ │ │ ├── zoom-original.png │ │ │ ├── application-exit.png │ │ │ ├── document-save-as.png │ │ │ └── edit-find-replace.png │ │ ├── Acao.java │ │ ├── componente │ │ │ ├── JTextPaneToolTip.java │ │ │ ├── ItemDeMenu.java │ │ │ ├── ItemDeMenuComCheckbox.java │ │ │ └── Menu.java │ │ ├── BotaoDaBarraDeFerramentas.java │ │ ├── Applet.java │ │ ├── NoComTabelaDeAtributos.java │ │ ├── Icone.java │ │ ├── Tema.java │ │ ├── Aplicativo.java │ │ ├── TelaPrincipalCompletaDesktop.java │ │ ├── TelaPrincipalCompletaJavaWebStart.java │ │ ├── TerminalEmJanela.java │ │ ├── PortugolTokenMaker.java │ │ ├── ExampleFileFilter.java │ │ ├── TelaPrincipalCompleta.java │ │ └── RelatorioDaAnalise.java │ │ ├── interpretador │ │ ├── execucao │ │ │ ├── EscutaDeExecutor.java │ │ │ ├── PosicaoDeMemoria.java │ │ │ ├── PilhaDeExecucao.java │ │ │ ├── ErroEmTempoDeExecucao.java │ │ │ ├── Registro.java │ │ │ ├── RegistroDeAtivacao.java │ │ │ ├── VetorOuMatriz.java │ │ │ ├── ExecutorDeComandos.java │ │ │ └── Executor.java │ │ ├── tipo │ │ │ ├── TipoSubrotinaPredefinida.java │ │ │ ├── TipoPrimitivo.java │ │ │ ├── Campo.java │ │ │ ├── TipoRegistro.java │ │ │ ├── Tipo.java │ │ │ ├── TipoSubrotina.java │ │ │ └── TipoVetorOuMatriz.java │ │ ├── TerminalEncerrado.java │ │ ├── simbolo │ │ │ ├── Atributo.java │ │ │ ├── TabelaDeAtributos.java │ │ │ ├── Simbolo.java │ │ │ └── TabelaDeSimbolos.java │ │ ├── analise │ │ │ ├── ErroSemantico.java │ │ │ ├── AnalisadorSemantico.java │ │ │ └── AnalisadorDeDeclaracoes.java │ │ ├── subrotina │ │ │ ├── Parametro.java │ │ │ └── SubrotinaPreDefinida.java │ │ ├── referencia │ │ │ ├── Referencia.java │ │ │ ├── ReferenciaPosicaoEmVetorOuMatriz.java │ │ │ └── ReferenciaVariavel.java │ │ ├── auxiliar │ │ │ └── NumeraLinhas.java │ │ ├── TerminalDeTexto.java │ │ ├── Terminal.java │ │ └── Interpretador.java │ │ ├── auxiliar │ │ └── Log.java │ │ └── base │ │ └── lexer │ │ └── CustomLexer.java ├── theme.dtd ├── vs.xml ├── eclipse.xml ├── dark.xml ├── default.xml ├── default-alt.xml └── idea.xml ├── sablecc.bat ├── .project ├── .gitignore └── .classpath /lib/sablecc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/lib/sablecc.jar -------------------------------------------------------------------------------- /lib/autocomplete.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/lib/autocomplete.jar -------------------------------------------------------------------------------- /lib/rsyntaxtextarea.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/lib/rsyntaxtextarea.jar -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /sablecc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | rm -rf sablecc/* 3 | java -cp lib/sablecc.jar org.sablecc.sablecc.SableCC src/portugol.sablecc -d sablecc -------------------------------------------------------------------------------- /sablecc/.gitkeep: -------------------------------------------------------------------------------- 1 | Esse arquivo é usado somente para o Git não ignorar essa pasta no commit, já que ela está vazia. Quando povoar essa pasta, excluir este arquivo. -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/copy.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/cut.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/paste.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/redo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/redo.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/undo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/undo.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/brasil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/brasil.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/console.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/console.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/delete.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/folder.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/zoom-in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/zoom-in.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/edit-find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/edit-find.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/help-about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/help-about.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/selectall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/selectall.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/user-away.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/user-away.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/zoom-out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/zoom-out.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/arrow-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/arrow-right.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/document-new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/document-new.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/user-online.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/user-online.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/dialog-cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/dialog-cancel.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/document-open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/document-open.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/document-print.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/document-print.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/document-save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/document-save.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/zoom-original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/zoom-original.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/application-exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/application-exit.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/document-save-as.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/document-save-as.png -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/icones/edit-find-replace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinyanalista/portugol/HEAD/src/br/com/vinyanalista/portugol/ide/icones/edit-find-replace.png -------------------------------------------------------------------------------- /sablecc.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: http://stackoverflow.com/questions/6836566/batch-file-delete-all-files-and-folders-in-a-directory 3 | rd "sablecc/br" /s /q 4 | call java -cp lib/sablecc.jar org.sablecc.sablecc.SableCC src/portugol.sablecc -d sablecc 5 | pause -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/execucao/EscutaDeExecutor.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.execucao; 2 | 3 | public interface EscutaDeExecutor { 4 | void aoEncerrarExecucao(ErroEmTempoDeExecucao erroEmTempoDeExecucao); 5 | } 6 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/tipo/TipoSubrotinaPredefinida.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.tipo; 2 | 3 | public class TipoSubrotinaPredefinida extends TipoSubrotina { 4 | public TipoSubrotinaPredefinida() { 5 | super(null, null); 6 | } 7 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/TerminalEncerrado.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador; 2 | 3 | public class TerminalEncerrado extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public TerminalEncerrado() { 7 | super("Terminal encerrado"); 8 | } 9 | 10 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/execucao/PosicaoDeMemoria.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.execucao; 2 | 3 | public class PosicaoDeMemoria { 4 | private Object valor; 5 | 6 | public Object getValor() { 7 | return valor; 8 | } 9 | 10 | public void setValor(Object valor) { 11 | this.valor = valor; 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | PortugolOnline 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/Acao.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide; 2 | 3 | import javax.swing.*; 4 | 5 | public abstract class Acao extends AbstractAction { 6 | protected static final long serialVersionUID = 1L; 7 | 8 | public Acao(String nome, Icon icone, String tooltip, KeyStroke atalho) { 9 | super(nome, icone); 10 | putValue(ACCELERATOR_KEY, atalho); 11 | putValue(SHORT_DESCRIPTION, tooltip); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/componente/JTextPaneToolTip.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide.componente; 2 | 3 | import javax.swing.*; 4 | 5 | public class JTextPaneToolTip extends JToolTip { 6 | private static final long serialVersionUID = 1L; 7 | 8 | private final JTextPane textPane; 9 | 10 | public JTextPaneToolTip(JTextPane textPane) { 11 | this.textPane = textPane; 12 | } 13 | 14 | @Override 15 | public void setTipText(String text) { 16 | textPane.setText(text); 17 | } 18 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/componente/ItemDeMenu.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide.componente; 2 | 3 | import javax.swing.*; 4 | 5 | public class ItemDeMenu extends JMenuItem { 6 | private static final long serialVersionUID = 1L; 7 | 8 | private final JTextPaneToolTip tooltip; 9 | 10 | public ItemDeMenu(Action acao, JTextPaneToolTip tooltip) { 11 | super(acao); 12 | this.tooltip = tooltip; 13 | } 14 | 15 | @Override 16 | public JToolTip createToolTip() { 17 | return tooltip; 18 | } 19 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/componente/ItemDeMenuComCheckbox.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide.componente; 2 | 3 | import javax.swing.*; 4 | 5 | public class ItemDeMenuComCheckbox extends JCheckBoxMenuItem { 6 | private static final long serialVersionUID = 1L; 7 | 8 | private final JTextPaneToolTip tooltip; 9 | 10 | public ItemDeMenuComCheckbox(Action acao, JTextPaneToolTip tooltip) { 11 | super(acao); 12 | this.tooltip = tooltip; 13 | } 14 | 15 | @Override 16 | public JToolTip createToolTip() { 17 | return tooltip; 18 | } 19 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/BotaoDaBarraDeFerramentas.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide; 2 | 3 | import javax.swing.*; 4 | 5 | public class BotaoDaBarraDeFerramentas extends JButton { 6 | private static final long serialVersionUID = 1L; 7 | 8 | public BotaoDaBarraDeFerramentas(Action acao) { 9 | super(acao); 10 | setText(null); 11 | setToolTipText((String) acao.getValue(Action.NAME)); 12 | } 13 | 14 | @Override 15 | public void setText(String text) { 16 | // Não faz nada, pois os botões da barra de ferramentas não devem 17 | // apresentar texto 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # https://github.com/github/gitignore 2 | 3 | ########### 4 | # Windows # 5 | 6 | # Windows image file caches 7 | Thumbs.db 8 | ehthumbs.db 9 | 10 | # Folder config file 11 | Desktop.ini 12 | 13 | # Recycle Bin used on file shares 14 | $RECYCLE.BIN/ 15 | 16 | # Windows Installer files 17 | *.cab 18 | *.msi 19 | *.msm 20 | *.msp 21 | 22 | ######### 23 | # Linux # 24 | 25 | *~ 26 | .directory 27 | 28 | ########### 29 | # Eclipse # 30 | ########### 31 | 32 | bin/ 33 | 34 | ########### 35 | # SableCC # 36 | 37 | sablecc/* 38 | !sablecc/.gitkeep 39 | 40 | ######### 41 | # Other # 42 | 43 | portugol.jar -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.6 12 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/execucao/PilhaDeExecucao.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.execucao; 2 | 3 | import java.util.Stack; 4 | 5 | public class PilhaDeExecucao { 6 | 7 | private final Stack pilha; 8 | 9 | public PilhaDeExecucao() { 10 | pilha = new Stack(); 11 | } 12 | 13 | public void inserir(RegistroDeAtivacao registroDeAtivacao) { 14 | pilha.push(registroDeAtivacao); 15 | } 16 | 17 | public RegistroDeAtivacao obterRegistroAtual() { 18 | return pilha.peek(); 19 | } 20 | 21 | public RegistroDeAtivacao remover() { 22 | return pilha.pop(); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/simbolo/Atributo.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.simbolo; 2 | 3 | public enum Atributo { 4 | SIMBOLO, // Simbolo 5 | ID, // String 6 | LINHA, // Integer 7 | COLUNA, // Integer 8 | TIPO, // Tipo ou TipoArray (que herda de Tipo) 9 | CAPACIDADE, // Integer 10 | POSICAO, // Integer 11 | VALOR, // Integer, String ou Float (?) 12 | SOMENTE_LEITURA, // Boolean 13 | STRING, // String (apenas para fins de teste) 14 | INICIO, // Integer 15 | PASSO, // Integer 16 | FIM, // Integer 17 | REFERENCIA; // Referencia 18 | } -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/componente/Menu.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide.componente; 2 | 3 | import javax.swing.*; 4 | 5 | public class Menu extends JMenu { 6 | private static final long serialVersionUID = 1L; 7 | 8 | private final JTextPaneToolTip tooltip; 9 | 10 | public Menu(String texto, String ajuda, JTextPaneToolTip tooltip) { 11 | super(texto); 12 | setToolTipText(ajuda); 13 | this.tooltip = tooltip; 14 | } 15 | 16 | public Menu(String texto, char mnemonico) { 17 | super(texto); 18 | setMnemonic(mnemonico); 19 | tooltip = null; 20 | } 21 | 22 | @Override 23 | public JToolTip createToolTip() { 24 | if (tooltip == null) { 25 | return super.createToolTip(); 26 | } else { 27 | return tooltip; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/tipo/TipoPrimitivo.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.tipo; 2 | 3 | public enum TipoPrimitivo { 4 | NUMERICO { 5 | 6 | @Override 7 | public String toString() { 8 | return "NUMERICO"; 9 | } 10 | 11 | }, LITERAL { 12 | 13 | @Override 14 | public String toString() { 15 | return "LITERAL"; 16 | } 17 | 18 | }, LOGICO { 19 | 20 | @Override 21 | public String toString() { 22 | return "LOGICO"; 23 | } 24 | }, DETERMINADO_EM_TEMPO_DE_EXECUCAO { 25 | 26 | @Override 27 | public String toString() { 28 | return "determinado em tempo de execução"; 29 | } 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/analise/ErroSemantico.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.analise; 2 | 3 | import br.com.vinyanalista.portugol.base.node.Node; 4 | 5 | public class ErroSemantico extends Exception { 6 | private static final long serialVersionUID = 1L; 7 | 8 | private final int coluna; 9 | private final int linha; 10 | private final Node no; 11 | 12 | public ErroSemantico(Node no, String mensagem, int linha, int coluna) { 13 | super(mensagem); 14 | this.coluna = coluna; 15 | this.linha = linha; 16 | this.no = no; 17 | } 18 | 19 | public int getColuna() { 20 | return coluna; 21 | } 22 | 23 | public int getLinha() { 24 | return linha; 25 | } 26 | 27 | public Node getNo() { 28 | return no; 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/simbolo/TabelaDeAtributos.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.simbolo; 2 | 3 | import java.util.*; 4 | 5 | public class TabelaDeAtributos { 6 | private final HashMap tabela; 7 | 8 | public TabelaDeAtributos() { 9 | tabela = new HashMap(); 10 | } 11 | 12 | public Set atributos() { 13 | return tabela.keySet(); 14 | } 15 | 16 | public boolean possui(Atributo atributo) { 17 | return tabela.containsKey(atributo); 18 | } 19 | 20 | public void inserir(Atributo atributo, Object valor) { 21 | tabela.put(atributo, valor); 22 | } 23 | 24 | public Object obter(Atributo atributo) { 25 | return tabela.get(atributo); 26 | } 27 | 28 | public int tamanho() { 29 | return tabela.size(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/subrotina/Parametro.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.subrotina; 2 | 3 | import br.com.vinyanalista.portugol.interpretador.simbolo.Simbolo; 4 | import br.com.vinyanalista.portugol.interpretador.tipo.Tipo; 5 | 6 | public class Parametro { 7 | private final String descricao; 8 | private final String identificador; 9 | private final Tipo tipo; 10 | 11 | public Parametro(String identificador, String descricao, Tipo tipo) { 12 | this.identificador = identificador; 13 | this.descricao = descricao; 14 | this.tipo = tipo; 15 | } 16 | 17 | public String getDescricao() { 18 | return descricao; 19 | } 20 | 21 | public String getIdentificador() { 22 | return identificador; 23 | } 24 | 25 | public Tipo getTipo() { 26 | return tipo; 27 | } 28 | 29 | public Simbolo getSimbolo() { 30 | return Simbolo.obter(identificador); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/execucao/ErroEmTempoDeExecucao.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.execucao; 2 | 3 | import br.com.vinyanalista.portugol.base.node.Node; 4 | 5 | public class ErroEmTempoDeExecucao extends Exception { 6 | private static final long serialVersionUID = 1L; 7 | 8 | private final int coluna; 9 | private final int linha; 10 | private final Node no; 11 | 12 | public ErroEmTempoDeExecucao(String mensagem) { 13 | this(null, mensagem, 1, 1); 14 | } 15 | 16 | public ErroEmTempoDeExecucao(Node no, String mensagem, int linha, int coluna) { 17 | super(mensagem); 18 | this.coluna = coluna; 19 | this.linha = linha; 20 | this.no = no; 21 | } 22 | 23 | public int getColuna() { 24 | return coluna; 25 | } 26 | 27 | public int getLinha() { 28 | return linha; 29 | } 30 | 31 | public Node getNo() { 32 | return no; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/Applet.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide; 2 | 3 | import java.util.Locale; 4 | 5 | import javax.swing.*; 6 | 7 | import br.com.vinyanalista.portugol.auxiliar.Log; 8 | 9 | public class Applet extends JApplet { 10 | private static final long serialVersionUID = 1L; 11 | 12 | private final TelaPrincipalMinima telaPrincipalMinima; 13 | 14 | public Applet() { 15 | Locale.setDefault(new Locale("pt", "BR")); 16 | try { 17 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 18 | } catch (Exception e) { 19 | e.printStackTrace(); // Não deve acontecer 20 | } 21 | Log.informacao("Executando via applet"); 22 | telaPrincipalMinima = new TelaPrincipalMinima(); 23 | setRootPane(telaPrincipalMinima); 24 | } 25 | 26 | @Override 27 | public void start() { 28 | SwingUtilities.invokeLater(new Runnable() { 29 | public void run() { 30 | telaPrincipalMinima.editor.requestFocusInWindow(); 31 | } 32 | }); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/referencia/Referencia.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.referencia; 2 | 3 | import br.com.vinyanalista.portugol.interpretador.execucao.*; 4 | 5 | public abstract class Referencia { 6 | private Referencia proximaReferencia; 7 | private Referencia referenciaAnterior; 8 | 9 | public Referencia(Referencia proximaReferencia) { 10 | this.proximaReferencia = proximaReferencia; 11 | if (proximaReferencia != null) { 12 | proximaReferencia.referenciaAnterior = this; 13 | } 14 | } 15 | 16 | public Referencia getProximaReferencia() { 17 | return proximaReferencia; 18 | } 19 | 20 | public Referencia getReferenciaAnterior() { 21 | return referenciaAnterior; 22 | } 23 | 24 | public abstract PosicaoDeMemoria resolver(RegistroDeAtivacao registroDeAtivacao) throws ErroEmTempoDeExecucao; 25 | 26 | protected abstract PosicaoDeMemoria resolver(PosicaoDeMemoria resultadoDaReferenciaAnterior) throws ErroEmTempoDeExecucao; 27 | 28 | public void setProximaReferencia(Referencia proximaReferencia) { 29 | this.proximaReferencia = proximaReferencia; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/execucao/Registro.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.execucao; 2 | 3 | import java.util.HashMap; 4 | 5 | import br.com.vinyanalista.portugol.interpretador.simbolo.*; 6 | import br.com.vinyanalista.portugol.interpretador.tipo.*; 7 | 8 | public class Registro { 9 | private final HashMap campos; 10 | 11 | public Registro(TipoRegistro tipo) { 12 | TabelaDeSimbolos campos = tipo.getCampos(); 13 | int quantidadeDeCampos = campos.tamanho(); 14 | this.campos = new HashMap(quantidadeDeCampos); 15 | for (int c = 0; c < quantidadeDeCampos; c++) { 16 | TabelaDeAtributos atributosDoCampo = campos.obter(c); 17 | Simbolo simboloDoCampo = (Simbolo) atributosDoCampo.obter(Atributo.SIMBOLO); 18 | Tipo tipoDoCampo = (Tipo) atributosDoCampo.obter(Atributo.TIPO); 19 | PosicaoDeMemoria campo = new PosicaoDeMemoria(); 20 | campo.setValor(tipoDoCampo.getValorPadrao()); 21 | this.campos.put(simboloDoCampo, campo); 22 | } 23 | } 24 | 25 | public PosicaoDeMemoria getCampo(Simbolo campo) { 26 | return campos.get(campo); 27 | } 28 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/simbolo/Simbolo.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.simbolo; 2 | 3 | import java.util.Dictionary; 4 | 5 | public class Simbolo implements Comparable { 6 | 7 | private String representacao; 8 | 9 | private Simbolo(String representacao) { 10 | this.representacao = representacao; 11 | } 12 | 13 | @Override 14 | public int compareTo(Simbolo outroSimbolo) { 15 | return representacao.compareTo(outroSimbolo.representacao); 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return representacao; 21 | } 22 | 23 | private static Dictionary simbolosConhecidos = new java.util.Hashtable(); 24 | 25 | public static Simbolo obter(String id) { 26 | // Garante que cada ID seja atribuído a um único símbolo 27 | String representacao = id.intern(); 28 | Simbolo simbolo = (Simbolo) simbolosConhecidos.get(representacao); 29 | if (simbolo == null) { 30 | simbolo = new Simbolo(representacao); 31 | simbolosConhecidos.put(representacao, simbolo); 32 | } 33 | return simbolo; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/auxiliar/NumeraLinhas.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.auxiliar; 2 | 3 | import java.util.StringTokenizer; 4 | 5 | public class NumeraLinhas { 6 | 7 | public static String numerar(String texto) { 8 | StringTokenizer quebraString = new StringTokenizer(texto.replace("\n", " \n"), "\n"); 9 | int qtdDeAlgarismos = String.valueOf(quebraString.countTokens()).length(); 10 | String linha = null; 11 | int qtdDeLinhas = 0; 12 | StringBuilder constroiString = new StringBuilder(); 13 | while (quebraString.hasMoreTokens()) { 14 | linha = quebraString.nextToken(); 15 | qtdDeLinhas++; 16 | String numDaLinha = String.valueOf(qtdDeLinhas); 17 | for (int i = String.valueOf(qtdDeLinhas).length(); i < qtdDeAlgarismos; i++) { 18 | constroiString.append("0"); 19 | } 20 | constroiString.append(numDaLinha).append(": ").append(linha); 21 | if (quebraString.hasMoreTokens()) { 22 | constroiString.append("\n"); 23 | } 24 | } 25 | return constroiString.toString(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/NoComTabelaDeAtributos.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide; 2 | 3 | 4 | import br.com.vinyanalista.portugol.interpretador.simbolo.TabelaDeAtributos; 5 | 6 | // import javax.swing.ImageIcon; 7 | import javax.swing.tree.DefaultMutableTreeNode; 8 | 9 | public class NoComTabelaDeAtributos extends DefaultMutableTreeNode { 10 | /* public static final ImageIcon ICONE_NO = new ImageIcon(ItemDaArvoreSemantica.class.getResource("../icons/user-online.png")); 11 | public static final ImageIcon ICONE_GRUPO = new ImageIcon(ItemDaArvoreSemantica.class.getResource("../icons/folder.png")); */ 12 | private static final long serialVersionUID = 1L; 13 | 14 | private TabelaDeAtributos tabelaDeAtributos; 15 | 16 | public NoComTabelaDeAtributos(String nome) { 17 | super(nome); 18 | } 19 | 20 | public TabelaDeAtributos getTabelaDeAtributos() { 21 | return tabelaDeAtributos; 22 | } 23 | 24 | /* public final void setIcon(QIcon qicon) { 25 | super.setIcon(0, qicon); 26 | } */ 27 | 28 | public void setTabelaDeAtributos(TabelaDeAtributos tabelaDeAtributos) { 29 | this.tabelaDeAtributos = tabelaDeAtributos; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/tipo/Campo.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.tipo; 2 | 3 | import br.com.vinyanalista.portugol.base.node.PVariavel; 4 | 5 | public class Campo { 6 | public static String identificadorGlobal(String identificadorDoRegistro, 7 | String identificadorDoCampo) { 8 | return identificadorDoRegistro + "." + identificadorDoCampo; 9 | } 10 | 11 | public static String string(String stringDoRegistro, String stringDoCampo) { 12 | return stringDoRegistro + "." + stringDoCampo; 13 | } 14 | 15 | private final String identificador; 16 | private final PVariavel variavel; 17 | 18 | public Campo(String identificador, PVariavel variavel) { 19 | this.identificador = identificador; 20 | this.variavel = variavel; 21 | } 22 | 23 | @Override 24 | public boolean equals(Object objeto) { 25 | if (!(objeto instanceof Campo)) { 26 | return false; 27 | } 28 | Campo outroCampo = (Campo) objeto; 29 | 30 | return this.identificador.equals(outroCampo.identificador) 31 | && this.variavel.equals(outroCampo.variavel); 32 | } 33 | 34 | public String getIdentificador() { 35 | return identificador; 36 | } 37 | 38 | public PVariavel getVariavel() { 39 | return variavel; 40 | } 41 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/tipo/TipoRegistro.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.tipo; 2 | 3 | import br.com.vinyanalista.portugol.interpretador.execucao.Registro; 4 | import br.com.vinyanalista.portugol.interpretador.simbolo.TabelaDeSimbolos; 5 | 6 | public class TipoRegistro extends Tipo { 7 | private final TabelaDeSimbolos tabelaDeSimbolos; 8 | 9 | public TipoRegistro() { 10 | super(null); 11 | tabelaDeSimbolos = new TabelaDeSimbolos(); 12 | } 13 | 14 | public TabelaDeSimbolos getCampos() { 15 | return tabelaDeSimbolos; 16 | } 17 | 18 | @Override 19 | public boolean ehLogico() { 20 | return false; 21 | } 22 | 23 | @Override 24 | public boolean ehNumerico() { 25 | return false; 26 | } 27 | 28 | @Override 29 | public boolean equals(Object objeto) { 30 | if (!(objeto instanceof TipoRegistro)) { 31 | return false; 32 | } 33 | return tabelaDeSimbolos 34 | .equals(((TipoRegistro) objeto).tabelaDeSimbolos); 35 | } 36 | 37 | @Override 38 | public Object getValorPadrao() { 39 | return new Registro(this); 40 | } 41 | 42 | @Override 43 | public boolean podeReceberEntradaDoUsuario() { 44 | return false; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | // TODO Implementar TipoRegistro.toString() 50 | return "REGISTRO([...])"; 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/Icone.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide; 2 | 3 | import javax.swing.ImageIcon; 4 | 5 | public enum Icone { 6 | ABRIR("document-open.png"), 7 | AUMENTAR_FONTE("zoom-in.png"), 8 | CANCELAR("dialog-cancel.png"), 9 | COLAR("paste.png"), 10 | CONSOLE("console.png"), 11 | COPIAR("copy.png"), 12 | DATA_HORA("user-away.png"), 13 | DELETAR("delete.png"), 14 | DESFAZER("undo.png"), 15 | DIMINUIR_FONTE("zoom-out.png"), 16 | EXECUTAR("arrow-right.png"), 17 | IMPRIMIR("document-print.png"), 18 | LOCALIZAR("edit-find.png"), 19 | NO_RAIZ("user-online.png"), 20 | NOVO("document-new.png"), 21 | PASTA("folder.png"), 22 | PORTUGOL("brasil.png"), 23 | RECORTAR("cut.png"), 24 | REFAZER("redo.png"), 25 | RESTAURAR_TAMANHO_PADRAO_DE_FONTE("zoom-original.png"), 26 | SAIR("application-exit.png"), 27 | SALVAR("document-save.png"), 28 | SALVAR_COMO("document-save-as.png"), 29 | SELECIONAR_TUDO("selectall.png"), 30 | SOBRE("help-about.png"), 31 | SUBSTITUIR("edit-find-replace.png"); 32 | 33 | private static final String PACOTE_DOS_ICONES = "br/com/vinyanalista/portugol/ide/icones/"; 34 | 35 | public static ImageIcon obterIcone(Icone icone) { 36 | return new ImageIcon(TelaPrincipalMinima.class.getClassLoader() 37 | .getResource(PACOTE_DOS_ICONES + icone.nomeDoArquivo)); 38 | } 39 | 40 | private final String nomeDoArquivo; 41 | 42 | private Icone(String nomeDoArquivo) { 43 | this.nomeDoArquivo = nomeDoArquivo; 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/Tema.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide; 2 | 3 | import java.awt.Color; 4 | import java.io.IOException; 5 | 6 | import org.fife.ui.rsyntaxtextarea.*; 7 | 8 | public enum Tema { 9 | DARK("dark.xml", "Escuro"), DEFAULT_ALT("default-alt.xml", 10 | "Padrão do RSyntaxTextArea (alternativo)"), DEFAULT("default.xml", 11 | "Padrão do RSyntaxTextArea"), ECLIPSE("eclipse.xml", "Eclipse"), IDEA( 12 | "idea.xml", "IntelliJ Idea"), VS("vs.xml", "Visual Studio"); 13 | 14 | public void aplicar(RSyntaxTextArea editor) { 15 | try { 16 | Theme theme = Theme.load(getClass().getResourceAsStream("/" + arquivo)); 17 | theme.apply(editor); 18 | corDaLinhaNormal = editor.getCurrentLineHighlightColor(); 19 | } catch (IOException excecao) { 20 | excecao.printStackTrace(); 21 | } 22 | } 23 | 24 | private final String arquivo; 25 | private Color corDaLinhaComErro; 26 | private Color corDaLinhaNormal; 27 | private final String nome; 28 | 29 | private Tema(String arquivo, String nome) { 30 | this.arquivo = arquivo; 31 | corDaLinhaComErro = new Color(255, 200, 200); 32 | this.nome = nome; 33 | corDaLinhaNormal = null; 34 | } 35 | 36 | public Color getCorDaLinhaComErro() { 37 | return corDaLinhaComErro; 38 | } 39 | 40 | public Color getCorDaLinhaNormal() { 41 | return corDaLinhaNormal; 42 | } 43 | 44 | public String getNome() { 45 | return nome; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return nome; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/referencia/ReferenciaPosicaoEmVetorOuMatriz.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.referencia; 2 | 3 | import br.com.vinyanalista.portugol.interpretador.execucao.*; 4 | import br.com.vinyanalista.portugol.interpretador.tipo.TipoVetorOuMatriz; 5 | 6 | public class ReferenciaPosicaoEmVetorOuMatriz extends Referencia { 7 | 8 | private final int[] posicoes; 9 | 10 | public ReferenciaPosicaoEmVetorOuMatriz(int[] posicoes, Referencia proximaReferencia) { 11 | super(proximaReferencia); 12 | this.posicoes = posicoes; 13 | } 14 | 15 | @Override 16 | public PosicaoDeMemoria resolver(RegistroDeAtivacao registroDeAtivacao) { 17 | return null; 18 | } 19 | 20 | @Override 21 | protected PosicaoDeMemoria resolver(PosicaoDeMemoria resultadoDaReferenciaAnterior) throws ErroEmTempoDeExecucao { 22 | VetorOuMatriz vetorOuMatriz = (VetorOuMatriz) resultadoDaReferenciaAnterior.getValor(); 23 | PosicaoDeMemoria celula = vetorOuMatriz.obterCelula(posicoes); 24 | if (getProximaReferencia() == null) { 25 | return celula; 26 | } else { 27 | return getProximaReferencia().resolver(celula); 28 | } 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | String referenciaComoString = TipoVetorOuMatriz.dimensoesParaString(posicoes); 34 | if (getProximaReferencia() != null) { 35 | if (getProximaReferencia() instanceof ReferenciaVariavel) { 36 | return referenciaComoString + "." + getProximaReferencia().toString(); 37 | } else if (getProximaReferencia() instanceof ReferenciaPosicaoEmVetorOuMatriz) { 38 | return referenciaComoString + getProximaReferencia().toString(); 39 | } 40 | } 41 | return referenciaComoString; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/referencia/ReferenciaVariavel.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.referencia; 2 | 3 | import br.com.vinyanalista.portugol.interpretador.execucao.*; 4 | import br.com.vinyanalista.portugol.interpretador.simbolo.Simbolo; 5 | 6 | public class ReferenciaVariavel extends Referencia { 7 | private final Simbolo simbolo; 8 | 9 | public ReferenciaVariavel(Simbolo simbolo, Referencia proximaReferencia) { 10 | super(proximaReferencia); 11 | this.simbolo = simbolo; 12 | } 13 | 14 | @Override 15 | public PosicaoDeMemoria resolver(RegistroDeAtivacao registroDeAtivacao) throws ErroEmTempoDeExecucao { 16 | PosicaoDeMemoria posicaoDeMemoria = registroDeAtivacao.obterPosicaoDeMemoria(simbolo); 17 | if (getProximaReferencia() == null) { 18 | return posicaoDeMemoria; 19 | } else { 20 | return getProximaReferencia().resolver(posicaoDeMemoria); 21 | } 22 | } 23 | 24 | @Override 25 | protected PosicaoDeMemoria resolver(PosicaoDeMemoria resultadoDaReferenciaAnterior) { 26 | if (resultadoDaReferenciaAnterior.getValor() instanceof Registro) { 27 | Registro registro = (Registro) resultadoDaReferenciaAnterior.getValor(); 28 | return registro.getCampo(simbolo); 29 | } 30 | return null; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | String referenciaComoString = simbolo.toString(); 36 | if (getProximaReferencia() != null) { 37 | if (getProximaReferencia() instanceof ReferenciaVariavel) { 38 | return referenciaComoString + "." + getProximaReferencia().toString(); 39 | } else if (getProximaReferencia() instanceof ReferenciaPosicaoEmVetorOuMatriz) { 40 | return referenciaComoString + getProximaReferencia().toString(); 41 | } 42 | } 43 | return referenciaComoString; 44 | } 45 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/auxiliar/Log.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.auxiliar; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Calendar; 5 | 6 | /** 7 | * Utility class that serves only for debugging purposes. 8 | * 9 | * @author Antonio Vinicius Menezes Medeiros 10 | * @since 1.0 11 | * 12 | */ 13 | public class Log { 14 | // Logging is activated by default 15 | protected static boolean ATIVADO = true; 16 | 17 | /** 18 | * Obtains the current time as a string. 19 | * 20 | * @return the current time 21 | */ 22 | protected static String dataHoraAtuais() { 23 | return new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(Calendar.getInstance() 24 | .getTime()); 25 | } 26 | 27 | /** 28 | * Writes an information message to the log. If logging is not enabled, a 29 | * call to this method has no effect. 30 | * 31 | * @param message 32 | * the information message to be written 33 | * @see #turnOnLogging() 34 | * @see #turnOffLogging() 35 | */ 36 | public static void informacao(String mensagem) { 37 | if (ATIVADO) 38 | System.out.println(dataHoraAtuais() + " - " + mensagem); 39 | } 40 | 41 | /** 42 | * Writes an error message to the log. If logging is not enabled, a call to 43 | * this method has no effect. 44 | * 45 | * @param message 46 | * the error message to be written 47 | * @see #turnOnLogging() 48 | * @see #turnOffLogging() 49 | */ 50 | public static void erro(String mensagem) { 51 | if (ATIVADO) 52 | System.err.println(dataHoraAtuais() + " - " + mensagem); 53 | } 54 | 55 | /** 56 | * Activates logging. 57 | * 58 | * @see #turnOffLogging() 59 | */ 60 | public void habilitarLog() { 61 | ATIVADO = true; 62 | } 63 | 64 | /** 65 | * Deactivates logging. 66 | * 67 | * @see #turnOnLogging() 68 | */ 69 | public void desabilitarLog() { 70 | ATIVADO = false; 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/tipo/Tipo.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.tipo; 2 | 3 | public class Tipo { 4 | protected final TipoPrimitivo tipoPrimitivo; 5 | 6 | public Tipo(TipoPrimitivo tipoPrimitivo) { 7 | this.tipoPrimitivo = tipoPrimitivo; 8 | } 9 | 10 | public TipoPrimitivo getTipoPrimitivo() { 11 | return tipoPrimitivo; 12 | } 13 | 14 | public boolean ehCompativel(Tipo outroTipo) { 15 | return this.equals(outroTipo) 16 | || (tipoPrimitivo != null && tipoPrimitivo.equals(TipoPrimitivo.DETERMINADO_EM_TEMPO_DE_EXECUCAO)) 17 | || (outroTipo.tipoPrimitivo != null && outroTipo.tipoPrimitivo.equals(TipoPrimitivo.DETERMINADO_EM_TEMPO_DE_EXECUCAO)); 18 | } 19 | 20 | public boolean ehLiteral() { 21 | return tipoPrimitivo.equals(TipoPrimitivo.LITERAL) || tipoPrimitivo.equals(TipoPrimitivo.DETERMINADO_EM_TEMPO_DE_EXECUCAO); 22 | } 23 | 24 | public boolean ehLogico() { 25 | return tipoPrimitivo.equals(TipoPrimitivo.LOGICO) || tipoPrimitivo.equals(TipoPrimitivo.DETERMINADO_EM_TEMPO_DE_EXECUCAO); 26 | } 27 | 28 | public boolean ehNumerico() { 29 | return tipoPrimitivo.equals(TipoPrimitivo.NUMERICO) || tipoPrimitivo.equals(TipoPrimitivo.DETERMINADO_EM_TEMPO_DE_EXECUCAO); 30 | } 31 | 32 | @Override 33 | public boolean equals(Object objeto) { 34 | if (!(objeto instanceof Tipo)) { 35 | return false; 36 | } 37 | return tipoPrimitivo.equals(((Tipo) objeto).tipoPrimitivo); 38 | } 39 | 40 | public Object getValorPadrao() { 41 | switch (tipoPrimitivo) { 42 | case LITERAL: 43 | return ""; 44 | case LOGICO: 45 | return false; 46 | case NUMERICO: 47 | return 0; 48 | default: 49 | return null; 50 | } 51 | } 52 | 53 | public boolean podeReceberEntradaDoUsuario() { 54 | return !tipoPrimitivo.equals(TipoPrimitivo.DETERMINADO_EM_TEMPO_DE_EXECUCAO); // Todos os tipos primitivos podem ser obtidos do usuário 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return tipoPrimitivo.toString(); 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/Aplicativo.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide; 2 | 3 | import java.awt.Toolkit; 4 | import java.awt.event.*; 5 | import java.util.Locale; 6 | 7 | import javax.swing.*; 8 | 9 | import br.com.vinyanalista.portugol.auxiliar.Log; 10 | 11 | public class Aplicativo extends JFrame { 12 | private static final long serialVersionUID = 1L; 13 | 14 | private final TelaPrincipalCompleta telaPrincipalCompleta; 15 | 16 | public Aplicativo() { 17 | super(); 18 | if (TelaPrincipalCompletaJavaWebStart.executandoViaJavaWebStart()) { 19 | Log.informacao("Executando via Java Web Start"); 20 | telaPrincipalCompleta = new TelaPrincipalCompletaJavaWebStart(this); 21 | } else { 22 | telaPrincipalCompleta = new TelaPrincipalCompletaDesktop(this); 23 | } 24 | 25 | setRootPane(telaPrincipalCompleta); 26 | 27 | addWindowListener(new WindowAdapter() { 28 | // Confirma antes de sair 29 | // http://iitdu.forumsmotion.com/t593-java-swing-adding-confirmation-dialogue-for-closing-window-in-jframe 30 | public void windowClosing(WindowEvent e) { 31 | telaPrincipalCompleta.sair(); 32 | } 33 | 34 | // Ícone da janela 35 | // http://stackoverflow.com/questions/15657569/how-to-set-icon-to-jframe 36 | public void windowOpened(WindowEvent evt) { 37 | setIconImage(Icone.obterIcone(Icone.PORTUGOL).getImage()); 38 | telaPrincipalCompleta.editor.requestFocusInWindow(); 39 | } 40 | }); 41 | setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); 42 | setMinimumSize(telaPrincipalCompleta.getMinimumSize()); 43 | setSize(telaPrincipalCompleta.getSize()); 44 | setLocationRelativeTo(null); // Centraliza a janela 45 | } 46 | 47 | public static void main(String[] args) { 48 | Locale.setDefault(new Locale("pt", "BR")); 49 | 50 | final Aplicativo aplicativo = new Aplicativo(); 51 | 52 | SwingUtilities.invokeLater(new Runnable() { 53 | public void run() { 54 | try { 55 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 56 | } catch (Exception e) { 57 | e.printStackTrace(); // Não deve acontecer 58 | } 59 | Toolkit.getDefaultToolkit().setDynamicLayout(true); 60 | aplicativo.setVisible(true); 61 | } 62 | }); 63 | } 64 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/simbolo/TabelaDeSimbolos.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.simbolo; 2 | 3 | import java.util.*; 4 | 5 | public class TabelaDeSimbolos { 6 | private final TabelaDeSimbolos pai; 7 | private final HashMap tabela; 8 | 9 | public TabelaDeSimbolos() { 10 | this(null); 11 | } 12 | 13 | public TabelaDeSimbolos(TabelaDeSimbolos pai) { 14 | this.pai = pai; 15 | tabela = new HashMap(); 16 | } 17 | 18 | @Override 19 | public boolean equals(Object obj) { 20 | // TODO Implementar TabelaDeSimbolos.equals(Object) 21 | return super.equals(obj); 22 | } 23 | 24 | public boolean existe(Simbolo simbolo) { 25 | return existe(simbolo, true); 26 | } 27 | 28 | public boolean existe(Simbolo simbolo, boolean buscarNaTabelaPai) { 29 | boolean existe = tabela.containsKey(simbolo); 30 | if (!existe && buscarNaTabelaPai && pai != null) { 31 | existe = pai.existe(simbolo); 32 | } 33 | return existe; 34 | } 35 | 36 | public TabelaDeAtributos inserir(Simbolo simbolo, TabelaDeAtributos tabelaDeAtributos) { 37 | tabela.put(simbolo, tabelaDeAtributos); 38 | return tabelaDeAtributos; 39 | } 40 | 41 | public TabelaDeAtributos obter(Simbolo simbolo) { 42 | boolean existe = existe(simbolo, false); 43 | if (!existe && pai != null) { 44 | return pai.obter(simbolo); 45 | } else { 46 | return tabela.get(simbolo); 47 | } 48 | } 49 | 50 | public TabelaDeAtributos obter(int posicao) { 51 | // http://javarevisited.blogspot.com.br/2011/12/how-to-traverse-or-loop-hashmap-in-java.html 52 | int contador = -1; 53 | for (Simbolo simbolo : tabela.keySet()) { 54 | contador++; 55 | if (contador == posicao) { 56 | return tabela.get(simbolo); 57 | } 58 | } 59 | return null; 60 | } 61 | 62 | public List obterListaOrdenadaDeSimbolos() { 63 | List listaDeSimbolos = new ArrayList(tamanho()); 64 | for (Simbolo simbolo : tabela.keySet()) { 65 | listaDeSimbolos.add(simbolo); 66 | } 67 | Collections.sort(listaDeSimbolos); 68 | return listaDeSimbolos; 69 | } 70 | 71 | public int tamanho() { 72 | return tabela.size(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/base/lexer/CustomLexer.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.base.lexer; 2 | 3 | //import br.com.vinyanalista.portugol.base.node.*; 4 | 5 | import java.io.*; 6 | 7 | public class CustomLexer extends Lexer { 8 | 9 | /*private int contadorDeComentarios; 10 | private int linhaDoComentario; 11 | private int posicaoDoComentario; 12 | private StringBuilder textoDoComentario;*/ 13 | 14 | public CustomLexer(PushbackReader in) { 15 | super(in); 16 | /*contadorDeComentarios = 0; 17 | linhaDoComentario = 0; 18 | posicaoDoComentario = 0; 19 | textoDoComentario = null;*/ 20 | } 21 | 22 | @Override 23 | protected void filter() throws LexerException, IOException { 24 | // Tratamento de comentários aninhados 25 | // Verifica se está no estado comentário 26 | /*if (state.equals(State.COMENTARIO)) { 27 | // Verifica se acabou de entrar no estado comentário 28 | if (textoDoComentario == null) { 29 | // O token reconhecido deve ser um comentário 30 | // A referência ao token é mantida e ao contador é atribuído o 31 | // valor 1 32 | contadorDeComentarios = 1; 33 | linhaDoComentario = token.getLine(); 34 | posicaoDoComentario = token.getPos(); 35 | textoDoComentario = new StringBuilder(token.getText()); 36 | token = null; // Continuar a ler da entrada 37 | } else { 38 | // Já estava no estado comentário 39 | textoDoComentario.append(token.getText()); // Acumula o texto 40 | if (token instanceof TComentarioA) { 41 | contadorDeComentarios++; 42 | } else if (token instanceof TComentarioF) { 43 | contadorDeComentarios--; 44 | // Verifica se o fim da entrada foi atingido 45 | } else if (token instanceof EOF) { 46 | // Se sim, o comentário não tem fim, então lança uma exceção 47 | throw new LexerException(new InvalidToken(textoDoComentario 48 | .toString(), token.getLine(), token.getPos()), "[" 49 | + (token.getLine()) + "," + (token.getPos()) 50 | + "] Fim do comentário não encontrado"); 51 | } 52 | if (contadorDeComentarios != 0) { 53 | token = null; // Continuar a ler da entrada 54 | } else { 55 | token = new TComentarioBloco(textoDoComentario.toString(), 56 | linhaDoComentario, posicaoDoComentario); // Retorna 57 | // o 58 | // comentário 59 | state = State.NORMAL; // Volta ao estado normal 60 | textoDoComentario = null; // Libera a referência ao 61 | // comentário 62 | } 63 | } 64 | }*/ 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/execucao/RegistroDeAtivacao.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.execucao; 2 | 3 | import java.util.HashMap; 4 | 5 | import br.com.vinyanalista.portugol.interpretador.simbolo.*; 6 | import br.com.vinyanalista.portugol.interpretador.tipo.*; 7 | 8 | public class RegistroDeAtivacao { 9 | private final HashMap memoria; 10 | private final RegistroDeAtivacao pai; 11 | private final Simbolo simboloDaSubrotina; 12 | private final TabelaDeSimbolos tabelaDeSimbolos; 13 | private Tipo tipoDoRetorno; 14 | private Object valorRetornado; 15 | 16 | public RegistroDeAtivacao(Simbolo simboloDaSubrotina, 17 | TabelaDeSimbolos tabelaDeSimbolos, RegistroDeAtivacao pai) { 18 | memoria = new HashMap(); 19 | this.pai = pai; 20 | this.simboloDaSubrotina = simboloDaSubrotina; 21 | this.tabelaDeSimbolos = tabelaDeSimbolos; 22 | tipoDoRetorno = null; 23 | valorRetornado = null; 24 | for (int s = 0; s < tabelaDeSimbolos.tamanho(); s++) { 25 | TabelaDeAtributos atributosDoSimbolo = tabelaDeSimbolos.obter(s); 26 | Tipo tipo = (Tipo) atributosDoSimbolo.obter(Atributo.TIPO); 27 | if (tipo instanceof TipoSubrotina || tipo instanceof TipoSubrotinaPredefinida) { 28 | continue; 29 | } 30 | PosicaoDeMemoria posicaoDeMemoria = new PosicaoDeMemoria(); 31 | posicaoDeMemoria.setValor(tipo.getValorPadrao()); 32 | Simbolo simbolo = (Simbolo) atributosDoSimbolo.obter(Atributo.SIMBOLO); 33 | atribuirPosicaoDeMemoria(simbolo, posicaoDeMemoria); 34 | } 35 | } 36 | 37 | public void atribuirPosicaoDeMemoria(Simbolo simbolo, PosicaoDeMemoria posicaoDeMemoria) { 38 | memoria.put(simbolo, posicaoDeMemoria); 39 | } 40 | 41 | public TabelaDeSimbolos getTabelaDeSimbolos() { 42 | return tabelaDeSimbolos; 43 | } 44 | 45 | public Tipo getTipoDoRetorno() { 46 | return tipoDoRetorno; 47 | } 48 | 49 | public Object getValorRetornado() { 50 | return valorRetornado; 51 | } 52 | 53 | public PosicaoDeMemoria obterPosicaoDeMemoria(Simbolo simbolo) { 54 | PosicaoDeMemoria posicaoDeMemoria = memoria.get(simbolo); 55 | if (posicaoDeMemoria == null) { 56 | return pai.obterPosicaoDeMemoria(simbolo); 57 | } else { 58 | return posicaoDeMemoria; 59 | } 60 | } 61 | 62 | public void setTipoDoRetorno(Tipo tipoDoRetorno) { 63 | this.tipoDoRetorno = tipoDoRetorno; 64 | } 65 | 66 | public void setValorRetornado(Object valorRetornado) { 67 | this.valorRetornado = valorRetornado; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return (simboloDaSubrotina == null ? "ALGORITMO" : simboloDaSubrotina.toString()); 73 | } 74 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/TerminalDeTexto.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador; 2 | 3 | import java.awt.Color; 4 | import java.util.Scanner; 5 | 6 | public class TerminalDeTexto extends Terminal { 7 | private static final long serialVersionUID = 1L; 8 | 9 | private Scanner scanner; 10 | 11 | public TerminalDeTexto() { 12 | super(); 13 | scanner = new Scanner(System.in); 14 | } 15 | 16 | @Override 17 | public synchronized void encerrar() { 18 | if (isEncerrado()) { 19 | return; 20 | } 21 | super.encerrar(); 22 | scanner.close(); 23 | } 24 | 25 | @Override 26 | public synchronized void erro(String mensagemDeErro) { 27 | if (isEncerrado()) { 28 | return; 29 | } 30 | mudarCor(Color.RED); 31 | System.out.println(mensagemDeErro); 32 | mudarCor(null); 33 | } 34 | 35 | @Override 36 | protected synchronized void escrever(String mensagem) { 37 | mudarCor(null); 38 | System.out.println(mensagem); 39 | } 40 | 41 | @Override 42 | public void informacao(String mensagemDeInformacao) { 43 | if (isEncerrado()) { 44 | return; 45 | } 46 | mudarCor(Color.GREEN); 47 | System.out.println(mensagemDeInformacao); 48 | mudarCor(null); 49 | } 50 | 51 | @Override 52 | protected synchronized String ler() { 53 | mudarCor(Color.CYAN); 54 | String leitura = scanner.nextLine(); 55 | mudarCor(null); 56 | return leitura; 57 | } 58 | 59 | @Override 60 | public synchronized void limpar() { 61 | if (isEncerrado()) { 62 | return; 63 | } 64 | // TODO Implementar ConsoleTextual.limpar() 65 | } 66 | 67 | @Override 68 | protected void mudarCor(Color cor) { 69 | // http://stackoverflow.com/questions/1448858/how-to-color-system-out-println-output 70 | // https://github.com/fusesource/jansi/blob/master/jansi/src/main/java/org/fusesource/jansi/Ansi.java 71 | StringBuilder sequenciaDeEscapeANSI = new StringBuilder(); 72 | sequenciaDeEscapeANSI.append((char) 27); 73 | sequenciaDeEscapeANSI.append('['); 74 | int corComoInteiro = 39; // Cor padrão 75 | if (cor != null) { 76 | if (cor == Color.BLACK) { 77 | corComoInteiro = 30; 78 | } else if (cor == Color.BLUE) { 79 | corComoInteiro = 34; 80 | } else if (cor == Color.CYAN) { 81 | corComoInteiro = 36; 82 | } else if (cor == Color.GREEN) { 83 | corComoInteiro = 32; 84 | } else if (cor == Color.MAGENTA) { 85 | corComoInteiro = 35; 86 | } else if (cor == Color.RED) { 87 | corComoInteiro = 31; 88 | } else if (cor == Color.WHITE) { 89 | corComoInteiro = 37; 90 | } else if (cor == Color.YELLOW) { 91 | corComoInteiro = 33; 92 | } 93 | } 94 | sequenciaDeEscapeANSI.append(corComoInteiro); 95 | sequenciaDeEscapeANSI.append('m'); 96 | System.out.print(sequenciaDeEscapeANSI); 97 | } 98 | 99 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/execucao/VetorOuMatriz.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.execucao; 2 | 3 | import br.com.vinyanalista.portugol.interpretador.tipo.*; 4 | 5 | public class VetorOuMatriz { 6 | private final Object[] celulas; 7 | 8 | public VetorOuMatriz(TipoVetorOuMatriz tipo) { 9 | this(tipo.getTipoDasCelulas(), tipo.getCapacidades()); 10 | } 11 | 12 | private VetorOuMatriz(Tipo tipoDasCelulas, int[] capacidades) { 13 | int capacidadeDessaDimensao = extrairInteiroDessaDimensao(capacidades); 14 | celulas = new Object[capacidadeDessaDimensao]; 15 | if (haOutrasDimensoes(capacidades)) { 16 | int[] capacidadesDasOutrasDimensoes = extrairInteirosDasOutrasDimensoes(capacidades); 17 | for (int c = 0; c < celulas.length; c++) { 18 | celulas[c] = new VetorOuMatriz(tipoDasCelulas, capacidadesDasOutrasDimensoes); 19 | } 20 | } else { 21 | for (int c = 0; c < celulas.length; c++) { 22 | PosicaoDeMemoria celula = new PosicaoDeMemoria(); 23 | celula.setValor(tipoDasCelulas.getValorPadrao()); 24 | celulas[c] = celula; 25 | } 26 | } 27 | } 28 | 29 | public boolean ehVetor() { 30 | return (celulas[0] instanceof PosicaoDeMemoria); 31 | } 32 | 33 | private int[] extrairInteirosDasOutrasDimensoes(int[] inteiros) { 34 | if (!haOutrasDimensoes(inteiros)) { 35 | return null; 36 | } 37 | int[] inteirosDasOutrasDimensoes = new int[inteiros.length - 1]; 38 | System.arraycopy(inteiros, 1, inteirosDasOutrasDimensoes, 0, 39 | inteiros.length - 1); 40 | return inteirosDasOutrasDimensoes; 41 | } 42 | 43 | private int extrairInteiroDessaDimensao(int[] inteiros) { 44 | return inteiros[0]; 45 | } 46 | 47 | private boolean haOutrasDimensoes(int[] inteiros) { 48 | return (inteiros.length > 1); 49 | } 50 | 51 | public PosicaoDeMemoria obterCelula(int[] posicoes) throws ErroEmTempoDeExecucao { 52 | int posicaoNessaDimensao = extrairInteiroDessaDimensao(posicoes); 53 | if (posicaoNessaDimensao <= celulas.length) { 54 | Object celulaNessaDimensao = celulas[posicaoNessaDimensao - 1]; 55 | boolean saoEsperadasOutrasDimensoes = haOutrasDimensoes(posicoes); 56 | boolean haOutrasDimensoes = (celulaNessaDimensao instanceof VetorOuMatriz); 57 | if (haOutrasDimensoes && saoEsperadasOutrasDimensoes) { 58 | VetorOuMatriz vetorOuMatriz = (VetorOuMatriz) celulaNessaDimensao; 59 | int[] posicoesNasOutrasDimensoes = extrairInteirosDasOutrasDimensoes(posicoes); 60 | return vetorOuMatriz.obterCelula(posicoesNasOutrasDimensoes); 61 | } 62 | if (!haOutrasDimensoes && !saoEsperadasOutrasDimensoes) { 63 | return (PosicaoDeMemoria) celulaNessaDimensao; 64 | } 65 | } 66 | throw new ErroEmTempoDeExecucao("A posição indicada não existe no vetor ou matriz"); 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /src/theme.dtd: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 29 | 32 | 34 | 39 | 42 | 44 | 46 | 49 | 54 | 56 | 59 | 61 | 65 | 68 | 71 | 80 | -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/tipo/TipoSubrotina.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.tipo; 2 | 3 | import java.util.*; 4 | 5 | import br.com.vinyanalista.portugol.base.node.*; 6 | import br.com.vinyanalista.portugol.interpretador.simbolo.*; 7 | 8 | public class TipoSubrotina extends Tipo { 9 | public static String parametrosParaString(String[] parametros) { 10 | StringBuilder string = new StringBuilder("("); 11 | for (int p = 0; p < parametros.length; p++) { 12 | string.append(parametros[p].trim().toUpperCase()); 13 | if (p < parametros.length - 1) { 14 | string.append(", "); 15 | } 16 | } 17 | string.append(")"); 18 | return string.toString(); 19 | } 20 | 21 | /* public static String argumentosParaString(AChamadaASubRotina chamada) { 22 | List argumentos = chamada.getExpressao(); 23 | int quantidadeDeArgumentos = argumentos.size(); 24 | String[] argumentosComoString = new String[quantidadeDeArgumentos]; 25 | for (int a = 0; a < quantidadeDeArgumentos; a++) { 26 | argumentosComoString[a] = argumentos.get(a).toString(); 27 | } 28 | return parametrosParaString(argumentosComoString); 29 | } */ 30 | 31 | private final PSubRotina implementacao; 32 | private final List parametros; 33 | private final TabelaDeSimbolos tabelaDeSimbolos; 34 | 35 | public TipoSubrotina(PSubRotina implementacao, TabelaDeSimbolos tabelaDeSimbolosPai) { 36 | super(null); 37 | this.implementacao = implementacao; 38 | parametros = new ArrayList(); 39 | tabelaDeSimbolos = new TabelaDeSimbolos(tabelaDeSimbolosPai); 40 | } 41 | 42 | public PSubRotina getImplementacao() { 43 | return implementacao; 44 | } 45 | 46 | public List getParametros() { 47 | return parametros; 48 | } 49 | 50 | public TabelaDeSimbolos getTabelaDeSimbolos() { 51 | return tabelaDeSimbolos; 52 | } 53 | 54 | @Override 55 | public Object getValorPadrao() { 56 | return null; 57 | } 58 | 59 | @Override 60 | public boolean ehLogico() { 61 | return false; 62 | } 63 | 64 | @Override 65 | public boolean ehNumerico() { 66 | return false; 67 | } 68 | 69 | @Override 70 | public boolean equals(Object objeto) { 71 | if (!(objeto instanceof TipoSubrotina)) { 72 | return false; 73 | } 74 | return toString().equals(((TipoSubrotina) objeto).toString()); 75 | } 76 | 77 | @Override 78 | public boolean podeReceberEntradaDoUsuario() { 79 | return false; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | int quantidadeDeParametros = parametros.size(); 85 | String[] parametrosComoString = new String[quantidadeDeParametros]; 86 | for (int p = 0; p < quantidadeDeParametros; p++) { 87 | Simbolo simboloDoParametro = parametros.get(p); 88 | TabelaDeAtributos atributosDoParametro = tabelaDeSimbolos.obter(simboloDoParametro); 89 | Tipo tipoDoParametro = (Tipo) atributosDoParametro.obter(Atributo.TIPO); 90 | parametrosComoString[p] = tipoDoParametro.toString(); 91 | } 92 | return "SUB-ROTINA" + parametrosParaString(parametrosComoString); 93 | } 94 | 95 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/Terminal.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador; 2 | 3 | import java.awt.Color; 4 | 5 | import br.com.vinyanalista.portugol.interpretador.execucao.ErroEmTempoDeExecucao; 6 | 7 | public abstract class Terminal { 8 | private static final String FALSO = "FALSO"; 9 | private static final String VERDADEIRO = "VERDADEIRO"; 10 | 11 | private boolean encerrado; 12 | 13 | public Terminal() { 14 | encerrado = false; 15 | } 16 | 17 | public synchronized void encerrar() { 18 | encerrado = true; 19 | } 20 | 21 | public abstract void erro(String mensagemDeErro); 22 | 23 | protected abstract void escrever(String mensagem); 24 | 25 | public synchronized void escrever(Object... expressoes) { 26 | if (encerrado) { 27 | return; 28 | } 29 | StringBuilder mensagem = new StringBuilder(); 30 | for (Object expressao : expressoes) { 31 | mensagem.append(expressao); 32 | } 33 | escrever(mensagem.toString()); 34 | } 35 | 36 | public abstract void informacao(String mensagemDeInformacao); 37 | 38 | public synchronized boolean isEncerrado() { 39 | return encerrado; 40 | } 41 | 42 | protected abstract String ler(); 43 | 44 | public synchronized String lerLiteral() throws ErroEmTempoDeExecucao, TerminalEncerrado { 45 | if (encerrado) { 46 | throw new TerminalEncerrado(); 47 | } 48 | String leitura = ler(); 49 | // O terminal pode ter sido encerrado durante a leitura 50 | if (encerrado) { 51 | throw new TerminalEncerrado(); 52 | } 53 | return leitura; 54 | } 55 | 56 | public synchronized Boolean lerLogico() throws ErroEmTempoDeExecucao, TerminalEncerrado { 57 | if (encerrado) { 58 | throw new TerminalEncerrado(); 59 | } 60 | String leitura = ler().toUpperCase(); 61 | // O terminal pode ter sido encerrado durante a leitura 62 | if (encerrado) { 63 | throw new TerminalEncerrado(); 64 | } 65 | if (leitura.equals(VERDADEIRO)) { 66 | return Boolean.TRUE; 67 | } else if (leitura.equals(FALSO)) { 68 | return Boolean.FALSE; 69 | } else { 70 | throw new ErroEmTempoDeExecucao("O programa esperava a entrada de um valor do tipo LOGICO"); 71 | } 72 | } 73 | 74 | public synchronized Number lerNumerico() throws ErroEmTempoDeExecucao, TerminalEncerrado { 75 | if (encerrado) { 76 | throw new TerminalEncerrado(); 77 | } 78 | String valorLido = ler(); 79 | // O terminal pode ter sido encerrado durante a leitura 80 | if (encerrado) { 81 | throw new TerminalEncerrado(); 82 | } 83 | Integer valorInteiro = null; 84 | Double valorReal = null; 85 | try { 86 | valorInteiro = Integer.parseInt(valorLido); 87 | } catch (Exception excecao) { 88 | } 89 | try { 90 | valorReal = Double.parseDouble(valorLido); 91 | } catch (Exception excecao) { 92 | } 93 | if (valorInteiro != null) { 94 | return valorInteiro; 95 | } else if (valorReal != null) { 96 | return valorReal; 97 | } else { 98 | throw new ErroEmTempoDeExecucao("O programa esperava a entrada de um valor do tipo NUMERICO"); 99 | } 100 | } 101 | 102 | public abstract void limpar(); 103 | 104 | protected abstract void mudarCor(Color cor); 105 | 106 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/ide/TelaPrincipalCompletaDesktop.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.ide; 2 | 3 | import java.io.*; 4 | import java.util.*; 5 | 6 | import javax.swing.*; 7 | 8 | public class TelaPrincipalCompletaDesktop extends TelaPrincipalCompleta { 9 | private static final long serialVersionUID = 1L; 10 | 11 | protected final JFileChooser dialogoArquivo; 12 | 13 | public TelaPrincipalCompletaDesktop(JFrame janelaDoAplicativo) { 14 | super(janelaDoAplicativo); 15 | 16 | /* Diálogo de arquivo */ 17 | 18 | dialogoArquivo = new JFileChooser(); 19 | ExampleFileFilter filtroDeArquivos = new ExampleFileFilter(); 20 | filtroDeArquivos.addExtension(EXTENSAO); 21 | filtroDeArquivos.setDescription(TIPO_DE_ARQUIVO); 22 | dialogoArquivo.setFileFilter(filtroDeArquivos); 23 | } 24 | 25 | @Override 26 | protected String lerDoArquivo(String caminhoDoArquivo) throws FileNotFoundException, IOException { 27 | StringBuffer codigo = null; 28 | File arquivo = new File(caminhoDoArquivo); 29 | Reader leitor = new FileReader(arquivo); 30 | char[] buffer = new char[100000]; 31 | int numeroDeCaracteresLidos; 32 | codigo = new StringBuffer(); 33 | while ((numeroDeCaracteresLidos = leitor.read(buffer, 0, buffer.length)) != -1) 34 | codigo.append(new String(buffer, 0, numeroDeCaracteresLidos)); 35 | leitor.close(); 36 | return codigo.toString(); 37 | } 38 | 39 | @Override 40 | protected String mostrarDialogoAbrirArquivo() { 41 | if (dialogoArquivo.showOpenDialog(janelaDoAplicativo) != JFileChooser.APPROVE_OPTION) { 42 | return null; 43 | } 44 | if (arquivoModificado && !confirmarAntesDeDescartarAlteracoes()) { 45 | return null; 46 | } 47 | return dialogoArquivo.getSelectedFile().getPath(); 48 | } 49 | 50 | @Override 51 | protected String mostrarDialogoSalvarArquivo() { 52 | String caminhoDoArquivo = null; 53 | if (dialogoArquivo.showSaveDialog(janelaDoAplicativo) != JFileChooser.APPROVE_OPTION) { 54 | // Usuário cancelou 55 | return null; 56 | } 57 | // Adiciona extensão ao nome do arquivo 58 | caminhoDoArquivo = dialogoArquivo.getSelectedFile().getPath(); 59 | caminhoDoArquivo = adicionarExtensaoAutomaticamente(caminhoDoArquivo); 60 | File arquivo = new File(caminhoDoArquivo); 61 | // Verifica se o arquivo já existe 62 | if (arquivo.exists()) { 63 | String[] opcoes = { "Sobrescrever", "Cancelar" }; 64 | int resposta = JOptionPane.showOptionDialog(this, 65 | "Já existe um arquivo chamado \"" + arquivo.getName() 66 | + "\". Tem certeza de que deseja sobrescrevê-lo?", 67 | "Sobrescrever o arquivo? - " + NOME_DO_PROGRAMA, 68 | JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, 69 | null, opcoes, opcoes[1]); 70 | if (resposta == JOptionPane.NO_OPTION) { 71 | // Arquivo já existe e usuário não deseja sobrescrevê-lo 72 | return null; 73 | } 74 | } 75 | return caminhoDoArquivo; 76 | } 77 | 78 | @Override 79 | protected void salvarNoArquivo(String codigoFonte, String caminhoDoArquivo) throws IOException { 80 | PrintWriter impressora = new PrintWriter(new FileWriter(new File(caminhoDoArquivo))); 81 | StringTokenizer codigoFonteComQuebraDeLinha = new StringTokenizer( 82 | codigoFonte, System.getProperty(PROPRIEDADE_FIM_DE_LINHA)); 83 | while (codigoFonteComQuebraDeLinha.hasMoreTokens()) { 84 | impressora.println(codigoFonteComQuebraDeLinha.nextToken()); 85 | } 86 | impressora.close(); 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /src/br/com/vinyanalista/portugol/interpretador/tipo/TipoVetorOuMatriz.java: -------------------------------------------------------------------------------- 1 | package br.com.vinyanalista.portugol.interpretador.tipo; 2 | 3 | import br.com.vinyanalista.portugol.interpretador.execucao.VetorOuMatriz; 4 | 5 | public class TipoVetorOuMatriz extends Tipo { 6 | public static String dimensoesParaString(String[] dimensoes) { 7 | StringBuilder string = new StringBuilder("["); 8 | for (int d = 0; d < dimensoes.length; d++) { 9 | string.append(dimensoes[d].trim().toUpperCase()); 10 | if (d < dimensoes.length - 1) { 11 | string.append(", "); 12 | } 13 | } 14 | string.append("]"); 15 | return string.toString(); 16 | } 17 | 18 | public static String dimensoesParaString(int[] dimensoes) { 19 | int quantidadeDeDimensoes = dimensoes.length; 20 | String[] dimensoesComoString = new String[quantidadeDeDimensoes]; 21 | for (int d = 0; d < quantidadeDeDimensoes; d++) { 22 | dimensoesComoString[d] = String.valueOf(dimensoes[d]); 23 | } 24 | return dimensoesParaString(dimensoesComoString); 25 | } 26 | 27 | private final int[] capacidades; 28 | private final Tipo tipoDasCelulas; 29 | 30 | public TipoVetorOuMatriz(Tipo tipo, int[] capacidades) { 31 | super(tipo.getTipoPrimitivo()); 32 | this.capacidades = capacidades; 33 | tipoDasCelulas = tipo; 34 | } 35 | 36 | public TipoVetorOuMatriz(TipoPrimitivo tipoPrimitivo, int[] capacidades) { 37 | this(new Tipo(tipoPrimitivo), capacidades); 38 | } 39 | 40 | public boolean ehVetor() { 41 | return (capacidades.length == 1); 42 | } 43 | 44 | public int getCapacidade(int dimensao) { 45 | return capacidades[dimensao]; 46 | } 47 | 48 | public int[] getCapacidades() { 49 | return capacidades; 50 | } 51 | 52 | public int getDimensoes() { 53 | return capacidades.length; 54 | } 55 | 56 | public Tipo getTipoDasCelulas() { 57 | return tipoDasCelulas; 58 | } 59 | 60 | @Override 61 | public boolean ehCompativel(Tipo outroTipo) { 62 | if (outroTipo instanceof TipoVetorOuMatriz) { 63 | return ehCompativel((TipoVetorOuMatriz) outroTipo); 64 | } else { 65 | return false; 66 | } 67 | } 68 | 69 | public boolean ehCompativel(TipoVetorOuMatriz outroTipoVetorOuMatriz) { 70 | return this.equals(outroTipoVetorOuMatriz); 71 | } 72 | 73 | @Override 74 | public boolean ehLogico() { 75 | return false; // Um vetor ou matriz não é um valor lógico 76 | } 77 | 78 | @Override 79 | public boolean ehNumerico() { 80 | return false; // Um vetor ou matriz não é um número 81 | } 82 | 83 | @Override 84 | public boolean equals(Object objeto) { 85 | if (!(objeto instanceof TipoVetorOuMatriz)) { 86 | return false; 87 | } 88 | TipoVetorOuMatriz outroTipo = (TipoVetorOuMatriz) objeto; 89 | return tipoDasCelulas.equals(outroTipo.tipoDasCelulas) && capacidades.equals(capacidades); 90 | } 91 | 92 | @Override 93 | public Object getValorPadrao() { 94 | return new VetorOuMatriz(this); 95 | } 96 | 97 | @Override 98 | public boolean podeReceberEntradaDoUsuario() { 99 | return false; 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return getTipoDasCelulas().toString() + dimensoesParaString(capacidades); 105 | } 106 | 107 | } -------------------------------------------------------------------------------- /src/vs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |