Aktív témák
-
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;
}
;
Aktív témák
- HP Elitebook 840 G8, I7-1185G7, 32 GB RAM, 512 SSD (MAGYAR VILÁGÍTÓ BILLENTYŰZET)
- Eladó használt Gigabyte AMD Radeon HD 6750 videókártya
- GIGABYTE GTX 1060 Mini ITX OC 3GB videókártya
- Új ASUS VivoBook 15 X1504VA - 15,6"FHD IPS - i5-1335U - 16GB - 512GB - Win11 - 1,5 év gari - MAGYAR
- Eladó ASUS ROG Zephyrus G14 GA401Q + teljes gamer szett --csere is érdekel
- Xiaomi 11 Lite 5G NE 256GB Kártyafüggetlen 1Év Garanciával
- Csere-Beszámítás! RTX Gamer Számítógép PC Játékra! I5 12400F / RTX 3070 / 32GB DDR4 / 1TB SSD
- Telefon felvásárlás!! iPhone 11/iPhone 11 Pro/iPhone 11 Pro Max
- AKCIÓ! "ÚJ" Microsoft Surface 5 13,5 notebook - i5 1235U 8GB RAM 256GB SSD Intel Iris Xe IGP 27% áfa
- Bomba ár! Dell Precision M4600 - i7-QM I 8GB I 500GB I Nvidia I HDMI I 15,6" FHD I W10 I Gari!
Állásajánlatok
Cég: Promenade Publishing House Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest