Joshua created the alphabet, language, and lexer. James worked primarily on the grammar and parser.
{var: Variable name [a-z][A-Z], num: Integer [0-9][0-9]*, op: operators [+ | - | ^]}
Input will and follow this format, allowing for spaces: {op}{num}{op}{var}{op}{num}{var}{op}{num} Assuming the terms are in order
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”
Here is an example of the parse tree that would be created if we gave the input +2x^2+4x - 4
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)