Skip to content

Juxtaposing quotation mark #436

Open

Description

@sergey-goncharov

This grammar Exp. Exp ::= Ident "'" ; generates a parser that correctly parses x ', but not x' for some reason. I've played with other characters, including other quotation symbols, such as ’ and then both x’ and x ’ are recognized, which is imho the correct behaviour. Any particular reasons, why ' is treated specially (and how to avoid it?)? Thanks!

Activity

  1. added
    lexerConcerning the generated lexer
    builtinConcerning built-in tokens like Integer, String etc.
    on Feb 8, 2023
  2. andreasabel commented on Feb 8, 2023

    @andreasabel
    Member

    Since Idents can contain quotation marks, x' will parse as an identifier.
    You can define your own identifier tokens, e.g.:

    Exp. Exp ::= Id "'";
    token Id letter (letter | digit | '_')*;
    

    This works as expected in the "imperative" backends (C, C++, Java) but not in the "functional" ones (Haskell, OCaml).

    The problem is in how the functional backends implement the lexer: they always include lexing of Ident, so that keywords can be lexed as Ident and then classified as keywords later. This is to prevent explosion of the lexer automata.
    Unfortunately, it leads to this bug.

    Related:

  3. sergey-goncharov commented on Feb 8, 2023

    @sergey-goncharov
    Author

    Thanks, Andreas, for a quick reply!

    Exp. Exp ::= Id "'";
    token Id letter (letter | digit | '_')*;
    

    That is roughly how I started. I've just minimized that example, since the problem persisted. I am following the basics steps from the tutorial, which suggests to use Test, generated with bnfc -d -m for basic testing.

  4. andreasabel commented on Feb 8, 2023

    @andreasabel
    Member

    Yes, unfortunately "'" isn't a proper operator character atm in the standard backend (Haskell).
    You can use this invocation instead, to use the C backend instead of the Haskell one.

    bnfc --c -m GRAMMAR.cf
    
  5. jasper-e commented on Sep 3, 2023

    @jasper-e

    Yes, unfortunately "'" isn't a proper operator character atm in the standard backend (Haskell). You can use this invocation instead, to use the C backend instead of the Haskell one.

    bnfc --c -m GRAMMAR.cf
    

    My problem is that I combine bnfc Haskell backend with Haskell-based uuagc...
    I would highly appreciate a command line flag for the Haskell backend to omit including Ident, which I could put in my Makefile...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    HaskellOCamlbugbuiltinConcerning built-in tokens like Integer, String etc.lexerConcerning the generated lexer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions