diff options
| author | Mustafa Quraish <[email protected]> | 2022-02-06 21:18:04 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-02-06 21:19:45 -0500 |
| commit | 0dd893225bebffd9a25f1345ec49922aa961b882 (patch) | |
| tree | e843cef529e0e1d6cdba85c2268742e3aed68749 /compiler/tokens.cup | |
| parent | Add some information to the README (diff) | |
| download | cup-0dd893225bebffd9a25f1345ec49922aa961b882.tar.xz cup-0dd893225bebffd9a25f1345ec49922aa961b882.zip | |
[C]: Add `here` keyword that evaluates to a string with it's location
It's not really a keyword like the other ones, but just handled
completely at the lexer level since it already knows the location of the
token, so it injects a string literal instead.
We also use this in the self-hosted compiler now for better error
reporting for where the error happened internally.
Diffstat (limited to 'compiler/tokens.cup')
| -rw-r--r-- | compiler/tokens.cup | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/compiler/tokens.cup b/compiler/tokens.cup index cf1b011..9c00a8a 100644 --- a/compiler/tokens.cup +++ b/compiler/tokens.cup @@ -185,16 +185,18 @@ fn location_print(loc: Location *) { putu(loc.col + 1); } -fn die_loc2(loc: Location*, msg1: char *, msg2: char *) { +fn die_loc2(eloc: char*, loc: Location*, msg1: char *, msg2: char *) { location_print(loc); puts(": "); puts(msg1); putsln(msg2); + puts("Note: Error happened here: "); + putsln(eloc); exit(1); } -fn die_loc(loc: Location*, msg: char *) { - die_loc2(loc, msg, ""); +fn die_loc(eloc: char*, loc: Location*, msg: char *) { + die_loc2(eloc, loc, msg, ""); } fn token_from_type(token: Token*, typ: int, loc: Location *) { |