diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-07-30 09:07:20 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-07-30 09:07:20 +0000 |
commit | 113fc467a7170a8a564049c64d1036dd10e6abac (patch) | |
tree | e4719817a3e0175a9f7cbd4e07fc994ff41f8ef6 /src/build.y | |
parent | 900976d2d74e0de57858b265c2ef0d17a29e921a (diff) | |
download | build-113fc467a7170a8a564049c64d1036dd10e6abac.tar.gz build-113fc467a7170a8a564049c64d1036dd10e6abac.tar.bz2 build-113fc467a7170a8a564049c64d1036dd10e6abac.tar.xz build-113fc467a7170a8a564049c64d1036dd10e6abac.zip |
It's starting to look pretty good, just trying to figure out how to get through
everything that needs to be made modular and general.
Diffstat (limited to 'src/build.y')
-rw-r--r-- | src/build.y | 87 |
1 files changed, 55 insertions, 32 deletions
diff --git a/src/build.y b/src/build.y index 600b923..45a84f1 100644 --- a/src/build.y +++ b/src/build.y | |||
@@ -1,19 +1,21 @@ | |||
1 | %skeleton "lalr1.cc" | ||
2 | %define "parser_class_name" "BuildParser" | ||
3 | %defines | 1 | %defines |
4 | %{ | 2 | %{ |
5 | # include <string> | 3 | # include <string> |
6 | # include "builder.h" | 4 | # include "builder.h" |
5 | # include "action.h" | ||
6 | # include "command.h" | ||
7 | # include "build.tab.h" | 7 | # include "build.tab.h" |
8 | void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ); | ||
8 | %} | 9 | %} |
9 | 10 | ||
10 | %parse-param { Builder &bld } | 11 | %parse-param { Builder &bld } |
11 | %lex-param { Builder &bld } | 12 | %lex-param { Builder &bld } |
13 | %pure-parser | ||
12 | 14 | ||
13 | %locations | 15 | %locations |
14 | %initial-action | 16 | %initial-action |
15 | { | 17 | { |
16 | @$.begin.filename = @$.end.filename = &bld.file; | 18 | //@$.begin.filename = @$.end.filename = &bld.file; |
17 | } | 19 | } |
18 | 20 | ||
19 | %debug | 21 | %debug |
@@ -23,6 +25,7 @@ | |||
23 | } | 25 | } |
24 | 26 | ||
25 | %token <strval> STRING "string literal" | 27 | %token <strval> STRING "string literal" |
28 | %token <strval> REGEXP "regular expression" | ||
26 | 29 | ||
27 | %token TOK_ADDSET "+=" | 30 | %token TOK_ADDSET "+=" |
28 | %token TOK_DEFAULT "keyword 'default'" | 31 | %token TOK_DEFAULT "keyword 'default'" |
@@ -43,49 +46,69 @@ | |||
43 | %token TOK_PERFORM "keyword 'perform'" | 46 | %token TOK_PERFORM "keyword 'perform'" |
44 | %token TOK_PRODUCES "keyword 'produces'" | 47 | %token TOK_PRODUCES "keyword 'produces'" |
45 | %token TOK_COMMAND "keyword 'command'" | 48 | %token TOK_COMMAND "keyword 'command'" |
49 | %token TOK_CHECK "keyword 'check'" | ||
46 | %token TOK_EOL "end of line" | 50 | %token TOK_EOL "end of line" |
51 | %token ',' ':' '=' | ||
47 | 52 | ||
48 | %destructor { delete[] $$; } STRING | 53 | %destructor { delete[] $$; } STRING |
49 | 54 | ||
50 | %% | 55 | %% |
51 | 56 | ||
52 | input: | 57 | input: |
53 | | input line | 58 | | input fullline |
54 | ; | 59 | ; |
55 | 60 | ||
56 | line: stuff TOK_EOL { printf("\n"); } | 61 | fullline: TOK_EOL |
62 | | line TOK_EOL | ||
63 | ; | ||
64 | |||
65 | line: TOK_DEFAULT TOK_ACTION ':' | ||
66 | { | ||
67 | bld.add( new Action() ); | ||
68 | } | ||
69 | actionlst | ||
70 | | STRING TOK_ACTION ':' | ||
71 | { | ||
72 | bld.add( new Action( $1 ) ); | ||
73 | } | ||
74 | actionlst | ||
75 | | TOK_CREATE createwhat TOK_FROM createfrom TOK_USING createusing | ||
57 | ; | 76 | ; |
58 | 77 | ||
59 | stuff: | 78 | createwhat: TOK_FILE STRING { printf("target: %s\n", $2 ); } |
60 | | stuff token | 79 | ; |
61 | ; | ||
62 | 80 | ||
63 | token: TOK_ADDSET { printf("+= "); } | 81 | createfrom: TOK_FILES TOK_IN createfromdirlst |
64 | | TOK_DEFAULT { printf("default "); } | 82 | ; |
65 | | TOK_ACTION { printf("action "); } | 83 | |
66 | | TOK_CREATE { printf("create "); } | 84 | createfromdirlst: createfromdir |
67 | | TOK_FILE { printf("file "); } | 85 | | createfromdirlst ',' createfromdir |
68 | | TOK_FROM { printf("from "); } | 86 | ; |
69 | | TOK_FILES { printf("files "); } | 87 | |
70 | | TOK_IN { printf("in "); } | 88 | createfromdir: STRING { printf(" srcdir: %s\n", $1 ); } |
71 | | TOK_USING { printf("using "); } | 89 | ; |
72 | | TOK_RULE { printf("rule "); } | 90 | |
73 | | TOK_REQUIRES { printf("requires "); } | 91 | createusing: TOK_RULE STRING { printf(" rule: %s\n", $2 ); } |
74 | | TOK_FOR { printf("for "); } | 92 | ; |
75 | | TOK_SET { printf("set "); } | 93 | |
76 | | TOK_MATCHES { printf("matches "); } | 94 | actionlst: action |
77 | | TOK_ALL { printf("all "); } | 95 | | actionlst ',' action |
78 | | TOK_ONE { printf("one "); } | 96 | ; |
79 | | TOK_PERFORM { printf("perform "); } | 97 | |
80 | | TOK_PRODUCES { printf("produces "); } | 98 | action: TOK_CHECK STRING |
81 | | TOK_COMMAND { printf("command "); } | 99 | { |
82 | ; | 100 | bld.add( new Command( Command::cmdCheck, $2 ) ); |
101 | } | ||
102 | ; | ||
83 | 103 | ||
84 | %% | 104 | %% |
85 | 105 | ||
86 | void yy::BuildParser::error( const yy::BuildParser::location_type &l, | 106 | void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ) |
87 | const std::string &m ) | ||
88 | { | 107 | { |
89 | bld.error( l, m ); | 108 | fprintf( stderr, "%s:%d-%d:%d-%d: %s\n", |
109 | bld.file.c_str(), | ||
110 | locp->first_line, locp->last_line, | ||
111 | locp->first_column, locp->last_column, | ||
112 | msg | ||
113 | ); | ||
90 | } | 114 | } |
91 | |||