I'm (now) trying to use ANTLR4 and C # to develop a language, and so far I have been doing this. In this process, I decided to try to create a simple evaluator of mathematical expressions. In this process, I created the following ANTLR grammar for it:
grammar Calculator; @parser::members { protected const int EOF = Eof; } @lexer::members { protected const int EOF = EOF; protected const int HIDDEN = Hidden; } program : expr+ ; expr : expr op=('*' | '/') expr | expr op=('+' | '-') expr | INT | '(' expression ')' ; INT : [0-9]+ ; MUL : '*' ; DIV : '/' ; ADD : '+' ; SUB : '-' ; WS : (' ' | '\r' | '\n') -> channel(HIDDEN) ;
When I try to generate C # code with this command:
java -jar C:\...\antlr-4.2-complete.jar -DLanguage=CSharp .\...\Grammar.g4
I get these odd errors:
error(50): C:\Users\Ethan\Documents\Visual Studio 2015\Projects\CypressLang\CypressLang\Source\.\Grammar\CypressGrammar.g4:1:0: syntax error: 'รฏ' came as a complete surprise to me error(50): C:\Users\Ethan\Documents\Visual Studio 2015\Projects\CypressLang\CypressLang\Source\.\Grammar\CypressGrammar.g4:1:1: syntax error: 'ยป' came as a complete surprise to me error(50): C:\Users\Ethan\Documents\Visual Studio 2015\Projects\CypressLang\CypressLang\Source\.\Grammar\CypressGrammar.g4:1:2: syntax error: 'ยฟ' came as a complete surprise to me error(50): C:\Users\Ethan\Documents\Visual Studio 2015\Projects\CypressLang\CypressLang\Source\.\Grammar\CypressGrammar.g4:1:3: syntax error: mismatched input 'grammar' expecting SEMI
What could be causing these errors and how can I fix them? In my opinion, at the moment, Visual Studio inserts odd characters at the beginning of the file, and I cannot delete them.
source share