[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to parse linear equations
From: |
Hans Aberg |
Subject: |
Re: how to parse linear equations |
Date: |
Sat, 16 Jan 2010 19:35:07 +0100 |
[Please keep the cc to the Help-Bison list, so that others can help.]
On 16 Jan 2010, at 19:00, Michael Chen wrote:
If I use an array to hold the coefficients. Do I dynamically allocate
an array ...
If, at least for a start until you know the other things work, you use
an array that can hold all the information and restrict to a fixed
maximum number of equations, you do not need to dynamically allocate.
Otherwise, a polymorphic pointer is convenient. I use C++ which has
language support for it via virtual class functions, and cleanup via
destructors.
Others here use C, and can explain; typically a pointer void*, using
Bison's type system sorting it out. Then one has to do the cleanup by
hand in the actions, plus writing some special code (it was %error or
something) for handling parse error recovery (if you do that), as the
rule actions are not executed at this time.
...for each leaf node of the ast tree?
One can use a reference count in order to avoid always creating a new
object. If the actions typically build new objects, this may not have
much impact on the execution time of the code.
You might also not worry about memory leaks for a start, fixing that
later when you have some working code.
Hans