Voglio analizzare una stringa che fornisco al parser nella funzione principale di yacc. So che questo potrebbe essere fatto usando yy_scan_string
ma non so come usarlo. Ho cercato sul web e sulle pagine man ma non mi è ancora chiaro. Mi aiuti per favore.come usare yy_scan_string in lex
risposta
ho trovato e l'esempio qui a me stesso. Possa esso può essere utile per voi:
Questo funziona per me. Ho questo codice nella sezione subroutine (vale a dire la terza sezione) del mio file Bison:
struct eq_tree_node *parse_equation(char *str_input)
{
struct eq_tree_node *result;
yy_scan_string(str_input);
yyparse();
/* to avoid leakage */
yylex_destroy();
/* disregard this. it is the function that I defined to get
the result of the parsing. */
result = symtab_get_parse_result();
return result;
}
come si dichiara yy_scan_string nella prima sezione del bisonte? Inoltre devo aggiungere qualcosa in flex? – Ruturaj
str_input dovrebbe essere meglio const char * in questo caso. –
Nel caso qualcuno ha bisogno del campione per una lexer rientrante:
int main(void)
{
yyscan_t scanner;
YY_BUFFER_STATE buf;
yylex_init(&scanner);
buf = yy_scan_string("replace me with the string youd like to scan", scanner);
yylex(scanner);
yy_delete_buffer(buf, scanner);
yylex_destroy(scanner);
return 0;
}
Nel caso in cui qualcun altro sta ricevendo il simbolo non è definito o altri errori di questo tipo quando si prova questo: ricordarsi di includere '% opzione reentrant' nel file lexer. – chacham15
Questo ha funzionato per me ... uso yy_scan_string()
int main(int argc, char **argv)
{
char Command[509];
int ReturnVal;
char input[40] = "This is my input string";
/*Copy string into new buffer and Switch buffers*/
yy_scan_string (input);
/*Analyze the string*/
yylex();
/*Delete the new buffer*/
yy_delete_buffer(YY_CURRENT_BUFFER);
}
- 1. Motivi per usare le alternative lex/yacc?
- 2. Lex e Yacc in PHP
- 3. Lex/Yacc per C#?
- 4. Stati di avvio in Lex/Flex
- 5. Utilizzando Yacc e Lex in Xcode
- 6. Cerchi una grammatica Java in formato lex/yacc
- 7. Problemi con boost :: spirit :: lex & whitespace
- 8. Posizione caratteri nello scanner utilizzando Lex/Flex
- 9. Rimozione di commenti nidificati bz lex
- 10. Strumenti di analisi haskell - yacc: lex :: happy :?
- 11. Come usare Flex su Windows
- 12. Come implementare le direttive include usando boost :: spirit :: lex?
- 13. Problema di parser Spirit e Lex parser
- 14. Stringhe Lex con virgolette singole, doppie o triple
- 15. Come usare come in XPath?
- 16. Come rendere YY_INPUT puntare a una stringa anziché a stdin in Lex & Yacc (Solaris)
- 17. Qual è la differenza tra lex/yacc e fslex/fsyacc?
- 18. Are Parse :: Yapp, Parse :: Lex o Marpa :: R2 ancora usato?
- 19. Qual è la differenza tra Flex/Lex e Yacc/Bison?
- 20. qual è la differenza tra lex e yacc
- 21. Creazione di un progetto C++ in CodeBlocks/Eclipse che utilizza yacc e lex
- 22. Come usare Int64 in C#
- 23. Come usare viewGroup in Android
- 24. Come usare dump in TWIG?
- 25. Come usare ajax in Brython
- 26. Come usare fork() in Perl?
- 27. Come usare javascript in dattiloscritto
- 28. come usare RegisterHotKey() in C#?
- 29. Come usare regex in MySQL?
- 30. Come usare Guids in C#?
Strettamente legato a: http://stackoverflow.com/q/1920604/15168 e http://stackoverflow.com/q/1909166/15168 (anche se non proprio un duplicato di entrambi). –