%%% Section 3: Arithmetic Expressions %%% exp(ePlus(E1, E2)) :- exp(E1), exp(E2). exp(eTimes(E1, E2)) :- exp(E1), exp(E2). exp(eInt(N)) :- integer(N). token(tLparen). token(tRparen). token(tPlus). token(tTimes). token(tInt(N)) :- integer(N). %% some very simple test cases :- initialization(parse([tInt(1), tPlus, tInt(2), tTimes, tInt(3)], ePlus(eInt(1), eTimes(eInt(2), eInt(3))))). :- initialization(parse([tInt(1), tTimes, tInt(2), tPlus, tInt(3)], ePlus(eTimes(eInt(1), eInt(2)), eInt(3)))). :- initialization(parse([tLparen, tInt(1), tRparen], eInt(1))). :- initialization(parse([tLparen, tInt(1), tPlus, tInt(2), tRparen], ePlus(eInt(1), eInt(2)))). :- initialization(parse([tLparen,tInt(1),tPlus,tInt(2),tRparen,tTimes,tInt(3)], eTimes(ePlus(eInt(1), eInt(2)), eInt(3)))). :- initialization(parse([tInt(1),tTimes,tLparen,tInt(2),tPlus,tInt(3),tRparen], eTimes(eInt(1), ePlus(eInt(2), eInt(3))))). % some negative examples if you decide to attempt the extra credit %:- initialization(\+ parse([tPlus, tInt(1), tInt(2)], _)). %:- initialization(\+ parse([tInt(1), tInt(2), tPlus], _)). %:- initialization(\+ parse([tLparen, tRparen], _)).