Posted 14 years ago
by Krzysztof
Hi,
I've somehow created a lexical parser - it works (colors words etc.), but I'm having trouble with my semantic parser (I don't need any outlining etc., just parsing).
I'm trying to copy and than change your simple language, the effects are miserable.
here is my compilation unit:and here is my Macro:
I have also copied the compilationUnit's <AstNode> and <Declarations> - the help says they are optional, but apparently not for me... I haven't got the faintest idea what they do, I understand - more or less - the nonterminals only (and tokenIDs of course).
I generate the code by your grammar designer.
Below is a single line that should be matched:
#define TEN 10
The thing is, after the parser finds to the MatchMacro method (generated by designer) there is a 'DefineKeyword' (the #define word) ahead (a can see it in debugger by calling this.LookAheadTokenText) returns false saying there is an 'Unexpected Token'.
So my questions:
Can you show me how to write a parser that parses this simple line above (assume you already properly recognise tokens)?
What are AstNodes and Declarations tags for?
this will be it for the start. Thanks in advance.
I've somehow created a lexical parser - it works (colors words etc.), but I'm having trouble with my semantic parser (I don't need any outlining etc., just parsing).
I'm trying to copy and than change your simple language, the effects are miserable.
here is my compilation unit:
<NonTerminal Key="CompilationUnit">
<Production>
<![CDATA[
<%
compilationUnit = new CompilationUnit();
compilationUnit.StartOffset = this.LookAheadToken.StartOffset;
System.Boolean errorReported = false;
while (!this.IsAtEnd) {
if (IsNonTerminal("Macro")) {
errorReported = false;
%>
{ "Macro" }
<%
}
else {
// Error recovery: Advance to the next token since nothing was matched
if (!errorReported) {
this.ReportSyntaxError("Function declaration expected.");
errorReported = true;
}
this.AdvanceToNext();
}
}
compilationUnit.EndOffset = this.LookAheadToken.EndOffset;
%>
]]>
</Production>
</NonTerminal>
<NonTerminal Key="Macro">
<Production>
<![CDATA[
'DefineKeyword'
'MacroIdentifier'
'MacroIdentifier' | 'IntegerNumber' | ('OpenParenthesis' 'Space' 'Address' 'CloseParenthesis')
]]></Production>
</NonTerminal>
I generate the code by your grammar designer.
Below is a single line that should be matched:
#define TEN 10
The thing is, after the parser finds to the MatchMacro method (generated by designer) there is a 'DefineKeyword' (the #define word) ahead (a can see it in debugger by calling this.LookAheadTokenText) returns false saying there is an 'Unexpected Token'.
So my questions:
Can you show me how to write a parser that parses this simple line above (assume you already properly recognise tokens)?
What are AstNodes and Declarations tags for?
this will be it for the start. Thanks in advance.