Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/artem-burashnikov/simpleparser

Part of the SPBU's programming course. Parser, interpretator and optimizer for a simple formal language.
https://github.com/artem-burashnikov/simpleparser

fsharp interpretator optimizer parser parser-combinators

Last synced: about 2 months ago
JSON representation

Part of the SPBU's programming course. Parser, interpretator and optimizer for a simple formal language.

Awesome Lists containing this project

README

        

[![MIT License][license-shield]][license-url]

# SimpleParser

SPBU 3rd semester homework assignment.



  1. Language Grammar


  2. Getting Started



  3. License

## Language grammar

Definition using [EBNF][grammar-notation] notation:

`[x]` denotes one or more

`{x}` denotes zero or more

`(x)` denotes a capture group

```ignorelang
digit = "1" | ... | "9"

number = { digit }

letter = "a" | ... | "z" | "A" | ... | "Z"

identifier = letter { letter | digit }

factor = identifier | number | ifExpression | (factor "*" factor)

add = factor | (add "+" add)

arithmeticExpression = factor | add

booleanValue = "true" | "false"

relationalOperator = "=" | "<>" | "<=" | "<" | ">=" | ">"

booleanExpression = booleanValue | (arithmeticExpression | identifier) relationalOperator (arithmeticExpression | identifier)

ifExpression = "if" "(" booleanExpression ")" "then"
"(" [ arithmeticExpression | booleanExpression | ifExpression ] ")"
"else"
"(" [ arithmeticExpression | booleanExpression | ifExpression ] ")"

command = "print:" (arithmeticExpression | identifier)

assignment = identifier "=" (booleanValue | arithmeticExpression | identifier | ifExpression)

statement = assignment | command

program = {statement}
```

## Getting Started

To get a local copy up and running follow the steps below.

### Prerequisites

[.NET >= 7.0][net-link]

### Installation

1. Clone the repo:

```shell
git clone https://github.com/artem-burashnikov/SimpleParser.git
```

2. Build the project:

```shell
./build.sh
```

### Usage

CLI is available:

```ignorelang
USAGE: SimpleParser [--help]

FILEPATH:

Specify a path to the file
containing a program.

OPTIONS:

--help Display this list of options.
```
Following a language definition, a simple program may look like this:
```
x=3
y=2
z=if(true)then(x*y+7)else(1)
print:z
```
Outputs `13` to the console.

## License

Distributed under the MIT License. See [LICENSE][license-url] for more information.

[license-shield]: https://img.shields.io/github/license/artem-burashnikov/SimpleParser.svg?style=for-the-badge
[license-url]: https://github.com/artem-burashnikov/SimpleParser/blob/main/LICENSE
[net-link]: https://dotnet.microsoft.com/en-us/download
[grammar-notation]: https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form