+/*
+ * Copyright (C) 2012
+ * Wolfgang Bumiller
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* For fte/gmgqcc */
static const char *keywords_fg[] = {
- "var",
"switch", "case", "default",
"struct", "union",
- "break", "continue"
+ "break", "continue",
+ "typedef"
};
static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]);
if (!strcmp(command, "push")) {
if (!strcmp(param, "line")) {
lex->push_line++;
- --line;
+ if (lex->push_line == 1)
+ --line;
}
else
goto unroll;
if (!strcmp(param, "line")) {
if (lex->push_line)
lex->push_line--;
- --line;
+ if (lex->push_line == 0)
+ --line;
}
else
goto unroll;
}
break;
}
+ lex_ungetch(lex, ch);
}
if (lex->flags.preprocessing) {
- lex_tokench(lex, ' '); /* ch); */
+ if (ch == '\n')
+ lex_tokench(lex, '\n');
+ else
+ lex_tokench(lex, ' '); /* ch); */
}
}
ch = ' '; /* cause TRUE in the isspace check */
int lex_do(lex_file *lex)
{
- int ch, nextch;
+ int ch, nextch, thirdch;
lex_token_new(lex);
#if 0
continue;
}
- lex->sline = lex->line;
- lex->tok.ctx.line = lex->sline;
- lex->tok.ctx.file = lex->name;
-
if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) {
return (lex->tok.ttype = ch);
}
+ lex->sline = lex->line;
+ lex->tok.ctx.line = lex->sline;
+ lex->tok.ctx.file = lex->name;
+
if (lex->eof)
return (lex->tok.ttype = TOKEN_FATAL);
if (!strcmp(v, "flush"))
{
- size_t frame;
- for (frame = 0; frame < vec_size(lex->frames); ++frame)
- mem_d(lex->frames[frame].name);
+ size_t fi;
+ for (fi = 0; fi < vec_size(lex->frames); ++fi)
+ mem_d(lex->frames[fi].name);
vec_free(lex->frames);
/* skip line (fteqcc does it too) */
ch = lex_getch(lex);
{
case '[':
case '(':
+ case ':':
+ case '?':
lex_tokench(lex, ch);
lex_endtoken(lex);
if (lex->flags.noops)
return (lex->tok.ttype = TOKEN_OPERATOR);
case ')':
case ';':
- case ':':
case '{':
case '}':
case ']':
*/
switch (ch)
{
+ /*
case '+':
case '-':
+ */
case '*':
case '/':
case '<':
nextch = lex_getch(lex);
if (nextch != '.') {
lex_ungetch(lex, nextch);
- lex_ungetch(lex, nextch);
+ lex_ungetch(lex, '.');
lex_endtoken(lex);
return (lex->tok.ttype = ch);
}
lex_tokench(lex, nextch);
} else if (ch == '-' && nextch == '>') {
lex_tokench(lex, nextch);
+ } else if (ch == '&' && nextch == '~') {
+ thirdch = lex_getch(lex);
+ if (thirdch != '=') {
+ lex_ungetch(lex, thirdch);
+ lex_ungetch(lex, nextch);
+ }
+ else {
+ lex_tokench(lex, nextch);
+ lex_tokench(lex, thirdch);
+ }
} else
lex_ungetch(lex, nextch);