Giter Club home page Giter Club logo

Comments (2)

parrt avatar parrt commented on May 17, 2024

Sam points out better to have getters to avoid fields. most of time fast enough. Add:

getA() -> single element, or list
getA(i) -> single at ith position

no need for -Xno-auto-ctx-labels

from antlr4.

parrt avatar parrt commented on May 17, 2024

Ok, got Sam's idea in for getters. from

    statement
        : block
        |   ASSERT expression (':' expression)? ';'
        |   'if' parExpression statement ('else' statement)?
        |   'for' '(' forControl ')' statement
        |   'while' parExpression statement
        |   'do' statement 'while' parExpression ';'
        |   'try' block
            ( catches 'finally' block
            | catches
            | 'finally' block
            )
        |   'switch' parExpression '{' switchBlockStatementGroups '}'
        |   'synchronized' parExpression block
        |   'return' expression? ';'
        |   'throw' expression ';'
        |   'break' Identifier? ';'
        |   'continue' Identifier? ';'
        |   ';'
        |   statementExpression ';'
        |   Identifier ':' statement
        ;

we get:

public static class statementContext extends ParserRuleContext<Token> {
    public blockContext block(int i) {
        return (blockContext)getRuleContext(blockContext.class,i);
    }
    public List<expressionContext> expression() {
        return (List<expressionContext>)getRuleContexts(expressionContext.class);
    }
    public parExpressionContext parExpression() {
        return (parExpressionContext)getRuleContext(parExpressionContext.class,0);
    }
    public statementContext statement(int i) {
        return (statementContext)getRuleContext(statementContext.class,i);
    }
    public List<catchesContext> catches() {
        return (List<catchesContext>)getRuleContexts(catchesContext.class);
    }
    public expressionContext expression(int i) {
        return (expressionContext)getRuleContext(expressionContext.class,i);
    }
    public statementExpressionContext statementExpression() {
        return (statementExpressionContext)getRuleContext(statementExpressionContext.class,0);
    }
    public List<blockContext> block() {
        return (List<blockContext>)getRuleContexts(blockContext.class);
    }
    public List<statementContext> statement() {
        return (List<statementContext>)getRuleContexts(statementContext.class);
    }
    public switchBlockStatementGroupsContext switchBlockStatementGroups() {
        return (switchBlockStatementGroupsContext)getRuleContext(switchBlockStatementGroupsContext.class,0);
    }
    public Token ASSERT() { return getToken(JavaLRParser.ASSERT, 0); }
    public forControlContext forControl() {
        return (forControlContext)getRuleContext(forControlContext.class,0);
    }
    public Token Identifier() { return getToken(JavaLRParser.Identifier, 0); }
    public catchesContext catches(int i) {
        return (catchesContext)getRuleContext(catchesContext.class,i);
    }
    public statementContext(ParserRuleContext<Token> parent, int state) {
        super(parent, state);
    }
    @Override
    public void enterRule(ParseTreeListener<Token> listener) {
        if ( listener instanceof JavaLRListener ) ((JavaLRListener)listener).enter(this);
    }
    @Override
    public void exitRule(ParseTreeListener<Token> listener) {
        if ( listener instanceof JavaLRListener ) ((JavaLRListener)listener).exit(this);
    }
}

from antlr4.

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.