Lexical Analyzer v0.1.0
 
Loading...
Searching...
No Matches
lexer.h
Go to the documentation of this file.
1#ifndef LEXER_H
2#define LEXER_H
3
4
22
23#include "lexer_validation.h"
24
36
59
60
61
146
147
160const char *toktyp_rval(const tok_e type);
161
162
163
180tok_e get_toktyp(const char *const value, const tokcat_e type);
181 // End of TokenClassification group
183
184
185
186
187
197
208typedef struct tok_t{
209 char *val;
211 size_t ln;
212 size_t col;
213} tok_t;
214
215
226
227
239tok_t **tok_nctor(const size_t n);
240
241
256tok_t *tok_ptor(char *value,
257 const tok_e type,
258 const size_t line,
259 const size_t col);
260
261
272void tok_dtor(tok_t *tok);
273
274
283void printf_tok(const tok_t *const tok);
284
285
297bool fwrite_tok(FILE *fp, const tok_t *const tok);
298 // End of TokenStructure group
300
301
302
303
316
325typedef struct tokset_t {
327 size_t toksz;
328} tokset_t;
329
330
342
343
356tokset_t *tokset_ptor(const size_t toksz);
357
358
370
371
383size_t cnt_toktyp(const tokset_t *const set, const tok_e type);
384
385
395void printf_tokset(const tokset_t *const set);
396
397
411bool fwrite_tokset(FILE *fp, const tokset_t *const set);
412 // End of TokenSet group
414
415 // End of Lexer group
417
418#endif
tokcat_e
Token category enumeration for categorizing different token types in the pre-processing phase.
Definition lexer.h:48
tok_e get_toktyp(const char *const value, const tokcat_e type)
Determines the specific token type from a given token string and its category.
tok_e
Token type enumeration for categorizing various types of tokens during lexical analysis.
Definition lexer.h:72
const char * toktyp_rval(const tok_e type)
Returns a string representation of a token type.
@ LITERAL
String/character literals.
Definition lexer.h:51
@ NFKI_LITERAL
Numerical literals, keywords, or identifiers.
Definition lexer.h:57
@ SYMBOLS
Operators/punctuation (+, ;).
Definition lexer.h:50
@ PRE_PROC
Preprocessor directives (#define, #include).
Definition lexer.h:49
@ KEYWORD
Keyword token type.
Definition lexer.h:78
@ FLOATING_POINT_LITERAL
Floating point literal token type.
Definition lexer.h:108
@ CHARACTER_LITERAL
Character literal token type.
Definition lexer.h:115
@ OPERATOR
Operator token type.
Definition lexer.h:86
@ STRING_LITERAL
String literal token type.
Definition lexer.h:122
@ NUMERIC_LITERAL
Numeric literal token type.
Definition lexer.h:101
@ INVALID_IDENTIFIER
Invalid identifier token type.
Definition lexer.h:130
@ IDENTIFIER
Identifier token type.
Definition lexer.h:137
@ PRE_PROCESSOR_OPERATOR
Preprocessor operator token type.
Definition lexer.h:144
@ PUNCTUATION
Punctuation token type.
Definition lexer.h:94
void tokset_dtor(tokset_t *set)
Frees the memory associated with a token set.
void printf_tokset(const tokset_t *const set)
Prints the contents of a token set to the standard output.
tokset_t * tokset_ptor(const size_t toksz)
Creates and initializes a token set with a specified number of tokens.
bool fwrite_tokset(FILE *fp, const tokset_t *const set)
Writes the contents of a token set to a file.
size_t cnt_toktyp(const tokset_t *const set, const tok_e type)
Counts the number of tokens of a specific type in a token set.
tokset_t * tokset_ctor()
Allocates and returns a new token set object.
void tok_dtor(tok_t *tok)
Frees the memory associated with a token.
void printf_tok(const tok_t *const tok)
Prints the contents of a token to the standard output.
tok_t * tok_ptor(char *value, const tok_e type, const size_t line, const size_t col)
Creates and initializes a token with given values.
tok_t ** tok_nctor(const size_t n)
Allocates and returns an array of token objects.
bool fwrite_tok(FILE *fp, const tok_t *const tok)
Writes the contents of a token to a file.
tok_t * tok_ctor()
Allocates and returns a new token object.
Container for token data and metadata.
Definition lexer.h:208
char * val
Definition lexer.h:209
size_t col
Definition lexer.h:212
tok_e typ
Definition lexer.h:210
size_t ln
Definition lexer.h:211
Container for multiple tokens.
Definition lexer.h:325
size_t toksz
Definition lexer.h:327
tok_t ** toks
Definition lexer.h:326