Question: Write a top-down parser in java accepting the (left-recursing free) language below. To simplify matters, assume the input to your parser is a list (=string)
Write a top-down parser in java accepting the (left-recursing free) language below. To simplify matters, assume the input to your parser is a list (=string) of tokens, for example as follows:
E ::= -E | 0E' | 1E' | 2E' | ... E' ::= +E | *E | /E |
interface Token class T_Plus () implements Token class T_Times () implements Token class T_Minus () implements Token class T_Division () implements Token class T_Int ( n : Int ) implements Token
Here is a suggestion for the data type of abstract syntax trees in pseudo-code.
interface AST class Plus ( l : AST, r : AST ) implements AST class Times ( l : AST, r : AST ) implements AST class Minus ( arg : AST ) implements AST class Div ( l : AST, r : AST ) implements AST class Integer ( n : Int ) implements AST
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
