Using Datalog by itself, is it possible? - datalog

I am currently studying Datalog for my report in class, I only need to discuss basic syntax and a basic example.
I know Datalog is usually used as a query language and is usually only implemented to other languages such as Java, Lua, C, etc. but is it possible to teach Datalog only by itself, or am I required to use another language implementing it to show a simple working program?

There are a few online demos you can use:
http://iris-reasoner.org/demo
http://ysangkok.github.io/mitre-datalog.js/wrapper.html
https://repl.logicblox.com/ (docs here:
https://developer.logicblox.com/content/docs4/tutorial/repl/section/split.html )
I haven't tried it myself yet, but http://abcdatalog.seas.harvard.edu also looks nice and easy to run.
A complete overview is on Wikipedia: https://en.wikipedia.org/wiki/Datalog

Related

Chatbot in Prolog

I've been trying to create a chatbot (as an assignment) in prolog, so far I have made a database in a .pl file and I have listed a lot of possible conversations.
I know that prolog works like this for example if we have
Chatbot(good)
and we type
?-Chatbot(good).
it will respond
yes or ture.
Now I don't know how to use my database so that the program can work exactly as a chatbot for example without the need to write in appropriate syntax:
Hello (typed by the user)
Hi there, (typed by the program automatically)
My database is like this:
answer( question, [
[Yes, I am here]]).
question ([are you there?])
The prototype chatbot I'm aware of is ELIZA by Weizenbaum 1966.
Implementing it in Prolog is rather easy, as shown in The Art of Prolog by Sterling & Shapiro.
Googling for 'ELIZA Prolog', the first link gives you a fairly complex implementation, and you could adapt/reuse the engine with your database. But this way you will lose all the fun. I suggest you read the book and take the time to implement your own.
edit
Just in case you haven't still seen it, SWISH offers a clean, barebone ELIZA implementation among its examples.

Is using Debugger a wrong course to join competition of programming?

I'm practicing programming to take part in competition of programming. I have taken part in JOI and PCK, which are popular competition of programming in Japan. But only using a simple text editor is allowed in JOI and PCK. I'm still using debugger during my practice of programming of competition. Is it a wrong course?
If they allow you to only use a text editor then you should practice in such conditions to get used to the right rules.
It's possible that they mean you aren't allowed to use an IDE, but that you can still use a command line debugger like GDB. I would check to see if they explicitly ban debuggers, or just IDEs.

How to build a static code analysis tool?

I m in process of understanding and building a static code analysis tool for a proprietary language from a big company. Reason for doing this , I have to review a rather large code base , and a static code analysis would help a lot and they do not have one for the language so far.
I would like to know how does one go about building a static code analysis tool , for e.g. Lint or SpLint for C.
Any books, articles , blogs , sites..etc would help.
Thanks.
I know this is an old post, but the answers don't really seem that satisfactory. This article is a pretty good introduction to the technology behind the static analysis tools, and has several links to examples.
A good book is "Secure Programming with Static Analysis" by Brian Chest and Jacob West.
You need good infrastructrure, such as a parser, a tree builder, tree analyzers, symbol table builders, flow analyzers, and then to get on with your specific task you need to code specific checks for the specific problems of interest to you, using all the infrastructure machinery.
Building all that foundation machinery is actually pretty hard, and it doesn't help you do your specific task. People don't write the operating system for every application they code; why should you build all the infrastructure? Like an OS, it is better if you simply acquire good infrastructure.
People will tell you to lex and yacc. That's kind of like suggesting you use the real time keneral part of the OS; useful, but far from all the infrastructure you really need.
Our DMS Software Reengineering Toolkit provides all the necessary infracture. It has been used to define many language front ends as well as
many tools for such languages.
Such infrastructure would allow you to define your specific nonstandard language relatively quickly, and then get on with your task of coding your special checks.
There is a blog by DeepSource that covers everything one needs to know to build an understanding of static code analysis and equip you with the basic theory and the right tools so that you can write analyzers on your own.
Here’s the link: https://deepsource.io/blog/introduction-static-code-analysis/
Obviously you need a parser for the language. A good high level AST is useful.
You need to enumerate a set of "mistakes" in the language. Without knowing more about the language in question, we can't help here. Examples: unallocated pointers in C, etc.
Combine the AST with the mistakes in #2.

windows programming without a OOP language

Which language ( that is not oop ) should I consider using for writing gui windows apps ?
I guess the obvious answers are visual basic and C , but am wondering if I should look into anything else
am not saying OOP sucks or anything. I just don't.. not using it. The END
ty
Edit: I just want a language that has a non oop paradigm option and that is/can be used to write a windows gui application .
It is quite possible to write procedural code in any language.
There is FreeBasic
I'd personally recommend giving Fortran a go, it's quite nice...
I'd use Python. Sure it can be used in a OO way (as pretty much all other languages can as well), but it's pretty easy to write clean, simple, procedural code with it as well.
C would be my choice, Visual Studio supports it and has an excellent debugger. There are also plenty of examples out on the web in C for Windows programming so you'll have the easiest time getting your code to work.
OO is kind of a pervasive paradigm these days. It's pretty much impossible to avoid, even languages like VB and C can be used to program in an OO way, although I do get what you mean. Have you considered Fortran? COBOL? J? Perl? Python? They can all pretty much be used in a non OO way.
Not to mention assembly language.
F# I guess, avoiding its inherent object-oriented programming model. But do you like functional languages and the .NET framework?!
Out of curiosity, why do you need such a thing?
Windows programming is OO by design. Even if you use C, all the API functions work like OO.
Every handle has a corresponding Create function
CloseHandle if used to close any object, not just a specific type
And finally every single API function gets a Handle to a relevant object, just like the old implementation of OO in pure C with structs - the equivalent of this.
Well, there are guys who are still using Visual Foxpro, or Visual Basic 6 (which is NOT OO, contrary to what some people say).
C and Windows API. It is not OO, but feels like, because OO (C++, Java, C#) is nothing but making structs into objects.

What tools for migrating programs from a platform A to B

As a pet project, I was thinking about writing a program to migrate applications written in a language A into a language B.
A and B would be object-oriented languages. I suppose it is a very hard task : mapping language constructs that are alike is doable, but mapping libraries concepts will be a very long task.
I was wondering what tools to use, I know this has to do with compilation, but I'm a bit afraid to use Lex and Yacc and all that stuff.
I was thinking of maybe using the Eclipse Modeling Framework, which would help me write models (of application code) transformations in a readable form.
But first I would have to write parsers for creating the models (and also create the metamodel from the language grammar).
Are there tools that exist that would make my task easier?
You can use special transformation tools/languages for that TXL or Stratego/XT.
Also you can have a look and easily try Java to Python and Java to Tcl migrating projects made by me with TXL.
You are right about mapping library concepts. It is rather hard and long task. There are two ways here:
Fully migrate the class library from language A to B
Migrate classes/functions from language A to the corresponding concepts in language B
The approach you will choose depends on your goals and time/resources available. Also in many cases you wont be doing a general A->B migration which will cover all possible cases, you will need just to convert some project/library/etc. so you will see in your particular cases what is better to do with classes/libraries.
I think this is almost impossibly hard, especially as a personal project. But if you are going to do it, don't make life even more difficult for yourself by trying to come up with a general solution. Choose two specific real-life programming languages ind investigate the possibities of converting between them. I think you will be shocked by the number of problems and issues this will expose.
There are some tools for direct migration for some combinations of A and B.
There are a variety of reverse engineering and code generation tools for different languages and platforms. It's fairly rare to see reverse engineering tools which capture all the semantics of the source language, and the semantics of UML are not well defined ( since it's designed to map to different implementation languages, it itself doesn't define a complete execution model for its behavioural representations ), so you're unlikely to be able to reverse engineer and generate code between tools. You may find one tool that does full reverse engineering and full code generation for your A and B languages, and so may be able to get somewhere.
In general you don't use the same idioms on different platforms, so you're more likely to get something which emulates A code on B rather than something which corresponds to a native B solution.
If you want to use Java as the source language(that language you try to convert) than you might use Checkstyle AST(its used to write Rules). It gives you tree structure with every operation done in the source code. This will be much more easier than writing your own paser or using regex.
You can run com.puppycrawl.tools.checkstyle.gui.Main from checkstyle-4.4.jar to launch Swing GUI that parse Java Source Code.
Based on your comment
I'm not sure yet, but I think the source language/framework would be Java/Swing and the target some RIA language like Flex or a Javascript/Ajax framework. – Alain Michel 3 hours ago
Google Web Toolkit might be worth a look.
See this answer: What kinds of patterns could I enforce on the code to make it easier to translate to another programming language?

Resources