diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml
index 0560db5..d33aad3 100644
--- a/nbproject/private/private.xml
+++ b/nbproject/private/private.xml
@@ -4,10 +4,6 @@
- file:/D:/Projetos/hal/src/net/unesc/hal/analysis/Semantic.java
- file:/D:/Projetos/hal/src/net/unesc/hal/analysis/semantic/Node.java
- file:/D:/Projetos/hal/src/net/unesc/hal/views/Editor.java
- file:/D:/Projetos/hal/src/net/unesc/hal/analysis/semantic/Identifier.java
file:/D:/Projetos/hal/src/net/unesc/hal/languages/HAL.java
diff --git a/samples/Exemplo1.lms b/samples/Exemplo1.lms
index b3f0332..cbf2032 100644
--- a/samples/Exemplo1.lms
+++ b/samples/Exemplo1.lms
@@ -5,7 +5,7 @@ var
var
a :integer;
begin
- a:=200000;
+ a:=20000;
readln(a);
if a=x then
z:=z+x
@@ -26,4 +26,5 @@ begin
end.
-
+
+
diff --git a/src/net/unesc/hal/analysis/Lexicon.java b/src/net/unesc/hal/analysis/Lexicon.java
index 78122d8..976008a 100644
--- a/src/net/unesc/hal/analysis/Lexicon.java
+++ b/src/net/unesc/hal/analysis/Lexicon.java
@@ -200,8 +200,6 @@ private void run() {
is_comment_loop = false;
cur_char = chars.get(++car);
buffer.clear();
- } else {
- System.out.println(parseBuffer(buffer) + cur_char);
}
}
diff --git a/src/net/unesc/hal/analysis/Semantic.java b/src/net/unesc/hal/analysis/Semantic.java
index aa0f6df..17ae81a 100644
--- a/src/net/unesc/hal/analysis/Semantic.java
+++ b/src/net/unesc/hal/analysis/Semantic.java
@@ -24,6 +24,11 @@ public class Semantic {
private Node tree;
private Node currNode;
+ private String attrId;
+ private String lastId;
+
+ private boolean isAttribution;
+ private boolean isArgument;
public Semantic() {
this.errors = new ArrayList<>();
@@ -31,6 +36,10 @@ public Semantic() {
this.currNode = tree;
this.currType = 0;
this.currCategory = -1;
+ this.isAttribution = false;
+ this.isArgument = false;
+ this.attrId = null;
+ this.lastId = null;
}
public ArrayList getErrors() {
@@ -51,60 +60,54 @@ public void check(String[] item) {
String line = item[0];
Integer cod = new Integer(item[1]);
- String token = item[2];
String source = item[3];
- //1, "program"
- //2, "label"
- //3, "const"
- //4, "var"
- //5, "procedure"
- //6, "begin"
- //7, "end"
- //8, "integer"
- //9, "array"
- //10, "of"
- //11, "call"
- //12, "goto"
- //13, "if"
- //14, "then"
- //15, "else"
- //16, "while"
- //17, "do"
- //18, "repeat"
- //19, "until"
- //20, "readln"
- //21, "writeln"
- //22, "or"
- //23, "and"
- //24, "not"
- //27, "for"
- //28, "to"
- //29, "case"
switch (cod) {
case 2:
+ // Label
currCategory = CATEGORY_LABEL;
break;
case 3:
+ // Constant
currCategory = CATEGORY_CONSTANT;
break;
case 4:
+ // Var
currCategory = CATEGORY_VARIABLE;
break;
case 5:
+ // Procedure
currCategory = CATEGORY_PROCEDURE;
break;
case 6:
+ // Begin
currCategory = 0;
break;
case 7:
+ // End
if (currNode.getParent() != null) {
currNode = currNode.getParent();
}
break;
case 25:
+ // Identifier
+ lastId = source;
handleIdentifier(line, source);
break;
+ case 38:
+ // :=
+ if(currCategory == 0){
+ attrId = lastId;
+ isAttribution = true;
+ }
+ break;
+ case 47:
+ // Ponto e vírgula
+ if(currCategory == 0){
+ isAttribution = false;
+ isArgument = false;
+ }
+ break;
}
}
@@ -113,7 +116,7 @@ private void handleIdentifier(String line, String source) {
switch (currCategory) {
case -1:
// Nome do programa
- return;
+ break;
case CATEGORY_PROCEDURE:
if (addProcedure(source) == -1) {
addError("Linha ->" + line + ": A procedure " + source + " já foi declarada");
@@ -144,10 +147,47 @@ private void handleIdentifier(String line, String source) {
default:
if (!anyMatchDeclaration(source, currNode)) {
addError("Linha ->" + line + ": O identificador " + source + " não foi declarado");
+ break;
+ }
+ if(isAttribution && attrId != null && getIdentifierType(attrId, currNode) != getIdentifierType(source, currNode)){
+ addError("Linha ->" + line + ": A atribuição de valor (" + source + ") para o identificador " + attrId + " é incompatível com o seu tipo");
+ break;
}
+ if(anyMatchProcedure(source)){
+ attrId = source;
+ isArgument = true;
+ break;
+ }
+ if(isArgument && getIdentifierType(source, currNode) != TYPE_INTEGER){
+ addError("Linha ->" + line + ": O argumento (" + source + ") é incompatível com a procedure " + attrId);
+ break;
+ }
+
+
}
}
+ private int getIdentifierType(String name, Node n){
+
+ for (Node p : n.getChildren()) {
+ if (p.isProcedure() && p.getName().toUpperCase().equals(name.toUpperCase())) {
+ return -1;
+ }
+ }
+
+ for (Identifier i : n.getIdentifiers()) {
+ if (i.getName().toUpperCase().equals(name.toUpperCase())) {
+ return i.getType();
+ }
+ }
+
+ if (n.getParent() != null) {
+ return getIdentifierType(name, n.getParent());
+ }
+
+ return -1;
+ }
+
private int addIdentifier(String name, int category, int type) {
if (anyMatchIdentifier(name)) {
return -1;
@@ -272,7 +312,7 @@ private String parseCategory(int category) {
case CATEGORY_CONSTANT:
return "Constante";
case CATEGORY_LABEL:
- return "Label";
+ return "Rótulo";
case CATEGORY_PARAMETER:
return "Parâmetro";
case CATEGORY_PROCEDURE:
diff --git a/src/net/unesc/hal/analysis/semantic/Node.java b/src/net/unesc/hal/analysis/semantic/Node.java
index 722f4e2..2a4a440 100644
--- a/src/net/unesc/hal/analysis/semantic/Node.java
+++ b/src/net/unesc/hal/analysis/semantic/Node.java
@@ -33,8 +33,8 @@ public void addIdentifier(Identifier id){
this.identifiers.add(id);
}
- public void getIdentifier(int value){
- this.identifiers.get(value);
+ public Identifier getIdentifier(int value){
+ return this.identifiers.get(value);
}
public ArrayList getChildren() {
diff --git a/src/net/unesc/hal/listeners/EditorListener.java b/src/net/unesc/hal/listeners/EditorListener.java
index de31b2e..fcf0578 100644
--- a/src/net/unesc/hal/listeners/EditorListener.java
+++ b/src/net/unesc/hal/listeners/EditorListener.java
@@ -4,8 +4,7 @@
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import javax.swing.Icon;
import javax.swing.JOptionPane;
import net.unesc.hal.analysis.lexicon.Source;
import net.unesc.hal.exceptions.EditorException;
@@ -48,7 +47,7 @@ private void handle(String cmd) throws EditorException, IOException {
+ "\n\nDisciplina:"
+ "\n- Compiladores 2018/1"
+ "\n\nProfessor:"
- + "\n- Gilberto Vieira", "Sobre", JOptionPane.INFORMATION_MESSAGE);
+ + "\n- Gilberto Vieira", "Sobre", JOptionPane.PLAIN_MESSAGE);
break;
case Editor.SAVE:
ed.setPath(File.write(src.getCode(), ed, ed.getPath()));
diff --git a/src/net/unesc/hal/resources/favicon.png b/src/net/unesc/hal/resources/favicon.png
deleted file mode 100644
index d5baaf9..0000000
Binary files a/src/net/unesc/hal/resources/favicon.png and /dev/null differ
diff --git a/src/net/unesc/hal/resources/icon.png b/src/net/unesc/hal/resources/icon.png
new file mode 100644
index 0000000..c35a401
Binary files /dev/null and b/src/net/unesc/hal/resources/icon.png differ
diff --git a/src/net/unesc/hal/views/Editor.java b/src/net/unesc/hal/views/Editor.java
index 5c2a2ee..cc391da 100644
--- a/src/net/unesc/hal/views/Editor.java
+++ b/src/net/unesc/hal/views/Editor.java
@@ -187,7 +187,7 @@ private void initEditor() {
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (unsaved) {
- if (JOptionPane.showConfirmDialog(null, "Deseja salvar as alteraçãos antes de sair?", "Salvar alterações", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) {
+ if (JOptionPane.showConfirmDialog(null, "Deseja salvar as alteraçãos antes de sair?", "Salvar alterações", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
btnSave.doClick();
};
}
@@ -197,7 +197,7 @@ public void windowClosing(WindowEvent e) {
);
fa = new FiniteAutomaton(new HAL());
- setIconImage(new ImageIcon(getClass().getResource("../resources/favicon.png")).getImage());
+ setIconImage(new ImageIcon(getClass().getResource("../resources/icon.png")).getImage());
fieldEditor = new TextPanelHighLight();
fieldEditor.setCaretColor(Color.WHITE);