diff options
solution to first homework (#132)
* Delete lex.yy.c
* adding homework1
* Delete output
* correction to the location of the folders
Co-authored-by: dtrendafilov <trendafilov.dn@gmail.com>
1 files changed, 77 insertions, 0 deletions
| -rw-r--r-- | homework/9MI0800164/Homework1_9MI0800164/lua_lex.l | 77 |
diff --git a/homework/9MI0800164/Homework1_9MI0800164/lua_lex.l b/homework/9MI0800164/Homework1_9MI0800164/lua_lex.l new file mode 100644 index 0000000..e51f53c --- /dev/null +++ b/homework/9MI0800164/Homework1_9MI0800164/lua_lex.l @@ -0,0 +1,77 @@ +%{ + +%} + +DIGIT [0-9] +ID [a-zA-Z_0-9]* +KEYWORD and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while +OPERATOR "+"|"-"|"*"|"/"|"%"|"^"|"#"|"=="|"~="|"<="|">="|"<"|">"|"="|"("|")"|"{"|"}"|"["|"]"|"::"|";"|":"|","|"."|".."|"..."|"<<"|">>"|"&"|"|"|"//"|"~"|"'"|"--"|"?"|"\""|"\\n" + + +%% + +{DIGIT}+ { + printf("<span class=\"number\">%s</span>", yytext); + } +{KEYWORD} printf("<span class=\"keyword\">%s</span>", yytext); + +(".") printf("<span class=\"string\">%s</span>", yytext); + +{ID} printf("<span class=\"identifier\">%s</span>", yytext); + +(--.) printf("<span class=\"comment\">%s</span>", yytext); + +{OPERATOR} printf("<span class=\"operator\">%s</span>", yytext); + +[ \t\n]+ printf("%s", yytext); + +. printf( "Unrecognized character: %s\n", yytext ); + +%% +int yywrap() +{ + return 1; +} +int main(int argc, const char* argv[]) +{ + if ( argc > 0 ) + yyin = fopen( "markov_chain.lua", "r" ); + else + yyin = stdin; + puts( + "<!doctype>" + "<html>" + "<head>" + " <title>markov_chain.lua</title>" + " <style>" + " .keyword {" + " color: red;" + " }" + " .identifier {" + " color: purple;" + " }" + " .string {" + " color: orange;" + " }" + + " .number {" + " color: blue;" + " }" + " .string {" + " color: green;" + " }" + " .operator {" + " font-style: bold;" + " }" + " .comment {" + " color: gray;" + " }" + " </style>" + "</head>" + "<body>" + " <pre class=\"code\">" + ); + yylex(); + puts("</pre></body></html>"); + return 0; +} |
