5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is furnished to do
10 * so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 static const char *const parse_punct[] = {
28 "&&", "||", "<=", ">=", "==", "!=", ";", ",", "!", "*",
29 "/" , "(" , "-" , "+" , "=" , "[" , "]", "{", "}", "...",
30 "." , "<" , ">" , "#" , "&" , "|" , "$", "@", ":", NULL
32 * $,@,: are extensions:
33 * $ is a shorter `self`, so instead of self.frags, $.frags
35 * : is compiler builtin functions
39 int parse(struct lex_file *file) {
41 while ((token = lex_token(file)) != ERROR_LEX && \
42 token != ERROR_COMPILER && \
43 token != ERROR_INTERNAL && \
44 token != ERROR_PARSE && \
45 token != ERROR_PREPRO && file->length >= 0) {
48 token = lex_token(file);
49 while ((token == ' ' || token == '\n') && file->length >= 0)
50 token = lex_token(file);
53 error(ERROR_PARSE, "Expected `(` after if\n", "");
56 /* TODO: Preprocessor */
58 token = lex_token(file);
59 token = lex_token(file);
60 token = lex_token(file);
61 token = lex_token(file);
62 token = lex_token(file);
63 token = lex_token(file);
66 /* PUNCTUATION PARSING BEGINS */
68 token = lex_token(file);
69 if (token == '&') { /* && */
70 token = lex_token(file);
71 printf("--> LOGICAL AND\n");
74 printf("--> BITWISE AND\n");
77 token = lex_token(file);
78 if (token == '|') { /* || */
79 token = lex_token(file);
80 printf("--> LOGICAL OR\n");
83 printf("--> BITWISE OR\n");
86 token = lex_token(file);
87 if (token == '=') { /* != */
88 token = lex_token(file);
89 printf("--> LOGICAL NOT EQUAL\n");
92 printf("--> LOGICAL NOT\n");
95 token = lex_token(file);
96 if (token == '=') { /* <= */
97 token = lex_token(file);
98 printf("--> LESS THAN OR EQUALL\n");
101 printf("--> LESS THAN\n");
104 token = lex_token(file);
105 if (token == '=') { /* >= */
106 token = lex_token(file);
107 printf("--> GREATER THAN OR EQUAL\n");
110 printf("--> GREATER THAN\n");
113 token = lex_token(file);
114 if (token == '=') { /* == */
115 token = lex_token(file);
116 printf("--> COMPARISION \n");
119 printf("--> ASSIGNMENT\n");
122 token = lex_token(file);
123 printf("--> FINISHED STATMENT\n");
126 token = lex_token(file);
127 printf("--> SUBTRACTION EXPRESSION\n");
130 token = lex_token(file);
131 printf("--> ASSIGNMENT EXPRRESSION\n");
138 // "&&", "||", "<=", ">=", "==", "!=", ";", ",", "!", "*",
139 //"/" , "(" , "-" , "+" , "=" , "[" , "]", "{", "}", "...",
140 //"." , "<" , ">" , "#" , "&" , "|" , "$", "@", ":", NULL