Merge branch 'main' of https://gitlab2.istic.univ-rennes1.fr/tuvu/tp2-vsl-pds
This commit is contained in:
@@ -16,14 +16,6 @@ TYPE_INT: 'INT'
|
|||||||
;
|
;
|
||||||
TYPE_VOID: 'VOID'
|
TYPE_VOID: 'VOID'
|
||||||
;
|
;
|
||||||
LE : '<='
|
|
||||||
;
|
|
||||||
LT : '<'
|
|
||||||
;
|
|
||||||
GE : '>='
|
|
||||||
;
|
|
||||||
GT : '>'
|
|
||||||
;
|
|
||||||
ASSIGN :':='
|
ASSIGN :':='
|
||||||
;
|
;
|
||||||
IF : 'IF'
|
IF : 'IF'
|
||||||
@@ -46,7 +38,7 @@ PRINT : 'PRINT'
|
|||||||
;
|
;
|
||||||
RETURN: 'RETURN'
|
RETURN: 'RETURN'
|
||||||
;
|
;
|
||||||
TEXT : '"' (ASCII)+ '"'
|
TEXT : '"' (ASCII)+ '"' {getText().substring(1,getText().length()-1)}
|
||||||
;
|
;
|
||||||
NUMBER : (DIGIT)+
|
NUMBER : (DIGIT)+
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package TP2.asd;
|
package TP2.asd;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.swing.plaf.synth.SynthLabelUI;
|
|
||||||
|
|
||||||
import TP2.asd.Interface.*;
|
import TP2.asd.Interface.*;
|
||||||
import TP2.llvm.ProgramLLVM.*;
|
import TP2.llvm.ProgramLLVM.*;
|
||||||
import TP2.llvm.Interface.*;
|
import TP2.llvm.Interface.*;
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import TP2.asd.Interface.Type;
|
|||||||
import TP2.asd.Program.Type_intImp;
|
import TP2.asd.Program.Type_intImp;
|
||||||
|
|
||||||
public class SymTable {
|
public class SymTable {
|
||||||
private Stack<PMap<String,Type>> stackMap;
|
private PStack<PMap<String,Type>> stackMap;
|
||||||
private int id=1;
|
private int id=1;
|
||||||
public SymTable(){
|
public SymTable(){
|
||||||
this.stackMap= new Stack<>();
|
this.stackMap= ConsPStack.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String addNewTempVar(/*Type type*/){
|
public String addNewTempVar(/*Type type*/){
|
||||||
@@ -22,17 +22,17 @@ public class SymTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void next_layer(){
|
public void next_layer(){
|
||||||
stackMap.push(HashTreePMap.empty());
|
stackMap.plus(HashTreePMap.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void quit_layer() throws Exception{
|
public void quit_layer() throws Exception{
|
||||||
if(stackMap.isEmpty()){
|
if(stackMap.isEmpty()){
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
stackMap.pop();
|
stackMap.minus(stackMap.indexOf(stackMap.getLast()));
|
||||||
}
|
}
|
||||||
public PMap<String,Type> peppapeek(){
|
public PMap<String,Type> peppapeek(){
|
||||||
return stackMap.peek();
|
return stackMap.getLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addVar(String s, Type t){
|
public void addVar(String s, Type t){
|
||||||
@@ -41,9 +41,9 @@ public class SymTable {
|
|||||||
pmap= pmap.plus(s/*+"_"+this.id*/,t);
|
pmap= pmap.plus(s/*+"_"+this.id*/,t);
|
||||||
//this.id++;
|
//this.id++;
|
||||||
//Delete old ones
|
//Delete old ones
|
||||||
stackMap.pop();
|
stackMap.minus(stackMap.indexOf(stackMap.getLast()));
|
||||||
//Push the new one
|
//Push the new one
|
||||||
stackMap.push(pmap);
|
stackMap.plus(pmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Usually look for var in highest level , if not found research.
|
//Usually look for var in highest level , if not found research.
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ FUNC INT main() {
|
|||||||
b:=3
|
b:=3
|
||||||
c:=1
|
c:=1
|
||||||
a := b+c
|
a := b+c
|
||||||
RETURN 4 + 6 * 5 + a }
|
RETURN 4 + 6 * 5 + 2 }
|
||||||
Reference in New Issue
Block a user