252 Commits

Author SHA1 Message Date
Lucas
4c4c06f728 Merge branch 'Endabgabe'
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-08 13:21:53 +02:00
Lucas
30bd5a0b5c Oder Documentation and Delete unnecessary
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-08 13:20:41 +02:00
f673612f54 Merge pull request 'Endabgabe' (#20) from Endabgabe into main
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Reviewed-on: #20
Reviewed-by: i22030 <i22030@hb.dhbw-stuttgart.de>
2024-07-05 11:59:46 +00:00
Maximilian Stahl
9760e39a29 Test updated
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-05 13:57:07 +02:00
Maximilian Stahl
93e17e5415 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 13:51:29 +02:00
Maximilian Stahl
b151edc2fd Updated README.md 2024-07-05 13:51:14 +02:00
Lucas
c0d8ab8399 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 13:50:11 +02:00
Lucas
f50bb7efd7 refactoring 2024-07-05 13:49:43 +02:00
Maximilian Stahl
51a390752b Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 13:46:31 +02:00
Maximilian Stahl
3114064038 Fixed Generation 2024-07-05 13:46:18 +02:00
Lucas
745db43b34 make and input
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 13:44:11 +02:00
Lucas
e0286e0840 Merge branch 'Endabgabe' of https://gitea.hb.dhbw-stuttgart.de/i22005/JavaCompiler into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 13:25:01 +02:00
Lucas
ebef717141 refactoring 2024-07-05 13:24:48 +02:00
Maximilian Stahl
3de54afa93 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
# Conflicts:
#	src/main/java/bytecode/MethodCodeGen.java
2024-07-05 13:23:57 +02:00
Maximilian Stahl
30d3cfa44a Fix and Final Test File 2024-07-05 13:23:09 +02:00
efa1a21655 Fix for MethodCallNode
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 06:30:55 -04:00
3fb11e5d7e Fixed methotcall with params
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 06:20:49 -04:00
Bruder John
c6e61defce Revert "Some small changes for SemanticAnalyzer"
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This reverts commit dbde4e8047.
2024-07-05 09:34:06 +02:00
Bruder John
dbde4e8047 Some small changes for SemanticAnalyzer
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-05 09:13:27 +02:00
5a12d61623 Changed testfiles
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 21:59:37 -04:00
f5bccab651 Small change
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 21:40:21 -04:00
0de5c3e993 Fixed MethodCall
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 21:03:52 -04:00
3628a0a4d8 Merge branch 'Endabgabe' of https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0 into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 20:04:23 -04:00
36f0683240 Fixed crement assign 2024-07-04 20:04:10 -04:00
Purplumbi504
97aadb9ba8 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 23:41:17 +02:00
Purplumbi504
e5dcbb8f99 Fixing AstBuilder For
pp script
2024-07-04 23:41:04 +02:00
e96f30fe19 Updated Loop Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 23:39:54 +02:00
64b15af6ef Null Test Deleted
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 23:15:22 +02:00
4ff6854094 NonCalculation Type added
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 23:14:00 +02:00
0a9cc7655a Changed For Structure
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 23:07:54 +02:00
7e66b5b8e3 Fixed Target = null
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 22:53:33 +02:00
d835a98e6f Some fixes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 16:41:44 -04:00
240913d422 Fixed MemberAccess Type
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 22:38:39 +02:00
4bee432294 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 22:24:59 +02:00
0cf4715782 Fixes of Constructor 2024-07-04 22:24:50 +02:00
Purplumbi504
3c0f7e857a Adding comments to ASTBuilder und ANTL Grammar
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 21:57:53 +02:00
Purplumbi504
2b7e0d0d42 Changing location of Makefile
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 21:13:38 +02:00
Purplumbi504
bd61a0e595 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 21:11:35 +02:00
Purplumbi504
24407a5c1c Revert test case directory: singleFeatureTests 2024-07-04 21:11:21 +02:00
195440e9d9 Added SemanticAnalyzer ElseIfStatement
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 20:49:54 +02:00
6fa57cf319 Type Error Change
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 20:36:36 +02:00
1de6add080 Fixe Type Error
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 20:23:43 +02:00
c315966219 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 19:45:09 +02:00
c2c4974c76 More Abgabe Tests working 2024-07-04 19:44:59 +02:00
Purplumbi504
85e0cf3807 Revert test case directory: singleFeatureTests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 19:10:21 +02:00
Purplumbi504
6f3fb02666 Fixing test case directory: singleFeatureTests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 19:03:44 +02:00
Purplumbi504
435697053a Fixing ReflectionTests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 18:57:36 +02:00
8eba420d48 Some changes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 12:29:23 -04:00
fbff03c3d7 Add typenode again
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 11:31:21 -04:00
721e1caa79 Merge remote-tracking branch 'origin/Endabgabe' into code-generator 2024-07-04 11:30:54 -04:00
6d3e1f859e Increment/Decrement assign
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 11:20:10 -04:00
f6b34bf70b readme.md gelöscht
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 15:16:39 +00:00
430d551f7d README.md aktualisiert
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 15:08:02 +00:00
8e0d627505 Readme fixed
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 17:06:49 +02:00
6b6051cad8 Readme fixed
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 17:04:48 +02:00
1f8e045b1e Readme 2024-07-04 17:03:49 +02:00
ceb1231632 Fixed Renaming Errors
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 17:02:02 +02:00
Maximilian Stahl
31929878b0 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
# Conflicts:
#	src/main/java/semantic/SemanticAnalyzer.java
#	src/test/java/semantic/SemanticTest.java
2024-07-04 16:55:15 +02:00
Lucas
ea97f34398 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 16:49:27 +02:00
Lucas
2f7b310254 refactoring, readme 2024-07-04 16:49:14 +02:00
Bruder John
9b8155ebab added class identifier to member acces node
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 16:31:45 +02:00
entep01
4775c3f47e Fixes and changed For Builder 2024-07-04 16:30:19 +02:00
Bruder John
2e3a7850a4 Fix Double Name 2024-07-04 16:29:42 +02:00
Bruder John
d925a3258c Add Class name to Memberaccesnode and identifier to assignable
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 15:58:46 +02:00
Lucas
fb5372bc8f make clean
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 15:22:37 +02:00
Lucas
f29be4fd8c E2E tests done
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 15:22:05 +02:00
Bruder John
34bb86c7f4 fixed if Check
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-04 10:40:13 +02:00
Bruder John
c0e197e2d0 added type to expression
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 09:09:55 +02:00
Bruder John
ae872ed906 removed Begin to Tast test
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 08:29:50 +02:00
91552ad147 Endabgabe Test Klassen
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-03 23:04:07 +02:00
084808c3ab Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 21:24:29 +02:00
d19748766f Fixed If Else Statements und If Else Tests 2024-07-03 21:24:19 +02:00
Bruder John
4bdb65a6ce fixed MemberAccess in MethodCalls
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 20:47:44 +02:00
Bruder John
97e0c228d6 Merge branch 'Endabgabe' of https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0 into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 20:37:35 +02:00
Bruder John
d4be77ceb2 Changed Some Tests 2024-07-03 20:36:57 +02:00
ca539add98 More Semantic Test
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 20:36:49 +02:00
1bcf396f95 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 20:28:16 +02:00
8ba58d492b Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
# Conflicts:
#	src/test/java/semantic/EndToTypedAstTest.java
#	src/test/resources/input/typedAstFeatureTests/CorrectTest.java
2024-07-03 20:27:41 +02:00
Bruder John
ed25868ff7 fix tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 20:27:29 +02:00
879fa08cdc SemanticAnalyzer Fail Tests 2024-07-03 20:26:39 +02:00
Bruder John
0e512161a0 Added Class name to Member accesnode
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 20:22:09 +02:00
Bruder John
ba08c6f6b0 Merge branch 'Endabgabe' of https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0 into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 19:25:59 +02:00
c5aea85965 New Generated
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 18:49:15 +02:00
2a1d0a0b8a Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 18:47:59 +02:00
f1abe5d5a8 Fixed ASTBuilder Tests 2024-07-03 18:47:46 +02:00
Bruder John
a9d7e841f5 changed correct Semantic check 2024-07-03 18:42:14 +02:00
Bruder John
b7863d0684 fixed thistar
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 18:33:30 +02:00
Bruder John
7ccff3208c added Semanticcheck to main
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 18:24:02 +02:00
Bruder John
3e0e6f8327 Commpiling Compiler in Intelij
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 18:22:04 +02:00
Bruder John
ab5a51d3b1 Merge remote-tracking branch 'origin/ParserAlterStand' into johns-branch
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-03 18:16:53 +02:00
Bruder John
a4c1c502ab Revert "Merge branch 'NewParser' into johns-branch"
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This reverts commit 84ecf316cd, reversing
changes made to 7ddea8f18d.
2024-07-03 18:15:57 +02:00
Bruder John
7d441116bd Merge branch 'code-generator' into chainedMethodsSemanticCheck
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-03 17:45:42 +02:00
Bruder John
8afa3b8461 Added Own Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 17:41:17 +02:00
Bruder John
84ecf316cd Merge branch 'NewParser' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 17:22:30 +02:00
Bruder John
7ddea8f18d removed Correct test
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 17:06:44 +02:00
46154fbb01 Merged Code, Semantic and Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 17:03:12 +02:00
9aac795c07 Merge branch 'Tests' of https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0 into NewParser 2024-07-03 17:01:50 +02:00
e59f4e7190 Merge branch 'johns-branch' of https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0 into NewParser 2024-07-03 17:01:33 +02:00
Lucas
e6a2b0fe9d Semantic Tests work
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 15:58:02 +02:00
Bruder John
44c2f551de Merge branch 'Tests' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 15:50:46 +02:00
Bruder John
bad034acfd Merge branch 'chainedMethodsSemanticCheck' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 15:38:25 +02:00
Bruder John
ba73e1bd45 Revert "added chainedmethods"
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This reverts commit b7affd75ae.
2024-07-03 15:35:39 +02:00
Bruder John
b7affd75ae added chainedmethods
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 15:35:09 +02:00
Lucas
2ef50f93a9 added system properties
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 15:21:58 +02:00
Lucas
1cf1aaf837 Doku, AllFeaturesClassExample not running!!!
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 14:08:27 +02:00
Lucas
2bf73385af small changes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 13:06:06 +02:00
Lucas
b072af346b Huge Changes in TestFiles, ReflectionsTest, much more
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 13:04:33 +02:00
Lucas
27baa429b4 small changes in main for bytecode
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 09:35:50 +02:00
bd76135895 Some changes
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-02 21:43:03 -04:00
Lucas
6cec17eb45 Merge remote-tracking branch 'origin/code-generator' into Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-03 00:47:49 +02:00
87be850a0e Revert "Merge branch 'main' into code-generator"
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This reverts commit 8956362033, reversing
changes made to b58fa00c9a.
2024-07-02 18:07:48 -04:00
72f82ff863 Revert "Merge branch 'NewParser' into code-generator"
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This reverts commit f0dd6d5eb6, reversing
changes made to 8956362033.
2024-07-02 18:07:42 -04:00
7419953510 Revert "Merge branch 'johns-branch' into code-generator"
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This reverts commit 449b895d20, reversing
changes made to f0dd6d5eb6.
2024-07-02 18:07:26 -04:00
449b895d20 Merge branch 'johns-branch' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 17:52:23 -04:00
f0dd6d5eb6 Merge branch 'NewParser' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 17:52:04 -04:00
8956362033 Merge branch 'main' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 17:51:24 -04:00
Lucas
ed4aa2d59b small changes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 23:51:06 +02:00
Lucas
6760a17f00 Revert "Merged Code Gen!!!"
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This reverts commit 671317f28b.
2024-07-02 23:49:44 +02:00
Lucas
671317f28b Merged Code Gen!!!
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 23:45:54 +02:00
Lucas
e862a7427b Merge remote-tracking branch 'origin/code-generator' into Tests 2024-07-02 23:45:33 +02:00
233725778f Merge branch 'johns-branch' of https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0 into NewParser 2024-07-02 20:37:42 +02:00
3227d69fc1 Merged Main and Code-Generator
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-07-02 20:25:15 +02:00
4ca6972ccd Merge branch 'code-generator' of https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0 into NewParser 2024-07-02 20:10:54 +02:00
0047f6c08e Merge remote-tracking branch 'origin/NewParser' into NewParser
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 20:08:23 +02:00
88ce9e52f0 More Tests for ASTBuilder
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 20:08:08 +02:00
Purplumbi504
437de74cc6 New Grammer
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 19:13:59 +02:00
Purplumbi504
ca77307f0c Merge remote-tracking branch 'origin/NewParser' into NewParser
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 19:12:29 +02:00
Purplumbi504
5f46130439 Adding Switch Case AST 2024-07-02 19:12:19 +02:00
3e1456351c Merge remote-tracking branch 'origin/NewParser' into NewParser
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
# Conflicts:
#	src/test/java/parser/AstBuilderTest.java
2024-07-02 18:00:29 +02:00
d26cd0c13a For Test 2024-07-02 17:57:48 +02:00
Purplumbi504
cfde5219a4 Merge remote-tracking branch 'origin/NewParser' into NewParser
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 17:51:11 +02:00
Purplumbi504
f414e278bb Adding Test Cases 2024-07-02 17:50:58 +02:00
Maximilian Stahl
741a56cb99 Merge remote-tracking branch 'origin/NewParser' into NewParser
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
# Conflicts:
#	src/main/java/parser/astBuilder/ASTBuilder.java
2024-07-02 17:39:05 +02:00
Maximilian Stahl
02e5f3a729 Fixes and changed For Builder 2024-07-02 17:36:48 +02:00
Bruder John
f7338a06b3 added MemberAccess to Assignable
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 15:47:33 +02:00
Bruder John
3996082fa7 Merge branch 'main' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 14:52:13 +02:00
903e87901e Merge pull request 'Constructor Fix' (#18) from NewParser into main
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Reviewed-on: #18
Reviewed-by: Johannes Ehlert <i22005@hb.dhbw-stuttgart.de>
2024-07-02 12:51:46 +00:00
775beb60fe Merge pull request 'Gemeinsame Changes von Discord' (#19) from Tests into main
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Reviewed-on: #19
Reviewed-by: Johannes Ehlert <i22005@hb.dhbw-stuttgart.de>
2024-07-02 12:50:57 +00:00
Bruder John
2537051668 fix if field and parameter have same identifier
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 14:31:44 +02:00
Bruder John
82356ec189 set types of expressions
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 10:36:22 +02:00
Bruder John
561eafbf4c fixed constructor node parameter decleration
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-02 08:48:37 +02:00
b58fa00c9a Fixed some problems
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 21:49:25 -04:00
Lucas
92990e4042 gemeinsame dc changes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 23:53:42 +02:00
Lucas
3500ffd377 small changes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 23:31:22 +02:00
Lucas
771b92bfd7 Merge branch 'main' into Tests 2024-07-01 23:31:00 +02:00
c94c7a6477 Constructor Fix
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 23:20:15 +02:00
c7ad574474 Merge pull request 'code-generator' (#13) from code-generator into main
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Reviewed-on: #13
Reviewed-by: Johannes Ehlert <i22005@hb.dhbw-stuttgart.de>
2024-07-01 21:14:36 +00:00
22c3850062 Merge branch 'main' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 17:14:10 -04:00
Lucas
21da31dee3 Merge branch 'main' into Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 23:10:16 +02:00
Lucas
294df16e89 small changes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 23:09:53 +02:00
3112660880 Merge pull request 'johns-branch' (#17) from johns-branch into main
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Reviewed-on: #17
Reviewed-by: i22035 <i22035@hb.dhbw-stuttgart.de>
2024-07-01 21:08:23 +00:00
c135819ba0 Merge branch 'main' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 17:07:52 -04:00
e94cd9cc2a Merge pull request 'NewParser' (#16) from NewParser into main
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Reviewed-on: #16
Reviewed-by: Johannes Ehlert <i22005@hb.dhbw-stuttgart.de>
2024-07-01 21:07:27 +00:00
Maximilian Stahl
dcd20a2394 AST Builder Tests and Fixes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 16:40:02 +02:00
Bruder John
71ffb8bb83 added for loops to the test
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 16:04:27 +02:00
Bruder John
2d455ba197 added som more checks
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 15:45:57 +02:00
Bruder John
77fecfa476 added Type to Assignable
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 13:25:27 +02:00
Bruder John
36e56fa66e added some tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 12:58:24 +02:00
Bruder John
f3e3158460 added private fields
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 12:58:11 +02:00
Bruder John
7b1e6fced4 Merge branch 'NewParser' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 09:35:01 +02:00
Bruder John
4d5c0017b4 Merge branch 'main' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 08:32:44 +02:00
093beb9ef1 Merge branch 'NewParser' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-30 19:28:01 -04:00
2ae0988986 Changed For Loop Structure
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-30 22:17:52 +02:00
Lucas
18fc17b707 Merge branch 'main' into Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-30 18:34:02 +02:00
Lucas
bea71838ac Reflections: not running
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-30 18:33:01 +02:00
dfded3e592 Added ASTBuilder Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-30 13:20:58 +02:00
0298e2cb76 Merge branch 'NewParser' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-29 20:24:54 -04:00
Purplumbi504
dccd34db73 Adding Test Cases
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-29 16:05:11 +02:00
90f91d58d1 OutputDirectory
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-27 19:56:54 -04:00
612c967023 Bytecode for if/elseif/else
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 19:56:31 -04:00
f12e553ffc Merge branch 'main' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 17:34:30 -04:00
f24e279596 Merge branch 'NewParser' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 17:33:50 -04:00
c5fc378eed Bytecode for loops
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 17:32:50 -04:00
Purplumbi504
27f50b9c66 Adding EmptyClass Test AST
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-27 21:14:02 +02:00
3e901ea254 Merge pull request 'NewParser' (#15) from NewParser into main
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Reviewed-on: #15
Reviewed-by: Johannes Ehlert <i22005@hb.dhbw-stuttgart.de>
2024-06-27 16:56:32 +00:00
85ae06048c Add Return if Returntype is Void
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 18:55:28 +02:00
cd845cd91c Fixed Merge Conflicts
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 18:45:14 +02:00
Bruder John
4d21d8e94e fix method overlaoding semantic check
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-27 15:17:05 +02:00
Bruder John
a34c7ded50 added Some Semantic Checks
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 15:04:01 +02:00
78d5528733 Merge pull request 'More Tests, Structure, etc. Huge Changes' (#14) from Tests into main
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Reviewed-on: #14
Reviewed-by: Johannes Ehlert <i22005@hb.dhbw-stuttgart.de>
2024-06-27 10:49:35 +00:00
Bruder John
10eb17497e added some Semantic Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 10:45:38 +02:00
Bruder John
576146c4fc Merge branch 'Tests' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 08:35:07 +02:00
Bruder John
bf365194be Merge branch 'NewParser' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 08:31:56 +02:00
Bruder John
35b3e9ee46 Added Some Semantice Checks
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 08:11:17 +02:00
Maximilian Stahl
88a25207e9 Added Interface and fixed bugs
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-26 17:34:40 +02:00
Lucas
4e56760dd6 Old spelling mistake in semantic fixed
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-26 16:28:53 +02:00
Lucas
347bdcbd94 Update .gitignore
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-26 16:22:38 +02:00
Lucas
d594bacb7d Semantic Tests refactored
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-26 16:21:04 +02:00
Lucas
eb313464f0 Tests (structure) refactored
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-26 11:25:24 +02:00
Bruder John
8163d0b61e removing Semantic Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-26 09:55:12 +02:00
Bruder John
92e1daab5b Merge branch 'NewParser' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-26 09:51:33 +02:00
70a3788030 Merge branch 'NewParser' into code-generator
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-25 17:48:47 -04:00
b562a789a0 Fixed Merge Conflicts and Bugs
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-25 22:35:28 +02:00
c05ad761d7 Merge branch 'main' of https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0 into NewParser 2024-06-25 21:53:14 +02:00
Lucas
34d17660ef Tests refactored
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-25 18:05:58 +02:00
Lucas
cc6d26e17d Tests refactored
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-25 18:05:26 +02:00
Lucas
f9743efddc Merge branch 'main' into Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-25 16:43:42 +02:00
Lucas
b37e065857 Small changes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-25 16:41:04 +02:00
4c5473827e Small change
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-24 18:52:55 -04:00
d631b01c82 ConstructorNode and NotNode
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-23 16:06:07 -04:00
Bruder John
8cd22c6e4c Removed some Exercices from Tests because parser is not ready for
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-23 20:57:53 +02:00
ef0bc99bbf Bytecode for dotSubstractionNode
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-23 14:54:53 -04:00
99948fef07 Bytecode for ValueNode
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-23 14:35:57 -04:00
66c9481b3e Add all accept methods
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-23 13:43:42 -04:00
fd8d451ba7 Renaming again
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-23 11:33:33 -04:00
f27a7471bc Merge branch 'NewParser' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-23 11:19:09 -04:00
a15f684c04 Add visitors and code for binary expressions
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-23 11:10:06 -04:00
4a78ab62a1 Fixed some Merge Conflicts
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-23 14:18:42 +02:00
Purplumbi504
8d3602eda3 Renaiming packages
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-23 13:59:06 +02:00
Purplumbi504
fcaeb850ba Merge remote-tracking branch 'origin/NewParser' into NewParser
# Conflicts:
#	src/main/java/ast/ClassNode.java
#	src/main/java/ast/expressions/AssignableExpressionNode.java
#	src/main/java/ast/expressions/ExpressionNode.java
#	src/main/java/ast/expressions/IExpressionNode.java
#	src/main/java/ast/expressions/binaryexpression/BinaryExpressionNode.java
#	src/main/java/ast/expressions/binaryexpression/CalculationExpressionNode.java
#	src/main/java/ast/expressions/binaryexpression/DotExpressionNode.java
#	src/main/java/ast/expressions/binaryexpression/DotSubstractionExpressionNode.java
#	src/main/java/ast/expressions/binaryexpression/EnumDotOperator.java
#	src/main/java/ast/expressions/binaryexpression/EnumLineOperator.java
#	src/main/java/ast/expressions/binaryexpression/EnumNonCalculationOperator.java
#	src/main/java/ast/expressions/binaryexpression/NonCalculationExpressionNode.java
#	src/main/java/ast/expressions/unaryexpression/MemberAccessNode.java
#	src/main/java/ast/expressions/unaryexpression/NotExpressionNode.java
#	src/main/java/ast/expressions/unaryexpression/UnaryExpressionNode.java
#	src/main/java/ast/members/ConstructorNode.java
#	src/main/java/ast/members/MainMethodNode.java
#	src/main/java/ast/statement/ForStatementNode.java
#	src/main/java/ast/statement/WhileStatementNode.java
#	src/main/java/ast/statement/ifstatement/ElseStatementNode.java
#	src/main/java/ast/statement/ifstatement/IfElseStatementNode.java
#	src/main/java/ast/statement/ifstatement/IfStatementNode.java
#	src/main/java/ast/statement/statementexpression/methodcallstatementnexpression/TargetNode.java
#	src/main/java/ast/statementexpressions/AssignStatementExpressionNode.java
#	src/main/java/ast/statementexpressions/AssignableExpressionNode.java
#	src/main/java/ast/statementexpressions/CrementExpressionStatementExpressionNode.java
#	src/main/java/ast/statementexpressions/IStatementExpressionNode.java
#	src/main/java/ast/statementexpressions/NewDeclarationStatementExpressionNode.java
#	src/main/java/ast/statementexpressions/crementExpression/CrementType.java
#	src/main/java/ast/statementexpressions/crementExpression/DecrementExpressionNode.java
#	src/main/java/ast/statementexpressions/crementExpression/IncrementExpressionNode.java
#	src/main/java/ast/statementexpressions/methodcallstatementnexpression/ChainedMethodNode.java
#	src/main/java/ast/statementexpressions/methodcallstatementnexpression/MethodCallStatementExpressionNode.java
#	src/main/java/ast/statements/BlockStatementNode.java
#	src/main/java/ast/statements/IStatementNode.java
#	src/main/java/ast/statements/LocalVariableDeclarationNode.java
#	src/main/java/ast/statements/ReturnStatementNode.java
#	src/main/java/bytecode/ClassCodeGen.java
#	src/main/java/bytecode/Mapper.java
#	src/main/java/bytecode/MethodCodeGen.java
#	src/main/java/parser/astBuilder/ASTBuilder.java
#	src/main/java/parser/generated/SimpleJava.interp
#	src/main/java/parser/generated/SimpleJava.tokens
#	src/main/java/parser/generated/SimpleJavaBaseListener.java
#	src/main/java/parser/generated/SimpleJavaBaseVisitor.java
#	src/main/java/parser/generated/SimpleJavaLexer.interp
#	src/main/java/parser/generated/SimpleJavaLexer.java
#	src/main/java/parser/generated/SimpleJavaLexer.tokens
#	src/main/java/parser/generated/SimpleJavaListener.java
#	src/main/java/parser/generated/SimpleJavaParser.java
#	src/main/java/parser/generated/SimpleJavaVisitor.java
#	src/main/java/semantic/SemanticVisitor.java
2024-06-23 10:58:46 +02:00
Purplumbi504
864ddbaeee Fix errors in if Statments.
For and Do While loop as While loop.
2024-06-23 10:57:25 +02:00
fb3f822160 Merge branch 'main' into code-generator
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-21 19:25:35 -04:00
fd6da5cad2 Merge pull request 'johns-branch' (#12) from johns-branch into main
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Reviewed-on: #12
Reviewed-by: i22035 <i22035@hb.dhbw-stuttgart.de>
2024-06-21 16:30:55 +00:00
Bruder John
c44118c872 Fixed all
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-21 18:28:08 +02:00
Bruder John
0020f582a1 Merge branch 'main' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-21 18:26:07 +02:00
8b5a0d528e Merge pull request 'Tests, Structure, More' (#10) from Tests into main
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Reviewed-on: #10
Reviewed-by: Johannes Ehlert <i22005@hb.dhbw-stuttgart.de>
2024-06-21 16:16:53 +00:00
Bruder John
1b91e25d17 fixed tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-21 18:09:32 +02:00
Bruder John
9edee73705 Merge branch 'NewParser' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-21 18:07:18 +02:00
Bruder John
5bf9a4fc73 added wrong type in if clause
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-21 18:06:49 +02:00
6d36eb109c Added Enums for Operators and MainMethodNode
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-21 18:02:29 +02:00
Bruder John
7b41c45cd5 Fixed all Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-21 17:03:49 +02:00
Bruder John
cf41babcb7 Added BaseType And refferenz Type
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-21 16:42:27 +02:00
Bruder John
b9ada16dd1 Fixed SemanticCheck for new AST and added Some Test
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-21 15:23:48 +02:00
Bruder John
b5738034b0 Merge branch 'NewParser' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-21 10:47:54 +02:00
b9f6014f59 Assignments
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-20 18:12:04 -04:00
Bruder John
0ec65af9f9 Added Method Check
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-20 16:53:31 +02:00
Bruder John
fd8c3b066a Trying to change to new AST
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-20 11:43:58 +02:00
af64f88198 Merge branch 'NewParser' into code-generator
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-19 15:22:00 -04:00
837e751094 Generate jar with first class as main
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-19 12:53:14 -04:00
Lucas
8cc67080ec Small changes
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-19 17:09:38 +02:00
Lucas
cfcb61d49e Running now possible with make or java.exe -jar in console
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-19 16:32:46 +02:00
Lucas
8f742191bb Small changes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-19 14:19:47 +02:00
Lucas
102961bccc Added logging
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-19 12:49:46 +02:00
Lucas
f59d7e9918 First Tests for Parser, pls check
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-17 17:42:50 +02:00
Lucas
0732712e61 Make, Main: Raupenpiler startup
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-17 13:42:56 +02:00
57c2023215 Merge remote-tracking branch 'origin/NewParser' into code-generator
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-16 16:52:24 -04:00
Purplumbi504
12ab402746 Fix errors in if Statments.
For and Do While loop as While loop.
2024-06-16 13:15:39 +02:00
Lucas
b6cc925e02 Fixed Makefile
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-06-12 18:01:21 +02:00
Lucas
6a971345d4 Structure and more
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-12 11:17:16 +02:00
Lucas
8d6190b130 Structure, Makefile, Docs, TestCompilerOutput, more; TODO: fix marked Problems in Makefile; fix Compiler (look at TestCompilerOutput docs)
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-05-31 17:09:04 +02:00
09e36a84dc Merge remote-tracking branch 'origin/parser2.0' into code-generator
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
2024-05-31 11:32:53 +02:00
Maximilian Stahl
e395c4d96b Fixed Boolean and Char Literal
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-05-31 11:32:11 +02:00
Bruder John
8a5f307947 Fix Type
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-05-31 11:27:02 +02:00
514f7d724a Merge remote-tracking branch 'origin/parser2.0' into code-generator
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-05-31 11:20:38 +02:00
Lucas
9f40949f5a Structure
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-05-31 11:20:31 +02:00
Maximilian Stahl
de5c2a5002 Added Parser Visitors
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-05-31 11:16:25 +02:00
Lucas
1132ff015c Changes in tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-05-31 11:05:45 +02:00
Lucas
2a20a91d35 Refactor structure and more
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-05-31 10:55:41 +02:00
407b03620e Code for assignment
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-05-31 10:46:23 +02:00
Lucas
b2e1745d51 Merge branch 'main' into Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-05-31 10:04:40 +02:00
Lucas
a0e55d7b27 first testrun of the day 2024-05-31 10:00:46 +02:00
Lucas
5a28d88f6a comments 2024-05-31 09:58:07 +02:00
245 changed files with 9539 additions and 2845 deletions

9
.gitignore vendored
View File

@@ -76,4 +76,11 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
/target
/target
src/main/resources/logs/miniCompilerLog.log
src/test/java/main/CompilerInput.class
src/test/resources/output/javac/CompilerInput$Test.class
src/test/resources/output/javac/CompilerInput.class
src/test/resources/output/miniCompiler/CompilerInput.class
src/test/resources/output/miniCompiler/CompilerInput$Test.class
.idea/inspectionProfiles/Project_Default.xml

19
.idea/ANTLRv4ToolGrammarProperties.xml generated Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ANTLRv4ToolGrammarProperties">
<option name="perGrammarGenerationSettings">
<list>
<PerGrammarGenerationSettings>
<option name="fileName" value="$PROJECT_DIR$/src/main/java/parser/grammar/SimpleJava.g4" />
<option name="autoGen" value="true" />
<option name="outputDir" value="C:\Users\janni\Desktop\NichtHaskell2.0\src\main\java" />
<option name="libDir" value="" />
<option name="encoding" value="" />
<option name="pkg" value="parser.generated" />
<option name="language" value="" />
<option name="generateVisitor" value="true" />
</PerGrammarGenerationSettings>
</list>
</option>
</component>
</project>

View File

@@ -6,6 +6,11 @@
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="maven_central" />
<option name="name" value="Maven Central" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />

2
.idea/misc.xml generated
View File

@@ -6,7 +6,7 @@
<PerGrammarGenerationSettings>
<option name="fileName" value="$PROJECT_DIR$/src/main/java/parser/SimpleJava.g4" />
<option name="autoGen" value="true" />
<option name="outputDir" value="C:\Users\Johannes\Documents\Github\JavaCompiler\src\main\java" />
<option name="outputDir" value="C:\Users\ARB00075\Documents\DH\Compilerbau\NichtHaskell2.0\src\main\java" />
<option name="libDir" value="" />
<option name="encoding" value="" />
<option name="pkg" value="parser.generated" />

Binary file not shown.

37
Makefile Normal file
View File

@@ -0,0 +1,37 @@
### IntelliJs play buttons do not work. Run in "src/test" folder with "make" command to run all
### Or run only parts with "make compile-javac", "make clean" etc.
all: compile-javac compile-miniCompiler
compile-javac:
#javac -d src/test/resources/output/javac src/test/resources/input/CompilerInput.java
compile-miniCompiler:
cd ../.. ; mvn -DskipTests install
cd ../.. ; mvn exec:java -DgenJar=true -DgenClass=true -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'"
# cp src/main/resources/output/CompilerInput.class src/test/resources/output/miniCompiler
test-miniCompiler:
# move the compiled class to the test/main folder
mv src/main/resources/output/CompilerInput.class src/test/java/main/
# compile the test class
javac src/test/java/main/EndToEndTester.java
# run the test class
java -cp src/test/java/main EndToEndTester
clean:
# clean main output folders
rm -f src/main/resources/output/*.class
rm -f src/main/resources/output/*.jar
# clean resources output folders
rm -f src/test/resources/output/javac/*.class
rm -f src/test/resources/output/miniCompiler/*.class
rm -f src/test/resources/output/miniCompiler/*.jar
# clean logs
rm -f src/main/resources/logs/*
# clean test/java/main folders from .class files for End-to-End tests
rm -f src/test/java/main/*.class
# clean javac output from every folder
rm -f src/test/resources/input/*/*.class
# clean test results from maven surefire plugin
rm -f ../../target/surefire-reports/*.txt

BIN
Parser_Dokumentation.pdf Normal file

Binary file not shown.

136
README.md Normal file
View File

@@ -0,0 +1,136 @@
# "Nicht Haskel 2.0" Java Compiler
Realisation of a subset of the Java Standard Compiler in the course Compiler Construction of the 4th semester Computer Science at the Duale Hochschule Stuttgart (Horb).
This project aims to provide a simplified version of the Java compiler, focusing on key language features and demonstrating the principles of compiler construction.
## Realised Java syntax
- **Data types**: `int`, `boolean`, `char`
- **Access modifier**: `public`, `protected`, `private`
- **Operators**: `=` `+` `-` `*` `%` `/` `>` `<` `>=` `<=` `==` `!=` `!` `&&` `||` `++` `--`
- **Keywords**: `class`, `this`, `while`, `do`, `if`, `else`, `for`, `return`, `new`, `switch`, `case`, `break`, `default`, `:`
- **Statements**:
- `if` ... `if else` ... `else`;
- `while` ... ;
- `do` ... `while`;
- `for`;
- **Comments**:
- Single line: `// comment`
- Multi-line: `/* comment */`
- **Further functions**:
- All methods are overloadable
- High maintainability and expandability through implementation of the visitor pattern
- Logging Input and Outputs
- Error Handling in the Semantic Check
## Project Structure
```plain
src/
└── main/
├── java/
│ ├── ast/ -> Defining the structure of the AST
│ ├── bytecode/ -> Generate Java bytecode
│ ├── main/ -> Running the compiler
│ ├── parser/
│ │ ├── astBuilder/ -> Builder creating the AST
│ │ ├── generated/ -> Antlr generated grammar
│ │ └── grammar/ -> Antlr grammar
│ ├── semantic/ -> Running the semantic check
│ └── visitor/ -> Visitor interface
└── resources/
test/
└── java/
│ ├── main/ -> Running E2E tests
│ ├── parser/ -> Performs tests on the parser
│ ├── semantic/ -> Performs tests on the semantic check
└── resources/ -> Ressources for running the Tests
```
## Class-Diagramm AST
![AST Diagramm](ast.png)
## Distribution of the realisation
### i22030 & i22035
Ausführliche Beschreibung der Parser Umsetzung:
![Parserumsetzung](Parser_Dokumentation.pdf)
Parser:
- Grammar -> (src/main/java/parser/grammar)
- Scanner
- Parser
- Abstract Syntax Tree (AST) -> (src/main/java/ast)
- AstBuilder -> (src/main/java/parser/astBuilder)
Parser tests:
- ParserTests -> (src/test/java/parser)
- TestCases -> (src/test/resources/input/singeFeatureTests)
Other:
- Documentation -> (README.md)
- Ast Class-Diagramm -> (ast.png)
- PowerPoint
### i22005
Semantic check:
- Set all types and check whether types have been used correctly
- Contexts -> (src/main/java/semantic/context)
- Exceptions Handling -> (src/main/java/semantic/exceptions)
Semantic Tests:
- Typing and Type checking -> (src/test/java/semantic/EndToTypedAstTest)
- Exception and feature test -> (src/test/resources/input/typedAstExceptionsTests)
### i22007
Bytecode generation:
- Complete bytecode generation -> (src/mein/java/bytecode)
### i22011
Tests and execution:
- Makefile
- Running Compiler -> (src/main/main)
- Running E2E tests -> (src/test/main)
- Typing and Type checking -> (src/test/java/semantic/EndToTypedAstTest)
## Used Tools
- [Maven 4.0](https://maven.apache.org/index.html)
- Used for automating the build process and managing dependencies.
- [ANTLR4 v.13.1](https://www.antlr.org/)
- Used to parse the input Java code into the Abstract Syntax Tree.
## How to run the compiler
### Possibilities
### 1. Start miniCompiler using make:
Make needs to be installed
```bash
cd .\src\test\ ; make clean compile-miniCompiler
```
### 2. Start miniCompiler using jar:
If you do not have the .jar, download it [here](https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0/src/branch/main/JavaCompiler-1.0-jar-with-dependencies.jar) or compile it using mvn package or make first
```
java.exe -DgenJar=bool -DgenClass=bool -jar path_to_jar\jarName.jar 'path_to_input_file.java' 'path_to_output_directory'
```
Example (jar needs to be in the target directory)
```bash
java.exe -DgenJar=true -DgenClass=true -jar .\target\JavaCompiler-1.0-jar-with-dependencies.jar 'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'
```
- set DgenJar true, to generate the jar, false for no jar
```
DgenJar=true
```
- set DgenClass true, to generate class files, false for no class files
```
DgenClass=true
```

BIN
ast.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

64
pom.xml
View File

@@ -4,13 +4,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<groupId>de.dhbw-stuttgart</groupId>
<artifactId>JavaCompiler</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<java.version>22</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@@ -19,7 +20,25 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.3</version> <!-- Change the version as needed -->
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<version>1.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -52,8 +71,41 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version> <!-- Change the version as needed -->
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
</project>

View File

@@ -1,132 +0,0 @@
import ast.ASTNode;
import org.antlr.v4.runtime.*;
import ast.ProgramNode;
//import bytecode.ByteCodeGenerator;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.CommonTokenStream;
import parser.astBuilder.ASTBuilder;
import parser.generated.SimpleJavaLexer;
import parser.generated.SimpleJavaParser;
//import semantic.SemanticAnalyzer;
import java.io.IOException;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) throws Exception {
if(args.length > 0) {
} else {
try {
CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/main/resources/CompilerInput.java"));
parseFile(codeCharStream);
} catch (IOException e) {
System.err.println("Error reading the file: " + e.getMessage());
}
}
}
static void parseFile(CharStream codeCharStream) {
/* ------------------------- Scanner -> tokens ------------------------- */
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
// Printing the tokens
// tokenStream.fill();
// List<Token> tokens = tokenStream.getTokens();
// System.out.println("-------------------- Scanner -> tokens --------------------");
// for (Token token : tokens) {
// String tokenType = SimpleJavaLexer.VOCABULARY.getSymbolicName(token.getType());
// String tokenText = token.getText();
// // System.out.println("Token Type: " + tokenType + ", Token Text: " +
// // tokenText);
// System.out.println(tokenType + " " + tokenText);
// }
// System.out.println();
/* ------------------------- Parser -> Parsetree ------------------------- */
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
ParseTree parseTree = parser.program(); // parse the input
// Printing the parse tree
// System.out.println("-------------------- Parser -> Parsetree --------------------");
// System.out.println(parseTree.toStringTree(parser));
// printTree(parseTree, parser, 0);
// System.out.println();
/* ------------------------- AST builder -> AST ------------------------- */
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
System.out.println(abstractSyntaxTree);
// Printing the AST
// System.out.println("-------------------- AST builder -> AST --------------------");
// // System.out.println("AST: " + ast.toString());
// printAST(abstractSyntaxTree, 0);
// System.out.println();
/*
* ------------------------- Semantic Analyzer -> Tast -------------------------
*/
//SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
//ProgramNode typedAst = (ProgramNode) semanticAnalyzer.generateTast(abstractSyntaxTree);
// Printing the Tast
System.out.println("Tast generated");
/*
* ------------------------- Bytecode Generator -> Bytecode
* -------------------------
*/
//ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator();
//byteCodeGenerator.generateByteCode(abstractSyntaxTree);
//byteCodeGenerator.visit(typedAst);
System.out.println("Bytecode generated");
}
/**
* This method is used to print the parse tree in a structured format.
* It recursively traverses the tree and prints the rule names and text of the
* nodes.
*
* @param tree The parse tree to be printed.
* @param parser The parser used to parse the input. It's used to get the rule
* names.
* @param indent The current indentation level. It's used to format the output.
*/
public static void printTree(ParseTree tree, Parser parser, int indent) {
// Create an indentation string based on the current indentation level
String indentString = " ".repeat(indent * 2);
// If the tree node is an instance of RuleContext (i.e., it's an internal node),
// print the rule name
if (tree instanceof RuleContext) {
int ruleIndex = ((RuleContext) tree).getRuleIndex();
String ruleName = parser.getRuleNames()[ruleIndex];
System.out.println(indentString + ruleName);
} else {
// If the tree node is not an instance of RuleContext (i.e., it's a leaf node),
// print the text of the node
System.out.println(indentString + tree.getText());
}
// Recursively print the children of the current node, increasing the
// indentation level
for (int i = 0; i < tree.getChildCount(); i++) {
printTree(tree.getChild(i), parser, indent + 1);
}
}
public static void printAST(ASTNode node, int indent) {
String indentString = " ".repeat(indent * 2);
System.out.println(indentString + node.getClass().toString());
// for (ASTNode child : node.) {
// printAST(child, indent + 1);
// }
}
}

View File

@@ -1,5 +1,6 @@
package ast;
public interface ASTNode { }
public interface ASTNode {
}

View File

@@ -1,42 +1,35 @@
package ast;
import ast.type.AccessModifierNode;
import ast.member.ConstructorNode;
import ast.member.MemberNode;
import ast.member.MethodNode;
import ast.members.MemberNode;
import ast.members.MethodNode;
import bytecode.visitor.ClassVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
public class ClassNode implements ASTNode {
public class ClassNode implements ASTNode, Visitable {
public AccessModifierNode accessType;
public String identifier;
public List<MemberNode> members = new ArrayList<>();
public boolean hasConstructor;
public ClassNode() {}
public ClassNode() {
public ClassNode(String accessType, String identifier){
}
public ClassNode(String accessType, String identifier) {
this.accessType = new AccessModifierNode(accessType);
this.identifier = identifier;
hasConstructor = false;
}
public void addMember(MemberNode member) {
if (member instanceof ConstructorNode) {
this.hasConstructor = true;
}
members.add(member);
}
public void ensureConstructor(){
if(!hasConstructor) {
ConstructorNode constructor = new ConstructorNode(new AccessModifierNode("public"), identifier);
members.addFirst(constructor);
}
}
public List<MethodNode> getMethods(){
public List<MethodNode> getMethods() {
List<MethodNode> methods = new ArrayList<>();
for (MemberNode member : members) {
if (member instanceof MethodNode methodNode) {
@@ -45,4 +38,15 @@ public class ClassNode implements ASTNode {
}
return methods;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(ClassVisitor classVisitor) {
classVisitor.visit(this);
}
}

View File

@@ -1,13 +1,27 @@
package ast;
import bytecode.visitor.ProgramVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
public class ProgramNode implements ASTNode {
public class ProgramNode implements ASTNode, Visitable {
public List<ClassNode> classes = new ArrayList<>();
public void addClass(ClassNode classNode) {
classes.add(classNode);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(ProgramVisitor programVisitor) {
programVisitor.visit(this);
}
}

View File

@@ -1,17 +0,0 @@
package ast.block;
import ast.ASTNode;
import ast.statement.IStatementNode;
import java.util.ArrayList;
import java.util.List;
public class BlockNode implements ASTNode {
public List<IStatementNode> statements = new ArrayList<>();
public BlockNode() {}
public void addStatement(IStatementNode statement) {
statements.add(statement);
}
}

View File

@@ -1,5 +0,0 @@
package ast.expression;
import ast.ASTNode;
public interface IExpressionNode extends ASTNode {}

View File

@@ -1,7 +0,0 @@
package ast.expression.binaryexpression;
import ast.expression.IExpressionNode;
import java.beans.Expression;
public class BinaryExpressionNode implements IExpressionNode {}

View File

@@ -1,19 +0,0 @@
package ast.expression.binaryexpression;
import ast.ASTNode;
public class CalculationExpressionNode extends BinaryExpressionNode {
public CalculationExpressionNode calculationExpression;
public String operator;
public DotExpressionNode dotExpression;
public CalculationExpressionNode(CalculationExpressionNode calculationExpression, String operator, DotExpressionNode dotExpression) {
this.calculationExpression = calculationExpression;
this.operator = operator;
this.dotExpression = dotExpression;
}
public CalculationExpressionNode(DotExpressionNode dotExpression) {
this.dotExpression = dotExpression;
}
}

View File

@@ -1,19 +0,0 @@
package ast.expression.binaryexpression;
import ast.ASTNode;
public class DotExpressionNode extends BinaryExpressionNode {
public DotExpressionNode dotExpression;
public String operator;
public DotSubstractionExpressionNode dotSubstractionExpression;
public DotExpressionNode(DotExpressionNode dotExpression, String operator, DotSubstractionExpressionNode dotSubstractionExpression) {
this.dotExpression = dotExpression;
this.operator = operator;
this.dotSubstractionExpression = dotSubstractionExpression;
}
public DotExpressionNode(DotSubstractionExpressionNode dotSubstractionExpression) {
this.dotSubstractionExpression = dotSubstractionExpression;
}
}

View File

@@ -1,31 +0,0 @@
package ast.expression.binaryexpression;
import ast.ASTNode;
import ast.expression.unaryexpression.MemberAccessNode;
import ast.statement.statementexpression.methodcallstatementnexpression.MethodCallStatementExpressionNode;
import ast.type.ValueNode;
public class DotSubstractionExpressionNode extends BinaryExpressionNode {
public ValueNode value;
public String identifier;
public MemberAccessNode memberAccess;
public MethodCallStatementExpressionNode methodCall;
public CalculationExpressionNode calculationExpression;
public DotSubstractionExpressionNode(ValueNode value) {
this.value = value;
}
public DotSubstractionExpressionNode(String identifier) {
this.identifier = identifier;
}
public DotSubstractionExpressionNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public DotSubstractionExpressionNode(MethodCallStatementExpressionNode methodCall, CalculationExpressionNode calculationExpression) {
this.methodCall = methodCall;
this.calculationExpression = calculationExpression;
}
}

View File

@@ -1,17 +0,0 @@
package ast.expression.binaryexpression;
import ast.ASTNode;
import ast.expression.IExpressionNode;
import ast.expression.unaryexpression.UnaryExpressionNode;
public class NonCalculationExpressionNode extends BinaryExpressionNode {
public UnaryExpressionNode unaryExpression;
public String operator;
public IExpressionNode expression;
public NonCalculationExpressionNode(UnaryExpressionNode unaryExpression, String operator, IExpressionNode expression) {
this.unaryExpression = unaryExpression;
this.operator = operator;
this.expression = expression;
}
}

View File

@@ -1,19 +0,0 @@
package ast.expression.unaryexpression;
import ast.ASTNode;
import java.util.ArrayList;
import java.util.List;
public class MemberAccessNode implements ASTNode {
public Boolean thisExpr;
public List<String> identifiers = new ArrayList<>();
public MemberAccessNode(Boolean thisExpr) {
this.thisExpr = thisExpr;
}
public void addIdentifier(String identifier) {
identifiers.add(identifier);
}
}

View File

@@ -1,12 +0,0 @@
package ast.expression.unaryexpression;
import ast.ASTNode;
import ast.expression.IExpressionNode;
public class NotExpressionNode implements ASTNode {
public IExpressionNode expression;
public NotExpressionNode(IExpressionNode expression) {
this.expression = expression;
}
}

View File

@@ -1,45 +0,0 @@
package ast.expression.unaryexpression;
import ast.expression.IExpressionNode;
import ast.statement.IStatementNode;
import ast.type.ValueNode;
import java.util.Objects;
public class UnaryExpressionNode implements IExpressionNode {
public String thisExp;
public String identifier;
public MemberAccessNode memberAccess;
public ValueNode value;
public NotExpressionNode notExpression;
public IStatementNode statement;
public IExpressionNode expression;
public UnaryExpressionNode(String value) {
if(Objects.equals(value, "this")) {
this.thisExp = "this";
} else {
this.identifier = value;
}
}
public UnaryExpressionNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public UnaryExpressionNode(ValueNode value) {
this.value = value;
}
public UnaryExpressionNode(NotExpressionNode notExpression) {
this.notExpression = notExpression;
}
public UnaryExpressionNode(IStatementNode statement) {
this.statement = statement;
}
public UnaryExpressionNode(IExpressionNode expression) {
this.expression = expression;
}
}

View File

@@ -0,0 +1,13 @@
package ast.expressions;
import ast.ASTNode;
import ast.type.type.ITypeNode;
import visitor.Visitable;
public interface IExpressionNode extends ASTNode, Visitable {
ITypeNode getType();
void setType(ITypeNode type);
}

View File

@@ -0,0 +1,33 @@
package ast.expressions.binaryexpressions;
import ast.expressions.IExpressionNode;
import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
public class BinaryNode implements IExpressionNode, Visitable {
public ITypeNode typeNode;
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public ITypeNode getType() {
return typeNode;
}
@Override
public void setType(ITypeNode type) {
this.typeNode = type;
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,43 @@
package ast.expressions.binaryexpressions;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class CalculationNode extends BinaryNode {
public CalculationNode calculationExpression;
public EnumLineOperator operator;
public DotNode dotExpression;
public CalculationNode(CalculationNode calculationExpression, String operator, DotNode dotExpression) {
this.calculationExpression = calculationExpression;
setOperator(operator);
this.dotExpression = dotExpression;
}
public CalculationNode(DotNode dotExpression) {
this.dotExpression = dotExpression;
}
public void setOperator(String operator) {
if (operator != null) {
if (operator.equals("+")) {
this.operator = EnumLineOperator.PLUS;
} else if (operator.equals("-")) {
this.operator = EnumLineOperator.MINUS;
}
}
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,40 @@
package ast.expressions.binaryexpressions;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class DotNode extends BinaryNode {
public DotNode dotExpression;
public EnumDotOperator operator;
public DotSubtractionNode dotSubtractionExpression;
public DotNode(DotNode dotExpression, String operator, DotSubtractionNode dotSubtractionExpression) {
this.dotExpression = dotExpression;
setOperator(operator);
this.dotSubtractionExpression = dotSubtractionExpression;
}
public DotNode(DotSubtractionNode dotSubtractionExpression) {
this.dotSubtractionExpression = dotSubtractionExpression;
}
public void setOperator(String operator) {
switch (operator) {
case "*" -> this.operator = EnumDotOperator.MULT;
case "/" -> this.operator = EnumDotOperator.DIV;
case "%" -> this.operator = EnumDotOperator.MOD;
}
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,44 @@
package ast.expressions.binaryexpressions;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.type.ValueNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class DotSubtractionNode extends BinaryNode {
public ValueNode value;
public String identifier;
public MemberAccessNode memberAccess;
public MethodCallNode methodCall;
public CalculationNode calculationExpression;
public DotSubtractionNode(ValueNode value) {
this.value = value;
}
public DotSubtractionNode(String identifier) {
this.identifier = identifier;
}
public DotSubtractionNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public DotSubtractionNode(MethodCallNode methodCall, CalculationNode calculationExpression) {
this.methodCall = methodCall;
this.calculationExpression = calculationExpression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,5 @@
package ast.expressions.binaryexpressions;
public enum EnumDotOperator {
MULT, DIV, MOD
}

View File

@@ -0,0 +1,5 @@
package ast.expressions.binaryexpressions;
public enum EnumLineOperator {
PLUS, MINUS
}

View File

@@ -0,0 +1,5 @@
package ast.expressions.binaryexpressions;
public enum EnumNonCalculationOperator {
AND, OR, GREATER, LESS, GREATER_EQUAL, LESS_EQUAL, EQUAL, NOT_EQUAL
}

View File

@@ -0,0 +1,43 @@
package ast.expressions.binaryexpressions;
import ast.expressions.IExpressionNode;
import ast.expressions.unaryexpressions.UnaryNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class NonCalculationNode extends BinaryNode {
public UnaryNode unaryExpression;
public EnumNonCalculationOperator operator;
public IExpressionNode expression;
public NonCalculationNode(UnaryNode unaryExpression, String operator, IExpressionNode expression) {
this.unaryExpression = unaryExpression;
setOperator(operator);
this.expression = expression;
}
public void setOperator(String operator) {
switch (operator) {
case "&&" -> this.operator = EnumNonCalculationOperator.AND;
case "||" -> this.operator = EnumNonCalculationOperator.OR;
case ">" -> this.operator = EnumNonCalculationOperator.GREATER;
case "<" -> this.operator = EnumNonCalculationOperator.LESS;
case ">=" -> this.operator = EnumNonCalculationOperator.GREATER_EQUAL;
case "<=" -> this.operator = EnumNonCalculationOperator.LESS_EQUAL;
case "==" -> this.operator = EnumNonCalculationOperator.EQUAL;
case "!=" -> this.operator = EnumNonCalculationOperator.NOT_EQUAL;
}
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,45 @@
package ast.expressions.unaryexpressions;
import ast.ASTNode;
import ast.type.type.ITypeNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
public class MemberAccessNode implements ASTNode, Visitable {
public Boolean thisExpr;
public List<String> identifiers = new ArrayList<>();
private ITypeNode typeNode;
public MemberAccessNode(Boolean thisExpr) {
this.thisExpr = thisExpr;
}
public void addIdentifier(String identifier) {
identifiers.add(identifier);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
public ITypeNode getTypeNode() {
return typeNode;
}
public void setTypeNode(ITypeNode typeNode) {
this.typeNode = typeNode;
}
}

View File

@@ -0,0 +1,35 @@
package ast.expressions.unaryexpressions;
import ast.expressions.IExpressionNode;
import ast.type.type.ITypeNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class NotNode implements IExpressionNode {
public IExpressionNode expression;
public NotNode(IExpressionNode expression) {
this.expression = expression;
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return null;
}
@Override
public ITypeNode getType() {
return expression.getType();
}
@Override
public void setType(ITypeNode type) {
this.expression.setType(type);
}
}

View File

@@ -0,0 +1,70 @@
package ast.expressions.unaryexpressions;
import ast.expressions.IExpressionNode;
import ast.statements.IStatementNode;
import ast.type.type.*;
import ast.type.ValueNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import java.util.Objects;
public class UnaryNode implements IExpressionNode {
public String thisExp;
public String identifier;
public MemberAccessNode memberAccess;
public ValueNode value;
public NotNode notExpression;
public IStatementNode statement;
public IExpressionNode expression;
public ITypeNode type;
public UnaryNode(String value) {
if (Objects.equals(value, "this")) {
this.thisExp = "this";
} else {
this.identifier = value;
}
}
public UnaryNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public UnaryNode(ValueNode value) {
this.value = value;
}
public UnaryNode(NotNode notExpression) {
this.notExpression = notExpression;
}
public UnaryNode(IStatementNode statement) {
this.statement = statement;
}
public UnaryNode(IExpressionNode expression) {
this.expression = expression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public ITypeNode getType() {
return type;
}
public void setType(ITypeNode type) {
this.type = type;
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -1,31 +0,0 @@
package ast.member;
import ast.block.BlockNode;
import ast.parameter.ParameterNode;
import ast.type.AccessModifierNode;
import java.util.ArrayList;
import java.util.List;
public class ConstructorNode extends MethodNode {
public AccessModifierNode accessType;
public String identifier;
public List<ParameterNode> parameters = new ArrayList<>();
public BlockNode body;
public ConstructorNode(AccessModifierNode accessType, String identifier) {
this.accessType = accessType;
this.identifier = identifier;
}
public ConstructorNode(String accessType, String identifier, BlockNode body) {
this.accessType = new AccessModifierNode(accessType);
this.identifier = identifier;
this.body = body;
}
public void addParameter(ParameterNode parameterNode) {
parameters.add(parameterNode);
}
}

View File

@@ -1,16 +0,0 @@
package ast.member;
import ast.type.AccessModifierNode;
import ast.type.TypeNode;
public class FieldNode implements MemberNode {
public AccessModifierNode accessTypeNode;
public TypeNode type;
public String identifier;
public FieldNode(AccessModifierNode accessTypeNode, TypeNode type, String name){
this.accessTypeNode = accessTypeNode;
this.type = type;
this.identifier = name;
}
}

View File

@@ -1,65 +0,0 @@
package ast.member;
import ast.block.BlockNode;
import ast.parameter.ParameterNode;
import ast.type.AccessModifierNode;
import ast.type.TypeNode;
import java.util.ArrayList;
import java.util.List;
public class MethodNode implements MemberNode {
public AccessModifierNode accesModifier;
public TypeNode type;
public Boolean voidType;
public String identifier;
public List<ParameterNode> parameters = new ArrayList<>();
public BlockNode block;
public MethodNode() {}
public MethodNode(BlockNode block){
this.block = block;
}
public MethodNode(String accessModifier, String type, Boolean voidType, String identifier, BlockNode block){
this.accesModifier = new AccessModifierNode(accessModifier);
this.type = new TypeNode(type);
this.voidType = voidType;
this.identifier = identifier;
this.block = block;
}
public void addParameter(ParameterNode parameter) {
this.parameters.add(parameter);
}
/*
public boolean isSame(MethodNode methodNode){
boolean isSame = false;
if(methodNode.identifier.equals(identifier)){
if(parameters != null && methodNode.parameters != null){
if(parameters.parameters.size() == methodNode.parameters.parameters.size()){
for(int i = 0; i < parameters.parameters.size(); i++){
if(parameters.parameters.get(i).identifier.equals(methodNode.parameters.parameters.get(i).identifier)){
isSame = true;
}
}
}
}
}
return isSame;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
*/
}

View File

@@ -0,0 +1,41 @@
package ast.members;
import ast.parameters.ParameterNode;
import ast.statements.BlockNode;
import ast.type.AccessModifierNode;
import bytecode.visitor.MethodVisitor;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ConstructorNode extends MethodNode implements Visitable {
public ConstructorNode(String accessType, String identifier, BlockNode block) {
this.accesModifier = new AccessModifierNode(accessType);
this.identifier = identifier;
this.block = block;
}
public void addParameter(ParameterNode parameterNode) {
parameters.add(parameterNode);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
public boolean isSame(MethodNode methodNode) {
if (!(Objects.equals(this.identifier, methodNode.getIdentifier())) || getParameters().size() != methodNode.getParameters().size()) {
return false;
}
for (int i = 0; i < this.getParameters().size(); i++) {
if (!this.getParameters().get(i).type.equals(methodNode.getParameters().get(i).type)) {
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,31 @@
package ast.members;
import ast.type.AccessModifierNode;
import ast.type.type.ITypeNode;
import bytecode.visitor.ClassVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
public class FieldNode implements MemberNode, Visitable {
public AccessModifierNode accessTypeNode;
public ITypeNode type;
public String identifier;
public FieldNode(AccessModifierNode accessTypeNode, ITypeNode type, String name) {
this.accessTypeNode = accessTypeNode;
this.type = type;
this.identifier = name;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(ClassVisitor classVisitor) {
classVisitor.visit(this);
}
}

View File

@@ -0,0 +1,17 @@
package ast.members;
import ast.statements.BlockNode;
import bytecode.visitor.MethodVisitor;
import visitor.Visitable;
public class MainMethodNode extends MethodNode implements Visitable {
public MainMethodNode(BlockNode block) {
this.block = block;
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -1,4 +1,4 @@
package ast.member;
package ast.members;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSubTypes;
@@ -10,7 +10,8 @@ import ast.ASTNode;
@JsonSubTypes({
@JsonSubTypes.Type(value = MethodNode.class, name = "Method"),
@JsonSubTypes.Type(value = FieldNode.class, name = "Field") }
@JsonSubTypes.Type(value = FieldNode.class, name = "Field")}
)
public interface MemberNode extends ASTNode {}
public interface MemberNode extends ASTNode {
}

View File

@@ -0,0 +1,83 @@
package ast.members;
import ast.parameters.ParameterNode;
import ast.statements.BlockNode;
import ast.type.AccessModifierNode;
import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class MethodNode implements MemberNode, Visitable {
public AccessModifierNode accesModifier;
public ITypeNode type;
public Boolean voidType;
public String identifier;
public List<ParameterNode> parameters = new ArrayList<>();
public BlockNode block;
public MethodNode() {
}
public MethodNode(String accessModifier, ITypeNode type, Boolean voidType, String identifier, BlockNode block) {
this.accesModifier = new AccessModifierNode(accessModifier);
this.type = type;
this.voidType = voidType;
this.identifier = identifier;
this.block = block;
}
public void addParameter(ParameterNode parameter) {
this.parameters.add(parameter);
}
public List<ParameterNode> getParameters() {
return parameters;
}
public boolean isSame(MethodNode methodNode) {
if (!(Objects.equals(this.identifier, methodNode.getIdentifier())) || type.equals(methodNode.type)
|| getParameters().size() != methodNode.getParameters().size()) {
return false;
}
for (int i = 0; i < this.getParameters().size(); i++) {
if (!this.getParameters().get(i).type.equals(methodNode.getParameters().get(i).type)) {
return false;
}
}
return true;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
public String getIdentifier() {
return identifier;
}
public ITypeNode getType() {
return type;
}
public void setType(ITypeNode type) {
this.type = type;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
}

View File

@@ -1,14 +0,0 @@
package ast.parameter;
import ast.ASTNode;
import ast.type.TypeNode;
public class ParameterNode implements ASTNode {
public TypeNode type;
public String identifier;
public ParameterNode(TypeNode type, String identifier) {
this.type = type;
this.identifier = identifier;
}
}

View File

@@ -0,0 +1,23 @@
package ast.parameters;
import ast.ASTNode;
import ast.type.type.*;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
public class ParameterNode implements ASTNode, Visitable {
public ITypeNode type;
public String identifier;
public ParameterNode(ITypeNode type, String identifier) {
this.type = type;
this.identifier = identifier;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@@ -1,23 +0,0 @@
package ast.statement;
import ast.ASTNode;
import ast.expression.IExpressionNode;
public class ForStatementNode implements IStatementNode {
public IExpressionNode statementExpressionInit;
public IStatementNode localVariableDeclarationInit;
public IExpressionNode expression;
public IExpressionNode statementExpression;
public ForStatementNode(IExpressionNode statementExpressionInit, IExpressionNode expression, IExpressionNode statementExpression) {
this.statementExpressionInit = statementExpressionInit;
this.expression = expression;
this.statementExpression = statementExpression;
}
public ForStatementNode(IStatementNode localVariableDeclarationInit, IExpressionNode expression, IExpressionNode statementExpression) {
this.localVariableDeclarationInit = localVariableDeclarationInit;
this.expression = expression;
this.statementExpression = statementExpression;
}
}

View File

@@ -1,6 +0,0 @@
package ast.statement;
import ast.ASTNode;
public interface IStatementNode extends ASTNode {
}

View File

@@ -1,19 +0,0 @@
package ast.statement;
import ast.ASTNode;
import ast.expression.IExpressionNode;
import ast.type.TypeNode;
public class LocalVariableDeclarationNode implements IStatementNode {
public TypeNode type;
public String identifier;
public String assign;
public IExpressionNode expression;
public LocalVariableDeclarationNode(TypeNode type, String identifier, String assign, IExpressionNode expression) {
this.type = type;
this.identifier = identifier;
this.assign = assign;
this.expression = expression;
}
}

View File

@@ -1,12 +0,0 @@
package ast.statement;
import ast.ASTNode;
import ast.expression.IExpressionNode;
public class ReturnStatementNode implements IStatementNode {
public IExpressionNode expression;
public ReturnStatementNode(IExpressionNode expression) {
this.expression = expression;
}
}

View File

@@ -1,15 +0,0 @@
package ast.statement;
import ast.ASTNode;
import ast.block.BlockNode;
import ast.expression.IExpressionNode;
public class WhileStatementNode implements IStatementNode {
public IExpressionNode expression;
public BlockNode block;
public WhileStatementNode(IExpressionNode expression, BlockNode block) {
this.expression = expression;
this.block = block;
}
}

View File

@@ -1,13 +0,0 @@
package ast.statement.ifstatement;
import ast.ASTNode;
import ast.block.BlockNode;
import ast.statement.IStatementNode;
public class ElseStatementNode implements IStatementNode {
public BlockNode block;
public ElseStatementNode(BlockNode block) {
this.block = block;
}
}

View File

@@ -1,21 +0,0 @@
package ast.statement.ifstatement;
import ast.ASTNode;
import ast.statement.IStatementNode;
import java.util.ArrayList;
import java.util.List;
public class IfElseStatementNode implements IStatementNode {
public IfStatementNode ifStatement;
public List<ElseStatementNode> elseStatements = new ArrayList<>();
public IfElseStatementNode(IfStatementNode ifStatement) {
this.ifStatement = ifStatement;
}
public void addElseStatement(ElseStatementNode elseStatement) {
elseStatements.add(elseStatement);
}
}

View File

@@ -1,16 +0,0 @@
package ast.statement.ifstatement;
import ast.ASTNode;
import ast.block.BlockNode;
import ast.expression.IExpressionNode;
import ast.statement.IStatementNode;
public class IfStatementNode implements IStatementNode {
public IExpressionNode expression;
public BlockNode block;
public IfStatementNode(IExpressionNode expression, BlockNode block) {
this.expression = expression;
this.block = block;
}
}

View File

@@ -1,14 +0,0 @@
package ast.statement.statementexpression;
import ast.ASTNode;
import ast.expression.IExpressionNode;
public class AssignStatementExpressionNode implements IStatementExpressionNode {
public AssignableExpressionNode assignable;
public IExpressionNode expression;
public AssignStatementExpressionNode(AssignableExpressionNode assignable, IExpressionNode expression) {
this.assignable = assignable;
this.expression = expression;
}
}

View File

@@ -1,17 +0,0 @@
package ast.statement.statementexpression;
import ast.ASTNode;
import ast.expression.unaryexpression.MemberAccessNode;
public class AssignableExpressionNode implements IStatementExpressionNode {
public String identifier;
public MemberAccessNode memberAccess;
public AssignableExpressionNode(String identifier) {
this.identifier = identifier;
}
public AssignableExpressionNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
}

View File

@@ -1,5 +0,0 @@
package ast.statement.statementexpression;
import ast.statement.IStatementNode;
public interface IStatementExpressionNode extends IStatementNode {}

View File

@@ -1,20 +0,0 @@
package ast.statement.statementexpression;
import ast.ASTNode;
import ast.expression.IExpressionNode;
import java.util.ArrayList;
import java.util.List;
public class NewDeclarationStatementExpressionNode implements IStatementExpressionNode {
public String identifier;
public List<IExpressionNode> expressions = new ArrayList<>();
public NewDeclarationStatementExpressionNode(String identifier) {
this.identifier = identifier;
}
public void addExpression(IExpressionNode expression) {
expressions.add(expression);
}
}

View File

@@ -1,5 +0,0 @@
package ast.statement.statementexpression.crementExpression;
public enum CrementType {
PREFIX, SUFFIX
}

View File

@@ -1,14 +0,0 @@
package ast.statement.statementexpression.crementExpression;
import ast.ASTNode;
import ast.statement.statementexpression.AssignableExpressionNode;
import ast.statement.statementexpression.IStatementExpressionNode;
public class DecrementExpressionNode implements IStatementExpressionNode {
public CrementType crementType;
public AssignableExpressionNode assignableExpression;
public DecrementExpressionNode(CrementType crementType, AssignableExpressionNode assignableExpression) {
this.assignableExpression = assignableExpression;
}
}

View File

@@ -1,14 +0,0 @@
package ast.statement.statementexpression.crementExpression;
import ast.ASTNode;
import ast.statement.statementexpression.AssignableExpressionNode;
import ast.statement.statementexpression.IStatementExpressionNode;
public class IncrementExpressionNode implements IStatementExpressionNode {
public CrementType crementType;
public AssignableExpressionNode assignableExpression;
public IncrementExpressionNode(CrementType crementType, AssignableExpressionNode assignableExpression) {
this.assignableExpression = assignableExpression;
}
}

View File

@@ -1,20 +0,0 @@
package ast.statement.statementexpression.methodcallstatementnexpression;
import ast.ASTNode;
import ast.expression.IExpressionNode;
import java.util.ArrayList;
import java.util.List;
public class ChainedMethodNode implements ASTNode {
public String identifier;
public List<IExpressionNode> expressions = new ArrayList<>();
public ChainedMethodNode(String identifier) {
this.identifier = identifier;
}
public void addExpression(IExpressionNode expression) {
expressions.add(expression);
}
}

View File

@@ -1,30 +0,0 @@
package ast.statement.statementexpression.methodcallstatementnexpression;
import ast.ASTNode;
import ast.expression.IExpressionNode;
import ast.statement.statementexpression.IStatementExpressionNode;
import java.util.ArrayList;
import java.util.List;
public class MethodCallStatementExpressionNode implements IStatementExpressionNode {
public TargetNode target;
public List<ChainedMethodNode> chainedMethods = new ArrayList<>();
public String identifier;
public List<IExpressionNode> expressions = new ArrayList<>();
public MethodCallStatementExpressionNode(TargetNode target, String identifier) {
this.target = target;
this.identifier = identifier;
}
public void addChainedMethod(ChainedMethodNode chainedMethode) {
chainedMethods.add(chainedMethode);
}
public void addExpression(IExpressionNode expression) {
expressions.add(expression);
}
}

View File

@@ -1,28 +0,0 @@
package ast.statement.statementexpression.methodcallstatementnexpression;
import ast.ASTNode;
import ast.expression.unaryexpression.MemberAccessNode;
import ast.statement.statementexpression.NewDeclarationStatementExpressionNode;
public class TargetNode implements ASTNode {
public Boolean thisTar;
public MemberAccessNode memberAccess;
public NewDeclarationStatementExpressionNode newDeclaration;
public String identifier;
public TargetNode(Boolean thisTar) {
this.thisTar = thisTar;
}
public TargetNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public TargetNode(NewDeclarationStatementExpressionNode newDeclaration) {
this.newDeclaration = newDeclaration;
}
public TargetNode(String identifier) {
this.identifier = identifier;
}
}

View File

@@ -0,0 +1,27 @@
package ast.statementexpressions;
import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class AssignNode implements IStatementExpressionNode {
public AssignableNode assignable;
public IExpressionNode expression;
public AssignNode(AssignableNode assignable, IExpressionNode expression) {
this.assignable = assignable;
this.expression = expression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,32 @@
package ast.statementexpressions;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.type.type.ITypeNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class AssignableNode implements IStatementExpressionNode {
public String identifier;
public ITypeNode typeNode;
public MemberAccessNode memberAccess;
public AssignableNode(String identifier) {
this.identifier = identifier;
}
public AssignableNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
public void setTypeNode(ITypeNode typeNode) {
this.typeNode = typeNode;
}
}

View File

@@ -0,0 +1,6 @@
package ast.statementexpressions;
import ast.statements.IStatementNode;
public interface IStatementExpressionNode extends IStatementNode {
}

View File

@@ -0,0 +1,33 @@
package ast.statementexpressions;
import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import java.util.ArrayList;
import java.util.List;
public class NewDeclarationNode implements IStatementExpressionNode {
public String identifier;
public List<IExpressionNode> expressions = new ArrayList<>();
public NewDeclarationNode(String identifier) {
this.identifier = identifier;
}
public void addExpression(IExpressionNode expression) {
expressions.add(expression);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,5 @@
package ast.statementexpressions.crementexpressions;
public enum CrementType {
PREFIX, SUFFIX
}

View File

@@ -0,0 +1,28 @@
package ast.statementexpressions.crementexpressions;
import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.IStatementExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
public class DecrementNode implements IStatementExpressionNode, Visitable {
public CrementType crementType;
public AssignableNode assignableExpression;
public DecrementNode(CrementType crementType, AssignableNode assignableExpression) {
this.crementType = crementType;
this.assignableExpression = assignableExpression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,28 @@
package ast.statementexpressions.crementexpressions;
import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.IStatementExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import visitor.Visitable;
import semantic.TypeCheckResult;
public class IncrementNode implements IStatementExpressionNode, Visitable {
public CrementType crementType;
public AssignableNode assignableExpression;
public IncrementNode(CrementType crementType, AssignableNode assignableExpression) {
this.crementType = crementType;
this.assignableExpression = assignableExpression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,29 @@
package ast.statementexpressions.methodcallstatementnexpressions;
import ast.ASTNode;
import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
public class ChainedMethodNode implements ASTNode, Visitable {
public String identifier;
public List<IExpressionNode> expressions = new ArrayList<>();
public ChainedMethodNode(String identifier) {
this.identifier = identifier;
}
public void addExpression(IExpressionNode expression) {
expressions.add(expression);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return null;
}
}

View File

@@ -0,0 +1,43 @@
package ast.statementexpressions.methodcallstatementnexpressions;
import ast.expressions.IExpressionNode;
import ast.statements.IStatementNode;
import ast.type.type.ITypeNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import java.util.ArrayList;
import java.util.List;
public class MethodCallNode implements IStatementNode {
public TargetNode target;
public ITypeNode type;
public List<ChainedMethodNode> chainedMethods = new ArrayList<>();
public String identifier;
public List<IExpressionNode> parameters = new ArrayList<>();
public MethodCallNode(TargetNode target, String identifier) {
this.target = target;
this.identifier = identifier;
}
public void addChainedMethod(ChainedMethodNode chainedMethode) {
chainedMethods.add(chainedMethode);
}
public void addExpression(IExpressionNode parameter) {
parameters.add(parameter);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,37 @@
package ast.statementexpressions.methodcallstatementnexpressions;
import ast.ASTNode;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.statementexpressions.NewDeclarationNode;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
public class TargetNode implements ASTNode, Visitable {
public Boolean thisTar;
public MemberAccessNode memberAccess;
public NewDeclarationNode newDeclaration;
public String identifier;
public TargetNode(Boolean thisTar) {
this.thisTar = thisTar;
}
public TargetNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public TargetNode(NewDeclarationNode newDeclaration) {
this.newDeclaration = newDeclaration;
}
public TargetNode(String identifier) {
this.identifier = identifier;
}
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@@ -0,0 +1,31 @@
package ast.statements;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
import java.util.List;
public class BlockNode implements IStatementNode, Visitable {
public List<IStatementNode> statements = new ArrayList<>();
public BlockNode() {
}
public void addStatement(IStatementNode statement) {
statements.add(statement);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,19 @@
package ast.statements;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class ElseNode implements IStatementNode {
public BlockNode block;
public ElseNode(BlockNode block) {
this.block = block;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@@ -0,0 +1,7 @@
package ast.statements;
import ast.ASTNode;
import visitor.Visitable;
public interface IStatementNode extends ASTNode, Visitable {
}

View File

@@ -0,0 +1,33 @@
package ast.statements;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import java.util.ArrayList;
import java.util.List;
public class IfElseNode implements IStatementNode {
public IfNode ifStatement;
public List<IfNode> elseIfStatements = new ArrayList<>();
public ElseNode elseStatement;
public IfElseNode(IfNode ifStatement, ElseNode elseNode) {
this.ifStatement = ifStatement;
this.elseStatement = elseNode;
}
public void addElseIfStatement(IfNode elseIfStament) {
elseIfStatements.add(elseIfStament);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@@ -0,0 +1,20 @@
package ast.statements;
import ast.expressions.IExpressionNode;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class IfNode implements IStatementNode {
public IExpressionNode expression;
public BlockNode block;
public IfNode(IExpressionNode expression, BlockNode block) {
this.expression = expression;
this.block = block;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@@ -0,0 +1,32 @@
package ast.statements;
import ast.expressions.IExpressionNode;
import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class LocalVariableDeclarationNode implements IStatementNode {
public ITypeNode type;
public String identifier;
public String assign;
public IExpressionNode expression;
public LocalVariableDeclarationNode(ITypeNode type, String identifier, String assign, IExpressionNode expression) {
this.type = type;
this.identifier = identifier;
this.assign = assign;
this.expression = expression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,30 @@
package ast.statements;
import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class ReturnNode implements IStatementNode {
public IExpressionNode expression;
public Boolean voidReturn = false;
public ReturnNode(IExpressionNode expression) {
if (expression != null) {
this.expression = expression;
} else {
voidReturn = true;
}
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@@ -0,0 +1,30 @@
package ast.statements;
import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class WhileNode implements IStatementNode {
public IExpressionNode expression;
public BlockNode block;
public WhileNode(IExpressionNode expression, BlockNode block) {
this.expression = expression;
this.block = block;
}
public void test() {
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@@ -8,7 +8,7 @@ public class AccessModifierNode {
}
private void setModifier(String accessType) {
switch(accessType) {
switch (accessType) {
case "public":
this.accessType = EnumAccessModifierNode.PUBLIC;
break;

View File

@@ -1,5 +0,0 @@
package ast.type;
public enum EnumTypeNode {
INT, BOOLEAN, CHAR, IDENTIFIER
}

View File

@@ -1,25 +0,0 @@
package ast.type;
public class TypeNode {
public EnumTypeNode type;
public TypeNode(String type) {
setType(type);
}
private void setType(String type) {
switch(type) {
case "int":
this.type = EnumTypeNode.INT;
break;
case "boolean":
this.type = EnumTypeNode.BOOLEAN;
break;
case "char":
this.type = EnumTypeNode.CHAR;
break;
default:
this.type = EnumTypeNode.IDENTIFIER;
}
}
}

View File

@@ -1,8 +1,12 @@
package ast.type;
import ast.ASTNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import visitor.Visitable;
public class ValueNode implements ASTNode {
public class ValueNode implements ASTNode, Visitable {
public EnumValueNode valueType;
public String value;
@@ -10,4 +14,14 @@ public class ValueNode implements ASTNode {
this.valueType = valueType;
this.value = value;
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@@ -0,0 +1,26 @@
package ast.type.type;
public class BaseType implements ITypeNode {
public final TypeEnum typeEnum;
public BaseType(TypeEnum typeEnum) {
this.typeEnum = typeEnum;
}
public TypeEnum getTypeEnum() {
return typeEnum;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BaseType other = (BaseType) obj;
return typeEnum == other.typeEnum;
}
}

View File

@@ -0,0 +1,4 @@
package ast.type.type;
public interface ITypeNode {
}

View File

@@ -0,0 +1,30 @@
package ast.type.type;
public class ReferenceType implements ITypeNode {
public final String identifier;
public ReferenceType(String identifier) {
this.identifier = identifier;
}
public String getIdentifier() {
return identifier;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ReferenceType other = (ReferenceType) obj;
if (identifier == null) {
return other.identifier == null;
} else return identifier.equals(other.identifier);
}
}

View File

@@ -0,0 +1,9 @@
package ast.type.type;
public enum TypeEnum {
VOID,
INT,
CHAR,
BOOL,
NULL
}

View File

@@ -2,15 +2,89 @@ package bytecode;
import ast.ProgramNode;
import ast.ClassNode;
import ast.members.MainMethodNode;
import ast.members.MemberNode;
import bytecode.visitor.ProgramVisitor;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
public class ByteCodeGenerator implements ProgramVisitor {
@Override
public void visit(ProgramNode programNode) {
for (ClassNode classDeclarationNode : programNode.classes) {
ClassCodeGen classCodeGen = new ClassCodeGen();
classDeclarationNode.accept(classCodeGen);
private JarOutputStream jarOutputStream;
private ByteArrayOutputStream byteArrayOutputStream;
private final String outputDirectory;
private final boolean generateJar;
private final boolean generateClassFiles;
public ByteCodeGenerator(String outputDirectory, boolean generateJar, boolean generateClassFiles) {
this.outputDirectory = outputDirectory;
this.generateJar = generateJar;
this.generateClassFiles = generateClassFiles;
}
@Override
public void visit(ProgramNode programNode) {
if(generateJar) {
byteArrayOutputStream = new ByteArrayOutputStream();
try {
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
boolean foundMainClass = false;
for (ClassNode classNode : programNode.classes) {
if (foundMainClass) {
break;
}
for (MemberNode memberNode : classNode.members) {
if (memberNode instanceof MainMethodNode) {
manifest.getMainAttributes().putValue("Main-Class", classNode.identifier);
foundMainClass = true;
break;
}
}
}
jarOutputStream = new JarOutputStream(byteArrayOutputStream, manifest);
} catch (IOException e) {
throw new RuntimeException(e);
}
for (ClassNode classDeclarationNode : programNode.classes) {
ClassCodeGen classCodeGen = new ClassCodeGen(jarOutputStream, outputDirectory, generateJar, generateClassFiles);
classDeclarationNode.accept(classCodeGen);
}
try {
jarOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
saveJarFile(byteArrayOutputStream.toByteArray(), "output.jar");
} else {
for (ClassNode classDeclarationNode : programNode.classes) {
ClassCodeGen classCodeGen = new ClassCodeGen(jarOutputStream, outputDirectory, generateJar, generateClassFiles);
classDeclarationNode.accept(classCodeGen);
}
}
}
private void saveJarFile(byte[] jarBytes, String jarFileName) {
File directory = new File(outputDirectory);
if (!directory.exists()) {
directory.mkdirs();
}
File jarFile = new File(directory, jarFileName);
try (FileOutputStream fos = new FileOutputStream(jarFile)) {
fos.write(jarBytes);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@@ -1,25 +1,37 @@
package bytecode;
import ast.ClassNode;
import ast.member.FieldNode;
import ast.member.MemberNode;
import ast.member.MethodNode;
import ast.type.BaseTypeNode;
import ast.members.FieldNode;
import ast.members.MemberNode;
import ast.members.MethodNode;
import ast.type.type.BaseType;
import bytecode.visitor.ClassVisitor;
import java.io.File;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
public class ClassCodeGen implements ClassVisitor {
private Mapper mapper;
private final Mapper mapper;
private ClassWriter classWriter;
private final JarOutputStream jarOutputStream;
private final String outputDirectory;
private final boolean generateJar;
private final boolean generateClassFiles;
public ClassCodeGen() {
mapper = new Mapper();
public ClassCodeGen(JarOutputStream jarOutputStream, String outputDirectory, boolean generateJar, boolean generateClassFiles) {
this.mapper = new Mapper();
this.jarOutputStream = jarOutputStream;
this.outputDirectory = outputDirectory;
this.generateJar = generateJar;
this.generateClassFiles = generateClassFiles;
}
@Override
@@ -37,28 +49,31 @@ public class ClassCodeGen implements ClassVisitor {
}
}
classWriter.visitEnd();
printIntoClassFile(classWriter.toByteArray(), classNode.identifier);
if (generateJar) {
writeToJar(classWriter.toByteArray(), classNode.identifier);
}
if (generateClassFiles) {
printIntoClassFile(classWriter.toByteArray(), classNode.identifier, outputDirectory);
}
classWriter.visitEnd();
}
@Override
public void visit(FieldNode fieldNode) {
if(fieldNode.type instanceof BaseTypeNode baseTypeNode){
classWriter.visitField(mapper.mapAccessTypeToOpcode(fieldNode.accessTypeNode), fieldNode.identifier, mapper.getTypeChar(baseTypeNode.enumType), null, null );
if (fieldNode.type instanceof BaseType) {
classWriter.visitField(mapper.mapAccessTypeToOpcode(fieldNode.accessTypeNode), fieldNode.identifier, mapper.getTypeChar((BaseType) fieldNode.type), null, null);
}
classWriter.visitEnd();
}
private void printIntoClassFile(byte[] byteCode, String name) {
String directoryPath = "src/main/java/classFileOutput";
File directory = new File(directoryPath);
private void printIntoClassFile(byte[] byteCode, String name, String outputDirectory) {
File directory = new File(outputDirectory);
if (!directory.exists()) {
directory.mkdirs();
}
String filePath = directoryPath + "/" + name + ".class";
String filePath = outputDirectory + "/" + name + ".class";
try {
FileOutputStream fileOutputStream = new FileOutputStream(filePath);
fileOutputStream.write(byteCode);
@@ -67,4 +82,15 @@ public class ClassCodeGen implements ClassVisitor {
e.printStackTrace();
}
}
private void writeToJar(byte[] byteCode, String className) {
try {
JarEntry jarEntry = new JarEntry(className + ".class");
jarOutputStream.putNextEntry(jarEntry);
jarOutputStream.write(byteCode);
jarOutputStream.closeEntry();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -1,43 +1,64 @@
package bytecode;
import ast.parameter.ParameterNode;
import ast.parameters.ParameterNode;
import ast.type.*;
import ast.type.type.BaseType;
import ast.type.type.ITypeNode;
import ast.type.type.ReferenceType;
import ast.type.type.TypeEnum;
import org.objectweb.asm.Opcodes;
import ast.type.BaseTypeNode;
import java.util.List;
public class Mapper {
public int mapAccessTypeToOpcode(AccessTypeNode type) {
switch (type.enumAccessTypeNode) {
case EnumAccessTypeNode.PUBLIC:
public int mapAccessTypeToOpcode(AccessModifierNode accessModifierNode) {
switch (accessModifierNode.accessType) {
case EnumAccessModifierNode.PUBLIC:
return Opcodes.ACC_PUBLIC;
case EnumAccessTypeNode.PRIVATE:
case EnumAccessModifierNode.PRIVATE:
return Opcodes.ACC_PRIVATE;
case EnumAccessModifierNode.PUBLIC_STATIC:
return Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC;
case EnumAccessModifierNode.PRIVATE_STATIC:
return Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC;
}
return 0;
}
public String generateMethodDescriptor(BaseTypeNode baseTypeNode, ParameterListNode parameterListNode) {
public String generateMethodDescriptor(ITypeNode type, List<ParameterNode> parameters) {
String descriptor = "(";
for(ParameterNode parameterNode : parameterListNode.parameters) {
descriptor += getTypeChar(EnumTypeNode.INT);
for (ParameterNode parameterNode : parameters) {
if(parameterNode.type instanceof BaseType) {
descriptor += getTypeChar((BaseType) parameterNode.type);
} else {
ReferenceType referenceType = (ReferenceType) parameterNode.type;
descriptor += "L" + referenceType.getIdentifier() + ";";
}
}
descriptor += ")";
descriptor += getTypeChar(baseTypeNode.enumType);
if(type instanceof BaseType) {
descriptor += getTypeChar((BaseType) type);
} else if(type instanceof ReferenceType) {
descriptor += "L" + ((ReferenceType) type).getIdentifier() +";";
}
return descriptor;
}
public String getTypeChar(EnumTypeNode enumTypeNode) {
public String getTypeChar(BaseType type) {
String typeChar = "";
switch (enumTypeNode) {
case EnumTypeNode.INT:
switch (type.getTypeEnum()) {
case TypeEnum.INT:
typeChar = "I";
break;
case EnumTypeNode.CHAR:
case TypeEnum.CHAR:
typeChar = "C";
break;
case EnumTypeNode.BOOLEAN:
case TypeEnum.BOOL:
typeChar = "Z";
break;
case TypeEnum.VOID:
typeChar = "V";
break;
}
return typeChar;
}

View File

@@ -1,9 +1,28 @@
package bytecode;
import ast.member.ConstructorNode;
import ast.member.MethodNode;
import ast.parameter.ParameterNode;
import ast.type.BaseTypeNode;
import ast.expressions.IExpressionNode;
import ast.expressions.binaryexpressions.*;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.expressions.unaryexpressions.NotNode;
import ast.expressions.unaryexpressions.UnaryNode;
import ast.members.ConstructorNode;
import ast.members.MainMethodNode;
import ast.members.MethodNode;
import ast.parameters.ParameterNode;
import ast.statementexpressions.AssignNode;
import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.NewDeclarationNode;
import ast.statementexpressions.crementexpressions.CrementType;
import ast.statementexpressions.crementexpressions.DecrementNode;
import ast.statementexpressions.crementexpressions.IncrementNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statements.*;
import ast.type.AccessModifierNode;
import ast.type.EnumAccessModifierNode;
import ast.type.ValueNode;
import ast.type.type.BaseType;
import ast.type.type.ReferenceType;
import ast.type.type.TypeEnum;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
@@ -17,82 +36,709 @@ import static org.objectweb.asm.Opcodes.*;
public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
private ClassWriter classWriter;
private Mapper mapper;
private final ClassWriter classWriter;
private final Mapper mapper;
private MethodVisitor methodVisitor;
private List<String> localVaribales;
private final List<String> localVariables;
public MethodCodeGen(ClassWriter classWriter) {
this.classWriter = classWriter;
mapper = new Mapper();
localVaribales = new ArrayList<>();
localVariables = new ArrayList<>();
}
// Method nodes
@Override
public void visit(ConstructorNode constructorNode) {
methodVisitor =
classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.visibility),
classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.accesModifier),
"<init>",
"()V",
mapper.generateMethodDescriptor(new BaseType(TypeEnum.VOID), constructorNode.parameters),
null,
null);
methodVisitor.visitCode();
localVariables.add("this");
// Add all method parameters to localVariables
for (ParameterNode parameterNode : constructorNode.parameters) {
localVariables.add(parameterNode.identifier);
}
methodVisitor.visitVarInsn(ALOAD, 0);
methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
methodVisitor.visitInsn(RETURN);
methodVisitor.visitMaxs(1, 1);
// Visit all statements
for (IStatementNode statementNode : constructorNode.block.statements) {
statementNode.accept(this);
}
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
}
@Override
public void visit(MainMethodNode mainMethodNode) {
AccessModifierNode accessModifierNode = new AccessModifierNode("");
accessModifierNode.accessType = EnumAccessModifierNode.PUBLIC_STATIC;
methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
"main",
"([Ljava/lang/String;)V",
null,
null);
methodVisitor.visitCode();
localVariables.add("this");
localVariables.add("args");
// Visit all statements
for (IStatementNode statementNode : mainMethodNode.block.statements) {
statementNode.accept(this);
}
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
}
@Override
public void visit(MethodNode methodNode) {
if (methodNode.type instanceof BaseTypeNode baseTypeNode) {
methodVisitor = classWriter.visitMethod(mapper.mapAccessTypeToOpcode(methodNode.visibility),
methodNode.identifier,
mapper.generateMethodDescriptor(baseTypeNode, methodNode.parameters),
null,
null);
methodVisitor = classWriter.visitMethod(mapper.mapAccessTypeToOpcode(methodNode.accesModifier),
methodNode.getIdentifier(),
mapper.generateMethodDescriptor(methodNode.getType(), methodNode.parameters),
null,
null);
methodVisitor.visitCode();
localVaribales.add("this");
for (ParameterNode parameterNode : methodNode.parameters.parameters) {
localVaribales.add(parameterNode.identifier);
methodVisitor.visitCode();
localVariables.add("this");
// Add all method parameters to localVariables
for (ParameterNode parameterNode : methodNode.parameters) {
localVariables.add(parameterNode.identifier);
}
// Visit all statements
for (IStatementNode statementNode : methodNode.block.statements) {
statementNode.accept(this);
}
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
}
// Binary expressions
@Override
public void visit(BinaryNode binaryNode) {
binaryNode.accept(this);
}
@Override
public void visit(CalculationNode calculationNode) {
if (calculationNode.calculationExpression != null) {
calculationNode.calculationExpression.accept(this);
}
if (calculationNode.dotExpression != null) {
calculationNode.dotExpression.accept(this);
}
if (calculationNode.operator != null) {
switch (calculationNode.operator) {
case PLUS:
methodVisitor.visitInsn(IADD);
break;
case MINUS:
methodVisitor.visitInsn(ISUB);
break;
}
//test();
methodVisitor.visitMaxs(1, localVaribales.size());
methodVisitor.visitEnd();
}
}
public void test() {
Label start = new Label();
Label loop = new Label();
Label end = new Label();
methodVisitor.visitLabel(start);
//methodVisitor.visitVarInsn(Opcodes.ICONST_M1, 99);
//methodVisitor.visitInsn(Opcodes.ICONST_5);
methodVisitor.visitLdcInsn(99);
// methodVisitor.visitInsn(Opcodes.ICONST_0);
//methodVisitor.visitVarInsn(Opcodes.ILOAD, 2);
methodVisitor.visitVarInsn(Opcodes.ISTORE, 1);
methodVisitor.visitLabel(loop);
methodVisitor.visitVarInsn(Opcodes.ILOAD, 1);
methodVisitor.visitInsn(Opcodes.ICONST_5);
methodVisitor.visitJumpInsn(Opcodes.IF_ICMPGE, end);
methodVisitor.visitFieldInsn(Opcodes.GETSTATIC,
"java/lang/System", "out",
"Ljava/io/PrintStream;");
methodVisitor.visitLdcInsn("Bytecode");
methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
"java/io/PrintStream", "println",
"(Ljava/lang/String;)V", false);
methodVisitor.visitIincInsn(1, 1);
methodVisitor.visitJumpInsn(Opcodes.GOTO, loop);
methodVisitor.visitLabel(end);
methodVisitor.visitVarInsn(Opcodes.ILOAD, 1);
methodVisitor.visitInsn(Opcodes.IRETURN);
methodVisitor.visitEnd();
@Override
public void visit(DotNode dotNode) {
if (dotNode.dotExpression != null) {
dotNode.dotExpression.accept(this);
}
if (dotNode.dotSubtractionExpression != null) {
dotNode.dotSubtractionExpression.accept(this);
}
if (dotNode.operator != null) {
switch (dotNode.operator) {
case DIV:
methodVisitor.visitInsn(IDIV);
break;
case MULT:
methodVisitor.visitInsn(IMUL);
break;
case MOD:
methodVisitor.visitInsn(IREM);
break;
}
}
}
@Override
public void visit(DotSubtractionNode dotSubtractionNode) {
if (dotSubtractionNode.value != null) {
dotSubtractionNode.value.accept(this);
} else if (dotSubtractionNode.identifier != null) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(dotSubtractionNode.identifier));
} else if (dotSubtractionNode.memberAccess != null) {
dotSubtractionNode.memberAccess.accept(this);
} else if (dotSubtractionNode.methodCall != null) {
dotSubtractionNode.methodCall.accept(this);
} else if (dotSubtractionNode.calculationExpression != null) {
dotSubtractionNode.calculationExpression.accept(this);
}
}
@Override
public void visit(NonCalculationNode nonCalculationNode) {
Label labelFalse = new Label();
Label labelTrue = new Label();
switch (nonCalculationNode.operator) {
case AND:
nonCalculationNode.unaryExpression.accept(this);
methodVisitor.visitJumpInsn(IFEQ, labelFalse); // Value compared to 0 (false)
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IFEQ, labelFalse);
break;
case OR:
nonCalculationNode.unaryExpression.accept(this);
methodVisitor.visitJumpInsn(IFNE, labelTrue);
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IFEQ, labelFalse);
break;
case GREATER:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IF_ICMPLE, labelFalse);
break;
case LESS:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IF_ICMPGE, labelFalse);
break;
case GREATER_EQUAL:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IF_ICMPLT, labelFalse);
break;
case LESS_EQUAL:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
methodVisitor.visitJumpInsn(IF_ICMPGT, labelFalse);
break;
case EQUAL:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
if (nonCalculationNode.unaryExpression.getType() instanceof BaseType && nonCalculationNode.expression.getType() instanceof BaseType) {
methodVisitor.visitJumpInsn(IF_ICMPNE, labelFalse);
} else {
methodVisitor.visitJumpInsn(IF_ACMPNE, labelFalse);
}
break;
case NOT_EQUAL:
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
if (nonCalculationNode.unaryExpression.getType() instanceof BaseType && nonCalculationNode.expression.getType() instanceof BaseType) {
methodVisitor.visitJumpInsn(IF_ICMPEQ, labelFalse);
} else {
methodVisitor.visitJumpInsn(IF_ACMPEQ, labelFalse);
}
break;
}
Label labelEndLogicalExpression = new Label();
methodVisitor.visitLabel(labelTrue);
methodVisitor.visitInsn(ICONST_1); // true
methodVisitor.visitJumpInsn(GOTO, labelEndLogicalExpression);
methodVisitor.visitLabel(labelFalse);
methodVisitor.visitInsn(ICONST_0); // false
methodVisitor.visitLabel(labelEndLogicalExpression);
}
// Unary expressions
@Override
public void visit(MemberAccessNode memberAccessNode) {
// Only used to get, not to put
int localVarIndex = localVariables.indexOf("memberAccessNode.identifier"); // TODO
if (localVarIndex >= 0) { // local var object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else { // this field
methodVisitor.visitVarInsn(ALOAD, 0);
}
if (memberAccessNode.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(GETFIELD, memberAccessNode.identifiers.get(0), memberAccessNode.identifiers.get(1), mapper.getTypeChar((BaseType) memberAccessNode.getTypeNode()));
} else if (memberAccessNode.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(GETFIELD, memberAccessNode.identifiers.get(0), memberAccessNode.identifiers.get(1), "L" + ((ReferenceType) memberAccessNode.getTypeNode()).getIdentifier() + ";");
}
}
@Override
public void visit(NotNode notNode) {
Label labelFalse = new Label();
Label labelTrue = new Label();
notNode.expression.accept(this);
methodVisitor.visitJumpInsn(Opcodes.IFNE, labelFalse); // false if value is true (value != 0)
Label labelEndLogicalExpression = new Label();
methodVisitor.visitLabel(labelTrue);
methodVisitor.visitInsn(ICONST_1); // true
methodVisitor.visitJumpInsn(GOTO, labelEndLogicalExpression);
methodVisitor.visitLabel(labelFalse);
methodVisitor.visitInsn(ICONST_0); // false
methodVisitor.visitLabel(labelEndLogicalExpression);
}
@Override
public void visit(UnaryNode unaryNode) {
if (unaryNode.thisExp != null) {
methodVisitor.visitVarInsn(ALOAD, 0); // this
} else if (unaryNode.memberAccess != null) {
unaryNode.memberAccess.setTypeNode(unaryNode.getType());
unaryNode.memberAccess.accept(this);
} else if (unaryNode.value != null) {
unaryNode.value.accept(this);
} else if (unaryNode.notExpression != null) {
unaryNode.notExpression.accept(this);
} else if (unaryNode.statement != null) {
unaryNode.statement.accept(this);
} else if (unaryNode.expression != null) {
unaryNode.expression.accept(this);
} else if (unaryNode.identifier != null) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(unaryNode.identifier));
}
}
// Statements
@Override
public void visit(BlockNode blockNode) {
for (IStatementNode statementNode : blockNode.statements) {
statementNode.accept(this);
}
}
@Override
public void visit(IfElseNode ifElseNode) {
Label elseLabel = new Label();
Label endLabel = new Label();
Label[] elseIfLabels = new Label[ifElseNode.elseIfStatements.size()];
for (int i = 0; i < ifElseNode.elseIfStatements.size(); i++) {
elseIfLabels[i] = new Label();
}
ifElseNode.ifStatement.expression.accept(this);
if (ifElseNode.elseIfStatements.isEmpty()) {
// No else if
methodVisitor.visitJumpInsn(IFEQ, elseLabel);
} else {
// else if statements
methodVisitor.visitJumpInsn(IFEQ, elseIfLabels[0]);
}
ifElseNode.ifStatement.block.accept(this); // accept if block
methodVisitor.visitJumpInsn(GOTO, endLabel);
for (int i = 0; i < ifElseNode.elseIfStatements.size(); i++) {
methodVisitor.visitLabel(elseIfLabels[i]);
ifElseNode.elseIfStatements.get(i).expression.accept(this);
if (i + 1 < elseIfLabels.length) {
// at least one more else if
methodVisitor.visitJumpInsn(IFEQ, elseIfLabels[i + 1]);
} else {
methodVisitor.visitJumpInsn(IFEQ, elseLabel);
}
ifElseNode.elseIfStatements.get(i).block.accept(this);
methodVisitor.visitJumpInsn(GOTO, endLabel);
}
if (ifElseNode.elseStatement != null) {
methodVisitor.visitLabel(elseLabel);
ifElseNode.elseStatement.block.accept(this);
} else {
methodVisitor.visitLabel(elseLabel);
}
methodVisitor.visitLabel(endLabel);
}
@Override
public void visit(LocalVariableDeclarationNode localVariableDeclarationNode) {
if (localVariableDeclarationNode.expression != null) {
// Process expression
localVariableDeclarationNode.expression.accept(this);
if (localVariableDeclarationNode.expression instanceof UnaryNode) {
UnaryNode unaryNode = (UnaryNode) localVariableDeclarationNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
incrementNode.assignableExpression.typeNode = unaryNode.type;
loadIncrement(incrementNode);
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
decrementNode.assignableExpression.typeNode = unaryNode.type;
loadDecrement(decrementNode);
}
}
// add local var to list if not in list
if (!localVariables.contains(localVariableDeclarationNode.identifier)) {
localVariables.add(localVariableDeclarationNode.identifier);
}
if (localVariableDeclarationNode.type instanceof BaseType) {
methodVisitor.visitVarInsn(ISTORE, localVariables.indexOf(localVariableDeclarationNode.identifier));
} else if (localVariableDeclarationNode.type instanceof ReferenceType) {
methodVisitor.visitVarInsn(ASTORE, localVariables.indexOf(localVariableDeclarationNode.identifier));
}
} else {
// Local var declaration
if (!localVariables.contains(localVariableDeclarationNode.identifier)) {
localVariables.add(localVariableDeclarationNode.identifier);
}
}
}
@Override
public void visit(AssignNode assignNode) {
if (assignNode.assignable.memberAccess != null) { // this / object
assignNode.assignable.memberAccess.setTypeNode(assignNode.assignable.typeNode);
if (assignNode.expression instanceof UnaryNode) {
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i
incrementNode.accept(this); // crement
fieldOrObjectVarCrementAssign(assignNode); // assign
} else { // i++
fieldOrObjectVarCrementAssign(assignNode); // assign
incrementNode.accept(this); // crement
}
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
if (decrementNode.crementType.equals(CrementType.PREFIX)) {
decrementNode.accept(this); // crement
fieldOrObjectVarCrementAssign(assignNode); // assign
} else {
fieldOrObjectVarCrementAssign(assignNode); // assign
decrementNode.accept(this); // crement
}
}
} else {
assignFieldOrObjectVar(assignNode);
}
} else { // local var
if (assignNode.expression instanceof UnaryNode) {
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
if (unaryNode.statement instanceof IncrementNode || unaryNode.statement instanceof DecrementNode) {
localVarCrementAssign(assignNode);
}
} else {
assignNode.expression.accept(this);
assignLocalVar(assignNode);
}
}
}
private void loadIncrement(IncrementNode incrementNode) {
AssignableNode assignableNode = incrementNode.assignableExpression;
if (assignableNode.memberAccess != null) {
assignableNode.memberAccess.accept(this);
} else {
if (assignableNode.typeNode instanceof BaseType) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignableNode.identifier));
} else if (assignableNode.typeNode instanceof ReferenceType) {
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignableNode.identifier));
}
}
}
private void loadDecrement(DecrementNode decrementNode) {
AssignableNode assignableNode = decrementNode.assignableExpression;
if (assignableNode.memberAccess != null) {
assignableNode.memberAccess.accept(this);
} else {
if (assignableNode.typeNode instanceof BaseType) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignableNode.identifier));
} else if (assignableNode.typeNode instanceof ReferenceType) {
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignableNode.identifier));
}
}
}
private void assignLocalVar(AssignNode assignNode) {
if (!localVariables.contains(assignNode.assignable.identifier)) {
localVariables.add(assignNode.assignable.identifier);
}
if (assignNode.expression.getType() instanceof BaseType) {
methodVisitor.visitVarInsn(ISTORE, localVariables.indexOf(assignNode.assignable.identifier));
} else if (assignNode.expression.getType() instanceof ReferenceType) {
methodVisitor.visitVarInsn(ASTORE, localVariables.indexOf(assignNode.assignable.identifier));
}
}
private void assignFieldOrObjectVar(AssignNode assignNode) {
int localVarIndex = localVariables.indexOf(assignNode.assignable.identifier);
if (localVarIndex >= 0) { // object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else if (assignNode.assignable.memberAccess.thisExpr) { // this
methodVisitor.visitVarInsn(ALOAD, 0);
} else {
localVariables.add(assignNode.assignable.identifier);
}
assignNode.expression.accept(this);
if (assignNode.expression.getType() instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) assignNode.expression.getType()));
} else if (assignNode.expression.getType() instanceof ReferenceType) {
ReferenceType referenceType = (ReferenceType) assignNode.expression.getType();
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), "L" + referenceType.getIdentifier() + ";");
}
}
private void localVarCrementAssign(AssignNode assignNode) {
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i
incrementNode.accept(this);
incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement(incrementNode);
assignLocalVar(assignNode);
} else { // i++
incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement(incrementNode);
assignLocalVar(assignNode);
incrementNode.accept(this);
}
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
if (decrementNode.crementType.equals(CrementType.PREFIX)) {
decrementNode.accept(this);
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
assignLocalVar(assignNode);
} else {
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
assignLocalVar(assignNode);
decrementNode.accept(this);
}
}
}
private void fieldOrObjectVarCrementAssign(AssignNode assignNode) {
int localVarIndex = localVariables.indexOf(assignNode.assignable.identifier);
if (localVarIndex >= 0) { // object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else if (assignNode.assignable.memberAccess.thisExpr) { // field
methodVisitor.visitVarInsn(ALOAD, 0);
} else {
localVariables.add(assignNode.assignable.identifier);
}
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement((incrementNode));
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
}
if (assignNode.expression.getType() instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) assignNode.expression.getType()));
} else if (assignNode.expression.getType() instanceof ReferenceType) {
ReferenceType referenceType = (ReferenceType) assignNode.expression.getType();
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), "L" + referenceType.getIdentifier() + ";");
}
}
@Override
public void visit(IncrementNode incrementNode) {
if (incrementNode.assignableExpression.memberAccess != null) { // Object var / field
int localVarIndex = localVariables.indexOf(incrementNode.assignableExpression.identifier);
if (localVarIndex >= 0) { // object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else { // this
methodVisitor.visitVarInsn(ALOAD, 0);
}
if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(GETFIELD, incrementNode.assignableExpression.memberAccess.identifiers.get(0), incrementNode.assignableExpression.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) incrementNode.assignableExpression.memberAccess.getTypeNode()));
} else if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(GETFIELD, incrementNode.assignableExpression.memberAccess.identifiers.get(0), incrementNode.assignableExpression.memberAccess.identifiers.get(1), "L" + (((ReferenceType) incrementNode.assignableExpression.memberAccess.getTypeNode()).getIdentifier() + ";"));
}
methodVisitor.visitInsn(ICONST_1);
methodVisitor.visitInsn(IADD);
if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, incrementNode.assignableExpression.memberAccess.identifiers.get(0), incrementNode.assignableExpression.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) incrementNode.assignableExpression.memberAccess.getTypeNode()));
} else if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(PUTFIELD, incrementNode.assignableExpression.memberAccess.identifiers.get(0), incrementNode.assignableExpression.memberAccess.identifiers.get(1), "L" + (((ReferenceType) incrementNode.assignableExpression.memberAccess.getTypeNode()).getIdentifier() + ";"));
}
} else { // local var
methodVisitor.visitIincInsn(localVariables.indexOf(incrementNode.assignableExpression.identifier), 1);
}
}
@Override
public void visit(DecrementNode decrementNode) {
if (decrementNode.assignableExpression.memberAccess != null) { // Object var / field
int localVarIndex = localVariables.indexOf(decrementNode.assignableExpression.identifier);
if (localVarIndex >= 0) { // object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else { // this
methodVisitor.visitVarInsn(ALOAD, 0);
}
if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(GETFIELD, decrementNode.assignableExpression.memberAccess.identifiers.get(0), decrementNode.assignableExpression.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) decrementNode.assignableExpression.memberAccess.getTypeNode()));
} else if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(GETFIELD, decrementNode.assignableExpression.memberAccess.identifiers.get(0), decrementNode.assignableExpression.memberAccess.identifiers.get(1), "L" + (((ReferenceType) decrementNode.assignableExpression.memberAccess.getTypeNode()).getIdentifier() + ";"));
}
methodVisitor.visitInsn(ICONST_1);
methodVisitor.visitInsn(ISUB);
if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, decrementNode.assignableExpression.memberAccess.identifiers.get(0), decrementNode.assignableExpression.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) decrementNode.assignableExpression.memberAccess.getTypeNode()));
} else if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(PUTFIELD, decrementNode.assignableExpression.memberAccess.identifiers.get(0), decrementNode.assignableExpression.memberAccess.identifiers.get(1), "L" + (((ReferenceType) decrementNode.assignableExpression.memberAccess.getTypeNode()).getIdentifier() + ";"));
}
} else { // local var
methodVisitor.visitIincInsn(localVariables.indexOf(decrementNode.assignableExpression.identifier), -1);
}
}
@Override
public void visit(NewDeclarationNode newDeclarationNode) {
methodVisitor.visitTypeInsn(NEW, newDeclarationNode.identifier);
methodVisitor.visitInsn(DUP);
List<ParameterNode> parameterNodes = new ArrayList<>();
for (IExpressionNode expressionNode : newDeclarationNode.expressions) {
expressionNode.accept(this);
parameterNodes.add(new ParameterNode(expressionNode.getType(), ""));
}
methodVisitor.visitMethodInsn(INVOKESPECIAL, newDeclarationNode.identifier, "<init>", mapper.generateMethodDescriptor(new BaseType(TypeEnum.VOID), parameterNodes), false);
}
@Override
public void visit(ValueNode valueNode) {
switch (valueNode.valueType) {
case INT_VALUE:
int intValue = Integer.parseInt(valueNode.value);
if (intValue >= Byte.MIN_VALUE && intValue <= Byte.MAX_VALUE) { // load int as byte
methodVisitor.visitIntInsn(BIPUSH, intValue);
} else if (intValue >= Short.MIN_VALUE && intValue <= Short.MAX_VALUE) { // load int as short
methodVisitor.visitIntInsn(SIPUSH, intValue);
} else { // load int as const
methodVisitor.visitLdcInsn(intValue);
}
break;
case BOOLEAN_VALUE:
if (valueNode.value.equals("true")) {
methodVisitor.visitInsn(ICONST_1);
} else {
methodVisitor.visitInsn(ICONST_0);
}
break;
case CHAR_VALUE:
char charValue = valueNode.value.charAt(0);
if (charValue <= Byte.MAX_VALUE) { // load char as byte
methodVisitor.visitIntInsn(BIPUSH, charValue);
} else if (charValue <= Short.MAX_VALUE) { // load char as short
methodVisitor.visitIntInsn(SIPUSH, charValue);
} else { // load char as const
methodVisitor.visitLdcInsn(charValue);
}
break;
case NULL_VALUE:
methodVisitor.visitInsn(ACONST_NULL);
break;
}
}
@Override
public void visit(ReturnNode returnNode) {
if (returnNode.voidReturn) { // Return nothing
methodVisitor.visitInsn(RETURN);
} else { // Return something
// Process expression
returnNode.expression.accept(this);
if (returnNode.expression instanceof UnaryNode) {
UnaryNode unaryNode = (UnaryNode) returnNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement(incrementNode);
}
if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
}
}
// Return result of expression
if (returnNode.expression.getType() instanceof BaseType) {
methodVisitor.visitInsn(IRETURN);
} else if (returnNode.expression.getType() instanceof ReferenceType) {
methodVisitor.visitInsn(ARETURN);
}
}
}
@Override
public void visit(WhileNode whileNode) {
Label loopLabel = new Label();
Label endOfLoopLabel = new Label();
methodVisitor.visitLabel(loopLabel);
// while loop
whileNode.expression.accept(this);
methodVisitor.visitJumpInsn(IFEQ, endOfLoopLabel); // if condition is false, jump out of loop
whileNode.block.accept(this);
methodVisitor.visitJumpInsn(GOTO, loopLabel);
methodVisitor.visitLabel(endOfLoopLabel);
}
@Override
public void visit(MethodCallNode methodCallNode) {
List<ParameterNode> parameterNodes = new ArrayList<>();
int localVarIndex = -1;
if (methodCallNode.target.memberAccess.identifiers.size() > 1) {
localVarIndex = localVariables.indexOf(methodCallNode.target.memberAccess.identifiers.get(1));
}
if (localVarIndex >= 0) { // local var object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else { // this field
methodVisitor.visitVarInsn(ALOAD, 0);
}
for (IExpressionNode expressionNode : methodCallNode.parameters) {
expressionNode.accept(this);
parameterNodes.add(new ParameterNode(expressionNode.getType(), ""));
}
if(methodCallNode.type == null) {
methodCallNode.type = new BaseType(TypeEnum.INT);
}
methodVisitor.visitMethodInsn(INVOKEVIRTUAL, methodCallNode.target.memberAccess.identifiers.get(0), methodCallNode.identifier, mapper.generateMethodDescriptor(methodCallNode.type, parameterNodes), false);
}
}

View File

@@ -1,9 +1,9 @@
package bytecode.visitor;
import ast.ClassNode;
import ast.member.FieldNode;
import ast.members.FieldNode;
public interface ClassVisitor {
void visit(ClassNode classNode);
void visit(FieldNode fieldNode);
void visit(ClassNode classNode);
void visit(FieldNode fieldNode);
}

View File

@@ -1,9 +1,68 @@
package bytecode.visitor;
import ast.member.ConstructorNode;
import ast.member.MethodNode;
import ast.expressions.binaryexpressions.*;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.expressions.unaryexpressions.NotNode;
import ast.expressions.unaryexpressions.UnaryNode;
import ast.members.ConstructorNode;
import ast.members.MainMethodNode;
import ast.members.MethodNode;
import ast.statementexpressions.AssignNode;
import ast.statementexpressions.NewDeclarationNode;
import ast.statementexpressions.crementexpressions.DecrementNode;
import ast.statementexpressions.crementexpressions.IncrementNode;
import ast.statementexpressions.methodcallstatementnexpressions.ChainedMethodNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statements.*;
import ast.type.ValueNode;
public interface MethodVisitor {
// members
void visit(ConstructorNode constructorNode);
void visit(MethodNode methodNode);
void visit(MainMethodNode mainMethodNode);
// Binary expressions
void visit(BinaryNode binaryNode);
void visit(CalculationNode calculationNode);
void visit(DotNode dotNode);
void visit(DotSubtractionNode dotSubtractionNode);
void visit(NonCalculationNode nonCalculationNode);
// Unary expressions
void visit(MemberAccessNode memberAccessNode);
void visit(NotNode notExpressionNode);
void visit(UnaryNode unaryExpressionNode);
// statements
void visit(BlockNode blockNode);
void visit(IfElseNode ifElseNode);
void visit(IncrementNode incrementNode);
void visit(DecrementNode decrementNode);
void visit(LocalVariableDeclarationNode localVariableDeclarationNode);
void visit(ReturnNode returnNode);
void visit(WhileNode whileNode);
// statement expression
void visit(MethodCallNode methodCallNode);
void visit(AssignNode assignNode);
void visit(NewDeclarationNode newDeclarationNode);
// type
void visit(ValueNode valueNode);
}

View File

@@ -3,5 +3,5 @@ package bytecode.visitor;
import ast.ProgramNode;
public interface ProgramVisitor {
void visit(ProgramNode programNode);
void visit(ProgramNode programNode);
}

View File

@@ -0,0 +1,116 @@
package main;
import ast.ASTNode;
import ast.ProgramNode;
import parser.astBuilder.ASTBuilder;
import parser.generated.SimpleJavaLexer;
import parser.generated.SimpleJavaParser;
import semantic.SemanticAnalyzer;
import bytecode.ByteCodeGenerator;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.ParseTree;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Optional;
/**
* Start miniCompiler using make:
* <p> <code> cd .\src\test\ </code>
* <p> <code> make clean compile-miniCompiler </code>
* <p> Start miniCompiler using jar:
* <p> <code> java.exe -DgenJar=true_OR_false -DgenClass=true_OR_false -jar path_to_jar\JavaCompiler-1.0-jar-with-dependencies.jar 'path_to_input_file.java' 'path_to_output_directory' </code>
* <p> Example (jar needs to be in the target directory, compile with make or mvn package first):
* <code> java.exe -DgenJar=true -DgenClass=true -jar .\target\JavaCompiler-1.0-jar-with-dependencies.jar 'src/main/resources/input/CompilerInput.java' 'src/main/resources/output' </code>
*/
public class Main {
public static void main(String[] args) throws Exception {
if (args.length == 2) {
// args[0] is the input file path
// args[1] is the output directory path
String inputFilePath = args[0];
String outputDirectoryPath = args[1];
System.out.println("Compiling file: " + inputFilePath);
try {
CharStream inputCharStream = CharStreams.fromPath(Paths.get(inputFilePath));
compileFile(inputCharStream, outputDirectoryPath);
} catch (IOException e) {
System.err.println("Error reading the file: " + e.getMessage());
}
}
else {
try {
CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/finalTest/Car.java"));
compileFile(codeCharStream, "src/test/resources/input/finalTest");
} catch (IOException e) {
System.err.println("Error reading the file: " + e.getMessage());
}
}
}
/**
* This method is used to compile a file from a given CharStream and output the bytecode to a specified directory.
* It goes through the following steps:
* <p>1. Scanner: It uses the SimpleJavaLexer to tokenize the input CharStream.
* <p>2. Parser: It uses the SimpleJavaParser to parse the tokens and generate a ParseTree.
* <p>3. AST Builder: It uses the ASTBuilder to visit the ParseTree and generate an Abstract Syntax Tree (AST).
* <p>4. Semantic Analyzer: It uses the SemanticAnalyzer to generate a typed AST.
* <p>5. Bytecode Generator: It uses the ByteCodeGenerator to generate bytecode from the typed AST and output it to the specified directory.
*
* @param inputCharStream The CharStream representing the input file to be compiled.
* @param outputDirectoryPath The path of the directory where the output bytecode should be written.
*/
static void compileFile(CharStream inputCharStream, String outputDirectoryPath) {
// Initialize the logger
new MiniCompilerLogger();
/* ------------------------- Scanner -> tokens ------------------------- */
// Use the SimpleJavaLexer to tokenize the input CharStream
SimpleJavaLexer lexer = new SimpleJavaLexer(inputCharStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
tokenStream.fill();
// Log the tokens
MiniCompilerLogger.logScanner(tokenStream);
/*------------------------- Parser -> Parsetree -------------------------*/
// Use the SimpleJavaParser to parse the tokens and generate a ParseTree
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
ParseTree parseTree = parser.program(); // parse the input
// Log the ParseTree
MiniCompilerLogger.logParser(parseTree, parser);
/*------------------------- AST builder -> AST -------------------------*/
// Use the ASTBuilder to visit the ParseTree and generate an Abstract Syntax Tree (AST)
ASTBuilder astBuilder = new ASTBuilder();
ASTNode abstractSyntaxTree = astBuilder.visit(parseTree);
// Log the AST
MiniCompilerLogger.logAST(abstractSyntaxTree);
/*------------------------- Semantic Analyzer -> typed AST -------------------------*/
// Use the SemanticAnalyzer to generate a typed AST
ASTNode typedAst = SemanticAnalyzer.generateTast(abstractSyntaxTree);
// Log the typed AST
MiniCompilerLogger.logSemanticAnalyzer(typedAst);
if(SemanticAnalyzer.errors.isEmpty()){
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/
// Use the ByteCodeGenerator to generate bytecode from the typed AST and output it to the specified directory
final boolean genJar = Optional.ofNullable(System.getProperty("genJar")).map(String::toLowerCase).map(Boolean::parseBoolean).orElse(true);
final boolean genClass = Optional.ofNullable(System.getProperty("genClass")).map(String::toLowerCase).map(Boolean::parseBoolean).orElse(true);
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(outputDirectoryPath, genJar, genClass);
assert typedAst != null;
byteCodeGenerator.visit((ProgramNode) typedAst);
// Log the bytecode generation
MiniCompilerLogger.logBytecodeGenerator();
} else {
for(Exception exception : SemanticAnalyzer.errors){
exception.printStackTrace();
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More