[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] How to extend the C99 / GCC LR Parser
|
There's not a lot of documentation on the LR parser, but you can take a look at the UPC and XLC++ parsers, they serve as good examples of how to extend the LR parser.
This is how I handled keywords in the UPC parser... I kept the default behavior of the preprocessor which returns them as identifier tokens. Then I provided an implementation of IDOMTokenMap that maps those identifier tokens that match the keyword to the proper token type that LPG expects. If you take a look at the UPCLanguage class in the UPC parser you can see how that's done. Also, UPCLangage returns an instance of ICLanguageKeywords from its getAdapter() method, this is required for the new keywords to be highlighted in the editor.
Keep in mind that while the LR parser is extensible the rest of CDT is not. Any new types of AST nodes you add will not be recognized by CDT unless they implement existing interfaces. Therefore the amount of extensibility provided by the LR parser is very limited.
|
![]() |
Mike Kucera | ![]() | |
Rational Multicore Tooling | ![]() |
UI Team Lead | ![]() |
IBM Toronto Lab | ![]() | ![]() |
mkucera@xxxxxxxxxx | ![]() | ![]() |
|
|
"Sebastian Wagner" ---07/07/2011 11:15:34 AM---Hello all, I am working on a parser for a C based language which contains some small extensions, e.g
From: "Sebastian Wagner" <se.wagner@xxxxxx>
To: cdt-dev@xxxxxxxxxxx
Date: 07/07/2011 11:15 AM
Subject: [cdt-dev] How to extend the C99 / GCC LR Parser
Sent by: cdt-dev-bounces@xxxxxxxxxxx
Hello all,
I am working on a parser for a C based language which contains some small extensions, e.g. special type qualifiers. Therefore I would like to extend the C99 or GCC LR Parser.
I read a lot of content in the web and CDT source code. I managed to generate the Parser from the grammar file and I'm able to compile the generated files. I also understood that today the lexer is not generated using the LPG, but is a part of the preprocessor.
Now, nevertheless I didn't get the complete overview where I need to do changes if for instance I want to add a new type qualifier "__data16". Do I have to do modifications on the preprocessor and do I do that? I think keywords can be added using the ScannerExtensionConfiguration, but I don't know how to do this correctly. Do I also need to do adaptations to the AST?
It would be great if one of you could give me a short overview in which modules I need to do modifications, so that I understand the behavior better.
Thanks in advance!!
Sebastian Wagner
___________________________________________________________
Schon gehört? WEB.DE hat einen genialen Phishing-Filter in die
Toolbar eingebaut! http://produkte.web.de/go/toolbar
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


