ndr_lex.c revision d0e518695adc90b82233b99af7dffbb3d3f92c00
5aefb6555731130ca4fd295960123d71f2d21fe8rie * CDDL HEADER START
5aefb6555731130ca4fd295960123d71f2d21fe8rie * The contents of this file are subject to the terms of the
5aefb6555731130ca4fd295960123d71f2d21fe8rie * Common Development and Distribution License (the "License").
5aefb6555731130ca4fd295960123d71f2d21fe8rie * You may not use this file except in compliance with the License.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5aefb6555731130ca4fd295960123d71f2d21fe8rie * See the License for the specific language governing permissions
5aefb6555731130ca4fd295960123d71f2d21fe8rie * and limitations under the License.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * When distributing Covered Code, include this CDDL HEADER in each
5aefb6555731130ca4fd295960123d71f2d21fe8rie * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * If applicable, add the following below this CDDL HEADER, with the
5aefb6555731130ca4fd295960123d71f2d21fe8rie * fields enclosed by brackets "[]" replaced with your own identifying
5aefb6555731130ca4fd295960123d71f2d21fe8rie * information: Portions Copyright [yyyy] [name of copyright owner]
5aefb6555731130ca4fd295960123d71f2d21fe8rie * CDDL HEADER END
f441771b0ce9f9d6122d318ff8290cb1a2848f9dRod Evans * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * Use is subject to license terms.
5aefb6555731130ca4fd295960123d71f2d21fe8rie#pragma ident "%Z%%M% %I% %E% SMI"
5aefb6555731130ca4fd295960123d71f2d21fe8rie * C-like lexical analysis.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * 1. Define a "struct node"
5aefb6555731130ca4fd295960123d71f2d21fe8rie * 2. Define a "struct symbol" that encapsulates a struct node.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * 3. Define a "struct integer" that encapsulates a struct node.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * 4. Set the YACC stack type in the grammar:
5aefb6555731130ca4fd295960123d71f2d21fe8rie * #define YYSTYPE struct node *
5aefb6555731130ca4fd295960123d71f2d21fe8rie * 5. Define %token's in the grammer for IDENTIFIER, STRING and INTEGER.
5aefb6555731130ca4fd295960123d71f2d21fe8rie * Using "_KW" as a suffix for keyword tokens, i.e. "struct" is
5aefb6555731130ca4fd295960123d71f2d21fe8rie * "%token STRUCT_KW":
5aefb6555731130ca4fd295960123d71f2d21fe8rie * // atomic values
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * %token INTEGER STRING IDENTIFIER
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * // keywords
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * %token STRUCT_KW CASE_KW
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * // operators
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * %token PLUS MINUS ASSIGN ARROW
5aefb6555731130ca4fd295960123d71f2d21fe8rie * // overloaded tokens (++ --, < > <= >=, == !=, += -= *= ...)
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * %token INCOP RELOP EQUOP ASSOP
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * 6. It's easiest to use the yacc(1) generated token numbers for node
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * labels. For node labels that are not actually part of the grammer,
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * use a %token with an L_ prefix:
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * // node labels (can't be generated by lex)
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * %token L_LT L_LTE L_GT L_GTE L_EQU L_NEQ
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans * 7. Call set_lex_input() before parsing.
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define iswhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\f')
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define is_between(c, l, u) ((l) <= (c) && (c) <= (u))
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define is_white(c) ((c) == ' ' || c == '\r' || c == '\t' || c == '\f')
5aefb6555731130ca4fd295960123d71f2d21fe8rie#define is_xdigit(c) \
08278a5e91755ccdb5850c19d21d42fb2e16b50eRod Evans (is_digit(c) || is_between((c), 'A', 'F') || is_between((c), 'a', 'f'))
5aefb6555731130ca4fd295960123d71f2d21fe8rie/* In yacc(1) generated parser */
5aefb6555731130ca4fd295960123d71f2d21fe8rie * The keywtab[] and optable[] could be external to this lex
5aefb6555731130ca4fd295960123d71f2d21fe8rie * and it would all still work.
yylex(void)
char *p = lexeme;
int c, xc;
top:
p = lexeme;
if (c == EOF)
return (EOF);
line_number++;
goto top;
int sc;
goto top;
goto top;
goto top;
lex_at_bol = 0;
if (is_white(c))
goto top;
if (is_sstart(c)) {
} while (is_sfollow(c));
return (IDENTIFIER);
if (is_digit(c)) {
} while (is_xdigit(c));
goto convert_icon;
} while (is_digit(c));
goto convert_icon;
while (is_digit(c)) {
return (INTEGER);
lexeme[0] = c;
goto top;
xc = c;
line_number++;
goto top;
if (sym) {
if (sym) {
goto top;
static ndr_symbol_t *
ndr_symbol_t *p;
ndr_symbol_t *p;
*pp = p;
static ndr_integer_t *
ndr_integer_t *p;
*pp = p;
struct node *
return (np);
char *p = buf;
char *q = buf;
int in_word = 0;
if (!in_word) {
if (iswhite(c))
*pp++ = q;
if (isquote(c)) {
int qc = c;
while (((c = *p++) != 0) && (c != qc))
} else if (iswhite(c)) {
in_word = 0;
if (in_word)
*pp = (char *)0;