Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

bohatey/php-xml-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Documentation of Project Implementation for IPP 2024/2025

Name and surname: Daniel Bohata

Goal

Project goal is to implement an interpreter in php for XML source code representation of SOL25 language. The programme should be able to execute all instruction in the source code provided to it. Source code can be specified using either stdin or --source=file flag. User input can be again specified using either stdin or --input=file. Atleast one of the two arguments has to be specified. For help use --help. Project assignment available from: https://moodle.vut.cz/mod/folder/view.php?id=508604.

Draft

In theory, we should be able to represent the entire source code using instances. Since SOL25 is based on Smalltalk, we can represent the entire code as a tree. Each node would be an instance(object) of a class. Each class would define its own behaviour. By behaviour I mean how the class reacts to messages. Each class would have its own set of methods and instance variables. There would be no root, only an array of instances of classes. This should allow for easy implementation with inheritance. Each class would inherit from class Object which would define the basic behaviour of all classes. From Object Main and all the other basic classes would inherit. Lastly, user defined classes would inherit from whatever the user wants.

Implementation

What I actually implemented is a bit different. I did not have enough time to implement the draft structure. What I did instead is a bit more simple as can be seen in the UML class diagram below. The main class is Interpreter which contains the main loop and all the logic. It uses context sharing - sharing DOMElements between functions. First I check that there is a Main class and that it has a method run. After that I load all the classes and methods into their respective arrays. After that I recursively execute the code in run method of class Main. I decide which method to call based on the name of the node. Every variable is stored as an instance of it's respective class. Ideally, all communication would be done using only objects, however sometimes i pass values like string or null. Some theory was kept from the draft as I have implemented a tree structure from the Object class. All classes get instantiated in ClassInstance and the objects are stored in its object variable. Sadly, there is no support for custom classes or other methods other that run. Variables are stored in a global array which makes that impossible. Instance variables are stored in instances in attribute array attributes.

UML class diagram

As you can see, the class diagram is a bit different from the draft. There are built in classes like Integer, String, Nil and others that inherit from Object. They get created using ClassInstance::create. False, True and Nil are singletons. They only get created once and then reused in the whole program. I store them in an array and use method getSingletons to access them. That in itself is also encapsulation. There is one extra class OwnException which is used to throw custom exceptions for semantic errors and others.

File structure:

  • Interpreter.php Contains most of the logic of the interpreter.
  • Src/*.php Contains the classes that are used in the interpreter.

Testing

Testing has been done using automatic tests provided by a fellow student Jakub Lůčný. I pass 48 out of 87 tests. I am not the author of these tests. Tests available from: https://github.com/Kubikuli/IPP_proj2-tests.

Code formatting

Code succesfully passes both phpstan level 9 and phpcs with --standard=PSR12 flag.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages