Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Bug Fixes / Improvements
Browse files Browse the repository at this point in the history
I am too tired to write an explanation.
  • Loading branch information
GitHababi committed Sep 10, 2021
1 parent 49c6031 commit fe984be
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 54 deletions.
Binary file modified .vs/C-Double-Flat/v16/.suo
Binary file not shown.
4 changes: 4 additions & 0 deletions C-Double-Flat/Core/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public static void ConsoleWrite<T>(this List<T> first)
{
first.ForEach(item => Console.WriteLine(item));
}
public static void ConsoleWrite<T>(this T[] first)
{
foreach (T item in first)Console.WriteLine(item);
}
public static bool MatchesList<T>(this T first, List<T> second)
{
foreach (T item in second) if (first.Equals(item)) return true;
Expand Down
2 changes: 1 addition & 1 deletion C-Double-Flat/Core/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Value Run(List<Value> Inputs)
List<Statement> arguments = new List<Statement>();
for (int i = 0; i < args.Count; i++)
{
ASSIGN a = new ASSIGN();
AssignStatement a = new AssignStatement();
a.Identifier = args[i];
a.IsAsName = false;
a.Value = (i >= Inputs.Count) ? ExpressionNode.None : new ExpressionNode(ValueHelper.ValueToToken(Inputs[i]));
Expand Down
1 change: 1 addition & 0 deletions C-Double-Flat/Core/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ private Token StringLiteralFinder()
'n' => '\n',
't' => '\t',
'"' => '"',
'^' => '^',
_ => (string)"^" + _currentChar.ToString(),
};
Advance();
Expand Down
1 change: 0 additions & 1 deletion C-Double-Flat/Core/Parser/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ private ExpressionNode ParseTerm()

if (tokens.Count > index + 1)
{
Console.WriteLine(tokens[index + 1].Type);
if (tokens[index + 1].Type == TokenType.INSRT)
{
FunctionCallNode funccall = new(new Token(TokenType.ASNAME, current));
Expand Down
42 changes: 21 additions & 21 deletions C-Double-Flat/Core/Parser/StatementParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private List<Statement> Private_Parse()
// Removes all no op statements

output1.RemoveAll(a => {
return a.GetType() == typeof(NONE);
return a.GetType() == typeof(NoOperationStatement);
});
return output1;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ private Statement ParseStatement()
return ParseAsName();
case TokenType.NXTLN:
index++;
return new NONE(); // No-op
return new NoOperationStatement(); // No-op
case TokenType.RETURN:
return ParseReturn();
case TokenType.IF:
Expand All @@ -120,7 +120,7 @@ private Statement ParseStatement()
return ParseRepeat();
default:
index++;
return new NONE();
return new NoOperationStatement();
}
}

Expand All @@ -132,7 +132,7 @@ private Statement ParseAsName()
{
if (TokenHelper.Contains(tokens.ToArray().Skip(index).Take(endpoint - index).ToList(), TokenType.LCURLY))
{
FUNCTION output1 = new();
FunctionStatement output1 = new();
output1.IsAsName = true;

List<Token> assigner1 = TokenHelper.Split(tokens.ToArray().Skip(index).ToList(), TokenType.ASSGN)[0];
Expand Down Expand Up @@ -180,7 +180,7 @@ private Statement ParseAsName()
return output1;

}
ASSIGN output = new();
AssignStatement output = new();
output.IsAsName = true;

List<Token> assigner = TokenHelper.Split(tokens.ToArray().Skip(index).ToList(), TokenType.ASSGN)[0];
Expand All @@ -203,9 +203,9 @@ private Statement ParseAsName()
return ParseExpressionStatement();
}

private REPEAT ParseRepeat()
private RepeatStatement ParseRepeat()
{
REPEAT output = new();
RepeatStatement output = new();

index += 1;
Expect(TokenType.LPAREN);
Expand All @@ -227,9 +227,9 @@ private REPEAT ParseRepeat()
return output;
}

private RUN ParseRun()
private RunStatement ParseRun()
{
RUN output = new RUN();
RunStatement output = new RunStatement();

index += 1; //moving one over because we just skipped past a return token.

Expand All @@ -245,9 +245,9 @@ private RUN ParseRun()
return output;
}

private LOOP ParseLoop()
private LoopStatement ParseLoop()
{
LOOP output = new();
LoopStatement output = new();

index++;
Expect(TokenType.LPAREN);
Expand All @@ -270,9 +270,9 @@ private LOOP ParseLoop()
return output;
}

private IF ParseIf()
private IfStatement ParseIf()
{
IF output = new IF();
IfStatement output = new IfStatement();
index++;
Expect(TokenType.LPAREN);
List<Token> inParenthesis = TokenHelper.GetFromParenthesis(tokens.Skip(index).ToList());
Expand Down Expand Up @@ -315,9 +315,9 @@ private IF ParseIf()
return output;
}

private RETURN ParseReturn()
private ReturnStatement ParseReturn()
{
RETURN output = new RETURN();
ReturnStatement output = new ReturnStatement();

index += 1; //moving one over because we just skipped past a return token.

Expand All @@ -333,10 +333,10 @@ private RETURN ParseReturn()
return output;
}

private ASSIGN ParseAssignment()
private AssignStatement ParseAssignment()
{

ASSIGN output = new ASSIGN();
AssignStatement output = new AssignStatement();

output.Identifier = currentToken;

Expand All @@ -354,9 +354,9 @@ private ASSIGN ParseAssignment()
return output;
}

private EXPRESSION ParseExpressionStatement()
private ExpressionStatement ParseExpressionStatement()
{
EXPRESSION output = new EXPRESSION();
ExpressionStatement output = new ExpressionStatement();

int endpoint = NextStatementEnding();

Expand All @@ -367,9 +367,9 @@ private EXPRESSION ParseExpressionStatement()
return output;
}

private FUNCTION ParseFunctionAssignment()
private FunctionStatement ParseFunctionAssignment()
{
FUNCTION output = new FUNCTION();
FunctionStatement output = new FunctionStatement();

output.Identifier = currentToken; // Assign name to the function Node

Expand Down
34 changes: 17 additions & 17 deletions C-Double-Flat/Core/Runtime/Interpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static Value Interpret(List<Statement> Statements, ref Dictionary<string
Returned = interpreter.Didreturned;
scope = interpreter.scopedVars;
return output;

}

private readonly List<Statement> statements = new();
Expand All @@ -56,36 +56,36 @@ private Value Private_Interpret()
for (int i = 0; i < statements.Count; i++)
{
index = i;
if (statements[index].GetType() == typeof(ASSIGN)) AssignVar();
else if (statements[index].GetType() == typeof(EXPRESSION)) RunExpression();
else if (statements[index].GetType() == typeof(FUNCTION)) { AssignFunction(); }
else if (statements[index].GetType() == typeof(RETURN)) { return Return(); }
else if (statements[index].GetType() == typeof(IF))
if (statements[index].GetType() == typeof(AssignStatement)) AssignVar();
else if (statements[index].GetType() == typeof(ExpressionStatement)) RunExpression();
else if (statements[index].GetType() == typeof(FunctionStatement)) { AssignFunction(); }
else if (statements[index].GetType() == typeof(ReturnStatement)) { return Return(); }
else if (statements[index].GetType() == typeof(IfStatement))
{
Value output = IfStatement(out bool didReturn);
if (didReturn)
{
return output;
}
}
else if (statements[index].GetType() == typeof(LOOP))
else if (statements[index].GetType() == typeof(LoopStatement))
{
Value output = LoopStatement(out bool didReturn);
if (didReturn) { return output; }
}
else if (statements[index].GetType() == typeof(REPEAT))
else if (statements[index].GetType() == typeof(RepeatStatement))
{
Value output = RepeatStatement(out bool didReturn);
if (didReturn) return output;
}
else if (statements[index].GetType() == typeof(RUN)) RunRun();
else if (statements[index].GetType() == typeof(RunStatement)) RunRun();
}
return Value.Default;
}

private void RunRun()
{
RUN runningstatement = (RUN)statements[index];
RunStatement runningstatement = (RunStatement)statements[index];
string incomplete_path = InterpretExpression(runningstatement.Path).CastValue(ValueType.STRING).Data;

string fullstring = "";
Expand All @@ -102,7 +102,7 @@ private void RunRun()

private void AssignVar()
{
ASSIGN assigner = (ASSIGN)statements[index];
AssignStatement assigner = (AssignStatement)statements[index];
string name;

if (assigner.IsAsName)
Expand Down Expand Up @@ -140,13 +140,13 @@ private void AssignVar()

private void RunExpression()
{
EXPRESSION expression = (EXPRESSION)statements[index];
ExpressionStatement expression = (ExpressionStatement)statements[index];
InterpretExpression(expression.Value);
}

private void AssignFunction()
{
FUNCTION func = (FUNCTION)statements[index];
FunctionStatement func = (FunctionStatement)statements[index];

string id;
if (func.IsAsName)
Expand All @@ -166,7 +166,7 @@ private void AssignFunction()

private Value Return()
{
RETURN expression = (RETURN)statements[index];
ReturnStatement expression = (ReturnStatement)statements[index];

Didreturned = true;

Expand All @@ -175,7 +175,7 @@ private Value Return()

private Value RepeatStatement(out bool didReturn)
{
REPEAT statement = (REPEAT)statements[index];
RepeatStatement statement = (RepeatStatement)statements[index];

Value output = Value.Default;
didReturn = false;
Expand All @@ -192,7 +192,7 @@ private Value RepeatStatement(out bool didReturn)

private Value IfStatement(out bool didReturn)
{
IF statement = (IF)statements[index];
IfStatement statement = (IfStatement)statements[index];



Expand All @@ -208,7 +208,7 @@ private Value IfStatement(out bool didReturn)

private Value LoopStatement(out bool didReturn)
{
LOOP statement = (LOOP)statements[index];
LoopStatement statement = (LoopStatement)statements[index];

Value output = Value.Default;
didReturn = false;
Expand Down
18 changes: 16 additions & 2 deletions C-Double-Flat/Core/Standard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ class Standard
{ "disp_echo", new Display_Echo() },
{ "disp_prompt", new Display_Prompt() },
{ "disp_clear", new Display_Clear() },

// The following two lines are debug functions, they can be disabled by being commented out.

{ "dbug_vars", new Debug_Vars() },
// Uncomment these two lines to enable debug functions.
{ "dbug_parse", new Debug_Parse() },

{ "math_abs", new Math_Abs() },
{ "math_round", new Math_Round() },
{ "math_rand", new Math_Rand() },
Expand Down Expand Up @@ -444,7 +447,7 @@ string IFunction.Description()
Value IFunction.Run(List<Value> Inputs)
{
if (Inputs.Count < 1) throw new ArgumentCountException(1, "string_length");
return new Value(Inputs[0].Data.Length.ToString());
return new Value(Inputs[0].Data.Length);
}
}
class String_Split : IFunction
Expand All @@ -458,6 +461,17 @@ Value IFunction.Run(List<Value> Inputs)
{
if (Inputs.Count < 3) throw new ArgumentCountException(3, "string_split");
string[] split = ((string)Inputs[0]).Split((string)Inputs[1]);


if ((string)Inputs[1] == "") //if split by '' then divide each char.
{
char[] temp = ((string)Inputs[0]).ToCharArray();
split = new string[temp.Length];
for (int i = 0; i < temp.Length; i++)
{
split[i] = temp[i].ToString();
}
}
try
{
return new (split[(int)Inputs[2]]);
Expand Down
Loading

0 comments on commit fe984be

Please sign in to comment.