This repository was archived by the owner on Jul 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexical_analyzer.h
More file actions
63 lines (53 loc) · 1.68 KB
/
lexical_analyzer.h
File metadata and controls
63 lines (53 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef __LEXICAL_ANALYZER_H__
#define __LEXICAL_ANALYZER_H__
#include "token.h"
#include <stdio.h>
/**
* Enumaration for possible lexer errors.
* */
typedef enum {
NONE = 0,
NONLETTER_VAR_INITIAL,
NAME_TOO_LONG,
NUM_TOO_LONG,
INV_SYM,
NO_SOURCE_CODE
} LexErr;
/**
* LexerOut struct: the return value of lexicalAnalyzer() func
* */
typedef struct {
/**
* The list of tokens to be filled by lexicalAnalyzer(). The essential
* .. field that should be filled after successful execution of lexical
* .. analysis, ie., when encountered no errors.
* */
TokenList tokenList;
/**
* Should be filled when an error is encountered while lexical analysis.
* Otherwise, should be kept as NONE to signal success.
* Be careful that the errorLine field should also be filled with the number
* .. of the line the error was encountered when LexErr is different than
* .. NONE.
* */
LexErr lexerError;
/**
* Should be filled when LexErr is encountered. Indicates the number of line
* .. that the LexErr is encountered.
* */
int errorLine;
} LexerOut;
/**
* Deallocates the memory dynamically allocated for the members of LexerOut.
* */
void deleteLexerOut(LexerOut*);
/**
* Does lexical analysis on the given source code.
* If the analysis is successful, i.e. no errors in the given source code,
* .. returns a LexerOut with lexerError=LexErr::NONE, and a TokenList filled
* .. with tokens.
* If the analysis is NOT successful, i.e. errors are found in the given source
* .. code, returns a LexerOut with lexerError and errorLine fields properly set.
* */
LexerOut lexicalAnalyzer(char* sourceCode);
#endif