From d942fd5baffdafb2645287a5bf362fb7c120190f Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Wed, 10 Oct 2018 21:46:36 +0300 Subject: Added a sample homework --- demo/flex/js2html.flex | 77 -------------------------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 demo/flex/js2html.flex (limited to 'demo/flex/js2html.flex') diff --git a/demo/flex/js2html.flex b/demo/flex/js2html.flex deleted file mode 100644 index 4dfe28a..0000000 --- a/demo/flex/js2html.flex +++ /dev/null @@ -1,77 +0,0 @@ -/* scanner for a toy JavaScript-like language */ - -%{ -#define YY_NO_UNISTD_H -%} - -DIGIT [0-9] -ID [a-z_$][a-z0-9_$]* -STRQ '([^\']|(\\\'))*' -STRDQ "([^\"]|(\\\"))*" - -%% - -{DIGIT}+ { - printf("%s", yytext); - } - -{DIGIT}+"."{DIGIT}* { - printf("%s", yytext); - } - -if|else|for|while|do|break|switch|case|function|return|new|delete|try|throw|catch|class|public|private { - printf("%s", yytext); -} - -{ID} printf("%s", yytext); -{STRQ}|{STRDQ} printf("%s", yytext); - -"."|"+"|"-"|"*"|"/"|"="|"!"|">"|"<"|"!=="|"==="|">="|"<="|"++"|"--"|"=>" printf("%s", yytext); - -[;(){}:? \t\n]+ printf("%s", yytext); /* echo the rest */ - -. printf( "Unrecognized character: %s\n", yytext ); - -%% - -int yywrap() -{ - return 1; -} - - -int main(int argc, const char* argv[]) -{ - ++argv, --argc; /* skip over program name */ - if ( argc > 0 ) - yyin = fopen( argv[0], "r" ); - else - yyin = stdin; - - puts( - "" - "" - "" - " hello.js" - " " - "" - "" - "
"
-        );
-    yylex();
-    puts("
"); - return 0; -} -- cgit v1.3.1-23-gd82d