Aktív témák
-
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... -
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.ccutolsó 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;
} -
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;
}
; -
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 â}â tokenparserbase.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
Aktív témák
- Autós topik
- Sok memóriát spórol a neurális textúratömörítés
- Gitáros topic
- Hegesztés topic
- Milyen légkondit a lakásba?
- Jóárasított AI PC-ket szeretne látni az AMD
- Luck Dragon: Asszociációs játék. :)
- Kertészet, mezőgazdaság topik
- Magga: PLEX: multimédia az egész lakásban
- Ingatlanos topic!
- További aktív témák...
- Lenovo ThinkCentre M720q/ Dell OptiPlex 3060- 3070/ Hp EliteDesk 800 mini, micro PC-Számla/garancia
- LG 27GP95RP - 27" Nano IPS - UHD 4K - 160Hz 1ms - NVIDIA G-Sync - FreeSync Premium PRO - HDR 600
- Készpénzes számítógép PC félkonfig alkatrész hardver felvásárlás személyesen / postával korrekt áron
- 0% THM részletfizetés, beszámítás! Gamer PC, notebook, konzol, Apple termék, hardver KAMATMENTESEN!
- Lenovo Yoga Pro 9 (16IMH9) - Intel Core Ultra 9 185H, RTX 4060, 32GB, érintős (ELKELT)
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Promenade Publishing House Kft.
Város: Budapest