generated from codecrafters-io/course-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
599 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
# | ||
# This script is used to compile your program on CodeCrafters | ||
# | ||
# This runs before .codecrafters/run.sh | ||
# | ||
# Learn more: https://codecrafters.io/program-interface | ||
|
||
set -e # Exit on failure | ||
|
||
mvn -B package -Ddir=/tmp/codecrafters-build-interpreter-java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
# | ||
# This script is used to run your program on CodeCrafters | ||
# | ||
# This runs after .codecrafters/compile.sh | ||
# | ||
# Learn more: https://codecrafters.io/program-interface | ||
|
||
set -e # Exit on failure | ||
|
||
exec java -jar /tmp/codecrafters-build-interpreter-java/codecrafters-interpreter.jar "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.jar | ||
target/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/interpreter.png) | ||
|
||
This is a starting point for Java solutions to the | ||
["Build your own Interpreter" Challenge](https://app.codecrafters.io/courses/interpreter/overview). | ||
|
||
This challenge follows the book | ||
[Crafting Interpreters](https://craftinginterpreters.com/) by Robert Nystrom. | ||
|
||
In this challenge you'll build an interpreter for | ||
[Lox](https://craftinginterpreters.com/the-lox-language.html), a simple | ||
scripting language. Along the way, you'll learn about tokenization, ASTs, | ||
tree-walk interpreters and more. | ||
|
||
Before starting this challenge, make sure you've read the "Welcome" part of the | ||
book that contains these chapters: | ||
|
||
- [Introduction](https://craftinginterpreters.com/introduction.html) (chapter 1) | ||
- [A Map of the Territory](https://craftinginterpreters.com/a-map-of-the-territory.html) | ||
(chapter 2) | ||
- [The Lox Language](https://craftinginterpreters.com/the-lox-language.html) | ||
(chapter 3) | ||
|
||
These chapters don't involve writing code, so they won't be covered in this | ||
challenge. This challenge will start from chapter 4, | ||
[Scanning](https://craftinginterpreters.com/scanning.html). | ||
|
||
**Note**: If you're viewing this repo on GitHub, head over to | ||
[codecrafters.io](https://codecrafters.io) to try the challenge. | ||
|
||
# Passing the first stage | ||
|
||
The entry point for your program is in `src/main/java/Main.java`. Study and | ||
uncomment the relevant code, and push your changes to pass the first stage: | ||
|
||
```sh | ||
git commit -am "pass 1st stage" # any msg | ||
git push origin master | ||
``` | ||
|
||
Time to move on to the next stage! | ||
|
||
# Stage 2 & beyond | ||
|
||
Note: This section is for stages 2 and beyond. | ||
|
||
1. Ensure you have `mvn` installed locally | ||
2. Run `./your_program.sh` to run your program, which is implemented in | ||
`src/main/java/Main.java`. | ||
3. Commit your changes and run `git push origin master` to submit your solution | ||
to CodeCrafters. Test output will be streamed to your terminal. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Set this to true if you want debug logs. | ||
# | ||
# These can be VERY verbose, so we suggest turning them off | ||
# unless you really need them. | ||
debug: false | ||
|
||
# Use this to change the Java version used to run your code | ||
# on Codecrafters. | ||
# | ||
# Available versions: java-23 | ||
language_pack: java-23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
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>io.codecrafters</groupId> | ||
<artifactId>codecrafters-interpreter</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>23</maven.compiler.source> | ||
<maven.compiler.target>23</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>23</java.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<finalName>codecrafters-interpreter</finalName> <!-- Please do not change this final artifact name--> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<!-- This is the main class of your program which will be executed--> | ||
<mainClass>Main</mainClass> | ||
</manifest> | ||
</archive> | ||
<outputDirectory>${dir}</outputDirectory> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
// You can use print statements as follows for debugging, they'll be visible when running tests. | ||
System.err.println("Logs from your program will appear here!"); | ||
|
||
if (args.length < 2) { | ||
System.err.println("Usage: ./your_program.sh tokenize <filename>"); | ||
System.exit(1); | ||
} | ||
|
||
String command = args[0]; | ||
String filename = args[1]; | ||
|
||
if (!command.equals("tokenize")) { | ||
System.err.println("Unknown command: " + command); | ||
System.exit(1); | ||
} | ||
|
||
String fileContents = ""; | ||
try { | ||
fileContents = Files.readString(Path.of(filename)); | ||
} catch (IOException e) { | ||
System.err.println("Error reading file: " + e.getMessage()); | ||
System.exit(1); | ||
} | ||
|
||
// Uncomment this block to pass the first stage | ||
// | ||
// if (fileContents.length() > 0) { | ||
// throw new RuntimeException("Scanner not implemented"); | ||
// } else { | ||
// System.out.println("EOF null"); // Placeholder, remove this line when implementing the scanner | ||
// } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
# | ||
# Use this script to run your program LOCALLY. | ||
# | ||
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program. | ||
# | ||
# Learn more: https://codecrafters.io/program-interface | ||
|
||
set -e # Exit early if any commands fail | ||
|
||
# Copied from .codecrafters/compile.sh | ||
# | ||
# - Edit this to change how your program compiles locally | ||
# - Edit .codecrafters/compile.sh to change how your program compiles remotely | ||
( | ||
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory | ||
mvn -B package -Ddir=/tmp/codecrafters-build-interpreter-java | ||
) | ||
|
||
# Copied from .codecrafters/run.sh | ||
# | ||
# - Edit this to change how your program runs locally | ||
# - Edit .codecrafters/run.sh to change how your program runs remotely | ||
exec java -jar /tmp/codecrafters-build-interpreter-java/codecrafters-interpreter.jar "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# syntax=docker/dockerfile:1.7-labs | ||
FROM maven:3.9.9-eclipse-temurin-23-alpine | ||
|
||
# Ensures the container is re-built if dependency files change | ||
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="pom.xml" | ||
|
||
WORKDIR /app | ||
|
||
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses | ||
COPY --exclude=.git --exclude=README.md . /app | ||
|
||
# Install language-specific dependencies | ||
RUN .codecrafters/compile.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
# | ||
# This script is used to compile your program on CodeCrafters | ||
# | ||
# This runs before .codecrafters/run.sh | ||
# | ||
# Learn more: https://codecrafters.io/program-interface | ||
|
||
set -e # Exit on failure | ||
|
||
mvn -B package -Ddir=/tmp/codecrafters-build-interpreter-java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
# | ||
# This script is used to run your program on CodeCrafters | ||
# | ||
# This runs after .codecrafters/compile.sh | ||
# | ||
# Learn more: https://codecrafters.io/program-interface | ||
|
||
set -e # Exit on failure | ||
|
||
exec java -jar /tmp/codecrafters-build-interpreter-java/codecrafters-interpreter.jar "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.jar | ||
target/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/interpreter.png) | ||
|
||
This is a starting point for Java solutions to the | ||
["Build your own Interpreter" Challenge](https://app.codecrafters.io/courses/interpreter/overview). | ||
|
||
This challenge follows the book | ||
[Crafting Interpreters](https://craftinginterpreters.com/) by Robert Nystrom. | ||
|
||
In this challenge you'll build an interpreter for | ||
[Lox](https://craftinginterpreters.com/the-lox-language.html), a simple | ||
scripting language. Along the way, you'll learn about tokenization, ASTs, | ||
tree-walk interpreters and more. | ||
|
||
Before starting this challenge, make sure you've read the "Welcome" part of the | ||
book that contains these chapters: | ||
|
||
- [Introduction](https://craftinginterpreters.com/introduction.html) (chapter 1) | ||
- [A Map of the Territory](https://craftinginterpreters.com/a-map-of-the-territory.html) | ||
(chapter 2) | ||
- [The Lox Language](https://craftinginterpreters.com/the-lox-language.html) | ||
(chapter 3) | ||
|
||
These chapters don't involve writing code, so they won't be covered in this | ||
challenge. This challenge will start from chapter 4, | ||
[Scanning](https://craftinginterpreters.com/scanning.html). | ||
|
||
**Note**: If you're viewing this repo on GitHub, head over to | ||
[codecrafters.io](https://codecrafters.io) to try the challenge. | ||
|
||
# Passing the first stage | ||
|
||
The entry point for your program is in `src/main/java/Main.java`. Study and | ||
uncomment the relevant code, and push your changes to pass the first stage: | ||
|
||
```sh | ||
git commit -am "pass 1st stage" # any msg | ||
git push origin master | ||
``` | ||
|
||
Time to move on to the next stage! | ||
|
||
# Stage 2 & beyond | ||
|
||
Note: This section is for stages 2 and beyond. | ||
|
||
1. Ensure you have `mvn` installed locally | ||
2. Run `./your_program.sh` to run your program, which is implemented in | ||
`src/main/java/Main.java`. | ||
3. Commit your changes and run `git push origin master` to submit your solution | ||
to CodeCrafters. Test output will be streamed to your terminal. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Set this to true if you want debug logs. | ||
# | ||
# These can be VERY verbose, so we suggest turning them off | ||
# unless you really need them. | ||
debug: false | ||
|
||
# Use this to change the Java version used to run your code | ||
# on Codecrafters. | ||
# | ||
# Available versions: java-23 | ||
language_pack: java-23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
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>io.codecrafters</groupId> | ||
<artifactId>codecrafters-interpreter</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>23</maven.compiler.source> | ||
<maven.compiler.target>23</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>23</java.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<finalName>codecrafters-interpreter</finalName> <!-- Please do not change this final artifact name--> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<!-- This is the main class of your program which will be executed--> | ||
<mainClass>Main</mainClass> | ||
</manifest> | ||
</archive> | ||
<outputDirectory>${dir}</outputDirectory> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Oops, something went wrong.