Skip to content

Commit

Permalink
simple-program.ob compiles. simple varibake declaration should compile
Browse files Browse the repository at this point in the history
now
  • Loading branch information
patrickdet committed Jun 4, 2012
1 parent 2e69e50 commit 0b94f6e
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 61 deletions.
3 changes: 2 additions & 1 deletion haw/ci/Application.java
Expand Up @@ -24,7 +24,8 @@ public static void main(String[] args) throws IOException {
System.out.println(node.toString());

System.out.println("Code:");
node.compile(new SymbolTable());
SymbolTable symbolTable = new SymbolTable();
node.compile(symbolTable);
} catch (ParserAcceptError e) {
System.out.println(String.format("Failure (cur: %s, nex: %s)", parser.getCurrent(),parser.getNext()));
e.printStackTrace();
Expand Down
3 changes: 1 addition & 2 deletions haw/ci/lib/Parser.java
Expand Up @@ -55,7 +55,6 @@
import haw.ci.lib.nodes.FormalParameterSectionNode;
import haw.ci.lib.nodes.IdentListNode;
import haw.ci.lib.nodes.IdentNode;
import haw.ci.lib.nodes.IdentifierTypeNode;
import haw.ci.lib.nodes.IfStatementNode;
import haw.ci.lib.nodes.IntegerNode;
import haw.ci.lib.nodes.ModuleNode;
Expand Down Expand Up @@ -146,7 +145,7 @@ private AbstractNode Type() throws ParserAcceptError {
AbstractNode type = null;
switch (current.getToken()) {
case IDENTIFER:
type = new IdentifierTypeNode(current.getValue());
type = new IdentNode(current.getValue());
next();
break;
case ARRAY:
Expand Down
8 changes: 4 additions & 4 deletions haw/ci/lib/SymbolTable.java
Expand Up @@ -40,14 +40,14 @@ public int getConstVal(String ident){



public void declare(String ident, Descriptor descr) {
public void declare(String ident, Descriptor descriptor) {
if(!(addressMap.containsKey(ident))){
descriptorMap.put(ident, descr);
descriptorMap.put(ident, descriptor);
addressMap.put(ident, currentAddress);
if(descr == null){
if(descriptor == null){
System.out.println("---- compile Error-----\n Variable = " + ident);
}
currentAddress += descr.size();
currentAddress += descriptor.size();
}else{
System.out.println("Fehler, zweimal die gleiche Variable deklariert");
}
Expand Down
11 changes: 11 additions & 0 deletions haw/ci/lib/nodes/IdentListNode.java
@@ -1,5 +1,8 @@
package haw.ci.lib.nodes;

import haw.ci.lib.SymbolTable;
import haw.ci.lib.descriptor.Descriptor;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -46,5 +49,13 @@ public String toString(int indentation) {
}
return output;
}

public Descriptor compile(SymbolTable symbolTable, Descriptor descriptor) {
for (IdentNode node : nodes) {
symbolTable.declare(node.getIdentifierName(), descriptor);
}

return null;
}

}
50 changes: 0 additions & 50 deletions haw/ci/lib/nodes/IdentifierTypeNode.java

This file was deleted.

4 changes: 2 additions & 2 deletions haw/ci/lib/nodes/TypeDeclarationNode.java
Expand Up @@ -45,10 +45,10 @@ public boolean equals(Object obj) {
public String toString(int indentation) {
String result = toString(indentation, this.getClass().getName() + "\n");
if(ident != null) {
result += ident.toString() + "\n";
result += ident.toString(indentation) + "\n";
}
if(type != null) {
result += type.toString() + "\n";
result += type.toString(indentation) + "\n";
}

return result;
Expand Down
11 changes: 11 additions & 0 deletions haw/ci/lib/nodes/VarListNode.java
@@ -1,5 +1,8 @@
package haw.ci.lib.nodes;

import haw.ci.lib.SymbolTable;
import haw.ci.lib.descriptor.Descriptor;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -46,6 +49,14 @@ public String toString(int indentation) {
}
return output;
}

public Descriptor compile(SymbolTable symbolTable) {
for (VarNode node : nodes) {
node.compile(symbolTable);
}

return null;
}



Expand Down
4 changes: 2 additions & 2 deletions haw/ci/lib/nodes/VarNode.java
Expand Up @@ -51,10 +51,10 @@ public boolean equals(Object obj) {
public String toString(int indentation) {
String result = toString(indentation, this.getClass().getName() + "\n");
if(identList != null) {
result += identList.toString() + "\n";
result += identList.toString(indentation) + "\n";
}
if(type != null) {
result += type.toString() + "\n";
result += type.toString(indentation) + "\n";
}

return result;
Expand Down
1 change: 1 addition & 0 deletions simple-program.ob
@@ -1,4 +1,5 @@
module foo;
var i, j : integer;
begin
i := 1;
j := 2;
Expand Down

0 comments on commit 0b94f6e

Please sign in to comment.