Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e3acea9

Browse files
Utility to generate pscexamples.js (built by Makefile)
1 parent b2ed859 commit e3acea9

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

‎Makefile‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ BISON = bison
55
CPP = g++
66
CPPFLAGS = -std=c++20 -O3
77
TARGET = psc
8+
PROGS = pscexamples
89

910
AUTOGEN = Parser.hpp Parser.cpp Lexer.cpp Location.hpp
1011
OBJS = Lexer.o Parser.o main.o
12+
PROGS_OBJS = pscexamples.o
1113

12-
all: $(TARGET)
14+
all: $(TARGET)$(PROGS)
1315

1416
$(AUTOGEN): scanner.l grammar.y
1517
$(BISON) grammar.y
@@ -21,8 +23,11 @@ $(AUTOGEN): scanner.l grammar.y
2123
$(TARGET): $(AUTOGEN) $(OBJS)
2224
$(CPP) $(CPPFLAGS) -o $(TARGET) $(OBJS)
2325

26+
$(PROGS): $(PROGS_OBJS)
27+
$(CPP) $(CPPFLAGS) -o $(PROGS) $(PROGS_OBJS)
28+
2429
clean:
25-
rm -f $(TARGET) $(AUTOGEN) $(OBJS)
30+
rm -f $(PROGS)$(PROGS_OBJS)$(TARGET) $(AUTOGEN) $(OBJS)
2631

2732
# Static dependencies
2833
Lexer.o: SymbolTypes.hpp Tree.hpp Expression.hpp Symbol.hpp Lexer.hpp Parser.hpp

‎Makefile.nmake‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ CPPFlags = /nologo /EHsc /std:c++20 /O2 /wd4005 $(FlexLexer_h)
1313
Target = psc.exe
1414
Objs = Lexer.obj Parser.obj main.obj
1515
Autogen = Lexer.cpp Parser.hpp Parser.cpp Location.hpp
16+
Progs = pscexamples.exe
17+
ProgsObjs = pscexamples.obj
1618

17-
all: $(Target)
19+
all: $(Target) $(Progs)
1820

1921
$(Autogen): scanner.l grammar.y
2022
$(Bison) grammar.y
@@ -26,8 +28,11 @@ $(Autogen): scanner.l grammar.y
2628
$(Target): $(Autogen) $(Objs)
2729
$(CPP) $(CPPFlags) /Fe$(Target) $(Objs)
2830

31+
$(Progs): $(ProgsObjs)
32+
$(CPP) $(CPPFlags) /Fe$(Progs) $(ProgsObjs)
33+
2934
clean:
30-
del $(Target) $(Objs) $(Autogen)
35+
del $(Progs) $(ProgsObjs) $(Target) $(Objs) $(Autogen)
3136

3237
# Static dependencies
3338
Lexer.obj: SymbolTypes.hpp Tree.hpp Expression.hpp Symbol.hpp Lexer.hpp Parser.hpp

‎pscexamples.cpp‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// pscexamples.cpp : group pseudocode programs into .js file for web interface
2+
// Note: use ./pscexamples hello.psc chars.psc ... > ../pscexamples.js
3+
4+
#include <iostream>
5+
#include <fstream>
6+
#include <span>
7+
#include <string>
8+
9+
using std::span;
10+
using std::cout;
11+
using std::ifstream;
12+
using std::string;
13+
14+
int main(const int argc, const char **argv) {
15+
span<const char*> args{ argv + 1, argv + argc };
16+
cout << "pseudocode_examples = [ ";
17+
for (auto sep = ""; auto pscfile : args) {
18+
cout << sep << "{ name: \'" << pscfile << "\', code: `";
19+
ifstream file(pscfile);
20+
string code;
21+
getline(file, code, '0円');
22+
cout << code;
23+
cout << "` }";
24+
sep = ", ";
25+
}
26+
cout << " ];";
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /