-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlador.java
More file actions
86 lines (75 loc) · 2.38 KB
/
Controlador.java
File metadata and controls
86 lines (75 loc) · 2.38 KB
1
2
3
4
5
6
7
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package src;
import java.io.*;
import java.util.*;
import src.Excepciones.Controlador.DefinicionMultiple;
public class Controlador
{
public Controlador(){
}
public Macro Consult(HashMap<String,Macro> table,String name)
{
if(table.containsKey(name)){
return table.get(name);
}
return null;
}
public String sub(HashMap<String,String> args, String line)
{
if(args==null){
return line;
}
SortedMap<String,String> sort=new TreeMap<>((String a, String b) -> b.compareTo(a));
for(Map.Entry<String,String> set:args.entrySet())
{
sort.put(set.getKey(),set.getValue());
}
for(Map.Entry<String,String> set:sort.entrySet())
{
line=line.replace(set.getKey(), set.getValue());
}
return line;
}
public void gen(File salida,FileWriter escritor,HashMap<String,Macro> tableDef) throws IOException
{
salida.createNewFile();
escritor=new FileWriter(salida,false);
for(Map.Entry<String,Macro> set:tableDef.entrySet())
{
escritor.write(set.getKey() + " \n "
+ set.getValue()+"\n");
}
escritor.close();
}
public void addMacro(int i,int j,ArrayList<String> p,HashMap<String,Macro> tableDef,HashMap<String,Boolean> defined)
{
String Name=Macro.readNameDef(p.get(i));
if(tableDef.containsKey(Name) && !Name.contains("#"))
{
throw new DefinicionMultiple();
}
String[] Arguments=Macro.readArgsDef(p.get(i));
Macro x=new Macro(Name, i+1,j,p, Arguments,tableDef,defined);
tableDef.put(Name, x);
defined.put(Name,true);
}
public ArrayList<String> Lectura(BufferedReader archivo) throws IOException
{
ArrayList<String> lines=new ArrayList<>();
String line;
archivo.reset();
while (true)
{
try {
line=archivo.readLine();
if(line==null) break;
line=Operaciones.obtener(line);
lines.add(line+"\n");
} catch (EOFException e)
{
break;
}
}
archivo.reset();
return lines;
}
}