help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get the text corresponding to a bison rule


From: sgaurelius
Subject: Re: How to get the text corresponding to a bison rule
Date: Fri, 28 Nov 2008 05:23:22 -0800 (PST)

Basically, I want to derive information from it. For example, if I got a
matrix like [[1,2],[3,4]], I want to find the dimensions of it. The thing
is, taht I had already a pretty good function for doing this, when I had
manipulating the expression without bison. now with bison, if I want to the
same thing, i have to make it from the start. I will try to do it just with
bison, but if it gets too complicated, I might use my old function to find
dimensions and then do whatever I want with bison.

Stratis


Laurence Finston wrote:
> 
> 
> On Fri, 28 Nov 2008, sgaurelius wrote:
> 
>> Flex scanner has previously analyzed the string and extracted the tokens.
>> However, if I want the text that corresponds to this expression, for
>> example
>> the "(1+2)" and not just the tokens, what should I do ? Is there some
>> solution ?
> 
> Save `yytext' somewhere "persistent".  `yytext' is available in the 
> actions of your scanner.  You can save it in a data member of an object 
> that you pass as a parameter to `yylex'.  If you use Flex, you can pass a 
> parameter of a certain type (I'd have to look up what it's called) and 
> declare an object of a type of your choice to be a data member of this 
> object.  I use this to carry around information that needs to be available 
> within my scanner and parser rules, and outside them.  This is a 
> thread-safe approach.
> 
> Alternatively, you could pass the strings back to `yyparse' as the 
> semantic values of the tokens, _unless_ you need the semantic values to be 
> numeric values or something else.  This might be easier, because you 
> wouldn't have to keep track of which string is associated with a given 
> token.  If you chose this approach, you might have to convert strings to 
> numbers in your parser rules, which isn't very difficult.
> 
> There are probably other approaches, but these are the ones that occur to 
> me off the top of my head.  However, I can't think of any reason why I 
> would want to keep the strings.
> 
> Laurence Finston
> 
> 
> _______________________________________________
> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-get-the-text-corresponding-to-a-bison-rule-tp20732674p20734369.html
Sent from the Gnu - Bison - Help mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]