Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
8822dc45
Commit
8822dc45
authored
Dec 22, 2016
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unary operators and parentheses
parent
4aeeaff0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
0 deletions
+35
-0
src/ast.cpp
src/ast.cpp
+20
-0
src/ast.h
src/ast.h
+8
-0
src/lexer.l
src/lexer.l
+2
-0
src/parser.yy
src/parser.yy
+5
-0
No files found.
src/ast.cpp
View file @
8822dc45
...
...
@@ -85,6 +85,26 @@ void Binop::print_ast(std::ostream &out, unsigned int depth) const
right
->
print_ast
(
out
,
depth
+
1
);
}
void
Unop
::
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
)
const
{
std
::
string
indent
(
depth
,
' '
);
std
::
string
opstr
;
switch
(
op
)
{
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
LNOT
:
opstr
=
"!"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
BNOT
:
opstr
=
"~"
;
break
;
default:
opstr
=
"???"
;
break
;
}
out
<<
indent
<<
opstr
<<
std
::
endl
;
expr
->
print_ast
(
out
,
depth
+
1
);
}
void
ExprStatement
::
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
)
const
{
std
::
string
indent
(
depth
,
' '
);
...
...
src/ast.h
View file @
8822dc45
...
...
@@ -42,6 +42,14 @@ public:
int
op
;
};
class
Unop
:
public
Expression
{
public:
Unop
(
int
op
,
Expression
*
expr
)
:
expr
(
expr
),
op
(
op
)
{
}
void
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
=
0
)
const
override
;
Expression
*
expr
;
int
op
;
};
class
Statement
:
public
Node
{
};
using
StatementList
=
std
::
vector
<
Statement
*>
;
...
...
src/lexer.l
View file @
8822dc45
...
...
@@ -34,6 +34,8 @@ using namespace ebpf::bpftrace;
"}" { return Parser::make_RBRACE(loc); }
"[" { return Parser::make_LBRACKET(loc); }
"]" { return Parser::make_RBRACKET(loc); }
"(" { return Parser::make_LPAREN(loc); }
")" { return Parser::make_RPAREN(loc); }
\//[ \t\n\r]*[\/\{] { return Parser::make_ENDPRED(loc); } // If "/" is followed by "/" or "{", choose ENDPRED, otherwise DIV
"," { return Parser::make_COMMA(loc); }
"=" { return Parser::make_ASSIGN(loc); }
...
...
src/parser.yy
View file @
8822dc45
...
...
@@ -43,6 +43,8 @@ void yyerror(ebpf::bpftrace::Driver &driver, const char *s);
RBRACE "}"
LBRACKET "["
RBRACKET "]"
LPAREN "("
RPAREN ")"
ENDPRED "end predicate"
COMMA ","
ASSIGN "="
...
...
@@ -119,6 +121,7 @@ stmt : expr { $$ = new ast::ExprStatement($1); }
expr : INT { $$ = new ast::Integer($1); }
| var { $$ = $1; }
| "(" expr ")" { $$ = $2; }
| expr EQ expr { $$ = new ast::Binop($1, token::EQ, $3); }
| expr NE expr { $$ = new ast::Binop($1, token::NE, $3); }
| expr LE expr { $$ = new ast::Binop($1, token::LE, $3); }
...
...
@@ -135,6 +138,8 @@ expr : INT { $$ = new ast::Integer($1); }
| expr BAND expr { $$ = new ast::Binop($1, token::BAND, $3); }
| expr BOR expr { $$ = new ast::Binop($1, token::BOR, $3); }
| expr BXOR expr { $$ = new ast::Binop($1, token::BXOR, $3); }
| LNOT expr { $$ = new ast::Unop(token::LNOT, $2); }
| BNOT expr { $$ = new ast::Unop(token::BNOT, $2); }
;
var : IDENT { $$ = new ast::Variable($1); }
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment