[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Hi everyone,
From: |
address@hidden |
Subject: |
Re: Hi everyone, |
Date: |
Sun, 17 Feb 2019 18:43:38 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 |
Now a very simple question: i have this lexer.l file:
%{
#include <stdio.h>
#include <stdlib.h>
enum yytokentype {
NUMBER = 285,
VAL = 292,
ADD = 286,
SUB = 287,
MUL = 288,
DIV = 289,
ABS = 290,
EOL = 291,
STRING = 292
};
int yylval;
char yyltext[256];
%}
%%
"+" { return ADD; }
"-" { return SUB; }
"*" { return MUL; }
"/" { return DIV; }
"|" { return ABS; }
[a-zA-Z] { strcpy(yytext, yyltext); return STRING; }
[0-9]+ { yylval = atoi(yytext); return NUMBER; }
\n { return EOL; }
[ \t] { /* ignore whitespaces */ }
. { printf("Unknow char :%c", *yytext); }
%%
int main(int argc, char **argv){
int tok;
while(tok = yylex())
{
printf("%d", tok);
if(tok == STRING) {
printf(" = %s\n", &yyltext);
}else if(tok == NUMBER) {
printf(" = %d\n", yylval);
}else printf("\n");
}
return(0);
}
what am i doing wrong so that i'm not able to parse strings with [a-zA-Z] ?
On 17.02.19 15:53, Akim Demaille wrote:
Le 17 févr. 2019 à 14:17, address@hidden <address@hidden> a écrit :
Is there a way i can put my c source code not inside one the the lexer.l or
parser.y files ? so i can keep tem separate from the rules ?
Two opposite answers:
I said:
Le 17 févr. 2019 à 15:49, Akim Demaille <address@hidden> a écrit :
No, sorry. There are several approaches to parsing, one which is fully declarative and
your rules are "pure". That's not the case of Flex/Bison: you must define
rules with actions. Yet you should keep your action simple and move complex processing
into functions.
Uxio said:
Le 17 févr. 2019 à 15:46, Uxio Prego <address@hidden> a écrit :
Yes of course, by inclusion of headers, in a very much
common way. You can then manipulate shorter *.y and
*.l docs, but this is not going to fix any Bison usage issue
you are having.
And of course Uxio is right. You can put the function you depend upon in other
compilation units (i.e., other *.c files). What I meant is: Flex and Bison are
useless if you don't *call* code from your actions.
- Re: Hi everyone,, (continued)
- Re: Hi everyone,, address@hidden, 2019/02/17
- Re: Hi everyone,, address@hidden, 2019/02/17
- Re: Hi everyone,, Uxio Prego, 2019/02/17
- Re: Hi everyone,, address@hidden, 2019/02/17
- Re: Hi everyone,, address@hidden, 2019/02/17
- Re: Hi everyone,, address@hidden, 2019/02/17
- Re: Hi everyone,, Uxio Prego, 2019/02/17
- Re: Hi everyone,, Akim Demaille, 2019/02/17
- Re: Hi everyone,, Akim Demaille, 2019/02/17
- Re: Hi everyone,,
address@hidden <=
- Re: Hi everyone,, Uxio Prego, 2019/02/17
- Re: Hi everyone,, address@hidden, 2019/02/17
- RE: Hi everyone,, Jannick, 2019/02/17