From c3c5c8850defae4f97bef2410e93b0906049649d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind?= Date: Sun, 13 Feb 2022 17:43:32 +0100 Subject: [PATCH] Completed scanner --- exercises/02/vslc/src/scanner.l | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 exercises/02/vslc/src/scanner.l 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