Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Implementation of Programming Languages / Homework 02 / commonlisp2html.l
diff options
context:
space:
mode:
Commit387ec42070ea17cd57658d3386b0529ca9be1782 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-11-16 21:56:36 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-11-16 21:56:36 +0200
Filesb908a2c0f087e0cf41ca4ab9e982fae2b96e055a /Year 2/Implementation of Programming Languages/Homework 02/commonlisp2html.l
uni-projects-387ec42070ea17cd57658d3386b0529ca9be1782.tar
uni-projects-387ec42070ea17cd57658d3386b0529ca9be1782.tar.gz
uni-projects-387ec42070ea17cd57658d3386b0529ca9be1782.zip
Parent9b9cac4c0037b3c397842143f85c08e13d2bc91e (diff)
[IPL/HW02] Added tokens for all types of parsed data
1 files changed, 13 insertions, 15 deletions
-rw-r--r--Year 2/Implementation of Programming Languages/Homework 02/commonlisp2html.l28
diff --git a/Year 2/Implementation of Programming Languages/Homework 02/commonlisp2html.l b/Year 2/Implementation of Programming Languages/Homework 02/commonlisp2html.l
index 01b69d5..cbb226f 100644
--- a/Year 2/Implementation of Programming Languages/Homework 02/commonlisp2html.l
+++ b/Year 2/Implementation of Programming Languages/Homework 02/commonlisp2html.l
@@ -37,27 +37,25 @@ CONST_VAR \+([0-9A-z.?-_])+\+
%%
-{LEFTBRACKET} { return LBRACKET; }
-{RIGHTBRACKET} { return RBRACKET; }
-{STR} { printf("<span class=\"string\">%s</span>", yytext); }
-{NUMBERS} { printf("<span class=\"number\">%s</span>", yytext); }
-{COMMENT} { printf("<span class=\"comment\">%s</span>", yytext); }
-{PARAMETER_TYPE} { printf("<span class=\"parameter-type\">%s</span>", yytext); }
-{KEYWORD} { printf("<span class=\"keyword\">%s</span>", yytext); }
-{CONSTANTS} { printf("<span class=\"constant\">%s</span>", yytext); }
+{LEFTBRACKET} { return LBRACKET; }
+{RIGHTBRACKET} { return RBRACKET; }
+{STR} { yylval = strdup(yytext); return STR; }
+{NUMBERS} { yylval = strdup(yytext); return NUM; }
+{COMMENT} { yylval = strdup(yytext); return COMMENT;}
+{PARAMETER_TYPE} { yylval = strdup(yytext); return PARAMETER_TYPE; }
+{KEYWORD} { yylval = strdup(yytext); return KEYWORD; }
+{CONSTANTS} { yylval = strdup(yytext); return CONSTANT; }
-{SPECIAL_FORM} { printf("<span class=\"special-operator\">%s</span>", yytext); }
-{F_ARITHMETIC}|{F_NUM_COMPARISON}|{F_TRIGONOMETRIC}|{F_TRIGONOMETRIC}|{F_OTHER_MATH}|{F_LOGICAL}|{F_LISTS}|{F_OTHER} { printf("<span class=\"function\">%s</span>", yytext); }
-{M_ARITHMETIC}|{M_LOGICAL}|{M_CONDITIONAL}|{M_DECLARE} { printf("<span class=\"macro\">%s</span>", yytext); }
+{SPECIAL_FORM} { yylval = strdup(yytext); return SPECIAL_FORM; }
+{F_ARITHMETIC}|{F_NUM_COMPARISON}|{F_TRIGONOMETRIC}|{F_TRIGONOMETRIC}|{F_OTHER_MATH}|{F_LOGICAL}|{F_LISTS}|{F_OTHER} { yylval = strdup(yytext); return FUNCTION; }
+{M_ARITHMETIC}|{M_LOGICAL}|{M_CONDITIONAL}|{M_DECLARE} { yylval = strdup(yytext); return MACRO; }
-{GLOBAL_VAR}|{CONST_VAR} { printf("<span class=\"variable\">%s</span>", yytext); }
+{GLOBAL_VAR}|{CONST_VAR} { yylval = strdup(yytext); return VARIABLE; }
- /* " " { return SPACE; } */
-\t { return TAB; }
\n { return NEWLINE; }
/* flex catches the longest possibility, so if some variable name contains a known word (function, macro, etc.), this will prevent it from highlighting */
-[A-z]+ { yylval = strdup(yytext); return OTHER; }
+[A-z]+|" "|\t { yylval = strdup(yytext); return OTHER; }
%%