picoe / Eto.Parse

Recursive descent LL(k) parser for .NET with Fluent API, BNF, EBNF and Gold Grammars
MIT License
148 stars 30 forks source link

[Question] How can i make a "recursive" parser using the C# api ? #61

Closed ykafia closed 2 years ago

ykafia commented 2 years ago

I Have this EBNF example, and i'm trying to reproduce what postfix_expression does using the C# api

constants = 
    integer_cst 
    | float_cst 
    | bool_cst;

identifier := letter, {"_" | letter_or_digit};

primary_expression := identifier | constants;

increment_op = "++" | "--";

(* This part is recursive *)
postfix_expression := 
    primary_expression
    | postfix_expression, "[", postfix_expression, "]"
    | postfix_expression, increment_op;

grammar = postfix_expression;
ykafia commented 2 years ago

I have an answer to my question,

The trick is to use an AlternativeParser