In this assignment you are to implement a recursive-descent recognizer with a web interface for the BNF grammar given below. Based on the pseudocode you have done in PL Assignment 1, this is a good opportunity to develop the web programming skills required by today's IT field. You must ask the user for input stream.
EXP ::= EXP + TERM | EXP - TERM | TERM
TERM ::= TERM * FACTOR | TERM / FACTOR | FACTOR
FACTOR ::= ( EXP ) | DIGIT
DIGIT ::= 0 | 1 | 2 | 3
My pseudocode for PL 1:
procedure exp()
term()
if (token == ‘+’){
match(‘+’)
term()
}
Else (if token == ‘-‘){
match(‘-‘)
term()
}
else
errorsfound
procedure term()
factor()
if (token == ‘*’){
match(‘*’)
factor()
}
else if (token == ‘/’){
match(‘/’)
factor()
}
else
errorsfound
procedure factor()
if (token == ‘(‘){
match(‘(‘)
exp()
match(‘)’)
}
else
digit()
procedure digit()
if token == ‘0’
match(‘0’)
else if token == ‘1’
match(‘1’)
else (if token == ‘2’)
match(‘2’)
else if (token ==’3’)
match(‘3’)
else
errorfound
match(t)
if (token == t)
nexttokenpointer
else
errorfound
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Basically create a javascript that can read a user's input thats a simple mathematical expression using ( ) * / + - and ends with $ (so that we know it terminates), and determine if that input is in a valid form or not. Example 2/(3+1)$ is valid, and 1*a$ is not valid