Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while creating a circuit through file #36

Open
jenila19 opened this issue Oct 14, 2023 · 0 comments
Open

Error while creating a circuit through file #36

jenila19 opened this issue Oct 14, 2023 · 0 comments

Comments

@jenila19
Copy link

Hi, I am getting the following error while creating a circuit in jupyter using circuitgraph. My file is a halfadder program
" module halfadder
(
input a,
input b,
output sum,
output carry
);

xor x1(sum, a, b) ;
and a1(carry, a, b) ;

endmodule"

##Error I got for the code "c = cg.from_file('C:/Users/jenil/Downloads/halfadder.v')"


UnexpectedCharacters Traceback (most recent call last)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\lark\lexer.py:648, in ContextualLexer.lex(self, lexer_state, parser_state)
647 lexer = self.lexers[parser_state.position]
--> 648 yield lexer.next_token(lexer_state, parser_state)
649 except EOFError:

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\lark\lexer.py:581, in BasicLexer.next_token(self, lex_state, parser_state)
580 allowed = {""}
--> 581 raise UnexpectedCharacters(lex_state.text, line_ctr.char_pos, line_ctr.line, line_ctr.column,
582 allowed=allowed, token_history=lex_state.last_token and [lex_state.last_token],
583 state=parser_state, terminals_by_name=self.terminals_by_name)
585 value, type_ = res

UnexpectedCharacters: No terminal matches 'a' in the current parser context, at line 3 col 8

input a,
          ^

Expected one of:
* RPAR
* COMMA

Previous tokens: Token('IDENTIFIER', 'input')

During handling of the above exception, another exception occurred:

UnexpectedToken Traceback (most recent call last)
Cell In[15], line 2
1 from circuitgraph import Circuit
----> 2 c = cg.from_file('C:/Users/jenil/Downloads/halfadder.v')

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\circuitgraph\io.py:75, in from_file(path, name, fmt, blackboxes, warnings, error_on_warning, fast)
73 netlist = f.read()
74 if fmt == "verilog" or path.suffix == ".v":
---> 75 return verilog_to_circuit(
76 netlist,
77 name,
78 infer_module_name,
79 blackboxes,
80 warnings,
81 error_on_warning,
82 fast,
83 )
84 if fmt == "bench" or path.suffix == ".bench":
85 return bench_to_circuit(netlist, name)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\circuitgraph\io.py:238, in verilog_to_circuit(netlist, name, infer_module_name, blackboxes, warnings, error_on_warning, fast)
235 else:
236 raise ValueError(f"Could not read netlist: {name} module not found") from e1
--> 238 return parse_verilog_netlist(module, blackboxes, warnings, error_on_warning)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\circuitgraph\parsing\verilog.py:374, in parse_verilog_netlist(netlist, blackboxes, warnings, error_on_warning)
372 with open(Path(file).parent.absolute() / "verilog.lark") as f:
373 parser = Lark(f, parser="lalr", transformer=transformer)
--> 374 [c] = parser.parse(netlist)
375 return c

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\lark\lark.py:652, in Lark.parse(self, text, start, on_error)
634 def parse(self, text: str, start: Optional[str]=None, on_error: 'Optional[Callable[[UnexpectedInput], bool]]'=None) -> 'ParseTree':
635 """Parse the given text, according to the options provided.
636
637 Parameters:
(...)
650
651 """
--> 652 return self.parser.parse(text, start=start, on_error=on_error)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\lark\parser_frontends.py:101, in ParsingFrontend.parse(self, text, start, on_error)
99 kw = {} if on_error is None else {'on_error': on_error}
100 stream = self._make_lexer_thread(text)
--> 101 return self.parser.parse(stream, chosen_start, **kw)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\lark\parsers\lalr_parser.py:41, in LALR_Parser.parse(self, lexer, start, on_error)
39 def parse(self, lexer, start, on_error=None):
40 try:
---> 41 return self.parser.parse(lexer, start)
42 except UnexpectedInput as e:
43 if on_error is None:

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\lark\parsers\lalr_parser.py:171, in _Parser.parse(self, lexer, start, value_stack, state_stack, start_interactive)
169 if start_interactive:
170 return InteractiveParser(self, parser_state, parser_state.lexer)
--> 171 return self.parse_from_state(parser_state)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\lark\parsers\lalr_parser.py:193, in _Parser.parse_from_state(self, state, last_token)
191 except NameError:
192 pass
--> 193 raise e
194 except Exception as e:
195 if self.debug:

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\lark\parsers\lalr_parser.py:183, in _Parser.parse_from_state(self, state, last_token)
181 try:
182 token = last_token
--> 183 for token in state.lexer.lex(state):
184 state.feed_token(token)
186 end_token = Token.new_borrow_pos('$END', '', token) if token else Token('$END', '', 0, 1, 1)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\lark\lexer.py:657, in ContextualLexer.lex(self, lexer_state, parser_state)
655 last_token = lexer_state.last_token # Save last_token. Calling root_lexer.next_token will change this to the wrong token
656 token = self.root_lexer.next_token(lexer_state, parser_state)
--> 657 raise UnexpectedToken(token, e.allowed, state=parser_state, token_history=[last_token], terminals_by_name=self.root_lexer.terminals_by_name)
658 except UnexpectedCharacters:
659 raise e

UnexpectedToken: Unexpected token Token('IDENTIFIER', 'a') at line 3, column 8.
Expected one of:
* RPAR
* COMMA
Previous tokens: [Token('IDENTIFIER', 'input')]. PI give a guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant