help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: indentations instead of endtag in a grammar


From: Andreas Wagner
Subject: Re: indentations instead of endtag in a grammar
Date: Thu, 18 Feb 2010 16:22:19 +0100

I have just one small question left. Is it possible to get the *.y file as
well? If not its ok because its your code. I just want to understand the
behaviour between flex and bison with line indentations.

Regards


2010/2/18 Andreas Wagner <address@hidden>

> Hi Conrad,
>
> very much thx for your answer and the link to the parathon.l file. I think
> this could help me a lot. Im not trying to parse Phyton-code. I have a
> language which is "python-like" cause of the line indentations.
>
> Regards
>
> 2010/2/17 Conrad Irwin <address@hidden>
>
>
>>
>> On 02/17/2010 02:22 PM, Andreas Wagner wrote:
>> > Thx for your fast answers. I will take a look.
>> > @ Istvan is it possible that u send me the *.l & *.y files for python
>> > (if u have them)?
>> > Or post a link. Always when i search for python and .y or bison i just
>> > find links to PyBison or PLY but no bison and lex file for Python.
>> >
>>
>> Real Python has a hand-coded tokenizer and their own parser generator,
>> probably explaining why you haven't found what you were looking for
>> (though downloading the source code would tell you that pretty quickly).
>>
>> As part of a recent project, I implemented a lexer for Python [1]; as it
>> runs is a fairly complex environment (and I'm rubbish at writing C), you
>> won't be able to compile it, but the ideas are copyable. The bison
>> parser is auto-generated from some C++ class files, so it's not terribly
>> illuminating either, an excerpt:
>>
>> if_statement: TOK_IF test_phrase TOK_COLON suite {
>>                $$ = IfStatement::parse($1, $2, $3, $4); }
>>            | if_statement TOK_ELSE TOK_COLON suite {
>>                $$ = IfStatement::parse($1, $2, $3, $4); }
>>            ;
>> suite: simple_statement TOK_NEWLINE {
>>        $$ = Suite::parse($1, $2); }
>>     | TOK_NEWLINE TOK_INDENT suite_body TOK_OUTDENT {
>>        $$ = Suite::parse($1, $2, $3, $4); }
>>     ;
>>
>> Note that in addition to keeping a stack of indentation levels, the
>> lexer also keeps track of open brackets, as a newline inside a bracket
>> does not count as significant in Python (nor a newline after a \).
>>
>> Yours
>> Conrad
>>
>> [1] http://jelzo.com/got/181/parathon.l A lexer for Python(ish).
>>
>>
>>
>> _______________________________________________
>> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
>>
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]