dabeaz / sly

Sly Lex Yacc
Other
816 stars 107 forks source link

sly: Parse error in input. EOF #84

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi. I'm getting this error every time, when I'm using this code:

class SerialLexer(Lexer):
    tokens = { NAME, NUMBER, PLUS, MINUS, TIMES, DIVIDE, ASSIGN, LPAREN, RPAREN }
    ...
    ignore_comment = r'#.*'
...
# test
3 + 2

How can I fix it?

dabeaz commented 2 years ago

The error is being caused some issue in your grammar. What does the parser look like?

ghost commented 2 years ago

https://gitlab.com/Pelfox/serial/-/blob/main/serial.py#L31

dabeaz commented 2 years ago

Is there a reduce/reduce conflict reported?

ghost commented 2 years ago

No

dabeaz commented 2 years ago

If the input file is literally what you show above, then it's being fed to the parser line-by-line. The first line with the comment in it is "empty" (contains no statement or expression). That's most likely the source of the error.

ghost commented 2 years ago

So, I tried with

# 

And it gives to me sly: Parse error in input. EOF

dabeaz commented 2 years ago

Right. Because you're giving the parser empty input (no tokens). There are no parsing rules to match empty input.