Skip to content

Commit

Permalink
Merge pull request #1 from Baxi19/baxi_dev
Browse files Browse the repository at this point in the history
Baxi dev
  • Loading branch information
Baxi19 authored Nov 12, 2020
2 parents 7771408 + eb32cca commit cfc1ecd
Show file tree
Hide file tree
Showing 36 changed files with 469 additions and 194 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/Proyecto Compi/backend/IDLE.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/Proyecto Compi/contextualAnalysis/Function.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/Proyecto Compi/errors/Error.class
Binary file not shown.
Binary file modified out/production/Proyecto Compi/frontend/Window.class
Binary file not shown.
Binary file modified out/production/Proyecto Compi/utils/TYPE.class
Binary file not shown.
16 changes: 12 additions & 4 deletions src/backend/IDLE.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ public class IDLE {
protected String path = "";
protected JFileChooser fileChooser = new JFileChooser();

//TODO: Set vars in the first value every time when visitor run
//Contextual Analysis
public int tableId = 0;
public SymbolTable tablaSimbolos = new SymbolTable();
public ArrayList<TerminalNode> parameters = new ArrayList<>();
public ArrayList<Object> auxParam = new ArrayList<>();
public String callWith = "";
public int paramenter = 0;
public String returnStatement ;
public Boolean existReturn = false;


//Singleton
public static IDLE getInstance(){
Expand Down Expand Up @@ -105,9 +109,13 @@ private void markErrors() throws BadLocationException {
private void markContextErrors() throws BadLocationException {
for (int i = 0; i < errorsContextual.size() ; i++) {
int row = errorsContextual.get(i).getRow();
int startIndex = codeArea.getLineStartOffset(row-1);
int endIndex = codeArea.getLineEndOffset(row-1);
codeArea.getHighlighter().addHighlight(startIndex, endIndex, painter);
if(row != -1){
int startIndex = codeArea.getLineStartOffset(row-1);
int endIndex = codeArea.getLineEndOffset(row-1);
codeArea.getHighlighter().addHighlight(startIndex, endIndex, painter);
}


}

}
Expand Down
12 changes: 6 additions & 6 deletions src/contextualAnalysis/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
//Class Function, will represent "Iden" as method's declaration
public class Function extends Ident {
public ArrayList<Ident> parameters;
public Object returnValue;
public String returnValue;

//------------------------------------------------------------------------------------------------------------------
//Constructor
public Function(TerminalNode token, TYPE type, int level, ParserRuleContext declCtx) {
super(token, type, level, declCtx);
this.parameters = new ArrayList<>();
this.returnValue = null;
this.returnValue = "VOID";
}

public Function(TerminalNode token, TYPE type, int level, ParserRuleContext declCtx, ArrayList<Ident> parameters) {
super(token, type, level, declCtx);
this.parameters = parameters;
this.returnValue = null;
this.returnValue = "VOID";
}

public Function(TerminalNode token, TYPE type, int level, ParserRuleContext declCtx,ArrayList<Ident> parameters, Object returnValue) {
public Function(TerminalNode token, TYPE type, int level, ParserRuleContext declCtx,ArrayList<Ident> parameters, String returnValue) {
super(token, type, level, declCtx);
this.parameters = parameters;
this.returnValue = returnValue;
Expand All @@ -47,14 +47,14 @@ public Object getReturnValue() {
return returnValue;
}

public void setReturnValue(Object returnValue) {
public void setReturnValue(String returnValue) {
this.returnValue = returnValue;
}

//------------------------------------------------------------------------------------------------------------------
@Override
public String toString() {
return "\n(" + token.getSymbol().getLine()+ "," + token.getSymbol().getCharPositionInLine() + ") ID = " + super.getId() +", Name = " + token.getText() + ", Level = " + level + ", Type = " + type + ", Parameters = " + parameters.size() + ", Declaration Context=" + declCtx.getText();
return "\n(" + token.getSymbol().getLine()+ "," + token.getSymbol().getCharPositionInLine() + ") ID = " + super.getId() +", Name = " + token.getText() + ", Level = " + level + ", Type = " + type + ", Parameters = " + parameters.size() + ", Return = " + returnValue + ", Declaration Context=" + declCtx.getText();
}

//------------------------------------------------------------------------------------------------------------------
Expand Down
62 changes: 62 additions & 0 deletions src/contextualAnalysis/HashContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package contextualAnalysis;

import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.TerminalNode;
import utils.TYPE;

import java.util.ArrayList;

public class HashContent extends Ident {
public ArrayList<Ident> data;

//Constructor
public HashContent(TerminalNode token, TYPE type, int level, ParserRuleContext declCtx) {
super(token, type, level, declCtx);
this.data = new ArrayList<>();
}

//Getter & Setter
public ArrayList<Ident> getData() {
return data;
}

public void setData(ArrayList<Ident> data) {
this.data = data;
}

//Return the size of Hash content
public int len(){
return this.getData().size();
}

//Return first element in Hash content
public Ident first(){
return this.getData().get(0);
}

//Return last element in Hash content
public Ident last(){
return this.getData().get(len()-1);
}

//Return Hash content with out first element
public ArrayList<Ident> rest(){
this.getData().remove(0);
return this.getData();
}

//Insert value
public Boolean push(Ident value){
try {
this.getData().add(value);
return true;
}catch (Exception e){
return false;
}
}

@Override
public String toString() {
return "\n(" + token.getSymbol().getLine()+ "," + token.getSymbol().getCharPositionInLine() + ") ID = " + super.getId() +", Name = " + token.getText() + ", Level = " + level+ ", Type = " + type + ", HASH Size = " + len() + ", Declaration Context=" + declCtx.getText();
}
}
62 changes: 62 additions & 0 deletions src/contextualAnalysis/HashLiteral.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package contextualAnalysis;

import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.TerminalNode;
import utils.TYPE;

import java.util.ArrayList;

public class HashLiteral extends Ident {
public ArrayList<Ident> data;

//Contructor
public HashLiteral(TerminalNode token, TYPE type, int level, ParserRuleContext declCtx) {
super(token, type, level, declCtx);
this.data = new ArrayList<>();
}

//Setter & Getter
public ArrayList<Ident> getData() {
return data;
}

public void setData(ArrayList<Ident> data) {
this.data = data;
}

//Return the size of Hash content
public int len(){
return this.getData().size();
}

//Return first element in Hash content
public Ident first(){
return this.getData().get(0);
}

//Return last element in Hash content
public Ident last(){
return this.getData().get(len()-1);
}

//Return Hash content with out first element
public ArrayList<Ident> rest(){
this.getData().remove(0);
return this.getData();
}

//Insert value
public Boolean push(Ident value){
try {
this.getData().add(value);
return true;
}catch (Exception e){
return false;
}
}

@Override
public String toString() {
return "\n(" + token.getSymbol().getLine()+ "," + token.getSymbol().getCharPositionInLine() + ") ID = " + super.getId() +", Name = " + token.getText() + ", Level = " + level+ ", Type = " + type + ", HASH Size = " + len() + ", Declaration Context=" + declCtx.getText();
}
}
Loading

0 comments on commit cfc1ecd

Please sign in to comment.