Skip to content

Give warnings if there is action code in grammar #71

Closed

Description

@kaby76

As noted here, the javadoc/ grammar contains actions. lab.antlr.org should output a warning message if the grammar contains action code since action code will not be executed. Even long-time users of Antlr will make an assumption that is wrong.

Activity

  1. ericvergnaud commented on Feb 27, 2023

    @ericvergnaud

    Maybe I'm wrong but I don't see anything in the lab code for preventing execution of predicates

  2. kaby76 commented on Feb 27, 2023

    @kaby76
    CollaboratorAuthor

    There were a few comments about supporting other targets and even action code in the long discussion last year, e.g. interp simulator for Javascript and even antlr4ts. For now, it would be best for the interp itself to output a warming if an action is encountered.

  3. ericvergnaud commented on Feb 27, 2023

    @ericvergnaud

    The lab runs on server side in Java, running parsers in a lambda could be a solution to prevent damage

  4. kaby76 commented on Feb 27, 2023

    @kaby76
    CollaboratorAuthor

    Also to consider, there's only a syntaxError() as output from the parser. No such thing as a warning. Seems rather limited to what most compilers do. I suppose the interpreter not being able to execute an action is pretty much a failure though. What should happen if the parse doesn't actually need to execute the action from a particular start rule? No need to produce a warning even if the grammar does have actions.

  5. ericvergnaud commented on Feb 27, 2023

    @ericvergnaud

    I'd be comfortable not executing actions because the lab is about parsing, not about further steps. But predicates participate in parsing so it's certainly worth a discussion.

  6. kaby76 commented on Feb 27, 2023

    @kaby76
    CollaboratorAuthor

    Sorry, I use "actions" to be either { ... } or { ... }? target-specific code because the parse tree node is actionBlock for either when parsing .g4's. We may need to discuss both. I thought there were grammars that had both, where { ... } blocks were used to initialize some state variables for the { ... }? predicates. Checking now

    for i in `find . -name desc.xml`; do echo $i; d="$(dirname $i)"; echo $d; trparse $d/*.g4 | trxgrep ' //element/actionBlock' | trtext; done
    
  7. ericvergnaud commented on Feb 27, 2023

    @ericvergnaud

    A solution worth exploring would be to generate the lexer and parser in JavaScript on the server, and run them in the browser. This would require devs to code predicates in JS (in the lab) but that sounds like a reasonable requirement

  8. kaby76 commented on Feb 27, 2023

    @kaby76
    CollaboratorAuthor

    Most if not all grammars in grammars-v4 that have a JS port are in "target agnostic format", which means there are addition source files in JS. It would be nice to have the tool have an extra tab for these files. Otherwise, we'd need to refactor the grammars on the fly to use @members and remove the superClass option.

  9. ericvergnaud commented on Feb 27, 2023

    @ericvergnaud

    Maybe we should convert this into a discussion?

  10. kaby76 commented on Feb 27, 2023

    @kaby76
    CollaboratorAuthor

    Maybe we should convert this into a discussion?

    Yes, please do.

    Also of note. There is no consistent "recognizer base class method reference" syntax across targets. So we have action code with:

    • this.FooBar() in CSharp, Java
    • l.FooBar() and p.FooBar()` in Go
    • this.FooBar() in JavaScript, TypeScript
    • this->FooBar() in Cpp
    • $this->FooBar() in PHP
    • self.FooBar() in Python3

    (I haven't set up testing for Swift because of the lack of a Mac machine--currently a brick, can't install a new OS on a blank HDD.)

    The grammars contain either self.FooBar() or this.FooBar(), and that is modified to the target-specific format.

  11. locked and limited conversation to collaborators on Feb 27, 2023
  12. converted this issue into a discussion #73 on Feb 27, 2023
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions