alex / rply

An attempt to port David Beazley's PLY to RPython, and give it a cooler API.
BSD 3-Clause "New" or "Revised" License
381 stars 60 forks source link

Parsing IF and IF-ELSE statement. #89

Closed AlexisHuvier closed 5 years ago

AlexisHuvier commented 5 years ago

Hey, i made a parser with theses productions :

@self.pg.production('if_statement : IF expression OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO')
        def ifexp(p):
            return If(p[1], p[4])

        @self.pg.production('if_statement : IF expression NEWLINE OPEN_CRO NEWLINE statementlist NEWLINE '
                            'CLOSE_CRO')
        def ifexp2(p):
            return If(p[1], p[5])

        @self.pg.production('if_statement : IF expression OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO '
                            'ELSE OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO')
        def ifelse(p):
            return IfElse(p[1], p[4], p[10])

        @self.pg.production('if_statement : IF expression OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO '
                            'NEWLINE ELSE OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO')
        @self.pg.production('if_statement : IF expression OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO '
                            'ELSE NEWLINE OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO')
        def ifelse2(p):
            return IfElse(p[1], p[4], p[11])

        @self.pg.production('if_statement : IF expression OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO '
                            'NEWLINE ELSE NEWLINE OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO')
        def ifelse3(p):
            return IfElse(p[1], p[4], p[12])

        @self.pg.production('if_statement : IF expression NEWLINE OPEN_CRO NEWLINE statementlist NEWLINE '
                            'CLOSE_CRO ELSE OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO')
        def ifelse4(p):
            return IfElse(p[1], p[5], p[11])

        @self.pg.production('if_statement : IF expression NEWLINE OPEN_CRO NEWLINE statementlist NEWLINE '
                            'CLOSE_CRO NEWLINE ELSE OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO')
        @self.pg.production('if_statement : IF expression NEWLINE OPEN_CRO NEWLINE statementlist NEWLINE '
                            'CLOSE_CRO ELSE NEWLINE OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO')
        def ifelse5(p):
            return IfElse(p[1], p[5], p[12])

        @self.pg.production('if_statement : IF expression NEWLINE OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO '
                            'NEWLINE ELSE NEWLINE OPEN_CRO NEWLINE statementlist NEWLINE CLOSE_CRO')
        def ifelse6(p):
            return IfElse(p[1], p[5], p[13])

But if i made this code :

a = enter("Votre age : ")
a = int(a)
if a >= 18
{
    show("Vous etes majeur")
}

show(a)

I have an error on show. So i think, parser think this is a IFELSE statement but no.

Can you help me ?

alex commented 5 years ago

Unfortunately I'm not ablw to provide support in creating parsers, unless you think you've found a bug in rply you'll need to get support somewhere else (e.g. Stack Overflow).