Why scanf in bison grammatical rule not working?












0















I have this gramatical rule in my .y file



...
listaIdentificadores :listaIdentificadores ',' ID {leer($3);}
|ID {leer($1);}
;
...


and this is definition of leer()



void leer(char* identificador) {
int valor;
scanf("%d",&valor);
cargarTS(identificador, valor);
}


but when scanf() should be executed it does not ask for the keyboard input and it simply continues with the execution of the following code line.










share|improve this question




















  • 1





    I am not familar with Bison, but are you leaving any newlines (n or pressing Enter) or any other characters in the input stream before the scanf() from other scanf()s, reads, et cetera?

    – Tau
    Nov 14 '18 at 14:42








  • 1





    You are going to have to provide more code than that. Where is the lexer getting its input from? If it is also coming from standard input, it's very hard to see how that can "work" (although it's also not clear to me what you are trying to do).

    – rici
    Nov 14 '18 at 15:14











  • I'm using 'flex', getting the characters from the standard input. maybe later I can upload all the code

    – Cosmonauta
    Nov 14 '18 at 17:25






  • 1





    "getting the characters from the standard input". So when you call scanf, do you expect that to read from the file that you're piping into stdin? So does that mean that after the ID token there will be a number in the source and you want scanf to read that number? If that's the case, you should just add an integer token to your grammar rule instead of scanf. If you're trying to read user input independently from reading the source code, you can't read both from stdin.

    – sepp2k
    Nov 14 '18 at 17:32






  • 1





    @Cosmonauta First of all, you can't read input from stdin as the same type as you're reading the source from stdin? How should that work? Do you want the user to enter the source code, followed by some terminator and then the input? If so, that won't work because your actions are going to be evaluated while the source is being read, not after. Secondly, trying to run the program while parsing it, isn't going to work anyway. As soon as you try to implement ifs or loops that way, you're going run into trouble. You'll want to make your parser generate an AST or bytecode and then ...

    – sepp2k
    Nov 15 '18 at 17:52
















0















I have this gramatical rule in my .y file



...
listaIdentificadores :listaIdentificadores ',' ID {leer($3);}
|ID {leer($1);}
;
...


and this is definition of leer()



void leer(char* identificador) {
int valor;
scanf("%d",&valor);
cargarTS(identificador, valor);
}


but when scanf() should be executed it does not ask for the keyboard input and it simply continues with the execution of the following code line.










share|improve this question




















  • 1





    I am not familar with Bison, but are you leaving any newlines (n or pressing Enter) or any other characters in the input stream before the scanf() from other scanf()s, reads, et cetera?

    – Tau
    Nov 14 '18 at 14:42








  • 1





    You are going to have to provide more code than that. Where is the lexer getting its input from? If it is also coming from standard input, it's very hard to see how that can "work" (although it's also not clear to me what you are trying to do).

    – rici
    Nov 14 '18 at 15:14











  • I'm using 'flex', getting the characters from the standard input. maybe later I can upload all the code

    – Cosmonauta
    Nov 14 '18 at 17:25






  • 1





    "getting the characters from the standard input". So when you call scanf, do you expect that to read from the file that you're piping into stdin? So does that mean that after the ID token there will be a number in the source and you want scanf to read that number? If that's the case, you should just add an integer token to your grammar rule instead of scanf. If you're trying to read user input independently from reading the source code, you can't read both from stdin.

    – sepp2k
    Nov 14 '18 at 17:32






  • 1





    @Cosmonauta First of all, you can't read input from stdin as the same type as you're reading the source from stdin? How should that work? Do you want the user to enter the source code, followed by some terminator and then the input? If so, that won't work because your actions are going to be evaluated while the source is being read, not after. Secondly, trying to run the program while parsing it, isn't going to work anyway. As soon as you try to implement ifs or loops that way, you're going run into trouble. You'll want to make your parser generate an AST or bytecode and then ...

    – sepp2k
    Nov 15 '18 at 17:52














0












0








0








I have this gramatical rule in my .y file



...
listaIdentificadores :listaIdentificadores ',' ID {leer($3);}
|ID {leer($1);}
;
...


and this is definition of leer()



void leer(char* identificador) {
int valor;
scanf("%d",&valor);
cargarTS(identificador, valor);
}


but when scanf() should be executed it does not ask for the keyboard input and it simply continues with the execution of the following code line.










share|improve this question
















I have this gramatical rule in my .y file



...
listaIdentificadores :listaIdentificadores ',' ID {leer($3);}
|ID {leer($1);}
;
...


and this is definition of leer()



void leer(char* identificador) {
int valor;
scanf("%d",&valor);
cargarTS(identificador, valor);
}


but when scanf() should be executed it does not ask for the keyboard input and it simply continues with the execution of the following code line.







scanf bison






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 14:49









Cœur

17.6k9105145




17.6k9105145










asked Nov 14 '18 at 14:37









CosmonautaCosmonauta

1




1








  • 1





    I am not familar with Bison, but are you leaving any newlines (n or pressing Enter) or any other characters in the input stream before the scanf() from other scanf()s, reads, et cetera?

    – Tau
    Nov 14 '18 at 14:42








  • 1





    You are going to have to provide more code than that. Where is the lexer getting its input from? If it is also coming from standard input, it's very hard to see how that can "work" (although it's also not clear to me what you are trying to do).

    – rici
    Nov 14 '18 at 15:14











  • I'm using 'flex', getting the characters from the standard input. maybe later I can upload all the code

    – Cosmonauta
    Nov 14 '18 at 17:25






  • 1





    "getting the characters from the standard input". So when you call scanf, do you expect that to read from the file that you're piping into stdin? So does that mean that after the ID token there will be a number in the source and you want scanf to read that number? If that's the case, you should just add an integer token to your grammar rule instead of scanf. If you're trying to read user input independently from reading the source code, you can't read both from stdin.

    – sepp2k
    Nov 14 '18 at 17:32






  • 1





    @Cosmonauta First of all, you can't read input from stdin as the same type as you're reading the source from stdin? How should that work? Do you want the user to enter the source code, followed by some terminator and then the input? If so, that won't work because your actions are going to be evaluated while the source is being read, not after. Secondly, trying to run the program while parsing it, isn't going to work anyway. As soon as you try to implement ifs or loops that way, you're going run into trouble. You'll want to make your parser generate an AST or bytecode and then ...

    – sepp2k
    Nov 15 '18 at 17:52














  • 1





    I am not familar with Bison, but are you leaving any newlines (n or pressing Enter) or any other characters in the input stream before the scanf() from other scanf()s, reads, et cetera?

    – Tau
    Nov 14 '18 at 14:42








  • 1





    You are going to have to provide more code than that. Where is the lexer getting its input from? If it is also coming from standard input, it's very hard to see how that can "work" (although it's also not clear to me what you are trying to do).

    – rici
    Nov 14 '18 at 15:14











  • I'm using 'flex', getting the characters from the standard input. maybe later I can upload all the code

    – Cosmonauta
    Nov 14 '18 at 17:25






  • 1





    "getting the characters from the standard input". So when you call scanf, do you expect that to read from the file that you're piping into stdin? So does that mean that after the ID token there will be a number in the source and you want scanf to read that number? If that's the case, you should just add an integer token to your grammar rule instead of scanf. If you're trying to read user input independently from reading the source code, you can't read both from stdin.

    – sepp2k
    Nov 14 '18 at 17:32






  • 1





    @Cosmonauta First of all, you can't read input from stdin as the same type as you're reading the source from stdin? How should that work? Do you want the user to enter the source code, followed by some terminator and then the input? If so, that won't work because your actions are going to be evaluated while the source is being read, not after. Secondly, trying to run the program while parsing it, isn't going to work anyway. As soon as you try to implement ifs or loops that way, you're going run into trouble. You'll want to make your parser generate an AST or bytecode and then ...

    – sepp2k
    Nov 15 '18 at 17:52








1




1





I am not familar with Bison, but are you leaving any newlines (n or pressing Enter) or any other characters in the input stream before the scanf() from other scanf()s, reads, et cetera?

– Tau
Nov 14 '18 at 14:42







I am not familar with Bison, but are you leaving any newlines (n or pressing Enter) or any other characters in the input stream before the scanf() from other scanf()s, reads, et cetera?

– Tau
Nov 14 '18 at 14:42






1




1





You are going to have to provide more code than that. Where is the lexer getting its input from? If it is also coming from standard input, it's very hard to see how that can "work" (although it's also not clear to me what you are trying to do).

– rici
Nov 14 '18 at 15:14





You are going to have to provide more code than that. Where is the lexer getting its input from? If it is also coming from standard input, it's very hard to see how that can "work" (although it's also not clear to me what you are trying to do).

– rici
Nov 14 '18 at 15:14













I'm using 'flex', getting the characters from the standard input. maybe later I can upload all the code

– Cosmonauta
Nov 14 '18 at 17:25





I'm using 'flex', getting the characters from the standard input. maybe later I can upload all the code

– Cosmonauta
Nov 14 '18 at 17:25




1




1





"getting the characters from the standard input". So when you call scanf, do you expect that to read from the file that you're piping into stdin? So does that mean that after the ID token there will be a number in the source and you want scanf to read that number? If that's the case, you should just add an integer token to your grammar rule instead of scanf. If you're trying to read user input independently from reading the source code, you can't read both from stdin.

– sepp2k
Nov 14 '18 at 17:32





"getting the characters from the standard input". So when you call scanf, do you expect that to read from the file that you're piping into stdin? So does that mean that after the ID token there will be a number in the source and you want scanf to read that number? If that's the case, you should just add an integer token to your grammar rule instead of scanf. If you're trying to read user input independently from reading the source code, you can't read both from stdin.

– sepp2k
Nov 14 '18 at 17:32




1




1





@Cosmonauta First of all, you can't read input from stdin as the same type as you're reading the source from stdin? How should that work? Do you want the user to enter the source code, followed by some terminator and then the input? If so, that won't work because your actions are going to be evaluated while the source is being read, not after. Secondly, trying to run the program while parsing it, isn't going to work anyway. As soon as you try to implement ifs or loops that way, you're going run into trouble. You'll want to make your parser generate an AST or bytecode and then ...

– sepp2k
Nov 15 '18 at 17:52





@Cosmonauta First of all, you can't read input from stdin as the same type as you're reading the source from stdin? How should that work? Do you want the user to enter the source code, followed by some terminator and then the input? If so, that won't work because your actions are going to be evaluated while the source is being read, not after. Secondly, trying to run the program while parsing it, isn't going to work anyway. As soon as you try to implement ifs or loops that way, you're going run into trouble. You'll want to make your parser generate an AST or bytecode and then ...

– sepp2k
Nov 15 '18 at 17:52












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302691%2fwhy-scanf-in-bison-grammatical-rule-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302691%2fwhy-scanf-in-bison-grammatical-rule-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()