Are DCG's just "syntactic sugar"?

No, they are just syntactic sugar but they do make working with certain types of data easier, e.g. list, difference list, bill of materials, fill gap parsing. See: dcg_translate_rule/2 and source code (GitHub)

If you are processing lots of list or difference list then you should consider using DCGs (example). If you are parsing input text that is anything more complicated then returning tokens by splitting at delimiters then I would say you should always use DCGs.

For the last few months I have been parsing many different types of data files, some a few gigabytes in size, some very complex, and over the decades have worked with many types of parsing technology, Regular Expressions,recursive decent parser, ANTLR, parser combinator, and others, but by far the one parsing technology I actually enjoy using and is powerful enough to tackle every problem I have is DCGs. Granted DCGs may not be the fastest parsers around, but for getting a parser up and working and running down the details of those odd transitions during development I have found no better means.

4 Likes