I know that languages like Python have simultaneous (or "multiway") assignment. Today at an exam I came across a question along the lines of
Write the productions of a grammar for simultaneous assignment, so that if
a,b = 1, 1+0;
is passed, it would parse fine buta,b,c = 1, 1+0
would return an error (that is to say the number of ids needs to be the same as expressions)? The error should be syntax error.
I understood by this:
You do not need to write the attributes for the grammar (since it was syntax only).
I've tried and looked for all over the place for hints that might help me, but I still see no way of working it out with the way I have been taught how to write grammar. This is what I have so far:
P -> id Id_Tail = exp exp_Tail
Id_Tail -> , id Id_Tail
Id_Tail -> ε
exp_Tail -> , exp exp_Tail
exp_Tail -> ε
exp -> //assume this is is defined well enough to allow for all type of expressions that will generate/have a num (value) that is allowed to be assigned to the respective id
However, this in no way will generate the syntax error that is wanted (it could keep on generating more expressions than ids).