Skip to content

Commit

Permalink
Catch invalid escape sequences in the lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
bras5523 committed Aug 7, 2024
1 parent 787b2eb commit ae6a152
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cognac.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ void to_exe(module_t* mod)
STRING(CC), c_source_path, "-o", exe_path,
"-Ofast", "-flto", "-s", "-w",
//"-O0", "-ggdb3", "-g", "-rdynamic",
"-lm", "-Wall", NULL
"-lm", "-Wall", "-Wpedantic", NULL
};
pid_t p = fork();
if (!p) execvp(args[0], args);
Expand Down
4 changes: 3 additions & 1 deletion src/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int last_openbrace_col;
ALLOWCHAR [A-Za-z0-9\-\?\!\'\+\/\*\>\=\<\^]
FORMAL [A-Z\-\?\!\+\/\*\>\<\=\^]
END [;\(\)$^\~[:space:]]
ESCAPES [abfnrtv\\\"]

%%
D[eE][fF]/{END} return DEF;
Expand All @@ -38,7 +39,8 @@ L[eE][tT]/{END} return LET;
{FORMAL}{ALLOWCHAR}*/{END} yylval.text=lc(strdup(yytext)); return IDENTIFIER;
{ALLOWCHAR}+:{FORMAL}{ALLOWCHAR}*/{END} yylval.text=lc(strdup(yytext)); return MODULE_IDENTIFIER;
\\{ALLOWCHAR}+/{END} yylval.text=lc(strdup(yytext+1)); return SYMBOL;
\"(\\.|[^\n"\\])*\"/{END} yylval.text=strdup(yytext); return STRING;
\"(\\{ESCAPES}|[^\n"\\])*\"/{END} yylval.text=strdup(yytext); return STRING;
\"(\\.|[^\n"\\])*\"/{END} yyerror("invalid escape sequence");
\" yyerror("unterminated string"); // TODO error message is printing with wrong column.

; return ';';
Expand Down

0 comments on commit ae6a152

Please sign in to comment.