Giter Site home page Giter Site logo

core-final's Introduction

Core-Interpreter

How to run

  • cd to the Interpreter folder
  • To compile, run javac Main.java in your terminal
  • To run the actual program, run javac Main.java testfile datafile

Project Description

  • Adding function definitions and function calls on Core-Interpreter for a version of the Core language, a pretend language. Core-Interpreter executes the whole program(including function calls now) and check if there is any runtime error.
  • The way I handle function calls is that adding a new stack to stackspace right before each function call and pop them off right after each function call.

How I execute function calls:

  • Formals:
    • formals.execute() -> parameters[]
  • Funcdecl:
    • funcdecl.execute() -> Check if there are duplicate formal parameters
    • funcdecl.getFunctionBody() -> Get functionbody
  • Funccall:
    • funccal.execute(inputScanner) -> Execute the function here.
    • For more specific details, check comments on funccal.execute(inputScanner).

Main class

  • Skeleton of the program's workflow : )

Core class

  • Core Enums.

Scanner Class

  • Scanner:
    • The class constructor takes as input the name of the input file and finds the first token (the current token)
  • tokenize:
    • This method should return a tokens list.
  • currentToken:
    • This method should return the token the scanner is currently on, without consuming that token.
  • nextToken:
    • This method should advance the scanner to the next token in the stream (the next token becomes the current token).
  • getID:
    • If the current token is ID, then this method should return the string value of the identifier.
  • getCONST:
    • If the current token is CONST, then this method should return the value of the constant.
  • expectedToken:
    • Return if the current token == given Core c. If so, dequeues the tokens.

Utility class

  • expectedhelper:
    • If the current token is an invalid token, print out error message
    • If the current token is not expected token print out error message, expected token and curren token.
  • errorhelper:
    • If the current token is an invalid token, print out error message
    • If the current token is not expected token print out error message, expected tokens and curren token.
  • DoubleDeclarationError:
    • Print out error message to notify user the file has double declared variable.
  • FunctionParameterDoubleDeclarationError:
    • Print out error message to notify user the file has double declared parameters.
  • UseUndeclaredIdError:
    • Print out error message to notify user the file used undeclared variable.
  • UseUndeclaredFunctionError:
    • Print out error message to notify user calls on undeclared function.
  • unmatchingFunctionParameter:
    • Print out error message to notify user the amount of actual parameters does not align with the amount of formal parameters for function.
  • DeclaredTypeError:
    • Print out error message to notify user the file contains wrongly declared variable.
  • InvalidInput:
    • Print out runtime error message to notify user all values in the .data file have already been used.
  • refIndexNull:
    • Print out runtime error message to notify user the class they are assigning constant to is null.

Memory class

  • Construct the memory class using singleton pattern.
  • Separated the memory in 4 different scope:
    • Static/Global--> globalSpace
    • Static functions//Global --> functionDeclaration
    • Local/Stack --> stackSpace
    • Heap/Reference variables --> heapSpace

Corevar class

  • Contains 2 key attributes for each Core variable:
    • Type: int/ref
    • Value: int --> the actual int value | ref --> the pointer

Grammar classes:

core_grammar_func

core-final's People

Contributors

aikozhaoz avatar

Watchers

 avatar

core-final's Issues

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.