I'm trying to write some new statements for an internal C DSL.
The tool of my choice is MPS and the base is the c-core of mbeddr.
I found this tutorial on the internet. Since it is a little old, I am not able to duplicate the exact structure of the setup itself.
What I want to do is to create a new language. This language must be extended by com.mbeddr.core. I found, how to extend the language and did so. I needed to extend every single language com.mbeddr.core.* by its own, everything else did not work (it does not even work properly now).
The I created a new statement in a structure module. There I extended the concept to a Statement (c.m.c.statements.structure is shown). Then, following the video tutorial, I wanted to add an expression as a child, this is where it fails.
I am not sure where I went wrong here. It is very difficult to set it up properly, since all tutorials/guides are outdated.
Thanks for your help,
Best Simon
Related
I'm building an AI-based Q&A chatbot. What are the precise steps? How should I start working on it as I'm new to Python as well as AI.
(Note:- Using Python and building a generative chatbot is mandatory as it's an assignment)
Chatbots, well at least the ones worth naming chatbots, are quite intricate. There are lots of teams out there working every day to make one. But, the good news is that the word "intelligent" doesn't have an exact definition and something simple will probably suffice for you.
You can use an exact matching method which will let you down the first time you give it a chance. You can compare the set of words in existing questions and the one you receive, which is a little bit better. But, If you still feel you want to push it further, read this:
How to Create a Simple JARVIS — Chatbots are Coming
I hope that helps.
I've been taking a look at ReasonML (https://reasonml.github.io/) and in general, as a 'loyal' ;) functional programmer, I like the idea. However, I believe there's a missing part in my reasoning about the project.
In particular I'm a bit confused if it comes what to search for. For example, I'd like to build a simple web server. Shall I use JS-related libraries (express, ...), OCaml technologies, or maybe yet something else ?
What I'm actually missing is a step-by-step guide that presents a way to build a full basic application (in this case: let's say a simple web server with db connection).
Last thing - forgive me imprecise language. As I said: I'm pretty sure there's a gap in my reasoning about ReasonML and I'd like to fill it ;).
If you want to write portable code, you should use the OCaml technologies, so Array.length (from OCaml core) instead of Js.Array.length (Bucklescript JS wrapper).
If you do not care about native code, but just want to target JS (node/browser), then you can use the FFI and leverage your existing knowledge of JS libraries.
IMHO, this FFI is one of the nicer things of reasonML. The resulting code is small and you can inspect the .bs.js files to see what it's doing.
But as said, you lose the ability to generate native code this way.
Here is an example,
https://github.com/wires/reason-ffi
Say I don't have a range function in OCaml or ReasonML and I don't want to write one, but I know ramda has one. Just write some JS,
// range.js
exports.range = require('ramda').range
Then wrap it with types, like
[#bs.module "./range.js"] external range' : (int,int) => array(int) = "range";
let range : (int,int) => list(int) = (a,b) => range'(a,b) |> Array.to_list
I'm not saying this is the ultimate way to use this tool, but I find it a very frictionless way to transition untyped garbage JS to something reasonably maintainable.
And you can leverage your existing JS library knowledge and keep building with reasonML, instead of spending your time writing a boring range function (which is also learning... of course)
Is there a such thing as a preprocessor whose statements, once processed, disappear completely and get replaced by the target language syntax permanently?
I want to research it on the web but I don't know what term to search for. If I search for "code generator", "templating language", "preprocessor directives", "mixins", "annotations" I get generators whose input becomes the source of truth.
The closest thing I can think of is a macro.
What I'm trying to do
I often have to write code that is verbose and unnecessary manual labor and am looking for a smarter way to input at least the majority of it and have it automatically transformed and only source-control the output (and hand edit if necessary). For example:
Java code - Instead of writing getters/setters, javadoc (perhaps the transformer can be a maven plugin)
HTML - I just want to add URLs, and have my preprocessor automatically convert them to links, images, videos, audio etc. depending on the file extension with some regex substitution (currently I run a perl script via a cron job)
I just want to use it as my own shorthand and not enforce it in my project and make the output editable so that others have to learn a new framework or language (like Protobuf, Stringtemplate, GWT, C hash-defines, PHP, JSP etc).
There should be no direct clue that I used a template/preprocessor to generate it.
What you want is a "program transformation system". See https://en.wikipedia.org/wiki/Program_transformation. (This is a superset of "transpilers" [ugly term]).
A good source-to-source transformation system will let you apply rewrite rules of the form of:
if you see *this*, replace it by *that* if *this_condition*.
You can then take your source code, and run a set of rewrite rules across that code to change it.
The resulting code is "transformed"; the rewrite rules are not visible.
It seems like Transpiler is one way to describe it.
First off I've searched my hind end off for hours now trying to find an answer, but I can't seem to find anything remotely useful. What I am trying to do is to find a way to add in code-folding to the built in batch language. Basically I love using batch, but when I have tons of code, I want to be able to hide the code I do not need to edit which will make it easier to find the code I DO need to edit. What I want is to be able to make it so if I typed "::{" (without quotes) and have finished code in the middle and end with "::}" (also without quotes).
First question, is it possible? Can I add something like this (that one could normally add in the "user defined language") to the built-in batch language?
Next question, if not, where could I figure out how to basically re-create the batch language (and add my own twists) into a new "user defined language"?
Last question, if neither of those are possible, what are my other options?
Like I said, I've researched for hours. I'm not one to ask for help on forums, but I'm desperate at this point. All I want is to use the batch language and have code folding. Doesn't seem like too much to ask, but it might be!
Thanks!
In Notepad++ you can define a language by going to the Language menu --> Define your language (at least in version 6.6.9 anyway). On the Folder & Default tab, under Folding in code 1 style, input a ( into the "Open" box. Input a ) into the "Close" box. Save this as "Windows Batch" (or at least something that doesn't conflict with the in-built language named "batch".
Until you define styles, it'll be ugly and unusable, but it should allow you to collapse / expand parenthetical code blocks as a proof of concept and see whether this project is worthy of further effort. Your next steps will be to copypaste batch keywords from %PROGRAMFILES(x86)%\Notepad++\langs.model.xml, and use the "batch" language styles from your favorite theme in Notepad++\themes\. If I were doing it, I'd input a few basic things using the GUI (like keywords, folding characters, etc.), then export to an XML file on the Desktop and copypaste the rest from a theme, search-&-replacing stuff as needed to massage the theme into your user-defined language. At the end, import your massaged XML into the Define your language dialog. It was going to be more effort than I felt like exerting, but your mileage may vary. If you decide to undertake this journey and you complete it, I hope you'll consider sharing your efforts.
This similar question has a few answers that suggest some workarounds you might find worthwhile -- in particular, hiding, rather than collapsing.
I have a code library that makes heavy use of XPathNavigator to parse some specific xml document. The xml document is cross-referenced, meaning that an element can reference another which has not yet been encountered during parsing:
<ElementA ...>
<DependentElementX id="1234">
</ElementA>
<ElementX id="1234" .../>
The document doesn't really look like this, but the point is that 1) there is an xml schema that enforces the overall document structure, 2) elements inside the document can reference each other using some IDs, and 3) there is quite a few such cross references between different elements in the document.
The document is parsed in two phases. In the first pass I walk through the document
XPathDocument doc = ...;
XPathNavigator nav = doc.CreateNavigator();
nav.MoveToRoot();
nav.MoveToFirstChild()...
and occasionally 'bookmark' the current position (element) in the document using XPathNavigator.Clone() method. This gives me a lightweight instance of an XPathNavigator which I can store somewhere and use later to jump back to a particular place (element) in my document.
Once I have enough information collected in the first pass (for example, I have made sure there is indeed an ElementX with an id='1234'), I jump back to saved bookmarks (using those saved XPathNavigators) and complete the parsing.
Well, now I'm about to use this library in Silverlight 3.0 and to my horror the XPathNavigator is not in the System.Xml assembly.
Questions:
1) Am I missing something obvious (i.e. XPathNavigator does exist in some shape or form, for example in a toolkit or a freeware library)?
2) If I do have to make modifications in the code, what would be the best way to go? Ideally, I would like to make minimal changes, not to rewrite 80% of the code just to be able to use something like XLinq.
To resume, in case I have to give up XPathNavigator, all I need is a way to bookmark places in my document and to get back to them so that I can continue to iterate from where I left off.
Thanks in advance for any help/ideas.
You are not missing something obvious, there is no implementation of XPathNavigator or XPathDocument in the Silverlight versions of the libraries.
The "best way to go" is highly subjective and would really depend on how many lines of code are really depending on XPathNavigator. However I see a couple of choices.
Go ahead and re-write the code using XDocument, XElement etc from the System.Xml.Linq namepsace. This may not be as bad a choice as you might think.
Wrap Xml-to-Linq objects in your own implementation of those properties and methods of the XPathNavigator that you are actually using. It shouldn't be too hard re-create most the features of the XPathNavigator against the Xml-to-Linq objects. You can then run your existing code against your own XPathNavigator.
XPath (xdoc.XPathSelectElements) is available in Silverlight 4: here's an online test tool.
There are tons of ways:
How to deal with XML in C#
You can still use Linq to XML just minus the linq syntax and use the Linq Extension methods.