[09ababb7] | 1 | /*
|
---|
[051b3db8] | 2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[09ababb7] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #ifndef LEX_T_H_
|
---|
| 30 | #define LEX_T_H_
|
---|
| 31 |
|
---|
[23de644] | 32 | #include "bigint_t.h"
|
---|
| 33 |
|
---|
[09ababb7] | 34 | /** Lexical element class */
|
---|
| 35 | typedef enum {
|
---|
| 36 | lc_invalid,
|
---|
| 37 | lc_eof,
|
---|
| 38 |
|
---|
| 39 | lc_ident,
|
---|
[074444f] | 40 | lc_lit_char,
|
---|
[09ababb7] | 41 | lc_lit_int,
|
---|
| 42 | lc_lit_string,
|
---|
| 43 |
|
---|
| 44 | /* Keywords */
|
---|
[051bc69a] | 45 | lc_and,
|
---|
[37f527b] | 46 | lc_as,
|
---|
[051bc69a] | 47 | lc_break,
|
---|
[074444f] | 48 | lc_bool,
|
---|
[37f527b] | 49 | lc_builtin,
|
---|
[074444f] | 50 | lc_char,
|
---|
[09ababb7] | 51 | lc_class,
|
---|
[38aaacc2] | 52 | lc_deleg,
|
---|
[09ababb7] | 53 | lc_do,
|
---|
[051bc69a] | 54 | lc_elif,
|
---|
[09ababb7] | 55 | lc_else,
|
---|
| 56 | lc_end,
|
---|
[051bc69a] | 57 | lc_enum,
|
---|
[09ababb7] | 58 | lc_except,
|
---|
[074444f] | 59 | lc_false,
|
---|
[09ababb7] | 60 | lc_finally,
|
---|
| 61 | lc_for,
|
---|
| 62 | lc_fun,
|
---|
| 63 | lc_new,
|
---|
| 64 | lc_get,
|
---|
| 65 | lc_if,
|
---|
| 66 | lc_in,
|
---|
| 67 | lc_int,
|
---|
| 68 | lc_interface,
|
---|
| 69 | lc_is,
|
---|
[fa36f29] | 70 | lc_nil,
|
---|
[051bc69a] | 71 | lc_not,
|
---|
| 72 | lc_or,
|
---|
[09ababb7] | 73 | lc_override,
|
---|
[94d484a] | 74 | lc_packed,
|
---|
[09ababb7] | 75 | lc_private,
|
---|
| 76 | lc_prop,
|
---|
| 77 | lc_protected,
|
---|
| 78 | lc_public,
|
---|
| 79 | lc_raise,
|
---|
[37f527b] | 80 | lc_resource,
|
---|
[09ababb7] | 81 | lc_return,
|
---|
[fa36f29] | 82 | lc_self,
|
---|
[09ababb7] | 83 | lc_set,
|
---|
| 84 | lc_static,
|
---|
| 85 | lc_string,
|
---|
| 86 | lc_struct,
|
---|
[051b3db8] | 87 | lc_switch,
|
---|
[09ababb7] | 88 | lc_then,
|
---|
| 89 | lc_this,
|
---|
[074444f] | 90 | lc_true,
|
---|
[09ababb7] | 91 | lc_var,
|
---|
| 92 | lc_with,
|
---|
[051b3db8] | 93 | lc_when,
|
---|
[09ababb7] | 94 | lc_while,
|
---|
| 95 | lc_yield,
|
---|
| 96 |
|
---|
| 97 | /* Operators */
|
---|
| 98 | lc_period,
|
---|
| 99 | lc_slash,
|
---|
| 100 | lc_lparen,
|
---|
| 101 | lc_rparen,
|
---|
| 102 | lc_lsbr,
|
---|
| 103 | lc_rsbr,
|
---|
| 104 | lc_equal,
|
---|
| 105 | lc_notequal,
|
---|
| 106 | lc_lt,
|
---|
| 107 | lc_gt,
|
---|
| 108 | lc_lt_equal,
|
---|
| 109 | lc_gt_equal,
|
---|
| 110 | lc_assign,
|
---|
| 111 | lc_plus,
|
---|
[23de644] | 112 | lc_minus,
|
---|
| 113 | lc_mult,
|
---|
[09ababb7] | 114 | lc_increase,
|
---|
| 115 |
|
---|
| 116 | /* Punctuators */
|
---|
| 117 | lc_comma,
|
---|
| 118 | lc_colon,
|
---|
| 119 | lc_scolon,
|
---|
| 120 |
|
---|
| 121 | lc__limit
|
---|
| 122 | } lclass_t;
|
---|
| 123 |
|
---|
| 124 | typedef struct {
|
---|
| 125 | /* String ID */
|
---|
| 126 | int sid;
|
---|
| 127 | } lem_ident_t;
|
---|
| 128 |
|
---|
[074444f] | 129 | typedef struct {
|
---|
| 130 | /* Character value */
|
---|
| 131 | bigint_t value;
|
---|
| 132 | } lem_lit_char_t;
|
---|
| 133 |
|
---|
[09ababb7] | 134 | typedef struct {
|
---|
| 135 | /* Integer value */
|
---|
[23de644] | 136 | bigint_t value;
|
---|
[09ababb7] | 137 | } lem_lit_int_t;
|
---|
| 138 |
|
---|
| 139 | typedef struct {
|
---|
| 140 | /* String value */
|
---|
| 141 | char *value;
|
---|
| 142 | } lem_lit_string_t;
|
---|
| 143 |
|
---|
| 144 | /** Lexical element */
|
---|
| 145 | typedef struct {
|
---|
| 146 | /* Lexical element class */
|
---|
| 147 | lclass_t lclass;
|
---|
| 148 |
|
---|
| 149 | union {
|
---|
| 150 | lem_ident_t ident;
|
---|
[074444f] | 151 | lem_lit_char_t lit_char;
|
---|
[09ababb7] | 152 | lem_lit_int_t lit_int;
|
---|
| 153 | lem_lit_string_t lit_string;
|
---|
| 154 | } u;
|
---|
| 155 |
|
---|
| 156 | /** Coordinates of this lexical element */
|
---|
[051bc69a] | 157 | struct cspan *cspan;
|
---|
[09ababb7] | 158 | } lem_t;
|
---|
| 159 |
|
---|
| 160 | /** Lexer state object */
|
---|
| 161 | typedef struct lex {
|
---|
| 162 | /** Input object */
|
---|
| 163 | struct input *input;
|
---|
| 164 |
|
---|
| 165 | /** Lexing buffer */
|
---|
| 166 | char *inbuf;
|
---|
| 167 |
|
---|
| 168 | /** Pointer to current position in lexing buffer */
|
---|
| 169 | char *ibp;
|
---|
| 170 |
|
---|
| 171 | /** Number of the line currently in inbuf */
|
---|
| 172 | int ib_line;
|
---|
| 173 |
|
---|
| 174 | /** Column number adjustment (due to tabs) */
|
---|
| 175 | int col_adj;
|
---|
| 176 |
|
---|
[051bc69a] | 177 | /** @c b_true if we have the previous lem in @c prev */
|
---|
| 178 | bool_t prev_valid;
|
---|
| 179 |
|
---|
| 180 | /** Previous lem (only valid if @c current_valid is true) */
|
---|
| 181 | lem_t prev;
|
---|
| 182 |
|
---|
| 183 | /** @c b_true if we have the current lem in @c current */
|
---|
[37f527b] | 184 | bool_t current_valid;
|
---|
| 185 |
|
---|
| 186 | /** Curent lem (only valid if @c current_valid is true) */
|
---|
[09ababb7] | 187 | lem_t current;
|
---|
| 188 | } lex_t;
|
---|
| 189 |
|
---|
| 190 | #endif
|
---|