From 201d7d2594f7597407fab50acac0bf51de8cce3e Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Tue, 12 Nov 2024 13:56:37 -0600 Subject: [PATCH] This is a rust project now, let's end the segregation --- .gitignore | 5 +-- rust/Cargo.lock => Cargo.lock | 0 rust/Cargo.toml => Cargo.toml | 0 rust/.gitignore | 1 - src/Makefile | 20 --------- src/deelang.cpp | 11 ----- {rust/src => src}/emitter.rs | 0 {rust/src => src}/evaluator.rs | 0 src/lexer.l | 54 ----------------------- {rust/src => src}/main.rs | 0 {rust/src => src}/parser.rs | 0 src/parser.y | 78 ---------------------------------- src/syntax.cpp | 49 --------------------- src/syntax.h | 50 ---------------------- 14 files changed, 1 insertion(+), 267 deletions(-) rename rust/Cargo.lock => Cargo.lock (100%) rename rust/Cargo.toml => Cargo.toml (100%) delete mode 100644 rust/.gitignore delete mode 100644 src/Makefile delete mode 100644 src/deelang.cpp rename {rust/src => src}/emitter.rs (100%) rename {rust/src => src}/evaluator.rs (100%) delete mode 100644 src/lexer.l rename {rust/src => src}/main.rs (100%) rename {rust/src => src}/parser.rs (100%) delete mode 100644 src/parser.y delete mode 100644 src/syntax.cpp delete mode 100644 src/syntax.h diff --git a/.gitignore b/.gitignore index 7f8c9c5..c8b241f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ -deelang -*.o -parser.h -lexer.h \ No newline at end of file +target/* \ No newline at end of file diff --git a/rust/Cargo.lock b/Cargo.lock similarity index 100% rename from rust/Cargo.lock rename to Cargo.lock diff --git a/rust/Cargo.toml b/Cargo.toml similarity index 100% rename from rust/Cargo.toml rename to Cargo.toml diff --git a/rust/.gitignore b/rust/.gitignore deleted file mode 100644 index c8b241f..0000000 --- a/rust/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/* \ No newline at end of file diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 30b7fe8..0000000 --- a/src/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -.PHONY: all clean -all: deelang -CC = g++ -CPPFLAGS = -g - -lexer.o lexer.h: parser.h lexer.l - flex -o lexer.cpp --header-file=lexer.h lexer.l - $(CC) -c lexer.cpp - rm lexer.cpp - -parser.h parser.o: parser.y - bison -o parser.cpp --header=parser.h parser.y - $(CC) -c parser.cpp - rm parser.cpp - -deelang: deelang.cpp lexer.o parser.o syntax.o - $(CC) $(CPPFLAGS) -o $@ $^ - -clean: - rm -rf *.o parser.h lexer.h deelang diff --git a/src/deelang.cpp b/src/deelang.cpp deleted file mode 100644 index 04a11ab..0000000 --- a/src/deelang.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "syntax.h" -#include "lexer.h" -#include "parser.h" - -using namespace std; - -int main() { - yyparse(); - - return 0; -} diff --git a/rust/src/emitter.rs b/src/emitter.rs similarity index 100% rename from rust/src/emitter.rs rename to src/emitter.rs diff --git a/rust/src/evaluator.rs b/src/evaluator.rs similarity index 100% rename from rust/src/evaluator.rs rename to src/evaluator.rs diff --git a/src/lexer.l b/src/lexer.l deleted file mode 100644 index 162a4bc..0000000 --- a/src/lexer.l +++ /dev/null @@ -1,54 +0,0 @@ -%{ -#include -#include -#include "syntax.h" -#include "parser.h" -using namespace std; - -stack s; - -#define YY_USER_INIT s.push(0); BEGIN(freshline); - -%} - -%option noyywrap - -%x freshline - -digit [0-9] -letter [A-Za-z] - -%% -""/[^\t ] { -if (s.top() == 0) { - BEGIN(0); -} else { - s.pop(); yyless(0); return DEDENT; -} - } -[ \t]+ { -if (s.top() == yyleng) { - BEGIN(0); // Same indentation, continue -} else if (s.top() > yyleng) { - s.pop(); yyless(0); return DEDENT; - // Same rule again until the stack is even -} else { - s.push(yyleng); BEGIN(0); return INDENT; -} - } -#[^\n]* // Eat comments -\"[^"]*\" yylval.sym = new string(yytext); return STRING; -if return IF; -else return ELSE; -elif return ELIF; -{digit}+|{digit}*\.{digit}+ yylval.num = atof(yytext); return NUM; -{letter}({letter}|{digit}|[?.-])* yylval.sym = new string(yytext); return ID; -"<-" return GETS; -"->" return MAPS; -".." return CAT; -[(){}.,*/+-] return yytext[0]; -[\t ] // Eat whitespace not first on a line -"/"\n // Eat newlines ending in / -[\n;] BEGIN(freshline); return STOP; -. fprintf(stderr, "Scanning error!\nOffender: %s\n", yytext); exit(1); -%% \ No newline at end of file diff --git a/rust/src/main.rs b/src/main.rs similarity index 100% rename from rust/src/main.rs rename to src/main.rs diff --git a/rust/src/parser.rs b/src/parser.rs similarity index 100% rename from rust/src/parser.rs rename to src/parser.rs diff --git a/src/parser.y b/src/parser.y deleted file mode 100644 index 371c9b3..0000000 --- a/src/parser.y +++ /dev/null @@ -1,78 +0,0 @@ -%{ - -#include -#include - -#include "syntax.h" - -using namespace std; - -int yylex(); -void yyerror(const char* p) { fprintf(stderr, p); } - -%} - -%define parse.trace - -%union { - float num; - std::string *sym; - Node *expr; - NodeList *exprlist; -} - -%token ID -%token NUM -%token STRING - -%token STOP -%token INDENT DEDENT -%token IF ELIF ELSE - -%right GETS -%left CAT -%left '+' '-' -%left '/' '*' -%left MAPS - -%nterm expr -%nterm exprlist - -%% -program: statements | statements statement; -statements: statements statement STOP - | statements STOP - | // null production ; -statement: assignment | funcall | conditional; -assignment: ID GETS expr; -assignments: assignments assignment STOP | // null production; -expr: funcdef - | funcall - | objdef - | expr CAT expr { $$ = new OpNode(CAT, $1, $3); } - | expr '+' expr { $$ = new OpNode('+', $1, $3); } - | expr '-' expr { $$ = new OpNode('-', $1, $3); } - | expr '*' expr { $$ = new OpNode('*', $1, $3); } - | expr '/' expr { $$ = new OpNode('/', $1, $3); } - | '(' expr ')' {$$ = $2;} - | ID {$$ = new IdNode($1);} - | NUM {$$ = new NumNode($1);} - | STRING {$$ = new StringNode($1);}; - -funcdef: param MAPS expr | param MAPS block; -param: ID | '_' | // null production; - -funcall: ID '(' exprlist ')' { print_expression_list($3); } -exprlist: exprlist ',' expr { $1 -> push_back($3); $$ = $1; } - | expr { $$ = new NodeList(); $$ -> push_back($1); } - | { $$ = new NodeList(); } // null production; - -conditional: IF expr block elifs - | IF expr block elifs ELSE block; -elifs: ELIF expr block elifs| // null production; - -objdef: '{' block_assignments '}' | '{' '}' - -block: STOP INDENT statement statements DEDENT -block_assignments: STOP INDENT assignments DEDENT -%% \ No newline at end of file diff --git a/src/syntax.cpp b/src/syntax.cpp deleted file mode 100644 index c9ba282..0000000 --- a/src/syntax.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include - -#include "syntax.h" - -using namespace std; - -IdNode::IdNode(string *id) { - this->id = id; -} - -void IdNode::display() { - cout << *id; -} - -NumNode::NumNode(float num) { - this->num = num; -} - -void NumNode::display() { - cout << num; -} - -StringNode::StringNode(string* stringVal) { - this->stringVal = stringVal; -} - -void StringNode::display() { - cout << *stringVal; -} - -OpNode::OpNode(int op, Node *first, Node *second) { - this->op = op; - this->first = first; - this->second = second; -} - -void OpNode::display() { - first->display(); - cout << " " << (char)op << " "; - second->display(); -} - -void print_expression_list(NodeList *list) { - for (Node *expr : *list) { - expr->display(); - } -} diff --git a/src/syntax.h b/src/syntax.h deleted file mode 100644 index fe75316..0000000 --- a/src/syntax.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef SYNTAX_H -#define SYNTAX_H - -#include -#include - -class Node { -public: - virtual void display() = 0; -}; - -class IdNode : public Node { -private: - std::string *id; -public: - IdNode(std::string*); - virtual void display(); -}; - -class NumNode : public Node { -private: - float num; -public: - NumNode(float); - virtual void display(); -}; - -class StringNode : public Node { -private: - std::string* stringVal; -public: - StringNode(std::string*); - virtual void display(); -}; - -class OpNode : public Node { -private: - int op; - Node *first; - Node *second; -public: - OpNode(int, Node*, Node*); - virtual void display(); -}; - -class NodeList : public std::vector{}; - -void print_expression_list(NodeList *); - -#endif /* SYNTAX_H */