What are these odd errors when trying to generate C # using ANTLR4?

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.

+5
source share
1 answer

Today is not a good day.

Visual Studio decided to mess with me and change my file formats to UTF-8 for all my files. All I had to do was go to File > Advanced Save Settings and change the encoding to US-ASCII. This removed the odd characters inserted at the beginning and solved (most) of my problems.

+4
source

Source: https://habr.com/ru/post/1234894/


All Articles