Filled in a lot of code
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed
Some checks failed
continuous-integration/appveyor/branch AppVeyor build failed
This commit is contained in:
parent
3ed9bc885a
commit
7967fc4d21
@ -4,6 +4,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@ -14,15 +15,59 @@ int main()
|
|||||||
|
|
||||||
bool exit = false;
|
bool exit = false;
|
||||||
while (!exit) {
|
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 {
|
struct MemoryStream {
|
||||||
private:
|
public:
|
||||||
long position = 0;
|
long position = 0;
|
||||||
long length = 0;
|
long length = 0;
|
||||||
|
private:
|
||||||
|
|
||||||
std::vector<char> chars;
|
std::vector<char> chars;
|
||||||
|
|
||||||
bool ensureCapacity(long step) {
|
bool ensureCapacity(long step) {
|
||||||
@ -54,7 +99,7 @@ public:
|
|||||||
chars[++position] = c;
|
chars[++position] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool writeChars(char* c, int count) {
|
bool writeChars(const char* c, int count) {
|
||||||
ensureCapacity(count);
|
ensureCapacity(count);
|
||||||
if (position >= length - count) length = position + count;
|
if (position >= length - count) length = position + count;
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
@ -64,13 +109,63 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
|
struct Parser {
|
||||||
// Debug program: F5 or Debug > Start Debugging menu
|
std::vector<std::string> symbolNames;
|
||||||
|
std::vector<std::string> symbolValues;
|
||||||
|
|
||||||
// Tips for Getting Started:
|
void Exit() {
|
||||||
// 1. Use the Solution Explorer window to add/manage files
|
std::exit(0);
|
||||||
// 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
|
void StartParsing(MemoryStream ms, bool dynamicInput = false) {
|
||||||
// 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
|
long startLength = ms.length;
|
||||||
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
@ -37,10 +37,10 @@ namespace Assignment_1
|
|||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("┌──────────────────────────────────────────┐");
|
Console.WriteLine("┌──────────────────────────────────────────────┐");
|
||||||
Console.WriteLine("│ 159.341 2021 Semester 1, Assignment 1 │");
|
Console.WriteLine("│ 159.341 2021 Semester 1, Assignment 1 (C#) │");
|
||||||
Console.WriteLine("│ Submitted by Brychan Dempsey, 14299890 │");
|
Console.WriteLine("│ Submitted by Brychan Dempsey, 14299890 │");
|
||||||
Console.WriteLine("└──────────────────────────────────────────┘");
|
Console.WriteLine("└──────────────────────────────────────────────┘");
|
||||||
// Parse the source from the memory stream
|
// Parse the source from the memory stream
|
||||||
bool exit = false;
|
bool exit = false;
|
||||||
while (!exit)
|
while (!exit)
|
||||||
@ -185,6 +185,8 @@ namespace Assignment_1
|
|||||||
{
|
{
|
||||||
// By turning the result of the command into an action,
|
// By turning the result of the command into an action,
|
||||||
// we can defer processing the final result until the end of this control flow
|
// 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 = () => { };
|
Action result = () => { };
|
||||||
source.Position = position;
|
source.Position = position;
|
||||||
switch ((Statements)statementType)
|
switch ((Statements)statementType)
|
||||||
@ -428,7 +430,7 @@ namespace Assignment_1
|
|||||||
}
|
}
|
||||||
Action Exit(Stream source, long initialStreamLength, bool isDynamicInput=false)
|
Action Exit(Stream source, long initialStreamLength, bool isDynamicInput=false)
|
||||||
{
|
{
|
||||||
Action exitAction = () =>
|
void exitAction()
|
||||||
{
|
{
|
||||||
if (source.Length != initialStreamLength && isDynamicInput)
|
if (source.Length != initialStreamLength && isDynamicInput)
|
||||||
{
|
{
|
||||||
@ -457,7 +459,7 @@ namespace Assignment_1
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
return exitAction;
|
return exitAction;
|
||||||
}
|
}
|
||||||
Action Print(Stream source, int mode = 0)
|
Action Print(Stream source, int mode = 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user