From 64a0ca2512199c55e51ec90dbd3ec7d563472255 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Tue, 31 Aug 2021 13:31:33 -0700 Subject: Handle references better in ANTLR Parser Tweak the grammar to handle references without left-recursion. Also split references and subreferences out from the regular expression rule to make their parsing more efficient. --- src/main/antlr4/FIRRTL.g4 | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/main/antlr4') diff --git a/src/main/antlr4/FIRRTL.g4 b/src/main/antlr4/FIRRTL.g4 index f5116485..d40c6560 100644 --- a/src/main/antlr4/FIRRTL.g4 +++ b/src/main/antlr4/FIRRTL.g4 @@ -99,9 +99,9 @@ stmt | mdir 'mport' id '=' id '[' exp ']' exp info? | 'inst' id 'of' id info? | 'node' id '=' exp info? - | exp '<=' exp info? - | exp '<-' exp info? - | exp 'is' 'invalid' info? + | ref '<=' exp info? + | ref '<-' exp info? + | ref 'is' 'invalid' info? | when | 'stop(' exp exp intLit ')' stmtName? info? | 'printf(' exp exp StringLit ( exp)* ')' stmtName? info? @@ -167,16 +167,22 @@ ruw exp : 'UInt' ('<' intLit '>')? '(' intLit ')' | 'SInt' ('<' intLit '>')? '(' intLit ')' - | id // Ref - | exp '.' fieldId - | exp '.' DoubleLit // TODO Workaround for #470 - | exp '[' intLit ']' - | exp '[' exp ']' + | ref | 'mux(' exp exp exp ')' | 'validif(' exp exp ')' | primop exp* intLit* ')' ; +ref + : id subref? + ; + +subref + : '.' fieldId subref? + | '.' DoubleLit subref? // TODO Workaround for #470 + | '[' (intLit | exp) ']' subref? + ; + id : Id | keywordAsId -- cgit v1.2.3