Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Base case: if PlusExpr is atomic, then LeftPlusExpr is also PlusExpr
- left_plus(PlusExpr, LeftPlusExpr) :-
- atomic(PlusExpr),
- LeftPlusExpr = PlusExpr.
- % Recursive case: PlusExpr is in the form A+B, where A and B are unrestricted plus expressions
- left_plus(A + B, LeftPlusExpr) :-
- % Recurse on A
- left_plus(A, LeftA),
- % If B is atomic, then LeftPlusExpr is LeftA + B
- ( atomic(B)
- -> LeftPlusExpr = LeftA + B
- ; % Else, B is in the form B1 + B2
- B = B1 + B2,
- % Recurse on B1 + B2
- left_plus(B1 + B2, LeftB),
- % Extract the left-most atomic from LeftB
- LeftB = LeftB1 + LeftB2,
- % LeftPlusExpr is LeftA + LeftB1 + LeftB2
- LeftPlusExpr = LeftA + LeftB1 + LeftB2
- ).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement