help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple problem


From: Hans Åberg
Subject: Re: simple problem
Date: Sun, 24 Feb 2019 15:32:23 +0100

> On 23 Feb 2019, at 23:19, address@hidden <address@hidden> wrote:
> 
> Hi again, i have the following code:

Here is a slightly different code, for example with input "x1 y2 34 ? exit". 
The lexer will rescan unless there is an action return, which happens for 
"exit". Typically in a lexer, whitespace is eaten, dividing up the tokens.

Otherwise, Flex has a mailing list, cf.
  https://en.wikipedia.org/wiki/Flex_(lexical_analyser_generator)
The manual is good, too.

Also, there is the Usenet newsgroup comp.compilers for general questions about 
parsing, mostly advanced.

--
%{
#include <stdio.h>
#include <stdlib.h>
%}

%option noyywrap

identifier  [[:alpha:]][[:alnum:]]*
integer     [[:digit:]]+

%%

[ \f\r\t\v\n]+  { /* eat whitespace */ }
"exit"          { printf("Exit!\n"); return 0; }
{identifier}    { printf("%s is an identifer\n", yytext); }
{integer}       { printf("%s is an integer\n", yytext); }
.               { printf("/* %s: do nothing*/\n", yytext); }

%%

int main(int argc, char **argv)
{

    printf("Start\n");
    yylex();
    printf("End\n");

    return(0);
}
--





reply via email to

[Prev in Thread] Current Thread [Next in Thread]