Git Product home page Git Product logo

Comments (5)

Mingun avatar Mingun commented on July 19, 2024 1

These are unintended consequences of #160 -- because we now run checks of each stage without throwing exceptions, the AST in reportInfiniteRepetition pass can have infinity recursive rules which we try to check. The fast solution is to factor out the reportInfiniteRecursion pass to its own stage before the current check stage. The more clever solution is to tweak all passes in a check stage so that they will not assume that AST contains no recursive rules.

from peggy.

Mingun avatar Mingun commented on July 19, 2024

Tip: if you need only start and end offset, more performant solution is use range() function.

Typical solution to parse arithmetic expressions:

//{ The higher the priority, the larger the rule number.
Expr// assignment, minimal priority
  = l:Expr0 t:(p1 Expr0)* {return rightAssotiative(l, t);};
Expr0// value lists
  = h:(@Expr1 comma)* t:Expr1? {return list(h, t);};
Expr1// Logical OR
  = l:Expr2 t:(p2 Expr2)* {return leftAssotiative(l, t);};
Expr2// Logical AND
  = l:Expr3 t:(p3 Expr3)* {return leftAssotiative(l, t);};
Expr3// Bitwise OR
  = l:Expr4 t:(p4 Expr4)* {return leftAssotiative(l, t);};
Expr4// Bitwise XOR
  = l:Expr5 t:(p5 Expr5)* {return leftAssotiative(l, t);};
Expr5// bitwise AND
  = l:Expr6 t:(p6 Expr6)* {return leftAssotiative(l, t);};
Expr6// comparison operators
  = l:Expr7 t:(p7 Expr7)* {return leftAssotiative(l, t);};
Expr7// relational operators
  = l:Expr8 t:(p8 Expr8)* {return leftAssotiative(l, t);};
Expr8// bitwise shift
  = l:Expr9 t:(p9 Expr9)* {return leftAssotiative(l, t);};
Expr9// addition and substraction
  = l:Expr10 t:(p10 Expr10)* {return leftAssotiative(l, t);};
Expr10// multiplication, division, remainder
  = l:Expr11 t:(p11 Expr11)* {return leftAssotiative(l, t);};
Expr11// pow
  = l:Expr12 t:(p12 Expr12)* {return leftAssotiative(l, t);};
Expr12// Logical and bitwise NOT, unary operators, maximum priority
  = o:p13 r:Expr12 {return node({kind: o, expr: r});}
  / Expr13
  ;
Expr13// prefix increment / decrement
  = o:p14 r:Expr13 {return node({kind: o, expr: r});}
  / Expr14
  ;
Expr14// postfix increment / decrement
  = r:Expr15 o:p15 {return node({kind: o, expr: r});}
  / Expr15
  ;
Expr15// function call, indexation, dot syntax
  = /*l:Expr16 t:suffix* {return suffix(l, t);};
Expr16
  = funcdef
  / block
  / literal
  / constant
  / IfExpr
  / ForExpr
  / WhileExpr
  / BreakExpr
  / YieldExpr
  / ReturnExpr
  / ContinueExpr
  / define
  / name
  / */"(" @Expr ")"
  ;
//}

//{ Operators
comma = @',' _;

p1 = @('='/'+='/'-='/'*='/'/='/'%='/'<<='/'>>='/'&='/'^='/'|='/'&&='/'||=') _;
p2 = @'||'_;
p3 = @'&&'_;
p4 = @'|' _;
p5 = @'^' _;
p6 = @'&' _;
p7 = @('=='/'!=') _;
p8 = @('<='/'<'/'>='/'>') _;
p9 = @('<<'/'>>') _;
p10= @[+-] _;
p11= @[*/%]_;
p12= @'**' _;
p13= !p14 @[!~+-] _;
p14= @('++'/'--') _;
p15= p14;
//}
_ 'Whitespace' = [ \r\n\t]*;

Error parsing grammar
Maximum call stack size exceeded

This is bad. Could you post the full minimal reproducible example of such grammar? It could be bug in peggy looks like some infinity recursion was not detected

from peggy.

DanielMazurkiewicz avatar DanielMazurkiewicz commented on July 19, 2024

Thanks for tip and grammar pattern!

from peggy.

DanielMazurkiewicz avatar DanielMazurkiewicz commented on July 19, 2024

@Mingun

This is bad. Could you post the full minimal reproducible example of such grammar? It could be bug in peggy looks like some infinity recursion was not detected

Narrowed it, this is minimal, or close to minimal that causes maximum stack exceeded error:

start = expr* 

expr
  = expr "++"

from peggy.

hildjj avatar hildjj commented on July 19, 2024

@Mingun do you have a suggestion for how to catch this as an infinite loop?

from peggy.

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.