[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-core
Subject:    Re: parser
From:       Jon Rafkind <rafkind () cs ! utah ! edu>
Date:       2008-04-19 22:35:55
Message-ID: 480A73CB.3000608 () cs ! utah ! edu
[Download RAW message or body]

Jon Rafkind wrote:
> Hi, I am writing a parser for Ruby in PLT Scheme but am having trouble 
> with statements that have a trailing "if ...". This expression
>
> x = y if true
>
> Leads my parser down this path
>
> Program -> Compstmt -> Stmt -> Lhs = Command-call -> Command -> 
> Operation Command-args -> Open-args -> Call-args -> Args -> Primary -> 
> If Expression-value Then Compstmt If-tail end
>
> Which is an error since the trailing if is not a full if statement. It 
> seems like Ruby deals with this by having kIF and kIF_MOD, but how 
> does the lexer know which one to generate?
>
> I'm using an LR parser generator which works basically the same as 
> bison so I usually just copy the rules from parse.y.
I guess I mostly figured this out. Around line ~4442 of parse.y it 
checks the kwtable depending on the current lexer state.

Sorry for the noise.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic