Skip to main content

A toy functional language compiler written in Python

Project description

# LnaC

### A toy functional language compiler written in Python.

---

LnaC is a toy functional language compiler written in Python 3 that supports limited program generation.

For some sample programs, see the [demos directory](demos).

## Quickstart

To install LnaC:
```
pip3 install lnac
```

To create, compile, and run an example program:
```c
$ nano return0.lna
$ less return0.lna

main : int
main =
=> 0

$ lnac return0.lna
$ ./return0 && $?
True
```

## Implementation

### Lexer
The LnaC lexer is primarily implemented in [`lexer.py`](lnac/lexer.py). Additionally, [`tokens.py`](lnac/tokens.py) contains definitions of the token classes used in the lexer and instances of recognized keyword and symbol tokens.

### Parser
The LnaC parser is implemented in [`parser/parser.py`](lnac/parser/) and creates an abstract syntax tree of nodes defined in [`tree/nodes.py`](lnac/tree/nodes.py).

### Assembly
LnaC writes out an intermediary assembly file that gcc then generates an executable from. This assembly file is written following the AT&T assembly syntax and is deleted following a successful compilation.

## References
- Writing a C Compiler - https://norasandler.com/2017/11/29/Write-a-Compiler.html
- ShivyC - https://github.com/ShivamSarodia/ShivyC

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lnac-0.0.9.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

lnac-0.0.9-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file lnac-0.0.9.tar.gz.

File metadata

  • Download URL: lnac-0.0.9.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lnac-0.0.9.tar.gz
Algorithm Hash digest
SHA256 d25b0f92de62e3ba10f8667dbf23c2d5a7792a9c08619c34bb347274921282a2
MD5 58931f66cec24d7d318bd051a83778af
BLAKE2b-256 8cb5d82f998303d43cdce986f033bbb1cf644dbd3e51a177419c4068b28fbdd3

See more details on using hashes here.

File details

Details for the file lnac-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: lnac-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lnac-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 768de2b040bf5817ff5748fcc799d8c7abf0c7d3c23347dc691525a9014aedc5
MD5 f3f549a23bfcec046c7ff59f318f5790
BLAKE2b-256 4b6851a3c72687d4f9cc0ba8857ff12b081fc1d61d7cf2856bffc4dc6a6b0ccd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page