Parsing an expression in Prolog and returning an abstract syntax
问题 I have to write parse(Tkns, T) that takes in a mathematical expression in the form of a list of tokens and finds T, and return a statement representing the abstract syntax, respecting order of operations and associativity. For example, ?- parse( [ num(3), plus, num(2), star, num(1) ], T ). T = add(integer(3), multiply(integer(2), integer(1))) ; No I've attempted to implement + and * as follows parse([num(X)], integer(X)). parse(Tkns, T) :- ( append(E1, [plus|E2], Tkns), parse(E1, T1), parse