.\" .\" UCSD p-System cross compiler .\" Copyright (C) 2006, 2007, 2012 Peter Miller .\" .\" This program is free software; you can redistribute it and/or modify .\" it under the terms of the GNU General Public License as published by .\" the Free Software Foundation; either version 2 of the License, or (at .\" you option) any later version. .\" .\" This program is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU .\" General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License along .\" with this program. If not, see .\" .ad l .hy 0 Compilers and Factories, 10
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 "=")?
.\" vim: set ts=8 sw=4 et :