diff --git a/exercises/02/vslc/src/scanner.l b/exercises/02/vslc/src/scanner.l new file mode 100644 index 0000000..b5cf462 --- /dev/null +++ b/exercises/02/vslc/src/scanner.l @@ -0,0 +1,34 @@ +%{ +#include +%} +%option noyywrap +%option array +%option yylineno + +WHITESPACE [\ \t\v\r\n] +COMMENT \/\/[^\n]+ +NUMBERS [0-9]+ +STRING \"[\ !#-~]*\" +IDENTIFIERS [A-Za-z_][A-Za-z0-9_]* +%% +{WHITESPACE}+ { /* Eliminate whitespace */ } +{COMMENT} { /* Eliminate comments */ } + +"func" { /*printf("FUNC\n");*/ return FUNC; } +"print" { /*printf("PRINT\n");*/ return PRINT; } +"return" { /*printf("RETURN\n");*/ return RETURN; } +"begin" { /*printf("OPENBLOCK\n");*/ return OPENBLOCK; } +"end" { /*printf("CLOSEBLOCK\n");*/ return CLOSEBLOCK; } +"continue" { /*printf("CONTINUE\n");*/ return CONTINUE; } +"if" { /*printf("IF\n");*/ return IF; } +"then" { /*printf("THEN\n");*/ return THEN; } +"else" { /*printf("ELSE\n");*/ return ELSE; } +"while" { /*printf("WHILE\n");*/ return WHILE; } +"do" { /*printf("DO\n");*/ return DO; } +"var" { /*printf("VAR\n");*/ return VAR; } + +{NUMBERS} { /*printf("NUMBER\n");*/ return NUMBER; } +{STRING} { /*printf("STRING\n");*/ return STRING; } +{IDENTIFIERS} { /*printf("IDENTIFIER\n");*/ return IDENTIFIER; } +. { /*printf("'%c'\n", yytext[0]);*/ return yytext[0]; } +%% \ No newline at end of file