lte__
lte__

Reputation: 7576

bisonc++ - No production rules?

I'm trying to compile the following with bisonc++:

%baseclass-preinclude <iostream>
%lsp-needed

%token NUMBER COMMENT KEYWORD VARIABLE LOGICAND LOGICOR LOGICEQUALS DOUBLELESSER
%token DOUBLEGREATER MOD LESSER GREATER OPEN CLOSE NEGATE CURLYOPEN CURLYCLOSE SEMICOLON

%left EQUALS
%left PLUS MINUS
%left TIMES
%left DIVISION

%%

start:
    expressions
    {
        std::cout << "start -> expressions" << std::endl;
    }
;

expressions:
    // empty
    {
        std::cout << "expressions -> epsylon" << std::endl;
    }
|
    exp expressions
    {
        std::cout << "expressions -> exp expressions" << std::endl;
    }
;

exp:
    NUMBER
    {
        std::cout << "exp -> NUMBER" << std::endl;
    }
|
    COMMENT
    {
        std::cout << "exp -> COMMENT" << std::endl;
    }
|
    exp LOGICAND exp
    {
        std::cout << "exp -> exp LOGICAND exp" << std::endl;
    }
|
    exp LOGICOR exp
    {
        std::cout << "exp -> exp LOGICOR exp" << std::endl;
    }
|
    exp LOGICEQUALS exp
    {
        std::cout << "exp -> exp LOGICEQUALS exp" << std::endl;
    }
|
    exp DOUBLELESSER exp
    {
        std::cout << "exp -> exp DOUBLELESSER exp" << std::endl;
    }
|    
    exp DOUBLEGREATER exp
    {
        std::cout << "exp -> exp DOUBLEGREATER exp" << std::endl;
    }
|
    exp PLUS exp
    {
        std::cout << "exp -> exp PLUS exp" << std::endl;
    }
|
    exp MINUS exp
    {
        std::cout << "exp -> exp MINUS exp" << std::endl;
    }
|
    exp TIMES exp
    {
        std::cout << "exp -> exp EQUAL exp" << std::endl;
    }
|
    exp EQUAL exp
    {
        std::cout << "exp -> exp EQUAL exp" << std::endl;
    }
|
    exp DIVISION exp
    {
        std::cout << "exp -> exp DIVISION exp" << std::endl;
    }
|
    exp MOD exp
    {
        std::cout << "exp -> exp MOD exp" << std::endl;
    }
|
    exp LESSER exp
    {
        std::cout << "exp -> exp LESSER exp" << std::endl;
    }
|    
    exp GREATER exp
    {
        std::cout << "exp -> exp GREATER exp" << std::endl;
    }
|
    OPEN exp CLOSE
    {
        std::cout << "exp -> OPEN exp CLOSE" << std::endl;
    }
|
    NEGATE exp
    {
        std::cout << "exp -> NEGATE exp" << std::endl;
    }
|
    CURLYOPEN exp CURLYCLOSE
    {
        std::cout << "exp -> CURLYOPEN exp CURLYCLOSE" << std::endl;
    }
|
    exp SEMICOLON
    {
        std::cout << "exp -> SEMICOLON" << std::endl;
    }
|
    KEYWORD VARIABLE SEMICOLON
    {
        std::cout << "exp -> KEYWORD VARIABLE SEMICOLON" << std::endl;
    }
;

However, it keeps returning with the error

') encountered.1] Line 1: unrecognized input (`
': identifier or character-constant expected.
[bead.y: fatal] Line 23: No production rules
134950080

I obviously have some production rules and have no idea what I'm doing wrong. I've copied most of the code from another working example and modified it to my liking. What is wrong?

Upvotes: 0

Views: 588

Answers (2)

Puszta D&#225;niel
Puszta D&#225;niel

Reputation: 16

Your files are not UNIX conform (calculate.l and calculate.y) If you're operating on Windows and you use Nodepad++, just do the following:

  1. Edit/EOL conversion/UNIX format
  2. Encoding/Convert your files to UTF-8 without BOM
  3. Save and recompile with flex and bisonc++

Hope this helps

Upvotes: 0

I had the same problem, and my teacher showed me, that some of the windows editors create invisible trash in your file, so edit your file with the terminal.

  • pico yourfile.y
  • Hit an Enter before the first line, than erase it.
  • Save

Thats it!

Upvotes: 0

Related Questions