Skip to content

Commit

Permalink
preparing for presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sauppb committed Apr 25, 2024
1 parent 985f041 commit cf68715
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 139 deletions.
9 changes: 9 additions & 0 deletions public/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
<body>
<h2>Changelog</h2>
<ul>
<li>
<strong> April 25, 2024:</strong>
<ul>
<li>Example are now in a dropdown</li>
<li>for loop now generates a block while incomplete</li>
<li>Added more examples</li>
<li>fixed some highlighting for the debugger</li>
</ul>
</li>
<li>
<strong> March 24, 2024:</strong>
<ul>
Expand Down
3 changes: 2 additions & 1 deletion src/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ class Praxly_addition {
await waitForStep();
textEditor.session.removeMarker(markerId);
}
return litNode_new(binop_typecheck(OP.ADDITION, a.realType, b.realType, this.json), a.value + b.value);
return litNode_new(binop_typecheck(OP.ADDITION, a.realType,
b.realType, this.json), a.value + b.value);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ export function highlightAstNode(node) {

// var errorRange = indextoAceRange(line - 1);
var Range = ace.require('ace/range').Range;
if (DEV_LOG){
console.log(`attempting to highlight: `, node.startIndex[0], node.startIndex[1], node.endIndex[0], node.endIndex[1]);
}

var errorRange = new Range(node.startIndex[0], node.startIndex[1], node.endIndex[0], node.endIndex[1]);
var markerId = session.addMarker(errorRange, 'error-marker', 'text');
var color = getStepInto()? `rgba(255, 255, 0, 0.4)` : `rgba(0, 255, 0, 0.2)`;
Expand Down
1 change: 0 additions & 1 deletion src/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export async function generateVariableTable(environment, level){
setStepInto(false);
let table = document.getElementById('Variable-table');
let parent = environment.parent;
console.warn(parent);
const variableList = environment.variableList;
// console.error(variableList);
for (const key in variableList) {
Expand Down
163 changes: 60 additions & 103 deletions src/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,17 @@ println fibonacci(10)
##mystery
##//this is from question 12 of the example problems
void mystery(int n)
while (n1)
if (n % 2 == 1)
n ← 3 * n + 1
else
n ← n / 2
end if
print n
end while
while (n1)
if (n % 2 == 1)
n ← 3 * n + 1
else
n ← n / 2
end if
print n
end while
end mystery
mystery(6)
##Bubble Sort
##// Global array declaration
int[] myArray = {5, 2, 9, 1, 5, 6};
Expand Down Expand Up @@ -158,107 +157,65 @@ end printArray
// Example usage
selectionSort()
printArray()
##Calculate Change
##// Function to calculate change
void calculateChange(int paidAmount, int itemCost)
int change ← paidAmount - itemCost
int cents ← change
int quarters ← cents / 25
cents ← cents % 25
int dimes ← cents / 10
cents ← cents % 10
int nickels ← cents / 5
int pennies ← cents % 5
// Print change breakdown
println "Change to be given:"
println "Quarters: " + quarters
println "Dimes: " + dimes
println "Nickels: " + nickels
println "Pennies: " + pennies
end calculateChange
// Main function
void main()
int itemCost ← 1789
int paidAmount ← 2000
// Check if paid amount is sufficient
if (paidAmount < itemCost)
println "Insufficient amount paid."
else
// Calculate and print change
calculateChange(paidAmount, itemCost)
end if
end main
`;


const testLater = `
##Insertion Sort
##// Global array declaration
int[] myArray = {5, 2, 9, 1, 5, 6};
// Insertion sort function
void insertionSort()
int n = 6
for (int i = 1; i < n; i = i + 1)
int key = myArray[i]
int j = i - 1
// Move elements of myArray[0..i-1] that are greater than key to one position ahead of their current position
while (j >= 0 and myArray[j] > key)
myArray[j + 1] = myArray[j]
j = j - 1
end while
// Run the main function
main()
##Count Characters
##// Count character function
int countCharacter(String str, char targetChar)
int count ← 0
for (int i ← 0; i < str.length(); i ← i + 1)
if (str.charAt(i) == targetChar)
count ← count + 1
end if
end for
return count
end countCharacter
myArray[j + 1] = key
end for
end insertionSort
println "Enter a string: "
String userString ← input
int occurrences ← countCharacter(userString, 'a')
println "Number of occurrences of '" + "a" + "' in " + userString + ":" + occurrences
// Print array function
void printArray()
int n = 6
for (int i = 0; i < n; i = i + 1)
println myArray[i]
end for
end printArray
// Example usage
insertionSort()
printArray()
##Merge Sort
##// Global array declaration
int[] myArray = {5, 2, 9, 1, 5, 6};
`;

// Merge sort function
void mergeSort(int left, int right)
if (left < right)
int mid = left + (right - left) / 2
// Sort first and second halves
mergeSort(left, mid)
mergeSort(mid + 1, right)
// Merge the sorted halves
int i = left
int j = mid + 1
int k = 0
int[6] temp
while (i <= mid and j <= right)
if (myArray[i] <= myArray[j])
temp[k] = myArray[i]
i = i + 1
else
temp[k] = myArray[j]
j = j + 1
end if
k = k + 1
end while
// Copy the remaining elements of left[], if there are any
while (i <= mid)
temp[k] = myArray[i]
i = i + 1
k = k + 1
end while
// Copy the remaining elements of right[], if there are any
while (j <= right)
temp[k] = myArray[j]
j = j + 1
k = k + 1
end while
// Copy the merged elements back to myArray
for (int p = 0; p < k; p = p + 1)
myArray[left + p] = temp[p]
end for
end if
end mergeSort

// Print array function
void printArray()
int n = 6
for (int i = 0; i < n; i = i + 1)
println myArray[i]
end for
end printArray

// Example usage
mergeSort(0, 5)
printArray()

`
5 changes: 0 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,6 @@ function GenerateExamples() {

GenerateExamples();

function applyExample(code) {
// append the example to the code
textEditor.setValue(code, -1);
textPane.click();
}

document.addEventListener('DOMContentLoaded', function() {
loadFromUrl();
Expand Down
4 changes: 4 additions & 0 deletions src/text2tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ class Parser {
result.type = NODETYPES.IF;
this.advance();
result.condition = this.parse_expression(9);
result.endIndex = this.getCurrentToken().endIndex;
if (this.has('\n')) {
this.advance();
result.statement = this.parse_block('else', 'end if');
Expand Down Expand Up @@ -890,6 +891,7 @@ class Parser {
}
this.advance();
if (this.has('\n')) {
result.endIndex = this.getCurrentToken().endIndex;
this.advance();
result.statement = this.parse_block('end for');
if (this.has('end for')) {
Expand All @@ -909,6 +911,7 @@ class Parser {
result.type = NODETYPES.WHILE;
this.advance();
result.condition = this.parse_expression(9);
result.endIndex = this.getCurrentToken().endIndex;
if (this.has('\n')) {
this.advance();
result.statement = this.parse_block('end while');
Expand Down Expand Up @@ -981,6 +984,7 @@ class Parser {
else if (this.has("print")) {
this.advance();
const expression = this.parse_expression(9);
result.endIndex = expression.endIndex;
if (this.has(';')) {
this.advance();
}
Expand Down
Loading

0 comments on commit cf68715

Please sign in to comment.