Completed scanner

main
Øyvind Skaaden 2022-02-13 17:43:32 +01:00
parent 4b69ab87c6
commit c3c5c8850d
1 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,34 @@
%{
#include <vslc.h>
%}
%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]; }
%%