Created
May 11, 2017 00:09
-
-
Save binary-signal/082513bfc9022be4e0e0870f2b4b74a7 to your computer and use it in GitHub Desktop.
compile flex parser and run with test input file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
clear | |
filex="mylexer.l" # input file for flex | |
folex="lex.yy.c" # output file of flex | |
fogcc="mylexer" # outpuf file of gcc | |
fe1="myprog.fc" # example file to run | |
now="$(date +"%r")" # Get the system time now | |
echo "FC compiler $now" | |
# check if flex input file exists | |
if [ ! -f "$filex" ]; then | |
echo "Lexer file not found!" | |
exit 1 | |
fi | |
echo | |
echo | |
echo "program: $fe1 " | |
echo "---------------------------------" | |
cat $fe1 | |
echo "---------------------------------" | |
echo | |
echo | |
echo "-> flexing $filex " | |
flex "$filex" | |
# check if compilation produced output file | |
if [ ! -f "$folex" ]; then | |
echo "fail" | |
echo "Lexer output file not found!" | |
exit 2 | |
fi | |
echo "-> compiling lexer" | |
# detect os | |
if [ "$(uname)" == "Darwin" ]; then | |
# Do something under Mac OS X platform | |
gcc -o "$fogcc" "$folex" -ll | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
# Do something under GNU/Linux platform | |
gcc -o "$fogcc" "$folex" -lfl | |
fi | |
gcc -o "$fogcc" "$folex" -ll | |
# check if compilation produced output file | |
if [ ! -f "$fogcc" ]; then | |
echo "fail" | |
echo "gcc output file not found!" | |
exit 3 | |
fi | |
# clean up files | |
if [ -f $folex ] ; then | |
echo "clean up files: $folex" | |
rm $folex | |
fi | |
echo "running mylexer < $fe1" | |
echo "---------------------------------" | |
echo | |
./mylexer < "$fe1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment