Generating a compiler from lex and yacc grammar

前端 未结 1 1296
感情败类
感情败类 2021-01-02 17:08

I\'m trying to generate a compiler so I can pass him a .c file after.

I\'ve downloaded both YACC and LEX grammars from http://www.quut.com/c/ANSI-C-grammar-y.html an

相关标签:
1条回答
  • 2021-01-02 17:32

    The version of yacc you are using is producing C code which is invalid for C99.

    The code it produces does not include declarations for the functions yylex or yyerror prior to calling them. This is producing the warnings. In the case of yyerror, it is also resulting in an implicit declaration which does not match the later actual definition.

    You can get around it by including the following at the top of the .y file:

    %{
    int yylex();
    void yyerror(const char *s);
    %}
    

    Or, you can switch to a more modern yacc compiler.

    See also this: Simple yacc grammars give an error

    0 讨论(0)
提交回复
热议问题