From 7c8f2a8aa04603d5bc83441353184589640e8c41 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 8 Nov 2022 19:45:50 +0200 Subject: [IPL/HW02] Copied work from HW01, added a help message to lexer.sh, added left margin to pre tag --- .../Homework 02/commonlisp2html.l | 56 ++++++++++++++++ .../Homework 02/example.lisp | 21 ++++++ .../Homework 02/highlighted.html | 74 ++++++++++++++++++++++ .../Homework 02/lexer.sh | 40 ++++++++++++ .../Homework 02/page_bottom.html | 3 + .../Homework 02/page_top.html | 50 +++++++++++++++ 6 files changed, 244 insertions(+) create mode 100644 Year 2/Implementation of Programming Languages/Homework 02/commonlisp2html.l create mode 100644 Year 2/Implementation of Programming Languages/Homework 02/example.lisp create mode 100644 Year 2/Implementation of Programming Languages/Homework 02/highlighted.html create mode 100755 Year 2/Implementation of Programming Languages/Homework 02/lexer.sh create mode 100644 Year 2/Implementation of Programming Languages/Homework 02/page_bottom.html create mode 100644 Year 2/Implementation of Programming Languages/Homework 02/page_top.html (limited to 'Year 2/Implementation of Programming Languages/Homework 02') diff --git a/Year 2/Implementation of Programming Languages/Homework 02/commonlisp2html.l b/Year 2/Implementation of Programming Languages/Homework 02/commonlisp2html.l new file mode 100644 index 0000000..46447b1 --- /dev/null +++ b/Year 2/Implementation of Programming Languages/Homework 02/commonlisp2html.l @@ -0,0 +1,56 @@ +%{ + +%} + +DIGIT [0-9] +BRACKET \(|\) + +STR \"([^\"]|\\\")*([^\\]|\\\\)\" +NUMBERS [^A-z](\+|-)?{DIGIT}+(\.{DIGIT}+(e{DIGIT}+|d{DIGIT}+|e-{DIGIT}+)?|\/{DIGIT}+)? + +COMMENT ;.*$ +PARAMETER_TYPE &[0-9A-z]+ +KEYWORD :[0-9A-z]+ +CONSTANTS T|NIL|pi|t + +SPECIAL_FORM block|function|if|let|quote|return-from|defun|demacro + +/* Functions */ +F_ARITHMETIC "+ "|"- "|"* "|\/|1\+|1-|conjugate|gcd|lcm +F_NUM_COMPARISON =|\/=|<|>|<=|>=|max|min +F_TRIGONOMETRIC sin|cos|tan|cis|asin|acos|atan|sinh|cosh|tanh|asinh|acosh|atanh +F_OTHER_MATH abs|sqrt|phase|signum +F_LOGICAL not +F_LISTS list +F_OTHER format + +/* Macros */ +M_ARITHMETIC incf|decf +M_LOGICAL and|or +M_CONDITIONAL when|unless|cond|case|typecase +M_DECLARE defvar|defparameter|defconstant|defun + +/* Not in spec, but commonly followed */ +GLOBAL_VAR \*([0-9A-z.?-_])+\* +CONST_VAR \+([0-9A-z.?-_])+\+ + +%% + +{BRACKET} { printf("%s", yytext); } +{STR} { printf("%s", yytext); } +{NUMBERS} { printf("%s", yytext); } +{COMMENT} { printf("%s", yytext); } +{PARAMETER_TYPE} { printf("%s", yytext); } +{KEYWORD} { printf("%s", yytext); } +{CONSTANTS} { printf("%s", yytext); } + +{SPECIAL_FORM} { printf("%s", yytext); } +{F_ARITHMETIC}|{F_NUM_COMPARISON}|{F_TRIGONOMETRIC}|{F_TRIGONOMETRIC}|{F_OTHER_MATH}|{F_LOGICAL}|{F_LISTS}|{F_OTHER} { printf("%s", yytext); } +{M_ARITHMETIC}|{M_LOGICAL}|{M_CONDITIONAL}|{M_DECLARE} { printf("%s", yytext); } + +{GLOBAL_VAR}|{CONST_VAR} { printf("%s", yytext); } + + /* 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]+ { printf("%s", yytext); } + +%% diff --git a/Year 2/Implementation of Programming Languages/Homework 02/example.lisp b/Year 2/Implementation of Programming Languages/Homework 02/example.lisp new file mode 100644 index 0000000..cd7a577 --- /dev/null +++ b/Year 2/Implementation of Programming Languages/Homework 02/example.lisp @@ -0,0 +1,21 @@ +(defvar *NAME* "John") +(defvar *AGE* 23) +(defvar *ABOUT* " T NIL cond decf block") + +;;; This is a stupid funciton +(defun adult? () + (>= *AGE* 18)) + +(defun will-I-graduate? () + NIL) + +(defun distance (p1 p2) + (sqrt (* p1 p1) (* p2 p2))) + +(defun bar (a b) + (if (and (> b a) (<= 10 b)) + (format t "Valid") + (format t "Invalid"))) + +(defun foo (&key ((:apple a)) ((:box b) 0) ((:charlie c) 0 c-supplied-p)) + (list a b c c-supplied-p)) diff --git a/Year 2/Implementation of Programming Languages/Homework 02/highlighted.html b/Year 2/Implementation of Programming Languages/Homework 02/highlighted.html new file mode 100644 index 0000000..6dde455 --- /dev/null +++ b/Year 2/Implementation of Programming Languages/Homework 02/highlighted.html @@ -0,0 +1,74 @@ + + + + Highlighted code + + + +

+(defvar *NAME* "John")
+(defvar *AGE* 23)
+(defvar *ABOUT* " T NIL cond decf block")
+
+;;; This is a stupid funciton
+(defun adult? ()
+  (>= *AGE* 18))
+
+(defun will-I-graduate? ()
+  NIL)
+
+(defun distance (p1 p2)
+  (sqrt (* p1 p1) (* p2 p2)))
+
+(defun bar (a b)
+  (if (and (> b a) (<= 10 b))
+    (format t "Valid")
+    (format t "Invalid")))
+
+(defun foo (&key ((:apple a)) ((:box b) 0) ((:charlie c) 0 c-supplied-p))
+  (list a b c c-supplied-p))
+		
+ + diff --git a/Year 2/Implementation of Programming Languages/Homework 02/lexer.sh b/Year 2/Implementation of Programming Languages/Homework 02/lexer.sh new file mode 100755 index 0000000..5a07c15 --- /dev/null +++ b/Year 2/Implementation of Programming Languages/Homework 02/lexer.sh @@ -0,0 +1,40 @@ +#! /bin/bash + +if [ "$1" = "-h" ] || [ "$1" = "-?" ] || [ "$1" = "--help" ]; then + cat << EOF +lexer.sh [-h|-?|--help|-b|-r|-p]