commit 8ca7e77e25dad36495724116d8e5b02a004d0e2b Author: Gene Stark Date: Sun Mar 27 16:45:17 2022 -0400 Bring in basecode from development repo. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b3fbca3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*~ +#* +*.d +*.o +*.out +bin/* +build/* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..4df88be --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,23 @@ +image: hwrunner:latest +variables: + GIT_SSL_NO_VERIFY: "true" + EXEC: mush + HW_DIR: hw4 +before_script: + - make clean all -C ${HW_DIR} +stages: + - build + - run + - test +build: + stage: build + script: + - echo "Build done" +run: + stage: run + script: + - cd ${HW_DIR} && bin/${EXEC} < rsrc/run_test.mush +test: + stage: test + script: + - cd ${HW_DIR} && bin/${EXEC}_tests -S --verbose=0 --timeout 5 diff --git a/hw4/Makefile b/hw4/Makefile new file mode 100644 index 0000000..d94d90b --- /dev/null +++ b/hw4/Makefile @@ -0,0 +1,61 @@ +CC := gcc +YACC := bison +LEX := flex +SRCD := src +TSTD := tests +BLDD := build +BIND := bin +INCD := include + +MAIN := $(BLDD)/main.o + +ALL_SRCF := $(shell find $(SRCD) -type f -name *.c) +ALL_OBJF := $(patsubst $(SRCD)/%,$(BLDD)/%,$(ALL_SRCF:.c=.o)) +ALL_FUNCF := $(filter-out $(MAIN) $(AUX), $(ALL_OBJF)) + +TEST_SRC := $(shell find $(TSTD) -type f -name *.c) + +INC := -I $(INCD) + +CFLAGS := -Wall -Werror -Wno-unused-function -MMD +COLORF := -DCOLOR +DFLAGS := -g -DDEBUG -DCOLOR +PRINT_STAMENTS := -DERROR -DSUCCESS -DWARN -DINFO + +TEST_LIB := -lcriterion +LIBS := + +EXEC := mush +TEST_EXEC := $(EXEC)_tests + +.PHONY: clean all setup debug + +all: setup $(BIND)/$(EXEC) $(BIND)/$(TEST_EXEC) + +debug: CFLAGS += $(DFLAGS) $(PRINT_STAMENTS) $(COLORF) +debug: all + +setup: $(BIND) $(BLDD) +$(BIND): + mkdir -p $(BIND) +$(BLDD): + mkdir -p $(BLDD) + +$(BIND)/$(EXEC): $(BLDD)/mush.tab.o $(BLDD)/mush.lex.o $(ALL_OBJF) + $(CC) $^ -o $@ $(LIBS) + +$(BIND)/$(TEST_EXEC): $(ALL_FUNCF) $(BLDD)/mush.tab.o $(BLDD)/mush.lex.o $(TEST_SRC) + $(CC) $(CFLAGS) $(INC) $(ALL_FUNCF) $(TEST_SRC) $(TEST_LIB) $(LIBS) -o $@ + +$(BLDD)/%.o: $(SRCD)/%.c $(INCD)/$(EXEC).tab.h + $(CC) $(CFLAGS) $(INC) -c -o $@ $< + +clean: + rm -rf $(BLDD) $(BIND) + +# Cancel the implicit rule that is doing the wrong thing. +%.c: %.y +%.c: %.l + +.PRECIOUS: $(BLDD)/*.d +-include $(BLDD)/*.d diff --git a/hw4/demo/mush b/hw4/demo/mush new file mode 100755 index 0000000..dd88f3a Binary files /dev/null and b/hw4/demo/mush differ diff --git a/hw4/include/debug.h b/hw4/include/debug.h new file mode 100644 index 0000000..e8fc8b6 --- /dev/null +++ b/hw4/include/debug.h @@ -0,0 +1,88 @@ +#ifndef DEBUG_H +#define DEBUG_H + +#include + +#define NL "\n" + +#ifdef COLOR +#define KNRM "\033[0m" +#define KRED "\033[1;31m" +#define KGRN "\033[1;32m" +#define KYEL "\033[1;33m" +#define KBLU "\033[1;34m" +#define KMAG "\033[1;35m" +#define KCYN "\033[1;36m" +#define KWHT "\033[1;37m" +#define KBWN "\033[0;33m" +#else +#define KNRM "" +#define KRED "" +#define KGRN "" +#define KYEL "" +#define KBLU "" +#define KMAG "" +#define KCYN "" +#define KWHT "" +#define KBWN "" +#endif + +#ifdef VERBOSE +#define DEBUG +#define INFO +#define WARN +#define ERROR +#define SUCCESS +#endif + +#ifdef DEBUG +#define debug(S, ...) \ + do { \ + fprintf(stderr, KMAG "DEBUG: %s:%s:%d " KNRM S NL, __FILE__, \ + __extension__ __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + } while (0) +#else +#define debug(S, ...) +#endif + +#ifdef INFO +#define info(S, ...) \ + do { \ + fprintf(stderr, KBLU "INFO: %s:%s:%d " KNRM S NL, __FILE__, \ + __extension__ __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + } while (0) +#else +#define info(S, ...) +#endif + +#ifdef WARN +#define warn(S, ...) \ + do { \ + fprintf(stderr, KYEL "WARN: %s:%s:%d " KNRM S NL, __FILE__, \ + __extension__ __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + } while (0) +#else +#define warn(S, ...) +#endif + +#ifdef SUCCESS +#define success(S, ...) \ + do { \ + fprintf(stderr, KGRN "SUCCESS: %s:%s:%d " KNRM S NL, __FILE__, \ + __extension__ __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + } while (0) +#else +#define success(S, ...) +#endif + +#ifdef ERROR +#define error(S, ...) \ + do { \ + fprintf(stderr, KRED "ERROR: %s:%s:%d " KNRM S NL, __FILE__, \ + __extension__ __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + } while (0) +#else +#define error(S, ...) +#endif + +#endif /* DEBUG_H */ diff --git a/hw4/include/mush.h b/hw4/include/mush.h new file mode 100644 index 0000000..19ede5a --- /dev/null +++ b/hw4/include/mush.h @@ -0,0 +1,53 @@ +/* + * DO NOT MODIFY THE CONTENTS OF THIS FILE. + * IT WILL BE REPLACED DURING GRADING + */ + +#include "syntax.h" + +/* Names of special store variables to hold results from job execution. */ +#define JOB_VAR "JOB" +#define STATUS_VAR "STATUS" +#define OUTPUT_VAR "OUTPUT" + +/* + * If you find it convenient, you may assume that the maximum number of jobs + * that can exist at one time is given by the following preprocessor symbol. + * Your code should continue to work even if the particular value of this + * symbol is changed before compilation. + */ +#define MAX_JOBS 10 + +/* Functions in program store module. */ +int prog_list(FILE *out); +int prog_insert(STMT *stmt); +int prog_delete(int min, int max); +void prog_reset(); +STMT *prog_fetch(); +STMT *prog_next(); +STMT *prog_goto(int lineno); + +/* Functions in data store module. */ +char *store_get_string(char *var); +int store_get_int(char *var, long *valp); +int store_set_string(char *var, char *val); +int store_set_int(char *var, long val); +void store_show(FILE *f); + +/* Functions in execution module. */ +int exec_interactive(); +int exec_stmt(STMT *stmt); +char *eval_to_string(EXPR *expr); +long eval_to_numeric(EXPR *expr); + +/* Functions in jobs module. */ +int jobs_init(void); +int jobs_fini(void); +int jobs_run(PIPELINE *pp); +int jobs_expunge(int jobid); +int jobs_wait(int jobid); +int jobs_poll(int jobid); +int jobs_cancel(int jobid); +int jobs_pause(void); +char *jobs_get_output(int jobid); +int jobs_show(FILE *file); diff --git a/hw4/include/mush.tab.h b/hw4/include/mush.tab.h new file mode 100644 index 0000000..79ea3fd --- /dev/null +++ b/hw4/include/mush.tab.h @@ -0,0 +1,125 @@ +/* A Bison parser, made by GNU Bison 3.5.1. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* Undocumented macros, especially those whose name start with YY_, + are private implementation details. Do not rely on them. */ + +#ifndef YY_YY_INCLUDE_MUSH_TAB_H_INCLUDED +# define YY_YY_INCLUDE_MUSH_TAB_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token type. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + NUMBER = 258, + NAME = 259, + WORD = 260, + STRING = 261, + LIST = 262, + DELETE = 263, + RUN = 264, + CONT = 265, + STOP = 266, + BG = 267, + CAPTURE = 268, + WAIT = 269, + POLL = 270, + CANCEL = 271, + PAUSE = 272, + SET = 273, + UNSET = 274, + IF = 275, + GOTO = 276, + SOURCE = 277, + EQ = 278, + PIPE = 279, + LESS = 280, + GREATER = 281, + EQUAL = 282, + LESSEQ = 283, + GREATEQ = 284, + AND = 285, + OR = 286, + NOT = 287, + LPAREN = 288, + RPAREN = 289, + PLUS = 290, + MINUS = 291, + TIMES = 292, + DIVIDE = 293, + MOD = 294, + COMMA = 295, + SHARP = 296, + DOLLAR = 297, + EOL = 298, + EoF = 299, + UNKNOWN = 300 + }; +#endif + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +union YYSTYPE +{ +#line 30 "src/mush.y" + + int number; + char *string; + STMT *stmt; + EXPR *expr; + ARG *args; + COMMAND *cmds; + PIPELINE *pline; + +#line 113 "include/mush.tab.h" + +}; +typedef union YYSTYPE YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + +int yyparse (void); + +#endif /* !YY_YY_INCLUDE_MUSH_TAB_H_INCLUDED */ diff --git a/hw4/include/syntax.h b/hw4/include/syntax.h new file mode 100644 index 0000000..e22dac5 --- /dev/null +++ b/hw4/include/syntax.h @@ -0,0 +1,212 @@ +/* + * DO NOT MODIFY THE CONTENTS OF THIS FILE. + * IT WILL BE REPLACED DURING GRADING + */ + +/* + * The elements of this enumerated type are used in the "class" field + * of the "STMT" structure to specify the particular kind of statement + * that the structure represents. The parenthesized names in the comments + * indicate which element (if any) of the "members" union in the STMT + * structure is used by each kind of statement. + */ +typedef enum { + NO_STMT_CLASS, + LIST_STMT_CLASS, // "list" statement + DELETE_STMT_CLASS, // "delete" statement (delete_stmt) + RUN_STMT_CLASS, // "run" statement + CONT_STMT_CLASS, // "cont" statement + STOP_STMT_CLASS, // "stop" statement + WAIT_STMT_CLASS, // "wait" statement (jobctl_stmt) + POLL_STMT_CLASS, // "poll" statement (jobctl_stmt) + CANCEL_STMT_CLASS, // "cancel" statement (jobctl_stmt) + PAUSE_STMT_CLASS, // "pause" statement + SET_STMT_CLASS, // "set" statement (set_stmt) + UNSET_STMT_CLASS, // "unset" statement (unset_stmt) + IF_STMT_CLASS, // "if" statement (if_stmt) + GOTO_STMT_CLASS, // "goto" statement (goto_stmt) + SOURCE_STMT_CLASS, // "source" statement (source_stmt) + FG_STMT_CLASS, // pipeline run in foreground (sys_stmt) + BG_STMT_CLASS // pipeline run in background (sys_stmt) +} STMT_CLASS; + +/* + * This structure is used to represent a statement. + * The value in the "class" field tells what kind of statement it is. + * Depending on this value, one of the fields of the "members" union + * may be valid. + */ +typedef struct stmt { + STMT_CLASS class; + int lineno; + union { + struct { + int from; + int to; + } delete_stmt; + struct { + struct pipeline *pipeline; + } sys_stmt; + struct { + struct expr *expr; + } jobctl_stmt; + struct { + char *name; + struct expr *expr; + } set_stmt; + struct { + char *name; + } unset_stmt; + struct { + struct expr *expr; + int lineno; + } if_stmt; + struct { + int lineno; + } goto_stmt; + struct { + char *file; + } source_stmt; + } members; +} STMT; + +/* + * This structure is used to represent a command. The "args" field points + * to the head of as a nonempty linked list of "args" that make up the command. + * The first "arg" is interpreted as the name of the command; the remainder + * are arguments to it. The "next" field is used to link commands into a + * pipeline. + */ +typedef struct command { + struct arg *args; + struct command *next; +} COMMAND; + +/* + * This structure is used to represent a "pipeline". The "commands" field + * points to the head of a nonempty list of commands. The "input_file" field, + * if non-NULL, is the name of a file from which input to the first command + * in the pipeline is to be redirected. Similarly, the "output_file" field, + * if non-NULL, is the name of a file to which output from the last command + * in the pipeline is to be redirected. If the "capture_output" field is + * nonzero, then instead of being redirected to a file, the output from the + * last command in the pipeline is to be redirected to a pipe. This pipe is + * to be read by the main process, which will "captures" the output and make + * it available as the value of a variable in the data store. + */ +typedef struct pipeline { + COMMAND *commands; + char *input_file; + char *output_file; + int capture_output; +} PIPELINE; + +/* + * Values of this enumerated type are used to identify the various kinds + * of expressions. + */ +typedef enum { + NO_EXPR_CLASS, + LIT_EXPR_CLASS, // literal string (value) + NUM_EXPR_CLASS, // numeric variable (variable) + STRING_EXPR_CLASS, // string variable (variable) + UNARY_EXPR_CLASS, // unary expression (unary_expr) + BINARY_EXPR_CLASS // binary expression (binary_expr) +} EXPR_CLASS; + +/* + * Values of this enumerated type are used to identify the various kinds + * of operators in expressions. + */ +typedef enum { + NO_OPRTR, + NOT_OPRTR, // "not" operator (unary_expr) + AND_OPRTR, // "and" operator (binary_expr) + OR_OPRTR, // "or" operator (binary_expr) + EQUAL_OPRTR, // "equal to" operator (binary_expr) + LESS_OPRTR, // "less than" operator (binary_expr) + GREATER_OPRTR, // "greater than" operator (binary_expr) + LESSEQ_OPRTR, // "less than or equal" operator (binary_expr) + GREATEQ_OPRTR, // "greater than or equal" operator (binary_expr) + PLUS_OPRTR, // "plus" (binary_expr) + MINUS_OPRTR, // "minus" (binary_expr) + TIMES_OPRTR, // "times" (binary_expr) + DIVIDE_OPRTR, // "divide" (binary_expr) + MOD_OPRTR // "mod" (binary_expr) +} OPRTR; + +/* + * Values of this enumerated type are used to identify the various kinds + * values that an expression can have. + */ +typedef enum { + NO_VALUE_TYPE, + NUM_VALUE_TYPE, // numeric value + STRING_VALUE_TYPE // string value +} VALUE_TYPE; + +/* + * This structure is used to represent an "expression". + */ +typedef struct expr { + EXPR_CLASS class; + VALUE_TYPE type; + union { + char *variable; + char *value; + struct { + OPRTR oprtr; + struct expr *arg; + } unary_expr; + struct { + OPRTR oprtr; + struct expr *arg1; + struct expr *arg2; + } binary_expr; + } members; +} EXPR; + +/* + * This structure is used to represent an "argument", which is + * a single element of a command. Arguments contain arbitrary expressions, + * which allows commands to be constructed that depend on the values + * of variables. + */ +typedef struct arg { + EXPR *expr; + struct arg *next; +} ARG; + +/* + * The following functions are used to print representations + * of the various syntactic objects to a specified output stream. + * A nonzero value for the "parens" argument of show_expr() causes + * a compound expression to be printed within enclosing parentheses. + */ +void show_stmt(FILE *file, STMT *stmt); +void show_pipeline(FILE *file, PIPELINE *pline); +void show_command(FILE *file, COMMAND *cmd); +void show_expr(FILE *file, EXPR *expr, int parens); +void show_oprtr(FILE *file, OPRTR oprtr); +void show_lineno(FILE *file, int lineno); + +/* + * The following functions are use to free the various syntactic + * objects. Freeing an object with one of these functions implies + * freeing all the objects that it references. + */ +void free_stmt(STMT *stmt); +void free_pipeline(PIPELINE *pline); +void free_commands(COMMAND *cmd); +void free_args(ARG *args); +void free_expr(EXPR *expr); +void free_oprtr(OPRTR oprtr); + +/* + * The following functions are use to make deep copies of the + * various syntactic objects. + */ +PIPELINE *copy_pipeline(PIPELINE *pline); +COMMAND *copy_commands(COMMAND *cmd); +ARG *copy_args(ARG *args); +EXPR *copy_expr(EXPR *expr); diff --git a/hw4/rsrc/bg_test.mush b/hw4/rsrc/bg_test.mush new file mode 100644 index 0000000..a41864a --- /dev/null +++ b/hw4/rsrc/bg_test.mush @@ -0,0 +1,7 @@ +10 sleep 10 & +15 echo line 15 +20 sleep 5 & +25 echo line 25 +30 sleep 3 & +35 echo line 35 +run diff --git a/hw4/rsrc/cancel_test.mush b/hw4/rsrc/cancel_test.mush new file mode 100644 index 0000000..b8ef19a --- /dev/null +++ b/hw4/rsrc/cancel_test.mush @@ -0,0 +1,6 @@ +10 sleep 10 & +15 set j10 = #JOB +20 sleep 2 +30 cancel #j10 +40 wait #j10 +run diff --git a/hw4/rsrc/delete_test.mush b/hw4/rsrc/delete_test.mush new file mode 100644 index 0000000..a9c9ea0 --- /dev/null +++ b/hw4/rsrc/delete_test.mush @@ -0,0 +1,7 @@ +10 echo line 10 +20 echo line 20 +30 echo line 30 +40 echo line 40 +50 echo line 50 +delete 10,25 +list diff --git a/hw4/rsrc/fg_test.mush b/hw4/rsrc/fg_test.mush new file mode 100644 index 0000000..8d29504 --- /dev/null +++ b/hw4/rsrc/fg_test.mush @@ -0,0 +1,7 @@ +10 sleep 10 +15 echo line 15 +20 sleep 5 +25 echo line 25 +30 sleep 3 +35 echo line 35 +run diff --git a/hw4/rsrc/goto_test.mush b/hw4/rsrc/goto_test.mush new file mode 100644 index 0000000..c2c7d7f --- /dev/null +++ b/hw4/rsrc/goto_test.mush @@ -0,0 +1,4 @@ +10 goto 30 +20 stop +30 echo yes +run diff --git a/hw4/rsrc/list_test.mush b/hw4/rsrc/list_test.mush new file mode 100644 index 0000000..7261724 --- /dev/null +++ b/hw4/rsrc/list_test.mush @@ -0,0 +1,3 @@ +10 echo line 10 +20 echo line 20 +list diff --git a/hw4/rsrc/loop1.mush b/hw4/rsrc/loop1.mush new file mode 100644 index 0000000..59f6093 --- /dev/null +++ b/hw4/rsrc/loop1.mush @@ -0,0 +1,4 @@ +10 echo hello +20 sleep 1 +30 goto 10 +run diff --git a/hw4/rsrc/loop2.mush b/hw4/rsrc/loop2.mush new file mode 100644 index 0000000..55d0277 --- /dev/null +++ b/hw4/rsrc/loop2.mush @@ -0,0 +1,8 @@ +10 set x = 1 +20 echo #x +25 sleep 1 +30 set x = !#x +35 echo #x +40 sleep 1 +50 goto 10 +run diff --git a/hw4/rsrc/pause_test.mush b/hw4/rsrc/pause_test.mush new file mode 100644 index 0000000..76659e0 --- /dev/null +++ b/hw4/rsrc/pause_test.mush @@ -0,0 +1,3 @@ +10 sleep 10 & +20 pause +run diff --git a/hw4/rsrc/pipeline_test.mush b/hw4/rsrc/pipeline_test.mush new file mode 100644 index 0000000..20875c8 --- /dev/null +++ b/hw4/rsrc/pipeline_test.mush @@ -0,0 +1,3 @@ +10 cat "/usr/share/dict/words" | grep program | grep sub > "pipeline_test.out" +20 cat "pipeline_test.out" +run diff --git a/hw4/rsrc/run_test.mush b/hw4/rsrc/run_test.mush new file mode 100644 index 0000000..d08171b --- /dev/null +++ b/hw4/rsrc/run_test.mush @@ -0,0 +1,4 @@ +10 echo line 10 +20 echo line 20 +30 echo line 30 +run diff --git a/hw4/rsrc/stop_test.mush b/hw4/rsrc/stop_test.mush new file mode 100644 index 0000000..bec4d48 --- /dev/null +++ b/hw4/rsrc/stop_test.mush @@ -0,0 +1,4 @@ +10 echo line 10 +20 stop +30 echo line 30 +run diff --git a/hw4/rsrc/wait_test.mush b/hw4/rsrc/wait_test.mush new file mode 100644 index 0000000..018d5c0 --- /dev/null +++ b/hw4/rsrc/wait_test.mush @@ -0,0 +1,19 @@ +10 sleep 10 & +11 set j10 = #JOB +12 echo j10 #j10 +15 echo line 15 +20 sleep 5 & +21 set j20 = #JOB +22 echo j20 #j20 +25 echo line 25 +30 sleep 3 & +31 set j30 = #JOB +32 echo j30 #j30 +35 echo line 35 +40 wait #j30 +45 echo j30 #STATUS +50 wait #j20 +55 echo j20 #STATUS +60 wait #j10 +65 echo j10 #STATUS +run diff --git a/hw4/src/execution.c b/hw4/src/execution.c new file mode 100644 index 0000000..001017d --- /dev/null +++ b/hw4/src/execution.c @@ -0,0 +1,392 @@ +/* + * DO NOT MODIFY THE CONTENTS OF THIS FILE. + * IT WILL BE REPLACED DURING GRADING + */ + +#include +#include +#include +#include +#include +#include + +#include "mush.h" +#include "mush.tab.h" +#include "debug.h" + +/* + * Mush: Execution engine. + */ + +extern int yylex_destroy(); +extern void push_input(FILE *in); +extern int pop_input(void); +extern int input_depth(void); +extern STMT *mush_parsed_stmt; + +static int exec_run(); +static int exec_cont(); + +#define PROMPT "mush: " + +/* Uncomment this to enable tracing of the parser. */ +//int yydebug = 1; + +/* + * A quit handler is installed to allow user-initiated escape + * from constructs that wait for signals. + */ +static volatile sig_atomic_t got_quit = 0; + +static void handler(int sig) { + got_quit = 1; +} + +/* + * Target for longjmp() to jump to after a low-level error has + * occurred, e.g. in expression evaluation. + */ +static jmp_buf onerror; + +/* + * Top-level interpreter loop. + * Reads single statements from stdin and either inserts them into the program, + * if they have a line number, otherwise executes them immediately. + */ +int exec_interactive() { + signal(SIGQUIT, SIG_IGN); + while(1) { + if(!input_depth() && isatty(fileno(stdin))) + fprintf(stdout, "%s", PROMPT); + fflush(stdout); + if(!yyparse()) { + STMT *stmt = mush_parsed_stmt; + if(stmt != NULL) { + if(stmt->lineno) { + prog_insert(stmt); + } else { + if(stmt->class == RUN_STMT_CLASS) { + free_stmt(stmt); + stmt = NULL; + exec_run(); + } else if(stmt->class == CONT_STMT_CLASS) { + free_stmt(stmt); + stmt = NULL; + exec_cont(); + } else { + exec_stmt(stmt); + free_stmt(stmt); + stmt = NULL; + } + } + } + } else { + if(pop_input()) + break; + } + if(!input_depth() && isatty(fileno(stdin))) { + store_show(stderr); + fprintf(stderr, "\n"); + jobs_show(stderr); + } + } + yylex_destroy(); + return 0; +} + +/* + * Enter an execution loop starting at the beginning of the program. + */ +static int exec_run() { + prog_reset(); + return exec_cont(); +} + +/* + * Enter an execution loop starting at the current line number. + */ +static int exec_cont() { + int err = 0; + STMT *stmt; + stmt = prog_fetch(); + if(stmt == NULL) { + fprintf(stderr, "No statement to execute\n"); + return -1; + } + if(setjmp(onerror)) + return -1; + signal(SIGQUIT, handler); + while(!got_quit) { + stmt = prog_fetch(); + if(!stmt) { + fprintf(stderr, "STOP (end of program)\n"); + break; + } + prog_next(); + err = exec_stmt(stmt); + if(err) + break; + } + signal(SIGQUIT, SIG_IGN); + if(got_quit) + fprintf(stderr, "Quit!\n"); + got_quit = 0; + return err; +} + +/* + * Execute a statement. + * This function is called from exec_run(). + * It can also be called separately to execute an individual statement + * read interactively. + * + * Successful execution (except for STOP) returns 0. + * Successful execution of STOP returns 1. + * Unsuccessful execution returns -1. + */ +int exec_stmt(STMT *stmt) { + int val; char *str; + FILE *in; + if(setjmp(onerror)) + return -1; + if(stmt->lineno) + debug("execute statement %d", stmt->lineno); + switch(stmt->class) { + case LIST_STMT_CLASS: + prog_list(stdout); + break; + case DELETE_STMT_CLASS: + prog_delete(stmt->members.delete_stmt.from, stmt->members.delete_stmt.to); + break; + case STOP_STMT_CLASS: + if(stmt->lineno) + fprintf(stderr, "STOP at line %d\n", stmt->lineno); + return 1; + case GOTO_STMT_CLASS: + if(!prog_goto(stmt->members.goto_stmt.lineno)) + return -1; + break; + case SET_STMT_CLASS: + switch(stmt->members.set_stmt.expr->type) { + case NUM_VALUE_TYPE: + val = eval_to_numeric(stmt->members.set_stmt.expr); + store_set_int(stmt->members.set_stmt.name, val); + break; + case STRING_VALUE_TYPE: + str = eval_to_string(stmt->members.set_stmt.expr); + store_set_string(stmt->members.set_stmt.name, str); + break; + default: + break; + } + break; + case UNSET_STMT_CLASS: + store_set_string(stmt->members.unset_stmt.name, NULL); + break; + case IF_STMT_CLASS: + val = eval_to_numeric(stmt->members.if_stmt.expr); + if(val) { + if(!prog_goto(stmt->members.if_stmt.lineno)) + return -1; + else + return 0; + } + break; + case SOURCE_STMT_CLASS: + in = fopen(stmt->members.source_stmt.file, "r"); + if(!in) { + fprintf(stderr, "Couldn't open source file: '%s'\n", + stmt->members.source_stmt.file); + return -1; + } + push_input(in); + break; + case FG_STMT_CLASS: + { + PIPELINE *pp = stmt->members.sys_stmt.pipeline; + int job = jobs_run(pp); + store_set_int(JOB_VAR, job); + int status = jobs_wait(job); + store_set_int(STATUS_VAR, status); + if(pp->capture_output) { + char *output = jobs_get_output(job); + debug("Captured output: '%s'", output); + store_set_string(OUTPUT_VAR, output); + } + jobs_expunge(job); + } + break; + case BG_STMT_CLASS: + { + int job = jobs_run(stmt->members.sys_stmt.pipeline); + store_set_int(JOB_VAR, job); + } + break; + case WAIT_STMT_CLASS: + { + int job = eval_to_numeric(stmt->members.jobctl_stmt.expr); + int status = jobs_wait(job); + store_set_int(STATUS_VAR, status); + jobs_expunge(job); + } + break; + case POLL_STMT_CLASS: + { + int job = eval_to_numeric(stmt->members.jobctl_stmt.expr); + int status = jobs_poll(job); + store_set_int(STATUS_VAR, status); + if(status >= 0) + jobs_expunge(job); + } + break; + case CANCEL_STMT_CLASS: + { + int job = eval_to_numeric(stmt->members.jobctl_stmt.expr); + jobs_cancel(job); + } + break; + case PAUSE_STMT_CLASS: + { + jobs_pause(); + } + default: + fprintf(stderr, "Unknown statement class: %d\n", stmt->class); + abort(); + } + return 0; +} + +/* + * Evaluate an expression, returning an integer result. + * It is assumed that the jmp_buf onerror has been initialized by the caller + * with a control point to escape to in case there is an error during evaluation. + */ +long eval_to_numeric(EXPR *expr) { + char *endp, *str1, *str2; + long opr1, opr2; + int err; + switch(expr->class) { + case LIT_EXPR_CLASS: + opr1 = strtol(expr->members.value, &endp, 0); + if(*endp == '\0') { + return opr1; + } else { + fprintf(stderr, "Literal '%s' is not an integer\n", expr->members.value); + longjmp(onerror, 0); + } + case STRING_EXPR_CLASS: + case NUM_EXPR_CLASS: + err = store_get_int(expr->members.variable, &opr1); + if(err) { + fprintf(stderr, "Variable %s does not have an integer value\n", + expr->members.variable); + longjmp(onerror, 0); + } + return opr1; + fprintf(stderr, "String variable %s in expression not implemented\n", + expr->members.variable); + abort(); + case UNARY_EXPR_CLASS: + opr1 = eval_to_numeric(expr->members.unary_expr.arg); + switch(expr->members.unary_expr.oprtr) { + case NOT_OPRTR: + return opr1 ? 0 : 1; + default: + fprintf(stderr, "Unknown unary numeric operator: %d\n", + expr->members.unary_expr.oprtr); + abort(); + } + case BINARY_EXPR_CLASS: + if(expr->members.binary_expr.oprtr == EQUAL_OPRTR) { + if(expr->members.binary_expr.arg1->type == NUM_VALUE_TYPE && + expr->members.binary_expr.arg2->type == NUM_VALUE_TYPE) { + opr1 = eval_to_numeric(expr->members.binary_expr.arg1); + opr2 = eval_to_numeric(expr->members.binary_expr.arg2); + return opr1 == opr2; + } else { + str1 = eval_to_string(expr->members.binary_expr.arg1); + str2 = eval_to_string(expr->members.binary_expr.arg2); + return !strcmp(str1, str2); + } + } + opr1 = eval_to_numeric(expr->members.binary_expr.arg1); + opr2 = eval_to_numeric(expr->members.binary_expr.arg2); + switch(expr->members.binary_expr.oprtr) { + case AND_OPRTR: + return opr1 && opr2; + case OR_OPRTR: + return opr1 || opr2; + case PLUS_OPRTR: + return opr1 + opr2; + case MINUS_OPRTR: + return opr1 - opr2; + case TIMES_OPRTR: + return opr1 * opr2; + case DIVIDE_OPRTR: + return opr1 / opr2; + case MOD_OPRTR: + return opr1 % opr2; + case LESS_OPRTR: + return opr1 < opr2; + case GREATER_OPRTR: + return opr1 > opr2; + case LESSEQ_OPRTR: + return opr1 <= opr2; + case GREATEQ_OPRTR: + return opr1 >= opr2; + default: + fprintf(stderr, "Unknown binary numeric operator: %d\n", + expr->members.binary_expr.oprtr); + abort(); + } + default: + fprintf(stderr, "Unknown expression class: %d\n", expr->class); + abort(); + } + return 0; +} + +/* + * Evaluate an expression, returning a string result. + * It is assumed that the jmp_buf onerror has been initialized by the caller + * with a control point to escape to in case there is an error during evaluation. + */ +char *eval_to_string(EXPR *expr) { + char *str1, *str2; + switch(expr->class) { + case LIT_EXPR_CLASS: + return expr->members.value; + case NUM_EXPR_CLASS: + case STRING_EXPR_CLASS: + str1 = store_get_string(expr->members.variable); + if(!str1) { + fprintf(stderr, "Variable %s does not have a value\n", + expr->members.variable); + longjmp(onerror, 0); + } + return str1; + case UNARY_EXPR_CLASS: + str1 = eval_to_string(expr->members.unary_expr.arg); + switch(expr->members.unary_expr.oprtr) { + default: + (void)str1; + fprintf(stderr, "Unknown unary string operator: %d\n", + expr->members.unary_expr.oprtr); + abort(); + } + case BINARY_EXPR_CLASS: + str1 = eval_to_string(expr->members.binary_expr.arg1); + str2 = eval_to_string(expr->members.binary_expr.arg2); + switch(expr->members.binary_expr.oprtr) { + default: + (void)str1; (void)str2; + fprintf(stderr, "Unknown binary string operator: %d\n", + expr->members.binary_expr.oprtr); + abort(); + } + default: + fprintf(stderr, "Unknown expression class: %d\n", expr->class); + abort(); + } + return 0; +} diff --git a/hw4/src/jobs.c b/hw4/src/jobs.c new file mode 100644 index 0000000..8be3158 --- /dev/null +++ b/hw4/src/jobs.c @@ -0,0 +1,223 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mush.h" +#include "debug.h" + +/* + * This is the "jobs" module for Mush. + * It maintains a table of jobs in various stages of execution, and it + * provides functions for manipulating jobs. + * Each job contains a pipeline, which is used to initialize the processes, + * pipelines, and redirections that make up the job. + * Each job has a job ID, which is an integer value that is used to identify + * that job when calling the various job manipulation functions. + * + * At any given time, a job will have one of the following status values: + * "new", "running", "completed", "aborted", "canceled". + * A newly created job starts out in with status "new". + * It changes to status "running" when the processes that make up the pipeline + * for that job have been created. + * A running job becomes "completed" at such time as all the processes in its + * pipeline have terminated successfully. + * A running job becomes "aborted" if the last process in its pipeline terminates + * with a signal that is not the result of the pipeline having been canceled. + * A running job becomes "canceled" if the jobs_cancel() function was called + * to cancel it and in addition the last process in the pipeline subsequently + * terminated with signal SIGKILL. + * + * In general, there will be other state information stored for each job, + * as required by the implementation of the various functions in this module. + */ + +/** + * @brief Initialize the jobs module. + * @details This function is used to initialize the jobs module. + * It must be called exactly once, before any other functions of this + * module are called. + * + * @return 0 if initialization is successful, otherwise -1. + */ +int jobs_init(void) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Finalize the jobs module. + * @details This function is used to finalize the jobs module. + * It must be called exactly once when job processing is to be terminated, + * before the program exits. It should cancel all jobs that have not + * yet terminated, wait for jobs that have been cancelled to terminate, + * and then expunge all jobs before returning. + * + * @return 0 if finalization is completely successful, otherwise -1. + */ +int jobs_fini(void) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Print the current jobs table. + * @details This function is used to print the current contents of the jobs + * table to a specified output stream. The output should consist of one line + * per existing job. Each line should have the following format: + * + * \t\t\t + * + * where is the numeric job ID of the job, is one of the + * following strings: "new", "running", "completed", "aborted", or "canceled", + * and is the job's pipeline, as printed by function show_pipeline() + * in the syntax module. The \t stand for TAB characters. + * + * @param file The output stream to which the job table is to be printed. + * @return 0 If the jobs table was successfully printed, -1 otherwise. + */ +int jobs_show(FILE *file) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Create a new job to run a pipeline. + * @details This function creates a new job and starts it running a specified + * pipeline. The pipeline will consist of a "leader" process, which is the direct + * child of the process that calls this function, plus one child of the leader + * process to run each command in the pipeline. All processes in the pipeline + * should have a process group ID that is equal to the process ID of the leader. + * The leader process should wait for all of its children to terminate before + * terminating itself. The leader should return the exit status of the process + * running the last command in the pipeline as its own exit status, if that + * process terminated normally. If the last process terminated with a signal, + * then the leader should terminate via SIGABRT. + * + * If the "capture_output" flag is set for the pipeline, then the standard output + * of the last process in the pipeline should be redirected to be the same as + * the standard output of the pipeline leader, and this output should go via a + * pipe to the main Mush process, where it should be read and saved in the data + * store as the value of a variable, as described in the assignment handout. + * If "capture_output" is not set for the pipeline, but "output_file" is non-NULL, + * then the standard output of the last process in the pipeline should be redirected + * to the specified output file. If "input_file" is set for the pipeline, then + * the standard input of the process running the first command in the pipeline should + * be redirected from the specified input file. + * + * @param pline The pipeline to be run. The jobs module expects this object + * to be valid for as long as it requires, and it expects to be able to free this + * object when it is finished with it. This means that the caller should not pass + * a pipeline object that is shared with any other data structure, but rather should + * make a copy to be passed to this function. + * + * @return -1 if the pipeline could not be initialized properly, otherwise the + * value returned is the job ID assigned to the pipeline. + */ +int jobs_run(PIPELINE *pline) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Wait for a job to terminate. + * @details This function is used to wait for the job with a specified job ID + * to terminate. A job has terminated when it has entered the COMPLETED, ABORTED, + * or CANCELED state. + * + * @param jobid The job ID of the job to wait for. + * @return the exit status of the job leader, as returned by waitpid(), + * or -1 if any error occurs that makes it impossible to wait for the specified job. + */ +int jobs_wait(int jobid) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Poll to find out if a job has terminated. + * @details This function is used to poll whether the job with the specified ID + * has terminated. This is similar to jobs_wait(), except that this function returns + * immediately without waiting if the job has not yet terminated. + * + * @param jobid The job ID of the job to wait for. + * @return the exit status of the job leader, as returned by waitpid(), if the job + * has terminated, or -1 if the job has not yet terminated or if any other error occurs. + */ +int jobs_poll(int jobid) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Expunge a terminated job from the jobs table. + * @details This function is used to expunge (remove) a job that has terminated from + * the jobs table, so that space in the table can be used to start some new job. + * In order to be expunged, a job must have terminated; if an attempt is made to expunge + * a job that has not yet terminated, it is an error. Any resources (exit status, + * open pipes, captured output, etc.) that were being used by the job are finalized + * and/or freed and will no longer be available. + * + * @param jobid The job ID of the job to expunge. + * @return 0 if the job was successfully expunged, -1 if the job could not be expunged. + */ +int jobs_expunge(int jobid) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Attempt to cancel a job. + * @details This function is used to attempt to cancel a running job. + * In order to be canceled, the job must not yet have terminated and there + * must not have been any previous attempt to cancel the job. + * Cancellation is attempted by sending SIGKILL to the process group associated + * with the job. Cancellation becomes successful, and the job actually enters the canceled + * state, at such subsequent time as the job leader terminates as a result of SIGKILL. + * If after attempting cancellation, the job leader terminates other than as a result + * of SIGKILL, then cancellation is not successful and the state of the job is either + * COMPLETED or ABORTED, depending on how the job leader terminated. + * + * @param jobid The job ID of the job to cancel. + * @return 0 if cancellation was successfully initiated, -1 if the job was already + * terminated, a previous attempt had been made to cancel the job, or any other + * error occurred. + */ +int jobs_cancel(int jobid) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Get the captured output of a job. + * @details This function is used to retrieve output that was captured from a job + * that has terminated, but that has not yet been expunged. Output is captured for a job + * when the "capture_output" flag is set for its pipeline. + * + * @param jobid The job ID of the job for which captured output is to be retrieved. + * @return The captured output, if the job has terminated and there is captured + * output available, otherwise NULL. + */ +char *jobs_get_output(int jobid) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Pause waiting for a signal indicating a potential job status change. + * @details When this function is called it blocks until some signal has been + * received, at which point the function returns. It is used to wait for a + * potential job status change without consuming excessive amounts of CPU time. + * + * @return -1 if any error occurred, 0 otherwise. + */ +int jobs_pause(void) { + // TO BE IMPLEMENTED + abort(); +} diff --git a/hw4/src/main.c b/hw4/src/main.c new file mode 100644 index 0000000..9178838 --- /dev/null +++ b/hw4/src/main.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include + +#include "mush.h" + +int main(int argc, char *argv[]) { + jobs_init(); + exec_interactive(); + jobs_fini(); +} diff --git a/hw4/src/mush.lex.c b/hw4/src/mush.lex.c new file mode 100644 index 0000000..75aac0e --- /dev/null +++ b/hw4/src/mush.lex.c @@ -0,0 +1,2219 @@ +#line 2 "src/mush.lex.c" + +#line 4 "src/mush.lex.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 4 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ + +/* TODO: this is always defined, so inline it */ +#define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) +#else +#define yynoreturn +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an + * integer in range [0..255] for use as an array index. + */ +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = NULL; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart ( FILE *input_file ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); +void yy_delete_buffer ( YY_BUFFER_STATE b ); +void yy_flush_buffer ( YY_BUFFER_STATE b ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state ( void ); + +static void yyensure_buffer_stack ( void ); +static void yy_load_buffer_state ( void ); +static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); + +void *yyalloc ( yy_size_t ); +void *yyrealloc ( void *, yy_size_t ); +void yyfree ( void * ); + +#define yy_new_buffer yy_create_buffer +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer( yyin, YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ +typedef flex_uint8_t YY_CHAR; + +FILE *yyin = NULL, *yyout = NULL; + +typedef int yy_state_type; + +extern int yylineno; +int yylineno = 1; + +extern char *yytext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state ( void ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); +static int yy_get_next_buffer ( void ); +static void yynoreturn yy_fatal_error ( const char* msg ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; +#define YY_NUM_RULES 45 +#define YY_END_OF_BUFFER 46 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static const flex_int16_t yy_accept[132] = + { 0, + 0, 0, 46, 42, 2, 3, 1, 24, 44, 28, + 29, 34, 19, 25, 26, 32, 30, 27, 31, 33, + 42, 22, 20, 23, 18, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 21, 42, 0, + 43, 0, 38, 40, 42, 36, 35, 37, 41, 42, + 41, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 39, 0, 0, 0, 0, + 42, 42, 42, 42, 15, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 0, 0, 0, 0, 42, 42, + 42, 42, 42, 42, 42, 6, 13, 42, 42, 42, + + 42, 0, 0, 0, 0, 42, 7, 42, 16, 4, + 42, 10, 42, 8, 42, 9, 0, 0, 42, 42, + 12, 42, 14, 0, 11, 5, 17, 0, 0, 0, + 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 1, 18, 19, 20, 20, + 20, 20, 20, 20, 21, 21, 21, 1, 1, 22, + 23, 24, 11, 25, 26, 26, 26, 26, 26, 26, + 27, 27, 27, 27, 27, 28, 27, 27, 27, 27, + 27, 27, 27, 27, 29, 27, 27, 27, 27, 27, + 1, 30, 1, 1, 27, 1, 31, 32, 33, 34, + + 35, 36, 37, 27, 38, 27, 27, 39, 27, 40, + 41, 42, 27, 43, 44, 45, 46, 47, 48, 49, + 27, 27, 1, 50, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static const YY_CHAR yy_meta[51] = + { 0, + 1, 2, 3, 2, 4, 5, 4, 4, 4, 4, + 6, 2, 2, 4, 4, 4, 4, 4, 7, 7, + 8, 2, 4, 2, 4, 8, 1, 1, 6, 6, + 7, 7, 8, 8, 8, 7, 1, 1, 1, 6, + 1, 1, 6, 1, 6, 6, 6, 1, 6, 4 + } ; + +static const flex_int16_t yy_base[148] = + { 0, + 0, 0, 69, 0, 353, 353, 353, 353, 45, 353, + 353, 353, 57, 353, 353, 353, 353, 353, 353, 353, + 74, 42, 41, 39, 353, 124, 154, 79, 65, 60, + 66, 67, 98, 57, 106, 68, 100, 10, 0, 103, + 353, 94, 353, 353, 0, 353, 353, 353, 353, 49, + 112, 105, 109, 111, 62, 50, 115, 116, 113, 128, + 126, 147, 132, 138, 157, 353, 155, 0, 0, 0, + 158, 163, 164, 166, 353, 171, 173, 174, 55, 184, + 175, 177, 186, 183, 190, 0, 0, 223, 188, 198, + 191, 228, 235, 192, 244, 353, 353, 200, 258, 206, + + 263, 205, 0, 0, 0, 234, 353, 239, 353, 353, + 273, 353, 246, 353, 280, 353, 0, 0, 285, 290, + 353, 295, 353, 0, 353, 353, 353, 0, 0, 0, + 353, 301, 309, 317, 321, 322, 324, 326, 328, 330, + 332, 334, 336, 338, 340, 342, 344 + } ; + +static const flex_int16_t yy_def[148] = + { 0, + 131, 1, 131, 132, 131, 131, 131, 131, 133, 131, + 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, + 132, 131, 131, 131, 131, 134, 134, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 131, 132, 133, + 131, 135, 131, 131, 21, 131, 131, 131, 131, 27, + 133, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 131, 133, 136, 137, 138, + 27, 27, 27, 27, 131, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 133, 139, 140, 133, 27, 27, + 27, 27, 27, 27, 27, 131, 131, 27, 27, 27, + + 27, 133, 141, 142, 88, 27, 131, 27, 131, 131, + 27, 131, 27, 131, 27, 131, 143, 144, 27, 27, + 131, 27, 131, 145, 131, 131, 131, 146, 147, 144, + 0, 131, 131, 131, 131, 131, 131, 131, 131, 131, + 131, 131, 131, 131, 131, 131, 131 + } ; + +static const flex_int16_t yy_nxt[404] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 4, 14, 15, 16, 17, 18, 19, 20, 4, 21, + 21, 22, 23, 24, 25, 26, 26, 27, 26, 4, + 26, 26, 28, 29, 26, 26, 30, 31, 32, 26, + 26, 33, 34, 35, 26, 36, 26, 37, 26, 38, + 41, 75, 75, 75, 49, 49, 96, 96, 96, 66, + 49, 48, 49, 47, 46, 49, 43, 49, 131, 131, + 49, 49, 49, 49, 42, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 49, 44, 44, 44, 44, 44, + 44, 44, 45, 45, 45, 44, 44, 44, 44, 54, + + 55, 56, 60, 49, 57, 49, 74, 64, 41, 52, + 49, 49, 67, 67, 49, 131, 49, 41, 49, 53, + 49, 49, 68, 44, 39, 49, 49, 49, 58, 49, + 65, 49, 42, 49, 39, 49, 49, 49, 59, 69, + 61, 42, 70, 49, 71, 49, 62, 49, 72, 73, + 63, 78, 49, 39, 39, 49, 49, 49, 76, 51, + 41, 77, 49, 49, 39, 49, 49, 79, 49, 49, + 80, 49, 82, 85, 85, 49, 49, 49, 49, 49, + 49, 83, 49, 39, 42, 97, 97, 97, 49, 49, + 89, 49, 81, 49, 84, 41, 49, 49, 91, 107, + + 107, 107, 131, 49, 131, 49, 92, 90, 102, 102, + 41, 49, 95, 131, 131, 93, 94, 98, 99, 42, + 100, 131, 106, 131, 131, 131, 111, 101, 41, 109, + 109, 109, 113, 49, 42, 108, 110, 110, 110, 49, + 49, 105, 105, 105, 49, 112, 112, 112, 105, 49, + 115, 49, 42, 105, 105, 105, 105, 105, 105, 114, + 114, 114, 131, 49, 116, 116, 116, 131, 49, 131, + 131, 131, 119, 120, 121, 121, 121, 131, 49, 131, + 122, 123, 123, 123, 131, 49, 125, 125, 125, 131, + 49, 126, 126, 126, 131, 49, 127, 127, 127, 131, + + 49, 39, 131, 131, 131, 131, 39, 39, 39, 40, + 40, 131, 40, 40, 40, 40, 40, 50, 50, 50, + 131, 50, 50, 50, 50, 40, 40, 40, 86, 86, + 87, 87, 88, 88, 103, 103, 104, 104, 117, 117, + 118, 118, 124, 124, 40, 40, 128, 128, 129, 129, + 130, 130, 3, 131, 131, 131, 131, 131, 131, 131, + 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, + 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, + 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, + 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, + + 131, 131, 131 + } ; + +static const flex_int16_t yy_chk[404] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 9, 56, 56, 56, 50, 56, 79, 79, 79, 38, + 79, 24, 34, 23, 22, 30, 13, 55, 3, 0, + 29, 31, 32, 36, 9, 21, 21, 21, 21, 21, + 21, 21, 21, 21, 28, 21, 21, 21, 21, 21, + 21, 21, 21, 21, 21, 21, 21, 21, 21, 29, + + 30, 31, 34, 33, 32, 37, 55, 36, 40, 28, + 52, 35, 42, 42, 53, 0, 54, 51, 59, 28, + 57, 58, 42, 21, 26, 26, 26, 26, 33, 26, + 37, 61, 40, 60, 26, 26, 26, 63, 33, 42, + 35, 51, 42, 64, 52, 26, 35, 26, 53, 54, + 35, 59, 62, 26, 27, 27, 27, 27, 57, 27, + 67, 58, 65, 71, 27, 27, 27, 60, 72, 73, + 61, 74, 63, 67, 67, 27, 76, 27, 77, 78, + 81, 64, 82, 27, 67, 80, 80, 80, 84, 80, + 71, 83, 62, 89, 65, 85, 91, 94, 73, 90, + + 90, 90, 0, 90, 0, 98, 74, 72, 85, 85, + 102, 100, 78, 0, 0, 76, 77, 81, 82, 85, + 83, 0, 89, 0, 0, 0, 94, 84, 88, 92, + 92, 92, 98, 92, 102, 91, 93, 93, 93, 106, + 93, 88, 88, 88, 108, 95, 95, 95, 88, 95, + 100, 113, 88, 88, 88, 88, 88, 88, 88, 99, + 99, 99, 0, 99, 101, 101, 101, 0, 101, 0, + 0, 0, 106, 108, 111, 111, 111, 0, 111, 0, + 113, 115, 115, 115, 0, 115, 119, 119, 119, 0, + 119, 120, 120, 120, 0, 120, 122, 122, 122, 0, + + 122, 132, 0, 0, 0, 0, 132, 132, 132, 133, + 133, 0, 133, 133, 133, 133, 133, 134, 134, 134, + 0, 134, 134, 134, 134, 135, 135, 135, 136, 136, + 137, 137, 138, 138, 139, 139, 140, 140, 141, 141, + 142, 142, 143, 143, 144, 144, 145, 145, 146, 146, + 147, 147, 131, 131, 131, 131, 131, 131, 131, 131, + 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, + 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, + 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, + 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, + + 131, 131, 131 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "src/mush.l" +#line 2 "src/mush.l" + +/* + * DO NOT MODIFY THE CONTENTS OF THIS FILE. + * IT WILL BE REPLACED DURING GRADING + */ + +#include + +#include "mush.h" +#include "mush.tab.h" + +extern YYSTYPE yylval; + +void push_input(FILE *in) { + yypush_buffer_state(yy_create_buffer(in, YY_BUF_SIZE)); +} + +int pop_input(void) { + if(yy_buffer_stack_top <= 0) { + return -1; + } else { + yypop_buffer_state(); + return 0; + } +} + +int input_depth(void) { + return yy_buffer_stack_top; +} + +#line 609 "src/mush.lex.c" +#line 610 "src/mush.lex.c" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals ( void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy ( void ); + +int yyget_debug ( void ); + +void yyset_debug ( int debug_flag ); + +YY_EXTRA_TYPE yyget_extra ( void ); + +void yyset_extra ( YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in ( void ); + +void yyset_in ( FILE * _in_str ); + +FILE *yyget_out ( void ); + +void yyset_out ( FILE * _out_str ); + + int yyget_leng ( void ); + +char *yyget_text ( void ); + +int yyget_lineno ( void ); + +void yyset_lineno ( int _line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap ( void ); +#else +extern int yywrap ( void ); +#endif +#endif + +#ifndef YY_NO_UNPUT + + static void yyunput ( int c, char *buf_ptr ); + +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy ( char *, const char *, int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen ( const char * ); +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus +static int yyinput ( void ); +#else +static int input ( void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + int n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK /*LINTED*/break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + { +#line 34 "src/mush.l" + +#line 829 "src/mush.lex.c" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 132 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 353 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 35 "src/mush.l" +{ } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 36 "src/mush.l" +{ } + YY_BREAK +case 3: +/* rule 3 can match eol */ +YY_RULE_SETUP +#line 37 "src/mush.l" +{ return EOL; } + YY_BREAK +case 4: +/* rule 4 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 4); +(yy_c_buf_p) = yy_cp = yy_bp + 4; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 38 "src/mush.l" +{ return LIST; } + YY_BREAK +case 5: +/* rule 5 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 6); +(yy_c_buf_p) = yy_cp = yy_bp + 6; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 39 "src/mush.l" +{ return DELETE; } + YY_BREAK +case 6: +/* rule 6 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 3); +(yy_c_buf_p) = yy_cp = yy_bp + 3; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 40 "src/mush.l" +{ return RUN; } + YY_BREAK +case 7: +/* rule 7 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 4); +(yy_c_buf_p) = yy_cp = yy_bp + 4; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 41 "src/mush.l" +{ return CONT; } + YY_BREAK +case 8: +/* rule 8 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 4); +(yy_c_buf_p) = yy_cp = yy_bp + 4; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 42 "src/mush.l" +{ return STOP; } + YY_BREAK +case 9: +/* rule 9 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 4); +(yy_c_buf_p) = yy_cp = yy_bp + 4; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 43 "src/mush.l" +{ return WAIT; } + YY_BREAK +case 10: +/* rule 10 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 4); +(yy_c_buf_p) = yy_cp = yy_bp + 4; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 44 "src/mush.l" +{ return POLL; } + YY_BREAK +case 11: +/* rule 11 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 6); +(yy_c_buf_p) = yy_cp = yy_bp + 6; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 45 "src/mush.l" +{ return CANCEL; } + YY_BREAK +case 12: +/* rule 12 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 5); +(yy_c_buf_p) = yy_cp = yy_bp + 5; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 46 "src/mush.l" +{ return PAUSE; } + YY_BREAK +case 13: +/* rule 13 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 3); +(yy_c_buf_p) = yy_cp = yy_bp + 3; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 47 "src/mush.l" +{ return SET; } + YY_BREAK +case 14: +/* rule 14 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 5); +(yy_c_buf_p) = yy_cp = yy_bp + 5; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 48 "src/mush.l" +{ return UNSET; } + YY_BREAK +case 15: +/* rule 15 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 2); +(yy_c_buf_p) = yy_cp = yy_bp + 2; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 49 "src/mush.l" +{ return IF; } + YY_BREAK +case 16: +/* rule 16 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 4); +(yy_c_buf_p) = yy_cp = yy_bp + 4; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 50 "src/mush.l" +{ return GOTO; } + YY_BREAK +case 17: +/* rule 17 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_bp + 6); +(yy_c_buf_p) = yy_cp = yy_bp + 6; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 51 "src/mush.l" +{ return SOURCE; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 52 "src/mush.l" +{ return CAPTURE; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 53 "src/mush.l" +{ return BG; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 54 "src/mush.l" +{ return EQ; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 55 "src/mush.l" +{ return PIPE; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 56 "src/mush.l" +{ return LESS; } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 57 "src/mush.l" +{ return GREATER; } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 58 "src/mush.l" +{ return NOT; } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 59 "src/mush.l" +{ return LPAREN; } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 60 "src/mush.l" +{ return RPAREN; } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 61 "src/mush.l" +{ return COMMA; } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 62 "src/mush.l" +{ return SHARP; } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 63 "src/mush.l" +{ return DOLLAR; } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 64 "src/mush.l" +{ return PLUS; } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 65 "src/mush.l" +{ return MINUS; } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 66 "src/mush.l" +{ return TIMES; } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 67 "src/mush.l" +{ return DIVIDE; } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 68 "src/mush.l" +{ return MOD; } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 69 "src/mush.l" +{ return EQUAL; } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 70 "src/mush.l" +{ return LESSEQ; } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 71 "src/mush.l" +{ return GREATEQ; } + YY_BREAK +case 38: +YY_RULE_SETUP +#line 72 "src/mush.l" +{ return AND; } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 73 "src/mush.l" +{ return OR; } + YY_BREAK +case 40: +/* rule 40 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_cp - 1); +(yy_c_buf_p) = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 74 "src/mush.l" +{ + yylval.string = strdup(yytext); + return NUMBER; +} + YY_BREAK +case 41: +/* rule 41 can match eol */ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +YY_LINENO_REWIND_TO(yy_cp - 1); +(yy_c_buf_p) = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +#line 78 "src/mush.l" +{ + yylval.string = strdup(yytext); + return NAME; +} + YY_BREAK +case 42: +YY_RULE_SETUP +#line 82 "src/mush.l" +{ + yylval.string = strdup(yytext); + return WORD; +} + YY_BREAK +case 43: +YY_RULE_SETUP +#line 86 "src/mush.l" +{ /* From Flex manual: A.4.3 Quoted Constructs */ + int n = strlen(yytext); + yytext[n-1] = '\0'; // Kill ending quotation + yylval.string = strdup(yytext+1); + return STRING; +} + YY_BREAK +case YY_STATE_EOF(INITIAL): +#line 92 "src/mush.l" +{ + if(!input_depth()) + return EoF; + pop_input(); + return EOL; +} + YY_BREAK +case 44: +YY_RULE_SETUP +#line 98 "src/mush.l" +{ return UNKNOWN; } + YY_BREAK +case 45: +YY_RULE_SETUP +#line 99 "src/mush.l" +ECHO; + YY_BREAK +#line 1215 "src/mush.lex.c" + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc( (void *) b->yy_ch_buf, + (yy_size_t) (b->yy_buf_size + 2) ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + /* "- 2" to take care of EOB's */ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + yy_state_type yy_current_state; + char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 132 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 132 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 131); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_UNPUT + + static void yyunput (int c, char * yy_bp ) +{ + char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + int number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return 0; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer( yyin, YY_BUF_SIZE ); + } + + yy_init_buffer( YY_CURRENT_BUFFER, input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree( (void *) b->yy_ch_buf ); + + yyfree( (void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return NULL; + + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = NULL; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (const char * yystr ) +{ + + return yy_scan_bytes( yystr, (int) strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = (yy_size_t) (_yybytes_len + 2); + buf = (char *) yyalloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yynoreturn yy_fatal_error (const char* msg ) +{ + fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param _line_number line number + * + */ +void yyset_lineno (int _line_number ) +{ + + yylineno = _line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param _in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * _in_str ) +{ + yyin = _in_str ; +} + +void yyset_out (FILE * _out_str ) +{ + yyout = _out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int _bdebug ) +{ + yy_flex_debug = _bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = NULL; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = NULL; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = NULL; + yyout = NULL; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer( YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, const char * s2, int n ) +{ + + int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (const char * s ) +{ + int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return malloc(size); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return realloc(ptr, size); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 99 "src/mush.l" + + diff --git a/hw4/src/mush.tab.c b/hw4/src/mush.tab.c new file mode 100644 index 0000000..abb5c3b --- /dev/null +++ b/hw4/src/mush.tab.c @@ -0,0 +1,2418 @@ +/* A Bison parser, made by GNU Bison 3.5.1. */ + +/* Bison implementation for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, + Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Undocumented macros, especially those whose name start with YY_, + are private implementation details. Do not rely on them. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "3.5.1" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + + + + +/* First part of user prologue. */ +#line 1 "src/mush.y" + + +/* + * DO NOT MODIFY THE CONTENTS OF THIS FILE. + * IT WILL BE REPLACED DURING GRADING + */ + +#include +#include +#include + +#include "mush.h" +#include "mush.tab.h" + +STMT *mush_parsed_stmt; + +int yylex(); +int yyparse(); + +void yyerror(const char *str) { + fprintf(stderr, "error: %s\n", str); +} + +int yywrap() { + return 1; +} + + +#line 99 "src/mush.tab.c" + +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif +# ifndef YY_NULLPTR +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# else +# define YY_NULLPTR ((void*)0) +# endif +# endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +/* Use api.header.include to #include this header + instead of duplicating it here. */ +#ifndef YY_YY_INCLUDE_MUSH_TAB_H_INCLUDED +# define YY_YY_INCLUDE_MUSH_TAB_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token type. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + NUMBER = 258, + NAME = 259, + WORD = 260, + STRING = 261, + LIST = 262, + DELETE = 263, + RUN = 264, + CONT = 265, + STOP = 266, + BG = 267, + CAPTURE = 268, + WAIT = 269, + POLL = 270, + CANCEL = 271, + PAUSE = 272, + SET = 273, + UNSET = 274, + IF = 275, + GOTO = 276, + SOURCE = 277, + EQ = 278, + PIPE = 279, + LESS = 280, + GREATER = 281, + EQUAL = 282, + LESSEQ = 283, + GREATEQ = 284, + AND = 285, + OR = 286, + NOT = 287, + LPAREN = 288, + RPAREN = 289, + PLUS = 290, + MINUS = 291, + TIMES = 292, + DIVIDE = 293, + MOD = 294, + COMMA = 295, + SHARP = 296, + DOLLAR = 297, + EOL = 298, + EoF = 299, + UNKNOWN = 300 + }; +#endif + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +union YYSTYPE +{ +#line 30 "src/mush.y" + + int number; + char *string; + STMT *stmt; + EXPR *expr; + ARG *args; + COMMAND *cmds; + PIPELINE *pline; + +#line 207 "src/mush.tab.c" + +}; +typedef union YYSTYPE YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + +int yyparse (void); + +#endif /* !YY_YY_INCLUDE_MUSH_TAB_H_INCLUDED */ + + + +#ifdef short +# undef short +#endif + +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif +#endif + +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; +#endif + +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; +#else +typedef short yytype_int16; +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned +# endif +#endif + +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + +/* Stored state numbers (used for stacks). */ +typedef yytype_int8 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(E) ((void) (E)) +#else +# define YYUSE(E) /* empty */ +#endif + +#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_INITIAL_VALUE(Value) Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + + +#define YY_ASSERT(E) ((void) (0 && (E))) + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS +# include /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yy_state_t yyss_alloc; + YYSTYPE yyvs_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +# define YYCOPY_NEEDED 1 + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYPTRDIFF_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ + } \ + while (0) + +#endif + +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYPTRDIFF_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 18 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 247 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 46 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 16 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 60 +/* YYNSTATES -- Number of states. */ +#define YYNSTATES 114 + +#define YYUNDEFTOK 2 +#define YYMAXUTOK 300 + + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ +static const yytype_int8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45 +}; + +#if YYDEBUG + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_int16 yyrline[] = +{ + 0, 95, 95, 102, 111, 118, 125, 133, 142, 151, + 160, 169, 178, 186, 195, 205, 214, 224, 233, 239, + 243, 251, 256, 261, 266, 273, 277, 284, 291, 296, + 304, 310, 317, 324, 331, 336, 340, 349, 358, 367, + 376, 385, 394, 403, 411, 420, 429, 438, 447, 458, + 462, 466, 467, 477, 480, 483, 484, 485, 486, 489, + 490 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || 1 +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "NUMBER", "NAME", "WORD", "STRING", + "LIST", "DELETE", "RUN", "CONT", "STOP", "BG", "CAPTURE", "WAIT", "POLL", + "CANCEL", "PAUSE", "SET", "UNSET", "IF", "GOTO", "SOURCE", "EQ", "PIPE", + "LESS", "GREATER", "EQUAL", "LESSEQ", "GREATEQ", "AND", "OR", "NOT", + "LPAREN", "RPAREN", "PLUS", "MINUS", "TIMES", "DIVIDE", "MOD", "COMMA", + "SHARP", "DOLLAR", "EOL", "EoF", "UNKNOWN", "$accept", "statement", + "pipeline", "command_list", "command", "arg_list", "arg", "atomic_expr", + "expr", "numeric_var", "string_var", "optional_lineno", "lineno", + "literal_number", "literal_string", "file", YY_NULLPTR +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[NUM] -- (External) token number corresponding to the + (internal) symbol number NUM (which must be that of a token). */ +static const yytype_int16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300 +}; +# endif + +#define YYPACT_NINF (-53) + +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) + +#define YYTABLE_NINF (-52) + +#define yytable_value_is_error(Yyn) \ + 0 + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int16 yypact[] = +{ + 61, -30, -53, -28, 21, -18, -16, -53, -53, 28, + 92, 18, -53, -53, -53, -10, -53, -53, -53, -53, + -53, -53, -53, 85, 85, 85, -12, 31, 32, 85, + 21, 4, 85, 33, 34, -9, -53, 8, -53, 116, + -53, -53, -53, -53, -3, 21, 85, -53, 117, 136, + 155, -53, 16, -1, 174, 0, -53, -53, 2, 208, + -53, -53, 3, 4, 1, -53, 116, -53, -53, 29, + -7, 85, 85, 85, 85, 85, 85, 85, 85, 85, + 85, 85, 85, -53, -53, -53, 85, -53, 21, -53, + -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, + -53, -53, -53, -7, -7, 110, 110, 110, 110, 110, + 189, 30, -53, -53 +}; + + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_int8 yydefact[] = +{ + 0, 0, 54, 0, 0, 0, 0, 18, 19, 0, + 0, 52, 53, 20, 2, 0, 4, 5, 1, 55, + 56, 57, 58, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 21, 25, 27, 28, + 30, 32, 33, 31, 0, 0, 0, 35, 0, 0, + 0, 12, 0, 0, 0, 0, 59, 60, 0, 0, + 49, 50, 0, 0, 0, 7, 0, 29, 6, 0, + 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 9, 10, 11, 0, 15, 0, 13, + 17, 34, 8, 22, 24, 23, 26, 3, 37, 38, + 36, 39, 40, 41, 42, 44, 45, 46, 47, 48, + 0, 0, 14, 16 +}; + + /* YYPGOTO[NTERM-NUM]. */ +static const yytype_int8 yypgoto[] = +{ + -53, -53, -53, -22, -53, 22, -53, -6, -23, -53, + -53, -53, -4, -53, -53, -52 +}; + + /* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = +{ + -1, 9, 35, 36, 37, 38, 39, 47, 48, 41, + 42, 10, 11, 12, 43, 58 +}; + + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int8 yytable[] = +{ + 15, 49, 50, 62, 40, 56, 54, 57, 56, 59, + 57, 93, 95, 13, 94, 14, 63, 64, 71, 72, + 73, 74, 75, 70, 2, 16, 55, 17, 18, 44, + 45, 51, 66, 40, 65, 52, 53, 60, 61, 86, + 68, 69, 87, 89, 96, 90, 92, 0, 98, 99, + 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 40, 67, 1, 110, 2, -51, -51, -51, 3, 4, + 5, 6, 97, 113, 0, -51, -51, -51, -51, -51, + -51, -51, -51, -51, 111, 0, 0, 0, 19, 20, + 21, 22, 0, 0, -51, 19, 20, 21, 22, 0, + 0, 0, -51, -51, 7, 8, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 0, 0, 46, 32, 19, + 20, 21, 22, 0, 0, 32, 33, 34, 0, 0, + 0, 0, 0, 33, 34, 71, 72, 73, 74, 75, + 76, 77, 71, 72, 73, 74, 75, 76, 77, 32, + 0, 0, 78, 79, 80, 81, 82, 33, 34, 0, + 83, 71, 72, 73, 74, 75, 76, 77, 0, 0, + 0, 78, 79, 80, 81, 82, 0, 0, 0, 84, + 71, 72, 73, 74, 75, 76, 77, 0, 0, 0, + 78, 79, 80, 81, 82, 88, 0, 0, 85, 71, + 72, 73, 74, 75, 76, 77, 0, 0, 0, 78, + 79, 80, 81, 82, 71, 72, 73, 74, 75, 76, + 77, 0, 0, 0, 78, 79, 80, 81, 82, 0, + 0, 0, 112, 71, 72, 73, 74, 75, 76, 77, + 0, 0, 91, 78, 79, 80, 81, 82 +}; + +static const yytype_int8 yycheck[] = +{ + 4, 24, 25, 12, 10, 4, 29, 6, 4, 32, + 6, 63, 64, 43, 13, 43, 25, 26, 25, 26, + 27, 28, 29, 46, 3, 43, 30, 43, 0, 11, + 40, 43, 24, 39, 43, 4, 4, 4, 4, 23, + 43, 45, 43, 43, 66, 43, 43, -1, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, + 66, 39, 1, 86, 3, 4, 5, 6, 7, 8, + 9, 10, 43, 43, -1, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 88, -1, -1, -1, 3, 4, + 5, 6, -1, -1, 33, 3, 4, 5, 6, -1, + -1, -1, 41, 42, 43, 44, 14, 15, 16, 17, + 18, 19, 20, 21, 22, -1, -1, 32, 33, 3, + 4, 5, 6, -1, -1, 33, 41, 42, -1, -1, + -1, -1, -1, 41, 42, 25, 26, 27, 28, 29, + 30, 31, 25, 26, 27, 28, 29, 30, 31, 33, + -1, -1, 35, 36, 37, 38, 39, 41, 42, -1, + 43, 25, 26, 27, 28, 29, 30, 31, -1, -1, + -1, 35, 36, 37, 38, 39, -1, -1, -1, 43, + 25, 26, 27, 28, 29, 30, 31, -1, -1, -1, + 35, 36, 37, 38, 39, 21, -1, -1, 43, 25, + 26, 27, 28, 29, 30, 31, -1, -1, -1, 35, + 36, 37, 38, 39, 25, 26, 27, 28, 29, 30, + 31, -1, -1, -1, 35, 36, 37, 38, 39, -1, + -1, -1, 43, 25, 26, 27, 28, 29, 30, 31, + -1, -1, 34, 35, 36, 37, 38, 39 +}; + + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_int8 yystos[] = +{ + 0, 1, 3, 7, 8, 9, 10, 43, 44, 47, + 57, 58, 59, 43, 43, 58, 43, 43, 0, 3, + 4, 5, 6, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 33, 41, 42, 48, 49, 50, 51, 52, + 53, 55, 56, 60, 11, 40, 32, 53, 54, 54, + 54, 43, 4, 4, 54, 58, 4, 6, 61, 54, + 4, 4, 12, 25, 26, 43, 24, 51, 43, 58, + 54, 25, 26, 27, 28, 29, 30, 31, 35, 36, + 37, 38, 39, 43, 43, 43, 23, 43, 21, 43, + 43, 34, 43, 61, 13, 61, 49, 43, 54, 54, + 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, + 54, 58, 43, 43 +}; + + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_int8 yyr1[] = +{ + 0, 46, 47, 47, 47, 47, 47, 47, 47, 47, + 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, + 47, 48, 48, 48, 48, 49, 49, 50, 51, 51, + 52, 53, 53, 53, 53, 54, 54, 54, 54, 54, + 54, 54, 54, 54, 54, 54, 54, 54, 54, 55, + 56, 57, 57, 58, 59, 60, 60, 60, 60, 61, + 61 +}; + + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_int8 yyr2[] = +{ + 0, 2, 2, 5, 2, 2, 3, 3, 4, 4, + 4, 4, 3, 4, 6, 4, 6, 4, 1, 1, + 2, 1, 3, 3, 3, 1, 3, 1, 1, 2, + 1, 1, 1, 1, 3, 1, 3, 3, 3, 3, + 3, 3, 3, 2, 3, 3, 3, 3, 3, 2, + 2, 0, 1, 1, 1, 1, 1, 1, 1, 1, + 1 +}; + + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) + +/* Error token number */ +#define YYTERROR 1 +#define YYERRCODE 256 + + + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +/* This macro is provided for backward compatibility. */ +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif + + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + + +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ + +static void +yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) +{ + FILE *yyoutput = yyo; + YYUSE (yyoutput); + if (!yyvaluep) + return; +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyo, yytoknum[yytype], *yyvaluep); +# endif + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ + +static void +yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) +{ + YYFPRINTF (yyo, "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + + yy_symbol_value_print (yyo, yytype, yyvaluep); + YYFPRINTF (yyo, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +static void +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +static void +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule) +{ + int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; + int yyi; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + yystos[+yyssp[yyi + 1 - yynrhs]], + &yyvsp[(yyi + 1) - (yynrhs)] + ); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) +# else +/* Return the length of YYSTR. */ +static YYPTRDIFF_T +yystrlen (const char *yystr) +{ + YYPTRDIFF_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +yystpcpy (char *yydest, const char *yysrc) +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYPTRDIFF_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYPTRDIFF_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (yyres) + return yystpcpy (yyres, yystr) - yyres; + else + return yystrlen (yystr); +} +# endif + +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, + yy_state_t *yyssp, int yytoken) +{ + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat: reported tokens (one for the "unexpected", + one per "expected"). */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Actual size of YYARG. */ + int yycount = 0; + /* Cumulated lengths of YYARG. */ + YYPTRDIFF_T yysize = 0; + + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[+*yyssp]; + YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + yysize = yysize0; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYPTRDIFF_T yysize1 + = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else + return 2; + } + } + } + } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + default: /* Avoid compiler warnings. */ + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + { + /* Don't count the "%s"s in the final size, but reserve room for + the terminator. */ + YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1; + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else + return 2; + } + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + ++yyp; + ++yyformat; + } + } + return 0; +} +#endif /* YYERROR_VERBOSE */ + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +{ + YYUSE (yyvaluep); + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + switch (yytype) + { + case 3: /* NUMBER */ +#line 75 "src/mush.y" + { free(((*yyvaluep).string)); } +#line 1226 "src/mush.tab.c" + break; + + case 4: /* NAME */ +#line 76 "src/mush.y" + { free(((*yyvaluep).string)); } +#line 1232 "src/mush.tab.c" + break; + + case 5: /* WORD */ +#line 77 "src/mush.y" + { free(((*yyvaluep).string)); } +#line 1238 "src/mush.tab.c" + break; + + case 6: /* STRING */ +#line 78 "src/mush.y" + { free(((*yyvaluep).string)); } +#line 1244 "src/mush.tab.c" + break; + + case 47: /* statement */ +#line 80 "src/mush.y" + { free_stmt(((*yyvaluep).stmt)); } +#line 1250 "src/mush.tab.c" + break; + + case 48: /* pipeline */ +#line 86 "src/mush.y" + { free_pipeline(((*yyvaluep).pline)); } +#line 1256 "src/mush.tab.c" + break; + + case 49: /* command_list */ +#line 83 "src/mush.y" + { free_commands(((*yyvaluep).cmds)); } +#line 1262 "src/mush.tab.c" + break; + + case 50: /* command */ +#line 82 "src/mush.y" + { free_commands(((*yyvaluep).cmds)); } +#line 1268 "src/mush.tab.c" + break; + + case 51: /* arg_list */ +#line 85 "src/mush.y" + { free_args(((*yyvaluep).args)); } +#line 1274 "src/mush.tab.c" + break; + + case 52: /* arg */ +#line 84 "src/mush.y" + { free(((*yyvaluep).expr)); } +#line 1280 "src/mush.tab.c" + break; + + case 54: /* expr */ +#line 81 "src/mush.y" + { free_expr(((*yyvaluep).expr)); } +#line 1286 "src/mush.tab.c" + break; + + case 55: /* numeric_var */ +#line 89 "src/mush.y" + { free(((*yyvaluep).string)); } +#line 1292 "src/mush.tab.c" + break; + + case 56: /* string_var */ +#line 90 "src/mush.y" + { free(((*yyvaluep).string)); } +#line 1298 "src/mush.tab.c" + break; + + case 60: /* literal_string */ +#line 88 "src/mush.y" + { free(((*yyvaluep).string)); } +#line 1304 "src/mush.tab.c" + break; + + case 61: /* file */ +#line 87 "src/mush.y" + { free(((*yyvaluep).string)); } +#line 1310 "src/mush.tab.c" + break; + + default: + break; + } + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + + + +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; +/* Number of syntax errors so far. */ +int yynerrs; + + +/*----------. +| yyparse. | +`----------*/ + +int +yyparse (void) +{ + yy_state_fast_t yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. + + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss; + yy_state_t *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYPTRDIFF_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + goto yysetstate; + + +/*------------------------------------------------------------. +| yynewstate -- push a new state, which is found in yystate. | +`------------------------------------------------------------*/ +yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + +/*--------------------------------------------------------------------. +| yysetstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + + if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + goto yyexhaustedlab; +#else + { + /* Get the current used size of the three stacks, in elements. */ + YYPTRDIFF_T yysize = yyssp - yyss + 1; + +# if defined yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yystacksize); + yyss = yyss1; + yyvs = yyvs1; + } +# else /* defined YYSTACK_RELOCATE */ + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yy_state_t *yyss1 = yyss; + union yyalloc *yyptr = + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = yylex (); + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + /* Discard the shifted token. */ + yychar = YYEMPTY; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 2: +#line 96 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = LIST_STMT_CLASS; + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1585 "src/mush.tab.c" + break; + + case 3: +#line 103 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = DELETE_STMT_CLASS; + (yyval.stmt)->members.delete_stmt.from = (yyvsp[-3].number); + (yyval.stmt)->members.delete_stmt.to = (yyvsp[-1].number); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1598 "src/mush.tab.c" + break; + + case 4: +#line 112 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = RUN_STMT_CLASS; + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1609 "src/mush.tab.c" + break; + + case 5: +#line 119 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = CONT_STMT_CLASS; + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1620 "src/mush.tab.c" + break; + + case 6: +#line 126 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = STOP_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-2].number); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1632 "src/mush.tab.c" + break; + + case 7: +#line 134 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = FG_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-2].number); + (yyval.stmt)->members.sys_stmt.pipeline = (yyvsp[-1].pline); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1645 "src/mush.tab.c" + break; + + case 8: +#line 143 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = BG_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-3].number); + (yyval.stmt)->members.sys_stmt.pipeline = (yyvsp[-2].pline); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1658 "src/mush.tab.c" + break; + + case 9: +#line 152 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = WAIT_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-3].number); + (yyval.stmt)->members.jobctl_stmt.expr = (yyvsp[-1].expr); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1671 "src/mush.tab.c" + break; + + case 10: +#line 161 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = POLL_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-3].number); + (yyval.stmt)->members.jobctl_stmt.expr = (yyvsp[-1].expr); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1684 "src/mush.tab.c" + break; + + case 11: +#line 170 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = CANCEL_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-3].number); + (yyval.stmt)->members.jobctl_stmt.expr = (yyvsp[-1].expr); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1697 "src/mush.tab.c" + break; + + case 12: +#line 179 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = PAUSE_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-2].number); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1709 "src/mush.tab.c" + break; + + case 13: +#line 187 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = GOTO_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-3].number); + (yyval.stmt)->members.goto_stmt.lineno = (yyvsp[-1].number); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1722 "src/mush.tab.c" + break; + + case 14: +#line 196 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = SET_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-5].number); + (yyval.stmt)->members.set_stmt.name = (yyvsp[-3].string); + (yyval.stmt)->members.set_stmt.expr = (yyvsp[-1].expr); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1736 "src/mush.tab.c" + break; + + case 15: +#line 206 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = UNSET_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-3].number); + (yyval.stmt)->members.unset_stmt.name = (yyvsp[-1].string); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1749 "src/mush.tab.c" + break; + + case 16: +#line 215 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = IF_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-5].number); + (yyval.stmt)->members.if_stmt.expr = (yyvsp[-3].expr); + (yyval.stmt)->members.if_stmt.lineno = (yyvsp[-1].number); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1763 "src/mush.tab.c" + break; + + case 17: +#line 225 "src/mush.y" + { + (yyval.stmt) = calloc(1, sizeof(STMT)); + (yyval.stmt)->class = SOURCE_STMT_CLASS; + (yyval.stmt)->lineno = (yyvsp[-3].number); + (yyval.stmt)->members.source_stmt.file = (yyvsp[-1].string); + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1776 "src/mush.tab.c" + break; + + case 18: +#line 234 "src/mush.y" + { + (yyval.stmt) = NULL; + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1786 "src/mush.tab.c" + break; + + case 19: +#line 240 "src/mush.y" + { + YYABORT; + } +#line 1794 "src/mush.tab.c" + break; + + case 20: +#line 244 "src/mush.y" + { + (yyval.stmt) = NULL; + mush_parsed_stmt = (yyval.stmt); + YYACCEPT; + } +#line 1804 "src/mush.tab.c" + break; + + case 21: +#line 252 "src/mush.y" + { + (yyval.pline) = calloc(1, sizeof(PIPELINE)); + (yyval.pline)->commands = (yyvsp[0].cmds); + } +#line 1813 "src/mush.tab.c" + break; + + case 22: +#line 257 "src/mush.y" + { + (yyval.pline) = (yyvsp[-2].pline); + (yyval.pline)->input_file = (yyvsp[0].string); + } +#line 1822 "src/mush.tab.c" + break; + + case 23: +#line 262 "src/mush.y" + { + (yyval.pline) = (yyvsp[-2].pline); + (yyval.pline)->output_file = (yyvsp[0].string); + } +#line 1831 "src/mush.tab.c" + break; + + case 24: +#line 267 "src/mush.y" + { + (yyval.pline) = (yyvsp[-2].pline); + (yyval.pline)->capture_output = 1; + } +#line 1840 "src/mush.tab.c" + break; + + case 25: +#line 274 "src/mush.y" + { + (yyval.cmds) = (yyvsp[0].cmds); + } +#line 1848 "src/mush.tab.c" + break; + + case 26: +#line 278 "src/mush.y" + { + (yyval.cmds) = (yyvsp[-2].cmds); + (yyval.cmds)->next = (yyvsp[0].cmds); + } +#line 1857 "src/mush.tab.c" + break; + + case 27: +#line 285 "src/mush.y" + { + (yyval.cmds) = calloc(1, sizeof(COMMAND)); + (yyval.cmds)->args = (yyvsp[0].args); + } +#line 1866 "src/mush.tab.c" + break; + + case 28: +#line 292 "src/mush.y" + { + (yyval.args) = calloc(1, sizeof(ARG)); + (yyval.args)->expr = (yyvsp[0].expr); + } +#line 1875 "src/mush.tab.c" + break; + + case 29: +#line 297 "src/mush.y" + { + (yyval.args) = calloc(1, sizeof(ARG)); + (yyval.args)->expr = (yyvsp[-1].expr); + (yyval.args)->next = (yyvsp[0].args); + } +#line 1885 "src/mush.tab.c" + break; + + case 30: +#line 305 "src/mush.y" + { + (yyval.expr) = (yyvsp[0].expr); + } +#line 1893 "src/mush.tab.c" + break; + + case 31: +#line 311 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = LIT_EXPR_CLASS; + (yyval.expr)->type = STRING_VALUE_TYPE; + (yyval.expr)->members.value = (yyvsp[0].string); + } +#line 1904 "src/mush.tab.c" + break; + + case 32: +#line 318 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = NUM_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.variable = (yyvsp[0].string); + } +#line 1915 "src/mush.tab.c" + break; + + case 33: +#line 325 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = STRING_EXPR_CLASS; + (yyval.expr)->type = STRING_VALUE_TYPE; + (yyval.expr)->members.variable = (yyvsp[0].string); + } +#line 1926 "src/mush.tab.c" + break; + + case 34: +#line 332 "src/mush.y" + { + (yyval.expr) = (yyvsp[-1].expr); + } +#line 1934 "src/mush.tab.c" + break; + + case 35: +#line 337 "src/mush.y" + { + (yyval.expr) = (yyvsp[0].expr); + } +#line 1942 "src/mush.tab.c" + break; + + case 36: +#line 341 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.oprtr = EQUAL_OPRTR; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 1955 "src/mush.tab.c" + break; + + case 37: +#line 350 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.oprtr = LESS_OPRTR; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 1968 "src/mush.tab.c" + break; + + case 38: +#line 359 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.oprtr = GREATER_OPRTR; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 1981 "src/mush.tab.c" + break; + + case 39: +#line 368 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.oprtr = LESSEQ_OPRTR; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 1994 "src/mush.tab.c" + break; + + case 40: +#line 377 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.oprtr = GREATEQ_OPRTR; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 2007 "src/mush.tab.c" + break; + + case 41: +#line 386 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.oprtr = AND_OPRTR; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 2020 "src/mush.tab.c" + break; + + case 42: +#line 395 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.oprtr = OR_OPRTR; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 2033 "src/mush.tab.c" + break; + + case 43: +#line 404 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = UNARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.unary_expr.oprtr = NOT_OPRTR; + (yyval.expr)->members.unary_expr.arg = (yyvsp[0].expr); + } +#line 2045 "src/mush.tab.c" + break; + + case 44: +#line 412 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.oprtr = PLUS_OPRTR; + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 2058 "src/mush.tab.c" + break; + + case 45: +#line 421 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.oprtr = MINUS_OPRTR; + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 2071 "src/mush.tab.c" + break; + + case 46: +#line 430 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.oprtr = TIMES_OPRTR; + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 2084 "src/mush.tab.c" + break; + + case 47: +#line 439 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.oprtr = DIVIDE_OPRTR; + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 2097 "src/mush.tab.c" + break; + + case 48: +#line 448 "src/mush.y" + { + (yyval.expr) = calloc(1, sizeof(EXPR)); + (yyval.expr)->class = BINARY_EXPR_CLASS; + (yyval.expr)->type = NUM_VALUE_TYPE; + (yyval.expr)->members.binary_expr.arg1 = (yyvsp[-2].expr); + (yyval.expr)->members.binary_expr.oprtr = MOD_OPRTR; + (yyval.expr)->members.binary_expr.arg2 = (yyvsp[0].expr); + } +#line 2110 "src/mush.tab.c" + break; + + case 49: +#line 459 "src/mush.y" + { (yyval.string) = (yyvsp[0].string); } +#line 2116 "src/mush.tab.c" + break; + + case 50: +#line 463 "src/mush.y" + { (yyval.string) = (yyvsp[0].string); } +#line 2122 "src/mush.tab.c" + break; + + case 51: +#line 466 "src/mush.y" + { (yyval.number) = 0; } +#line 2128 "src/mush.tab.c" + break; + + case 52: +#line 468 "src/mush.y" + { + if((yyvsp[0].number) <= 0) { + yyerror("Line number must be positive"); + YYERROR; + } + (yyval.number) = (yyvsp[0].number); + } +#line 2140 "src/mush.tab.c" + break; + + case 54: +#line 480 "src/mush.y" + { (yyval.number) = atoi((yyvsp[0].string)); free((yyvsp[0].string)); } +#line 2146 "src/mush.tab.c" + break; + + case 55: +#line 483 "src/mush.y" + { (yyval.string) = (yyvsp[0].string); } +#line 2152 "src/mush.tab.c" + break; + + case 56: +#line 484 "src/mush.y" + { (yyval.string) = (yyvsp[0].string); } +#line 2158 "src/mush.tab.c" + break; + + case 57: +#line 485 "src/mush.y" + { (yyval.string) = (yyvsp[0].string); } +#line 2164 "src/mush.tab.c" + break; + + case 58: +#line 486 "src/mush.y" + { (yyval.string) = (yyvsp[0].string); } +#line 2170 "src/mush.tab.c" + break; + + case 59: +#line 489 "src/mush.y" + { (yyval.string) = (yyvsp[0].string); } +#line 2176 "src/mush.tab.c" + break; + + case 60: +#line 490 "src/mush.y" + { (yyval.string) = (yyvsp[0].string); } +#line 2182 "src/mush.tab.c" + break; + + +#line 2186 "src/mush.tab.c" + + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + /* Now 'shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } + + goto yynewstate; + + +/*--------------------------------------. +| yyerrlab -- here on detecting error. | +`--------------------------------------*/ +yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (YY_("syntax error")); +#else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) + { + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; + } +# undef YYSYNTAX_ERROR +#endif + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; + + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + yystos[yystate], yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + + +#if !defined yyoverflow || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + + +/*-----------------------------------------------------. +| yyreturn -- parsing is finished, return the result. | +`-----------------------------------------------------*/ +yyreturn: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[+*yyssp], yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + return yyresult; +} +#line 492 "src/mush.y" + diff --git a/hw4/src/program.c b/hw4/src/program.c new file mode 100644 index 0000000..e6379b3 --- /dev/null +++ b/hw4/src/program.c @@ -0,0 +1,136 @@ +#include +#include + +#include "mush.h" +#include "debug.h" + +/* + * This is the "program store" module for Mush. + * It maintains a set of numbered statements, along with a "program counter" + * that indicates the current point of execution, which is either before all + * statements, after all statements, or in between two statements. + * There should be no fixed limit on the number of statements that the program + * store can hold. + */ + +/** + * @brief Output a listing of the current contents of the program store. + * @details This function outputs a listing of the current contents of the + * program store. Statements are listed in increasing order of their line + * number. The current position of the program counter is indicated by + * a line containing only the string "-->" at the current program counter + * position. + * + * @param out The stream to which to output the listing. + * @return 0 if successful, -1 if any error occurred. + */ +int prog_list(FILE *out) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Insert a new statement into the program store. + * @details This function inserts a new statement into the program store. + * The statement must have a line number. If the line number is the same as + * that of an existing statement, that statement is replaced. + * The program store assumes the responsibility for ultimately freeing any + * statement that is inserted using this function. + * Insertion of new statements preserves the value of the program counter: + * if the position of the program counter was just before a particular statement + * before insertion of a new statement, it will still be before that statement + * after insertion, and if the position of the program counter was after all + * statements before insertion of a new statement, then it will still be after + * all statements after insertion. + * + * @param stmt The statement to be inserted. + * @return 0 if successful, -1 if any error occurred. + */ +int prog_insert(STMT *stmt) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Delete statements from the program store. + * @details This function deletes from the program store statements whose + * line numbers fall in a specified range. Any deleted statements are freed. + * Deletion of statements preserves the value of the program counter: + * if before deletion the program counter pointed to a position just before + * a statement that was not among those to be deleted, then after deletion the + * program counter will still point the position just before that same statement. + * If before deletion the program counter pointed to a position just before + * a statement that was among those to be deleted, then after deletion the + * program counter will point to the first statement beyond those deleted, + * if such a statement exists, otherwise the program counter will point to + * the end of the program. + * + * @param min Lower end of the range of line numbers to be deleted. + * @param max Upper end of the range of line numbers to be deleted. + */ +int prog_delete(int min, int max) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Reset the program counter to the beginning of the program. + * @details This function resets the program counter to point just + * before the first statement in the program. + */ +void prog_reset(void) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Fetch the next program statement. + * @details This function fetches and returns the first program + * statement after the current program counter position. The program + * counter position is not modified. The returned pointer should not + * be used after any subsequent call to prog_delete that deletes the + * statement from the program store. + * + * @return The first program statement after the current program + * counter position, if any, otherwise NULL. + */ +STMT *prog_fetch(void) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Advance the program counter to the next existing statement. + * @details This function advances the program counter by one statement + * from its original position and returns the statement just after the + * new position. The returned pointer should not be used after any + * subsequent call to prog_delete that deletes the statement from the + * program store. + * + * @return The first program statement after the new program counter + * position, if any, otherwise NULL. + */ +STMT *prog_next() { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Perform a "go to" operation on the program store. + * @details This function performs a "go to" operation on the program + * store, by resetting the program counter to point to the position just + * before the statement with the specified line number. + * The statement pointed at by the new program counter is returned. + * If there is no statement with the specified line number, then no + * change is made to the program counter and NULL is returned. + * Any returned statement should only be regarded as valid as long + * as no calls to prog_delete are made that delete that statement from + * the program store. + * + * @return The statement having the specified line number, if such a + * statement exists, otherwise NULL. + */ +STMT *prog_goto(int lineno) { + // TO BE IMPLEMENTED + abort(); +} diff --git a/hw4/src/store.c b/hw4/src/store.c new file mode 100644 index 0000000..db9da8b --- /dev/null +++ b/hw4/src/store.c @@ -0,0 +1,102 @@ +#include +#include +#include + +/* + * This is the "data store" module for Mush. + * It maintains a mapping from variable names to values. + * The values of variables are stored as strings. + * However, the module provides functions for setting and retrieving + * the value of a variable as an integer. Setting a variable to + * an integer value causes the value of the variable to be set to + * a string representation of that integer. Retrieving the value of + * a variable as an integer is possible if the current value of the + * variable is the string representation of an integer. + */ + +/** + * @brief Get the current value of a variable as a string. + * @details This function retrieves the current value of a variable + * as a string. If the variable has no value, then NULL is returned. + * Any string returned remains "owned" by the data store module; + * the caller should not attempt to free the string or to use it + * after any subsequent call that would modify the value of the variable + * whose value was retrieved. If the caller needs to use the string for + * an indefinite period, a copy should be made immediately. + * + * @param var The variable whose value is to be retrieved. + * @return A string that is the current value of the variable, if any, + * otherwise NULL. + */ +char *store_get_string(char *var) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Get the current value of a variable as an integer. + * @details This retrieves the current value of a variable and + * attempts to interpret it as an integer. If this is possible, + * then the integer value is stored at the pointer provided by + * the caller. + * + * @param var The variable whose value is to be retrieved. + * @param valp Pointer at which the returned value is to be stored. + * @return If the specified variable has no value or the value + * cannot be interpreted as an integer, then -1 is returned, + * otherwise 0 is returned. + */ +int store_get_int(char *var, long *valp) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Set the value of a variable as a string. + * @details This function sets the current value of a specified + * variable to be a specified string. If the variable already + * has a value, then that value is replaced. If the specified + * value is NULL, then any existing value of the variable is removed + * and the variable becomes un-set. Ownership of the variable and + * the value strings is not transferred to the data store module as + * a result of this call; the data store module makes such copies of + * these strings as it may require. + * + * @param var The variable whose value is to be set. + * @param val The value to set, or NULL if the variable is to become + * un-set. + */ +int store_set_string(char *var, char *val) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Set the value of a variable as an integer. + * @details This function sets the current value of a specified + * variable to be a specified integer. If the variable already + * has a value, then that value is replaced. Ownership of the variable + * string is not transferred to the data store module as a result of + * this call; the data store module makes such copies of this string + * as it may require. + * + * @param var The variable whose value is to be set. + * @param val The value to set. + */ +int store_set_int(char *var, long val) { + // TO BE IMPLEMENTED + abort(); +} + +/** + * @brief Print the current contents of the data store. + * @details This function prints the current contents of the data store + * to the specified output stream. The format is not specified; this + * function is intended to be used for debugging purposes. + * + * @param f The stream to which the store contents are to be printed. + */ +void store_show(FILE *f) { + // TO BE IMPLEMENTED + abort(); +} diff --git a/hw4/src/syntax.c b/hw4/src/syntax.c new file mode 100644 index 0000000..7fa7ab8 --- /dev/null +++ b/hw4/src/syntax.c @@ -0,0 +1,357 @@ +/* + * DO NOT MODIFY THE CONTENTS OF THIS FILE. + * IT WILL BE REPLACED DURING GRADING + */ + +#include +#include +#include + +#include "syntax.h" + +/* + * Mush: Functions for manipulating syntax trees. + */ + +void show_stmt(FILE *file, STMT *stmt) { + show_lineno(file, stmt->lineno); + switch(stmt->class) { + case LIST_STMT_CLASS: + fprintf(file, "list"); + break; + case DELETE_STMT_CLASS: + fprintf(file, "delete %d, %d", + stmt->members.delete_stmt.from, + stmt->members.delete_stmt.to); + break; + case RUN_STMT_CLASS: + fprintf(file, "run"); + break; + case CONT_STMT_CLASS: + fprintf(file, "cont"); + break; + case STOP_STMT_CLASS: + fprintf(file, "stop"); + break; + case FG_STMT_CLASS: + show_pipeline(file, stmt->members.sys_stmt.pipeline); + break; + case BG_STMT_CLASS: + show_pipeline(file, stmt->members.sys_stmt.pipeline); + fprintf(file, "& "); + break; + case WAIT_STMT_CLASS: + fprintf(file, "wait "); + show_expr(file, stmt->members.jobctl_stmt.expr, 0); + break; + case POLL_STMT_CLASS: + fprintf(file, "poll "); + show_expr(file, stmt->members.jobctl_stmt.expr, 0); + break; + case CANCEL_STMT_CLASS: + fprintf(file, "cancel "); + show_expr(file, stmt->members.jobctl_stmt.expr, 0); + break; + case PAUSE_STMT_CLASS: + fprintf(file, "pause"); + break; + case SET_STMT_CLASS: + fprintf(file, "set "); + fprintf(file, "%s = ", stmt->members.set_stmt.name); + show_expr(file, stmt->members.set_stmt.expr, 0); + break; + case UNSET_STMT_CLASS: + fprintf(file, "unset "); + fprintf(file, "%s", stmt->members.unset_stmt.name); + break; + case IF_STMT_CLASS: + fprintf(file, "if "); + show_expr(file, stmt->members.if_stmt.expr, 0); + fprintf(file, " goto %d", stmt->members.if_stmt.lineno); + break; + case GOTO_STMT_CLASS: + fprintf(file, "goto %d", stmt->members.goto_stmt.lineno); + break; + case SOURCE_STMT_CLASS: + fprintf(file, "source %s", stmt->members.source_stmt.file); + break; + default: + fprintf(stderr, "Unknown statement class: %d\n", stmt->class); + abort(); + } + fprintf(file, "\n"); +} + +void show_pipeline(FILE *file, PIPELINE *pline) { + COMMAND *cmds = pline->commands; + while(cmds) { + show_command(file, cmds); + if(cmds->next) + fprintf(file, " | "); + cmds = cmds->next; + } + if(pline->input_file) + fprintf(file, " < %s", pline->input_file); + if(pline->capture_output) + fprintf(file, " >@"); + if(pline->output_file) + fprintf(file, " > %s", pline->output_file); +} + +void show_command(FILE *file, COMMAND *cmd) { + ARG *arg = cmd->args; + while(arg) { + show_expr(file, arg->expr, 0); + if(arg->next) + fprintf(file, " "); + arg = arg->next; + } +} + +void show_expr(FILE *file, EXPR *expr, int parens) { + switch(expr->class) { + case LIT_EXPR_CLASS: + fprintf(file, "%s", expr->members.value); + break; + case NUM_EXPR_CLASS: + fprintf(file, "#%s", expr->members.variable); + break; + case STRING_EXPR_CLASS: + fprintf(file, "$%s", expr->members.variable); + break; + case UNARY_EXPR_CLASS: + if(parens) + fprintf(file, "("); + show_oprtr(file, expr->members.unary_expr.oprtr); + fprintf(file, " "); + show_expr(file, expr->members.unary_expr.arg, 1); + if(parens) + fprintf(file, ")"); + break; + case BINARY_EXPR_CLASS: + if(parens) + fprintf(file, "("); + show_expr(file, expr->members.binary_expr.arg1, 1); + fprintf(file, " "); + show_oprtr(file, expr->members.binary_expr.oprtr); + fprintf(file, " "); + show_expr(file, expr->members.binary_expr.arg2, 1); + if(parens) + fprintf(file, ")"); + break; + default: + fprintf(stderr, "Unknown expression class: %d\n", expr->class); + abort(); + } +} + +void show_oprtr(FILE *file, OPRTR oprtr) { + switch(oprtr) { + case PLUS_OPRTR: + fprintf(file, "+"); + break; + case MINUS_OPRTR: + fprintf(file, "-"); + break; + case TIMES_OPRTR: + fprintf(file, "*"); + break; + case DIVIDE_OPRTR: + fprintf(file, "/"); + break; + case MOD_OPRTR: + fprintf(file, "%s", "%"); + break; + case AND_OPRTR: + fprintf(file, "&&"); + break; + case OR_OPRTR: + fprintf(file, "||"); + break; + case NOT_OPRTR: + fprintf(file, "!"); + break; + case EQUAL_OPRTR: + fprintf(file, "=="); + break; + case LESS_OPRTR: + fprintf(file, "<"); + break; + case GREATER_OPRTR: + fprintf(file, ">"); + break; + case LESSEQ_OPRTR: + fprintf(file, "<="); + break; + case GREATEQ_OPRTR: + fprintf(file, ">="); + break; + default: + fprintf(stderr, "Unknown operator: %d\n", oprtr); + abort(); + } +} + +void show_lineno(FILE *file, int lineno) { + if(lineno) + fprintf(file, "%7d\t", lineno); + else + fprintf(file, "\t"); +} + +void free_stmt(STMT *stmt) { + if(stmt == NULL) // Produced by error recovery production + return; + switch(stmt->class) { + case LIST_STMT_CLASS: + case DELETE_STMT_CLASS: + case RUN_STMT_CLASS: + case CONT_STMT_CLASS: + case STOP_STMT_CLASS: + break; + case FG_STMT_CLASS: + free_pipeline(stmt->members.sys_stmt.pipeline); + break; + case BG_STMT_CLASS: + free_pipeline(stmt->members.sys_stmt.pipeline); + break; + case GOTO_STMT_CLASS: + break; + case WAIT_STMT_CLASS: + case POLL_STMT_CLASS: + case CANCEL_STMT_CLASS: + free_expr(stmt->members.jobctl_stmt.expr); + break; + case SET_STMT_CLASS: + free(stmt->members.set_stmt.name); + free_expr(stmt->members.set_stmt.expr); + break; + case UNSET_STMT_CLASS: + free(stmt->members.unset_stmt.name); + break; + case IF_STMT_CLASS: + free_expr(stmt->members.if_stmt.expr); + break; + case SOURCE_STMT_CLASS: + free(stmt->members.source_stmt.file); + break; + case PAUSE_STMT_CLASS: + break; + default: + fprintf(stderr, "Unknown statement class: %d\n", stmt->class); + abort(); + } + free(stmt); +} + +void free_pipeline(PIPELINE *pline) { + free_commands(pline->commands); + if(pline->input_file) + free(pline->input_file); + if(pline->output_file) + free(pline->output_file); + free(pline); +} + +void free_commands(COMMAND *cmd) { + if(cmd->next) + free_commands(cmd->next); + if(cmd->args) + free_args(cmd->args); + free(cmd); +} + +void free_args(ARG *args) { + if(args->next) + free_args(args->next); + free_expr(args->expr); + free(args); +} + +void free_expr(EXPR *expr) { + switch(expr->class) { + case LIT_EXPR_CLASS: + free(expr->members.value); + break; + case NUM_EXPR_CLASS: + free(expr->members.variable); + break; + case STRING_EXPR_CLASS: + free(expr->members.variable); + break; + case UNARY_EXPR_CLASS: + free_expr(expr->members.unary_expr.arg); + break; + case BINARY_EXPR_CLASS: + free_expr(expr->members.binary_expr.arg1); + free_expr(expr->members.binary_expr.arg2); + break; + default: + fprintf(stderr, "Unknown expression class: %d\n", expr->class); + abort(); + } + free(expr); +} + +PIPELINE *copy_pipeline(PIPELINE *pline) { + if(!pline) + return NULL; + PIPELINE *copy = calloc(sizeof(PIPELINE), 1); + copy->commands = copy_commands(pline->commands); + copy->capture_output = pline->capture_output; + if(pline->input_file) + copy->input_file = strdup(pline->input_file); + if(pline->output_file) + copy->output_file = strdup(pline->output_file); + return(copy); +} + +COMMAND *copy_commands(COMMAND *cmd) { + if(!cmd) + return NULL; + COMMAND *copy = calloc(sizeof(COMMAND), 1); + copy->next = copy_commands(cmd->next); + copy->args = copy_args(cmd->args); + return copy; +} + +ARG *copy_args(ARG *args) { + if(!args) + return NULL; + ARG *copy = calloc(sizeof(ARG), 1); + copy->next = copy_args(args->next); + copy->expr = copy_expr(args->expr); + return copy; +} + +EXPR *copy_expr(EXPR *expr) { + if(!expr) + return NULL; + EXPR *copy = calloc(sizeof(EXPR), 1); + copy->class = expr->class; + copy->type = expr->type; + switch(expr->class) { + case LIT_EXPR_CLASS: + copy->members.value = strdup(expr->members.value); + break; + case NUM_EXPR_CLASS: + copy->members.variable = strdup(expr->members.variable); + break; + case STRING_EXPR_CLASS: + copy->members.variable = strdup(expr->members.variable); + break; + case UNARY_EXPR_CLASS: + copy->members.unary_expr.oprtr = expr->members.unary_expr.oprtr; + copy->members.unary_expr.arg = copy_expr(expr->members.unary_expr.arg); + break; + case BINARY_EXPR_CLASS: + copy->members.binary_expr.oprtr = expr->members.binary_expr.oprtr; + copy->members.binary_expr.arg1 = copy_expr(expr->members.binary_expr.arg1); + copy->members.binary_expr.arg2 = copy_expr(expr->members.binary_expr.arg2); + break; + default: + fprintf(stderr, "Unknown expression class: %d\n", expr->class); + abort(); + } + return copy; +} diff --git a/hw4/tests/base_tests.c b/hw4/tests/base_tests.c new file mode 100644 index 0000000..23146bd --- /dev/null +++ b/hw4/tests/base_tests.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +/* + * This just checks if mush exits normally on an empty input. + * It is not very interesting, unfortunately. + * It is just a place holder where something more interesting might go. + */ +Test(basecode_suite, mush_eof_test, .timeout=20) +{ + char *cmd = "ulimit -t 10; bin/mush < /dev/null"; + + int code = WEXITSTATUS(system(cmd)); + cr_assert_eq(code, EXIT_SUCCESS, + "Program exited with %d instead of EXIT_SUCCESS", + code); +}