Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Implementation of Programming Languages / Homework 02 / lexer.sh
blob: 5a07c15df72170fe27994948815d317291d11bfa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /bin/bash

if [ "$1" = "-h" ] || [ "$1" = "-?" ] || [ "$1" = "--help" ]; then
	cat << EOF
lexer.sh [-h|-?|--help|-b|-r|-p] <OPTION>

-h
-?
--help        Brings up this help message

-b <FILES>    Puts <FILES> through flex and compiles with gcc
              Outputed executable is "a.out"
-r <FILES>    Runs <FILES> through compiled lexer and prints results
              Expects "a.out" as the compiled lexer (in the current folder)
-p <FILES>    Runs <FILES> through compiled lexer and creates webpage with highlighting
              Expects "a.out" as the compiled lexer (in the current folder)
              Webpage is always named "highlighted.html". It is created by putting lexer
              output between "page_top.html" and "page_bottom.html"
EOF
	exit
fi

if [ "$1" = "-b" ]; then
	shift
	flex $@
	gcc lex.yy.c -lfl
fi

if [ "$1" = "-r" ]; then
	shift
	./a.out < $@
fi

if [ "$1" = "-p" ]; then
	filename="highlighted.html"
	cat ./page_top.html > $filename
	shift
	./a.out < $@ >> $filename
	cat ./page_bottom.html >> $filename
fi