Include C-project files

SyntaxEditor for Windows Forms Forum

Posted 11 years ago by Stepan Protsak
Version: 12.1.0304
Avatar

Hi,
I'm in process of writing parser for ANSI C language for SyntaxEditor v4.0. I'm doing that modifying .NET Languages Add-on source code (per your recommendation in this thread).
I've played some time modifying grammar definition file (ActiproSoftware.CSharp.Grammar.xml) with relative success.
Now I've started including and parsing relative files in C project.


Can you, please, give me a quick suggestion (starting point) how to implement the next two items:


1. How to make the 'Using' token works as it should, but set the "#include" string for recognizing this token?
I've tried to move the token to the 'PreProcessorDirectiveKeywordStart/End' scope in Grammar file. Also I've make relative changes in "GetTokenString" and "IsPreProcessorDirectiveStateScopeStart". But this doesn’t work for me: LookAheadToken in "MatchCompilationUnit" skips ‘Using’ token and its parameter and returns to me the next available token.


2. How can I parse source files which are referred as ‘#include <filename>’ and ‘#include "filename" ‘. I need this to include the types from these files to IntelliPrompt member list.


Asking you for help because documentation is not sufficient to do this without digging in huge amount of code (I’ve spend much more time doing that than expected and now can miss the schedule).
Thank You!

Comments (1)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Stepan,

We are more C# people here and haven't done C in quite a long time, so you'll have to bear with us.

If I was going to add some form of #include pre-processor directlve, I would probably start by looking for where something similar, like DefinePreProcessorDirective was defined and used throughout the code.  I'd add an IncludePreProcessorDirective and related processing in all the same locations.

The code in CSharpRecursiveDescentLexicalParser.GetNextTokenCore has special processing that handles pre-processor directives.  I'd probably add a collection in that class similar to how we do RegionTextRanges to accept a list of #include values and if I see an IncludePreProcessorDirective, append the value to that.

Then add a related collection for #include values on CompilationUnit.  At the bottom of the CompilationUnit production in the grammar, move the CSharpRecursiveDescentLexicalParser's new collection of #include values over to the CompilationUnit.

So at this point you have all the #include values on the CompilationUnit and accessible by any code you have that does resolution of types.  You might want to go look up the files right during the parse and parse them as well, then put their results in the AST that will be returned.  Or alternatively just do it on-demand when type resolution is needed.

I hope that helps.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.