[libre-riscv-dev] [Bug 280] POWER spec parser needs to support fall-through cases

bugzilla-daemon at libre-riscv.org bugzilla-daemon at libre-riscv.org
Sun Apr 5 18:01:18 BST 2020


Jacob Lifshay <programmerjake at gmail.com> changed:

           What    |Removed                     |Added
                 CC|                            |programmerjake at gmail.com

--- Comment #2 from Jacob Lifshay <programmerjake at gmail.com> ---
(In reply to Luke Kenneth Casson Leighton from comment #0)
> this is very tricky to get working at the *lexer* level and still support
> whitespace indentation.
> switch (n)
>     case(1): x <- 5
>     case(2): # here
>     case(3):
>         x <- 3
>     default:
>         x <- 9
> print (5)

How about switching the grammar to parse a case-sequence instead of a single
case, that way multiple cases before a statement block would be correctly

It might look like the following (doesn't handle empty lines):

switch := "switch" LPAREN expression RPAREN NL INDENT (case_sequence
case_body)+ DEDENT

case_sequence := (case NL)* case (NL default)?
              | default

case := "case" LPAREN expression RPAREN COLON

default := "default" COLON

case_body := statement_with_nl
          | NL INDENT statement_with_nl+ DEDENT

statement_with_nl := lhs "<-" expression NL
          | ...

You are receiving this mail because:
You are on the CC list for the bug.

More information about the libre-riscv-dev mailing list