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: Istvan Sandor
Subject: Re: indentations instead of endtag in a grammar
Date: Wed, 17 Feb 2010 14:30:41 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

Hi,

> How can i tell Bison that that it has to look for the indentations? Has
> anyone maybe an example that he/she can send me ? it would be very helpful,
> because i havent seen such an example.

Whitespace is usually handled by the lexer, in this case you need an
indication of the amount of leading whitespace for each line.

For example you could generate INDENT and DEDENT tokens (if I remember
right this is how it's done in python). An INDENT token would be
generated if the indentation level increases, a DEDENT if it decreases.

So the if would look roughly like:

if : IF INDENT stmt_list DEDENT


The lexer has to store the last seen indentation level and check the
indentation at each line:

if(current_indent < stored_indent) {
        stored_indent = current_indent;
        return DEDENT;
}
if(current_indent > stored_indent) {
        stored_indent = current_indent;
        return INDENT;
}

regards
Istvan




reply via email to

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