Back Next

Observations

A traditional response to this problem is to distinguish lvalue and rvalue expressions — in the grammar itself.

In Pascal, the following program contains an error:

 program example; var x: integer; begin
    x = 7 end.
but which error message is more helpful?
assignment_statement
    : left_expression ASSIGN right_expression
        { $$ = context->statement_assign($1, $3); }
    ; 
 statement
    : expression
        { $$ = context->statement_expression($1); }
    ;

expression
    : expression ASSIGN expression
        { $$ = context->expression_assign($1, $3); }
    ; 
ucsdpsys_compile: x.pas: 4: syntax error 
ucsdpsys_compile: x.pas: 4: statement expression not
    void as it should be, did you mean to use an
    assignment (written ":=") instead of an equality
    test (written "=")?