SCCS-vsn: usr.bin/tn3270/tools/mkmake.y 1.8
*lasttoken, /* Back pointer */
*depend_list, /* If target, dependancies */
*action_list, /* If target, actions */
*lasttoken, /* Back pointer */
*depend_list, /* If target, dependancies */
*action_list, /* If target, actions */
- *value_list; /* If variable, value list */
+ *value_list, /* If variable, value list */
+ *shell_item; /* If a shell variable, current value */
-%token <intval> FOR IN DO DONE
%token <string> TOKEN QUOTED_STRING
%token <string> TOKEN QUOTED_STRING
-%token <intval> MACRO_CHAR WHITE_SPACE NL END_OF_FILE
-%token <intval> ':' '=' '$' '{' '}' ';' '-' '@' '(' ')'
-%type <same> target assignment actions action
-%type <same> for_statement maybe_at_minus tokens token
-%type <intval> special_chars white_space macro_char
+%token <intval> FOR IN DO DONE
+%token <intval> MACRO_CHAR NL WHITE_SPACE
+%token <intval> ':' '=' '$' '{' '}' ';' '-' '@' '(' ')' ' ' '\t'
+%type <same> target assignment assign1 actions action command_list command list
+%type <same> for_statement maybe_at_minus tokens token non_white_token
+%type <same> maybe_tokens
+%type <intval> white_space macro_char
-makefile : lines END_OF_FILE;
lines : line
| lines line
;
lines : line
| lines line
;
-line : maybe_white_space NL
| assignment
| target_action
;
assignment :
| assignment
| target_action
;
assignment :
- token maybe_white_space '=' maybe_white_space tokens maybe_white_space NL
- | token maybe_white_space '=' maybe_white_space NL
{
assign($1, same_copy(null));
}
;
{
assign($1, same_copy(null));
}
;
+assign1: non_white_token maybe_white_space '=' maybe_white_space
+ ;
+
target_action: target actions
{
add_targets_actions($1, $2);
target_action: target actions
{
add_targets_actions($1, $2);
- tokens maybe_white_space ':' maybe_white_space tokens maybe_white_space NL
+ non_white_token maybe_tokens ':' maybe_tokens NL
{
$$ = add_depends($1, $5);
}
{
$$ = add_depends($1, $5);
}
- | tokens maybe_white_space ':' maybe_white_space NL
- {
- $$ = add_depends($1, same_copy(null));
- }
-action: white_space tokens NL
+action: white_space command_list NL
+ {
+ $$ = $2;
+ }
+ | white_space for_statement do command_list semi_colon done NL
- | white_space for_statement NL
+ ;
+
+for_statement: maybe_at_minus FOR white_space non_white_token
+ white_space IN tokens semi_colon
+ {
+ $$ = for_statement($1, $4, expand_variables($7, 0));
+ }
+ ;
+
+do: white_space DO white_space
+ ;
+
+done: white_space DONE
+ ;
+
+semi_colon: maybe_white_space ';'
+ ;
+
+command_list: list
+ | '(' list maybe_white_space ')'
-for_statement: maybe_at_minus FOR white_space token
- white_space IN white_space tokens maybe_white_space ';'
- maybe_white_space DO white_space '(' maybe_white_space
- tokens maybe_white_space ')' maybe_white_space ';'
- maybe_white_space DONE
+list: command
+ {
+ $$ = $1;
+ }
+ | list semi_colon command
+ {
+ $$ = same_cat($1, same_cat(same_char('\n'), $3));
+ }
+ ;
+
+command: non_white_token maybe_tokens
- $$ = for_statement($1, $4, expand_variables($8, 0), $16);
$$ = same_item(string_lookup(buffer));
}
;
$$ = same_item(string_lookup(buffer));
}
;
+
+maybe_tokens:
+ {
+ $$ = same_copy(null);
+ }
+ | tokens
+ ;
+
tokens : token
| tokens token
{
tokens : token
| tokens token
{
+token: non_white_token
+ | white_space
+ {
+ $$ = same_char($1);
+ }
+ ;
+
+non_white_token: TOKEN
$$ = same_item(string_lookup(buffer));
}
$$ = same_item(string_lookup(buffer));
}
+ | '$' '$' non_white_token
- char buffer[2];
-
- buffer[0] = $1;
- buffer[1] = 0;
-
- $$ = same_item(string_lookup(buffer));
+ $$ = shell_variable($3);
+ }
+ | MACRO_CHAR
+ {
+ $$ = same_char($1);
+ | '$' '{' non_white_token '}'
- | '$'
- ;
-
-special_chars : MACRO_CHAR
- | white_space
white_space : WHITE_SPACE
| white_space WHITE_SPACE
;
white_space : WHITE_SPACE
| white_space WHITE_SPACE
;
static string_t
*strings = 0;
static string_t
*strings = 0;
+ *shell_variables = 0,
+ *shell_special = 0,
*variables = 0,
*targets = 0,
*actions = 0;
*variables = 0,
*targets = 0,
*actions = 0;
+ if (tokens == 0) {
+ return list;
+ }
if (list) {
last = tokens->lasttoken;
tokens->lasttoken = list->lasttoken;
if (list) {
last = tokens->lasttoken;
tokens->lasttoken = list->lasttoken;
+
+same_t *
+shell_variable(name)
+same_t *name;
+{
+ same_t *shell;
+
+ if ((shell = same_search(shell_variables, name)) == 0) {
+ char buffer[100];
+ sprintf(buffer, "Unknown shell variable %s.", name->string->string);
+ yyerror(buffer);
+ exit(1);
+ }
+ return same_copy(shell->shell_item);
+}
+
-for_statement(special, variable, list, commands)
+for_statement(special, variable, list)
same_t
*special,
*variable,
same_t
*special,
*variable,
- return same_cat(special, same_cat(variable, same_cat(list, commands)));
+ shell_special = special;
+ variable->value_list = list;
+ shell_variables = variable;
+ return same_copy(null);
fprintf(stderr, "End of file ignored.\n");
exit(1);
}
fprintf(stderr, "End of file ignored.\n");
exit(1);
}
}
while ((c = Getchar()) != EOF) {
switch (c) {
}
while ((c = Getchar()) != EOF) {
switch (c) {
eof_found = 1;
ret_token(' ');
eof_found = 1;
ret_token(' ');
- Return(END_OF_FILE, 0);