[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changing input and capturing output
From: |
Donges, William E.,, III |
Subject: |
Changing input and capturing output |
Date: |
Mon, 5 Aug 2002 12:47:03 -0400 |
Well after a weekend of pounding my head against the keyboard I do not feel I
am any closer to solving this problem. I redefined yylex to move through a
string and on its own the function seems to work. But I still do not understand
how to get that string input into the parser in general. Here is the problem
recrystalized.
What I have:
1. A series of individual user defined string literals in the c end of a
program. (These are mathematical expressions of the form "
2^2-3+2-9d7*(9+6)"; (d is a specialized left associative operator which calls
for a in this case 9 numbers between 1 and 7)
2. A Nodified version of the bison manuals infix notation calculator that
understands my d operator. (This works brilliantly in a shell from
stdin and to stdout)
3. To use C. C++ is not an option.
What I need to do:
1. Take this string literals find the mathematics.
2. Evaluate the resultant mathematical expression.
3. Then return the resulting float the int portion of which can be reused.
(Or else it should do int math to begin with).
As an aside:
If a parse error is detected the error function should not output to standard
out but should somehow update a error flag that can be read. (This is primarily
a C problem not Bison so its not on topic here, My concern is that if 2 strings
are being sent to the parser and I use a global variables I will have
incorrectly reported errors on one of the two strings if only one has a parse
error)
I have asked about this in other places and was told to use Bison that If I
wanted a mathematical expression parser that was the way to go. For reasons
unclear to me however there does not seem to be any answer anywhere about
how to do what it is I have asked. To send in a string and capture its
resultant. I was able to get some valuable advice about rewriting yylex to work
on a string literal. I did that. But I still cannot comprehend how
to change the input away from stdin and the output away from stdout.
Ideas? Can this even be done? Why is it not more straight forward?
Bill Donges
- Changing input and capturing output,
Donges, William E.,, III <=