Giter Club home page Giter Club logo

compiler's Introduction

Compiler

A compiler for a simple language (Not finished)

PLPScanner:

Scanner groups input characters into tokens. It saves the text of “interesting” tokens and tags tokens with line and column numbers. It uses “longest possible token” rule. Scanner using a finite automaton, it starts in a distinguished initial state (START). It then moves from state to state based on the next available character of input. When it reaches one of a designated set of final states it recognizes the token associated with that state. Keywords are stored in a HashMap.

PLPParser:

The parser is the heart of a typical compiler. It calls the scanner to obtain the tokens of the input program, assembles the tokens together, checks tokens violate CFG or not and passes them to the later phases of the compiler. Parser will return an instance of Program if the sentence is legal (see Abstract Syntax). If the sentence does not parse it will throw a SyntaxException.

Symbol Table:

This language used static scoping, the compiler uses an insert operation to place a name-to-object binding into the symbol table for each newly encountered declaration. When it encounters the use of a name that should already have been declared, the compiler uses a lookup operation to search for an existing binding. The symbol table used in this project is a Leblanc-Cook symbol table. The symbol table has two parts: the a scope stack that indicates the scopes that compose the current referencing environment and a hash table keyed by name, stores symbol name, its category, scope number and type. As the semantic analyzer scans the program, it pushes and pops the scope stack whenever it enters or leaves a scope.

PLPTypeChecker:

Type Checker is used for type checking. If a type error is discovered, it throws a SemanticException.

Grammar: Semantic Rules and Conditions

Reference:

Programming Language Pragmatics SECOND EDITION. Author: Michael L. Scott
Compilers: Principles, Techniques, and Tools. Author: Alfred V. Aho, Ravi Sethi, Jeffrey Ullman

compiler's People

Contributors

tangni31 avatar

Stargazers

Andrew Johnson avatar

Watchers

James Cloos 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.