Aktív témák

  • zeronero

    csendes tag

    Sziasztok flex-bisonc++ párossal kéne egy feladatot megoldani, de folyton hasonloó hibákat kapok::: Egyenlőre a hibákat, és a parserbase.h rakom ki. De ha kell akkor majd kirakom a flex és bisonc++ fileokat is...Fontos lenne, aki tud kérem tegye..

    g++ while while.cc parse.cc lex.yy.cc

    In file included from Parser.h:5,
    from while.l:6:
    Parserbase.h:27: error: expected identifier before â(â token
    Parserbase.h:27: error: expected `}' before â(â token
    Parserbase.h:27: error: expected primary-expression before â,â token
    Parserbase.h:27: error: ISO C++ forbids initialization of member âyy_startâ
    Parserbase.h:27: error: making âyy_startâ static
    Parserbase.h:27: error: ISO C++ forbids in-class initialization of non-const static member âyy_startâ
    Parserbase.h:61: error: expected unqualified-id before â}â token
    Parserbase.h:67: error: expected unqualified-id before âprivateâ
    Parserbase.h:72: error: expected unqualified-id before âprotectedâ
    Parserbase.h:94: error: expected unqualified-id before â)â token
    Parserbase.h:96: error: non-member function âvoid ABORT()â cannot have cv-qualifier
    Parserbase.h:97: error: non-member function âvoid ACCEPT()â cannot have cv-qualifier
    Parserbase.h:98: error: non-member function âvoid ERROR()â cannot have cv-qualifier
    Parserbase.h:100: error: non-member function âbool debug()â cannot have cv-qualifier
    Parserbase.h:107: error: non-member function âsize_t top__()â cannot have cv-qualifier
    Parserbase.h:109: error: expected unqualified-id before âpublicâ
    Parserbase.h:111: error: expected declaration before â}â token

    parserbase.h
    // Generated by Bisonc++ V2.4.2 on Sun Apr 11 19:06:42 2010 +0100

    #ifndef ParserBase_h_included
    #define ParserBase_h_included

    #include <vector>
    #include <iostream>

    // $insert preincludes
    #include <iostream>

    namespace // anonymous
    {
    struct PI__;
    }


    class ParserBase
    {
    public:
    // $insert tokens

    // Symbolic tokens:
    enum Tokens__
    {
    SKIPTHIS = 257,
    BEGIN,
    END,
    PROGRAM,
    VARIABLE,
    WHILE,
    DO,
    DONE,
    IF,
    THEN,
    ENDIF,
    ELSE,
    SEMICOL,
    LPAR,
    RPAR,
    TRUE,
    FALSE,
    WRITE,
    READ,
    ASSIGN,
    NUMBER,
    ENDLINE,
    INTEGER,
    BOOLEAN,
    NOT,
    OR,
    AND,
    EQUAL,
    LESS,
    MORE,
    PLUS,
    MINUS,
    MULT,
    DIV,
    MOD,
    };

    // $insert STYPE
    typedef int STYPE__;


    private:
    int d_stackIdx__;
    std::vector<size_t> d_stateStack__;
    std::vector<STYPE__> d_valueStack__;

    protected:
    enum Return__
    {
    PARSE_ACCEPT__ = 0, // values used as parse()'s return values
    PARSE_ABORT__ = 1
    };
    enum ErrorRecovery__
    {
    DEFAULT_RECOVERY_MODE__,
    UNEXPECTED_TOKEN__,
    };
    bool d_debug__;
    size_t d_nErrors__;
    size_t d_requiredTokens__;
    size_t d_acceptedTokens__;
    int d_token__;
    int d_nextToken__;
    size_t d_state__;
    STYPE__ *d_vsp__;
    STYPE__ d_val__;
    STYPE__ d_nextVal__;

    ParserBase();

    void ABORT() const;
    void ACCEPT() const;
    void ERROR() const;
    void clearin();
    bool debug() const;
    void pop__(size_t count = 1);
    void push__(size_t nextState);
    void popToken__();
    void pushToken__(int token);
    void reduce__(PI__ const &productionInfo);
    void errorVerbose__();
    size_t top__() const;

    public:
    void setDebug(bool mode);
    };

    inline bool ParserBase::debug() const
    {
    return d_debug__;
    }

    inline void ParserBase::setDebug(bool mode)
    {
    d_debug__ = mode;
    }

    inline void ParserBase::ABORT() const
    {
    throw PARSE_ABORT__;
    }

    inline void ParserBase::ACCEPT() const
    {
    throw PARSE_ACCEPT__;
    }

    inline void ParserBase::ERROR() const
    {
    throw UNEXPECTED_TOKEN__;
    }


    // As a convenience, when including ParserBase.h its symbols are available as
    // symbols in the class Parser, too.
    #define Parser ParserBase


    #endif

  • zeronero

    csendes tag

    Alábbi nyelvhez kéne:
    pogram oszto
    integer a;
    integer i;
    integer oszto;
    boolean vanoszto;
    begin
    read( a );
    vanoszto := false;
    i := 2;
    while not vanoszto and i < a do
    if a mod i = 0 then
    vanoszto := true;
    oszto := i;
    endif
    i := i+1;
    done
    if vanoszto then
    write( vanoszto );
    write( oszto );
    else
    write( vanoszto );
    endif
    end

    ---------------------------------------------------------------------------------------------------------------------------------
    while.l%option noyywrap c++

    %{
    #include <iostream>
    #include <stdlib.h>
    #include "Parser.h"
    %}

    SZAMJEGY [0-9]
    WS [ \t\n]
    BETU [a-zA-Z]

    %%

    program return Parser::PROGRAM;
    begin return Parser::BEGIN;
    end return Parser::END;
    integer return Parser::INTEGER;
    boolean return Parser::BOOLEAN;
    skip return Parser::SKIPTHIS;
    if return Parser::IF;
    then return Parser::THEN;
    else return Parser::ELSE;
    endif return Parser::ENDIF;
    while return Parser::WHILE;
    do return Parser::DO;
    done return Parser::DONE;
    read return Parser::READ;
    write return Parser::WRITE;
    ";" return Parser::SEMICOL;
    ":=" return Parser::ASSIGN;
    "=" return Parser::EQUAL;
    "<" return Parser::LESS;
    ">" return Parser::MORE;
    "+" return Parser::PLUS;
    "-" return Parser::MINUS;
    "*" return Parser::MULT;
    and return Parser::AND;
    or return Parser::OR;
    not return Parser::NOT;
    div return Parser::DIV;
    mod return Parser::MOD;
    "(" return Parser::LPAR;
    ")" return Parser::RPAR;

    {SZAMJEGY}+ return Parser::NUMBER; //std::cout << "szamkonstans: " << YYText() <<std::endl;
    true return Parser::TRUE;
    false return Parser::FALSE;

    "#".*\n // nem kell semmit csinalni

    {BETU}({BETU}|{SZAMJEGY}|_)* return Parser::VARIABLE; //std::cout << "azonosito: " << YYText() <<std::endl;

    {WS}+ // feher szokozok: semmi teendo

    . {
    std::cerr << "Lexikalis hiba!" << std::endl;
    exit(0);
    }

    %%

    WHILE.Y-----------------------------------------------------------------------------------------------
    %baseclass-preinclude <iostream>
    %stype int

    %token SKIPTHIS
    %token BEGIN END PROGRAM VARIABLE
    %token WHILE DO DONE IF THEN ENDIF ELSE SEMICOL LPAR RPAR TRUE FALSE WRITE READ ASSIGN
    %token NUMBER
    %token ENDLINE
    %token INTEGER
    %token BOOLEAN

    %left NOT
    %left OR
    %left AND

    %left EQUAL
    %left LESS MORE
    %left PLUS MINUS
    %left MULT DIV MOD

    %%

    start:
    PROGRAM VARIABLE declarations blokk
    {
    std::cout << "start -> PROGRAM VARIABLE declarations blokk" << std::endl;
    }
    ;


    blokk:
    BEGIN program_lines END
    {
    std::cout << "blokk -> BEGIN program_lines END" << std::endl;
    }
    ;



    program_lines:
    program_line
    {
    std::cout << "program_line -> program_line" << std::endl;
    }
    |
    program_line program_lines
    {
    std::cout << "program_line -> program_line program_lines" << std::endl;
    }
    ;

    program_line:
    SKIPTHIS ENDLINE
    {
    std::cout << "program_line -> SKIPTHIS ENDLINE" << std::endl;
    }
    |
    statement
    {
    std::cout << "program_line -> statement" << std::endl;
    }
    |
    ENDLINE
    {
    std::cout << "program_line -> ENDLINE" << std::endl;
    }
    |
    function
    {
    std::cout << "program_line -> function ENDLINE" << std::endl;
    }
    ;


    statement:
    WHILE condition DO program_lines DONE
    {
    std::cout << "statement-> WHILE condition DO program_lines DONE" << std::endl;
    }
    |
    IF condition THEN program_lines ENDIF
    {
    std::cout << "statement -> IF condition THEN program_lines ENDIF" << std::endl;
    }
    |
    IF condition THEN program_lines ELSE program_lines ENDIF
    {
    std::cout << "statement -> IF condition THEN program_lines ELSE program_lines ENDIF" << std::endl;
    }
    ;
    declarations:
    declaration
    {
    std::cout << "declarations -> declaration" << std::endl;
    }
    |
    declaration declarations
    {
    std::cout << "declarations -> declaration declarations" << std::endl;
    }
    ;
    declaration:
    INTEGER VARIABLE SEMICOL
    {
    std::cout << "declaration -> INTEGER VARIABLE SEMICOL" << std::endl;
    }
    |
    BOOLEAN VARIABLE SEMICOL
    {
    std::cout << "declaration -> BOOLEAN VARIABLE SEMICOL" << std::endl;
    }

    ;

    condition:
    LPAR condition RPAR
    {
    std::cout << "condition -> LPAR condition RPAR" << std::endl;
    }
    |
    VARIABLE
    {
    std::cout << "condition -> VARIABLE" << std::endl;
    }
    |
    TRUE
    {
    std::cout << "condition -> TRUE" << std::endl;
    }
    |
    FALSE
    {
    std::cout << "condition -> FALSE" << std::endl;
    }
    |
    exp EQUAL exp
    {
    std::cout << "condition -> exp EQUAL exp" << std::endl;
    }
    |
    exp LESS exp
    {
    std::cout << "condition -> exp LESS exp" << std::endl;
    }
    |
    exp MORE exp
    {
    std::cout << "condition -> exp MORE exp" << std::endl;
    }
    |
    condition AND condition
    {
    std::cout << "condition -> condition AND condition" << std::endl;
    }
    |
    condition OR condition
    {
    std::cout << "condition -> condition OR condition" << std::endl;
    }
    |
    NOT condition
    {
    std::cout << "condition -> NOT condition" << std::endl;
    }
    ;

    function:
    WRITE LPAR VARIABLE RPAR SEMICOL
    {
    std::cout << "function -> WRITE LPAR VARIABLE RPAR SEMICOL" << std::endl;
    }
    |
    READ LPAR VARIABLE RPAR SEMICOL
    {
    std::cout << "function -> READ LPAR VARIABLE RPAR SEMICOL" << std::endl;
    }
    |
    VARIABLE ASSIGN exp SEMICOL
    {
    std::cout << "function -> VARIABLE ASSIGN exp" << std::endl;
    }
    ;
    exp:
    VARIABLE
    {
    std::cout << "exp -> VARIABLE" << std::endl;
    }
    |
    NUMBER
    {
    std::cout << "exp -> NUMBER" << std::endl;
    }
    |
    exp MOD exp
    {
    std::cout << "exp -> exp MOD 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 MULT exp
    {
    std::cout << "exp -> exp MULT exp" << std::endl;
    }
    |
    exp DIV exp
    {
    std::cout << "exp -> exp DIV exp" << std::endl;
    }
    ;

  • Jester01

    veterán

    válasz zeronero #1 üzenetére

    In file included from Parser.h:5,
    from while.l:6:

    Hogy került a while.l a fordítóhoz? Ugye nem akarod a bemeneti fájlokat is c++ -ként lefordítani? :Y

    Jester

  • zeronero

    csendes tag

    rm -rf while lex.yy.cc Parserbase.h parse.cc
    flex while.l
    bisonc++ while.y
    g++ -o while while.cc parse.cc lex.yy.cc

    utolsó lépésnél dobja az errort.
    While.cc
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include "Parser.h"
    #include <FlexLexer.h>

    using namespace std;

    yyFlexLexer *fl;

    int Parser::lex()
    {
    int ret = fl->yylex();
    stringstream ss;
    ss << fl->YYText();
    ss >> d_val__;
    return ret;
    }

    int main( int argc, char* argv[] )
    {
    if( argc != 2 )
    {
    cerr << "Egy parancssori argumentum kell!" << endl;
    return 1;
    }
    ifstream in( argv[1] );
    if( !in )
    {
    cerr << "Nem tudom megnyitni: " << argv[1] << endl;
    return 1;
    }

    fl = new yyFlexLexer(&in, &cout);
    Parser pars;
    cout<<"Végeredmény: "<<pars.parse() <<endl;
    return 0;
    }

    [ Szerkesztve ]

  • n21ovi

    csendes tag

    válasz zeronero #4 üzenetére

    Hello!

    Ford prog beadandó? :)

    Amúgy nekem ugyanez a hiba adódott, és nem tudok
    rájönni miért... Neked sikerült azóta?

  • n21ovi

    csendes tag

    válasz n21ovi #5 üzenetére

    Ok, na megvan a megoldás...
    Nem szereti a bison a "BEGIN" tokent... írd át vmi másra és menni fog!

  • zeronero

    csendes tag

    Köszi , de azota megoldottam, csak átírtam tokeneket pl. D_BEGIN -re és utána már jo volt.
    Most viszont, az automatikus bead. kiért. nem szereti valamiért... lex-es résznél kiakad, mondván, hogy nem jelezi a hibát...pedig az ajánlott példaprg. egészítettem ki...

  • facultx

    csendes tag

    válasz zeronero #7 üzenetére

    mondjuk ahogy nézem az általad kívánt nyelvet nem fogadja el mert a valtozo:=false estetet nem veszi figyelembe. ugyanis neked értékadáskor csak expression van definiálva, a logikai állítások pedig conditionok.

  • facultx

    csendes tag

    konkrétabban:

    "Gyakori hiba, hogy külön nyelvtani jelet vezettek be az egész kifejezés és a logikai kifejezés leírására. Ilyen módon biztosan konfliktusok lesznek a nyelvtanban! (Egyetlen változónevet melyikre is kellene redukálni?) A típusellenőrzés a szemantikus elemzés feladata lesz, most tehát az egész és logikai kifejezéseket együtt kell kezelni. " ( http://deva.web.elte.hu/ )

  • sany80

    csendes tag

    Én is a beadandón ügyködöm és bajban vagyok vele. Alaposan belezavarodtam ha valaki segítene hálás lennék.

    ezt dobja ki hibaüzenetként:

    [Warning] Line 46: (compiler.y) In production rule
    `4: declaration -> UNSIGNED IDENT #0001 '
    cannot determine default type of $0
    [Warning] Line 64: (compiler.y) In production rule
    `6: declaration -> BOOL IDENT #0002 '
    cannot determine default type of $0
    [Error 1] Line 90: (compiler.y) unrecognized input (`(') encountered
    Automatikus tesztelo: Hiba van a bisonc++ forrasfajljaban.

    A tanár tutorial-ja alapján csináltam de most már nem látom a fától az erdőt.

    Ez meg a file:

    %baseclass-preinclude "semantics.h"
    %lsp-needed

    %token UNSIGNED;
    %token BOOL;
    %token TRUE;
    %token FALSE;
    %token NUMBER;
    %token <szoveg> IDENT;
    %token ASSIGN;

    %union
    {
    std::string *szoveg;

    }

    %%

    start:
    declarations assignments
    ;

    declarations:
    // ures
    |
    declaration declarations
    ;

    declaration:
    UNSIGNED IDENT
    {
    szimbolumtabla[*$2] = var_data( d_loc__.first_line, unsigned );
    }
    {
    std::cout << *$2 = var_data( d_loc__.first_line, unsigned );

    if( szimbolumtabla.count(*$2) > 0 )
    {
    std::stringstream ss;
    ss << "Ujradeklaralt valtozo: " << *$2 << ".\n"
    << "Korabbi deklaracio sora: " << szimbolumtabla[*$2].decl_row << std::endl;
    error( ss.str().c_str() );
    }
    delete $2;
    }
    |
    BOOL IDENT
    {
    szimbolumtabla[*$2] = var_data( d_loc__.first_line, bool );
    }
    {
    std::cout << *$2 = var_data( d_loc__.first_line, bool );

    if( szimbolumtabla.count(*$2) > 0 )
    {
    std::stringstream ss;
    ss << "Ujradeklaralt valtozo: " << *$2 << ".\n"
    << "Korabbi deklaracio sora: " << szimbolumtabla[*$2].decl_row << std::endl;
    error( ss.str().c_str() );
    }
    delete $2;

    }
    ;

    assignments:
    // ures
    |
    assignment assignments
    ;

    assignment:
    IDENT ASSIGN expr
    {
    if ( IDENT != szimbolumtabla )
    cout << "azonosito nincs deklaralva";
    }

    ;

    expr:
    IDENT

    {
    if ( IDENT != szimbolumtabla )
    cout << "azonosito nincs deklaralva";
    }
    if( szimbolumtabla[*$1].var_type != *$3 ) //itt van az a bizonyos 90 sor
    {
    error( "Tipushibas ertekadas.\n" );
    $$ = new type(szimbolumtabla[*$1].var_type);
    }
    |
    NUMBER

    if( szimbolumtabla unsigned != *$3 )
    {
    error( "Tipushibas ertekadas.\n" );
    }
    $$ = new type(unsigned);
    |
    TRUE

    if( szimbolumtabla bool != *$3 )
    {
    error( "Tipushibas ertekadas.\n" );
    }
    $$ = new type(bool);
    |
    FALSE

    if( szimbolumtabla bool != *$3 )
    {
    error( "Tipushibas ertekadas.\n" );
    }
    $$ = new type(bool);
    ;

Aktív témák