Using DCGs for building a serialiser

Hi

I’ve given up using DCGs for my serialiser. I’m using state variables now (a Mercury feature). Thanks to Boris.

Bye,
Volker

Isn’t the use of two state variables and DCG the same thing

You mean two state variables in addition to the two implicit ones from the DCG?

I wanted the state to be encoded inside the two implicit lists. I’ve tried, but it wouldn’t compile in Mercury. The same in Prolog worked…

Also, the “[ … ]” syntax of DCGs didn’t work for the serialiser, in my example program.

I’ts a mess. I don’t understand what goes on with using DCGs for a serialiser. State variables are much clearer.

But I had no trouble building a parser with DCGs…

So long,
Volker

I understand that is for Mercury. The Prolog case is quite clean and used a lot. The entire SWI-Prolog html framework is based on them :slight_smile:

I surely see the benefits of state variables. Shouldn’t be too hard to implement using term_expansion/2. Anyone :slight_smile:

EDCGs already implement state variables. I use them a lot. (EDCGs allow two things: multiple “accumulators” / “state variables”; and the ability to customize how these accumulators/state variables are defined. For example, I have one accumulator that’s a symbol table, using rbtrees rather than lists.)

(I’ve also enhanced EDCGs so that they can generate => rules instead of :-, if desired.)