Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

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

License

Notifications You must be signed in to change notification settings

artem-burashnikov/SimpleParser

Repository files navigation

MIT License

SimpleParser

SPBU 3rd semester homework assignment.

  1. Language Grammar
  2. Getting Started
  3. License

Language grammar

Definition using EBNF notation:

[x] denotes one or more

{x} denotes zero or more

(x) denotes a capture group

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

Installation

  1. Clone the repo:

    git clone https://github.com/artem-burashnikov/SimpleParser.git
  2. Build the project:

    ./build.sh

Usage

CLI is available:

USAGE: SimpleParser [--help] <path>

FILEPATH:

    <path>                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 for more information.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Languages