Skip to content
Snippets Groups Projects
Commit 165ecd5d authored by Léo Grange's avatar Léo Grange
Browse files

add AST and parser elements for var/const/signal items

Language is now fully recognized, and AST is generated as expected.
parent 63e9882a
Branches
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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:
......
......@@ -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; }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment