Filled in a lot of code
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed

This commit is contained in:
Brychan Dempsey 2021-03-26 11:30:26 +13:00
parent 3ed9bc885a
commit 7967fc4d21
2 changed files with 115 additions and 18 deletions

View File

@ -4,6 +4,7 @@
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
int main()
{
@ -14,15 +15,59 @@ int main()
bool exit = false;
while (!exit) {
std::vector<char> MemoryChars(1024); // Pre-reserve
MemoryStream ms(1024);
}
}
bool IsWhiteSpace(char c) {
if (c == ' ' || c == '\r' || c == '\n') {
return true;
}
return false;
}
void skipWhitespace(MemoryStream ms) {
char c = ms.PeekChar();
while (ms.position < ms.length && IsWhiteSpace(c)) {
ms.ReadChar();
c = ms.PeekChar();
}
}
std::string FindNextWord(MemoryStream ms, long &position) {
std::string nextWord;
long start = ms.position;
char curr = ms.ReadChar();
while (ms.position < ms.length && IsWhiteSpace(curr))
{
curr = ms.ReadChar();
}
nextWord.push_back(curr);
while (ms.position < ms.length)
{
curr = ms.ReadChar();
if (IsWhiteSpace(curr) || curr == ';')
{
ms.position--;
break;
}
else
{
nextWord.push_back(curr);
}
}
position = ms.position;
ms.position = start;
return nextWord;
}
struct MemoryStream {
private:
public:
long position = 0;
long length = 0;
private:
std::vector<char> chars;
bool ensureCapacity(long step) {
@ -54,7 +99,7 @@ public:
chars[++position] = c;
}
bool writeChars(char* c, int count) {
bool writeChars(const char* c, int count) {
ensureCapacity(count);
if (position >= length - count) length = position + count;
for (int i = 0; i < count; i++)
@ -64,13 +109,63 @@ public:
}
};
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
struct Parser {
std::vector<std::string> symbolNames;
std::vector<std::string> symbolValues;
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
void Exit() {
std::exit(0);
}
void StartParsing(MemoryStream ms, bool dynamicInput = false) {
long startLength = ms.length;
long lastLinePos = 0;
long initPos = 0;
bool cont = false;
while (true) {
if (dynamicInput) {
lastLinePos = ms.position;
if (!cont)
{
std::cout << "Enter a command: " << std::endl;
}
std::string s;
std::getline(std::cin, s);
long pos = ms.position;
ms.writeChars(s.c_str(), s.size());
ms.position = pos;
}
if (!cont) {
initPos = ms.position;
}
else {
ms.position = initPos;
}
skipWhitespace(ms);
long position = 0;
std::string word = FindNextWord(ms, position);
try {
if (word._Equal("set")) {
}
else if (word._Equal("exit")) {
}
else if (word._Equal("append")) {
}
else if (word._Equal("list")) {
}
else if (word._Equal("print")) {
}
}
catch (std::exception e)
{
}
}
}
};

View File

@ -37,10 +37,10 @@ namespace Assignment_1
static void Main(string[] args)
{
Console.WriteLine("┌──────────────────────────────────────────┐");
Console.WriteLine("│ 159.341 2021 Semester 1, Assignment 1 │");
Console.WriteLine("│ Submitted by Brychan Dempsey, 14299890 │");
Console.WriteLine("└──────────────────────────────────────────┘");
Console.WriteLine("┌──────────────────────────────────────────────┐");
Console.WriteLine("│ 159.341 2021 Semester 1, Assignment 1 (C#) │");
Console.WriteLine("│ Submitted by Brychan Dempsey, 14299890 │");
Console.WriteLine("└──────────────────────────────────────────────┘");
// Parse the source from the memory stream
bool exit = false;
while (!exit)
@ -185,6 +185,8 @@ namespace Assignment_1
{
// By turning the result of the command into an action,
// we can defer processing the final result until the end of this control flow
// This simplifies parsing the eol, and prevents the result being processed too
// optimistically.
Action result = () => { };
source.Position = position;
switch ((Statements)statementType)
@ -428,7 +430,7 @@ namespace Assignment_1
}
Action Exit(Stream source, long initialStreamLength, bool isDynamicInput=false)
{
Action exitAction = () =>
void exitAction()
{
if (source.Length != initialStreamLength && isDynamicInput)
{
@ -457,7 +459,7 @@ namespace Assignment_1
}
}
}
};
}
return exitAction;
}
Action Print(Stream source, int mode = 0)