Giter VIP home page Giter VIP logo

scanner's Introduction

Requirements:

Based on the specification of the mini-language chosen implement a scanner that will take as input a text file containing the source program and will produce as output the following:

• PIF -> Program Internal Form

• ST -> Symbol Table

In addition, the program should be able to determine the lexical errors, specifying the location, and if possible, the type of the error.

Some additional restrictions:

  1. Identifiers: b. arbitrary length, no more than 250 characters
  2. Symbol Table: b. separate tables for indentifiers, respectively constants
  3. Symbol Table Organization: c. hashing table

The scanner is implemented in the C++ language.

The codification table is kept in memory as a map<string, int>.

The PIF is a vector<pair<int, int>>

There are two separate symbol tables, one for identifiers and one for constants, both implemented as hash tables on maps (map<int, string>). The collision strategy is open adressing, and rehashing when the tables are full.

First the file containing the program is read line by line. Then, the tokenizing is done using a regex. As the tokens of each line are processed, the symbol tables for identifiers and constants are built. The functions isConstant and isIdentifier are used to differentiate between the two types.

All the tokens constants are also kept in a temporary variable. After the symbol table construction is finished, the pif is built from the list of tokens.

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.