|
|
#include "mit-copyright.h"
#include <ctype.h>
Go to the source code of this file.
Defines | |
#define | is_identifier_char(c) (isalnum(c) || (c)=='_') |
#define | MAX_IDENTIFIER_LENGTH 128 |
Functions | |
void | lex_open () |
int | yylex () |
void | report_parse_error (char *error_message, int line_number) |
Variables | |
int | yylineno |
|
Definition at line 23 of file lexer.h. Referenced by yylex(). |
|
Definition at line 31 of file lexer.h. Referenced by yylex(). |
|
Referenced by parse_file(). |
|
Definition at line 1489 of file parser.c. Referenced by yylex(). 01492 { 01493 if (error_occured) 01494 return; 01495 error_occured = 1; 01496 01497 fprintf(stderr, "jwgc: error in description file: %s on line %d.\n", 01498 error_message, line_number); 01499 fflush(stderr); 01500 }
|
|
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 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... |