compiler-theory

Does the compiler decide when to inline my functions (in C++)?

南楼画角 提交于 2019-11-27 23:55:09
I understand you can use the inline keyword or just put a method in a class declaration ala short ctor or a getter method, but does the compiler make the final decision on when to inline my methods? For instance: inline void Foo::vLongBar() { //several function calls and lines of code } Will the compiler ignore my inline declaration if it thinks it will make my code inefficient? As a side issue, if I have a getter method declared outside my class like this: void Foo::bar() { std::cout << "baz"; } Will the compiler inline this under the covers? Whether or not a fiunction is inlined is, at the

How Lambda Expressions Are Translate In Java Byte Code

∥☆過路亽.° 提交于 2019-11-27 22:47:09
I am trying to create an example using lambda expression in java and i am using offical JDK8. My example was run successfully. But when i trying to check how the compiler translate lambda expression into byte code, this makes me some confusion.Following is the code of my example:- public class LambdaTest { public Integer lambdaBinaryOpertor(BinaryOperator<Integer> binaryOperator) { return binaryOperator.apply(60, 72); } public static void main(String[] args) { LambdaTest test = new LambdaTest(); BinaryOperator<Integer> binaryOperator = (a, b) -> a*b; System.out.println("Additon using Lambda

complexity of parsing C++

社会主义新天地 提交于 2019-11-27 15:17:20
问题 Out of curiosity, I was wondering what were some "theoretical" results about parsing C++. Let n be the size of my project (in LOC, for example, but since we'll deal with big-O it's not very important) Is C++ parsed in O(n) ? If not, what's the complexity? Is C (or Java or any simpler language in the sense of its grammar) parsed in O(n)? Will C++1x introduce new features that will be even harder to parse? References would be greatly appreciated! 回答1: I think the term "parsing" is being

Are there any “fun” ways to learn about Languages, Grammars, Parsing and Compilers? [closed]

≯℡__Kan透↙ 提交于 2019-11-27 00:18:44
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I'm preparing for an exam concerning languages, grammars, parsing and compilers. It's not really my cup of tea and most resources I

What programming languages are context-free?

有些话、适合烂在心里 提交于 2019-11-27 00:01:36
问题 Or, to be a little more precise: which programming languages are defined by a context-free grammar? From what I gather C++ is not context-free due to things like macros and templates. My gut tells me that functional languages might be context free, but I don't have any hard data to back that up with. Extra rep for concise examples :-) 回答1: The set of programs that are syntactically correct is context-free for almost all languages. The set of programs that compile is not context-free for

Does the compiler decide when to inline my functions (in C++)?

浪尽此生 提交于 2019-11-26 21:38:54
问题 I understand you can use the inline keyword or just put a method in a class declaration ala short ctor or a getter method, but does the compiler make the final decision on when to inline my methods? For instance: inline void Foo::vLongBar() { //several function calls and lines of code } Will the compiler ignore my inline declaration if it thinks it will make my code inefficient? As a side issue, if I have a getter method declared outside my class like this: void Foo::bar() { std::cout << "baz

How Lambda Expressions Are Translate In Java Byte Code

一笑奈何 提交于 2019-11-26 21:14:52
问题 I am trying to create an example using lambda expression in java and i am using offical JDK8. My example was run successfully. But when i trying to check how the compiler translate lambda expression into byte code, this makes me some confusion.Following is the code of my example:- public class LambdaTest { public Integer lambdaBinaryOpertor(BinaryOperator<Integer> binaryOperator) { return binaryOperator.apply(60, 72); } public static void main(String[] args) { LambdaTest test = new LambdaTest

What's the difference between parse tree and AST?

爱⌒轻易说出口 提交于 2019-11-26 17:29:57
问题 Are they generated by different phases of a compiling process? Or are they just different names for the same thing? 回答1: This is based on the Expression Evaluator grammar by Terrence Parr. The grammar for this example: grammar Expr002; options { output=AST; ASTLabelType=CommonTree; // type of $stat.tree ref etc... } prog : ( stat )+ ; stat : expr NEWLINE -> expr | ID '=' expr NEWLINE -> ^('=' ID expr) | NEWLINE -> ; expr : multExpr (( '+'^ | '-'^ ) multExpr)* ; multExpr : atom ('*'^ atom)* ;

How do C compilers implement functions that return large structures?

江枫思渺然 提交于 2019-11-26 16:06:59
问题 The return value of a function is usually stored on the stack or in a register. But for a large structure, it has to be on the stack. How much copying has to happen in a real compiler for this code? Or is it optimized away? For example: struct Data { unsigned values[256]; }; Data createData() { Data data; // initialize data values... return data; } (Assuming the function cannot be inlined..) 回答1: None; no copies are done. The address of the caller's Data return value is actually passed as a

Learning Resources on Parsers, Interpreters, and Compilers [closed]

被刻印的时光 ゝ 提交于 2019-11-26 15:47:19
I've been wanting to play around with writing my own language for a while now (ostensibly for the learning experience) and as such need to be relatively grounded in the construction of Parsers, Interpreters, and Compilers. So: Does anyone know of any good resources on constructing Parsers, Interpreters, and Compilers? EDIT: I'm not looking for compiler-compilers/parser-compilers such as Lex, Yacc and Bison... The best paper I ever read on compilers is dated 1964 "META II a syntax-oriented compiler writing language" by Val Schorre. ( http://doi.acm.org/10.1145/800257.808896 ) In 10 pages, he