Skip to content

Commit

Permalink
Merge pull request #17 from development
Browse files Browse the repository at this point in the history
Create grammar
  • Loading branch information
Kiyotoko committed Apr 26, 2024
2 parents 0c38529 + 526bdf5 commit a23571a
Show file tree
Hide file tree
Showing 55 changed files with 318 additions and 3,719 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
venv

# Compiled class file
*.class

Expand Down Expand Up @@ -164,4 +166,4 @@ fabric.properties
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
.idea/caches/build_file_checksums.ser
6 changes: 3 additions & 3 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 0 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,71 +20,3 @@ Vision-Lang is a learning project for building compilers. It is functional progr
## Installation

Check out [Jitpack](https://jitpack.io/#karl-zschiebsch/scvis) to get it for your Gradle or Maven project.

## Usage

### Execute files

Use the `FileInterpreter` to parse expressions from a file.

For example, if you want to use the following vision code:

```rust
a = 3
b = 4
c = 5

print(a^2+b^2, c^2)
```

You can do this with the following java code:

```java
import org.scvis.interpreter.FileInterpreter;

import java.io.File;
import java.io.IOException;

// ...

try(FileInterpreter interpreter = new FileInterpreter(new File(
getClass().getResource("basics.vis").getFile()))){
interpreter.interpretAll();
} catch (IOException ex){
// handle exception
}
```

This will print out the following to the default output stream:

```py
>>> 25.0 25.0
```

### Run interactive

You can use the `InteractiveInterpreter` to parse expressions from the terminal:

```java
import org.scvis.interpreter.InteractiveInterpreter;

// ...

try (InteractiveInterpreter interpreter = new InteractiveInterpreter()) {
interpreter.interpretAll();
}
```

This will look like this:

```py
>>> a = 3
3
>>> b = 4
4
>>> print(a^2 + b^2)
25.0
[25.0]
>>> exit
@exit
```
78 changes: 42 additions & 36 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,40 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.scvis</groupId>
<artifactId>scvis</artifactId>
<groupId>org.vision</groupId>
<artifactId>vision-lang</artifactId>
<version>0.1.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.javaVersion>11</project.javaVersion>
<project.mainClass>org.scvis.Launcher</project.mainClass>
<maven.compiler.source>${project.javaVersion}</maven.compiler.source>
<maven.compiler.target>${project.javaVersion}</maven.compiler.target>
<maven.compiler.release>${project.javaVersion}</maven.compiler.release>
<kotlin.version>2.0.0-Beta2</kotlin.version>
<antlr.version>4.9.3</antlr.version>
</properties>

<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Kiyotoko Apache Maven Packages</name>
<url>https://maven.pkg.github.com/Kiyotoko/vision-lang</url>
</repository>
</distributionManagement>

<dependencies>
<!-- ANTLR -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>${antlr.version}</version>
</dependency>
<!-- ASM -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.7</version>
</dependency>
<!-- Annotations -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand All @@ -35,47 +56,32 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<!-- ANTLR -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${antlr.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.1</version>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${antlr.version}</version>
<executions>
<execution>
<phase>prepare-package</phase>
<phase>generate-sources</phase>
<goals>
<goal>copy-dependencies</goal>
<goal>antlr4</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>${project.mainClass}</mainClass>
<packageName>scvis</packageName>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</plugins>
</build>
</project>
20 changes: 8 additions & 12 deletions scvis.iml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AutoImportedSourceRoots">
<option name="directories">
<list>
<option value="src/main/java" />
<option value="src/test/java" />
<option value="target/generated-sources/annotations" />
<option value="target/generated-test-sources/test-annotations" />
</list>
</option>
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="f4a88e7a-0665-49f6-8a1b-61d38aa2476d" />
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/src/main/antlr4" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/antlr4/vision" isTestSource="false" generated="true" />
<excludeFolder url="file://$MODULE_DIR$/.idea/codeStyles" />
<excludeFolder url="file://$MODULE_DIR$/.idea/sonarlint" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
</component>
</module>
16 changes: 16 additions & 0 deletions src/main/antlr4/org/vision/Vision.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
grammar Vision;

aroot: (declaration | call)* EOF;
call: NAME '(' ')';
declaration: VAR NAME EQUALS value;
value: NAME
| STRING
| NUMBER;

VAR : 'var';
NAME: [a-zA-Z]+;
EQUALS: '=';
NUMBER: [0-9]+;
STRING: '"'().*?'"';
NEWLINE : [\r\n]+;
WS: [ \t\n\r]+ -> skip;
88 changes: 0 additions & 88 deletions src/main/java/org/scvis/Vision.java

This file was deleted.

Loading

0 comments on commit a23571a

Please sign in to comment.