Skip to content

Commit

Permalink
Merge pull request #118 from redferret/dev
Browse files Browse the repository at this point in the history
New Language Implementation
  • Loading branch information
redferret authored Feb 24, 2021
2 parents ab0444a + 3679c18 commit c001d10
Show file tree
Hide file tree
Showing 16 changed files with 499 additions and 432 deletions.
396 changes: 200 additions & 196 deletions RowdyGrammar

Large diffs are not rendered by default.

Binary file modified bin/RowdyLib.jar
Binary file not shown.
1 change: 1 addition & 0 deletions bin/rowdy/core
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ native func equalsIgnoreCase(str1, str2)
native func strcmp(str1, str2)
native func contains(str, substring)
native func slice(str1, from, to)
native func getChar(str, index)

native func DecimalFormat(pattern)
native func format(str, formatter)
Expand Down
13 changes: 13 additions & 0 deletions bin/rowdy/fileReader
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ public class FileReader {
}
}

func asString() {
lines = ""
while true {
line = $readLine(this.reader)
if (line == null) {
break
} else {
lines = concat lines, line, "\n"
}
}
return lines
}

func nextLine() {
this.line = $readLine(this.reader)
return this.line
Expand Down
11 changes: 3 additions & 8 deletions src/rowdy/Rowdy.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void run() {
rowdyInstance.initialize(mainProgram);
rowdyInstance.optimizeProgram(mainProgram);
rowdyInstance.execute(programParameters);
} catch (ConstantReassignmentException | MainNotFoundException e) {
} catch (Throwable e) {
rowdyInstance.handleException(e, verbose);
}
} else {
Expand All @@ -117,9 +117,7 @@ public void run() {
}
});
linker.loadJarLibs("bin/");
} catch (AmbiguousGrammarException | ParseException | SyntaxException
| IOException | ClassNotFoundException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException | URISyntaxException ex) {
} catch (Throwable ex) {
rowdyInstance.handleException(ex, verbose);
}

Expand Down Expand Up @@ -158,10 +156,7 @@ public void run() {
linker.loadImport(importPath);
linker.loadJarLibs("bin/");
}
} catch (AmbiguousGrammarException | ParseException | SyntaxException
| IOException | ClassNotFoundException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException
| URISyntaxException | ConstantReassignmentException e) {
} catch (Throwable e) {
rowdyInstance.handleException(e, verbose);
}
} while (true);
Expand Down
2 changes: 2 additions & 0 deletions src/rowdy/RowdyInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ public void executeStmt(BaseNode parent, BaseNode seqControl) throws ConstantRea
if (importConstant != null) {
nextImport = ((Terminal) importConstant.symbol()).getValue().replaceAll("\\.", "/").replaceAll("\"", "");
}
case THROW_STMT:
((ThrowStatement) currentNode).execute();
default:
if (seqControl != null) {
if (seqControl.isSeqActive()) {
Expand Down
14 changes: 14 additions & 0 deletions src/rowdy/exceptions/ThrownException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

package rowdy.exceptions;

/**
*
* @author Richard
*/
public class ThrownException extends RuntimeException {

public ThrownException(String message) {
super(message);
}

}
Binary file modified src/rowdy/lang/Rowdy.gr
Binary file not shown.
226 changes: 114 additions & 112 deletions src/rowdy/lang/RowdyGrammarConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,34 @@ public class RowdyGrammarConstants {
CAST_BOL = 42,
CAST_DBL = 43,
AS = 44,
CONCAT = 45,
FUNC = 46,
CALL = 47,
RETURN = 48,
ISSET = 49,
ROUND = 50,
LCURLY = 51,
RCURLY = 52,
CONST = 53,
GLOBAL = 54,
NATIVE = 55,
DYNAMIC = 56,
STATIC = 57,
IMPORT = 58,
SUPER = 59,
THIS = 60,
PUBLIC = 61,
PRIVATE = 62,
CLASS = 63,
INHERITS = 64,
CONSTRUCTOR = 65,
IS = 66,
TEMP = 67,
NEW = 68,
DOT = 69,
AT = 70,
QUESTION = 71,
THROW = 45,
CONCAT = 46,
FUNC = 47,
CALL = 48,
RETURN = 49,
ISSET = 50,
ROUND = 51,
LCURLY = 52,
RCURLY = 53,
CONST = 54,
GLOBAL = 55,
NATIVE = 56,
DYNAMIC = 57,
STATIC = 58,
IMPORT = 59,
SUPER = 60,
THIS = 61,
PUBLIC = 62,
PRIVATE = 63,
CLASS = 64,
INHERITS = 65,
CONSTRUCTOR = 66,
IS = 67,
TEMP = 68,
NEW = 69,
DOT = 70,
AT = 71,
QUESTION = 72,
PROGRAM = 1000,
IMPORTS = 1001,
SINGLE_IMPORT = 1002,
Expand Down Expand Up @@ -101,89 +102,90 @@ public class RowdyGrammarConstants {
PRINT_STMT = 1025,
READ_STMT = 1026,
RETURN_STMT = 1027,
FUNC_OPTS = 1028,
NATIVE_FUNC_OPT = 1029,
DYNAMIC_OPT = 1030,
STATIC_OPT = 1031,
FUNC_CALL = 1032,
FUNC_CALL_TAIL = 1033,
ARRAY_PART = 1034,
FUNC_PARAMS = 1035,
FUNCTION_BODY = 1036,
PRIVATE_SCOPE = 1037,
FUNCTION = 1038,
ANONYMOUS_FUNC = 1039,
PARAMETERS = 1040,
PARAMS_TAIL = 1041,
ARRAY_ACCESS = 1042,
ARRAY_EXPR = 1043,
ARRAY_BODY = 1044,
MAP_EXPR = 1045,
MAP_BODY = 1046,
MAP_ELEMENT = 1047,
CLASS_DEF = 1048,
OBJECT_PRIVATE = 1049,
OBJECT_PUBLIC = 1050,
CONSTRUCTOR_METHOD = 1051,
SUPER_CONSTRUCTOR = 1052,
CLASS_BODY = 1053,
PUBLIC_MEMBERS = 1054,
PRIVATE_MEMBERS = 1055,
CLASS_DEFS = 1056,
INHERIT_OPT = 1057,
DOT_ATOMIC = 1058,
REF_ACCESS = 1059,
THIS_ = 1060,
ID_ = 1061,
NEW_OBJ = 1062,
OBJ_OR_ARRAY = 1063,
EXPRESSION = 1064,
EXPRESSIONS = 1065,
INCREMENT_EXPR = 1066,
DECREMENT_EXPR = 1067,
EXPR_LIST = 1068,
CAST_AS = 1069,
CAST_OPT = 1070,
CAST_DBL_OPT = 1071,
CAST_STR_OPT = 1072,
CAST_BINT_OPT = 1073,
CAST_INT_OPT = 1074,
CAST_BOL_OPT = 1075,
CAST_BYT_OPT = 1076,
CAST_SHRT_OPT = 1077,
CAST_LNG_OPT = 1078,
NULL_DEFAULT = 1079,
BOOL_EXPR = 1080,
ROUND_EXPR = 1081,
CONCAT_EXPR = 1082,
ISSET_EXPR = 1083,
BOOL_TERM = 1084,
BOOL_TERM_TAIL = 1085,
BOOL_FACTOR = 1086,
BOOL_FACTOR_TAIL = 1087,
ARITHM_EXPR = 1088,
RELATION_OPTION = 1089,
ARITHM_LESS = 1090,
ARITHM_LESSEQUAL = 1091,
ARITHM_GREATEREQUAL = 1092,
ARITHM_GREATER = 1093,
ARITHM_EQUAL = 1094,
ARITHM_NOTEQUAL = 1095,
TERM = 1096,
TERM_TAIL = 1097,
TERM_PLUS = 1098,
TERM_MINUS = 1099,
FACTOR = 1100,
FACTOR_MINUS = 1101,
FACTOR_TAIL = 1102,
FACTOR_TAIL_MUL = 1103,
FACTOR_TAIL_DIV = 1104,
FACTOR_TAIL_MOD = 1105,
FACTOR_TAIL_POW = 1106,
PAREN_EXPR = 1107,
ATOMIC = 1108,
ATOMIC_ID = 1109,
POST_INC_DEC = 1110,
ATOMIC_CONST = 1111,
ATOMIC_FUNC_CALL = 1112;
THROW_STMT = 1028,
FUNC_OPTS = 1029,
NATIVE_FUNC_OPT = 1030,
DYNAMIC_OPT = 1031,
STATIC_OPT = 1032,
FUNC_CALL = 1033,
FUNC_CALL_TAIL = 1034,
ARRAY_PART = 1035,
FUNC_PARAMS = 1036,
FUNCTION_BODY = 1037,
PRIVATE_SCOPE = 1038,
FUNCTION = 1039,
ANONYMOUS_FUNC = 1040,
PARAMETERS = 1041,
PARAMS_TAIL = 1042,
ARRAY_ACCESS = 1043,
ARRAY_EXPR = 1044,
ARRAY_BODY = 1045,
MAP_EXPR = 1046,
MAP_BODY = 1047,
MAP_ELEMENT = 1048,
CLASS_DEF = 1049,
OBJECT_PRIVATE = 1050,
OBJECT_PUBLIC = 1051,
CONSTRUCTOR_METHOD = 1052,
SUPER_CONSTRUCTOR = 1053,
CLASS_BODY = 1054,
PUBLIC_MEMBERS = 1055,
PRIVATE_MEMBERS = 1056,
CLASS_DEFS = 1057,
INHERIT_OPT = 1058,
DOT_ATOMIC = 1059,
REF_ACCESS = 1060,
THIS_ = 1061,
ID_ = 1062,
NEW_OBJ = 1063,
OBJ_OR_ARRAY = 1064,
EXPRESSION = 1065,
EXPRESSIONS = 1066,
INCREMENT_EXPR = 1067,
DECREMENT_EXPR = 1068,
EXPR_LIST = 1069,
CAST_AS = 1070,
CAST_OPT = 1071,
CAST_DBL_OPT = 1072,
CAST_STR_OPT = 1073,
CAST_BINT_OPT = 1074,
CAST_INT_OPT = 1075,
CAST_BOL_OPT = 1076,
CAST_BYT_OPT = 1077,
CAST_SHRT_OPT = 1078,
CAST_LNG_OPT = 1079,
NULL_DEFAULT = 1080,
BOOL_EXPR = 1081,
ROUND_EXPR = 1082,
CONCAT_EXPR = 1083,
ISSET_EXPR = 1084,
BOOL_TERM = 1085,
BOOL_TERM_TAIL = 1086,
BOOL_FACTOR = 1087,
BOOL_FACTOR_TAIL = 1088,
ARITHM_EXPR = 1089,
RELATION_OPTION = 1090,
ARITHM_LESS = 1091,
ARITHM_LESSEQUAL = 1092,
ARITHM_GREATEREQUAL = 1093,
ARITHM_GREATER = 1094,
ARITHM_EQUAL = 1095,
ARITHM_NOTEQUAL = 1096,
TERM = 1097,
TERM_TAIL = 1098,
TERM_PLUS = 1099,
TERM_MINUS = 1100,
FACTOR = 1101,
FACTOR_MINUS = 1102,
FACTOR_TAIL = 1103,
FACTOR_TAIL_MUL = 1104,
FACTOR_TAIL_DIV = 1105,
FACTOR_TAIL_MOD = 1106,
FACTOR_TAIL_POW = 1107,
PAREN_EXPR = 1108,
ATOMIC = 1109,
ATOMIC_ID = 1110,
POST_INC_DEC = 1111,
ATOMIC_CONST = 1112,
ATOMIC_FUNC_CALL = 1113;
}
4 changes: 4 additions & 0 deletions src/rowdy/nodes/RowdyNodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public BaseNode getNode(Symbol symbol, int line) {
LoopStatement lpstmt = new LoopStatement(symbol, line);
lpstmt.setAsNonCompressable();
return lpstmt;
case THROW_STMT:
ThrowStatement throwstmt = new ThrowStatement(symbol, line);
throwstmt.setAsNonCompressable();
return throwstmt;
case WHILE_LOOP:
WhileLoop whileLoop = new WhileLoop(symbol, line);
whileLoop.setAsNonCompressable();
Expand Down
2 changes: 1 addition & 1 deletion src/rowdy/nodes/statement/AssignStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import growdy.Symbol;
import rowdy.BaseNode;
import rowdy.Calculator;
import static rowdy.RowdyInstance.ATOMIC_GET;
import rowdy.Value;
import rowdy.nodes.RowdyNode;
import rowdy.exceptions.ConstantReassignmentException;
Expand All @@ -15,6 +14,7 @@
import static rowdy.lang.RowdyGrammarConstants.GLOBAL_DEF;
import static rowdy.lang.RowdyGrammarConstants.ID_MODIFIER;
import static rowdy.lang.RowdyGrammarConstants.ID;
import static rowdy.RowdyInstance.ATOMIC_GET;
import static rowdy.RowdyInstance.ATOMIC_SET;
import static rowdy.lang.RowdyGrammarConstants.COMP_ADD_;
import static rowdy.lang.RowdyGrammarConstants.COMP_DIV_;
Expand Down
9 changes: 8 additions & 1 deletion src/rowdy/nodes/statement/LoopStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import rowdy.Function;
import rowdy.Value;
import rowdy.exceptions.ConstantReassignmentException;
import static rowdy.lang.RowdyGrammarConstants.ATOMIC_ID;
import static rowdy.lang.RowdyGrammarConstants.ID;
import static rowdy.lang.RowdyGrammarConstants.STMT_LIST;

Expand All @@ -27,7 +28,13 @@ public Object execute(Object leftValue) {
Function curFunction = instance.callStack.peek();
Value curValue = curFunction.getSymbolTable().getValue(idName);
if (curValue == null) {
curFunction.getSymbolTable().allocate(idName, new Value(0, false), this.getLine(), false);
BaseNode presetValueNode = get(ATOMIC_ID);
if (presetValueNode != null) {
Value v = (Value) presetValueNode.execute();
curFunction.getSymbolTable().allocate(idName, v, this.getLine(), false);
} else {
curFunction.getSymbolTable().allocate(idName, new Value(0, false), this.getLine(), false);
}
} else {
throw new RuntimeException("ID '" + idName + "' already in use "
+ "on line " + getLine());
Expand Down
2 changes: 0 additions & 2 deletions src/rowdy/nodes/statement/ReadStatement.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

package rowdy.nodes.statement;

import growdy.Node;
import growdy.Symbol;
import growdy.Terminal;
import java.io.InputStream;
import java.util.Scanner;
import rowdy.BaseNode;
import rowdy.Value;
import rowdy.exceptions.ConstantReassignmentException;
import rowdy.nodes.RowdyNode;
import static rowdy.lang.RowdyGrammarConstants.ID;
import static rowdy.lang.RowdyGrammarConstants.PARAMS_TAIL;

Expand Down
Loading

0 comments on commit c001d10

Please sign in to comment.