Below is my bison file. What i want to parse is something like this -


a,s,d,sad,asd;


but it parses correctly only when i do this-


asd; , asd;
OR
assd;


Whats the problem with my code???

bison:


%token IDENTIFIER END_STMT CONST VOLATILE COMMA
%start translation_unit
%%


translation_unit:
/* nothing */
| translation_unit external_definition ;

external_definition:
declaration;

declaration: init_declarator_list END_STMT

init_declarator_list:id
| init_declarator_list COMMA id END_STMT

id:IDENTIFIER ;


%%


flex:


WSPACE [ \t\r\v]+
LETTER [a-zA-Z_]
DIGIT [0-9]
IDENT {LETTER}({LETTER}|{DIGIT})*
%%

";" {return END_STMT;}
',' {return COMMA;}
. {}
"const" {return CONST;}
"volatile" {return VOLATILE;}
\n {}
{WSPACE} {}
{IDENT} {return IDENTIFIER;}
%%
Posted on 2001-12-19 03:49:03 by MovingFulcrum
You might have better luck in a newsgroup - sorry, can't remember which one? This should have been posted in the heap? Edit: Oh, try comp.compilers
Posted on 2001-12-19 04:19:47 by bitRAKE
Thanks for the link bitRake but i finally manged to find the answer myself (that was after i had already posted the problem on comp.compliers, duh!)

It was this little thing -
',' 

which should actually have been -
","



GRrrr... I feel like shouting out loud now.

Posted on 2001-12-19 22:47:21 by MovingFulcrum
Try designing it all in asm w/o flex. That is what I'm doing, but that is because I need everything to be real-time: color-highlight, intellisense, assemble, code analysis. It's actually not much harder than doing intellisense by itself.
Posted on 2001-12-20 00:18:26 by bitRAKE
I dont need to code it manually. My color highlighting is already done real time.
The parsing and lexing will carry on in its own thread. Plus it doesnt have to parse
real time because probably the only time you will need it is when you press Ctrl-Space or in the tree view.
When you access either of them, that time only you will have to wait a bit to parse out the unparsed text and thats it. Also it doesnt needto check for validity of types, etc or parse mathematical operators, so it shouldnt be too slow.Plus I dont want real time compiling or code analysis.

Btw, What exactly do you mean when you say "code analysis"?

Btw, For how long have you been coding intellisense <prepares to get scared:) >
Posted on 2001-12-20 06:32:45 by MovingFulcrum
Don't worry you'll finish before me. I only code ten or so hours a week. I have been taking notes with the little bits of time here and there for over a year now. Mainly trying to design the data structures because it's a data driven design. I've been collecting and debugging the processor tables. Still have the API tables to do as well. There is a great deal of information in the table - so, I'm learning much doing it.

"code analysis" is the display of processor/memory state as you code. :) It's like a debugger, but built into the editor. There is much that is unknown until run-time, but there is also a great deal that is known without running the code. This information also helps the optimizer. I remember programming from debug in DOS and it was nice because you were coding/debugging at the same time - no assemble time. That's how I want this to be. Maybe, even allow the user to check the timing on sections of code. The goal is to provide as much information as the user wants in real-time.
Posted on 2001-12-20 12:41:51 by bitRAKE
bitRake,
Just one last question. I know this should be in comp.compilers but my previous post over there hasnt appeared even till now.

I still cant understand the difference between a reentrant and nonreentrant parser. I read the defintion in the bison mannual but i still cant get it. Can somebody explain plsssssss.
Posted on 2001-12-21 01:40:54 by MovingFulcrum
If the parser engine is reentrant, it can be used to parse more than one language in the same app. Or it can parse one language in several files simultaneously.
Posted on 2001-12-21 16:33:09 by tank
Im trying to lean flex and bison, anyone know any good tutorials?
Posted on 2001-12-21 19:27:33 by ChimpFace9000
Thanks everyone for replying. I guess a reentrant parser would be best for me:)

ChimpFace,
The bison and flex manuals are the best read. I dont knw of any such tutorials but this one on writing a scripting language is pretty good.
http://www.flipcode.com/tutorials/tut_scr01.shtml
tut_scr01 to tut_scr09. Just keep changing that no and you will proceed through the tut series :)
Posted on 2001-12-21 21:37:36 by MovingFulcrum
Ok thanks. I understand lex pretty well, but i just cant understand bison.
Posted on 2001-12-21 23:03:16 by ChimpFace9000
Yeah,
The BNF syntax can be a bit confusing, take a look at the links i pointed you to. If you have any specific questions post them here:)
Posted on 2001-12-21 23:08:03 by MovingFulcrum
Here is a good read as well: Code Generation Templates Using XML and XSL
Could be done for ASM, too!
Posted on 2001-12-22 21:35:18 by bitRAKE
Ok, i got a lex problem.

Im trying to get hex numbers from the input.

This is what im using in lex...
[0-9A-Fa-f]+		{ printf("'%s'", yytext); }


When i type "3456a", itll print "3456a". But if i type "34j56", itll print "34" report an error about the "j" and print "56". How do i stop this?
Posted on 2001-12-27 13:00:25 by ChimpFace9000