Pour the water, sugar, citric acid or lemon juice, and mastic gum into a large saucepan. Stir with a wooden spoon, place over high heat, and bring to a boil. Reduce the heat to low and simmer, uncovered, for 8 minutes. Add the dried figs and anise seeds to the sugar syrup and simmer, uncovered, for 40 minutes.
Meanwhile, toast the sesame seeds. Place a dry pot, free of any oil, over medium heat. Add the sesame seeds and stir regularly with a wooden spoon until they begin to take on some color, about 2–3 minutes. Remove from the heat and set aside to cool completely.
To toast the walnuts, heat a dry pot over medium heat. Add the chopped walnuts and cook, stirring constantly, for about 2–3 minutes, or until they begin to change color slightly. Toasting the walnuts will bring out their earthy flavor. Set aside to cool.
After the dried figs have simmered in the syrup for 40 minutes, add the toasted sesame seeds, walnuts, and raw pine nuts. Stir well to combine all the ingredients. Simmer for 1 more minute, then remove from the heat and set aside to cool.
Transfer the mixture to sterilized canning jars and seal tightly. Refrigerate.