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

Respuesta :

Answer:

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

Explanation:

good job