News:

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

YACC Function Specification

Started by cman, April 18, 2005, 01:52:42 PM

Previous topic - Next topic

cman

How is a function header expressed in a YACC file? Something like this:


 
   
   void myFunction ( param1 , param2 , param3 .... );




 


What I'm wondering is how to express that an unlimited number of parameters ( to a point ) are allowed in a function call in EBNF ? Also , How are these parameters accessed within the YACC code ( in the sematic action part of the code ) ? Thanks for any help....

tenkey

It's just easier to specify an unlimited number of arguments using left recursion. Left recursion keeps parse stack usage low on an LR parser like YACC.

My YACC syntax is weak, so I'll give it in old fashion BNF

<function definition> ::= <type> <identifier> '(' <formal argument list> ')' ';'

<formal argument list> ::= <formal argument> | <formal argument list> ',' <formal argument>
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

cman

OK , thanks tenkey! I found a grammer at http://www.lysator.liu.se/c/ANSI-C-grammar-y.html . How is the sematic action delt with ? Like this :



<function definition> ::= <type> <identifier> '(' <formal argument list> ')' ';'
{

    //how do you access the parameters here ( how do you know how many there are ) ?

};



Is there some "yy" prefix value that you use to determine the parameter count. And if so , how is this expressed in the sematic action after the statement? Thanks....