diff --git a/.gitignore b/.gitignore
index 09dd1da..78f9d84 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
venv/*
+Compiler/bin/*
+Compiler/obj/*
+.idea/*
diff --git a/.idea/.idea.lpc.dir/.idea/.idea.lpc.dir.iml b/.idea/.idea.lpc.dir/.idea/.idea.lpc.dir.iml
new file mode 100644
index 0000000..e6bc2ca
--- /dev/null
+++ b/.idea/.idea.lpc.dir/.idea/.idea.lpc.dir.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.lpc.dir/riderModule.iml b/.idea/.idea.lpc.dir/riderModule.iml
new file mode 100644
index 0000000..1a4e0d9
--- /dev/null
+++ b/.idea/.idea.lpc.dir/riderModule.iml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/lpc.iml b/.idea/lpc.iml
new file mode 100644
index 0000000..593064c
--- /dev/null
+++ b/.idea/lpc.iml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Compiler/.idea/.idea.Compiler/.idea/.idea.Compiler.iml b/Compiler/.idea/.idea.Compiler/.idea/.idea.Compiler.iml
new file mode 100644
index 0000000..e6bc2ca
--- /dev/null
+++ b/Compiler/.idea/.idea.Compiler/.idea/.idea.Compiler.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Compiler/.idea/.idea.Compiler/.idea/contentModel.xml b/Compiler/.idea/.idea.Compiler/.idea/contentModel.xml
new file mode 100644
index 0000000..0f74968
--- /dev/null
+++ b/Compiler/.idea/.idea.Compiler/.idea/contentModel.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Compiler/.idea/.idea.Compiler/.idea/indexLayout.xml b/Compiler/.idea/.idea.Compiler/.idea/indexLayout.xml
new file mode 100644
index 0000000..27ba142
--- /dev/null
+++ b/Compiler/.idea/.idea.Compiler/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Compiler/.idea/.idea.Compiler/.idea/misc.xml b/Compiler/.idea/.idea.Compiler/.idea/misc.xml
new file mode 100644
index 0000000..28a804d
--- /dev/null
+++ b/Compiler/.idea/.idea.Compiler/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Compiler/.idea/.idea.Compiler/.idea/modules.xml b/Compiler/.idea/.idea.Compiler/.idea/modules.xml
new file mode 100644
index 0000000..fc752e6
--- /dev/null
+++ b/Compiler/.idea/.idea.Compiler/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Compiler/.idea/.idea.Compiler/.idea/projectSettingsUpdater.xml b/Compiler/.idea/.idea.Compiler/.idea/projectSettingsUpdater.xml
new file mode 100644
index 0000000..4bb9f4d
--- /dev/null
+++ b/Compiler/.idea/.idea.Compiler/.idea/projectSettingsUpdater.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Compiler/.idea/.idea.Compiler/.idea/vcs.xml b/Compiler/.idea/.idea.Compiler/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/Compiler/.idea/.idea.Compiler/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Compiler/.idea/.idea.Compiler/.idea/workspace.xml b/Compiler/.idea/.idea.Compiler/.idea/workspace.xml
new file mode 100644
index 0000000..1ec3fd0
--- /dev/null
+++ b/Compiler/.idea/.idea.Compiler/.idea/workspace.xml
@@ -0,0 +1,264 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1597507445860
+
+
+ 1597507445860
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Compiler/.idea/.idea.Compiler/riderModule.iml b/Compiler/.idea/.idea.Compiler/riderModule.iml
new file mode 100644
index 0000000..1a4e0d9
--- /dev/null
+++ b/Compiler/.idea/.idea.Compiler/riderModule.iml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs
new file mode 100644
index 0000000..9f78a86
--- /dev/null
+++ b/Compiler/Compiler.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Compiler
+{
+ public class Compiler
+ {
+ public static void Main()
+ {
+ TestCompiler("../../../../tests/week_1/valid");
+ TestCompiler("../../../../tests/week_1/invalid");
+ }
+
+ static void TestCompiler(String path)
+ {
+ String[] files = Directory.GetFiles(path);
+ Lexer lexer = new Lexer();
+
+ foreach (String filename in files)
+ {
+ StreamReader file = new StreamReader(filename);
+ String contents = file.ReadToEnd();
+
+ List tokens = lexer.Lex(contents);
+
+ Console.WriteLine("-----------" + filename + "-----------");
+ foreach (Token token in tokens)
+ {
+ Console.WriteLine(token.ToString());
+ }
+ Console.WriteLine("--------------------------------------");
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Compiler/Compiler.csproj b/Compiler/Compiler.csproj
new file mode 100644
index 0000000..2c0dacc
--- /dev/null
+++ b/Compiler/Compiler.csproj
@@ -0,0 +1,8 @@
+
+
+
+ Exe
+ netcoreapp3.1
+
+
+
diff --git a/Compiler/Compiler.sln b/Compiler/Compiler.sln
new file mode 100644
index 0000000..6824ffe
--- /dev/null
+++ b/Compiler/Compiler.sln
@@ -0,0 +1,16 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compiler", "Compiler.csproj", "{B8389A68-322F-43FD-9934-8747C0D1D6E5}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B8389A68-322F-43FD-9934-8747C0D1D6E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B8389A68-322F-43FD-9934-8747C0D1D6E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B8389A68-322F-43FD-9934-8747C0D1D6E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B8389A68-322F-43FD-9934-8747C0D1D6E5}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+EndGlobal
diff --git a/Compiler/Lexer.cs b/Compiler/Lexer.cs
new file mode 100644
index 0000000..68d1408
--- /dev/null
+++ b/Compiler/Lexer.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+
+namespace Compiler
+{
+ class Lexer
+ {
+ //this method transforms a String into a list of tokens
+ public List Lex(String inputString)
+ {
+ //strip newlines
+ inputString = inputString.Replace("\n", "");
+ inputString = inputString.Replace("\r", "");
+
+ //initialize Token List
+ List tokens = new List();
+
+ //while the string is not empty
+ while (inputString.Length > 0)
+ {
+ //trim whitespace
+ inputString = inputString.Trim();
+ //get next token
+ Token t = Next(inputString);
+ //append token to list
+ tokens.Add(t);
+ //remove token from input string
+ inputString = inputString.Substring(t.Length);
+ }
+
+ return tokens;
+ }
+
+ //this function returns the next token from a string
+ private Token Next(String input)
+ {
+ //initialize different possible patterns
+ List patterns = new List();
+
+ patterns.Add(new Pattern(@"^\(", TokenType.OpenParenthesisToken));
+ patterns.Add(new Pattern(@"^\)", TokenType.CloseParenthesisToken));
+ patterns.Add(new Pattern(@"^int ", TokenType.IntToken));
+ patterns.Add(new Pattern(@"^}", TokenType.CloseBraceToken));
+ patterns.Add(new Pattern(@"^{", TokenType.OpenBraceToken));
+ patterns.Add(new Pattern(@"^return ", TokenType.ReturnToken));
+ patterns.Add(new Pattern(@"^;", TokenType.SemicolonToken));
+ patterns.Add(new Pattern(@"^[a-zA-Z]\w*", TokenType.IdentifierToken));
+ patterns.Add(new Pattern(@"^[0-9]+", TokenType.IntegerLiteralToken));
+
+ //try each pattern do determine if it is the one matching at the beginning
+ //TODO: There sure is room for optimization here
+ foreach (var pattern in patterns)
+ {
+ //get regex from pattern and match
+ Regex r = pattern.ToRegex();
+ Match m = r.Match(input);
+
+ //check if the match was successful and at the beginning of the string
+ if (m.Index == 0 && m.Success)
+ {
+ //generate new token from match
+ Token t = new Token(pattern.GetTokenType());
+ t.Length = m.Length;
+ t.Value = null;
+
+ //switch over token types to assign a value if needed
+ //the default case "InvalidToken" is here for security and should never happen. If it does,
+ //something is wrong with the regex
+ switch (pattern.GetTokenType())
+ {
+ case TokenType.IntegerLiteralToken:
+ t.Value = m.Value;
+ break;
+ case TokenType.IdentifierToken:
+ t.Value = m.Value;
+ break;
+ case TokenType.ReturnToken:
+ case TokenType.CloseParenthesisToken:
+ case TokenType.OpenParenthesisToken:
+ case TokenType.OpenBraceToken:
+ case TokenType.CloseBraceToken:
+ case TokenType.IntToken:
+ case TokenType.SemicolonToken:
+ break;
+ default:
+ t.TokenType = TokenType.InvalidToken;
+ throw new Exception("Match found, but no corresponding token. Check regex!");
+ }
+
+ return t;
+ }
+ }
+ //return the next token
+ return new Token(TokenType.InvalidToken);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Compiler/Pattern.cs b/Compiler/Pattern.cs
new file mode 100644
index 0000000..e0e32bf
--- /dev/null
+++ b/Compiler/Pattern.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Text.RegularExpressions;
+
+namespace Compiler
+{
+ public class Pattern
+ {
+ private String pattern;
+ private TokenType tokenType;
+
+ public Pattern(String pattern, TokenType tokenType)
+ {
+ this.pattern = pattern;
+ this.tokenType = tokenType;
+ }
+
+ public Regex ToRegex()
+ {
+ return new Regex(this.pattern);
+ }
+
+ public TokenType GetTokenType()
+ {
+ return this.tokenType;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Compiler/Token.cs b/Compiler/Token.cs
new file mode 100644
index 0000000..c374ccf
--- /dev/null
+++ b/Compiler/Token.cs
@@ -0,0 +1,28 @@
+using System;
+
+namespace Compiler
+{
+ public class Token
+ {
+ public TokenType TokenType { get; set; }
+ public String Value { get; set; }
+ public int Length { get; set; }
+
+ public Token(TokenType pTokenType)
+ {
+ this.TokenType = pTokenType;
+ }
+
+ public override string ToString()
+ {
+ if (Value == null)
+ {
+ return TokenType.ToString();
+ }
+ else
+ {
+ return TokenType.ToString() + ":" + Value.ToString();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Compiler/TokenType.cs b/Compiler/TokenType.cs
new file mode 100644
index 0000000..d5a069a
--- /dev/null
+++ b/Compiler/TokenType.cs
@@ -0,0 +1,19 @@
+namespace Compiler
+{
+ public enum TokenType
+ {
+ OpenParenthesisToken,
+ CloseParenthesisToken,
+ IntToken,
+ OpenBraceToken,
+ CloseBraceToken,
+ ReturnToken,
+ SemicolonToken,
+ IdentifierToken,
+ IntegerLiteralToken,
+
+ //special Token to represent invalid matches
+ InvalidToken
+
+ }
+}
\ No newline at end of file
diff --git a/grammar b/grammar
new file mode 100644
index 0000000..e69de29
diff --git a/test.s b/test.s
new file mode 100644
index 0000000..bdee87d
--- /dev/null
+++ b/test.s
@@ -0,0 +1,4 @@
+ .globl main
+main:
+ movl $15, %eax
+ ret
diff --git a/tests/week_1/invalid/missing_paren.c b/tests/week_1/invalid/missing_paren.c
new file mode 100644
index 0000000..8e72a5c
--- /dev/null
+++ b/tests/week_1/invalid/missing_paren.c
@@ -0,0 +1,3 @@
+int main( {
+ return 0;
+}
\ No newline at end of file
diff --git a/tests/week_1/invalid/missing_retval.c b/tests/week_1/invalid/missing_retval.c
new file mode 100644
index 0000000..2f8d9bf
--- /dev/null
+++ b/tests/week_1/invalid/missing_retval.c
@@ -0,0 +1,3 @@
+int main() {
+ return;
+}
\ No newline at end of file
diff --git a/tests/week_1/invalid/no_brace.c b/tests/week_1/invalid/no_brace.c
new file mode 100644
index 0000000..96aac66
--- /dev/null
+++ b/tests/week_1/invalid/no_brace.c
@@ -0,0 +1,2 @@
+int main() {
+ return 0;
diff --git a/tests/week_1/invalid/no_semicolon.c b/tests/week_1/invalid/no_semicolon.c
new file mode 100644
index 0000000..584f789
--- /dev/null
+++ b/tests/week_1/invalid/no_semicolon.c
@@ -0,0 +1,3 @@
+int main() {
+ return 0
+}
diff --git a/tests/week_1/invalid/no_space.c b/tests/week_1/invalid/no_space.c
new file mode 100644
index 0000000..14a289b
--- /dev/null
+++ b/tests/week_1/invalid/no_space.c
@@ -0,0 +1,3 @@
+int main() {
+ return0;
+}
\ No newline at end of file
diff --git a/tests/week_1/invalid/wrong_case.c b/tests/week_1/invalid/wrong_case.c
new file mode 100644
index 0000000..bbae350
--- /dev/null
+++ b/tests/week_1/invalid/wrong_case.c
@@ -0,0 +1,3 @@
+int main() {
+ RETURN 0;
+}
\ No newline at end of file
diff --git a/tests/week_1/valid/multi_digit.c b/tests/week_1/valid/multi_digit.c
new file mode 100644
index 0000000..13f3123
--- /dev/null
+++ b/tests/week_1/valid/multi_digit.c
@@ -0,0 +1,3 @@
+int main() {
+ return 100;
+}
\ No newline at end of file
diff --git a/tests/week_1/valid/newlines.c b/tests/week_1/valid/newlines.c
new file mode 100644
index 0000000..7d8ba2e
--- /dev/null
+++ b/tests/week_1/valid/newlines.c
@@ -0,0 +1,10 @@
+
+int
+main
+(
+)
+{
+return
+0
+;
+}
\ No newline at end of file
diff --git a/tests/week_1/valid/no_newlines.c b/tests/week_1/valid/no_newlines.c
new file mode 100644
index 0000000..6a86477
--- /dev/null
+++ b/tests/week_1/valid/no_newlines.c
@@ -0,0 +1 @@
+int main(){return 0;}
\ No newline at end of file
diff --git a/tests/week_1/valid/return_0.c b/tests/week_1/valid/return_0.c
new file mode 100644
index 0000000..e9cdae1
--- /dev/null
+++ b/tests/week_1/valid/return_0.c
@@ -0,0 +1,3 @@
+int main() {
+ return 0;
+}
\ No newline at end of file
diff --git a/tests/week_1/valid/return_2.c b/tests/week_1/valid/return_2.c
new file mode 100644
index 0000000..5c52fee
--- /dev/null
+++ b/tests/week_1/valid/return_2.c
@@ -0,0 +1,3 @@
+int main() {
+ return 2;
+}
\ No newline at end of file
diff --git a/tests/week_1/valid/spaces.c b/tests/week_1/valid/spaces.c
new file mode 100644
index 0000000..e77bfef
--- /dev/null
+++ b/tests/week_1/valid/spaces.c
@@ -0,0 +1 @@
+ int main ( ) { return 0 ; }
\ No newline at end of file