News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ytab.h ?????

Started by cman, January 09, 2005, 01:14:20 AM

Previous topic - Next topic

cman

I'm useing a version or flex/bison that I downloaded at

    http://www.monmouth.com/~wstreett/lex-yacc/lex-yacc.html

but the file ytab.h is missing when I use flex to generate a scanner. I belive I used flex once to generate a scanner ( from a tutorial ) with a certain command-line switch and I was able to compile the result with Borland Turbo 5.1.1 . Is there a switch I need to use or is the version of flex I'm useing incomplete in some way? If so where could I find a "full version" of the software. Thanks.....  :toothy

ÇódèKñïght

#1
you can get the full version from here http://gnuwin32.sourceforge.net/packages/flex.htm
I don't remember that i have any problems like that anyways you can  post your grammar and command line if you are still having this problem.

cman

OK , thanks! Sorry for the late reply ( I've been working many hours lately ). I'll try this out now that I have some time off .  :U

Randall Hyde

Quote from: cman on January 09, 2005, 01:14:20 AM
I'm useing a version or flex/bison that I downloaded at

    http://www.monmouth.com/~wstreett/lex-yacc/lex-yacc.html

but the file ytab.h is missing when I use flex to generate a scanner. I belive I used flex once to generate a scanner ( from a tutorial ) with a certain command-line switch and I was able to compile the result with Borland Turbo 5.1.1 . Is there a switch I need to use or is the version of flex I'm useing incomplete in some way? If so where could I find a "full version" of the software. Thanks.....  :toothy

IIRC, this file is actually generated by Bison when you use the -d option (certain versions of flex/bison may use ytab.h by default, I don't know because I always override this name when I compile the HLA source code). YMMV, depending on whom you got flex & bison from, but I'm pretty sure ytab.h is one of the many default names that bison packages produce.
Cheers,
Randy Hyde

cman

Darn! I can't seem to get anything to compile. :( I've attached a tutorial I found on the web. Can anyone explain the process to generate and compile the output? Thanks....

[attachment deleted by admin]

cman

OK , does anyone know of a tutorial with instructions on how to create the finished product ( the parser executable ? ) . Thanks for any information...

tenkey

If the two files in your attachment are supposed to be used together, you run yacc/bison and lex/flex before running the C compiler. You must find out from the docs what files these programs generate, so you know what to include when you call the C compiler.

You may as well do a search for "bison" and "flex", or "yacc". There are tutorials out there.

Here's a Unix tutorial for yacc: http://epaperpress.com/lexandyacc/
And a long one for bison: http://cs.wwc.edu/~aabyan/464/Book/
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

cman

Thanks tenkey!! I hate to use code generation software , but this seems like the way to go. A LR parser does not seem like that much work to construct , once all the states ( and productions for a state ) are found to construct the parse table; start with state 0 ,put the start symbol symbol in the set , include all productions derivable from the start symbol in the set ( closure rule ) , go to the next nonterminal  ( next state ) , do the same , ect. ,after this determine which states correspond to a shift and which to a reduce , ect. ( I take it this is the hard part of the process , the driver code for the parser does not look too complicated ). I'll try to get this to work! Thanks again!!!!!!  :toothy

cman

Should I be able to create a stand-alone scanner with flex? I keep getting a message from my compiler "unresolved external _yywrap" . Do I need to define a function called yywrap. If so , how. Thanks.......

ÇódèKñïght

 :bg
yywrap() is used when you have multiple files to scan one after another, you are getting this error because you haven't provide yywrap() either you should provide yywrap() to flex and return true

like this

int yywrap()
{
retrun 1;
}

or use
%option noyywrap

in your definitions section of flex file



cman

Thanks , CodeKnight! I finally got something compiled with your help ( all involved ). Thanks so much! I was wondering , how do I tell the lexer to find key words , when a keyword ( reserved word ? ) has the same definition as an identifier ( a block of characters starting with a letter and then letters or numbers ). Doesn't an reserved word fall into both categories with the definitions:

 

identifier           [a-z][a-z0-9]*    {  ...... }

if                                             {         }

[/code ]

since "if" satisfies both definitions? Which block of instructions is executed for "if" ( both ? ). Thanks......

Randall Hyde

Quote from: cman on January 24, 2005, 02:15:39 AM
Thanks , CodeKnight! I finally got something compiled with your help ( all involved ). Thanks so much! I was wondering , how do I tell the lexer to find key words , when a keyword ( reserved word ? ) has the same definition as an identifier ( a block of characters starting with a letter and then letters or numbers ). Doesn't an reserved word fall into both categories with the definitions:

 

identifier           [a-z][a-z0-9]*    {  ...... }

if                                             {         }

[/code ]

since "if" satisfies both definitions? Which block of instructions is executed for "if" ( both ? ). Thanks......


Whenever there is an ambiguity, FLEX uses the *first* rule it finds. Therefore, put your definition for identifiers *after* all your reserved words and you'll be okay.
Cheers,
Randy Hyde

cman

#12
Thanks Randall! I can't say enough how I appreciate the help I receive here ( masmforum ). So if I have a token that is a "super set" of another token , I place this token after the "subset"? As in the case:


"if"                     {
                             printf ( "if found" ) ;
                             return IF;
                          }


[a-z][a-z0-9]*     { 
                           printf ( "identifier found" );
                           return IDENTIFIER;
                        } 




but I can't seem to make something like this work:



..............
digit                        [0-9]
dentifier                  [a-z][a-z0-9]*
passThru                 @[ -~]+@   /* pass any block of characters though delimited by @ */
..........
%%

{identifier} {
                         cout << "identifier found\n";
                                     return Identifier;
                                }
{passThru}                 {
                                    cout << "pass through text" << endl;
                                    return Thru;
                                }

................

%%


When I declare the tokens like this , it seems that a passThru ( a way to write text that the parser cannot identify , but a program that performs a step after this can (  much in the same way that the C++ grammer denotes an inline assembler statement : "asm" [ <string> ] )  is parsed as a series of symbols and identifiers ( @ then and idenfier or symbol for each block of characters delimited by the @ character ). But , if I declare the "super set " first (  @[ -~]+@ ) ( "super set" with conditions that it starts and ends with the "@" character" ) then the parser works properly. I think I have LR ( 1 ) parsing learned  , but need to know how the "grammer compiler" generates code from the order of the statements I  present. Thanks........

Randall Hyde

Quote from: cman on January 25, 2005, 03:20:33 PM

but I can't seem to make something like this work:



..............
digit                        [0-9]
dentifier                  [a-z][a-z0-9]*
passThru                 @[ -~]+@   /* pass any block of characters though delimited by @ */
..........
[/quote]

Don't forget that '@' is part of the sequence ' '..'~', so the regular expression above, which matches the longest sequence surrounding by '@' symbols, may include stuff outside the @...@ sequence.  I'm assuming, of course, that you realize that the above does not include newlines and other control characters.


The general way to handle something like this is to use "context sensitive" sequences.  The following, from HLA v1.x, is the typical way one eats comments in a language like C/C++ or HLA:

\/\*         { BEGIN comment;      }
<comment>.      {}
<comment>\n      { ++LineCnt; ++TotalLines;   }
<comment>\*\/      { BEGIN 0;         }


Look up "context senstive" in the FLEX documentation for more details.
Cheers,
Randy Hyde

cman

Thank you very much , indeed ! So I'd be better off defineing a passThru as such:



passThru         @[^@]+@



or something like that  :bg......