GithubHelp home page GithubHelp logo

Lookahead woes and more about packcc HOT 2 CLOSED

joagre avatar joagre commented on August 16, 2024
Lookahead woes and more

from packcc.

Comments (2)

dolik-rce avatar dolik-rce commented on August 16, 2024 1

I don't think it is a problem related to lookahead...

The a[777].foo correctly matches FunctionCall rule, but it doesn't match Indexing. That is partially because Indexing tries to first match only index access, and it never gets to FunctionCall. Switching the order will help: Indexing <- FunctionCall / Symbol _ "[" _ Expr _ "]". But this is not the only problem, which makes it much harder to debug, because even if you fix one problem, it still doesn't work 🙂

I'd suggest to rewrite the grammar slightly to separate the index access from field access. Currently they're kind of intertwined (HasField contains Indexing). I can't tell you how exactly, I'd have to give it much more time than I have available, sorry.

from packcc.

joagre avatar joagre commented on August 16, 2024

Thanks for the input. I can see now that my grammar snippet is ambiguous/faulty and need to be rewritten. From a completelly naively point of view I would like to have an even more ambiguous grammar though:

Program            <- _ TopLevelExpr (_ "," _ TopLevelExpr)* EOF
TopLevelExpr       <- Expr / Binding

# Precedence ordered
Expr               <- Add
Add                <- Multiplicate (_ "+" _  Multiplicate)*
Multiplicate       <- Indexing (_ "*" _  Indexing)*
Indexing           <- Expr _ "[" _ Expr _ "]"  / FunctionCall
FunctionCall       <- FunctionName _ "(" _ ExprSequence? _ ")" / FieldAccess
FieldAccess        <- Expr (_ "." _ Expr)* / Primary

FunctionName       <- Symbol
Symbol             <- [a-zA-Z_][a-zA-Z_0-9_]*
ExprSequence       <- Expr (_ "," _ Expr)*

Primary            <- Literal / Symbol
Literal            <- NumberLiteral
NumberLiteral      <- [0-9]+

Binding            <- MatchPattern _ "=" _ Expr
MatchPattern       <- Literal / FieldAccess / Symbol

_                  <- WS*
WS                 <- [ \t\r\n]
EOF                <- _ !.

:-)

It would require a parser with indefinite backtracking. Maybe not even that would suffice. Life is hard.

Thanks

from packcc.

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.