help-bison
[Top][All Lists]
Advanced

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

Re: New user, seeking example


From: Markus Weißmann
Subject: Re: New user, seeking example
Date: Thu, 3 Sep 2009 10:54:50 +0200 (CEST)
User-agent: SquirrelMail/1.4.13

> 2009/9/2 "Markus W. Weißmann" <address@hidden>:
>
>> There is a wiki grammar described in this paper [1]; it is for ANTLR
>> afair,
>> but as ANTLR is just a LL parser generator, a transformation should be
>> rather easy.
>
>
> Mmm.
>
> Antlr has
> heading
> : heading_markup heading_content ( heading_markup )? ( blanks )?
> paragraph_separator
>
> Optional content ?  0 or 1
> Multiple repeats  * 0 .. many
>
> How are these done in Bison please?
>

optional statements can be done with (potentially) empty statements OR
with stating all cases; the best choice depends on how many combinations
there are for listing all cases, reusability of statements and your
personal preferences;

optionals would look like this:

%%
heading : heading_markup heading_content heading_markup_opt blanks_opt
paragraph_separator
        ;

heading_markup_opt : heading_markup
       | { /* EMPTY */ }
       ;

blanks_opt : blanks
       | { /* EMPTY */ }
       ;
%%

combinations could be written like:

%%
heading : heading_markup heading_content heading_markup blanks
paragraph_separator
       | heading_markup heading_content blanks paragraph_separator
       | heading_markup heading_content heading_markup paragraph_separator
       | heading_markup heading_content paragraph_separator
        ;
%%


writing 1..* would be done with a list statement -- either pre- or
postfix, depending on your needs.

%%
bar_lst : bar bar_lst
    | bar
    ;

foo_lst : foo_lst foo
    | foo
    ;
%%


Regards,

-Markus

-- 
Markus Weißmann, M.Sc.
Institut für Informatik
Technische Universität München
Raum 03.07.059, Boltzmannstr. 3, 85748 Garching






reply via email to

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