1//===- FlexLexer.h --------------------------------------------------------===// 2// 3// The MCLinker Project 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// -*-C++-*- 11// FlexLexer.h -- define interfaces for lexical analyzer classes generated 12// by flex 13 14// Copyright (c) 1993 The Regents of the University of California. 15// All rights reserved. 16// 17// This code is derived from software contributed to Berkeley by 18// Kent Williams and Tom Epperly. 19// 20// Redistribution and use in source and binary forms, with or without 21// modification, are permitted provided that the following conditions 22// are met: 23 24// 1. Redistributions of source code must retain the above copyright 25// notice, this list of conditions and the following disclaimer. 26// 2. Redistributions in binary form must reproduce the above copyright 27// notice, this list of conditions and the following disclaimer in the 28// documentation and/or other materials provided with the distribution. 29 30// Neither the name of the University nor the names of its contributors 31// may be used to endorse or promote products derived from this software 32// without specific prior written permission. 33 34// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 35// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 36// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 37// PURPOSE. 38 39// This file defines FlexLexer, an abstract class which specifies the 40// external interface provided to flex C++ lexer objects, and yyFlexLexer, 41// which defines a particular lexer class. 42// 43// If you want to create multiple lexer classes, you use the -P flag 44// to rename each yyFlexLexer to some other xxFlexLexer. You then 45// include <FlexLexer.h> in your other sources once per lexer class: 46// 47// #undef yyFlexLexer 48// #define yyFlexLexer xxFlexLexer 49// #include <FlexLexer.h> 50// 51// #undef yyFlexLexer 52// #define yyFlexLexer zzFlexLexer 53// #include <FlexLexer.h> 54// ... 55 56#ifndef __FLEX_LEXER_H 57// Never included before - need to define base class. 58#define __FLEX_LEXER_H 59 60#include <iostream> 61#ifndef FLEX_STD 62#define FLEX_STD std:: 63#endif 64 65extern "C++" { 66struct yy_buffer_state; 67typedef int yy_state_type; 68 69class FlexLexer { 70 public: 71 virtual ~FlexLexer() {} 72 73 const char* YYText() const { return yytext; } 74 int YYLeng() const { return yyleng; } 75 76 virtual void yy_switch_to_buffer(struct yy_buffer_state* new_buffer) = 0; 77 virtual struct yy_buffer_state* yy_create_buffer(FLEX_STD istream* s, 78 int size) = 0; 79 virtual void yy_delete_buffer(struct yy_buffer_state* b) = 0; 80 virtual void yyrestart(FLEX_STD istream* s) = 0; 81 82 virtual int yylex() = 0; 83 84 // Call yylex with new input/output sources. 85 int yylex(FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0) { 86 switch_streams(new_in, new_out); 87 return yylex(); 88 } 89 90 // Switch to new input/output streams. A nil stream pointer 91 // indicates "keep the current one". 92 virtual void switch_streams(FLEX_STD istream* new_in = 0, 93 FLEX_STD ostream* new_out = 0) = 0; 94 95 int lineno() const { return yylineno; } 96 97 int debug() const { return yy_flex_debug; } 98 void set_debug(int flag) { yy_flex_debug = flag; } 99 100 protected: 101 char* yytext; 102 int yyleng; 103 int yylineno; // only maintained if you use %option yylineno 104 int yy_flex_debug; // only has effect with -d or "%option debug" 105}; 106} 107#endif // FLEXLEXER_H 108 109#if defined(yyFlexLexer) || !defined(yyFlexLexerOnce) 110// Either this is the first time through (yyFlexLexerOnce not defined), 111// or this is a repeated include to define a different flavor of 112// yyFlexLexer, as discussed in the flex manual. 113#define yyFlexLexerOnce 114 115extern "C++" { 116class yyFlexLexer : public FlexLexer { 117 public: 118 // arg_yyin and arg_yyout default to the cin and cout, but we 119 // only make that assignment when initializing in yylex(). 120 yyFlexLexer(FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0); 121 122 virtual ~yyFlexLexer(); 123 124 void yy_switch_to_buffer(struct yy_buffer_state* new_buffer); 125 struct yy_buffer_state* yy_create_buffer(FLEX_STD istream* s, int size); 126 void yy_delete_buffer(struct yy_buffer_state* b); 127 void yyrestart(FLEX_STD istream* s); 128 129 void yypush_buffer_state(struct yy_buffer_state* new_buffer); 130 void yypop_buffer_state(); 131 132 virtual int yylex(); 133 virtual void switch_streams(FLEX_STD istream* new_in, 134 FLEX_STD ostream* new_out = 0); 135 virtual int yywrap(); 136 137 protected: 138 virtual int LexerInput(char* buf, int max_size); 139 virtual void LexerOutput(const char* buf, int size); 140 virtual void LexerError(const char* msg); 141 142 void yyunput(int c, char* buf_ptr); 143 int yyinput(); 144 145 void yy_load_buffer_state(); 146 void yy_init_buffer(struct yy_buffer_state* b, FLEX_STD istream* s); 147 void yy_flush_buffer(struct yy_buffer_state* b); 148 149 int yy_start_stack_ptr; 150 int yy_start_stack_depth; 151 int* yy_start_stack; 152 153 void yy_push_state(int new_state); 154 void yy_pop_state(); 155 int yy_top_state(); 156 157 yy_state_type yy_get_previous_state(); 158 yy_state_type yy_try_NUL_trans(yy_state_type current_state); 159 int yy_get_next_buffer(); 160 161 FLEX_STD istream* yyin; // input source for default LexerInput 162 FLEX_STD ostream* yyout; // output sink for default LexerOutput 163 164 // yy_hold_char holds the character lost when yytext is formed. 165 char yy_hold_char; 166 167 // Number of characters read into yy_ch_buf. 168 int yy_n_chars; 169 170 // Points to current character in buffer. 171 char* yy_c_buf_p; 172 173 int yy_init; // whether we need to initialize 174 int yy_start; // start state number 175 176 // Flag which is used to allow yywrap()'s to do buffer switches 177 // instead of setting up a fresh yyin. A bit of a hack ... 178 int yy_did_buffer_switch_on_eof; 179 180 size_t yy_buffer_stack_top; /**< index of top of stack. */ 181 size_t yy_buffer_stack_max; /**< capacity of stack. */ 182 struct yy_buffer_state** yy_buffer_stack; /**< Stack as an array. */ 183 void yyensure_buffer_stack(void); 184 185 // The following are not always needed, but may be depending 186 // on use of certain flex features (like REJECT or yymore()). 187 188 yy_state_type yy_last_accepting_state; 189 char* yy_last_accepting_cpos; 190 191 yy_state_type* yy_state_buf; 192 yy_state_type* yy_state_ptr; 193 194 char* yy_full_match; 195 int* yy_full_state; 196 int yy_full_lp; 197 198 int yy_lp; 199 int yy_looking_for_trail_begin; 200 201 int yy_more_flag; 202 int yy_more_len; 203 int yy_more_offset; 204 int yy_prev_more_offset; 205}; 206} 207 208#endif // yyFlexLexer || ! yyFlexLexerOnce 209