-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.h
74 lines (66 loc) · 2.2 KB
/
scanner.h
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
64
65
66
67
68
69
70
71
72
73
74
/**
* Implementace překladače imperativního jazyka IFJ22
*
* @file scanner.h
* @author Josef Kuchař ([email protected])
* @author Matej Sirovatka ([email protected])
* @author Tomáš Běhal ([email protected])
* @author Šimon Benčík ([email protected])
* @brief Header file for lexical analysis
*/
#ifndef __SCANNER_H__
#define __SCANNER_H__
#include <stdio.h>
#include "token.h"
enum scanner_state {
SC_CODE_START, // Start of code - should start with <?php
SC_ASSIGN, // Tokens that start with =
SC_EQUALS, // Tokens that start with ==
SC_EXCLAMATION, // Tokens that start with !
SC_NEQUALS, // Tokens that start with !=
SC_LESS, // Tokens that start with <
SC_GREATER, // Tokens that start with >
SC_VARIABLE_START, // Tokens that start with $
SC_VARIABLE, // Correct variables
SC_FUNCTION, // Tokens that start with alpha or _
SC_STRING_LIT, // Tokens that start with "
SC_DIVIDE, // Tokens that start with /
SC_MCOMMENT, // Multiline comments
SC_LCOMMENT, // Oneline comments
SC_QUESTION_MARK, // Tokens that start with ?
SC_END, // Everything after ?>
SC_HARDEND, // End of file
SC_START, // Initial state
SC_NUMBER, // Everything that begins with digit
SC_FLOAT, // Everything after decimal point
SC_EXPONENT_SIGN, // Exponent sign
SC_EXPONENT, // Exponent
SC_TYPE_OPTIONAL, // For example ?int
};
typedef struct {
enum scanner_state state; // Current state
str_t buffer; // Buffer for previous characters
FILE* input; // Input stream
size_t line_nr;
size_t col_nr;
} scanner_t;
/**
* @brief Get next token from input stream
*
* @param state Current state of the scanner
* @return Next token
*/
token_t scanner_get_next(scanner_t* state);
/**
* @brief Initialize scanner
*
* @return Initialized scanner
*/
scanner_t scanner_new(FILE* input);
/**
* @brief Free existing scanner
*
* @param scanner Scanner
*/
void scanner_free(scanner_t* scanner);
#endif // __SCANNER_H__