Skip to content

Commit 0acb736

Browse files
committed
Inital commit
0 parents  commit 0acb736

File tree

452 files changed

+25541
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

452 files changed

+25541
-0
lines changed

.github/workflows/gradle.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This workflow will build a Java project with Gradle
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
3+
4+
name: Java CI with Gradle
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up JDK 17
20+
uses: actions/setup-java@v2
21+
with:
22+
java-version: '17'
23+
distribution: 'adopt'
24+
- name: Grant execute permission for gradlew
25+
run: chmod +x gradlew
26+
- name: Build with Gradle
27+
run: ./gradlew build

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
HELP.md
2+
.gradle
3+
build/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
!**/src/main/**/build/
6+
!**/src/test/**/build/
7+
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
bin/
17+
!**/src/main/**/bin/
18+
!**/src/test/**/bin/
19+
20+
### IntelliJ IDEA ###
21+
.idea
22+
*.iws
23+
*.iml
24+
*.ipr
25+
out/
26+
!**/src/main/**/out/
27+
!**/src/test/**/out/
28+
29+
### NetBeans ###
30+
/nbproject/private/
31+
/nbbuild/
32+
/dist/
33+
/nbdist/
34+
/.nb-gradle/
35+
36+
### VS Code ###
37+
.vscode/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Fireball19
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# simple-csharp-compiler
2+
3+
## How to run
4+
5+
#### 1. Run SableCC
6+
7+
```
8+
java -jar libs/sablecc.jar -d src simple_csharp_grammar.scc
9+
```
10+
11+
Move lexer.dat and parser.dat from src/main/java/sablecc to build/classes/java/main/sablecc.
12+
13+
#### 2. Run the StupsCompiler with Gradle
14+
15+
```
16+
./gradlew run --args='-mode <filename.cs>'
17+
```
18+
19+
#### 3. Run the Jasmin assembler
20+
21+
```
22+
java -jar libs/jasmin/jasmin.jar <filename.j>
23+
```
24+
25+
#### 4. Run the generated Java file
26+
27+
```
28+
java <filename>
29+
```

build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
plugins {
2+
id 'java'
3+
id 'application'
4+
}
5+
6+
mainClassName = 'StupsCompiler'
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
14+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
15+
implementation 'com.github.freva:ascii-table:1.2.0'
16+
testImplementation 'com.github.stefanbirkner:system-rules:1.19.0'
17+
}
18+
19+
test {
20+
useJUnitPlatform()
21+
}

c#/HelloWorld.cs

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using System;
2+
3+
namespace HelloWorld
4+
{
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
double a2 = 5;
10+
int i2 = 5;
11+
double aa = 5.5 + -6;
12+
bool b2 = 5.5 == 5;
13+
14+
bool b = true != true;
15+
double ddd = 5.5;
16+
int a = 5;
17+
double dd = 6.5;
18+
int ii = 6;
19+
20+
int i = 5;
21+
double d = 5.5 + i;
22+
a = i2;
23+
24+
Console.WriteLine(5.5 + 7 + 8);
25+
26+
Test8("TEST8", 5 + 5, (2 + 2) * 5);
27+
Console.WriteLine(a2);
28+
Console.WriteLine(Test7(5, 5));
29+
Console.WriteLine(aa);
30+
Console.WriteLine(Test6());
31+
Console.WriteLine(b2);
32+
33+
34+
Console.WriteLine(d);
35+
Console.WriteLine(Test2(5));
36+
37+
38+
Console.WriteLine("Hallo" == "Hallo"); // true
39+
Console.WriteLine("Hallo" != "Hallo2"); // true
40+
Console.WriteLine("Hallo" != "Hallo"); // false
41+
Console.WriteLine(5.65 + 1.35);
42+
Console.WriteLine(5.65 - 1.35);
43+
Console.WriteLine(-+1.35);
44+
Console.WriteLine(1.35 % 0.5);
45+
Console.WriteLine(5.5 * 10.5);
46+
Console.WriteLine(4.4 / 2.2);
47+
Console.WriteLine((4 + 6) + (2 * 2));
48+
Console.WriteLine(5 + 5.5);
49+
Console.WriteLine((5 + 5.5) + 7);
50+
Console.WriteLine(5 == 3);
51+
52+
Test5("Hallo");
53+
54+
Console.WriteLine(d);
55+
Console.WriteLine(a);
56+
Console.WriteLine(dd);
57+
Console.WriteLine(ii);
58+
59+
Console.WriteLine(5);
60+
Console.WriteLine(99.9);
61+
Console.WriteLine(true);
62+
Console.WriteLine("Hello World!");
63+
Console.WriteLine();
64+
Console.WriteLine(5 + 5);
65+
Console.WriteLine(5 + 5 + 8);
66+
Console.WriteLine(5 - 5);
67+
Console.WriteLine(5 % 5);
68+
Console.WriteLine(5 * 5);
69+
Console.WriteLine(5 / 5);
70+
Console.WriteLine(true && true);
71+
Console.WriteLine(false || false);
72+
Console.WriteLine(-15);
73+
Console.WriteLine(2 + 4 * 8); // 34
74+
Console.WriteLine((2 + 4) * 8); // 48
75+
Test4(5);
76+
Console.WriteLine(!true);
77+
Console.WriteLine(!false);
78+
79+
if (false) {
80+
Console.WriteLine(true);
81+
} else {
82+
Console.WriteLine(false);
83+
}
84+
85+
Console.WriteLine(Test(5));
86+
Console.WriteLine(true != true); // false
87+
Console.WriteLine(b); // false
88+
Console.WriteLine(true == true); // true
89+
Console.WriteLine(5 <= 5); // true
90+
Console.WriteLine(6 > 7); // false
91+
92+
Console.WriteLine(true != false);
93+
}
94+
95+
static int Test(int i) {
96+
return i;
97+
}
98+
99+
static double Test2(int i) {
100+
return i;
101+
}
102+
103+
static double Test77(double d) {
104+
return d;
105+
}
106+
107+
static bool Test3() {
108+
return true;
109+
}
110+
111+
static void Test4(int i) {
112+
Console.WriteLine(i);
113+
}
114+
115+
static void Test5(string t) {
116+
Console.WriteLine(t);
117+
}
118+
119+
static double Test7(int i, int a) {
120+
return i + a;
121+
}
122+
123+
static double Test6() {
124+
return 5 + 5;
125+
}
126+
127+
static void Test8(string s, int i, double d) {
128+
Console.WriteLine(s);
129+
Console.WriteLine(i + d);
130+
}
131+
}
132+
}

c#/Test.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace HelloWorld
4+
{
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
double a = 0.1;
10+
double b = 0.2;
11+
double i = a + b;
12+
Console.WriteLine(a);
13+
Console.WriteLine(b);
14+
Console.WriteLine(i);
15+
}
16+
}
17+
}

c#/complex/many_variables_main.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
3+
namespace ManyVariablesMain
4+
{
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
int add_25 = 5 + 5 + 5 + 5 + 5;
10+
int div_mult_8 = 8 / 4 * 4;
11+
int mod_0 = 9 * 9 % 9;
12+
int unary_minus_2 = -2;
13+
int plus_div_par = (5 + 5 + 5 + 5) + 12 / (2 + 2);
14+
double implicit_int_cast_7 = 7;
15+
double mult_166_375 = 5.5 * 5.5 * 5.5;
16+
string a_string = "I am a string.";
17+
string another_string = "I am another string.";
18+
bool string_equals_true = "a" == "a";
19+
bool string_not_equals_true = "b" != "a";
20+
bool logical_or_true = true || false;
21+
bool logical_and_false = true && false;
22+
bool unary_not_true = !false;
23+
24+
Console.WriteLine(add_25);
25+
Console.WriteLine(div_mult_8);
26+
Console.WriteLine(mod_0);
27+
Console.WriteLine(unary_minus_2);
28+
Console.WriteLine(plus_div_par);
29+
Console.WriteLine(implicit_int_cast_7);
30+
Console.WriteLine(mult_166_375);
31+
Console.WriteLine(a_string);
32+
Console.WriteLine(another_string);
33+
Console.WriteLine(string_equals_true);
34+
Console.WriteLine(string_not_equals_true);
35+
Console.WriteLine(logical_or_true);
36+
Console.WriteLine(logical_and_false);
37+
Console.WriteLine(unary_not_true);
38+
}
39+
}
40+
}

c#/complex/nested_if.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace FibonacciRecursive
4+
{
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
if (4 < 5) {
10+
if (5 == 5) {
11+
if (7 > 2) {
12+
if (99 >= 99) {
13+
if (0 <= 0) {
14+
Console.WriteLine("SUCCESS.");
15+
}
16+
}
17+
}
18+
}
19+
}
20+
}
21+
}
22+
}

c#/complex/nested_while.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace AbsoluteDifference
4+
{
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
int i = 10;
10+
int j = 5;
11+
12+
while(i > 0) {
13+
i = i - 1;
14+
Console.WriteLine("-");
15+
while(j > 0) {
16+
j = j - 1;
17+
Console.WriteLine("*");
18+
}
19+
}
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)