[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to get the actual string for a symbol?
From: |
Peng Yu |
Subject: |
How to get the actual string for a symbol? |
Date: |
Wed, 30 Dec 2009 23:11:47 -0600 |
I want to get words from a file and print them out. But I'm not sure
how to make yylval a pointer to the string yytext. Could somebody let
me know how to modify the following code so that the string can be
retrieved the symbol WORD.
>yylval_string.l
%option nodefault
%{
# include "yylval_string.tab.h"
%}
%%
[A-Za-z]+ { /*I'm not sure how to make yylval a point to yytext */
return WORD; }
[[:space:]] { /*SPACE*/ }
. {
return UNEXPECTED_CHARACTER;
/*fprintf(stderr, "unexpeced_character: '%s'\n", yytext);*/
}
%%
>yylval_string.y
%{
# include <stdio.h>
%}
%token WORD UNEXPECTED_CHARACTER
%%
words:
WORD { printf("WORD = %s\n", $1); }
| words WORD { printf("WORD = %d\n", $2); }
;
%%
main()
{
yyparse();
}
yyerror(char *s)
{
fprintf(stderr, "error: %s\n", s);
}
- How to get the actual string for a symbol?,
Peng Yu <=