Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Bjorn.Hagen/inf-222-v-24-obligatory-2-skeleton
  • M.Fjeldstad/inf-222-v-24-obligatory-2-skeleton
  • Rolf.Glomsrud/INF222-Obligatory2-Skeleton
  • Mikhail.Barash/inf-222-v-24-obligatory-2-skeleton
  • Mahmod.Mohamed/inf-222-v-24-obligatory-2-skeleton
  • Kevinas.Pliuskus/inf-222-v-24-obligatory-2-skeleton
  • Markus.Halsvik/inf-222-v-24-obligatory-2-skeleton
  • torje.sylta/inf-222-v-24-obligatory-2-skeleton
  • Jens.Brown.Eriksen/inf-222-v-24-obligatory-2-skeleton
  • samuel.sjoen/inf-222-v-24-obligatory-2-skeleton
  • Magnus.Aune/inf-222-v-24-obligatory-2-skeleton
  • V.Larsen/inf-222-v-24-obligatory-2-skeleton
  • Lauritz.Angeltveit/inf-222-v-24-obligatory-2-skeleton
13 results
Show changes
Commits on Source (7)
# INF222_O2 # INF222_O2
This is a skeleton for INF222 Obligatory 2. This is a skeleton for INF222 Obligatory 2 V24.
**If you do not want to spend time setting up a local environment, please use Replit** **If you do not want to spend time setting up a local environment, please use Replit**
You can find the Replit [here](https://replit.com/@mikbar/INF222-V24-Oblig2-skeleton)
## Install and run ## Install and run
1. Clone this repository 1. Clone this repository
...@@ -12,5 +14,12 @@ This is a skeleton for INF222 Obligatory 2. ...@@ -12,5 +14,12 @@ This is a skeleton for INF222 Obligatory 2.
3. Open project folder in VScode 3. Open project folder in VScode
4. Run command `npm i` 4. Run command `npm i`
5. To run the project, execute command `npm run start` 5. To run the project, execute command `npm run start`
6. You should now probably see a lot of errors in your console relating to typescript missing code :)
If you have any problems with this, please contact a group leader during group session or on Discord. If you have any problems with this, please contact a group leader during group session or on Discord.
## Tips
For developing this, you should probably temporarily comment out the entirety of the "EvaluateVistor" and "TypeCheckVisitor", just so it is possible to work on the parser and you don't get too many errors :)
Don't forget to use the group sessions if you have any issues.
{ {
"name": "INF222_O2", "name": "INF222-Obligatory2-Skeleton",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
......
...@@ -13,12 +13,12 @@ function lookup<T>(x: string, env: Environment<T>): T | undefined { ...@@ -13,12 +13,12 @@ function lookup<T>(x: string, env: Environment<T>): T | undefined {
} }
function isDefined<T>(x: string, env: Environment<T>): boolean { function isDefined<T>(x: string, env: Environment<T>): boolean {
// 1. Return a Boolean value that represents whether an environment specified in parameter `x` has a variable specified in the parameter `x`. // 1. Return a Boolean value that represents whether an environment specified in parameter `env` has a variable specified in the parameter `x`.
// TODO: YOUR CODE HERE // Hint: You can find which methods to use at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map // TODO: YOUR CODE HERE // Hint: You can find which methods to use at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
} }
function declare<T>(x: string, v: T, env: Environment<T>): void { function declare<T>(x: string, v: T, env: Environment<T>): void {
// 1. Add a variable represented by the parameter `x` into the environment represented by the parameters `env`. // 1. Add a variable represented by the parameter `x` into the environment represented by the parameter `env`.
// TODO: YOUR CODE HERE // Hint: You can find which methods to use at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map // TODO: YOUR CODE HERE // Hint: You can find which methods to use at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
} }
......
...@@ -156,7 +156,7 @@ export function parseProgram(tokens: Token[]): AstNode[] { ...@@ -156,7 +156,7 @@ export function parseProgram(tokens: Token[]): AstNode[] {
// 3.1.3.1.3. Property `nodeType` should be `PhysicalUnit` // 3.1.3.1.3. Property `nodeType` should be `PhysicalUnit`
// TODO: YOUR CODE HERE // TODO: YOUR CODE HERE
};
// 3.1.4. Otherwise, if that value is one of the (???what???) units, then: // 3.1.4. Otherwise, if that value is one of the (???what???) units, then:
} else if (/* TODO: YOUR CODE HERE */) { } else if (/* TODO: YOUR CODE HERE */) {
// TODO: YOUR CODE HERE // TODO: YOUR CODE HERE
...@@ -292,12 +292,12 @@ export function parseProgram(tokens: Token[]): AstNode[] { ...@@ -292,12 +292,12 @@ export function parseProgram(tokens: Token[]): AstNode[] {
left, left,
// 5.2. A property that represents the operator of the multiplicative expression. // 5.2. A property that represents the operator of the multiplicative expression.
// TODO: YOUR CODE HERE // TODO: YOUR CODE HERE
// 5.3. A property that represents the right operator of the multiplicative expression. // 5.3. A property that represents the right operand of the multiplicative expression.
right, right,
// 5.4. A property `nodeType` which is (???what???). // 5.4. A property `nodeType` which is (???what???).
nodeType: /* TODO: YOUR CODE HERE */, nodeType: /* TODO: YOUR CODE HERE */,
}; };
// 2.2. Make an iteration of the loop to process the possible remaining part of the multiplicative expression. // 2.2. Make an iteration of the loop to process the possible remaining part of the addition-like expression.
} }
// 5.5. Return the AST node. // 5.5. Return the AST node.
return left; return left;
......
import { interpret } from "./interpreter";
const tests = {
testPlus: () => {
let code = "let a = 1[kg] + 2 [kg]";
try {
let resultingEnv = interpret(code);
console.assert(
resultingEnv.env.get("a")?.unit.value === "m" &&
resultingEnv.env.get("a")?.value === 3
);
} catch {
console.log("Failed simple plus statement");
}
},
testMinus: () => {},
testLeftAssociativity: () => {},
testParenthesis: () => {},
testMultiplication: () => {},
testDivision: () => {},
};
export function runTests() {
tests.testPlus();
}