ref: 64a411ede2df42eea0e6905a4985a3e54057c677
parent: 6ae2e2bb7bebdc3f4d450f1ddc6c69a02c3f4998
author: Peter Mikkelsen <peter@pmikkelsen.com>
date: Tue Jun 29 13:58:18 EDT 2021
Parse terms in parenthesis correctly
--- a/example.pl
+++ b/example.pl
@@ -2,6 +2,11 @@
math(A,B,C,D) :- D is A + B + C * A.
+parentest :-
+ 1 + 2 * 3 + 4.
+parentest :-
+ (0 * (1 + 2) * 3) * 3 + 4.
+
true.
likes(bob, ice).
--- a/parser.c
+++ b/parser.c
@@ -171,6 +171,11 @@
case CurlyBracketLeftTok:
result = curlybracketterm();
break;
+ case ParenLeftTok:
+ match(ParenLeftTok);
+ result = fullterm(ParenRightTok, nil, nil);
+ match(ParenRightTok);
+ break;
default:
print("Cant parse term of token type %d\n", lookahead.tag);
syntaxerror("term");
@@ -245,7 +250,7 @@
for(i = 0, t = list; i < length; i++){
Operator *op = getoperator(t->text);
- if(op){
+ if(op && t->tag == AtomTok){
infos[i].type = op->type;
infos[i].level = op->level;
}else{