Can I Safely Store and Access Variables in a Bison/Yacc Parser?

0
6
Asked By CodeNinja7 On

I'm working on a Bison/Yacc parser and currently trying to eliminate all my shift and reduce conflicts. My main question is whether it's safe to store values and later read them in different rules. I'm concerned about potential overlaps, especially when handling expressions. For example, in my code, I have expressions that store identifiers; can one ID overwrite another? Here's a snippet for reference: In the 'expr' rule, I store the current ID when encountering an ID token. Then, in 'exprids', I try to read that stored ID. Is this approach reliable or can Bison/Yacc cause issues due to its parsing mechanisms?

2 Answers

Answered By ParserGuru88 On

Yes, actions in a Bison/Yacc parser are executed as soon as they are encountered. This means that once you've committed to an action, it will happen in the order you've written it. Your parser doesn't do any weird parallel processing with actions; everything is handled sequentially. If your parser is unambiguous, you shouldn't face any issues with reading and storing values across rules.

Answered By OldSchoolDev On

I remember using lex/yacc years ago! It's definitely straightforward when it comes to variable handling. Just ensure you're managing your variables properly to avoid confusion. If you have a clear structure and your rules are well-defined, you should be good to go!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.