%{ /* Version vom 17.5.2004, in der Vorlesung interaktiv erstellt. */ #include #include double akku = 0.0, neue_zahl = 0.0; enum op_t {plus, minus, mal, durch, clear} op = plus; %} %option main %option noyywrap DIGIT [0-9] %% "-"?{DIGIT}+"."?{DIGIT}* { neue_zahl = atof(yytext); switch(op) { case plus: akku = akku + neue_zahl; break; case minus: akku = akku - neue_zahl; break; case mal: akku = akku * neue_zahl; break; case durch: akku = akku / neue_zahl; break; case clear: akku = neue_zahl; break; } printf("%g\n", akku); } "+" { op = plus; } "-" { op = minus; } "*" { op = mal; } "/" { op = durch; } [cC] { op = clear; } [ \t\n]+ /* ueberspringe White-Space */ . { printf("Unbekanntes Zeichen: '%s'\n", yytext);}