#ifndef LEXER_H #define LEXER_H #include #include #include // True if C could be used as a word #define ISWORD(C) \ C == TOKEN_WORD || C == TOKEN_THEN || C == TOKEN_ELIF || C == TOKEN_ELSE \ || C == TOKEN_IF || C == TOKEN_WHILE || C == TOKEN_UNTIL \ || C == TOKEN_DO || C == TOKEN_DONE || C == TOKEN_FOR || C == TOKEN_IN \ || C == TOKEN_NEG || C == TOKEN_FI || C == TOKEN_CURLY_LEFT \ || C == TOKEN_CURLY_RIGHT struct lexer { struct string *input; // input data size_t pos; // the current offset inside the input data char processed; struct token current_tok; // next (if processed) token }; // Creates a new lexer given an input string struct lexer *lexer_new(struct string *input); // Frees the given lexer, not its input void lexer_free(struct lexer *lexer); // Returns a token from the input string // If the token is a WORD, copies the word to the current_tok.value field struct token lexer_next_token(struct lexer *lexer); /* ** Processes the next token if necessary ** (previous call to lexer_pop or first call) */ // Returns the next token struct token lexer_peek(struct lexer *lexer); /* ** Processes the next token if necessary ** (previous call to lexer_pop or first call) */ // Returns the next token and moves the cursor forward struct token lexer_pop(struct lexer *lexer); #endif /* ! LEXER_H */