GithubHelp home page GithubHelp logo

bares's Introduction

Introduction

Basic ARithmetic Expression Evaluator based on Stacks

This program supports:

  • Integers in a range from -32.786 to 32.767.
  • Common operators like +, -, /, *, ^ and %.

This programming project implements a simple parser for an EBNF (Extended Backus-Naur Form) grammar.

It also uses my own vector implementation found here.

The objective Information on EBNF grammar may be found here.

Information on recursive descendent parsing may be found here.

The Grammar

The gramar we want to parse represents arithmetic expressions with addition and subtraction of integers.

<expr>            := <term>,{ ("+"|"-"),<term> };
<term>            := "(",<expr>,")" | <integer>;
<integer>         := 0 | ["-"],<natural_number>;
<natural_number>  := <digit_excl_zero>,{<digit>};
<digit_excl_zero> := "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
<digit>           := "0"| <digit_excl_zero>;

This grammar accepts expressions like:

  • "23 + 43 - 0 + -124 - 21"
  • " 21"
  • "-21 + -18"
  • " -54"
  • "-21 - 23 + 1234"
  • (2+3) * 8
  • 5 % 2 ^4
  • (5 % 3) ^4

And rejects expressions like:

  • 2+
  • 3 * d
  • 2 = 3
  • 2.3 + 4
  • "01 + 3"
  • " - 3 + 4"
  • "2 +"
  • " "
  • "+2 + 5"
  • "-02 + 4"
  • ")2 - 4"
  • "((2%3) * 8"
  • "3/(1-1)"

Usage

You will need at least g++ C11 compiler and GNU makefile

to build it simply run:

make

For running Bares execute it like this:

./bares input_file [output_file]

If you just want to give it a try, there is an sample input file inside the data/ directory with all the samples from the project pdf located in the res/ directory.

If no output file is specified this program will write to "output.txt" by default

Authorship

This Program was made by me, Max William, as an exercise for a programming languages course i'm taking in Computer Science at Universidade Federal do Rio Grande do Norte.

Github

If you've somehow managed to find this project outside of github the original repository is located here

bares's People

Contributors

maxwillf avatar selan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.