Re: fully parenthesized expression?



On 8 Mar 2007 09:40:28 -0500, Mr.E wrote:

[snip]
You need an output queue with both ends accessible rather than a FIFO
output stream ["print"]. But the technique I am using is different. I add
the source location range to all values on the operation and the argument
stacks. The expression terms get the location range of the corresponding
literal / identifier. So do the operations. When a new value is computed
its location range is evaluated as the least range containing the ranges of
the operation and operands generating the value. The ranges can be then
used for error messages generation and in your case to indicate parsing /
evaluation progress and operands association in the source.

Unfortunately, I'm not comprehending. I dont know if its similar to
an idea I played with unsuccessfully of 'marking' the resulting stack
element unusable after a reduction. As for example in a multiplcation

value[valTop-1] = value[valTop-1] * value[valTop];
usableValue[VTop - 1] = FALSE;

The variant with queue (pseudo-code):

Stack >> Right;
Stack >> Left;
Stack << Left * Right;
'(' >> Qutput; // The left side of the output queue accessed
Output << '*';
Output << Right;
Output << ')';

Once you finished, you can print Output.

The variant with source locations:

Stack >> Right;
Stack >> Left;
Stack <<
Operand
( Left.Value * Right.Value,
Left.Location + Right.Location + Location_of_Multiply
);

At this point you can show the operand's associations in the source code
window using for example colored boxes drawn around them. The operation
sign would have the color of the boxes around the operands. The result
could look like this:
.._____________. .___.
|.___. .___.| | |
|| 2 | * | 3 || + | 4 |
||___| |___|| | |
|_____________| |___|

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.



Relevant Pages

  • Re: fully parenthesized expression?
    ... The expression terms get the location range of the corresponding ... Where value is the stack for values and usableValue is the stack ... If the left hand side is not usable for display purposes then only the ...
    (comp.compilers)
  • Re: fully parenthesized expression?
    ... fully parenthesized representation of the original expression. ... reduce I print out what is on the stack but ... The expression terms get the location range of the corresponding ... used for error messages generation and in your case to indicate parsing / ...
    (comp.compilers)