-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 964a339
Showing
72 changed files
with
6,766 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,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
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,2 @@ | ||
# BoLang | ||
|
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,169 @@ | ||
<?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>com.diegokrupitza</groupId> | ||
<artifactId>BoLang</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<developers> | ||
<developer> | ||
<name>Diego Krupitza</name> | ||
<email>[email protected]</email> | ||
<url>https://diegokrupitza.com</url> | ||
</developer> | ||
</developers> | ||
|
||
<properties> | ||
<java.version>11</java.version> | ||
<maven.compiler.plugin>3.8.1</maven.compiler.plugin> | ||
<assertj.version>3.11.1</assertj.version> | ||
<lombok.version>1.18.20</lombok.version> | ||
<apache.commons-lang3.version>3.10</apache.commons-lang3.version> | ||
<apache.commons-collections4.version>4.4</apache.commons-collections4.version> | ||
<antlr.version>4.9.1</antlr.version> | ||
<reflections.version>0.9.12</reflections.version> | ||
<mojo.version>3.0.0</mojo.version> | ||
<antlr.visitor>true</antlr.visitor> | ||
<antlr.listener>true</antlr.listener> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
<version>${lombok.version}</version> | ||
</dependency> | ||
|
||
<!-- assertJ --> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>${assertj.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- apache commons --> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>${apache.commons-lang3.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-collections4</artifactId> | ||
<version>${apache.commons-collections4.version}</version> | ||
</dependency> | ||
|
||
<!-- antlr --> | ||
<dependency> | ||
<groupId>org.antlr</groupId> | ||
<artifactId>antlr4-runtime</artifactId> | ||
<version>${antlr.version}</version> | ||
</dependency> | ||
|
||
<!-- to process classpath at runtime --> | ||
<dependency> | ||
<groupId>org.reflections</groupId> | ||
<artifactId>reflections</artifactId> | ||
<version>${reflections.version}</version> | ||
</dependency> | ||
|
||
<!-- testing --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.7.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.7.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<version>5.7.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<!-- generating the antlr4 files --> | ||
<plugin> | ||
<groupId>org.antlr</groupId> | ||
<artifactId>antlr4-maven-plugin</artifactId> | ||
<version>${antlr.version}</version> | ||
<configuration> | ||
<listener>${antlr.listener}</listener> | ||
<visitor>${antlr.visitor}</visitor> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>antlr4</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- moving the antlr4 generated sources into the right folder --> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<version>${mojo.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>add-source</goal> | ||
</goals> | ||
<configuration> | ||
<sources> | ||
<source>${basedir}/target/generated-sources/antlr4</source> | ||
</sources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven.compiler.plugin}</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${lombok.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
|
||
<!-- parallel testing --> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</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,63 @@ | ||
grammar Bo; | ||
|
||
bo : stat+ ; | ||
|
||
scopecont : stat* ; | ||
|
||
stat : 'return' expr ';' #returnStat | ||
| 'if' '(' cond=expr ')' '{' ifStat=scopecont '}' 'else' '{' elseStat=scopecont '}' #ifElseStat | ||
| 'if' '(' cond=expr ')' '{' ifStat=scopecont '}' #ifStat | ||
| 'var' ID ':=' expr ';' #varDefStat | ||
| ID ':=' expr ';' #varAssignStat | ||
; | ||
|
||
expr : '(' expr ')' # parensExpr | ||
| op=('-'|'!') expr # unaryExpr | ||
| left=expr op=('+' | '-' | '*' | '/' | '<' | '<=' | '>' | '>=' | '==' | '!=' | '&&' | '||' | '++') right=expr # infixExpr | ||
| term # termExpr | ||
|
||
; | ||
|
||
term : num=NUM #numVal | ||
| string #stringVal | ||
| BOOLEAN #booleanEntry | ||
| id=ID #identifierVal | ||
| '#' id=ID #externalParamVal | ||
| func=ID '(' (expr ( ',' expr )*)? ')' #funcVal | ||
| '[' (expr ( ',' expr )*)? ']' #createList | ||
| id=ID'[' index=expr ']' #accessStringOrListItem | ||
; | ||
|
||
|
||
|
||
string : STRING | ||
; | ||
|
||
|
||
|
||
WS : [ \t\r\n]+ -> skip ; | ||
|
||
fragment DIGIT : [0-9]; | ||
fragment ESC: '\\"' | '\\\\'; | ||
|
||
OP_ADD: '+'; | ||
OP_SUB: '-'; | ||
OP_MUL: '*'; | ||
OP_DIV: '/'; | ||
OP_LESS: '<'; | ||
OP_LESSEQ: '<='; | ||
OP_GREATER: '>'; | ||
OP_GREATEREQ: '>='; | ||
OP_EQUAL: '=='; | ||
OP_NOTEQUAL: '!='; | ||
OP_AND: '&&'; | ||
OP_OR: '||'; | ||
OP_CONCAT: '++'; | ||
OP_NEG: '!'; | ||
|
||
NUM : (DIGIT+ | (DIGIT+'.'DIGIT+) | ('.'DIGIT+)); | ||
BOOLEAN : TRUE | FALSE; | ||
TRUE : 'TRUE' | 'True' | 'true'; | ||
FALSE : 'FALSE' | 'False' | 'false'; | ||
ID : [_A-Za-z] [_0-9A-Za-z]*; | ||
STRING : '"' (~'"'|ESC)* '"'; |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/diegokrupitza/bolang/symboltable/BoSymbolTable.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,48 @@ | ||
package com.diegokrupitza.bolang.symboltable; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Diego Krupitza | ||
* @version 1.0 | ||
* @date 08.07.21 | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
public class BoSymbolTable { | ||
|
||
private List<String> sym = new LinkedList<>(); | ||
private BoSymbolTable parent = null; | ||
|
||
public void add(String idName) { | ||
this.sym.add(idName); | ||
} | ||
|
||
/** | ||
* Generate a new subscope based on the current object | ||
* | ||
* @return the newly created SymbolTable scope with the current object set as parent | ||
*/ | ||
public BoSymbolTable createScope() { | ||
BoSymbolTable scope = new BoSymbolTable(); | ||
scope.setParent(this); | ||
return scope; | ||
} | ||
|
||
public boolean inScope(String name) { | ||
if (this.sym.contains(name)) { | ||
return true; | ||
} | ||
|
||
if (this.parent != null) { | ||
// we have a parent this means we need to check there too | ||
return this.parent.inScope(name); | ||
} | ||
|
||
return false; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/diegokrupitza/bolang/syntaxtree/BuildAstException.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,12 @@ | ||
package com.diegokrupitza.bolang.syntaxtree; | ||
|
||
/** | ||
* @author Diego Krupitza | ||
* @version 1.0 | ||
* @date 18.07.21 | ||
*/ | ||
public class BuildAstException extends RuntimeException { | ||
public BuildAstException(String s) { | ||
super(s); | ||
} | ||
} |
Oops, something went wrong.