https://github.com/louisjenkinscs/dsl
A minimal, Turing-complete, Domain-Specific Language; simple text editor with an interpreter, Abstract Syntax Tree and reduced Control Flow Graph graphical generator.
https://github.com/louisjenkinscs/dsl
abstract-syntax-tree control-flow-graph domain-specific-language grammar interpreter language syntax-tree turing-completeness
Last synced: 10 months ago
JSON representation
A minimal, Turing-complete, Domain-Specific Language; simple text editor with an interpreter, Abstract Syntax Tree and reduced Control Flow Graph graphical generator.
- Host: GitHub
- URL: https://github.com/louisjenkinscs/dsl
- Owner: LouisJenkinsCS
- License: bsd-3-clause
- Created: 2017-05-05T20:15:08.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-08-23T19:21:07.000Z (over 4 years ago)
- Last Synced: 2025-05-08T20:53:28.550Z (11 months ago)
- Topics: abstract-syntax-tree, control-flow-graph, domain-specific-language, grammar, interpreter, language, syntax-tree, turing-completeness
- Language: Java
- Size: 3.09 MB
- Stars: 18
- Watchers: 0
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DSL
DSL is a very minimal domain specific language, with a problem domain being academic research, designed and created for a Theory of Computation course. Bundled with this program is a simple text editor which allows the user to execute (interpret) code written in the language, generate a graph of the Abstract Syntax Tree for the language, and a reduced Control Flow Graph.
## Screenshots
Below are screenshots of the Fibonacci problem
### Output from interpretation

### Generated Abstract Syntax Tree

### Generated Control Flow Graph

## Developer's Note and Warning
I would like to note that this project was hacked together in a very brief time under *extremely* tense time constraints, and as such the code quality, to say the *least* is lacking. As well, the logic is counter-intuitive at times, and some things are still buggy and broken. I am officially done with the project, although it does deserve to be displayed here as a lot of work went into it.
### Bugs
#### Control Flow Graph - Basic Block Reduction
Control Flow Graph incorrectly reduces the last node of a while loop into its own basic block due to the wonky reduction algorithm I devised. If anyone wants to work on it, that's one of the first things needing to be done; the Control Flow Graph algorithm needs an entirely new overhaul. It should be noted that control flow itself is correct, as it does introduce a back-edge from the incorrectly-constructed singleton basic block.
## Grammar
The BNF grammar can be seen below...
```
prog : prog stmt
| stmt
| /* Empty */
;
conditional : WHILE expr block
| IF expr block
| IF expr block ELSE block
;
stmt : VAR NAME '=' expr ';'
| NAME '=' expr ';'
| conditional
| PRINT expr ';'
;
stmt_list : stmt stmt_list
| /* Empty */
;
block : '{' stmt_list '}'
;
expr : expr '+' expr
| expr '-' expr
| expr '*' expr
| expr '/' expr
| expr EQ expr
| expr NEQ expr
| expr GE expr
| expr LE expr
| expr '>' expr
| expr '<' expr
| '(' expr ')'
| INTEGER
| STRING
| NAME
;
```
### Code Example
```
var x = 0;
var y = 100;
while (x < y) {
if (x == 10) {
print "X: " + x;
}
}
```