Skip to content

Commit 74155cd

Browse files
committed
Implemented framework for graphic primitives
1 parent d328af4 commit 74155cd

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
cmake_minimum_required(VERSION 3.5)
22
project(PLOTSCRIPT CXX)
33

4+
# establish location of startup.pls script
5+
set(STARTUP_FILE ${CMAKE_SOURCE_DIR}/startup.pls)
6+
configure_file(${CMAKE_SOURCE_DIR}/startup_config.hpp.in ${CMAKE_BINARY_DIR}/startup_config.hpp)
7+
include_directories(${CMAKE_BINARY_DIR})
8+
49
# EDIT
510
# add any files you create related to the interpreter here
611
# excluding unit tests

plotscript.cpp

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "interpreter.hpp"
77
#include "semantic_error.hpp"
8+
#include "startup_config.hpp"
9+
810

911
void prompt(){
1012
std::cout << "\nplotscript> ";
@@ -25,10 +27,46 @@ void info(const std::string & err_str){
2527
std::cout << "Info: " << err_str << std::endl;
2628
}
2729

30+
int startup(Interpreter & interp){
31+
32+
std::ifstream ifs(STARTUP_FILE);
33+
34+
if(!ifs){
35+
error("Could not open file for reading.");
36+
return EXIT_FAILURE;
37+
}
38+
39+
if(!interp.parseStream(ifs)){
40+
ifs.close();
41+
error("Invalid Program. Could not parse.");
42+
return EXIT_FAILURE;
43+
}
44+
else{
45+
try{
46+
Expression exp = interp.evaluate();
47+
//std::cout << exp << std::endl;
48+
}
49+
catch(const SemanticError & ex){
50+
ifs.close();
51+
std::cerr << ex.what() << std::endl;
52+
return EXIT_FAILURE;
53+
}
54+
}
55+
56+
ifs.close();
57+
return EXIT_SUCCESS;
58+
}
59+
2860
int eval_from_stream(std::istream & stream){
2961

3062
Interpreter interp;
3163

64+
/*** Evaluate startup.pls ***/
65+
if(startup(interp) != 0){
66+
error("Invalid Startup Program.");
67+
return EXIT_FAILURE;
68+
}
69+
3270
if(!interp.parseStream(stream)){
3371
error("Invalid Program. Could not parse.");
3472
return EXIT_FAILURE;
@@ -69,7 +107,12 @@ int eval_from_command(std::string argexp){
69107
// A REPL is a repeated read-eval-print loop
70108
void repl(){
71109
Interpreter interp;
72-
110+
111+
/*** Evaluate startup.pls ***/
112+
if(startup(interp) != 0){
113+
error("Invalid Startup Program.");
114+
}
115+
73116
while(!std::cin.eof()){
74117

75118
prompt();
@@ -84,11 +127,11 @@ void repl(){
84127
}
85128
else{
86129
try{
87-
Expression exp = interp.evaluate();
88-
std::cout << exp << std::endl;
130+
Expression exp = interp.evaluate();
131+
std::cout << exp << std::endl;
89132
}
90133
catch(const SemanticError & ex){
91-
std::cerr << ex.what() << std::endl;
134+
std::cerr << ex.what() << std::endl;
92135
}
93136
}
94137
}

startup.pls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(begin
2+
)

startup_config.hpp.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef STARTUP_CONFIG_HPP
2+
#define STARTUP_CONFIG_HPP
3+
4+
#include <string>
5+
6+
const std::string STARTUP_FILE = "@STARTUP_FILE@";
7+
8+
#endif

0 commit comments

Comments
 (0)