Loading...
Searching...
No Matches
mjs_tok.h
1/*
2 * Copyright (c) 2016 Cesanta Software Limited
3 * All rights reserved
4 */
5
6#ifndef MJS_TOK_H_
7#define MJS_TOK_H_
8
9#include "mjs_internal.h"
10
11#if defined(__cplusplus)
12extern "C" {
13#endif /* __cplusplus */
14
15struct tok {
16 int tok;
17 int len;
18 const char* ptr;
19};
20
21struct pstate {
22 const char* file_name; /* Source code file name */
23 const char* buf; /* Nul-terminated source code buffer */
24 const char* pos; /* Current position */
25 int line_no; /* Line number */
26 int last_emitted_line_no;
27 struct mbuf offset_lineno_map;
28 int prev_tok; /* Previous token, for prefix increment / decrement */
29 struct tok tok; /* Parsed token */
30 struct mjs* mjs;
31 int start_bcode_idx; /* Index in mjs->bcode at which parsing was started */
32 int cur_idx; /* Index in mjs->bcode at which newly generated code is inserted
33 */
34 int depth;
35};
36
37enum {
38 TOK_EOF,
39 TOK_INVALID,
40
41 TOK_COLON,
42 TOK_SEMICOLON,
43 TOK_COMMA,
44 TOK_ASSIGN,
45 TOK_OPEN_CURLY,
46 TOK_CLOSE_CURLY,
47 TOK_OPEN_PAREN,
48 TOK_CLOSE_PAREN,
49 TOK_OPEN_BRACKET,
50 TOK_CLOSE_BRACKET,
51 TOK_MUL,
52 TOK_PLUS,
53 TOK_MINUS,
54 TOK_DIV,
55 TOK_REM,
56 TOK_AND,
57 TOK_OR,
58 TOK_XOR,
59 TOK_DOT,
60 TOK_QUESTION,
61 TOK_NOT,
62 TOK_TILDA,
63 TOK_LT,
64 TOK_GT,
65 TOK_LSHIFT,
66 TOK_RSHIFT,
67 TOK_MINUS_MINUS,
68 TOK_PLUS_PLUS,
69 TOK_PLUS_ASSIGN,
70 TOK_MINUS_ASSIGN,
71 TOK_MUL_ASSIGN,
72 TOK_DIV_ASSIGN,
73 TOK_AND_ASSIGN,
74 TOK_OR_ASSIGN,
75 TOK_REM_ASSIGN,
76 TOK_XOR_ASSIGN,
77 TOK_EQ,
78 TOK_NE,
79 TOK_LE,
80 TOK_GE,
81 TOK_LOGICAL_AND,
82 TOK_LOGICAL_OR,
83 TOK_EQ_EQ,
84 TOK_NE_NE,
85 TOK_LSHIFT_ASSIGN,
86 TOK_RSHIFT_ASSIGN,
87 TOK_URSHIFT,
88 TOK_URSHIFT_ASSIGN,
89
90 TOK_UNARY_PLUS,
91 TOK_UNARY_MINUS,
92 TOK_POSTFIX_PLUS,
93 TOK_POSTFIX_MINUS,
94
95 TOK_NUM = 200, /* Make sure they don't clash with ascii '+', '{', etc */
96 TOK_STR,
97 TOK_IDENT,
98 TOK_KEYWORD_BREAK,
99 TOK_KEYWORD_CASE,
100 TOK_KEYWORD_CATCH,
101 TOK_KEYWORD_CONTINUE,
102 TOK_KEYWORD_DEBUGGER,
103 TOK_KEYWORD_DEFAULT,
104 TOK_KEYWORD_DELETE,
105 TOK_KEYWORD_DO,
106 TOK_KEYWORD_ELSE,
107 TOK_KEYWORD_FALSE,
108 TOK_KEYWORD_FINALLY,
109 TOK_KEYWORD_FOR,
110 TOK_KEYWORD_FUNCTION,
111 TOK_KEYWORD_IF,
112 TOK_KEYWORD_IN,
113 TOK_KEYWORD_INSTANCEOF,
114 TOK_KEYWORD_NEW,
115 TOK_KEYWORD_NULL,
116 TOK_KEYWORD_RETURN,
117 TOK_KEYWORD_SWITCH,
118 TOK_KEYWORD_THIS,
119 TOK_KEYWORD_THROW,
120 TOK_KEYWORD_TRUE,
121 TOK_KEYWORD_TRY,
122 TOK_KEYWORD_TYPEOF,
123 TOK_KEYWORD_VAR,
124 TOK_KEYWORD_VOID,
125 TOK_KEYWORD_WHILE,
126 TOK_KEYWORD_WITH,
127 TOK_KEYWORD_LET,
128 TOK_KEYWORD_CONST,
129 TOK_KEYWORD_UNDEFINED,
130 TOK_MAX
131};
132
133MJS_PRIVATE void pinit(const char* file_name, const char* buf, struct pstate*);
134MJS_PRIVATE int pnext(struct pstate*);
135MJS_PRIVATE int mjs_is_ident(int c);
136MJS_PRIVATE int mjs_is_digit(int c);
137
138#if defined(__cplusplus)
139}
140#endif /* __cplusplus */
141
142#endif /* MJS_TOK_H_ */
Definition mbuf.h:48
Definition mjs_core.h:63
Definition mjs_tok.h:21
Definition mjs_tok.h:15