lexeme *st_eoln_eof(lexer_info *linfo, buffer *buf) { lexeme *lex = NULL; #ifdef LEXER_DEBUG print_state("ST_EOLN_EOF", linfo->c); #endif switch (linfo->c) { case '\n': lex = make_lex(LEX_EOLINE); break; case EOF: lex = make_lex(LEX_EOFILE); break; default: fprintf(stderr, "Lexer: error in ST_EOLN_EOF;"); print_state("ST_EOLN_EOF", linfo->c); exit(ES_LEXER_INCURABLE_ERROR); } deferred_get_char(linfo); linfo->state = ST_START; return lex; }
lexeme *st_one_sym_lex(lexer_info *linfo, buffer *buf) { lexeme *lex = NULL; #ifdef LEXER_DEBUG print_state("ST_ONE_SYM_LEX", linfo->c); #endif switch (linfo->c) { case '<': lex = make_lex(LEX_INPUT); break; case ';': lex = make_lex(LEX_SEMICOLON); break; case '(': lex = make_lex(LEX_BRACKET_OPEN); break; case ')': lex = make_lex(LEX_BRACKET_CLOSE); break; case '`': lex = make_lex(LEX_REVERSE); break; default: fprintf(stderr, "Lexer: error in ST_ONE_SYM_LEX;"); print_state("ST_ONE_SYM_LEX", linfo->c); exit(ES_LEXER_INCURABLE_ERROR); } /* We don't need buffer */ deferred_get_char(linfo); linfo->state = ST_START; return lex; }
void init_lexicons() { int i,j; for(i=0;i<GMAXWORDS;i++) fwords[i] = GUNKNOWN; for(i=0;i<GMAXWORDS;i++) for(j=0;j<GMAXNTS;j++) tagdict[i][j] = 0; make_lex(200003,&wordlex); make_lex(1003,&nt_lex); TRACEWORD = add_word("*TRACE*",&wordlex); fwords[TRACEWORD] = 1; }
lexeme *st_error(lexer_info *linfo, buffer *buf) { lexeme *lex = NULL; lex = make_lex(LEX_ERROR); print_state("ST_ERROR", linfo->c); clear_buffer(buf); linfo->get_next_char = 0; linfo->state = ST_START; /* TODO: read to '\n' or EOF (flush read buffer) */ return lex; }
lexeme *st_one_two_sym_lex(lexer_info *linfo, buffer *buf) { lexeme *lex = NULL; #ifdef LEXER_DEBUG print_state("ST_ONE_TWO_SYM_LEX", linfo->c); #endif if (buf->count_sym == 0) { add_to_buffer(buf, linfo->c); deferred_get_char(linfo); } else if (buf->count_sym == 1) { /* TODO: make it more pretty */ char prev_c = get_last_from_buffer(buf); clear_buffer(buf); switch (prev_c) { case '>': lex = (prev_c == linfo->c) ? make_lex(LEX_APPEND) : make_lex(LEX_OUTPUT); break; case '|': lex = (prev_c == linfo->c) ? make_lex(LEX_OR) : make_lex(LEX_PIPE); break; case '&': lex = (prev_c == linfo->c) ? make_lex(LEX_AND) : make_lex(LEX_BACKGROUND); break; default: fprintf(stderr, "Lexer: error (type 1) in ST_ONE_TWO_SYM_LEX;"); print_state("ST_ONE_TWO_SYM_LEX", linfo->c); exit(ES_LEXER_INCURABLE_ERROR); } if (prev_c == linfo->c) deferred_get_char(linfo); linfo->state = ST_START; return lex; } else { fprintf(stderr, "Lexer: error (type 2) in ST_ONE_TWO_SYM_LEX;"); print_state("ST_ONE_TWO_SYM_LEX", linfo->c); exit(ES_LEXER_INCURABLE_ERROR); } return lex; }
lexeme *st_word(lexer_info *linfo, buffer *buf) { lexeme *lex = NULL; #ifdef LEXER_DEBUG print_state("ST_WORD", linfo->c); #endif switch (linfo->c) { case EOF: case '\n': case ' ': case '\t': case '<': case ';': case '(': case ')': case '>': case '|': case '&': case '`': linfo->state = ST_START; lex = make_lex(LEX_WORD); lex->str = convert_to_string(buf, 1); return lex; case '\\': deferred_get_char(linfo); linfo->state = ST_BACKSLASH; break; case '\"': deferred_get_char(linfo); linfo->state = ST_IN_QUOTES; break; default: add_to_buffer(buf, linfo->c); deferred_get_char(linfo); } return lex; }