|
| |||||||||||||
#include "mit-copyright.h"#include "main.h"#include "new_string.h"#include "int_dictionary.h"#include "lexer.h"#include "parser.h"Go to the source code of this file.
Data Structures | |
| struct | keyword_info |
Defines | |
| #define | is_octal_digit(c) (((c)>='0') && ((c)<='7')) |
Functions | |
| void | lex_open (FILE *file) |
| void | lex_open_buffer (char *buffer) |
| int | yylex () |
Variables | |
| int | yylineno |
| int | yybufferpos |
|
|
|
|
|
Definition at line 165 of file lexer.c. References int_dictionary_Create(), int_dictionary_Define(), keyword_info::keyword_number, _int_dictionary_binding::value, and yylineno. 00167 {
00168 /*
00169 * Initialize I/O:
00170 */
00171 input_file = file;
00172 input_buffer = NULL;
00173 yylineno = 1;
00174 pushback = -1;
00175
00176 /*
00177 * Initialize keyword_dict from keywords if needed:
00178 */
00179 if (!keyword_dict) {
00180 int i;
00181
00182 keyword_dict = int_dictionary_Create(101);
00183
00184 for (i = 0; i < sizeof(keywords) / sizeof(struct keyword_info); i++)
00185 int_dictionary_Define(keyword_dict, keywords[i].keyword,
00186 0)->value = keywords[i].keyword_number;
00187 }
00188 }
|
|
|
Definition at line 191 of file lexer.c. References int_dictionary_Create(), int_dictionary_Define(), keyword_info::keyword_number, _int_dictionary_binding::value, yybufferpos, and yylineno. Referenced by parse_buffer(). 00193 {
00194 /*
00195 * Initialize I/O:
00196 */
00197 input_buffer = buffer;
00198 input_file = NULL;
00199 yylineno = 1;
00200 yybufferpos = 0;
00201 pushback = -1;
00202
00203 /*
00204 * Initialize keyword_dict from keywords if needed:
00205 */
00206 if (!keyword_dict) {
00207 int i;
00208
00209 keyword_dict = int_dictionary_Create(101);
00210
00211 for (i = 0; i < sizeof(keywords) / sizeof(struct keyword_info); i++)
00212 int_dictionary_Define(keyword_dict, keywords[i].keyword,
00213 0)->value = keywords[i].keyword_number;
00214 }
00215 }
|
|
|
Definition at line 522 of file lexer.c. References int_dictionary_binding, int_dictionary_Lookup(), is_identifier_char, MAX_IDENTIFIER_LENGTH, report_parse_error(), string_Copy, YYSTYPE::text, _int_dictionary_binding::value, yylineno, and yylval. 00523 {
00524 register int c, last_char;
00525 register char *ptr;
00526 int start_line_no;
00527 int_dictionary_binding *binding;
00528 char varname[MAX_IDENTIFIER_LENGTH + 1];
00529
00530 for (;;) {
00531 switch (c = input()) {
00532
00533 /*
00534 * Skip whitespace:
00535 */
00536 case ' ':
00537 case '\t':
00538 case '\n':
00539 continue;
00540
00541 /*
00542 * '#' comments out everything up to the and including
00543 * the next <cr>:
00544 */
00545 case '#':
00546 while ((c = input()) && (c != '\n'));
00547 if (!c)
00548 unput(c);
00549 continue;
00550
00551 /*
00552 * Handle c-style comments. Note that "/[^*]" is not the start
00553 * of any valid token.
00554 */
00555 case '/':
00556 start_line_no = yylineno;
00557
00558 /* verify that next character is a '*': */
00559 if ((c = input()) != '*')
00560 return (ERROR);
00561
00562 /* Scan until "*\/" or <EOF>: */
00563 for (last_char = 0;; last_char = c) {
00564 c = input();
00565 if (c == '/' && (last_char == '*'))
00566 break;
00567 if (!c) {
00568 unput(c);
00569 report_parse_error("unterminated c style comment found beginning", start_line_no);
00570 return (ERROR);
00571 }
00572 }
00573 continue;
00574
00575 /*
00576 * The following characters lex as themselves:
00577 * '+', '|', '&', '(', ')', '.', ',' and <EOF>:
00578 */
00579 case 0:
00580 case '+':
00581 case '|':
00582 case '&':
00583 case '(':
00584 case ')':
00585 case '.':
00586 case ',':
00587 return (c);
00588
00589 /*
00590 * Handle "=[^~=]", "=~", and "==":
00591 */
00592 case '=':
00593 switch (c = input()) {
00594 case '~':
00595 return (REGEQ);
00596 case '=':
00597 return (EQ);
00598 default:
00599 unput(c);
00600 return ('=');
00601 }
00602
00603 /*
00604 * Handle "![^~=]", "!~", and "!=":
00605 */
00606 case '!':
00607 switch (c = input()) {
00608 case '~':
00609 return (REGNEQ);
00610 case '=':
00611 return (NEQ);
00612 default:
00613 unput(c);
00614 return ('!');
00615 }
00616
00617 /*
00618 * Handle identifiers and keywords:
00619 *
00620 * Note that the below set of characters is hard coded from
00621 * is_identifier_char from parser.h.
00622 */
00623 case 'a':
00624 case 'b':
00625 case 'c':
00626 case 'd':
00627 case 'e':
00628 case 'f':
00629 case 'g':
00630 case 'h':
00631 case 'i':
00632 case 'j':
00633 case 'k':
00634 case 'l':
00635 case 'm':
00636 case 'n':
00637 case 'o':
00638 case 'p':
00639 case 'q':
00640 case 'r':
00641 case 's':
00642 case 't':
00643 case 'u':
00644 case 'v':
00645 case 'w':
00646 case 'x':
00647 case 'y':
00648 case 'z':
00649 case 'A':
00650 case 'B':
00651 case 'C':
00652 case 'D':
00653 case 'E':
00654 case 'F':
00655 case 'G':
00656 case 'H':
00657 case 'I':
00658 case 'J':
00659 case 'K':
00660 case 'L':
00661 case 'M':
00662 case 'N':
00663 case 'O':
00664 case 'P':
00665 case 'Q':
00666 case 'R':
00667 case 'S':
00668 case 'T':
00669 case 'U':
00670 case 'V':
00671 case 'W':
00672 case 'X':
00673 case 'Y':
00674 case 'Z':
00675 case '0':
00676 case '1':
00677 case '2':
00678 case '3':
00679 case '4':
00680 case '5':
00681 case '6':
00682 case '7':
00683 case '8':
00684 case '9':
00685 case '_':
00686 /*
00687 * Read in the first MAX_IDENTIFIER_LENGTH characters of the
00688 * identifier into varname null terminated. Eat
00689 * the rest of the characters of the identifier:
00690 */
00691 for (ptr = varname;;) {
00692 if (ptr < varname + MAX_IDENTIFIER_LENGTH)
00693 *(ptr++) = c;
00694 c = input();
00695 if (!is_identifier_char(c))
00696 break;
00697 }
00698 unput(c);
00699 *ptr = '\0';
00700
00701 /*
00702 * Look up the identifier in the keyword dictionary.
00703 * If its a match, return the keyword's #. In the case
00704 * of show, call handle_show to do more processing.
00705 * If not a match, treat as a variable name.
00706 */
00707 binding = int_dictionary_Lookup(keyword_dict, varname);
00708 if (!binding) {
00709 yylval.text = string_Copy(varname);
00710 return (VARNAME);
00711 }
00712 if (binding->value == SHOW)
00713 return (handle_show());
00714 else
00715 return (binding->value);
00716
00717 /*
00718 * Handle "${identifier}". Note that $ followed by a
00719 * non-identifier character is not the start of any valid token.
00720 */
00721 case '$':
00722 c = input();
00723 if (!is_identifier_char(c))
00724 return (ERROR);
00725
00726 /*
00727 * Read in the first MAX_IDENTIFIER_LENGTH characters of the
00728 * identifier into varname null terminated. Eat
00729 * the rest of the characters of the identifier:
00730 */
00731 for (ptr = varname;;) {
00732 if (ptr < varname + MAX_IDENTIFIER_LENGTH)
00733 *(ptr++) = c;
00734 c = input();
00735 if (!is_identifier_char(c))
00736 break;
00737 }
00738 unput(c);
00739 *ptr = '\0';
00740
00741 yylval.text = string_Copy(varname);
00742 return (VARREF);
00743
00744 /*
00745 * Handle constant strings:
00746 */
00747 case '"':
00748 if ((yylval.text = eat_string(yylineno)))
00749 return (STRING);
00750 else
00751 return (ERROR);
00752
00753 /*
00754 * All other characters do not start valid tokens:
00755 */
00756 default:
00757 return (ERROR);
00758 }
00759 }
00760 }
|
|
|
Definition at line 29 of file lexer.c. Referenced by lex_open_buffer(). |
|
|
Definition at line 28 of file lexer.c. Referenced by lex_open(), lex_open_buffer(), and yylex(). |
| Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |