PropertyValue
rdf:type
rdfs:label
  • Flex lexical analyser
rdfs:comment
  • This is an example of a Flex scanner for the instructional programming language PL/0. The tokens recognized are: '+', '-', '*', '/', '=', '(', ')', ',', ';', '.', ':=', '<', '<=', '<>', '>', '>='; numbers: 0-9 {0-9}; identifiers: a-zA-Z {a-zA-Z0-9} and keywords: begin, call, const, do, end, if, odd, procedure, then, var, while. %{1. * include "y.tab.h" %} digit [0-9] letter [a-zA-Z] yylval.id = strdup(yytext); return IDENT; } {digit}+ { yylval.num = atoi(yytext); return NUMBER; } [ ] /* skip whitespace */ . { printf("Unknown character [%c] ",yytext[0]); %%
dcterms:subject
foaf:homepage
dbkwik:babyish/property/wikiPageUsesTemplate
Name
  • flex
Genre
  • Lexical analyzer generator
latest release version
  • 2.500000
License
Operating System
Website
Developer
abstract
  • This is an example of a Flex scanner for the instructional programming language PL/0. The tokens recognized are: '+', '-', '*', '/', '=', '(', ')', ',', ';', '.', ':=', '<', '<=', '<>', '>', '>='; numbers: 0-9 {0-9}; identifiers: a-zA-Z {a-zA-Z0-9} and keywords: begin, call, const, do, end, if, odd, procedure, then, var, while. %{1. * 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; } [ ] /* skip whitespace */ . { printf("Unknown character [%c] ",yytext[0]); return UNKNOWN; } %% int yywrap(void){return 1;} The hand-written C code equivalent would likely be at least twice as many lines, and considerably harder to read.