cwbaker / lalr

LALR(1) parser for C++
MIT License
78 stars 11 forks source link

Calls to default_action_handler with length == 0 #48

Open mingodad opened 1 year ago

mingodad commented 1 year ago

I've noticed that in several grammars there is calls to default_action_handler with length == 0 (see bellow list) which doesn't seems to make sense because nothing can be done.

Also some calls to default_action_handler doesn't contain any nodes[length-1].state()->transitions->reduced_symbol .

Now testing lua.g test.lua
default_handler_counters = call : 699, zero = 42
----
Now testing carbon-lang.g prelude.carbon
default_handler_counters = call : 9743, zero = 302
----
Now testing postgresql-16.g test.sql
default_handler_counters = call : 20521, zero = 4919
----
Now testing lsl_ext.g test.lsl
default_handler_counters = call : 9109, zero = 3
----
Now testing bison.g carbon-lang.y
default_handler_counters = call : 1365, zero = 230
----
Now testing javascript-core.g test.js
default_handler_counters = call : 4295, zero = 0
----
Now testing cparser.g test.c
default_handler_counters = call : 11923, zero = 0
----
Now testing java11.g test.java
default_handler_counters = call : 7884, zero = 0
----
Now testing rust.g test.rs
default_handler_counters = call : 2558, zero = 208
----
Now testing gringo-ng.g test.clingo
default_handler_counters = call : 732, zero = 13
----
Now testing ada-adayacc.g test.adb
default_handler_counters = call : 364, zero = 85
mingodad commented 1 year ago

I think that now I better understand the lalr inner working, after going through it step by step with gdb I found that the call with lenght == 0 where due to reducing rules that have empty as one of their possible options but because there was no way to know about it in the action handlers I've added an extra parameter with the reducing transition (see here https://github.com/mingodad/lalr/commit/08939baf5b60fd9b833c604cbd2d96822c2de209).