On Tue, Jan 27, 2009 at 8:59 AM, Hans Aberg <hab...@math.su.se> wrote:
> On 27 Jan 2009, at 01:14, Alex Ryu wrote: > > I have a series of large arrays of floating point data. "Attached" to >> each >> array is a smaller array of integers, call it c. What I would like to do >> is perform operations on c of this nature: >> if c[1] < 54 and c[13] != 7 then c[3] = 16, etc. These instructions will >> be >> contained in a char buffer, which I think I can use as the input to lex. >> After the operations are made, then I just want to output/write to disk >> the >> arrays. Is this possible using lex and bison? It seems like it should >> be, >> but I can't quite find a way. How do I make yyparse() "see" the arrays? >> Would I have to directly modify the output of bison? Thanks for any help >> you can provide. >> Outline: >> Say c = {1,3,5,9,-8}, and instructs = "if c[1] < 54 and c[0] != 7 then >> c[3] >> = 16" Then I would want yyparse() to change c to {1,3,5,16,-8}. Remember >> that we have a lot of "c's", so I suppose one would make the substitution >> 1 >> for c[0], etc, before passing to yylex(). >> > > Bison and Flex are used to construct compilers/interpreters, from a small > calculators as in the Bison manual, to full grown computer languages. > > Why can't or would not want you use a for an existing language, like C/C++, > or Hugs or GHC for a language like Haskell <http://haskell.org> which > admit FFI (Foreign Function Interfaces) - that might save you time, even if > you want to take the long road of constructing. > > Otherwise, external is typically called from the actions - so you make sure > your .y file ha a #include to your code header, and inserts the actions into > the headers. If you want to be able to do definitions, make a lookup table > that the lexer can see. If you want to do loops and code jumps, build > closures that can be executed after the parsing. > > Hans > Thank you for your reply. I would prefer to keep everything in the project straight C for various reasons. Your idea is interesting, however, I would prefer things to be the other way around - my main function to only call yyparse to parse the instruction string when it encounters one of the integer "header" arrays mentioned above. The vast majority of execution time will be spent on processing the numeric data, and the code for that task is very long and complex. So I think it makes more sense to do it that way - however, I understand that might not be possible, seeing as it is not the purpose yacc is designed for. I suppose the best alternative is to just hand-write a parser in C, maybe using flex for the lexer? Thanks for your time Alex PS Is top posting or bottom posting the custom here? _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison