-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.h
More file actions
31 lines (25 loc) · 1.3 KB
/
lexer.h
File metadata and controls
31 lines (25 loc) · 1.3 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
// header file for the lexer module
#ifndef LEXER_H
#define LEXER_H
#define TEST // uncomment this line to run the self-grader
// the TokenType enumerated data type represents all possible token types in a JACK program, ERR is used to indicate a lexical error
typedef enum {RESWORD, ID , INT , SYMBOL, STRING, EOFile, ERR} TokenType;
// the LexErrCodes enumerated data type represent error codes for all possible lexical errors that can occur during tokenisation
// EofInCom: End of file in comment
// NewLnInStr: New line in string literal
// EofInStr: End of file in string literal
// IllSym: Illegal symbol in source file
typedef enum {EofInCom , NewLnInStr , EofInStr , IllSym, NoLexErr} LexErrCodes;
// a structure for representing tokens
typedef struct {
TokenType tp; // the type of this token, e.g. INT
char lx[128]; // the lexeme (string) of the token, e.g. "34". If the lexer encounters an error this string is set to an error message
int ec; // If the lexer encounters an error this value is set to the proper error code (see the above enumerated list of errors)
int ln; // the line number of the source file where the token exists
char fl[32]; // the file (name) in which this token exists
} Token;
int InitLexer (char* file);
Token GetNextToken ();
Token PeekNextToken ();
int StopLexer ();
#endif