HAT-trie in ANSI C implementation? - c

I am looking for ANSI C HAT-trie implementation released under some free license. I have not found one. Can you point me to some standalone implementation or a program that uses
HAT-tries to get at least slight idea how to implement it the roght way, please?
The original paper on HAT-trie can be found here:
http://crpit.com/confpapers/CRPITV62Askitis.pdf
PS: In case faster cache-conscious data structured well-suited for strings evolved since
the time the above paper was written, please point me to the papers or example source codes rather.

Someone is implementing it in C++ over on github
https://github.com/chris-vaszauskas/hat-trie
If you need a plain C implementation, this would be a good base to start from.
Java is also fairly readable for a C programmer
http://www.stochasticgeometry.ie/2008/05/06/implementing-hat-tries-in-java/

Please see the HAT-trie implementation site at code.google.com/p/hat-trie for implementation notes and source code.

Related

A more complete recursive descent c interpreter

I've seen several implementations of recursive descent c interpreters which all seem
to do a pretty good job - yet they all only implement a small portion of the C language -
for example they don't support structs or typedefs etc -
Does anyone know of any code that supports a large portion of the C language.
I know adding more functionality would be pretty trivial - but I'm a bit strapped
for time.
Picoc supports more that most of the Tiny/Small C interpreters. You might give it a look. And it does support structures.
If you just want to use it, this one looks awfully good for the job. There was a Dr. Dobb's article on it a while back ... there it is

Linux c programming reference

I am learning c programming in Linux. There are a lot of linux functions I need to look at. Is there a website that gives me the details of the Linux functions?
Are you referring to system calls in Linux? There are lots of sources. The man pages are your good friends in this regard. Try also http://linux.die.net/man/2/syscalls. I am sure there are lots of others.
The standard reference by far is "Advanced programming in the UNIX environment" by Richard Stevens. Unfortunately this book is quite old, so there is a revised edition by Eric Raymond, which covers new stuff in Linux. This -- more than anything else -- is the de facto standard for learning "old world" systems programming in Linux. (And most other *ixes, there are of course differences, but you won't notice them until you're much more advanced, and by that point you'll be familiar with the man pages and know where to look.)
You can look at the LSB (Linux Standard Base) website:
http://www.linuxfoundation.org/collaborate/workgroups/lsb
Here are is the last Linux Standard Base Core Specification:
http://refspecs.linuxfoundation.org/lsb.shtml
IMHO http://linux.die.net/man/ is the easiest to get to start with.
It has useful sections introductions, so you can get your bearings
Most usefully are the one line synopsis pages, e.g. http://linux.die.net/man/3/
This shows the scale of what you are asking, and also lets you search for a key word describing each function within your browser, which can be very handy.
As has been pointed out, it is not the most up-to-date, but IMHO it is easier for a beginner to use than the alternative I've seen (not that there can't be something better, just google doesn't bother to show it).
Also worth trying apropos or man 3 -K or aman -k`
I find the glibc manual very good. It is organized by topic and contains concise background material and examples. It'll allow you to get the big picture and serves as a reference. Manpages are a quicker way to access function descriptions but there are only useful if you already know what you are looking for.

About C documentation

Coming from Java environment, I feel I got spoiled a lot when it comes to documentation. In C, using Eclipse, mouseover putchar() shows:
__CRT_INLINE int __cdecl __MINGW_NOTHROW putchar(int __c)
{
return (--stdout->_cnt >= 0)
? (int) (unsigned char) (*stdout->_ptr++ = (char)__c)
: _flsbuf (__c, stdout);}
While all this is terrific, I was wondering if any IDE includes more information about the specifics of what a given function does, ie, "prints a character to the output device"? Something similar to this as part of an IDE would be awesome.
Is there a way to get this level of detailed as part of Eclipse or any other IDE?
The question, obviously is not about putchar(), but rather is about a general approach to documentation using C programming language.
NetBeans will show you the man page inline: http://netbeans.org/kb/docs/cnd/navigating-editing.html
I don't have a solution for eclipse or an IDE, but my approach usually involves googling the function's manpage. eg, man putchar, which you've already found.
I'll also suggest this, at the risk of downvotes: The IBM C documentation is, in my experience, really good. Often it has real working understandable code examples and everything.
Now, IBM C is different from GNU C, so there are differences or features that do not apply to gcc. That said, Take a look at its page on the putchar() function.
There are plenty of things to complain about in C99, but it is still the authoritative reference and imo the best source for answers to the question, "what does it do?"
MS Visual Studio wraps a little skin around the C99 bones.
And MSDN goes further: docs on MSDN are beginning actually to resemble real papers by real writers that communicate useful info to a wide audience of neophytes and pros alike.
All credit goes to Let_Me_Be.
The following link provides a complete solution to what i was looking for
eclipse.org/linuxtools/projectPages/libhover

Recursive Descent Parser for C

I'm looking for a parser for C. Here is what I need:
Written in C (not C++).
Handwritten (not generated).
BSD or similarly permissive license.
Capable of nontrivially parsing itself (can be a subset of C).
It can be part of a project as long as it's decoupled so that I can pull out the parser.
Is there an existing parser that fulfills these requirements?
If you don't need C99, then lcc is a slam dunk:
It is documented in a very clear, well-written book.
Techniques used for recursive-descent parsing of operators with precedence are well documented in an article and technical report by Dave Hanson.
Clear, handwritten ANSI C code.
One potential downside is that the lcc parser does not build an abstract-syntax treeā€”it goes straight from parsing to intermediate code.
If you must have C99 then I think tinycc (tcc) is your best bet.
How about Sparse?
You could try TCC. It's licensed under the Lesser GPL.
It seems that nwcc sufficiently agrees with your requirements.
Good c compiler is present at this location. Simple and accessible.
https://github.com/rui314/8cc
GCC has one in gcc/c-parser.c.
Check elsa, it uses the Generalized LR algorithm.
Its main use is for C++, but it also parses C code.
Check on its page, on the section called "How much C can Elsa parse?" which says it can parse most C programs, including the Linux kernel.
It's released under a BSD license.
Here is a recursive descent parser I ported to C:
http://www.gabotronics.com/resources/recursive-descent-parser.htm

C to IEC 61131-3 IL compiler

I have a requirement for porting some existing C code to a IEC 61131-3 compliant PLC.
I have some options of splitting the code into discrete function blocks and weaving those blocks into a standard solution (Ladder, FB, Structured Text etc). But this would require carving up the C code in order to build each function block.
When looking at the IEC spec I realsied that the IEC Instruction List form could be a target language for a compiler. The wikepedia article lists two development tools:
CoDeSys
Beremiz
But these seem to be targeted compiling IEC languages to C, not C to IEC.
Another possible solution is to push the C code through a C to Pascal translator and use that as a starting point for a Structured Text solution.
If not any of these I will go down the route of splitting the code up into function blocks.
Edit
As prompted by mlieson's reply I should have mentioned that the C code is an existing real-time control system. So the programs algorithms should already suit a PLC environment.
Maybe this answer comes too late but it is possible to call C code from CoDeSys thanks to an external library.
You can find documentation on the CoDeSys forum at http://forum-en.3s-software.com/viewtopic.php?t=620
That would give you to use your C code into the PLC with minor modifcations. You'll just have to define the functions or function blocks interfaces.
My guess is that a C to Pascal translator will not get you near enough for being worth the trouble. Structured text looks a lot like Pascal, but there are differences that you will need to fix everywhere.
Not a bug issue, but don't forget that PLCs runtime enviroment is a bit different. A C applications starts at main() and ends when main() returns. A PLC calls it main() over and over again, 100:s of times per second and it never ends.
Usally lengthy calculations and I/O needs to be coded in diffent fashion than a C appliation would use.
Unless your C source is many many thousands lines of code - Rewrite it.
It is impossible. To be short: the IL language is a 4GL (i.e. limited to
the domain, as well as other IEC 61131-3 languages -- ST, FBD, LD, SFC).
The C language is a 3GL.
To understand the problem, try to answer the question, which way to
express in IL manipulations with a pointer? for example, to express call a
function by a pointer. What about interrupts? Low level access to the
peripherial devices?
(really, there are more problems)
BTW, there is the Reflex language, aka "C with processes". Reflex is a 4GL for the
control domain with C-like syntax. But the known translators produce
C-code and Python-code.
If the amount of code to convert is a few thousand lines, recoding by hand is probably your best bet.
If you have lots of code to convert, then an automated tool might be very effective.
Using the DMS Software Reengineering Toolkit we've built translators to map mechanical motion diagrams into RLL (PLC) code. DMS also has full C parser/analyzers/front ends. The pieces are there to build a C to RLL code.
This isn't an easy task. It likely takes 6-12 man-months to configure DMS to something resembling what you want. If that's less than what it takes to do by hand, then its the right way to do it.
There are a few IEC development environments and target hardware that can use C blocks... I would also take a look at the reasons why it HAS to be an IEC-61131 complaint target. I have written extensively on compliance and why it doesn't mean squat.
SOFTplc corp can help I'm sure with user defined loadable modules... and they can be in C..
Schneider also supports C function blocks...
Labview too!! not sure why IEC is important that's all!! the compiler if existed would create bad code for sure:)
Your best bet is to split your C code into smaller parts which can be recoded as PLC functional blocks and use C to PASCAL convertor for each block which you will rewrite in structured text. Prepare to do a lot of manual work since automated conversion will probably disappoint you.
Also take a look at this page: http://www.control.com/thread/1026228786
Every time I've done this, I just parsed and converted it by hand from C directly to ST. I only ran into a few functions that required complete rewrites, although there was very little that dealt with pointers, which is something that ST generally chokes on, unfortunately.
Using the existing C code as blocks that are called by the PLC program would have the added advantage that the C blocks could run at the same periodicity that they did before, and their function is likely already well documented and tested. This would minimize any effect on changes from the existing control system. This is an architecture for controls with software PLCs that I have seen used before.

Resources