Giter VIP home page Giter VIP logo

pepl-compiler's Introduction

PEPL Compiler

Description

This project is a simple compiler for a polynomial-evaluation programming language.

Usage

This compiler takes programs written in a text file as input via redirection.

      ex.) $ ./a.out < program.txt

A program written in the compiler-specific language is composed of three sections (in order):

  1. A polynomial declaration section
  2. A START section
  3. A user input section

The Polynomial Declaration Section:

Polynomials are declared with the following 2 forms of syntax:

form 1: POLY <name> = <polynomial>;

      note: polynomials declared in this form have only one default parameter, x

      ex.) POLY F = x^2 + x - 1;

form 2: POLY <name>(<parameter list>) = <polynomial>;

      ex.) POLY X(p, i) = p*(i + 22/7);


The START Section

The beginning of this section starts with a single line that reads START. The following lines can consist of the following statements:

1.) initializing a user-input variable

    form: INPUT <variable name>;

      note: inputs are assigned to variables in the order in which they are provided.

      ex.) INPUT G;

        G will equal the int-value x if the input section consists of "x w" (where x is an integer, and w is a potentially empty list of integers delimited by spaces).

2.) polynomial function call

    form: <name>(<argument list>);

      ex.) F(1);

      ex.) F(G);

      ex.) X(G, i);

      ex.) F(X(5, G));


The User Input Section

This section is a line at the bottom of the program that consists of a non-empty list of integers. There must be a sufficient number of integers specified in this line for all INPUT statements (There cannot be more INPUT statements than there are user inputs).

      ex.) -3 1 4 1 5 9

Simple Examples

Program_1.txt

POLY F = x + 9;
START
F(2);
1 2 3 4 5

Terminal output

$ ./a.out < Program_1.txt
11

Program_2.txt

POLY A(M, N) =
      M^6 + 3 N - N^2 + 71;
POLY B(O, P, Q) = 1 O + 2 P + 3 Q - 4;
POLY C(R, S, T) = S + 100;
POLY D
      (U, V, W) = U^2 + 4 V^2 W^3 - 6 U^1 V^4;
POLY E = x^5 - x^4 + 2;
START
INPUT X;
INPUT Y;
A(X, Y);

INPUT X;
INPUT Y;
INPUT Z;
B(X, Y, Z);

INPUT X;
INPUT Y;
INPUT Z;
C(X, Y, Z);
D(X, Y, Z);

INPUT X;
INPUT Y;
INPUT Z;
D(X, Y, Z);
E(Z);

1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6

Terminal Output

$ ./a.out < Program_1.txt
74
22
101
32
3401
2502

pepl-compiler's People

Contributors

zackdillabough avatar

Stargazers

 avatar

Watchers

 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.