Skip to content

Commit 848cfe3

Browse files
Initial commit
1 parent d27e721 commit 848cfe3

File tree

42 files changed

+5826
-2
lines changed

Some content is hidden

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

42 files changed

+5826
-2
lines changed

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.nar
17+
*.ear
18+
*.zip
19+
*.tar.gz
20+
*.rar
21+
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*
24+
replay_pid*
25+
26+
.idea
27+
28+
target

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
# ez-lang
2-
EZ Language - Compiler Engineering Basics
1+
# EZ Programming Language
2+
3+
This project is part of the https://compilerprogramming.github.io/ project.
4+
5+
The EZ (pronounced EeeZee) programming language is designed to allow us to learn various compiler techniques.
6+
More documentation to follow, but for now please refer to the source code and the site above.

antlr-parser/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# EZ Programming Language
2+
3+
Provides an ANTLR version of the grammar. Note that the actual parser implements a hand coded recursive descent parser.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
struct Tree {
2+
var left: Tree?
3+
var right: Tree?
4+
}
5+
struct Test {
6+
var intArray: [Int]
7+
}
8+
struct TreeArray {
9+
var array: [Tree?]?
10+
}
11+
func print(n: Int) {}
12+
func foo(a: Int, b: [Int]) {
13+
while(1) {
14+
if (a > b.length)
15+
break
16+
print(b[a])
17+
a = a + 1
18+
a = a + 2
19+
}
20+
}
21+
func bar() -> Test {
22+
var v = new Test { intArray = new [Tree] {} }
23+
return v
24+
}
25+
func main() {
26+
var m = 42
27+
var t: Tree
28+
var b = true
29+
var c: Bool
30+
}

antlr-parser/pom.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>com.compilerprogramming.ezlang</groupId>
6+
<artifactId>compilercraft</artifactId>
7+
<version>1.0</version>
8+
</parent>
9+
<artifactId>antlr-parser</artifactId>
10+
<packaging>jar</packaging>
11+
<name>ANTLR Parser</name>
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<maven.compiler.target>20</maven.compiler.target>
15+
<maven.compiler.source>20</maven.compiler.source>
16+
<antlr4test-maven-plugin.version>1.22</antlr4test-maven-plugin.version>
17+
<antlr.version>4.11.1</antlr.version>
18+
<junit.version>4.13.2</junit.version>
19+
</properties>
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.antlr</groupId>
23+
<artifactId>antlr4-runtime</artifactId>
24+
<version>${antlr.version}</version>
25+
<type>jar</type>
26+
<scope>compile</scope>
27+
</dependency>
28+
</dependencies>
29+
<build>
30+
<pluginManagement>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-compiler-plugin</artifactId>
35+
<version>3.10.1</version>
36+
</plugin>
37+
</plugins>
38+
</pluginManagement>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.antlr</groupId>
42+
<artifactId>antlr4-maven-plugin</artifactId>
43+
<version>${antlr.version}</version>
44+
<configuration>
45+
<visitor>true</visitor>
46+
<listener>true</listener>
47+
</configuration>
48+
<executions>
49+
<execution>
50+
<phase>generate-sources</phase>
51+
<goals>
52+
<goal>antlr4</goal>
53+
</goals>
54+
</execution>
55+
</executions>
56+
</plugin>
57+
<plugin>
58+
<groupId>com.khubla.antlr</groupId>
59+
<artifactId>antlr4test-maven-plugin</artifactId>
60+
<version>${antlr4test-maven-plugin.version}</version>
61+
<configuration>
62+
<verbose>false</verbose>
63+
<showTree>true</showTree>
64+
<entryPoint>program</entryPoint>
65+
<grammarName>EZLanguage</grammarName>
66+
<packageName>com.compilerprogramming.ezlang.antlr</packageName>
67+
<exampleFiles>examples/</exampleFiles>
68+
</configuration>
69+
<executions>
70+
<execution>
71+
<goals>
72+
<goal>test</goal>
73+
</goals>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
</plugins>
78+
</build>
79+
</project>
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
grammar EZLanguage;
2+
3+
program
4+
: declaration+ EOF
5+
;
6+
7+
declaration
8+
: structDeclaration
9+
| functionDeclaration
10+
;
11+
12+
structDeclaration
13+
: 'struct' IDENTIFIER '{' fields '}'
14+
;
15+
16+
fields
17+
: varDeclaration+
18+
;
19+
20+
varDeclaration
21+
: 'var' IDENTIFIER ':' typeName ';'?
22+
;
23+
24+
typeName
25+
: simpleType
26+
| arrayType
27+
;
28+
29+
simpleType
30+
: IDENTIFIER ('?')?
31+
;
32+
33+
arrayType
34+
: '[' simpleType ']' ('?')?
35+
;
36+
37+
functionDeclaration
38+
: 'func' IDENTIFIER '(' parameters? ')' ('->' typeName)? block
39+
;
40+
41+
parameters
42+
: parameter (',' parameter)*
43+
;
44+
45+
parameter
46+
: IDENTIFIER ':' typeName
47+
;
48+
49+
block
50+
: '{' statement* '}'
51+
;
52+
53+
statement
54+
: 'if' '(' expression ')' statement
55+
| 'if' '(' expression ')' statement 'else' statement
56+
| 'while' '(' expression ')' statement
57+
| postfixExpression '=' expression ';'?
58+
| block
59+
| 'break' ';'?
60+
| 'continue' ';'?
61+
| varDeclaration
62+
| 'var' IDENTIFIER '=' expression ';'?
63+
| 'return' orExpression? ';'?
64+
| expression ';'?
65+
;
66+
67+
expression
68+
: orExpression
69+
;
70+
71+
orExpression
72+
: andExpression ('||' andExpression)*
73+
;
74+
75+
andExpression
76+
: relationalExpression ('&&' relationalExpression)*
77+
;
78+
79+
relationalExpression
80+
: additionExpression (('==' | '!='| '>'| '<'| '>='| '<=') additionExpression)*
81+
;
82+
83+
additionExpression
84+
: multiplicationExpression (('+' | '-') multiplicationExpression)*
85+
;
86+
87+
multiplicationExpression
88+
: unaryExpression (('*' | '/' ) unaryExpression)*
89+
;
90+
91+
unaryExpression
92+
: ('-' | '!') unaryExpression
93+
| postfixExpression
94+
;
95+
96+
postfixExpression
97+
: primaryExpression (indexExpression | callExpression | fieldExpression)*
98+
;
99+
100+
indexExpression
101+
: '[' orExpression ']'
102+
;
103+
104+
callExpression
105+
: '(' arguments? ')'
106+
;
107+
108+
arguments
109+
: orExpression (',' orExpression)*
110+
;
111+
112+
fieldExpression
113+
: '.' IDENTIFIER
114+
;
115+
116+
primaryExpression
117+
: INTEGER_LITERAL
118+
| IDENTIFIER
119+
| '(' orExpression ')'
120+
| 'new' typeName initExpression
121+
;
122+
123+
initExpression
124+
: '{' initializers? '}'
125+
;
126+
127+
initializers
128+
: initializer (',' initializer)*
129+
;
130+
131+
initializer
132+
: (IDENTIFIER '=')? orExpression
133+
;
134+
135+
///////////////////////////////////////////////////////////////////
136+
137+
IDENTIFIER
138+
: IDENTIFIER_NONDIGIT
139+
( IDENTIFIER_NONDIGIT
140+
| DEC_DIGIT
141+
)*
142+
;
143+
144+
fragment
145+
IDENTIFIER_NONDIGIT
146+
: NON_DIGIT
147+
;
148+
149+
fragment
150+
NON_DIGIT
151+
: [a-zA-Z_]
152+
;
153+
154+
// number
155+
INTEGER_LITERAL
156+
: DEC_LITERAL
157+
;
158+
DEC_LITERAL: DEC_DIGIT (DEC_DIGIT | '_')*;
159+
160+
fragment DEC_DIGIT: [0-9];
161+
162+
163+
WHITESPACE
164+
: [ \t]+
165+
-> skip
166+
;
167+
168+
NEWLINE
169+
: ( '\r' '\n'?
170+
| '\n'
171+
)
172+
-> skip
173+
;
174+
175+
LINE_COMMENT
176+
: '//' ~[\r\n]*
177+
-> skip
178+
;
179+
180+
181+
ANY: . ;

common/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.compilerprogramming.ezlang</groupId>
8+
<artifactId>compilercraft</artifactId>
9+
<version>1.0</version>
10+
</parent>
11+
<artifactId>common</artifactId>
12+
<packaging>jar</packaging>
13+
<name>Common</name>
14+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* DO NOT REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
* <p>
4+
* Contributor(s):
5+
* <p>
6+
* The Initial Developer of the Original Software is Dibyendu Majumdar.
7+
* <p>
8+
* This file is part of the Sea Of Nodes Simple Programming language
9+
* implementation. See https://github.com/SeaOfNodes/Simple
10+
* <p>
11+
* The contents of this file are subject to the terms of the
12+
* Apache License Version 2 (the "APL"). You may not use this
13+
* file except in compliance with the License. A copy of the
14+
* APL may be obtained from:
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*/
17+
package com.compilerprogramming.ezlang.exceptions;
18+
19+
public class CompilerException extends RuntimeException {
20+
public CompilerException(String message) {
21+
super(message);
22+
}
23+
24+
public CompilerException(String message, Throwable cause) {
25+
super(message, cause);
26+
}
27+
}

0 commit comments

Comments
 (0)