FLEX
FLEX is a grammar language created in 1987. Flex (fast lexical analyzer generator) is a free and open-source software alternative to lex. It is a computer program that generates lexical analyzers (also known as "scanners" or "lexers"). It is frequently used as the lex implementation together with Berkeley Yacc parser generator on BSD-derived operating systems (as both lex and yacc are part of POSIX), or together with GNU bison (a version of yacc) in *BSD ports and in Linux distributions. Read more on Wikipedia...
33Years Old | 25Users | ?Jobs |
- FLEX ranks in the top 10% of languages
- the FLEX website
- the FLEX wikipedia page
- FLEX first appeared in 1987
- See also: bison, yacc, c, ratfor, pl-0
- Have a question about FLEX not answered here? Email me and let me know how I can help.
Example code from Wikipedia:
%{ #include "y.tab.h" %} digit [0-9] letter [a-zA-Z] %% "+" { return PLUS; } "-" { return MINUS; } "*" { return TIMES; } "/" { return SLASH; } "(" { return LPAREN; } ")" { return RPAREN; } ";" { return SEMICOLON; } "," { return COMMA; } "." { return PERIOD; } ":=" { return BECOMES; } "=" { return EQL; } "<>" { return NEQ; } "<" { return LSS; } ">" { return GTR; } "<=" { return LEQ; } ">=" { return GEQ; } "begin" { return BEGINSYM; } "call" { return CALLSYM; } "const" { return CONSTSYM; } "do" { return DOSYM; } "end" { return ENDSYM; } "if" { return IFSYM; } "odd" { return ODDSYM; } "procedure" { return PROCSYM; } "then" { return THENSYM; } "var" { return VARSYM; } "while" { return WHILESYM; } {letter}({letter}|{digit})* { yylval.id = strdup(yytext); return IDENT; } {digit}+ { yylval.num = atoi(yytext); return NUMBER; } [ \t\n\r] /* skip whitespace */ . { printf("Unknown character [%c]\n",yytext[0]); return UNKNOWN; } %% int yywrap(void){return 1;}
Last updated August 9th, 2020