summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--colm/lmparse.kl43
-rw-r--r--colm/parsedata.cpp23
-rw-r--r--colm/parsedata.h3
-rw-r--r--colm/pdabuild.cpp10
4 files changed, 36 insertions, 43 deletions
diff --git a/colm/lmparse.kl b/colm/lmparse.kl
index 46006f51..799418a1 100644
--- a/colm/lmparse.kl
+++ b/colm/lmparse.kl
@@ -173,13 +173,14 @@ generic_def: KW_Map TK_Word '[' type_ref type_ref ']'
final {
Namespace *nspace = namespaceStack.top();
- KlangEl *langEl = getKlangEl( pd, nspace, $2->data, KlangEl::NonTerm );
+ KlangEl *langEl = getKlangEl( pd, nspace, $2->data );
/* Check that the element wasn't previously defined as something else. */
- if ( langEl->type != KlangEl::Unknown && langEl->type != KlangEl::NonTerm ) {
- error($1->loc) << "'" << curDefineId <<
+ if ( langEl->type != KlangEl::Unknown ) {
+ error($1->loc) << "'" << $2->data <<
"' already defined as something else" << endp;
}
+ langEl->type = KlangEl::NonTerm;
GenericType *generic = new GenericType( $2->data, GEN_MAP,
pd->nextGenericId++, langEl, $5->typeRef );
@@ -197,13 +198,14 @@ generic_def: KW_List TK_Word '[' type_ref ']'
final {
/* Get the language element. */
Namespace *nspace = namespaceStack.top();
- KlangEl *langEl = getKlangEl( pd, nspace, $2->data, KlangEl::NonTerm );
+ KlangEl *langEl = getKlangEl( pd, nspace, $2->data );
/* Check that the element wasn't previously defined as something else. */
- if ( langEl->type != KlangEl::Unknown && langEl->type != KlangEl::NonTerm ) {
- error($1->loc) << "'" << curDefineId <<
+ if ( langEl->type != KlangEl::Unknown ) {
+ error($1->loc) << "'" << $2->data <<
"' already defined as something else" << endp;
}
+ langEl->type = KlangEl::NonTerm;
GenericType *generic = new GenericType( $2->data, GEN_LIST,
pd->nextGenericId++, langEl, $4->typeRef );
@@ -249,8 +251,7 @@ global_def: KW_Global var_def opt_def_init
cfl_def: cfl_def_head obj_var_list properties_list cfl_prod_list
final {
/* Get the language element. */
- KlangEl *langEl = getKlangEl( pd, namespaceStack.top(),
- curDefineId, KlangEl::Unknown );
+ KlangEl *langEl = getKlangEl( pd, namespaceStack.top(), curDefineId );
/* Make a new object definition. */
ObjectDef *objectDef = new ObjectDef( ObjectDef::UserType, curDefineId,
@@ -264,8 +265,7 @@ cfl_def_head: KW_Def TK_Word
curDefineId = $2->data;
/* Get the language element. */
- KlangEl *langEl = getKlangEl( pd, namespaceStack.top(),
- $2->data, KlangEl::Unknown );
+ KlangEl *langEl = getKlangEl( pd, namespaceStack.top(), $2->data );
/* Check that the element wasn't previously defined as something else. */
if ( langEl->type != KlangEl::Unknown ) {
@@ -286,8 +286,7 @@ property:
KW_ReduceFirst
final {
/* Get the language element. */
- KlangEl *prodName = getKlangEl( pd, namespaceStack.top(),
- curDefineId, KlangEl::Unknown );
+ KlangEl *prodName = getKlangEl( pd, namespaceStack.top(), curDefineId );
prodName->reduceFirst = true;
};
@@ -612,9 +611,9 @@ literal_item: TK_Literal
error( $1->loc ) << "literal already defined in this namespace" << endp;
else {
/* Create a token for the literal. */
- KlangEl *newLangEl = getKlangEl( pd, nspace, name, KlangEl::Term );
- assert( newLangEl != 0 );
- assert( newLangEl->type == KlangEl::Term );
+ KlangEl *newLangEl = getKlangEl( pd, nspace, name );
+ assert( newLangEl->type == KlangEl::Unknown );
+ newLangEl->type = KlangEl::Term;
newLangEl->lit = $1->data;
newLangEl->isLiteral = true;
@@ -660,9 +659,9 @@ token_def:
name.setAs( 32, "_ignore_%.4x", pd->nextTokenId );
/* Create the token. */
- KlangEl *tokEl = getKlangEl( pd, namespaceStack.top(), name, KlangEl::Term );
- if ( tokEl->type != KlangEl::Unknown && tokEl->type != KlangEl::Term )
- error($1->loc) << "'" << name << "' already defined as something else" << endp;
+ KlangEl *tokEl = getKlangEl( pd, namespaceStack.top(), name );
+ if ( tokEl->type != KlangEl::Unknown )
+ error($1->loc) << "'" << name << "' already defined" << endp;
tokEl->type = KlangEl::Term;
tokEl->ignore = ignore;
@@ -840,8 +839,7 @@ start_reduce:
$$->localFrame = $1->localFrame;
/* Get the language element. */
- KlangEl *prodName = getKlangEl( pd, namespaceStack.top(),
- curDefineId, KlangEl::Unknown );
+ KlangEl *prodName = getKlangEl( pd, namespaceStack.top(), curDefineId );
/* References to the reduce item. */
pd->addProdRedObjectVar( pd->curLocalFrame, prodName );
@@ -1956,7 +1954,7 @@ void Parser::addRegularDef( const InputLoc &loc, Namespace *nspace,
}
else {
// Recover by ignoring the duplicate.
- error(loc) << "fsm \"" << name << "\" previously defined" << endl;
+ error(loc) << "regular definition \"" << name << "\" already exists" << endl;
}
}
@@ -1964,8 +1962,7 @@ void Parser::addProduction( InputLoc &loc, const String &name,
ProdElList *prodElList, bool commit, CodeBlock *redBlock )
{
/* Get the language element. */
- KlangEl *prodName = getKlangEl( pd, namespaceStack.top(),
- name, KlangEl::Unknown );
+ KlangEl *prodName = getKlangEl( pd, namespaceStack.top(), name );
assert( prodName->type == KlangEl::NonTerm );
Namespace *nspace = namespaceStack.top();
diff --git a/colm/parsedata.cpp b/colm/parsedata.cpp
index 2effebcf..c0f086b5 100644
--- a/colm/parsedata.cpp
+++ b/colm/parsedata.cpp
@@ -1090,10 +1090,9 @@ void ParseData::createDefaultScanner()
/* Now create the one and only token -> "<chr>" / any / */
name = "___DEFAULT_SCANNER_CHR";
- defaultCharKlangEl = getKlangEl( this, defaultNamespace,
- name, KlangEl::Term );
- assert( defaultCharKlangEl != 0 );
- assert( defaultCharKlangEl->type == KlangEl::Term );
+ defaultCharKlangEl = getKlangEl( this, defaultNamespace, name );
+ assert( defaultCharKlangEl->type == KlangEl::Unknown );
+ defaultCharKlangEl->type = KlangEl::Term;
Join *join = new Join( new Expression( BT_Any ) );
@@ -1138,7 +1137,7 @@ void ParseData::resolveReferenceFactor( PdaFactor *fact )
fact->nspace = nspace;
/* Look up the language element in the region. */
- KlangEl *langEl = getKlangEl( this, nspace, fact->refName, KlangEl::Unknown );
+ KlangEl *langEl = getKlangEl( this, nspace, fact->refName );
if ( fact->opt ) {
/* If the factor is an opt, create the opt element and link the factor
@@ -1150,7 +1149,7 @@ void ParseData::resolveReferenceFactor( PdaFactor *fact )
fact->langEl = inDict->value;
}
else {
- KlangEl *prodName = getKlangEl( this, nspace, optName, KlangEl::NonTerm );
+ KlangEl *prodName = getKlangEl( this, nspace, optName );
prodName->type = KlangEl::NonTerm;
prodName->isOpt = true;
@@ -1191,8 +1190,7 @@ void ParseData::resolveReferenceFactor( PdaFactor *fact )
fact->langEl = inDict->value;
}
else {
- KlangEl *prodName = getKlangEl( this, nspace,
- repeatName, KlangEl::NonTerm );
+ KlangEl *prodName = getKlangEl( this, nspace, repeatName );
prodName->type = KlangEl::NonTerm;
prodName->isRepeat = true;
@@ -1364,10 +1362,9 @@ void ParseData::initEmptyScanners()
InputLoc loc;
String name( reg->name.length() + 16, "__%s_DEF_PAT", reg->name.data );
- KlangEl *lel = getKlangEl( this, rootNamespace,
- name.data, KlangEl::Term );
- assert( lel != 0 );
- assert( lel->type == KlangEl::Term );
+ KlangEl *lel = getKlangEl( this, rootNamespace, name.data );
+ assert( lel->type == KlangEl::Unknown );
+ lel->type = KlangEl::Term;
Join *join = new Join( new Expression( BT_Any ) );
@@ -1666,7 +1663,7 @@ void ParseData::resolveUses()
error() << "do not have namespace for resolving reference" << endp;
/* Look up the language element in the region. */
- KlangEl *langEl = getKlangEl( this, nspace, lel->objectDefUses, KlangEl::Unknown );
+ KlangEl *langEl = getKlangEl( this, nspace, lel->objectDefUses );
lel->objectDef = langEl->objectDef;
}
}
diff --git a/colm/parsedata.h b/colm/parsedata.h
index 522a7aea..ab60f859 100644
--- a/colm/parsedata.h
+++ b/colm/parsedata.h
@@ -924,7 +924,6 @@ struct Parser;
typedef AvlMap<String, Parser *, CmpStr> ParserDict;
typedef AvlMapEl<String, Parser *> ParserDictEl;
-KlangEl *getKlangEl( ParseData *pd, Namespace *nspace,
- const String &data, KlangEl::Type defType );
+KlangEl *getKlangEl( ParseData *pd, Namespace *nspace, const String &data );
#endif /* _PARSEDATA_H */
diff --git a/colm/pdabuild.cpp b/colm/pdabuild.cpp
index a18f388f..4c718399 100644
--- a/colm/pdabuild.cpp
+++ b/colm/pdabuild.cpp
@@ -125,15 +125,14 @@ PdaGraph *ProdElList::walk( ParseData *pd )
}
-KlangEl *getKlangEl( ParseData *pd, Namespace *nspace,
- const String &data, KlangEl::Type defType )
+KlangEl *getKlangEl( ParseData *pd, Namespace *nspace, const String &data )
{
/* If the id is already in the dict, it will be placed in last found. If
* it is not there then it will be inserted and last found will be set to it. */
SymbolMapEl *inDict = nspace->symbolMap.find( data );
if ( inDict == 0 ) {
/* Language element not there. Make the new lang el and insert.. */
- KlangEl *langEl = new KlangEl( nspace, data, defType );
+ KlangEl *langEl = new KlangEl( nspace, data, KlangEl::Unknown );
inDict = nspace->symbolMap.insert( langEl->name, langEl );
pd->langEls.append( langEl );
}
@@ -1191,8 +1190,9 @@ void ParseData::insertUniqueEmptyProductions()
/* Get a language element. */
char name[20];
sprintf(name, "U%li", prodList.length());
- KlangEl *prodName = getKlangEl( this, rootNamespace,
- name, KlangEl::NonTerm );
+ KlangEl *prodName = getKlangEl( this, rootNamespace, name );
+ assert( prodName->type == KlangEl::Unknown );
+ prodName->type = KlangEl::NonTerm;
Definition *newDef = new Definition( InputLoc(), prodName,
0 /* FIXME new VarDef( name, 0 )*/,
false, 0, prodList.length(), Definition::Production );