question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Division sign (slash) is confused with multiline comment

See original GitHub issue

Hello,

I listed below a snapshot of my rules for parsing binary operation:


binary_operation: sum_operation

sum_operation: mul_operation
    | sum_operation PLUS mul_operation  -> add
    | sum_operation MINUS mul_operation -> minus
    
mul_operation: power_operation      
    | mul_operation MULTIPLICATION power_operation  -> mul
    | mul_operation DIVISION power_operation        -> div
    
power_operation: new_expression
    | power_operation POWER expression  -> power

expression: constant
		| reference

reference: name
 
name: ID | quoted_identifier

ID: /[A-Za-z][A-Za-z0-9\d_]*/
	
PLUS: "+"
DIVISION: "/"
MINUS: "-"
POWER : "^"
MULTIPLICATION: "*"

MULTILINE_COMMENT: /\/\*.*?\*\//s

%ignore MULTILINE_COMMENT
%ignore /\s/s

The rules work well when parsing the expression:

x/**/:=/**/(1.00000000000000002E-02/**/*y)

But parsing the following expression results in the error below:

x/**/:=/**/(y/**// 4.0)

lark.exceptions.UnexpectedCharacters: No terminal defined for ‘/’ at line Expecting: {‘MINUS’, ‘PLUS’, ‘MULTIPLICATION’, ‘POWER’}

Any help would be much appreciated,

Best regards

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:23 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
MegaIngcommented, Nov 19, 2020

Please give an MCVE. Your issue leads to a lot of open questions:

  • The grammar isn’t complete. There are a few rules referenced that you didn’t post.
  • Which parser did you use?
  • Which lexer did you use?

I can also see that what you posted there can’t be the exact grammar you are using (or we have an incredible severe bug in Lark somewhere that should prevent most grammars from working). Otherwise DIVIDE would have to appear in the Expected list.

We are certainly ready and open to help you, but you didn’t give us enough information.

1reaction
erezshcommented, Nov 27, 2020

I went with @MegaIng 's suggestion.

@khaled-ek @charles-esterbrook This is now fixed in master, and will be part of the next release.

Hopefully it won’t break anyone’s code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When parsing Javascript, what determines the meaning of a ...
Forward-slashes can mean a number of different things: division operator, regular expression literal, comment introducer, or line-comment introducer. The last ...
Read more >
Slash (punctuation) - Wikipedia
Once used to mark periods and commas, the slash is now used to represent division and fractions, exclusive 'or' and inclusive 'or', and...
Read more >
Comments in C/C++ - GeeksforGeeks
Multi-line comment. Single line Comment. Represented as // double forward slash. It is used to denote a single line comment ...
Read more >
Comments in programming languages
We have two types of comments here, the end-of-line comment and the block comment. An end-of-line comment terminates at the end of the...
Read more >
Clarifying Code with Javascript Comments | Udacity
Javascript multiline comments, also known as block comments, start with a forward slash followed by an asterisk (/*) and end with an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found