[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grammar
From: |
Hans Aberg |
Subject: |
Re: grammar |
Date: |
Sat, 14 Apr 2001 11:50:16 +0200 |
At 14:03 +0200 2001/04/13, address@hidden wrote:
>Could someone tell me how I can write the grammar to parse such message:
>
>abbcccd
>
>in which
>a is mandatory and non repetitive,
>b is mandatory and repetitive,
>c is optional and repetitive,
>d is mandatory and non repetitive.
If you are only interested in regular words, and do not intend to attach
actions to the rules, you can use Flex
ftp://ftp.digital.com/pub/GNU/non-gnu/flex/flex-2.5.4a.tar.gz
If you need greater generality, under C++, you could create a istream that
outputs characters representing grammar symbols.
Alternatively, using Bison, you could write your grammar as EBNF, and then
apply the definitions reducing to BNF (using Bison notation)
a? := | a -- Optional.
a+ := x, where x: a | x a -- One or more.
a* := x, where x: | x a -- Zero or more.
One the more advanced level, one could try tweak Bison so that it
understands EBNF directly. -- This is the way that mid-actions are
implemented (i.e., by introducing a new empty rule with an action). If you
do this, please don't report it to Bison bugs.
Hans Aberg
- grammar, bvermaut . cs, 2001/04/13
- Re: grammar,
Hans Aberg <=