Skip to content

rafaelmoschopoulos/PseudoInterp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


PseudoInterp

An interpreter of IB pseudocode built from scratch in C++!
View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact
  7. Acknowledgments

About The Project

This project is an interpreter of the IB pseudocode language built from scratch in C++. IB pseudocode is used in the IB CS course to write simple algorithms and programs. It contains all basic procedural structures (while, for, if/else), functions, primitive types (bool, float, int) arrays and strings, and ADTs (stack, queue, linked list/collections). It is a pseudo-OOP language, as ADTs are treated as objects but the user cannot define their own objects.

The interpreter utilizes a recursive descent parser to build the abstract syntax tree, which implements runtime polymorphism to represent all structures/expressions as nodes. Types are runtime-resolved and objects utilize sum-type std::variant to store the appropriate type. Some built in functions such as constructors for ADTs and input/output are hardcoded.

(back to top)

Built With

  • C++

(back to top)

Getting Started

This is a guide of how to build the interpreter on your machine and run an example program.

Prerequisites

  • g++ 11.3.0
  • GNU make 4.3
  • git 2.34.1

On Ubuntu:

$ sudo apt install git build-essential

Compilation

  1. Clone the repo on your machine.
$ git clone https://github.com/rafaelmoschopoulos/PseudoInterp
$ cd PseudoInterp/
  1. Build
$ make clean
$ make

The binary can be found in the /bin folder.

Running a program

The following flags are available:

  • -?: Prints informational message regarding usage.
  • -v: Prints program version.
  • -i: Sets input file.

To execute the example program, run $ ./bin/pseudointerp -i ./examples/ex1. This program reverses the contents of a stack.

More information on syntax can be found by referring to the official IB pseudocode guide, and looking at more examples in /examples.

(back to top)

Usage

  • Test pseudocode programs, or practice for IB tests/exams.
  • Quickly implement various algorithms, as all basic ADTs are available.

Accepted syntax

  • Literals
    pi = 3.14
    age = 10
    sad = false
    str = "hey\teveryone\tim\ta\t\string\n"
    chr = '\x24'
    
  • Control flow
    a = 3, b = 5
    if a > b or a == 0 then
      output(a+b)
    else if a == b then
      output(a)
    else
      output("Foo")
    
    loop for i from 0 to 10
      output(i*i)
    n = 0
    loop while n < 10
      output(n++)
    
  • Functions
    method fibo(n)
      if n == 0 or n == 1 then
        return n
      else
        return fibo(n-1) + fibo(n-2)
    
  • I/O
    age = 0
    input(age)
    output("i am " + age + "years old")
    
  • Arrays and strings
    A = Array(10)
    A = [1, 34, 23, 56, 3]
    str = "hello world"
    output(str[3] + " " + A[2])
    twoD = [[1, 2], [3, 4]]
    output(twoD[0, 1] + twoD[1][0])
    
  • ADTs
    S = Stack(), Q = Queue(), C = Collection()
    S.push(2), Q.enqueue(3)
    
    if not S.isEmpty() and not Q.isEmpty() then
      output(S.pop() + Q.dequeue())
    
    loop for i from 0 to 4
      C.addItem(input())
    loop while C.hasNext()
      output(C.getNext())
    C.resetNext()
    

(back to top)

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

Your Name - @raf_mos - raf.mos@princeton.edu

Project Link: https://github.com/rafaelmoschopoulos/PseudoInterp

(back to top)

Acknowledgments

(back to top)

About

Interpreter built from scratch in C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published