diff options
Diffstat (limited to '')
-rw-r--r-- | pymake.conf | 88 | ||||
-rw-r--r-- | src/build.l | 77 | ||||
-rw-r--r-- | src/build.y | 91 | ||||
-rw-r--r-- | src/builder.cpp | 34 | ||||
-rw-r--r-- | src/builder.h | 36 | ||||
-rw-r--r-- | src/main.cpp | 9 |
6 files changed, 331 insertions, 4 deletions
diff --git a/pymake.conf b/pymake.conf new file mode 100644 index 0000000..83d9885 --- /dev/null +++ b/pymake.conf | |||
@@ -0,0 +1,88 @@ | |||
1 | ### pymake by ~3o~ph()g (neonphog.com) ### | ||
2 | ## This skeleton file was generated by pymake... please edit for your project. | ||
3 | |||
4 | ## Global flag section, uncomment to set flags which will be applied to all | ||
5 | CXXFLAGS: -Ilibbu++/src | ||
6 | LDFLAGS: -Llibbu++ -lbu++ | ||
7 | |||
8 | ## A simple command to build everything in this directory, and output | ||
9 | ## an executable with the name 'main' | ||
10 | [BUILD] | ||
11 | DIR: src | ||
12 | COMMAND: exe | ||
13 | OUTPUT: build | ||
14 | |||
15 | ## To run a command, like a legacy 'make' command, issue the following: | ||
16 | #[RUN] | ||
17 | #COMMAND: make -C testsrc/legacy #this command will normally be run | ||
18 | #CLEAN: make -C testsrc/legacy clean #this command will be run on '-c' | ||
19 | |||
20 | ## A more complicated build example | ||
21 | #[BUILD] | ||
22 | #COMMAND: exe | ||
23 | #OUTPUT: the_one | ||
24 | #DIR: testsrc/one | ||
25 | #FILE: testsrc/share/test.cpp | ||
26 | #CXXFLAGS: -Itestsrc/share | ||
27 | #LDFLAGS: -lreadline | ||
28 | |||
29 | ## The [DIRBUILD] macro expands into many [BUILD] sections: | ||
30 | #[DIRBUILD] | ||
31 | #COMMAND: exe | ||
32 | #OUTPUT: db{NAME}.so #{NAME} will be replaced with the directory name | ||
33 | #ROOT: testsrc/db | ||
34 | #CXXFLAGS -Itestsrc/share | ||
35 | #LDFLAGS: -lreadline | ||
36 | |||
37 | ## The [OVERRIDE] directive allows you to append flags to specific targets | ||
38 | #[OVERRIDE] | ||
39 | #FILE: testsrc/db/mysql/main.o | ||
40 | #CXXFLAGS: -I../.. | ||
41 | |||
42 | ### The following are the build commands and triggers ### | ||
43 | ### These are the default gnu g++ build commands ### | ||
44 | |||
45 | ### Compile trigger ### | ||
46 | ## Takes c++ source code, builds an object file | ||
47 | ## Includes function for dependancy checking | ||
48 | [TRIGGER] | ||
49 | INPUT: .cpp #take input of *.cpp files | ||
50 | OUTPUT: .o #output .o files | ||
51 | COMMAND: g++ -c {INPUT} {CXXFLAGS} -I{DIR} -o {OUTPUT} | ||
52 | CHECK: g++ -M {INPUT} {CXXFLAGS} -I{DIR} | ||
53 | |||
54 | [TRIGGER] | ||
55 | INPUT: .c #take input of *.cpp files | ||
56 | OUTPUT: .o #output .o files | ||
57 | COMMAND: g++ -c {INPUT} {CXXFLAGS} -I{DIR} -o {OUTPUT} | ||
58 | CHECK: g++ -M {INPUT} {CXXFLAGS} -I{DIR} | ||
59 | |||
60 | [TRIGGER] | ||
61 | INPUT .y | ||
62 | OUTPUT: .tab.c | ||
63 | COMMAND: bison {INPUT} | ||
64 | |||
65 | [TRIGGER] | ||
66 | INPUT .l | ||
67 | OUTPUT: .yy.c | ||
68 | COMMAND: flex --bison-bridge -o {OUTPUT} {INPUT} | ||
69 | |||
70 | ### Executable command ### | ||
71 | ## Use this command if you want a simple executable | ||
72 | [COMMAND] | ||
73 | NAME: exe | ||
74 | COMMAND: g++ {INPUT} {LDFLAGS} -o {OUTPUT} | ||
75 | |||
76 | ### Library command ### | ||
77 | ## Use this command if you wish to create a library | ||
78 | [COMMAND] | ||
79 | NAME: lib | ||
80 | COMMAND: ar cr{ARFLAGS} {OUTPUT} {INPUT} | ||
81 | |||
82 | ### Strange example ### | ||
83 | ## The following trigger will take all *.q files, strip all '&'s from them | ||
84 | ## and generate a .cpp file, which will then be compiled using the cpp trigger. | ||
85 | #[TRIGGER] | ||
86 | #INPUT: .q | ||
87 | #OUTPUT: .cpp | ||
88 | #COMMAND: sed -e "s/&//g" {INPUT} > {OUTPUT} | ||
diff --git a/src/build.l b/src/build.l index 6daaa94..6a80f45 100644 --- a/src/build.l +++ b/src/build.l | |||
@@ -1,4 +1,20 @@ | |||
1 | int lineNum = 1; | 1 | %{ |
2 | # include <string> | ||
3 | # include "builder.h" | ||
4 | # include "build.tab.h" | ||
5 | # include "stringrep.h" | ||
6 | |||
7 | std::string strbuf; | ||
8 | %} | ||
9 | |||
10 | %x strsq | ||
11 | %x strdq | ||
12 | %x comment | ||
13 | %option noyywrap nounput batch debug | ||
14 | |||
15 | %{ | ||
16 | # define YY_USER_ACTION yylloc->columns (yyleng); | ||
17 | %} | ||
2 | %% | 18 | %% |
3 | 19 | ||
4 | [,:=] return yytext[0]; | 20 | [,:=] return yytext[0]; |
@@ -23,9 +39,62 @@ | |||
23 | "produces" return TOK_PRODUCES; | 39 | "produces" return TOK_PRODUCES; |
24 | "command" return TOK_COMMAND; | 40 | "command" return TOK_COMMAND; |
25 | 41 | ||
42 | "..."\n /* elipsis line continuation */ | ||
26 | \n+ return TOX_EOL; | 43 | \n+ return TOX_EOL; |
27 | [ \t\r]* | 44 | [ \t\r]* /* whitespace */ |
45 | |||
46 | \/\/.* /* single line comment */ | ||
47 | "#".* /* single line comment */ | ||
48 | |||
49 | [^ \t\r\n\'\"]+ { | ||
50 | yylval.strval = stringdup( yytext ); | ||
51 | return STRING; | ||
52 | } | ||
53 | |||
54 | \" { | ||
55 | BEGIN( strdq ); | ||
56 | strbuf = ""; | ||
57 | } | ||
58 | \' { | ||
59 | BEGIN( strsq ); | ||
60 | strbuf = ""; | ||
61 | } | ||
62 | |||
63 | <strdq>[^\\\n\"]+ { | ||
64 | strbuf += yytext; | ||
65 | } | ||
66 | |||
67 | <strsq>[^\\\n\']+ { | ||
68 | strbuf += yytext; | ||
69 | } | ||
70 | |||
71 | <strdq,strsq>\\n strbuf += "\n"; | ||
72 | <strdq,strsq>\\t strbuf += "\t"; | ||
73 | <strdq,strsq>\\r strbuf += "\r"; | ||
74 | <strdq,strsq>\\b strbuf += "\b"; | ||
75 | <strdq,strsq>\\f strbuf += "\f"; | ||
76 | |||
77 | <strdq>\" { | ||
78 | BEGIN( INITIAL ); | ||
79 | yylval->strval = stringdup( strbuf.c_str() ); | ||
80 | return STRING; | ||
81 | } | ||
82 | |||
83 | <strsq>\' { | ||
84 | BEGIN( INITIAL ); | ||
85 | yylval->strval = stringdup( strbuf.c_str() ); | ||
86 | return STRING; | ||
87 | } | ||
88 | |||
89 | |||
90 | void Builder::scanBegin() | ||
91 | { | ||
92 | if( !(yyin = fopen( file.c_str(), "r" )) ) | ||
93 | error( std::string("cannot open ") + file ); | ||
94 | } | ||
28 | 95 | ||
29 | \/\/.* | 96 | void Builder::scanEnd() |
30 | "#".* | 97 | { |
98 | fclose( yyin ); | ||
99 | } | ||
31 | 100 | ||
diff --git a/src/build.y b/src/build.y index e69de29..600b923 100644 --- a/src/build.y +++ b/src/build.y | |||
@@ -0,0 +1,91 @@ | |||
1 | %skeleton "lalr1.cc" | ||
2 | %define "parser_class_name" "BuildParser" | ||
3 | %defines | ||
4 | %{ | ||
5 | # include <string> | ||
6 | # include "builder.h" | ||
7 | # include "build.tab.h" | ||
8 | %} | ||
9 | |||
10 | %parse-param { Builder &bld } | ||
11 | %lex-param { Builder &bld } | ||
12 | |||
13 | %locations | ||
14 | %initial-action | ||
15 | { | ||
16 | @$.begin.filename = @$.end.filename = &bld.file; | ||
17 | } | ||
18 | |||
19 | %debug | ||
20 | %error-verbose | ||
21 | %union { | ||
22 | char *strval; | ||
23 | } | ||
24 | |||
25 | %token <strval> STRING "string literal" | ||
26 | |||
27 | %token TOK_ADDSET "+=" | ||
28 | %token TOK_DEFAULT "keyword 'default'" | ||
29 | %token TOK_ACTION "keyword 'action'" | ||
30 | %token TOK_CREATE "keyword 'create'" | ||
31 | %token TOK_FILE "keyword 'file'" | ||
32 | %token TOK_FROM "keyword 'from'" | ||
33 | %token TOK_FILES "keyword 'files'" | ||
34 | %token TOK_IN "keyword 'in'" | ||
35 | %token TOK_USING "keyword 'using'" | ||
36 | %token TOK_RULE "keyword 'rule'" | ||
37 | %token TOK_REQUIRES "keyword 'requires'" | ||
38 | %token TOK_FOR "keyword 'for'" | ||
39 | %token TOK_SET "keyword 'set'" | ||
40 | %token TOK_MATCHES "keyword 'matches'" | ||
41 | %token TOK_ALL "keyword 'all'" | ||
42 | %token TOK_ONE "keyword 'one'" | ||
43 | %token TOK_PERFORM "keyword 'perform'" | ||
44 | %token TOK_PRODUCES "keyword 'produces'" | ||
45 | %token TOK_COMMAND "keyword 'command'" | ||
46 | %token TOK_EOL "end of line" | ||
47 | |||
48 | %destructor { delete[] $$; } STRING | ||
49 | |||
50 | %% | ||
51 | |||
52 | input: | ||
53 | | input line | ||
54 | ; | ||
55 | |||
56 | line: stuff TOK_EOL { printf("\n"); } | ||
57 | ; | ||
58 | |||
59 | stuff: | ||
60 | | stuff token | ||
61 | ; | ||
62 | |||
63 | token: TOK_ADDSET { printf("+= "); } | ||
64 | | TOK_DEFAULT { printf("default "); } | ||
65 | | TOK_ACTION { printf("action "); } | ||
66 | | TOK_CREATE { printf("create "); } | ||
67 | | TOK_FILE { printf("file "); } | ||
68 | | TOK_FROM { printf("from "); } | ||
69 | | TOK_FILES { printf("files "); } | ||
70 | | TOK_IN { printf("in "); } | ||
71 | | TOK_USING { printf("using "); } | ||
72 | | TOK_RULE { printf("rule "); } | ||
73 | | TOK_REQUIRES { printf("requires "); } | ||
74 | | TOK_FOR { printf("for "); } | ||
75 | | TOK_SET { printf("set "); } | ||
76 | | TOK_MATCHES { printf("matches "); } | ||
77 | | TOK_ALL { printf("all "); } | ||
78 | | TOK_ONE { printf("one "); } | ||
79 | | TOK_PERFORM { printf("perform "); } | ||
80 | | TOK_PRODUCES { printf("produces "); } | ||
81 | | TOK_COMMAND { printf("command "); } | ||
82 | ; | ||
83 | |||
84 | %% | ||
85 | |||
86 | void yy::BuildParser::error( const yy::BuildParser::location_type &l, | ||
87 | const std::string &m ) | ||
88 | { | ||
89 | bld.error( l, m ); | ||
90 | } | ||
91 | |||
diff --git a/src/builder.cpp b/src/builder.cpp new file mode 100644 index 0000000..8c72fef --- /dev/null +++ b/src/builder.cpp | |||
@@ -0,0 +1,34 @@ | |||
1 | #include <iostream> | ||
2 | |||
3 | #include "builder.h" | ||
4 | #include "build.tab.h" | ||
5 | |||
6 | Builder::Builder() | ||
7 | { | ||
8 | } | ||
9 | |||
10 | Builder::~Builder() | ||
11 | { | ||
12 | } | ||
13 | |||
14 | void Builder::load( const char *sFN ) | ||
15 | { | ||
16 | file = sFN; | ||
17 | |||
18 | scanBegin(); | ||
19 | yy::BuildParser parser( *this ); | ||
20 | parser.set_debug_level( false ); | ||
21 | parser.parse(); | ||
22 | scanEnd(); | ||
23 | } | ||
24 | |||
25 | void Builder::error( const yy::location &l, const std::string &m ) | ||
26 | { | ||
27 | std::cerr << l << ": " << m << std::endl; | ||
28 | } | ||
29 | |||
30 | void Builder::error( const std::string &m ) | ||
31 | { | ||
32 | std::cerr << m << std::endl; | ||
33 | } | ||
34 | |||
diff --git a/src/builder.h b/src/builder.h new file mode 100644 index 0000000..e379608 --- /dev/null +++ b/src/builder.h | |||
@@ -0,0 +1,36 @@ | |||
1 | #ifndef BUILDER_H | ||
2 | #define BUILDER_H | ||
3 | |||
4 | #include <string> | ||
5 | |||
6 | union YYSTYPE; | ||
7 | |||
8 | namespace yy | ||
9 | { | ||
10 | class location; | ||
11 | class BuildParser; | ||
12 | } | ||
13 | class Builder; | ||
14 | |||
15 | #define YY_DECL int yylex( YYSTYPE *yylval_param, yy::location *yylloc, Builder &bld ) | ||
16 | YY_DECL; | ||
17 | |||
18 | class Builder | ||
19 | { | ||
20 | public: | ||
21 | Builder(); | ||
22 | virtual ~Builder(); | ||
23 | |||
24 | void load( const char *sFN ); | ||
25 | |||
26 | void error( const yy::location &l, const std::string &m ); | ||
27 | void error( const std::string &m ); | ||
28 | |||
29 | std::string file; | ||
30 | |||
31 | private: | ||
32 | void scanBegin(); | ||
33 | void scanEnd(); | ||
34 | }; | ||
35 | |||
36 | #endif | ||
diff --git a/src/main.cpp b/src/main.cpp index e69de29..7e130bc 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -0,0 +1,9 @@ | |||
1 | #include "builder.h" | ||
2 | |||
3 | int main() | ||
4 | { | ||
5 | Builder bld; | ||
6 | |||
7 | bld.load("congo"); | ||
8 | } | ||
9 | |||