GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - lydia-ath/miniPython-Compiler: A miniPython Compiler for the Compilers course @/AUEB (2021)

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

54 Commits
54 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
BNF.html
BNF.html
 
 
ParserTest.java
ParserTest.java
 
 
README.md
README.md
 
 
Visitor.java
Visitor.java
 
 
Visitor2.java
Visitor2.java
 
 
example.py
example.py
 
 
minipython.grammar
minipython.grammar
 
 
sablecc
sablecc
 
 
sablecc.bat
sablecc.bat
 
 

Repository files navigation

miniPython Compiler

A simple compiler for a miniPython high-level programming language. This is a group project for the Compilers course in the Computer Science department of AUEB

miniPython instructions

The instructions set of miniPython is a subset of Python's instructions . It supports the following:

  • Assign an integer,float number or string in a variable
  • Assign a list in a variable
  • Functions declaration with simple parameters (with support for default values) and one statement.
  • If, for and while blocks with one statement
  • Various statements/operations (print, type(x),min/max etc)
  • Arithmetic operators (+,- etc) and the -= and /= operators
  • Logical operators/ Comparison statements (<,>,==,! etc)
  • Function calling
  • One-line comments

Lexical and Syntax analysis

MiniPython's instruction set is described in the Backus–Naur form (or Backus normal form - BNF) in the file BNF.html. It's a subset of Python's syntax. In the minipython.grammar file, tokens are described for the lexical analysis, and productions (rules) for the syntax analysis.

Abstract Syntax Tree

In the Abstract Systax Tree section of the .grammar file, syntax rules where redefined and the non-essential tokens where removed. Only identifiers and numbers where preserved, as those are needed for the semantic analysis.

Semantic analysis - Semantic Errors

Two Visitors, implemented in Java and based on the classes Sablecc creates. Both Visitors traverse the AST, in order to spot semantic errors, create a symbol table, and define types for variables and return types for functions. The compiler recognises the following semantic errors:

  • Use of non defined variable.
  • Use of non defined function.
  • Function redefinition with the same number of arguments.
  • Parameters with the same name defined in a function.
  • Wrong number of parameters passed in a function call.
  • Non-numbers used in arithmetic and logical operations, functions' return types included.
  • Functions with no return statement used in operations or print statements.

Rules - Future Work

Some special rules apply on this compiler:

  • Operators apply only on number values.
  • All default parameters must be declared last in a function
  • Type checking in variables used in functions is performed only when the function is called.
  • Inside a function's statement (body), the paremeters can be used in any operation but not as a parameter for calling other functions (other functions can be called with literals or global variables as arguments,tho)

SableCC

We used the SableCC parser generator to create this compiler.

How to run the compiler

>sablecc minipython.grammar
>javac *.java
>java ParserTest example.py

Group

Themelina Kouzoumpasi Lydia Athanasiou
Konstantina Souvatzidaki

About

A miniPython Compiler for the Compilers course @/AUEB (2021)

Topics

bnf-parsercompiler-constructionjava-applicationpython-compilerpython-script

Resources

Readme
Activity

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.