help-bison
[Top][All Lists]
Advanced

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

RE: about lr(1) parsers


From: chinlu chinawa
Subject: RE: about lr(1) parsers
Date: Wed, 2 Aug 2006 10:50:01 +0100 (BST)

>Keywords, or hardwired names, are normally added 
>in the lexer, which may be generated by Flex. If 
>you want to have constructs such as 'define
><name>...', one way to do it is to make a lookup 
>table, where <name> is entered along with 
>syntactic and semantic data. When the lexer 
>finds a name, it checks the lookup table, and if 
>found, returns the correct token and passes the
>semantic data to the parser.

Hello Hans,

Am, what you mean with semantic data?

I've used your example, as I saw a simple cpp would be
a godd starting point.

However, I'm far from being able to do things like
this, if it's what you mean with semantic data:

#define max ((x)>(y)?(x):(y))

As it would require expansions and well, and a lot of
things I cannot do yet. Instead I'm using simple
constructions such like:

#define some   thing

or

#ifdef something
.....
#endif

which is more easily implementable.

So far, I've started to understad finite automatas,
have implemente one, together with linked lists rather
than perfect hashing and lookup talbes, that allows me
to start playing around #define and #ifdef more easily

Indeed, since I started to understand finite automata,
same has happend with lr(1) parsers, and I've got two
questions today, hope you can help.

In one hand, I don't seem to fully understand what a
finite automata should output, and how this output
should be feed to the parser.

As you said, I'm using hardcoded keywords, and can
recognize for example when a #define, #ifdef or just a
comment is coming over, though none of them looks like
a good example for this question.

Supossing that I have this:

sum 1+1

And that I recognize `sum' with the finite automata,
what should I pass to the parser (appart from 1+1 I
guess)?

I though feeding a parser with `1+1' would output the
result of that operation, though if you look this:

http://en.wikipedia.org/wiki/LR_parser

At the end of the example part, it says:

"The rule numbers that will then have been written to
the output stream will be [ 5, 3, 5, 2 ] which is
indeed a rightmost derivation of the string "1 + 1" in
reverse."

And my question to this regard is, what I'm supossed
to do with that `[ 5, 3, 5, 2 ]'?

Any clues?

Kind Regards,




        
        
                
___________________________________________________________ 
All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease 
of use." - PC Magazine 
http://uk.docs.yahoo.com/nowyoucan.html




reply via email to

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