Skip to content

Commit

Permalink
Merge pull request #3 from Pyro569/1.1.0
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
Pyro569 authored Nov 13, 2023
2 parents 4bd66df + 0fafd81 commit 9b1ff36
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ project-scripts/
testrun.sh
testrundebug.sh
build.sh
Main.cpp
Main.cpp
Main.c
22 changes: 22 additions & 0 deletions New-Compiler/ArgReader.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include Tokenization.dl;
#import dawnlang.io;
#import dawnlang.io.args;

function main(args){
C-Code[
for(int i = 1; i < argc; i++){
if(0 == strcmp(argv[i], "-b")){
printf("Build File\n");
}
if(0 == strcmp(argv[i], "-br")){
printf("Build and Run File\n");
}
if(0 == strcmp(argv[i], "-d")){
printf("Development Debug Mode\n");
}
if(0 == strcmp(argv[i], "-version")){
printf("DawnLang Version 1.1.0\n");
}
}
]-End
}
Binary file added New-Compiler/DawnLang
Binary file not shown.
Empty file added New-Compiler/Tokenization.dl
Empty file.
1 change: 1 addition & 0 deletions New-Compiler/WHAT_IS_THIS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory you are in, is a rewrite of the DawnLang compiler using the DawnLang language. The goal for this compiler is to be FULLY introduced by DawnLang 1.5.0 or earlier, however it will be introduced in sectional parts. For example, in the 1.1.0 release of DawnLang, the parser might be written in DawnLang while the rest is still written in C#, and then the 1.2.0 update might have the debugger written in DawnLang etc.
File renamed without changes.
8 changes: 4 additions & 4 deletions Creation.cs → Old-Compiler/Creation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static void CreateCFile(string FileName)
{
Tokenization.ErrorOpCode = "wc100"; //wc for writing c, 100 for first potential error spot

StreamWriter outputFile = new StreamWriter(FileName + ".cpp");
StreamWriter outputFile = new StreamWriter(FileName + ".c");

//write each converted token to the c file
foreach (string codeLines in Tokenization.ConvertedTokens)
Expand All @@ -25,7 +25,7 @@ public static void CompileCFile(string FileName, string OutputFileName)

Tokenization.ErrorOpCode = "cf200"; //cf for compile file, 200 for second potential error spot

Process.Start("gcc", FileName + ".cpp -w -lstdc++"); //-lstdc++ every time in case if c++ code sections are included
Process.Start("gcc", FileName + ".c -w -lstdc++"); //-lstdc++ every time in case if c++ code sections are included
Thread.Sleep(1500); //small micro sleep for program to not error moving file since it is so new
File.Move("./a.out", "./" + OutputFileName);
}
Expand All @@ -34,8 +34,8 @@ public static void Cleanup(string FileName)
{
Tokenization.ErrorOpCode = "cl100"; //cl for cleanup, 100 for first potential error spot

if (File.Exists("./" + FileName + ".cpp")) //delete the TempFile.c if it still exists (which it still should, if not, error)
File.Delete("./" + FileName + ".cpp");
if (File.Exists("./" + FileName + ".c")) //delete the TempFile.c if it still exists (which it still should, if not, error)
File.Delete("./" + FileName + ".c");
else
System.Environment.Exit(1);
}
Expand Down
File renamed without changes.
File renamed without changes.
30 changes: 27 additions & 3 deletions Tokenization.cs → Old-Compiler/Tokenization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ private static void ConvertTokens()
ConvertedTokens.Add("int " + Tokens[i + 1] + Tokens[i + 2]); //int a = 17;
if (Tokens[i + 3] == "input.int.last")
ConvertedTokens[ConvertedTokens.Count - 1] += "intinput";
if (Tokens[i + 3] == "list.size")
ConvertedTokens[ConvertedTokens.Count - 1] += "arraySize";
else
ConvertedTokens[ConvertedTokens.Count - 1] += Tokens[i + 3];
ConvertedTokens[ConvertedTokens.Count - 1] += ";";
Expand Down Expand Up @@ -290,7 +292,7 @@ private static void ConvertTokens()
switch (Tokens[i + 1])
{
case "dawnlang.io":
ConvertedTokens[ConvertedTokens.Count - 1] += "<stdio.h>\n#include <iostream>";
ConvertedTokens[ConvertedTokens.Count - 1] += "<stdio.h>";
break;
case "dawnlang.data.types":
ConvertedTokens[ConvertedTokens.Count - 1] += "<stdbool.h>";
Expand Down Expand Up @@ -350,6 +352,19 @@ private static void ConvertTokens()
for (int l = 0; l < TokensToRemove.Count; l++)
Tokens.Remove(Tokens[l]);
break;
case "list.size":
if (!ConvertedTokens.Contains("int arraySize"))
ConvertedTokens.Add("int");
ConvertedTokens[ConvertedTokens.Count - 1] += " arraySize = sizeof(";
ConvertedTokens[ConvertedTokens.Count - 1] += Tokens[i + 1] + ")/4;";
break;
case "list.element.add":
if (!ConvertedTokens.Contains("int arraySize"))
ConvertedTokens.Add("int");
ConvertedTokens[ConvertedTokens.Count - 1] += " arraySize = sizeof(";
ConvertedTokens[ConvertedTokens.Count - 1] += Tokens[i + 1] + ")/4;";
ConvertedTokens.Add(Tokens[i + 1] + "[arraySize] = " + Tokens[i + 3] + ";");
break;
case "print.list.element":
if (IntListNames.Contains(Tokens[i + 1]))
ConvertedTokens.Add("printf(\"%d\\n\", " + Tokens[i + 1] + "[" + Tokens[i + 3] + "]);");
Expand Down Expand Up @@ -453,7 +468,7 @@ private static void ConvertTokens()
if (Tokens[k] == "]" && Tokens[k + 1] == "-" && Tokens[k + 2] == "End")
break;
else
Tokens.Remove(Tokens[k]);
RemoveToken(new List<int> { k });
break;
case "return":
ConvertedTokens.Add("return ");
Expand Down Expand Up @@ -497,7 +512,7 @@ private static void ConvertTokens()
//change the value of an int variable
if (IntVars.Contains(Tokens[i]) && Tokens[i - 1] != "int" && Tokens[i + 1] == "=")
{
if (Tokens[i + 2] != "=" && Tokens[i + 2] != "<" && Tokens[i + 2] != ">")
if (Tokens[i + 2] != "=" && Tokens[i + 2] != "<" && Tokens[i + 2] != ">" && Tokens[i + 2] != "list.size")
ConvertedTokens.Add(Tokens[i] + " " + Tokens[i + 1] + " " + Tokens[i + 2] + ";");
}
else if (IntVars.Contains(Tokens[i]) && Tokens[i - 1] != "int" && Tokens[i + 1] == "+" && Tokens[i + 2] == "=")
Expand All @@ -510,6 +525,15 @@ private static void ConvertTokens()
ConvertedTokens.Add(Tokens[i] + " = intinput;");
RemoveToken(new List<int> { i, i + 1, i + 2 });
}
else if (IntVars.Contains(Tokens[i]) && Tokens[i + 2] == "list.size")
{
if (!ConvertedTokens.Contains("int arraySize"))
ConvertedTokens.Insert(ConvertedTokens.Count - 1, "int");
ConvertedTokens[ConvertedTokens.Count - 2] += " arraySize = sizeof(";
ConvertedTokens[ConvertedTokens.Count - 2] += Tokens[i + 3] + ")/4;";
ConvertedTokens.Add(Tokens[i] + " = arraySize;");
RemoveToken(new List<int> { i, i + 1, i + 2 });
}
else if (StringVars.Contains(Tokens[i]) && Tokens[i + 2] == "input.str.last")
{
ConvertedTokens.Add(Tokens[i] + " " + Tokens[i + 1] + " strinput;");
Expand Down
7 changes: 7 additions & 0 deletions Old-Compiler/testfile.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include print_number_function.dl;

function main(){
int twelve = 12;
//call the print_number function from the print_number_function.dl file
print_number(twelve);
}
13 changes: 0 additions & 13 deletions testfile.dl

This file was deleted.

0 comments on commit 9b1ff36

Please sign in to comment.