Giter Site home page Giter Site logo

Comments (5)

ltratt avatar ltratt commented on July 18, 2024

I think the error is because MULT/HEXDIGIT et al. don't appear in the grammar itself. However, the error is definitely confusing because the %epp is suppressing the better error message. If I get rid of the %epp lines I get this:

Warning: these tokens are defined in the lexer but not referenced in the
grammar:
  DIGIT
  GT
  GTEQ
  HEX
  HEXDIGIT
  HEXDIGITS
  LT
  LTEQ
  MULT
  SPACE
Error: these tokens are referenced in the grammar but not defined in the lexer:
  GREATER
  GREATEREQUAL
  HASH
  LESS
  LESSEQUAL
  SLASH
  STAR

from grmtools.

ratmice avatar ratmice commented on July 18, 2024

this is the error(s) I got, each run can yield different errors lol

Hmm, I knew this was the case with error recovery that it's errors were non-deterministic, but I wasn't aware of it in a case such as this. One other thing we could look at here is whether we should try and emit both the %epp errors, and the 'unreferenced in the lexer/grammar' warnings here. When I was adding output of multiple errors, I was somewhat conservative in that I was trying to avoid adding new cascading failures.

from grmtools.

ltratt avatar ltratt commented on July 18, 2024

One other thing we could look at here is whether we should try and emit both the %epp errors, and the 'unreferenced in the lexer/grammar' warnings here

This would definitely be good, but it's definitely some work.

from grmtools.

jymchng avatar jymchng commented on July 18, 2024

I think the error is because MULT/HEXDIGIT et al. don't appear in the grammar itself. However, the error is definitely confusing because the %epp is suppressing the better error message. If I get rid of the %epp lines I get this:

Warning: these tokens are defined in the lexer but not referenced in the
grammar:
  DIGIT
  GT
  GTEQ
  HEX
  HEXDIGIT
  HEXDIGITS
  LT
  LTEQ
  MULT
  SPACE
Error: these tokens are referenced in the grammar but not defined in the lexer:
  GREATER
  GREATEREQUAL
  HASH
  LESS
  LESSEQUAL
  SLASH
  STAR

@ltratt Thank you sir for your response.

For the first error,

> Warning: these tokens are defined in the lexer but not referenced in the
> grammar:
>   DIGIT

How can show me how can I define DIGIT in tinylang.l since it is a regex? The Java7 example wasn't helpful to me. Thank you.

from grmtools.

ratmice avatar ratmice commented on July 18, 2024

How can show me how can I define DIGIT in tinylang.l since it is a regex? The Java7 example wasn't helpful to me. Thank you.

These errors are a bit difficult to give general repair advice about. Here tinylang.l produces a token DIGIT, but the parser has no rules for how to consume one, comparing the linked lexer definitions:

[0-9] "DIGIT"
[0-9]+ "DIGITS"

Here, we have inlined the usage of DIGIT on the left hand side, in the original this was

digit    [0-9]
{digit}+      return tinylang::Parser::token::T_integer_literal;

While doing so we have added to the lexer the ability to produce the DIGIT token, it may never produce such a token depending on match precedence. But this token never existed in the original tinylang.l, and has nothing in tinylang.yy which prepares the parser to consume it, subsequently the lexer could produce a token which the parser does not expect.

So in this case I believe it makes sense to just remove the [0-9] "DIGIT" rule from the lexer. But in general the solution for either of these types of errors could involve modifying either or both of the lex and yacc files. E.g. when I typo the token in both.

hope that helps.

from grmtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.