|
From: | Hans Aberg |
Subject: | Re: Using the "output" from yacc |
Date: | Tue, 27 Jan 2009 15:59:02 +0100 |
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 dois 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 helpyou 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 1for 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
[Prev in Thread] | Current Thread | [Next in Thread] |