Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Why does COBOL have to be indented, as in, have additional spacing in each sourcefile?
Consider this code (note the additional whitespace):
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
DISPLAY 'Hello, world'.
STOP RUN.
A similar formatting can be seen in Fortran code:
program hello
print *, "Hello World!"
end program hello
But why do COBOL and Fortran need this whitespace? What's the reason?
Cobol no longer has to be indented. AFAIK, all most modern compilers support format free Cobol source.
The original reason was dealing with punch cards. Cobol kept the first 6 positions for a line sequence number. Column 7 was a continuation / comment / debug / form-feed. Area "A", or Columns 8-11, indicated certain special language artifacts like 01 levels, section or paragraph names, et al. Area "B", or Columns 12 - 72, was for open code. Columns 73 - 80 were for OS sequence numbers.
The two languages you mention, Cobol and Fortran, were both written before automatic parser generation existed. And they had no real prior art to draw on for good and bad ideas of how to create parse-able source text. So some of the things -- like Area "A" for special section headers -- made the task of manually writing parsers easier. Modern languages tend to use context free grammars to make parser generation simple. But that postdates Cobol.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
so recently I was reading a book that teach you how to program in C++ and I am at basic math stuff. I'm not a beginner in C++ but I have seen something strange that I can't find on the internet.
It is a math expression: 5*3(6' 4) and it has a single quote on it. I found didn't know what it was so I checked up on the internet for this and I found only that it is referred as prime. But I don't think it solve my problem and I don't know how correct that is.
Thanks in advance.
EDIT: I want to address all people who commented and answered (and those who will to do the same thing)in this post that I HAVE MADE A BIG MISTAKE. The real math expression was: 5*6(6*4) but my friend's book(which I got this expression) was not printed well and it looked like the one I have wrote in the past. I'm really really sorry about this....
C++14 and up allows single quote ' inside integer literals to allow for grouping digits. Thanks to this, 123'456'789 can be used as more readable equivalent to 123456789.
Depending on a country, it may be also used in mathematical (outside of C++) expressions, although Polish people would rather use 123 456 789 and UK people would use a comma AFAIK - 123,456,789. None of these is valid in C++ (or it would yield results far from expected), but it would be reasonable in mathematical text/formula.
Nevertheless, your example still wouldn't compile. There is no operator between 3 and opening bracket (.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Maybe there is some hidden and forgotten by everyone reason why those keys were choosen? In the same vein as this link http://www.catonmat.net/blog/why-vim-uses-hjkl-as-arrow-keys/ explains use of hjkl in vim and ~ in bash, maybe there is some story behind ^ and $? Actually, on the picture in that article, the terminal shown doesn't even have a ^ key.
I'd really appreciate if somebody will tell or show the keyboard layout used by Ken Thompson when he written a version of QED that supported regex. (And if people stop trying to be funny in the comments).
edit:
These are some amasing replies. Even if they are just guesses, they may serve like a great mnemonic material. Thank you! Just wish you didn't put it on hold so fast, maybe some people were too slow to answer.
It's hardly possible to answer this question today because regexps were introduced more than fifty years ago. I may share versions that seem the most reasonable for me.
Dollar sign was symbolizing the end of line yet in ed editor. First practical implementation of RE were introduced namely in ed and derivatives (like QED). And dollar sign was reused. It meant either the end of line or the last line, depending on context. This is more or less clear but the question why dollar sign was initially denoted the end of something yet remains. It ('$') seems to be an "ASCII approximation" of a typographic "end of paragraph" sign.
As for '^' as the beginning of line, it's probably an "ASCII approximation" of Lambda Greek letter which stood for an empty expression in early theoretical works like this: http://www.fing.edu.uy/inco/cursos/intropln/material/p419-thompson.pdf
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to create multi-language feature for C++ program which would be similar to Android.
I have file language.xml and language-us.xml, if user's language is US then lang_variable is searching in language-us.xml, if didn't found then use keyword in language.xml . In code I would like to access lang-variables something like: R.string.lang_variable.
Language files can be not xml, i just want to make multi-language.
Thanks, for answer !
This is easily done by using lookup tables.
Any phrase that needs translation is assigned an ID value.
There is a table of ID vs. text for every language, can be as simple as an array of text.
Each supported language has an ID. There is one table of language ID vs. Language Table for every supported language.
So, first take the language ID and get the translation table for the given language.
Next, use the phrase or text ID to get the phrase from the language table.
This doesn't really have anything to do with the C++ language.
Also, use a character type that can support all required encodings, such as multibyte or Unicode.
Edit 1: Spreadsheets
We use a spreadsheet that contains the language ID (first column) and the translated text in different languages (each language is a separate column). We then have a custom application that converts the spreadsheet into appropriate tables (as discussed above).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I see, C++ compilers support && and its textual equivalent and operator (Similar to || operator to or). I tend to like its textual form compare to special character form. But, recently I am discouraged from using textual form of such operator without any concrete reasoning. I don't seriously think, textual form will require more typing compare to special character form. Also, there won't be much on compiler overhead on parsing part. So why major C++ community tend towards && instead and. While I think, textual form is much clear while stating a condition to beginner. It also promote more poetry style coding rather than bombarding code with gibberish character.
Just my personal preference here; visually the && breaks up two identifiers better than and does. So at a glance it is a bit quicker to mentally parse the expression.
This is kind of a standard in most of the major languages.. You got to accept it as syntax and should not argue about how it should be. Language isn't designed according to individual liking or disliking. You're going to find many somewhat confusing things in C/C++ which were taken care of in modern languages like python etc. But C, Java are still most widely used languages so you must follow their syntax if you wish to program in these languages.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have been thinking about building my own compiler for a while and a few days ago I finally started on it. My compiler works like this:
Parse code from my own file. (With a .exe file made with c++)
Create assembly code
Create a file containing those assembly code
Compile that assembly file if it is made (done with a vbs script)
Link the .obj file
And we have our .exe file
Now I am having difficulties with finding the best way to parse my code. I haven't really made this yet but I will put my ideas here.
Find all variables and declare them. variables will be preceded with a 'var ' (for now). uninitialized variables will be put in the .data? section and initialized ones in the .data section.
Find the main procedure and start executing the functions and operations.
Now I was simply wondering if someone can improve my ideas. Or if someone has a better idea to make some kind of compiler and your own programming language.
Get yourself a copy of A. V. Aho, M. S. Lam, R. Sethi, J. D. Ullman: Compilers: Principles, Techniques, and Tools and start studying
The book covers the necessary theoretical background, especially:
Context-free grammars
Recursive-descent, LL, LR parsing
Symbol handling
Intermediate representation