r2813 - getParseTreeFromLexems(): more fixes according to updated BNF
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 2 Jun 2009 17:23:15 +0000 (17:23 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 2 Jun 2009 17:23:15 +0000 (17:23 +0000)
inc/code.php

index e7fc832dce1f00b18f7aea80d2e9fdffb47a9608..e9ecde763e137117931006f400abd24b179c15d2 100644 (file)
@@ -328,11 +328,14 @@ function getParseTreeFromLexems ($lexems)
                        // correct sentence base on the stack and some "and {something}" items
                        // on the input tape, hence let's detect this specific case and insist
                        // on "shift" action to make SYNT_AND_EXPR parsing hungry.
+                       // P.S. Same action is taken for SYNT_EXPR (logical-OR) to prevent
+                       // premature reduction of "condition" for grant/definition/context
+                       // modifier sentences. The shift tries to be conservative, it advances
+                       // by only one token on the tape.
                        if
                        (
-                               $stacktop['type'] == 'SYNT_AND_EXPR' and
-                               ($done < $todo) and
-                               $lexems[$done]['type'] == 'LEX_AND'
+                               $stacktop['type'] == 'SYNT_AND_EXPR' and $done < $todo and $lexems[$done]['type'] == 'LEX_AND' or
+                               $stacktop['type'] == 'SYNT_EXPR' and $done < $todo and $lexems[$done]['type'] == 'LEX_OR'
                        )
                        {
                                // shift!
@@ -444,12 +447,14 @@ function getParseTreeFromLexems ($lexems)
                                );
                                continue;
                        }
-                       // CTXMODLIST ::= CTXMOD
+                       // CTXMODLIST ::= CTXMODLIST CTXMOD
                        if
                        (
-                               $stacktop['type'] == 'SYNT_CTXMOD'
+                               $stacktop['type'] == 'SYNT_CTXMOD' and
+                               $stacksecondtop['type'] == 'SYNT_CTXMODLIST'
                        )
                        {
+                               array_pop ($stack);
                                array_pop ($stack);
                                array_push
                                (
@@ -458,19 +463,17 @@ function getParseTreeFromLexems ($lexems)
                                        (
                                                'type' => 'SYNT_CTXMODLIST',
                                                'lineno' => $stacktop['lineno'],
-                                               'load' => array ($stacktop['load'])
+                                               'load' => array_merge ($stacksecondtop['load'], array ($stacktop['load']))
                                        )
                                );
                                continue;
                        }
-                       // CTXMODLIST ::= CTXMODLIST CTXMOD
+                       // CTXMODLIST ::= CTXMOD
                        if
                        (
-                               $stacktop['type'] == 'SYNT_CTXMOD' and
-                               $stacksecondtop['type'] == 'SYNT_CTXMODLIST'
+                               $stacktop['type'] == 'SYNT_CTXMOD'
                        )
                        {
-                               array_pop ($stack);
                                array_pop ($stack);
                                array_push
                                (
@@ -479,7 +482,7 @@ function getParseTreeFromLexems ($lexems)
                                        (
                                                'type' => 'SYNT_CTXMODLIST',
                                                'lineno' => $stacktop['lineno'],
-                                               'load' => array_merge ($stacksecondtop['load'], array ($stacktop['load']))
+                                               'load' => array ($stacktop['load'])
                                        )
                                );
                                continue;
@@ -669,7 +672,7 @@ function getParseTreeFromLexems ($lexems)
                                                'type' => 'SYNT_GRANT',
                                                'lineno' => $stacktop['lineno'],
                                                'decision' => $stacksecondtop['type'],
-                                               'condition' => $stacktop['load']
+                                               'condition' => $stacktop
                                        )
                                );
                                continue;