Skip to content

Project for Organization of Programming Languages

Notifications You must be signed in to change notification settings

JC2615/ProgLangProj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Organization of Programming Languages Final Project

Work Distribution

Joshua created the alphabet, language, and lexer. James worked primarily on the grammar and parser.

Alphabet

{var: Variable name [a-z][A-Z], num: Integer [0-9][0-9]*, op: operators [+ | - | ^]}

Language

Input will and follow this format, allowing for spaces: {op}{num}{op}{var}{op}{num}{var}{op}{num} Assuming the terms are in order

Grammar

Link to initial grammar

Modified Grammar:

<expr>        ->  <term2>  <term1>  <term0>
<term2>       ->  <sign>  <number>  <variable>  <karat>  <two>
<term1>       ->  <sign>  <number>  <variable>  <term1a>
<term1a>      ->  <karat>  <one> |  𝛆
<term0>       ->  <sign>  <number>  <term0a>
<term0a>      ->  <variable>  <karat>  <zero> | 𝛆
<sign>        ->  “+” | “-”
<number>      ->  <number> <number> | <number> 𝛆 | “0” | “1” | “2” | “3” | “4” | “5” | “6” | “7” | “8” | “9”
<variable>    ->  “x”
<karat>       ->  “^”
<two>         ->  “2”
<one>         ->  “1”
<zero>        ->  “0”

Parse Tree

Here is an example of the parse tree that would be created if we gave the input +2x^2+4x - 4 image

Program and Testing

image To run, we simply enter a valid quadratic equation, like the ones below, then the program will display its roots. We tested the program with these inputs and you are able to see the output in the screenshot above:

  • +2x^2+4x-4 (valid input)
  • -5x^2-3+17 (invalid input, displays error)
  • -5x^2-3x+17 (valid input)

About

Project for Organization of Programming Languages

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages