error while compiling Yacc and lex files - yacc

I've tried to do something with Lex and Yacc, but I had this error:
calc.l:4:8: error expected ‘=’ ‘ ’ ‘ ’ ‘asm’ or ‘__attribute__’ before numeric constant
calc.y: In function 'yyparse':
calc.y:11:6: error: expected expression before '[' token
calc.y:11:12: error: expected expression before '}' token
I used this lines to generate the files:
yacc -d calc.y
flex calc.l
and then i used gcc for both generated C files.
sorry right now I'm not on my computer i only have the error lines saved, so i only want to know whether this errors are because I forgot something ?
P.S: sorry i couldn't come with the code, but I'll try to edit thi later.

Related

What do the numbers mean in antlr4 error and warning messages ?

Can someone point to the antlr 4 documentation or tell me about the numbers in error and warning messages ?
I have a lexer file and a parser file that is generating this warning:
warning(125): Sybase\SybTSqlParser.g4:1084:158: implicit definition of token R in parser
The numbers "1084:158" do not seem to correspond to a line number or character count.
After some inspiration by Bart Kiers jogging some old memory cells this is the explanation:
When compiling independent lexer and parser files, the lexer files lines are concatenated to the parser file line numbers.
If the lexer has 10 lines and the error is detected on parser file line 25, the error is reported on line 35.

Antlr4 No viable alternative at input symbols

I'm implementing a simple program walker grammar and I get this common error in multiple lines. I think it is caused by same reason, but I'm new to antlr so I couldn't figure it out.
For example, in this following code snippet:
program
: (declaration)*
(statement)*
EOF!
;
I got error:
No viable alternative at input '!'
after EOF, and I got a similar error with:
declaration
: INT VARNUM '=' expression ';'
-> ^(DECL VARNUM expression)
;
I got the error:
No viable alternative at input '->'
After reading other questions, I know that matching one token with multiple definitions can cause this problem. But I haven't test it with any input yet, I got this error in intelliJ. How can I fix my problem?
This is ANTLR v3 syntax, you're trying to compile it with ANTLR v4, which won't work.
Either downgrade to ANTLR v3, or use v4 syntax. The difference comes from the fact that v4 doesn't support automatic AST generation, and you're trying to use AST construction operators, which were removed.
The first snippet only requires you to remove the !. Parentheses aren't necessary.
program
: declaration*
statement*
EOF
;
As for the second one, remove everything after the ->:
declaration
: INT VARNUM '=' expression ';'
;
If you need to build an AST with v4, see my answer here.

IDEA javadoc generator - ignore errors

When I trying to generate javadoc - I get some meaningless errors like encoding error in non-javadoc comments. Maybe exists some command-line argument or something for ignore errors and generate docs anyway?
Error example (It's even not in javadocs, just inline Cyrillic comment)
GroupsSorter.java:83: error: unmappable character for encoding Cp1251
//Р?тоговый СЃРїРёСЃРѕРє
^

Internal EBCDIC support for ANTLR 3.1.3?

I'm trying to use ANTLR 3.1.3 on a system with local EBCDIC char set
Even a simple grammar like this:
lexer grammar test;
GENERIC_ID
: (LETTER)*
;
fragment LETTER
: 'a' .. 'z'
;
results in these errors during the initial compile (java org.antlr.Tool test.g):
error(10): internal error: problem parsing group <unknown>: line 1:1: unexpected char: 0x7 : line 1:1: unexpected char: 0x7
org.antlr.stringtemplate.language.GroupLexer.nextToken(GroupLexer.java:233)
antlr.TokenBuffer.fill(TokenBuffer.java:69)
antlr.TokenBuffer.LA(TokenBuffer.java:80)
antlr.LLkParser.LA(LLkParser.java:52)
antlr.Parser.match(Parser.java:210)
org.antlr.stringtemplate.language.GroupParser.group(GroupParser.java:120)
org.antlr.stringtemplate.StringTemplateGroup.parseGroup(StringTemplateGroup.java:792)
org.antlr.stringtemplate.StringTemplateGroup.<init>(StringTemplateGroup.java:274)
org.antlr.stringtemplate.PathGroupLoader.loadGroup(PathGroupLoader.java:67)
org.antlr.stringtemplate.StringTemplateGroup.loadGroup(StringTemplateGroup.java:969)
org.antlr.stringtemplate.StringTemplateGroup.loadGroup(StringTemplateGroup.java:955)
org.antlr.codegen.CodeGenerator.loadTemplates(CodeGenerator.java:198)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:292)
org.antlr.Tool.generateRecognizer(Tool.java:607)
org.antlr.Tool.process(Tool.java:429)
org.antlr.Tool.main(Tool.java:91)
error(10): internal error: test.g : java.lang.IllegalArgumentException: Can't find template outputFile.st; group hierarchy is [null]
org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:507)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:392)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:404)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:314)
org.antlr.Tool.generateRecognizer(Tool.java:607)
org.antlr.Tool.process(Tool.java:429)
org.antlr.Tool.main(Tool.java:91)
the grammar file seems to be processed appropriately, but it appears something internal is causing some problems. No matter what chars I use in the grammar file, the illegal char always seems to be 0x7.
Can I not compile ANTLR on a system with local EBCDIC char set? Any suggestions?
Update: it appears the problem lies in the template files (.stg files). If I convert the files in the codegen/templates directory to EBCDIC (also ANTLRCore.sti) then the compilation seems to complete. Is there a way to tell java/antlr to not read these files in local encoding? Either that or are these template files available in other encodings? Otherwise I am forced to convert by hand and replace each one

why am I getting an error in the identification division?

The following code :
IDENTIFICATION DIVISION.
PROGRAM-ID. tester.
PROCEDURE DIVISION.
greet_program.
DISPLAY "HELLO WORLD !".
STOP RUN.
produces a compiler error which says : Error: syntax error, unexpected WORD, expecting PROGRAM_ID
I am unable to spot the error. Where is it ?
The errors with the program are listed here at ideone
You are compiling using the option of a traditional "fixed" Cobol layout.
That means you need to start each line with seven blanks.
You should have asked yourself why the first error messages referred to column seven. You could also have found some sample Cobol cobde and compare it to yours. Other people you can find with Google who've done the same thing.