NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Sursa -> Analizor lexical (LEX - scanner) -> token/lexem -> Analiza sintactica (YACC-Parser) ->...
gcc -o out car.c ident.c lex.c lexem.c numar.c
Scris in myC ceva => ./out myC

in l3.
def/dec/
%%
reguli translator - bazate pe regular expressions + actiuni exprimate prin cod C
{D} urmat de o actiune (block C)
%%
cod utilizator - optional

in l3.
lex const.l => creeaza lex.yy.c
lex.yy.c = analizorul generat de lex
Sursa -> Analizor lexical (LEX - scanner) -> token/lexem -> Analiza sintactica (YACC-Parser) ->...
gcc -o out car.c ident.c lex.c lexem.c numar.c
Scris in myC ceva => ./out myC

.l --> lex const.l --> lex.yy.c (are functia yylex()) -->

scriem un main.c in care punem functia main() si o functie int yywrap() {return 1;}
in main apelam yylex();
gcc -o out lex.yy.c main.c

gcc -o outhist lexhisto.yy.c main2.c

yacc-->y.tab.c
yacc defineste lista de tokeni.
yacc -d ===> se mai creeaza si y.tab.h (pe asta il includem intr-un fisier de descriere a analizorului lexical
functia principala din y.tab.c (sursa analizorului lex) este yyparser
y.tab.h defineste lista de definitii de tokeni

1 scan.l
2. gram.y
3 yacc -d
4. #include ...
5. lex => lex.yy.c
6. crearea lui main
7. gcc
8. ./ ...
.l --> lex const.l --> lex.yy.c (are functia yylex()) -->

LABORATOR 3
- O secventa de caractere intre [] defineste o CLASA DE CARACTERE
lex va genera un lex.yy.c prin comanda lex specificatii_lex
Fisierul sursa (cu programul pe care vrem sa-l analizam) va fi input pentru lex.yy.c

To DO:
Sa scriem specificatii pt. Sa primeasca un flux de caractere din care sa elimine SPACE si TAB de la sfarsitul liniei
Daca exista mai multe SPACE-uri, sa le inlocuiasca cu un singur SPACE

+ 1 sau mai multe
* 0 sau mai multe
READ: http://dinosaur.compilertools.net/ LEX si YACC online manual

2. Specificatie LEX ce sa permita reluarea unui flux de intrare in care identificati nr. intregi pozitive divizibile cu 7
si le incrementati cu 5.

3. Calculator m_n_op
a_op_b

lex myconst.l
gcc -o lab3 lex.yy.c main.c
./lab3
[mail]


---------------------------------------------------------
T [t]
N [n]
D [0-9]
E [DEde][+]?{D}+
O [-+/*]

%%
{D}+ printf("%d", check());
{D}+"."{D}*({E})? |
{D}*"."{D}+({E})? |
{D}+{E} printf("real");
{T}+ printf("");
{N}+ printf("");
[ ]+ printf(" ");
{D}+{O}+{D} printf(" %d", calc());
%%
int check(){
int nr=0, i=0;
for (i=0; i<yyleng; i++) {
nr = nr*10+((yytext[i])-'0');
}
if (nr%7 == 0)
return nr+5;
}

int calc() {
int a=0, b=0, i=0;
char op;

for (i=0; i<yyleng && yytext[i] > 47 && yytext[i] < 58; i++) {
a = a*10+(yytext[i]-'0');
}
op = yytext[i++];
int j=i;
for (j=i; j<yyleng; j++) {
b = b*10+(yytext[j]-'0');
}
printf("%d %c %d =", a, op, b);
switch(op) {
case '+': return a+b;
case '-': return a-b;
case '*': return a*b;
case '/': return a/b;
}

}

_________________________________________________
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.