Fortran Encode 'R' Formatter - format

I am translating some FORTRAN code to java, but there is a formatter type that I can't really understand, and I didn't find its meaning on the internet.
I have line like this ENCODE(2,'(R2)',BUFFER) MY_DATA but I don't know what the '(R2)' formatter means.
Someone knows ?

Related

Are there any good extensible language cross compilers?

I am working on a project right now, and I would greatly enjoy being able to extend a cross compiler to convert some code into other languages. For example, I might have an AST of some code, and I would like to pass that off to a cross compiler with the intended language and receive some code in the language specified in return.
So to sum it up: is there any extensible cross compiler that I can just give an AST or equivalent and receive code in return?
(I know about Haxe, but the compiler is not very extensible and I would prefer to not transpile)
I have made the decision to use LLVM as the native compiler, and will write my own custom transpilers to other languages, as I could find no other decent option. If you would like to follow my project, head over to Provalang.

Pseudo Code in jGrasp

While writing pseudo code for java in jGrasp, do we write it in a comment or do we write it like any other code? I have already read the wiki page but wasn't able to reach a satisfactory understanding.
the pseudo code is basically a very detailed version of your code, you don't need to write it like any other code, you can write it as comments (these comments should let you or the person reading know what they would have to type in the program). In grade 12 computer science when we are told to write the pseudo code we just type it in words describing what is going to process, what does my code do basically do etc. I am really not sure how higher level coders do their pseudo code but as far as I know you can write it in a comment. ( you can/should type your pseudo code in word ) . I hope this helped.

Parsing Expression Grammar for syntax highlighting

First... Would it be possible to accomplish simple syntax highlighting using a PEG.
I'm only looking for it to be able to recognize and highlight basic things that are common to c style languages
Second... If there are any examples of this or something similar please let me know
Third... If I'm going about this the wrong way and there are more common and proven ways to do this then also let me know

How does Ruby Implement General Delimited Inputs?

After much searching, I can't figure how Ruby implements General Delimited Inputs.
All I can find is Kernel#`, which is used by %x{...}.
Any help would greatly appreciated. Thanks
This is handled in the parsing code, which is written in YACC and C. Check out the source code on GitHub. Specifically, the token that handles this type of quoting begins with tQWORDS_BEG (search within parse.y).
A detailed discussion of the YACC implementation would be long, but if you want to get started, that's where it lives in the code.
Note that the above link is for MRI Ruby. I don't know how other Ruby interpreters handle it, but they all do it in a parser somewhere, and most of those are written in C and likely use YACC to parse. Notable exceptions are JRuby, written in Java, and druby, in OCaml.

Building a syntax checker

I am building a app like a compiler with my own script language. The user will enter the code and the output will be another app.
So I need tell to user if some line is wrong and why it is.
But I don't know how to start.
I thought this:
All lines will start with a keyword, except for those who start with an variable. So different that are wrong.
So, I can calculate the next valid entries and check them.
Also, I thought that I can check each line, but it's complex because I can have this
var varName { /* ... */ };
Or
var varName {
/* ... */
};
Or Even
var varName
{
/* ... */
};
So why not remove the break-lines and check? Because I will lose the line number, which in this case is the most important.
Maybe I'm going to create a map between the code with and without break-line.
But first I want to hear you, if you already has this experience or you have any idea.
Thanks
There are formal languages to describe syntax and semantics of the language and there are tools that will generate parsers out of these descriptions. I suggest reading on flex and bison for starters.
It'll be fairly complicated to write your own language. But totally doable.
To able to recognize if a line is wrong, in the syntactical sense, you'd need to build a parser.
The parser checks the context-free grammar for a correct derivation of a structure from its tokens.
First you need to tokenize the file, then reconstruct it into a parse tree (to check syntax).
I took a class in this, CS 241. There's a very nice set of course notes which this is all explained in detail.
https://github.com/christhomson/lecture-notes/blob/master/cs241.pdf
You should check tools like: lex, bison and yacc.
lex is lexical analyser generator. It generates a code, which could be used for breaking the script to tokens (like numbers, keywords and so on...).
bison and yacc are both parser generators. Both can be used for generating code for parsing your language (combining tokens to statements).
Just google tutorials for those tools.

Resources