timtadh / dot_tools

A library to parse and generate the graphviz dot langauge.
Other
10 stars 5 forks source link

SyntaxError: LexToken(LCURLY,'{',11,355) #1

Open Perseus14 opened 6 years ago

Perseus14 commented 6 years ago

Hi,

I am trying to generate an AST of a Control Flow Graph of a simple Hello World program in C. I generated the DOT file using GCC's -fdump-tree-cfg-graph. When I tried to use the parse function, I got an error SyntaxError: LexToken(LCURLY,'{',11,355). I am assuming the problem is most likely the regex/lexer for strings(ID) in the DOT file does not include '{' or '}'.

The command to generate the DOT file

gcc HelloWorld.c -fdump-tree-cfg-graph

I am also attaching the source code and the generated DOT file

HelloWorld.zip

timtadh commented 6 years ago

Hi @Perseus14

You are right. This is the lexer for strings: https://github.com/timtadh/dot_tools/blob/master/dot_tools/dot_lexer.py#L85

As you can see I evidently (this was years ago now) only implemented it for " and did not include '. The reason is according to the official grammar: http://www.graphviz.org/doc/info/lang.html only " start strings.

Now all of that doesn't help you when GCC is outputting single '. Does graphviz successfully process the files? If it does I would willing to modify the lexer of this repo and my graphviz parser for go (https://github.com/timtadh/dot) to support them as well. If graphviz can't process the files with the single quotes then I will not modify this repo to. (Although you are of course free to make a fork that supports the single quotes -- I just won't merge it into the main branch since it wouldn't be conformant).