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 --- homework/80095/js2html/js2html.flex | 77 +++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 homework/80095/js2html/js2html.flex (limited to 'homework/80095/js2html/js2html.flex') diff --git a/homework/80095/js2html/js2html.flex b/homework/80095/js2html/js2html.flex new file mode 100644 index 0000000..4dfe28a --- /dev/null +++ b/homework/80095/js2html/js2html.flex @@ -0,0 +1,77 @@ +/* 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