Define LEX
LEX define are accomplished, direct open XML.ddw file from sample folder. Click here to see the diagram.
Define Grammar
Grammar support LR(n). 'n' is unlimited. Double click Syntax Node/Identifier/Number/Constant/Symbol, see the property :
.jpg)
Check the Lookup Right combobox, then the analyzer will reads input 1 more derivation to right to decide grammar regular. Serial connections have 'Lookup Right 1' then can support LR(n),n is unlimited. For example, define C++ member function declear syntax:
string get_string();
The parser read 'string' identifier, it is a DataType or FunctionName ? Here can not decide. It must lookup right one more derivation 'get_string', then reading 'get_string' also can not decide it is a DataType + FunctionName. So that lookup right again, read '(' then decide it is Dfunction DataType + FunctionName+'('.
Parser Code generation
The generattion gererate LEX type enum from 'CCDefines.h', a parser code in 'LParser.cpp', sample project in 'main.cpp'.
How the parser work in LR(n)? See the key code generated by Duceland Designer :
...
if(Is_DataType(words,index,this_tree))
{
index_1=index-1;
lookup_right_pass=false;
if(!lookup_right_pass)
{
index_1++;
if((*words)[index_1]->Type==ltKeyword || (*words)[index_1]->Value==L"operator")
lookup_right_pass=true;
index_1--;
}
if(!lookup_right_pass)
{
index_1++;
if((*words)[index_1]->Type==ltIdentifier)//function name
{
if(!lookup_right_pass)
{
index_1++;
if((*words)[index_1]->Type==ltLeftBracket/*'('*/)
lookup_right_pass=true;
index_1--;
}
}
index_1--;
}
if(!lookup_right_pass)
{
int local_old=index_1;
index_1++;
if(Is_decorate(words,index_1,NULL))
{
index_1--;
if(!lookup_right_pass)
{
index_1++;
if((*words)[index_1]->Type==ltIdentifier)//function name
{
if(!lookup_right_pass)
{
index_1++;
if((*words)[index_1]->Type==ltLeftBracket/*'('*/)
lookup_right_pass=true;
index_1--;
}
}
index_1--;
}
}
index_1=local_old;
}
if(lookup_right_pass)
{
if(tree)
{
tree->AddChild(this_tree);
}
current_word=(*words)[index];
goto S_4EBA4D22972F43C8A0C0E78C946E5587;//DataType
}
}
...
}
The local varaint lookup_right_pass check lookup right passed. If look right 1 fail, reader position will be turn back(index_1--).
