Skip to content

Commit

Permalink
NEM PRA DAR PUSH NO CÓDIGO EU SIRVO
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanchilger committed May 18, 2019
2 parents c9ec6dc + 7f64057 commit e7bdb58
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Compiled class file
*.class
**.class
**.Tester.java
# Log file
*.log
Expand Down
8 changes: 8 additions & 0 deletions examples/ex_entrai.fau
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
olokinho a = 0;
olokinho b = 0;
mostrai("digite-o-primeiro-valor");
entrai(a);
churrasqueira(b < a) {
mostrailn(a);
a = a - 1;
}
4 changes: 2 additions & 2 deletions examples/ex_if.fau
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
? asd

olokinho a = 5; ? merda1
olokinho b = 8;
olokinho b = 8;
olokinho c = 9;

eagora (a == 1+1+1+1+1) { ? soma doidona
Expand All @@ -22,4 +22,4 @@ eagora (a == 1+1+1+1+1) { ? soma doidona
mostrailn("hello_world3");
}

? cabô oporra
? cabô oporra
1 change: 1 addition & 0 deletions src/ex_123.fau
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mostrailn("hello world");
29 changes: 28 additions & 1 deletion src/faustop/core/lib/StandardLibrary.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package faustop.core.lib;
import faustop.core.main.util.Memory;
import faustop.core.main.util.Node;
import java.util.ArrayList;
import java.util.Scanner;

/*
* StandardLibrary class defines the Faustop native methods.
Expand All @@ -9,9 +13,32 @@ public class StandardLibrary {
public static final void mostrai(String pValue) {
System.out.print(pValue);
}

public static final void mostrailn(String pValue) {
System.out.println(pValue);
}

public static final void entrai(ArrayList<Node> children) {

Scanner input = new Scanner(System.in);
Node exp = children.get(1);
String varName = exp.children().get(1).key().getName();
String newValue;
newValue = input.nextLine();

if (Memory.intMap.containsKey(varName)) {
Memory.intMap.get(varName).setValue(newValue);

} else if (Memory.doubleMap.containsKey(varName)) {
Memory.doubleMap.get(varName).setValue(newValue);

} else if (Memory.stringMap.containsKey(varName)) {
Memory.stringMap.get(varName).setValue(newValue);

} else {
System.out.println("Variable `"+varName+"` not defined");
}

}

}
26 changes: 15 additions & 11 deletions src/faustop/core/main/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ public void run(Node pTreeRoot) {
if (pTreeRoot == null) return;
///////////// BUG TODO : THIS CODE IS SHITTY
for (Node child : pTreeRoot.children()) {
// System.out.println(child.key().getName());

if (child.key().getName().equals("keywordtype")) {
this.newVariable(child);

} else if (child.key().getName().equals("keywordbuiltin")) {
this.handleBuiltIn(child);
this.handleBuiltIn(child);

} else if (child.key().getName().equals("keywordflowcontroller")) {
if (child.children().get(0).key().getName().equals("eagora")) {
Expand Down Expand Up @@ -54,17 +53,21 @@ public void run(Node pTreeRoot) {

private void handleBuiltIn(Node pParent) {

String value;
String command = pParent.children().get(0).key().getName();
Node exp = pParent.children().get(1);
if(command.equals("mostrai") || command.equals("mostrailn")) {
String value;
Node exp = pParent.children().get(1);

if (command.equals("mostrai")) {
value = ExpressionParser.eval(exp.children());
StandardLibrary.mostrai(value);
if (command.equals("mostrai")) {
value = ExpressionParser.eval(exp.children());
StandardLibrary.mostrai(value);

} else if (command.equals("mostrailn")) {
value = ExpressionParser.eval(exp.children());
StandardLibrary.mostrailn(value);
} else if (command.equals("mostrailn")) {
value = ExpressionParser.eval(exp.children());
StandardLibrary.mostrailn(value);
}
} else {
StandardLibrary.entrai(pParent.children());
}
}

Expand Down Expand Up @@ -104,7 +107,6 @@ private void newVariable(Node pParent) {
}

private void changeVariable(Node pParent) {
// System.out.println("CUCUCUC");
Token tok = pParent.children().get(0).key();
String varName = tok.getName();
String newValue = ExpressionParser.eval(pParent.children().get(2).children());
Expand All @@ -117,6 +119,8 @@ private void changeVariable(Node pParent) {

} else if (Memory.intMap.containsKey(varName)) {
Memory.intMap.get(varName).setValue(newValue);
} else {
System.out.println("Variable `"+varName+"` not defined");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/faustop/core/main/Wrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public static void main(String[] args) {

while (token != null) {
parser.addToken(token); // adds the token into the token list
//System.out.println("Name: "+token.getName()+" type: "+token.getType());
// System.out.println("Name: "+token.getName()+" type: "+token.getType());
token = lexer.getNextToken();
}

parser.buildParseTree(); //build the parse tree based on the token list

parseTree = parser.getParseTree(); //get the parseTree
interpreter.run(parseTree.root());
// parseTree.traverse(parseTree.root());
Expand Down
1 change: 0 additions & 1 deletion src/faustop/core/main/util/OperatorParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,4 @@ public static void buildBoolean() {
OperatorParser.BOOLEAN.put("!=", dif);
}


}
7 changes: 5 additions & 2 deletions src/faustop/core/vars/String_.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ public String lessThan(String pObj) {
}

public String equal(String pObj) {
System.out.println("String class"+pObj);
Boolean ans = this.getValue().equals(pObj);
System.out.println("String class"+ans);
return Boolean.toString(ans);
}

public String greaterThanOrEqualTo(String pObj) {
Boolean ans = this.greaterThan(pObj).equals("true") || this.equal(pObj).equals("true");
return Boolean.toString(ans);
Boolean ans1 = this.greaterThan(pObj).equals("true");
Boolean ans2 = this.equal(pObj).equals("true");
return Boolean.toString(ans1 || ans2);
}

public String lessThanOrEqualTo(String pObj) {
Expand Down
3 changes: 3 additions & 0 deletions src/sources
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
./faustop/core/main/util/Symbols.java
./faustop/core/main/util/OperatorParser.java
./faustop/core/main/util/Memory.java
./faustop/core/main/util/Tree.java
./faustop/core/main/util/If.java
./faustop/core/main/util/While.java
./faustop/core/main/util/If.java
./faustop/core/main/util/Node.java
./faustop/core/main/Interpreter.java
./faustop/core/main/Lexer.java
./faustop/core/main/Parser.java
./faustop/core/main/Wrapper.java
./faustop/core/test/Nain.java

0 comments on commit e7bdb58

Please sign in to comment.