Talk:Main Page
From Icarus Verilog
Any discussion on better ways to structure this top level page?
- Perhaps you could have 2 columns instead of one? See Wikia:Template:Main for an example format. Angela talk 08:24, 4 November 2006 (UTC)
Contents |
[edit] Icarus Verilog
I try to understand how it is working for 2 specific cases.
It has a grammatical rule :
statement -> ...
| K_if '(' expression ')' statement_opt %prec less_than_K_else
| K_if '(' expression ')' statement_opt K_else statement_opt
| ...
|;
As far as I know from compilers theory (and Left to Right Bottom Up parsing, as also Icarus Verilgo it is), the above rule should throw conflict, because, the 2 options of the rule have the same prefix (e.g. s -> s1 ) ( | s1 s2)
However icarus is a tool, that works, but I can't understand how.
The 2nd issue is that, I want to make a mark, when the compiler, had read an "if(expr)" (cause I want to take the boolean expression inside the if,in cases it appears in switch cases, as the input of a state of one FSM), and not when whole rule "if(expr) stmt" or "if(expr) stmt else stmt" ends. I have a buffer,that I temporarily store the (boolean) expressions, and if e.g. we have the code "if(expr1)stmt else if(expr2) stmt", the compiler first recognize the inner "if(expr2) stmt" rule, but in my buffer, I also have both expr1 and expr2, and I dont know, which expressions of the buffer, belong to which "if()".
P.S. : Maybe another solution than the buffer, might be better,but I dont want a solution of transforming the grammar of the compiler.The main problem that I have, and I want to solve, is the 2nd,and I demand,of an easy way to do it. Problem Revision : I want to match every (boolean) expression, to the "if" it belongs.
To answer the first question. Look up context-dependent precedence in the bison manual. To answer the second question. If you treat the buffer as a stack it should be obvious which expression goes with which if. The top one is the last if you parsed. Depending on the information you need you may want to push a pointer to the actual if statement which you can easily interrogate to get the conditional expression and anything else you desire. We don't mind answering question that are not related directly to Icarus development, but you may get a better answer if you explain what you are trying to do along with the problem you are having. This is especially true when English is not your native language. In those cases the extra contextual information usually helps us understand what is being discussed.
Cary 23:28, 3 July 2009 (UTC)
[edit] Icarus Verilog problem again
The buffer-stack I told you, fills with the parts of every expr.What I mean : The way I fill the buffer, is when I saw only expressions like "a && b && c", or "a || c", and it is done with the following way : c && b && a (as a stack).
In case we have the following code : "if(expr1) begin
if(expr2)
stmt
end
the rule that is called is the "if(expr) stmt" ,and the stmt is analysed again to the same rule. As I figured out, and becouse Bison is bottom up, and left to right, it will see/recognize first the 1st expr1 (and it will be store in my buffer), but as the whole rule doesn't complete yet, it will proceed to analyse the "stmt", of the rule to the same rule again (if(expr2) stmt).So it sees the expr2, and it is stored to my buffer, above expr1, and then only I know an "if" is completed.
So revising again, the problem is that because the rule, has the "stmt" together with the "if(expr)" (and I obviously put code to every rule, after it is finished like "a -> b or c {//my_code}), if I have inner IFs, I will first recognise the most inner if (and only then I can put an IF-mark), but in my stack, I will also have all the outer-if expressions, without a separation between them.
When I had made a compiler (with lex-bison) to a lesson, the way we do the rule for IF, was something like this:
"stmt -> ifprefix stmt ifprefix -> if(epxr)"
So then when I saw the expr, I could also put a mark with the corresponding IF, and recursively for all the inner IFs-exprs.
P.S. : It's true English is not my native language, and please excuse me, for every mistake. I use the Icarus Verilog v0.8.6, and I don't know C++ (which is written with, as I can say). I only know C (and verilog). So it is a little difficult, to understand the whole code of icarus.
You can modify the parser to add markers fairly easily. Specifically, after the K_if '(' expression ')', but before the statement_opt add a { } block to set the end of expression marker. A { } code block increases the location count by one so for the simple if case change $5 to $6 and for the if/else case change $5 to $6 and $7 to $8 in the final { } block. This should give you what you want. If this works please let use know so we can remove this discussion, since it is very specific to what you are trying to do.
FYI the current stable Icarus Verilog is 0.9.1 and 0.8.7 is available if you need to stay with the V0.8 branch.
Cary 23:11, 6 July 2009 (UTC)
[edit] Icarus 3
The solution , you proposed me, I already know and I had I tried it (a long time before I send the 1st mail to you), and it throws the following errors :
The steps I do : 1) "K_if(expr) {printf("test1");} stmt" 2) Change $5 to $6 3) "K_if(expr) {printf("test2");} stmt else stmt" 4) Change $5 to $6 and $7 to $8. 5) "%> make install" to the folder that "parse.y" exists (I think the make is done without any errors). 6) "%> iverilog test.v"
The output is the following:
"test2 //(so it prints the message of the printf I just added, and then it throws the following error)
test.v:26: syntax error test.v:26: error: malformed statement
"
at that line , the code (of the input verilog file) is the following:
"line 26: else" (or "else if(in1)" in a different line)
It seems like (the parser is ok and) the syntax of the input file becomes false.
So the error has something to do with the "IF-ELSEs" (and I believe also with the bare "IFs").
The error appears only when I add the "{}" code inside the if/if-else rule. In the initial rule, it doesn't appear, and all works fine.
I have some guesses about what is going wrong and my version of bison does complain about this, but compiles the grammar anyway. Instead of figuring out what is wrong with my previous suggestion try the following which I briefly tested, so it should work fine.
Add a new tagged_expr sub rule as follows.
tagged_expr
: '(' { < code to start tagging an expression > } expression
')' { < code to finish a tagged expression >
$$ = $3;
}
Declare tagged_expr to have the same type as expression %type <expr>.
Replace the '(' expression ')' for the two K_if rules with tagged_expr. If you use the start code before the expression then to be complete you will need to modify the two K_if error rules to cleanup whatever you do in the start rule. You need to replace the various $ tokens to match the new rule. Basically $3 => $2, $5 => $3 and $7 => $5. Let me know how this works for you.
Cary 17:36, 7 July 2009 (UTC)
[edit] Thanks
I want to thank very much, for all of your help!!!
Your answer had helped me, but I made a little different rule, than the one you told me. In the additional rule I added, I included also the "IF" ( "ifprefix -> if(expr)" ). Could you also tell me, the changes to the code I should do, to add a corresponding elseprefix rule, above the else rule?
P.S. : If I want everything else, could I ask you again???
You are welcome. I'm not sure what you mean by an else prefix rule. Once you have reached an else token you are committed so I would assume that K_else {C code} statement_or_null should work after incrementing the statement reference by one place.
I'm willing to help, but remember this is taking time away from Icarus development and is likely not helping the Icarus community at large. If you want to ask questions like this please move this to a more appropriate place than the main talk page. Maybe you could describe a bit about what you are doing with Icarus on a personal page and then ask questions and describe the final solutions there. That would give me more context in understanding what you are doing and would allow others to benefit from what you have done.
Cary 21:20, 24 July 2009 (UTC)
[edit] Mail?
May I ask you, if you have a mail, for comunicating each other, because, I don't have a page?
You can have a page right here on the wiki. Create a real login and then build/copy what you want to your personal page. I don't normally give out my email, but if you use Icarus enough it's not hard to figure out how to contact me and I do check changes here from time to time.
Cary 02:04, 30 July 2009 (UTC)
[edit] Personal Page
I made (as you told me) a personal account and page (user : masterpainer). So we could disuss from there? Everyone can see , what I write there? And what is the other TAB "Discussion" (where should I my questions)?
[edit] Personal Page 2
I'm sorry for the annoying again...
I want to ask you : If I write or change something in my page, do you see this? I'm telling this, because I wrote something on Friday, and I don't know if you have seen it. If you don't be informed (via Notification or Email), when I write/change something there, may I ask you how I can inform you, so that you know that I have writen something?
