Skip to content

shallom/Pascal-Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Name: David Parker
EID: dp24559



Codegen Optimizations:
***************************************************************************************
Adds the offset for the array reference without doing another load
1) Array offset optimization:
	
	If there is an AREF that has a constant number for an offset. We do not need to load that constant number
	int a register then add it to our address for our AREF. By simply combining it into the register that contains
	the address we can save a few operations.

	Example:

	Novak's output:
	movl	$96,%eax         	#  96 -> %eax
	cltq	                  	#  sign-extend
	movsd	%xmm0,-1296(%rbp,%rax)	#  %xmm0 -> ac[%rax]

	Becomes:
	movsd	%xmm0,-1200(%rbp)     	#  %xmm0 -> ac

***************************************************************************************




Parser ALL Optimizations:
***************************************************************************************
1) 	AREF combination optimization:

	If an aref exists that contains a constant is sitting next to another aref that
	contains only a constant then we can "combine" the aref's into a single aref number
	by reusing the last aref token and modifying its offset.

	Example:
	(aref (aref(^ptr)
		       8)
		  16)

    Becomes,
    (aref (^ptr) 24)

2)	Binop return optimization:
	
	If binop tokens are just constant numbers, don't create a tree. Just return a single number token that is the result of that binop operation. This works for a 
	chain of binops as long as all rhs and lhs are constant numbers.

	Example:
		  *
		 /
		+--2
	   /
	  5--10
	  
	Becomes,
	30 

3) 	Binop add coalesce optimization:

	If a binop tree has variables and the first optimization cannot run, we can still combine like add operations into a single add.

	Example:
      +
	 /  	
	4--+
	   /
	 -12--*
	 	 /
	 	i--12
	 	
	Becomes, 
	    +
	   /
	 -8--*
 	    /
 	   i--12
***************************************************************************************
	

	

Project 2
***************************************************************************************
For project 2 we were given a partially completed lex specification,
some things that weren't working were floating points with e, overflow
for both ints and floating points, and the rest of the reserved words and
operators. Comments were also missing

Fixing the floating points to work with a given exponent e, was as simple as
changing the capital E to a lower case e for the regex to match properly.

I just added a match for each of the reserved words, operators and delimeters
to finish the incomplete list given by Novak.

Comments were a little bit trickier, the {} type comment regex was given by
Novak in class but getting the (* *) type to work with all the corner cases
took some regex magic (lots of research on regex structure), but I finally got
it to match every case. Basically the regex looks for (* then multiple instances 
of any string that is not *) until it finds the *) and terminates.

Strings was as easy as just chaning the {} comment regex to ''. One subtlety was
that I had to check if the inner string was not a ' OR it was a double single quote
'' then continue matching until it found the last '. I wrote a small function to parse
the given string beacuse 'hello world' would match yytext to 'hello world' instead of
hello world. So the function gets rid of the leading and trailing single quotes but also
changes double single qoutes into a single single qoute. For instance 'don''t' becomes
don't because the double single quote become just a single quote. The function also truncated
the string to just 15 characters, but the regex consumes infinitley many

Integers was as easy as just matching any number of digits, then I had a function to check
for overflow but also truncate down the digits.
**********************************************************************************************

About

Compilers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published