2
votes

When I generate my parser with bison, I obtain this warning:

warning: stray `@'

But that is because I have some legal Objective-C code containing @, for instance this is one of the rules having the warning:

file : axiom production_rule_list    { NSLog(@"file"); }
     ;

Is there any risk to use @ in the code? If not, how to tell bison that it is a legitimate use of @?

Thanks in advance.

3
Thanks but the problem is not during gcc compiling, but when I generate the parser with bison...Zaphod
@robmayoff My problem is just the bison warning, not the integration of Flex and Bison into Xcode.Zaphod
@Zaphod But the bison warning is resolved with the information in the linked post. You just have to rename your yacc file to use the .ym extension.Nikolai Ruhe

3 Answers

2
votes

The message is just a warning. You can ignore it. If you're using Xcode, it won't even show you the warning in its Issue Navigator.

Rename your Bison input file to have a .ym extension instead of a .y extension. That tells Xcode that it's a grammar with Objective-C actions.

2
votes

If you want to suppress the warning, you can use a #define AT @.

The code in the braces is just copied, apart from replacing the $… sequences with the code to give the relevant token. This appears to work fine with Objective-C, although if you're using ARC, you might need to do some digging (or just add extra blocks (in the C sense)) to make sure that objects are freed as soon as possible.

0
votes

As per the documentation in Actions - Bison 2.7, it appears that the code between the curly braces is expected to be C code. As such I doubt that you can use objective-c constructs there.

However you could create an external C function to do the work for you like:

Logit(char* message)
{
  NSLog(@"%s",message);
}

And use that in the Bison action

file : axiom production_rule_list    { Logit("file"); }
     ;