linkrope / gamma

Extended Affix Grammar Compiler Generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Let compiler generation fail for unproductive nonterminals

kuniss opened this issue · comments

If nonterminals are unproductive the compiler generator does not fail but issues a warning only.
However, the subsequently running D compiler almost fail due to a missing method.

It would be appreciated if the compiler generator already fails for unproductive terminals and only succeeds if it is forced to do so (with command line argument "--force").

Example for reproduction:

Code = Code Code "ADD" | number "ENTER".
 
Expr <+ Code2>:
    Term <Code1> ExprTail<Code1,Code2>.

ExprTail<- Code1, + Code3>:
    "+" Term<Code2> ExprTail<Code1 Code2 "ADD", Code3>.
//ExprTail<- Code,  + Code>: .

Term <+ number "ENTER": Code>:
    number <number>.

number = "0" | "1".

number:
    <+ "0": number> "0"
  | <+ "1": number> "1".

The example results with epsilon in the following output:

denis@modula:~/tmp/epsilon$ ./epsilon expr-bnf.eag 
info: Epsilon 1.02   JoDe/SteWe  22.11.96
info: SOAG-Evaluatorgenerator 1.06 dk 14.03.98
info: Analysing Expr
warn: 2 warnings
info: OK
warn: Analyser warnings on Expr's hyper-nonterminals:
warn: Expr unproductive
warn: ExprTail unproductive
Predicates in     Expr:  none. 
ELL(1) testing    Expr   ok
SLEAG testing   Expr   ok
info: ScanGen writing Expr
info: compile ExprScan.d
ELL(1) writing   Expr   +rc +ct info: compile Expr.d
dmd Expr.d ExprScan.d -g include/runtime.d src/epsilon/io.d src/io.d src/log.d src/epsilon/soag/listacks.d
Expr.d(627): Error: undefined identifier P0, did you mean function P1?

It's because the start symbol is not productive, so that no code is generated for it!
Strange things happen, if you forcefully set the start symbol to be productive (segmentation fault caused by infinite loop in error recovery mode).

When writing a grammar piece by piece, it can be helpful to generate compilers even if there are non-terminals that are not (yet) productive ("unfinished business"). Therefore, the compiler generation should only be aborted if the start symbol itself is not productive.

(Later on, we can add a general option "treat warnings as errors" for finished grammars.)

You mean, I should adapt the PR #12 to report an error only if the start symbol is affected?
However, if a different non-terminal than the start symbol is affected, a warning is sufficient and a compiler should be generated and D-compiled.