Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

How does perl's lexer and parser cooperate?

by PerlOnTheWay (Scribe)
on Dec 26, 2012 at 12:24 UTC ( #1010373=perlquestion: print w/ replies, xml ) Need Help??
PerlOnTheWay has asked for the wisdom of the Perl Monks concerning the following question:

For example in perly.y there's the terminal token GRAMPROG,

but this is not even mentioned in toke.c

Where does perl define the terminal tokens, and how lexer and parser cooperate?

Comment on How does perl's lexer and parser cooperate?
Select or Download Code
Re: How does perl's lexer and parser cooperate?
by Anonymous Monk on Dec 26, 2012 at 12:44 UTC
Re: How does perl's lexer and parser cooperate?
by dave_the_m (Parson) on Dec 26, 2012 at 14:14 UTC
    GRAMPROG is a 'fake' token that is actual passed as an arg to yyparse() to say what type of thing we want to parse; i.e. its an extension to the usual yacc/bison stuff which just has a hard-coded start, e.g.
    %start prog
    or similar.

    So the GRAM* stuff is fake; the rest of the tokens are returned by llyex in toke.c in the usual way.

    Dave.

      Dave, nice to see you again!

      It seems GRAMPROG is not the only one that's special, I tried to search other symbols like ADDOP in toke.c

      but it's never defined to "+" there.

      where are these terminal symbols finally defined?

        It seems GRAMPROG is not the only one that's special, I tried to search other symbols like ADDOP in toke.c but it's never defined to "+" there. where are these terminal symbols finally defined?
        I think you're misunderstanding how this works. ADDOP (and many of the others) don't correspond to actual terminal symbols like '+'. They are just numerical constants (ADDOP is defined as 305 in perly.h). yylex returns this value for multiple "addish" operator types, such as '+', '-', '.'; with extra info in the ival field indicating what op to use (such as OP_ADD, OP_CONCAT etc).

        Dave.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1010373]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2014-09-20 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (155 votes), past polls