Skip to content

Commit

Permalink
Merge pull request #1 from saiteja-talluri/suraj
Browse files Browse the repository at this point in the history
assignment 5
  • Loading branch information
saiteja-talluri authored Mar 20, 2019
2 parents 14f42bc + 0602fa2 commit 45dcd65
Show file tree
Hide file tree
Showing 19 changed files with 2,199 additions and 0 deletions.
114 changes: 114 additions & 0 deletions A4/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
testdir="tests"


if [ ! -d "$testdir" ];
then
echo "No directory named $testdir"
exit
fi

make

nodiff=true
stopondiff=false
#ignore these for now

for filename in "$testdir"/*.c; do

./mysclp -icode "$filename" 2>"$filename.myerr"
mv "$filename.spim" "$filename.myspim"
mv "$filename.ic" "$filename.myic"

./sclp -icode "$filename" 2>"$filename.err"
DIFF1=$(diff "$filename.spim" "$filename.myspim")
DIFF2=$(diff "$filename.err" "$filename.myerr")

DIFF3=$(diff "$filename.ic" "$filename.myic")




./mysclp -tokens -ast -symtab -eval "$filename" 2> /dev/null
mv "$filename.eval" "$filename.myeval"
mv "$filename.ast" "$filename.myast"
mv "$filename.sym" "$filename.mysym"
mv "$filename.toks" "$filename.mytoks"
./sclp -tokens -ast -symtab -eval "$filename" 2> /dev/null
DIFF4=$(diff "$filename.ast" "$filename.myast")
DIFF5=$(diff "$filename.eval" "$filename.myeval")

DIFF6=$(diff "$filename.toks" "$filename.mytoks")
DIFF7=$(diff "$filename.sym" "$filename.mysym")

if [ "$DIFF5" != "" ]
then
echo "eval comparison failed on $filename. Did not run further tests (lexicographic ordering)."
echo "Showing diff:"
echo "$DIFF5"
exit
fi

if [ "$DIFF1" != "" ]
then
echo "spim code comparison failed on $filename. Continuing further tests."
echo "continuing with further tests"
echo "Showing diff:"
echo "$DIFF1"
# exit
fi

if [ "$DIFF2" != "" ]
then
echo "error message comparison failed on $filename. "
echo "Showing diff:"
echo "$DIFF2"
echo "Continuing with further tests."
echo ""
echo ""
# exit
fi

# if [ "$DIFF3" != "" ]
# then
# echo "icode comparison failed on $filename. Continuing further tests."
# echo "Showing diff:"
# echo "$DIFF3"
# # exit
# fi


if [ "$DIFF4" != "" ]
then
echo "ast comparison failed on $filename. Continuing further tests."
echo "Showing diff:"
echo "$DIFF4"
# exit
fi



if [ "$DIFF6" != "" ]
then
if ! [ -s "$filename.myerr" ] #myerr is empty
then
echo "tokens comparison failed on $filename even though myerr is empty. Did not run further tests (lexicographic ordering)."
exit
fi
echo "tokens comparison failed on $filename, but myerr is non-empty. Continuing tests"
echo ""
# echo "Showing diff:"
# echo "$DIFF6"
# exit
fi

if [ "$DIFF7" != "" ]
then
echo "symtab comparison failed on $filename. Did not run further tests (lexicographic ordering)."
echo "Showing diff:"
echo "$DIFF7"
exit
fi


done
echo "All tests passed!"
24 changes: 24 additions & 0 deletions A5/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#------------------------------------------------------------------------------
CPP=g++
SOURCE=lex.yy.c parser.tab.c ast.cc ast-eval.cc local-environment.cc procedure-eval.cc program-eval.cc ast-compile.cc icode.cc
MYPROGRAM=sclp
MYLIBRARY=$(CURDIR)
LDFLAGS=-Wl,-rpath=$(CURDIR)
CFLAGS=-std=c++0x
FLEX=flex
ALLHEADERS=allheaders.h
BISON=bison
#-----------------------------------------------------------------------------

all: $(MYPROGRAM)

$(MYPROGRAM): $(SOURCE)
$(CPP) -include $(ALLHEADERS) -L$(MYLIBRARY) $(CFLAGS) $(LDFLAGS) $(SOURCE) -o $(MYPROGRAM) -lsclpshared -lfl -ly

lex.yy.c: scanner.l parser.tab.h
$(FLEX) -l --yylineno scanner.l
parser.tab.c parser.tab.h : parser.y
$(BISON) -d parser.y

clean:
rm -f $(MYPROGRAM)
60 changes: 60 additions & 0 deletions A5/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
This directory contains the following files:

- allheaders.h.gch which is a pre-compiled header file.
- libsclpshared.so which is a shared object file.
- sclp which is the reference implementation.
- program-eval.cc, procedure-eval.cc to get the flow of interpreter eval option, use of Symbol Table create
function with local environment.
- reg-alloc.cc for register allocation scheme
- Makefile which contains the commands to build your implementation.
- Besides, the following header files are provided ONLY for telling you the
class structure and the member functions whose implementation is provided
in the library. YOU DO NOT NEED TO INCLUDE ANY OF THESE FILES IN YOUR IMPLEMENTATION.
. storetokens.hh contains the declaration of the function which you can call to
store tokens and print them.
. ast.hh
. procedure.hh
. program.hh
. symbol-table.hh
. local-environment.hh
. reg-alloc.hh
. icode.hh
You need to write
- a scanner,
- a parser,
- actions within the scanner and parser to construct Abstract Syntax Trees,
- ast functions, and
- an interperter
- a compiler which generates spim code
for the input program.

You need to understand the local environment used for evaluation.

A high level description of the classes can be found on the sclp web page
https://www.cse.iitb.ac.in/~uday/web-source/.
You need to create the top level object for program.

You should work in the following steps:

1. Enhance your implementation of A4 by adding new rules in the scanner and parser for print operator (syntax: print var)
2. Add code to construct the ASTs for the new constructs.
3. Add code to generate spim code from ASTs.

For ease of working on small programs, you can use the -d option to produce the dump on the screen
instead of having to open the dump files.

For the AST you need to create objects of the following classes:

- Assignment_Ast,
- Name_Ast,
- Number_Ast,
- Arithmetic_Expr_Ast (and its derived classes)
- Selection_Statement_Ast
- Relational_Expr_Ast
- Logical_Expr_Ast
- COnditional_Op_Ast
- Iterative_Statement_Ast
- Sequence_Statement_Ast
- Print_Ast

You will need to submit ONLY the scanner.l, parser.y, ast.cc, local-environment.cc, ast-eval.cc, ast-compile.cc, and icode.cc files.
Binary file added A5/allheaders.h.gch
Binary file not shown.
Loading

0 comments on commit 45dcd65

Please sign in to comment.