Comments (2)
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.
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)
- Questions not answered in the README HOT 12
- Passing auxil to PCC_DEBUG HOT 3
- AST Mode HOT 11
- Uninitialized variables HOT 8
- value passthrough HOT 4
- parser reads more data than necessary HOT 3
- Strange bad generated parser HOT 5
- Memory usage compared to gcc compiler HOT 13
- raising error from action? HOT 2
- %value and memory management HOT 2
- Consider add support for UCD(Unicode Character Database) rule pattern HOT 3
- Pre type checking possible? HOT 5
- Parsing a "switch { case n: m }"
- How to do good syntax error handling? HOT 2
- Null pointer error on broken grammar HOT 2
- parsing python like languages HOT 4
- Actions on repeated rules HOT 2
- Proposal: visitor pattern generation/event interface?
- How to parse from a char array instead of stdin? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from packcc.