Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autocomp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Léo Grange
autocomp
Commits
165ecd5d
Commit
165ecd5d
authored
9 years ago
by
Léo Grange
Browse files
Options
Downloads
Patches
Plain Diff
add AST and parser elements for var/const/signal items
Language is now fully recognized, and AST is generated as expected.
parent
63e9882a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
node.cpp
+26
-0
26 additions, 0 deletions
node.cpp
node.hpp
+36
-1
36 additions, 1 deletion
node.hpp
parser.y
+8
-2
8 additions, 2 deletions
parser.y
with
70 additions
and
3 deletions
node.cpp
+
26
−
0
View file @
165ecd5d
...
...
@@ -25,6 +25,32 @@ void NAutoItem::printNode(std::ostream &o) {
}
void
NVarItem
::
printNode
(
std
::
ostream
&
o
)
{
o
<<
"var "
;
ident
->
printNode
(
o
);
}
void
NConstItem
::
printNode
(
std
::
ostream
&
o
)
{
o
<<
"const "
;
ident
->
printNode
(
o
);
o
<<
" = "
;
value
->
printNode
(
o
);
}
void
NSignalItem
::
printNode
(
std
::
ostream
&
o
)
{
o
<<
"signal "
;
ident
->
printNode
(
o
);
o
<<
" = "
<<
(
reverse
?
"! "
:
""
);
where
->
printNode
(
o
);
o
<<
" [ "
;
bit
->
printNode
(
o
);
o
<<
" ] "
;
}
void
NState
::
printNode
(
std
::
ostream
&
o
)
{
o
<<
"state "
;
ident
->
printNode
(
o
);
...
...
This diff is collapsed.
Click to expand it.
node.hpp
+
36
−
1
View file @
165ecd5d
...
...
@@ -85,6 +85,41 @@ public:
};
class
NVarItem
:
public
NItem
{
public:
NIdentifier
*
ident
;
NVarItem
(
NIdentifier
*
ident
)
:
ident
(
ident
)
{}
void
printNode
(
std
::
ostream
&
o
);
};
class
NConstItem
:
public
NItem
{
public:
NIdentifier
*
ident
;
NInteger
*
value
;
NConstItem
(
NIdentifier
*
ident
,
NInteger
*
value
)
:
ident
(
ident
),
value
(
value
)
{}
void
printNode
(
std
::
ostream
&
o
);
};
class
NSignalItem
:
public
NItem
{
public:
NIdentifier
*
ident
;
NIdentifier
*
where
;
NExpression
*
bit
;
bool
reverse
;
NSignalItem
(
NIdentifier
*
ident
,
NIdentifier
*
where
,
NExpression
*
bit
,
bool
reverse
)
:
ident
(
ident
),
where
(
where
),
bit
(
bit
),
reverse
(
reverse
)
{}
void
printNode
(
std
::
ostream
&
o
);
};
/*
class NItemSequence : public NAnySequence<NItem> {
};
...
...
@@ -117,7 +152,7 @@ class NStatement : public Node {
class NStatementSequence : public NAnySequence<NStatement> {
};
*/
class
NAssignStatement
:
public
NStatement
{
public:
...
...
This diff is collapsed.
Click to expand it.
parser.y
+
8
−
2
View file @
165ecd5d
...
...
@@ -97,6 +97,12 @@ items : items item { $1->addItem($2); $$ = $1; }
item : TOK_REG ident TOK_EQ literal { $$ = new NRegItem($2, $4); }
/* TODO var const signal*/
| TOK_VAR ident { $$ = new NVarItem($2); }
| TOK_CONST ident TOK_EQ literal { $$ = new NConstItem($2, $4); }
| TOK_SIGNAL ident TOK_EQ ident TOK_LBRAC expr TOK_RBRAC
{ $$ = new NSignalItem($2, $4, $6, false); }
| TOK_SIGNAL ident TOK_EQ TOK_NOT ident TOK_LBRAC expr TOK_RBRAC
{ $$ = new NSignalItem($2, $5, $7, true); }
| TOK_AUTO ident stmts states state {
$4->addItem($5);
$$ = new NAutoItem($2, $3, $4);
...
...
@@ -163,8 +169,8 @@ variable : ident { $$ = new NBitfieldVariable($1); }
{ $$ = new NBitfieldVariable($1, $3, $5); }
;
expr : variable
| literal
expr : variable
{ $$ = $1; }
| literal
{ $$ = $1; }
| unop expr { $$ = new NUnaryOperator($1, $2); }
| expr binop expr { $$ = new NBinaryOperator($2, $1, $3); }
| TOK_LPAR expr TOK_RPAR { $$ = $2; }
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment