I am writing in Prolog and keep getting the error;
syntax error: current or previous operator needs brackets
When referring to te=he following code:
convert_to_tokens([Word|Rest], [Token|RestTokens]) :-
atom_string(Atom, Word),
( Atom == '+' -> Token = pl
; Atom == '-' -> Token = mi
; Atom == '*' -> Token = ti
; Atom == '/' -> Token = di
; number_string(Number, Word) -> Token = Number
; atom_chars(Word, [H|T]), char_type(H, alpha) -> Token = id(Word)
; Token = Atom
),
convert_to_tokens(Rest, RestTokens).
I have tried using actual brackets, curly brackets, removing the brackets, etc. But I cannot seem to find a solution. Can anyone figure out what it is asking for? Thank you!
The brackets the error message refers to are round brackets. In place of
Atom == '+'writeAtom == (+)and same for-,*,/to make it ISO syntax. That specific error message was produced by gnu-prolog.Also note that the code was probably written for SWI, since e.g. atom_string/2 is not ISO, but is present in SWI. All these conversions are only necessary in SWI btw.