aboutsummaryrefslogtreecommitdiff
path: root/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'grammar')
-rw-r--r--grammar/grammar.go13
-rw-r--r--grammar/semantic_error.go3
2 files changed, 12 insertions, 4 deletions
diff --git a/grammar/grammar.go b/grammar/grammar.go
index 60f1705..3268902 100644
--- a/grammar/grammar.go
+++ b/grammar/grammar.go
@@ -203,7 +203,7 @@ func (b *GrammarBuilder) genSymbolTableAndLexSpec(root *spec.RootNode) (*symbolT
for _, prod := range root.LexProductions {
if _, exist := symTab.toSymbol(prod.LHS); exist {
b.errs = append(b.errs, &verr.SpecError{
- Cause: semErrDuplicateSym,
+ Cause: semErrDuplicateTerminal,
Detail: prod.LHS,
Row: prod.Pos.Row,
})
@@ -280,7 +280,7 @@ func (b *GrammarBuilder) genSymbolTableAndLexSpec(root *spec.RootNode) (*symbolT
for _, fragment := range root.Fragments {
if _, exist := checkedFragments[fragment.LHS]; exist {
b.errs = append(b.errs, &verr.SpecError{
- Cause: semErrDuplicateSym,
+ Cause: semErrDuplicateTerminal,
Detail: fragment.LHS,
Row: fragment.Pos.Row,
})
@@ -432,10 +432,17 @@ func (b *GrammarBuilder) genProductionsAndActions(root *spec.RootNode, symTabAnd
prods.append(p)
for _, prod := range root.Productions {
- _, err := symTab.registerNonTerminalSymbol(prod.LHS)
+ sym, err := symTab.registerNonTerminalSymbol(prod.LHS)
if err != nil {
return nil, err
}
+ if sym.isTerminal() {
+ b.errs = append(b.errs, &verr.SpecError{
+ Cause: semErrDuplicateName,
+ Detail: prod.LHS,
+ Row: prod.Pos.Row,
+ })
+ }
}
for _, prod := range root.Productions {
diff --git a/grammar/semantic_error.go b/grammar/semantic_error.go
index 4dcd313..2d722a8 100644
--- a/grammar/semantic_error.go
+++ b/grammar/semantic_error.go
@@ -21,7 +21,8 @@ var (
semErrNoProduction = newSemanticError("a grammar needs at least one production")
semErrUndefinedSym = newSemanticError("undefined symbol")
semErrDuplicateProduction = newSemanticError("duplicate production")
- semErrDuplicateSym = newSemanticError("duplicate symbol")
+ semErrDuplicateTerminal = newSemanticError("duplicate terminal")
+ semErrDuplicateName = newSemanticError("duplicate names are not allowed between terminals and non-terminals")
semErrDirInvalidName = newSemanticError("invalid directive name")
semErrDirInvalidParam = newSemanticError("invalid parameter")
)