[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 21:37:57 BST 2020


--- Comment #3 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Jacob Lifshay from comment #2)
> (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
> handled.

annoyingly, the more changes that are made to the grammar, the
less "like the spec" the grammar becomes, with the implication
that further manual intervention stages are required when it
comes to verifying against the 3.0B spec and, in future, against
3.0C and other releases.

i've made quite a few minor changes, some of them necessary (to support
syntax such as CR0[x] rather than CR0_subscript_x, some of them, well,
not being lazy, just "trying to get it working fast"

yet-another-preprocessor-stage - even if it is line-based rather than
ply-lexer-based, looking for 2 "case" statements (or case followed by
default) which are lined up, and inserting the ghost word "fallthrough"
would "do the trick"

this is ok:

   case (2): fallthrough
   case (3): x <- 3

the lexer happily recognises that... *sigh*

so it can be "faked" by recognising

spc spc spc case (2):
spc spc spc case (3):
spc spc spc default :

counting the number of spaces, recognising that there is a case after a case
(with no code) and "magically" putting in the ghost-word

horrible, but it "works" :)

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

More information about the libre-riscv-dev mailing list