diff --git a/src/main/java/dk/camelot64/kickc/parser/CParser.java b/src/main/java/dk/camelot64/kickc/parser/CParser.java index c5a3dd321..3a8f1634b 100644 --- a/src/main/java/dk/camelot64/kickc/parser/CParser.java +++ b/src/main/java/dk/camelot64/kickc/parser/CParser.java @@ -98,7 +98,7 @@ public class CParser { int charPositionInLine, String msg, RecognitionException e) { - final CommonToken offendingToken = (CommonToken) offendingSymbol; + final Token offendingToken = (Token) offendingSymbol; StatementSource source = new StatementSource(offendingToken.getInputStream().getSourceName(), line, charPositionInLine, null, -1, -1); throw new CompileError("Error parsing file: " + msg, source); } diff --git a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java index 9da9f27bf..390f2297b 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java +++ b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java @@ -929,6 +929,11 @@ public class TestProgramsFast extends TestPrograms { compileAndCompare("cstyle-decl-function.c"); } + @Test + public void testPreprocessor15() throws IOException { + assertError("preprocessor-15.c", "Error parsing file: extraneous input 'X' "); + } + @Test public void testPreprocessor14() throws IOException { compileAndCompare("preprocessor-14.c"); diff --git a/src/test/kc/preprocessor-15.c b/src/test/kc/preprocessor-15.c new file mode 100644 index 000000000..075a96714 --- /dev/null +++ b/src/test/kc/preprocessor-15.c @@ -0,0 +1,7 @@ +// Demonstrates a problem with the preprocessor where the syntax error in the number results in an exception instead of a readable error + +#define POKE(X,Y) (*(unsigned char*)(X))=Y + +void main() { + POKE(0x123X,1); +} \ No newline at end of file