Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 9MI0800164 / Homework1_9MI0800164 / lua_lex.l
diff options
context:
space:
mode:
Commit7e8bcc75b6ae00248ad4f9ff9753be251d88a4ff (patch)
Author
 dtagarev <92181714+dtagarev@users.noreply.github.com>
2022-11-03 20:51:40 +0200
Committer
 GitHub <noreply@github.com>
2022-11-03 20:51:40 +0200
Files62c25059ff0d41e13a0eac6765674fed68d604eb /homework/9MI0800164/Homework1_9MI0800164/lua_lex.l
IPL-7e8bcc75b6ae00248ad4f9ff9753be251d88a4ff.tar
IPL-7e8bcc75b6ae00248ad4f9ff9753be251d88a4ff.tar.gz
IPL-7e8bcc75b6ae00248ad4f9ff9753be251d88a4ff.zip
Parentdb0818ba7ebf7bc7602ba6cbf7afe2327b94cc87 (diff)
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.l77
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;
+}