0% found this document useful (0 votes)
19 views5 pages

Compilers-2 Project 3

Uploaded by

Rutheesh Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Compilers-2 Project 3

Uploaded by

Rutheesh Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Compilers-2

Project
Lexer and Parser
Team-9
Red Panda
Lexer
Lexer identifies various tokens and passes them to the parser. The following is a code
snippet of the lexer.

"<int>"|"<float>" {/*printf("%s",yytext);*/ return MATRIX_TYPE;}


"true"|"false" {/*printf("%s",yytext);*/ return BOOL;}
"NULL" {/*printf("%s",yytext);*/ return NUL;}
"++"|"--" {/*printf("%s",yytext);*/ return POST;}
"<<"|">>" {/*printf("%s",yytext);*/ return SHIFT;}
"**"|"%"|"*"|"/"|"+"|"-" {/*printf("%s",yytext);*/ return ARTH;}
"<="|">="|"=="|"<"|">" {/*printf("%s",yytext);*/ return COMP;}
"AND"|"OR" {/*printf("%s",yytext);*/ return LOG;}
"=" {/*printf("%s",yytext);*/ return ASSGN;}
Parser In our language, any program
shall have code block followed
by main like a main function in
C/C++, but it is not a function
that return a value. All normal
S : Decl Main Decl {} programming constructs are
; present in our language. In
Decl : addition to them domain
| GlobalDecl Decl{} specific classes like dataframe
| FuncDecl Decl and matrix are present. The
; following are first few rules of
Main: MAIN OBRACE stmt CBRACE our language.
Parser stmt : stmtL OBRACE stmt CBRACE stmt {}
| stmtL {}
;
The following rules illustrate how we incorporated
scopes in our language.
stmtL : stmtD stmtL {}
| {}
;
stmt generates list of statements with scopes included,
it can be simply group of statements which is
identified by second rule of stmt, or it can begin with a // these are different types of single
group of statements and then a scope begins followed statements
by stmt. stmtD : declstmt
| exprstmt
| callstmt
| condstmt
| loop
| returnstmt
| printstmt
| break
| continue
;
Parser
DF_DECL: DF ID ASSGN DF OBRAK CBRAK SEMICOL

The following is a special type of


DF_SELECT : SELECT OBRAK ID COMMA ID COMMA pred statement, that is applicable to only
CBRAK classes of type dataframe, we call this
DF_DELETEROW : DELETE OBRAK ID COMMA pred CBRAK select statement, it used to select rows
of a dataframe that satisfy some
DF_UPDATECOL : UPDATE OBRAK ID COMMA ID COMMA conditions.
pred COMMA rhs CBRAK

| UPDATE OBRAK ID COMMA ID COMMA


NUL COMMA rhs CBRAK

You might also like