Talk:Compiler/syntax analyzer
Unary operator precedence
In the grmmmar, the definition of primary is:
primary = Identifier | Integer | '(' expr ')' | ('+' | '-' | '!') expr ;
which makes the unary operators the lowest precedence? Should that be:
primary = Identifier | Integer | '(' expr ')' | ('+' | '-' | '!') primary ;
which would be more usual? If I read it correctly, the C reference implementation does treat unary operators as highest precedence. --Tigerofdarkness (talk) 08:46, 23 October 2016 (UTC)
You are correct. Thanks for catching this! I have modified the grammar. --Ed Davis (talk) 11:03, 23 October 2016 (UTC)
prt_list production incorrect
I think the prt_list production should be:
prt_list = (String | expr) { ',' (String | expr) } ;
because | is lower precedence than concatenation.
Yep, I agree. It has been corrected. Thanks for the catch! --Ed Davis (talk) 18:19, 22 April 2019 (UTC)
Prtc node type documentation ambiguity
In the C reference implementation, the 'putc' operation gets a 'Prtc' node type. while print(expression) gets a 'Prti' node type. The task documentation on this issue does not make this clear (it looks like the original thought was print(expression) would get 'Prtc' and that somehow putc got misspelled and the tangle of ideas was never completely spelled out).
I hope it's acceptable to instead use a 'Putc' node type for the putc operation. --Rdm (talk) 01:20, 21 January 2022 (UTC)
The three printing nodes types are:
- Prtc -- prints a character
- Prts -- prints a string
- Prti -- prints an integer
I used putc() for printing characters, because that is what C using. For a Rosetta code task, adding printf() would have been too big, and puts() (from C) adds a newline, which I did not want. So, I settled on putc() and print(). Of course, you are free to implement however you like, but it make not work with other implementations, e.g., you can intermix the C and Pything modules, because they use the same external names. --Ed Davis (talk) 17:55, 21 January 2021 (UTC)