yacc

Simple string passing through nodes in Bison/Yacc

会有一股神秘感。 提交于 2020-01-05 09:12:11
问题 I have to concatenate strings in semantic rules of my yacc file: %union { stringstream sstream; } %type<sstream> node1 node2 --- node1 : node2 { $$ << $1 << " goodbye" } node2 : final { $$ << "hello" } However, as stringstream or even string are not allowed in unions, I don't find any easy way to mix char * , int , and make nodes transport a string that I can manipulate everywhere. How should I do it ? 回答1: I don't remember bison / yacc details, but you sure can use pointer and new it. Just

Flex reentrant with start conditions

人盡茶涼 提交于 2020-01-04 09:18:27
问题 I am trying to make a reentrant scanner that relies on start conditions. I was following along something similar to this guys question: Writing re-entrant lexer with Flex And as the one poster mentioned, the scanner will work if you explicitly create the yyscan_t and pass it as an extra argument. However, I still get the yyg undeclared error message when using BEGIN <sc> , etc to manipulate the start condition. Is this a bug? Should I explicity use the yy_push_state and yy_pop_state state

YACC rules not getting reduced

拟墨画扇 提交于 2020-01-03 13:30:48
问题 I'm trying to learn YACC and having a bit of trouble figuring out the warning messages it is giving me. Here is part of my file: define_character: WORD IS STRING COLOR { printf("%s's full name is %s and thier color is %s", $1, $3, $4); }; dialog: WORD COLON STRING { printf("%s says %s", $1, $3); }; change_scene: SCENE SETSCENE WORD { printf("%s is the new scene", $3); }; The warnings that it gives me are: 2 rules never reduced 2 useless nonterminals and 2 useless rules warning: useless

Objective-C ParseKit return value

半世苍凉 提交于 2020-01-03 03:09:06
问题 In flex/lex/bison/yacc (all of which I just started reading about), you can set "$$" to be equal to some value ($1,$2,$3) and that's the value that gets returned. At least I think that's how it works. In ParseKit, you are given a stack so I imagine that the ($1,$2,$3) would be the first three values on the stack for example. But then I think what you would want to do is pop those values off the stack and put your return value on the stack. I see that the stack comes with a push method. Do you

Objective-C ParseKit return value

▼魔方 西西 提交于 2020-01-03 03:09:03
问题 In flex/lex/bison/yacc (all of which I just started reading about), you can set "$$" to be equal to some value ($1,$2,$3) and that's the value that gets returned. At least I think that's how it works. In ParseKit, you are given a stack so I imagine that the ($1,$2,$3) would be the first three values on the stack for example. But then I think what you would want to do is pop those values off the stack and put your return value on the stack. I see that the stack comes with a push method. Do you

What are the standard grammar parsers for iOS?

江枫思渺然 提交于 2020-01-02 20:17:21
问题 Does iOS for iPad and iPhone have support for a parser? In particular, is lex/yacc or flex/bison available for iOS development? Does xcode4 have a natively supported library? (I could generate my grammar via lex/yacc and then take the *.c files and put them in my project, but I was hoping for more tightly supported libraries.) Any ideas? 回答1: lex, yacc, flex, and bison all come with the Mac/iOS developer tools. Xcode has built-in rules for processing .l files with flex and .y files with bison

Most effective way to parse C-like definition strings?

三世轮回 提交于 2019-12-30 09:32:35
问题 I've got a set of function definitions written in a C-like language with some additional keywords that can be put before some arguments(the same way as "unsigned" or "register", for example) and I need to analyze these lines as well as some function stubs and generate actual C code from them. Is that correct that Flex/Yacc are the most proper way to do it? Will it be slower than writing a Shell or Python script using regexps(which may become big pain, as I suppose, if the number of additional

How to build an Array with Bison/Yacc and a Recursive Rule

吃可爱长大的小学妹 提交于 2019-12-30 05:23:07
问题 With Bison, I figured out how to get everything into one long string as follows: arg_list: WORD arg_list { strcat( $1, "IFS" ); $$ = strcat($1, $2); } | WORD ; and: WORD arg_list { printf("%s, %s\n", $1, $2); } But the problem is that I will then have to split up $2 in the second rule again to parse it. Is there a way to populate an array instead of just using concatenation? Am I going about this the wrong way? If I need to build something like a linked list that could make sense, just not

How do i implement If statement in Flex/bison

拥有回忆 提交于 2019-12-29 11:41:54
问题 I dont get the error, please can you help me out, here is the .l and .y file.thanks. %{ #include "ifanw.tab.h" extern int yylval; %} %% "=" { return EQ; } "!=" { return NE; } "<" { return LT; } "<=" { return LE; } ">" { return GT; } ">=" { return GE; } "+" { return PLUS; } "-" { return MINUS; } "*" { return MULT; } "/" { return DIVIDE; } ")" { return RPAREN; } "(" { return LPAREN; } ":=" { return ASSIGN; } ";" { return SEMICOLON; } "IF" { return IF; } "THEN" { return THEN; } "ELSE" { return

How do i implement If statement in Flex/bison

蹲街弑〆低调 提交于 2019-12-29 11:41:11
问题 I dont get the error, please can you help me out, here is the .l and .y file.thanks. %{ #include "ifanw.tab.h" extern int yylval; %} %% "=" { return EQ; } "!=" { return NE; } "<" { return LT; } "<=" { return LE; } ">" { return GT; } ">=" { return GE; } "+" { return PLUS; } "-" { return MINUS; } "*" { return MULT; } "/" { return DIVIDE; } ")" { return RPAREN; } "(" { return LPAREN; } ":=" { return ASSIGN; } ";" { return SEMICOLON; } "IF" { return IF; } "THEN" { return THEN; } "ELSE" { return