arithy / packcc

A parser generator for C
Other
347 stars 28 forks source link

Parsing a "switch { case n: m }" #73

Closed joagre closed 11 months ago

joagre commented 11 months ago

I tried to write a grammar to parse the following toy example:

switch 1 {
  case 2:
    3,
    42
  case 4:
    5
}

I tried with the following but it is not the way to do it:

SwitchStmt <- "switch" _ Expr _ "{" _ CaseStmt+ _ "}"
CaseStmt <- "case" _ Expr _ ":" _ ExprList
ExprList <- Expr (_ "," _ Expr)*
Expr <- [0-9]+
_ <- WS*
WS <- " " / "\t" / "\n" / "\r"

Any hints?

Cheers /J