Re: [PATCH v1] kconfig: add config and source entry details

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 24, 2024 at 2:27 PM Prasad Pandit <pjp@xxxxxxxxxxxxxxxxx> wrote:
>
> Hi,
>
> On Tuesday, 23 April, 2024 at 03:41:35 pm IST, Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote:
> >EOL is a statement separator.
>
> * Right. So are semi-colon (;), braces (}{) and colon (:) in case of C and Python.
>
> ===
> $ cat t.c
>
> #include <stdio.h>
>
> int main (void)
> { printf("Hello, world!\n");$
> $
> $ cc -xc -o t t.c
> t.c: In function ‘main’:
> t.c:6:1: error: expected declaration or statement at end of input
>     6 | { printf("Hello, world!\n");
>       | ^



It is because the missing closing brace
is a grammatical error.



> ---
>
> $ cat t.py
> #!/usr/bin/python
>
> if (x == 10)$
> $
> $ python t.py
>   File "/tmp/im/t.py", line 3
>     if (x == 10)
>                 ^
> SyntaxError: expected ':'
> ===
>
> * In above examples, files terminate without completing the statement and/or function definition (missing closing brace '}'), which is being treated as an error.



Again, this is wrong Python code. That's why.





>
>
> >Could you give me an example programming language
> >that errors out when \n is missing at the end of the
> >source file?
>
> * It is not about '\n' at the end of file, but '\n' at the end of the Kconfig statement/record. Because Kconfig language uses EOL as a separator.
>
>
> > I do not think requiring EOL at the end of file would help simplify the lexer/parser.
>
> * It does, because on the parser side you don't have to define rule(s) with EOF to parse statements.


Do you see any grammar that treats T_EOF in
scripts/kconfig/parser.y ?
It only handles T_EOL.

The parser is already simplified.



>
> >When the lexer is encountered with EOF, it must
> >tell the parser to finish the current statement
> >and go back to the previous source file.
> >So, EOF implies the end of the statement anyway.
>
> * No, EOF does not imply end of a statement. The errors reported by gcc(1) and Python above clearly confirm that EOF is not end of statement.



In Python, a newline (and also a semicolon)
separates two statements, but it does not mean
it is required at the end of file.


If EOF is encountered, the statement ends.




I attached two Python scripts for you.

test.py and test2.py are almost the same.

Only the difference is that
test2.py lacks a new line at the end of file.



masahiro@zoe:/tmp$ cat test.py
#!/usr/bin/python
print("A")
print("B")
masahiro@zoe:/tmp$ cat test2.py
#!/usr/bin/python
print("A")
print("B")masahiro@zoe:/tmp$



masahiro@zoe:/tmp$ ./test.py
A
B
masahiro@zoe:/tmp$ chmod +x test2.py
masahiro@zoe:/tmp$ ./test2.py
A
B



As I said, it is a linter's job (e.g. pylint)
to check the missing newline at the end.




>
> * In their case colon(':') or brace ('}') are the required terminators, whereas in Kconfig's case EOL ('\n') is the required terminator.
>
> * Because Kconfig language uses EOL ('\n') as statement separator/terminator, IMHO it should display an error when that condition is not met, because such statement remains incomplete.
>
>
> Thank you.







-- 
Best Regards
Masahiro Yamada
#!/usr/bin/python
print("A")
print("B")
#!/usr/bin/python
print("A")
print("B")

[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux