lex_t.h

00001 /*
00002  * Copyright (c) 2011 Jiri Svoboda
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #ifndef LEX_T_H_
00030 #define LEX_T_H_
00031 
00032 #include "bigint_t.h"
00033 
00035 typedef enum {
00036         lc_invalid,
00037         lc_eof,
00038 
00039         lc_ident,
00040         lc_lit_char,
00041         lc_lit_int,
00042         lc_lit_string,
00043 
00044         /* Keywords */
00045         lc_and,
00046         lc_as,
00047         lc_break,
00048         lc_bool,
00049         lc_builtin,
00050         lc_char,
00051         lc_class,
00052         lc_deleg,
00053         lc_do,
00054         lc_elif,
00055         lc_else,
00056         lc_end,
00057         lc_enum,
00058         lc_except,
00059         lc_false,
00060         lc_finally,
00061         lc_for,
00062         lc_fun,
00063         lc_new,
00064         lc_get,
00065         lc_if,
00066         lc_in,
00067         lc_int,
00068         lc_interface,
00069         lc_is,
00070         lc_nil,
00071         lc_not,
00072         lc_or,
00073         lc_override,
00074         lc_packed,
00075         lc_private,
00076         lc_prop,
00077         lc_protected,
00078         lc_public,
00079         lc_raise,
00080         lc_resource,
00081         lc_return,
00082         lc_self,
00083         lc_set,
00084         lc_static,
00085         lc_string,
00086         lc_struct,
00087         lc_switch,
00088         lc_then,
00089         lc_this,
00090         lc_true,
00091         lc_var,
00092         lc_with,
00093         lc_when,
00094         lc_while,
00095         lc_yield,
00096 
00097         /* Operators */
00098         lc_period,
00099         lc_slash,
00100         lc_lparen,
00101         lc_rparen,
00102         lc_lsbr,
00103         lc_rsbr,
00104         lc_equal,
00105         lc_notequal,
00106         lc_lt,
00107         lc_gt,
00108         lc_lt_equal,
00109         lc_gt_equal,
00110         lc_assign,
00111         lc_plus,
00112         lc_minus,
00113         lc_mult,
00114         lc_increase,
00115 
00116         /* Punctuators */
00117         lc_comma,
00118         lc_colon,
00119         lc_scolon,
00120 
00121         lc__limit
00122 } lclass_t;
00123 
00124 typedef struct {
00125         /* String ID */
00126         int sid;
00127 } lem_ident_t;
00128 
00129 typedef struct {
00130         /* Character value */
00131         bigint_t value;
00132 } lem_lit_char_t;
00133 
00134 typedef struct {
00135         /* Integer value */
00136         bigint_t value;
00137 } lem_lit_int_t;
00138 
00139 typedef struct {
00140         /* String value */
00141         char *value;
00142 } lem_lit_string_t;
00143 
00145 typedef struct {
00146         /* Lexical element class */
00147         lclass_t lclass;
00148 
00149         union {
00150                 lem_ident_t ident;
00151                 lem_lit_char_t lit_char;
00152                 lem_lit_int_t lit_int;
00153                 lem_lit_string_t lit_string;
00154         } u;
00155 
00157         struct cspan *cspan;
00158 } lem_t;
00159 
00161 typedef struct lex {
00163         struct input *input;
00164 
00166         char *inbuf;
00167 
00169         char *ibp;
00170 
00172         int ib_line;
00173 
00175         int col_adj;
00176 
00178         bool_t prev_valid;
00179 
00181         lem_t prev;
00182 
00184         bool_t current_valid;
00185 
00187         lem_t current;
00188 } lex_t;
00189 
00190 #endif

Generated on Thu Jun 2 07:45:42 2011 for HelenOS/USB by  doxygen 1.4.7