HI, I am now implementing the grammar and I have a question about PrimaryString.
My language cannot include a dollar sign( $ ) and a single quote( ' ) in its string, so I wrote the following regular expression for the PrimaryStringText in the lexer class:
lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[^\\$']+"));
Then, when I input 'abcdef$ghijk$lmn123' in the LL Parser Debugger's Input box,
I get the following parse result:
DocumentRoot[
constant[
character_string[
single_byte_character_string[
"'"
[
"abcdef"
"$"
"ghijk"
"$"
"lmn123"
]
"'"
]
]
]
]
I expected an error would occur because my language cannot include a dollar sign( $ ).
But parse succeeded.
Please tell me what I am doing wrong.
Is there something wrong with the regular expression? ([^\\$']+)
lexer
// Initialize the PrimaryString lexical state
lexicalState = lexicalStates["PrimaryString"];
lexicalState.DefaultClassificationType = classificationTypeProvider.String;
lexicalState.DefaultTokenId = MyLanguageTokenId.PrimaryStringText;
lexicalState.DefaultTokenKey = "PrimaryStringText";
lexicalScope = new DynamicLexicalScope();
lexicalState.LexicalScopes.Add(lexicalScope);
lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "PrimaryStringStartDelimiter", null);
lexicalPatternGroup.TokenId = MyLanguageTokenId.PrimaryStringStartDelimiter;
lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\'"));
lexicalScope.StartLexicalPatternGroup = lexicalPatternGroup;
lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "PrimaryStringEndDelimiter", null);
lexicalPatternGroup.TokenId = MyLanguageTokenId.PrimaryStringEndDelimiter;
lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[\'\\n]"));
lexicalScope.EndLexicalPatternGroup = lexicalPatternGroup;
lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "PrimaryStringText", null);
lexicalPatternGroup.TokenId = MyLanguageTokenId.PrimaryStringText;
lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[^\\$']+"));
lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
grammar
var PrimaryStringStartDelimiter = new Terminal(MyLanguageTokenId.PrimaryStringStartDelimiter, "PrimaryStringStartDelimiter");
var PrimaryStringEndDelimiter = new Terminal(MyLanguageTokenId.PrimaryStringEndDelimiter, "PrimaryStringEndDelimiter");
var PrimaryStringText = new Terminal(MyLanguageTokenId.PrimaryStringText, "PrimaryStringText");
single_byte_character_string.Production = PrimaryStringStartDelimiter + PrimaryStringText.ZeroOrMore() + PrimaryStringEndDelimiter;