473,383 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

lexical grammar

let's say we have the following declaration:

volatile int (*func)(int a);

We start with a declaration (A.2.2)
that expands to declaration-specifiers?
We find the right form:
type-qualifier declaration-specifiers opt?
after volatile is expanded, we look for
type specifier:
type-specifier declaration-specifiers opt

So after that is expanded we have:
(*func)(int a);

this counts as a init-declarator?
If so, then we expand it as a declarator
since it is not being initialized?

Then that brings us to the rule:
pointer opt direct-declarator
for (*func)(int a);

No pointer encountered yet, so we continue
expanding:

direct-declarator:
identifier
( declarator )
direct-declarator [ type-qualifier-list opt assignment-expression opt ]
direct-declarator [ static type-qualifier-list opt
assignment-expression ]
direct-declarator [ type-qualifier-list static assignment-expression ]
direct-declarator [ type-qualifier-list opt *]
direct-declarator ( parameter-type-list )
direct-declarator ( identifier-list opt )

We encounter ( declarator )
and reapply this rule?

If so, then the rule pointer opt direct-declarator
for declarator works here and we expand
the declarator part which qualifies as an
identifier. But that leaves us with:
(int a);

Which I wonder, where is the rule that should
be applied here that follows from our expansion?

Somewhere in the rules of direct declarator
we should branch to a rule that solves a parameter
list. But because our construction was (*func),
we should ignore the identifier in parens after
resolving that it was an identifier from
the direct declarator rule, right?

This is where I don't see how we branch to
a rule that resolves the parameter list.

I don't think it would be the following
rule:
direct-declarator ( parameter-type-list )
unless we consider the expanded identifier
as a direct declarator?

Also, chris torek, if you are reading this,
what data structure would you recommend for
representing this? I read an older
article by you that describes this process
as being in factored form. How do you recommend
to factor it all programmatically?

--
aegis

Nov 14 '05 #1
1 1930
"aegis" <ae***@mad.scientist.com> wrote:
Then that brings us to the rule:
pointer opt direct-declarator
for (*func)(int a);
You are (AFAICT!) OK up to here, but...
No pointer encountered yet, so we continue
expanding:

direct-declarator:
identifier
( declarator )
direct-declarator [ type-qualifier-list opt assignment-expression opt ]
direct-declarator [ static type-qualifier-list opt
assignment-expression ]
direct-declarator [ type-qualifier-list static assignment-expression ]
direct-declarator [ type-qualifier-list opt *]
direct-declarator ( parameter-type-list )
direct-declarator ( identifier-list opt )

We encounter ( declarator )
and reapply this rule?
....if so, we run into problems (as you see), so we take the next option
that applies, which is

direct-declarator ( parameter-type-list )

The first part (the direct-declarator) matches (*func), which you've
already done; the second part - ( parameter-type-list ) - matches the
(int a).
This is where I don't see how we branch to
a rule that resolves the parameter list.

I don't think it would be the following
rule:
direct-declarator ( parameter-type-list )
unless we consider the expanded identifier
as a direct declarator?
And you've just proved that it is, so all is fine, surely?
Also, chris torek, if you are reading this,
what data structure would you recommend for
representing this?


A tree, most likely.

Richard
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bengt Richter | last post by:
We have where syntax in combination with suite expression syntax (bear with me, I think a good synergy will emerge ;-) ...
0
by: Collin VanDyck | last post by:
Hello! I have set up a pluggable SAX transformation pipeline which is made up of individual nodes that transform the source XML, and for the most part it works well. Each node in the pipeline...
4
by: bariole | last post by:
Hi I am trying to make lexical analysis of some simplified html code with flex tool. However that kind of work is new to me and I don't know where to start. I have searched a web but I didn't...
3
by: junky_fellow | last post by:
I got one link to the ANSI C Grammar http://www.lysator.liu.se/c/ANSI-C-grammar-y.html However, I don't know how to understand this grammar. I am not a Computer Science Guy. Can anybody please...
13
by: Lucas Zimmerman | last post by:
Is there any Lex code available that describes how to scan C programs? I'd like to read someting related to this. One of my doubs is how C deals with ambiguities, for example, `a = x/*p;' or `a =...
2
by: Frank-René Schäfer | last post by:
penSource Project 'Quex': http://quex.sf.net Last weekend, the lexical analyser generator 'Quex' has been released on SourceForge. Quex provides advanced features for mode definitions and...
10
by: MBR | last post by:
Hello... I'm using the grammar at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_c.asp as a reference in creating my own C# parser using a custom...
6
by: enaeher | last post by:
I would expect this code: globalFnArray = ; for (var i = 0; i < 5; i++) { globalFnArray.push (function () { alert (i) }); } for (var j = 0; j < 5; j++) { globalFnArray(); } to alert 0, 1, 2,...
14
by: Khookie | last post by:
Woah... is it just me or do C programmers don't bother talking about how cool C can be (compared to Lisp, Haskell, etc.) - functionally speaking? // Lexical scoping - via nested functions...
3
by: globalrev | last post by:
i cant figure outif python has lexical or general scope. it seems functions have lexical scope but with some restrictions and some non-function scopes are dynamic?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.