https://github.com/aggstam/flex-bison-jvm-language
Simple Flex and Bison programs to validate provided SimpleLanguage file syntax, perform semantic analysis and compile to JVM asembly(jasmin) for execution.
https://github.com/aggstam/flex-bison-jvm-language
compiler flex-bison jvm-bytecode language-processing
Last synced: 10 months ago
JSON representation
Simple Flex and Bison programs to validate provided SimpleLanguage file syntax, perform semantic analysis and compile to JVM asembly(jasmin) for execution.
- Host: GitHub
- URL: https://github.com/aggstam/flex-bison-jvm-language
- Owner: aggstam
- License: gpl-3.0
- Created: 2023-01-24T15:26:36.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-16T15:17:47.000Z (over 2 years ago)
- Last Synced: 2025-01-12T20:33:33.645Z (11 months ago)
- Topics: compiler, flex-bison, jvm-bytecode, language-processing
- Language: Yacc
- Homepage:
- Size: 150 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flex-bison-jvm-language
Simple Flex and Bison programs producing the corresponding C code to validate
provided SimpleLanguage (.sl) file syntax, perform semantic analysis and compile to
JVM asembly(jasmin), which can then be executed.
SimpleLanguage syntax:
```
start {program name}
{command0}
.
.
.
{commandN}
end
```
Two types of commands exist:
1. Assignment(affix format): ({var} (expression))
2. Print: (print {var or (expression)})
Assigment command example:
```
(x (3 4 +))
```
Print command examples:
```
(print (3 4 +))
(print x)
```
Notes:
- Each command is enclosed in parentheses
- Type casting and coersion are supported
- Variables are not declared(type is deducted by first assignment)
Compilation and tests execution is streamline via a Makefile.
Six valid and one invalid test SimpleLanguage files have been provided to play with.
## Usage
```
% make
```
Makefile can be configured to use a different test case set and/or files.
## Execution example
```
❯ make test
flex -s -o lexer.c lexer.l
bison -v -o parser.c parser.y
gcc -Iexternal parser.c -o compiler -lfl
Errors found 0.
Generated: test_0.class
7
Errors found 0.
Generated: test_1.class
49
49.0
Errors found 0.
Generated: test_2.class
7.0
11.0
Errors found 0.
Generated: test_3.class
7.0
Errors found 0.
Generated: test_4.class
7
Errors found 0.
Generated: test_5.class
7
Errors found 0.
Generated: test_6.class
7.0
3
ERROR: syntax error, unexpected ')'. on line 2.
Warning: value is already int, in line 4.
Variable z NOT initialized, in line 5. ERROR: Variable fault. on line 5.
Integer var y. ERROR: Narrowing Conversion (float to int). on line 6.
Warning: value is already real, in line 8.
Variable x NOT initialized, in line 9. ERROR: Variable fault. on line 9.
Errors found 4.
No Code Generated.
make: [Makefile:40: test] Error 1 (ignored)
```