Hi
I'm trying to build a parser for a file I create. The file format is as
follow:
IDENTIFIER = NUMBER STRING STRING;
COMPOSITE = STRING { ITEM [, ITEM, ...] };
ITEM = NUMBER IDENTIFIER|COMP OSITE
A file example is as follow:
eggs_with_bacon = 1 { 2 eggs, 1 bacon_strip };
eggs = 0.02 "Egg" "Unit";
bagon_strip = 0.04 "Bacon strip" "Unit";
(My idea was to use it as means to calculate costs of buildings, so you
can detail it to the level of bricks and mortar, and get the total price
of the building, but it can be used as a means to calculate any kind of
costs).
I have already started building a parser, using bison/flex, with rules:
(flex rules)
[[:digit:]]+("."[[:digit:]]*)? return NUMBER;
[:alpha:][[:alnum:]_]* return IDENTIFIER;
\"[^\"]\" return STRING;
\= return EQUAL;
\{ return LBRACE;
\} return RBRACE;
\, return COMMA;
\; return SEMICOLON;
^#.*\n$ /* eat comments */
[.\n]+ /* eat this */
(end flex rules)
(bison rules)
line: /* empty */
| line description;
description: short-description
| long-description;
short-description: IDENTIFIER EQUAL NUMBER STRING STRING SEMICOLON;
long-description: IDENTIFIER EQUAL NUMBER LBRACE items RBRACE SEMICOLON;
items: item
| items COLON item;
item: NUMBER IDENTIFIER;
(end bison rules)
I added some dummy actions to the bison rules, just to debug it, and I'm
getting "parse error" after the first line is parsed. I think there are
something I'm missing, the parser should get to state 0 after reading
the first rule, but it is going to other state, and gives the 'parse
error'. Can someone tells me what is wrong with the rules?
TIA
P.S.: Sorry for the "engrish".
--
..O. Cesar A. K. Grossmann ICQ UIN: 35659423
...O http://www.LinuxByGrossmann.cjb.net/
OOO Quidquid Latine dictum sit, altum viditur