Add more structure constructor tests.
[piglit/hramrach.git] / tests / glean / lex.h
blob87e24dfc627c918c617c65281716280ce55c5b97
1 // BEGIN_COPYRIGHT
2 //
3 // Copyright (C) 1999 Allen Akin All Rights Reserved.
4 //
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
12 // conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
16 // Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
26 //
27 // END_COPYRIGHT
32 // lex.h: Simple lexical analysis utilities
34 // Given a string containing C-style tokens, returns information about
35 // successive tokens. Doesn't support all C tokens; just the few that
36 // GLEAN needs.
39 #ifndef __lex_h__
40 #define __lex_h__
42 #include <string>
44 #ifdef __WIN__
45 // ERROR is already defined in some windows header file
46 #undef ERROR
47 #endif
49 namespace GLEAN {
51 class Lex {
52 protected:
54 // State information:
55 const char* input;
56 const char* p;
57 bool ignoringCase;
59 public:
61 // Constructors:
63 Lex(const char* s, bool ignoreCase = false);
64 // Creates a lexer which will draw input from the given string.
66 // Exceptions:
68 struct Error { }; // Base class for errors.
69 struct Lexical: public Error { // Lexical error in string.
70 const char* err;
71 int position;
72 Lexical(const char* e, int p) {
73 err = e;
74 position = p;
77 struct InternalError: public Error { // Shouldn't happen.
80 // Tokens:
82 typedef enum {
83 ERROR = 0, // erroneous token; must be zero
84 END, // end of input
86 AND, // &
87 AND_AND, // &&
88 ASSIGN, // =
89 BANG, // !
90 COMMA, // ,
91 DOT, // .
92 EQ, // ==
93 GE, // >=
94 GT, // >
95 LE, // <=
96 LPAREN, // (
97 LT, // <
98 MINUS, // -
99 NE, // !=
100 OR, // |
101 OR_OR, // ||
102 PERCENT, // %
103 PLUS, // +
104 RPAREN, // )
105 SLASH, // /
106 STAR, // *
108 ICONST, // signed integer constant
110 ID // identifier
111 } Token;
113 // Utilities:
115 void next(); // fetch next token
117 Token token; // current token
118 std::string id; // most recent identifier
119 int iValue; // most recent signed integer value
121 inline int position() { // current position in input string
122 return p - input;
124 }; // class Lex
126 } // namespace GLEAN
128 #endif // __lex_h__