Giter Site home page Giter Site logo

cs335-ass3's Introduction

CS335A: Compiler Design (Assignment 3: PARSER)

  • Source Language: Python3

  • Target Language: x86 Assembly

  • Implementation Language: Python

  • Authors: Deepak Kumar(13229), Kamesh Kanwariyaa (13336), Palash Chauhan (13455) and Rahul Kumar Wadbude (13533)

  • Tool Used : PLY (Python Lex and Yacc)

Running Instruction


  1. Run the following command to run test1.py
make test=test/test1.py all

Directory Structure


  • bin:
    • lexer.py [Python source file to specify language lexemes]
    • parser.py [Python source file to specify grammar]
    • yacc.py [Python source file from PLY for parsing ]
    • generate.py [Python file to generate rightmost derivation in html ]
  • src:
    • lexer.py [Python source file to specify language lexemes]
    • parser.py [Python source file to specify grammar]
    • yacc.py [Python source file from PLY for parsing ]
    • generate.py [Python file to generate rightmost derivation in html ]
  • test:
    • 'test1'.py [Test files]
    • 'test2'.py [Test files]
    • 'test3'.py [Test files]
    • 'test4'.py [Test files]
    • 'test5'.py [Test files]
  • makefile
  • README.pdf

A Tutorial on the language features offered by the compiler


The compiler supports the basic structures of the Programming languages such as assignment , operators , loops ans function calls.

*Note : Indentation is through tabs or spaces

Assignment


a=10
a=10.2
a=b
a=[1,2,3,4,a,b]

Print Statement


print a
print 4
print 4.6
print 'hello world'
print "hello world"
print '''hello world'''

Operators with Parenthesis


c = a + b - c * c / d % k
c=(a+b)**(c+d)
a+=b
a-=c
a*=c
a/=c
a%=c

Relational & Logical Operators


a = 4 > 3
a= 4 > 3 and 5==5
a= a > b or c <= 9 and not True 
if True and True:
  do something

If Statement


a=9
if a==9:
  print 'yes'
a=10
if a == 10:
  print 1
else :
  print 2

While Statement


while a > 0:
  print 'hi'

Nested Looping



while a > 0:
  while b >= 0:
    while c>=0:
      for i in [1,2,3]:
        print 'hi'

Function Without Parameters


def myfun():
  a=10
myfun()

Function With Parameters



def myfun(c, d, e, f):
  print c,d,e,f
a = myfun(1000, 100, 10, 1)
print a

Function call from another function


def f():
	return 1
def f1():
  f()	

Recursion


f():
  print 'hi'
  if i>1:
    f()

Break & Continue Statement


for i in [1,2,3]
  a=1
  if i==3:
    break
  else:
    continue

cs335-ass3's People

Contributors

kkanwariya avatar warahul avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.