Hello!
I'm trying to create semantic parser for JavaScript language.
Does anybody made a grammar xml file for JavaScript?
I think I need to see an example of edited NonTerminal Production code (for "if/else", "for", "while", etc. statements) in order to understand how to do this by-my-own.
I've started to edit ActiproSoftware.Simple.Grammar.xml file, but right away I've got Error message from GrammarDesigner, that I couldn't understand.
I've changes "Statement" NonTermonal Production code in order to be able to make an assignment for var during it's declaration (like: var tmp = "test";).
I've added this code (just after the "Variable declaration statement" and before the "Assignment statement"):
| (
<%
' Variable statement with a value assignment
Dim variableName As Identifier = Nothing
Dim expression As Expression = Nothing
%>
'Var'
"Identifier<@ variableName @>"
'Assignment'
"Expression<@ expression @>"
'SemiColon<- ->'
<%
'statement = new AssignmentStatement(variableName, expression, new TextRange(startOffset, Me.Token.EndOffset))
%>
)
I've tried to run Parser Generator and got this Error message:
"A parser generator grammar exception occurred: r\nProduction 'Statement'contains an alternation that has multiple references to the terminal 'Var', either directly or via a non-terminal first set.
Does anybody knows what is this error means? Or more important: what is wrong with my code?
TX,
Einat
The full code looks like this:
<NonTerminal Key="Statement" Parameters="ByRef statement As Statement">
<Production>
<![CDATA[
<%
statement = Nothing
Dim startOffset As System.Int32 = Me.LookAheadToken.StartOffset
%>
"Block<@ statement @>"
| (
<%
' Empty statement
%>
'SemiColon'
<%
statement = new EmptyStatement(Me.Token.TextRange)
%>
)
| (
<%
' Variable declaration statement
Dim variableName As Identifier = Nothing
%>
'Var'
"Identifier<@ variableName @>"
'SemiColon<- ->'
<%
statement = new VariableDeclarationStatement(variableName, new TextRange(startOffset, Me.Token.EndOffset))
%>
)
| (
<%
' Variable statement with a value assignment
Dim variableName As Identifier = Nothing
Dim expression As Expression = Nothing
%>
'Var'
"Identifier<@ variableName @>"
'Assignment'
"Expression<@ expression @>"
'SemiColon<- ->'
<%
'statement = new AssignmentStatement(variableName, expression, new TextRange(startOffset, Me.Token.EndOffset))
%>
)
| (
<%
' Assignment statement
Dim variableName As Identifier = Nothing
Dim expression As Expression = Nothing
%>
"Identifier<@ variableName @>"
'Assignment'
"Expression<@ expression @>"
'SemiColon<- ->'
<%
statement = new AssignmentStatement(variableName, expression, new TextRange(startOffset, Me.Token.EndOffset))
%>
)
| (
<%
' Return statement
Dim expression As Expression = Nothing
%>
'Return'
"Expression<@ expression @>"
'SemiColon<- ->'
<%
statement = new ReturnStatement(expression, new TextRange(startOffset, Me.Token.EndOffset))
%>
)
]]></Production>
</NonTerminal>
I'm trying to create semantic parser for JavaScript language.
Does anybody made a grammar xml file for JavaScript?
I think I need to see an example of edited NonTerminal Production code (for "if/else", "for", "while", etc. statements) in order to understand how to do this by-my-own.
I've started to edit ActiproSoftware.Simple.Grammar.xml file, but right away I've got Error message from GrammarDesigner, that I couldn't understand.
I've changes "Statement" NonTermonal Production code in order to be able to make an assignment for var during it's declaration (like: var tmp = "test";).
I've added this code (just after the "Variable declaration statement" and before the "Assignment statement"):
| (
<%
' Variable statement with a value assignment
Dim variableName As Identifier = Nothing
Dim expression As Expression = Nothing
%>
'Var'
"Identifier<@ variableName @>"
'Assignment'
"Expression<@ expression @>"
'SemiColon<- ->'
<%
'statement = new AssignmentStatement(variableName, expression, new TextRange(startOffset, Me.Token.EndOffset))
%>
)
I've tried to run Parser Generator and got this Error message:
"A parser generator grammar exception occurred: r\nProduction 'Statement'contains an alternation that has multiple references to the terminal 'Var', either directly or via a non-terminal first set.
Does anybody knows what is this error means? Or more important: what is wrong with my code?
TX,
Einat
The full code looks like this:
<NonTerminal Key="Statement" Parameters="ByRef statement As Statement">
<Production>
<![CDATA[
<%
statement = Nothing
Dim startOffset As System.Int32 = Me.LookAheadToken.StartOffset
%>
"Block<@ statement @>"
| (
<%
' Empty statement
%>
'SemiColon'
<%
statement = new EmptyStatement(Me.Token.TextRange)
%>
)
| (
<%
' Variable declaration statement
Dim variableName As Identifier = Nothing
%>
'Var'
"Identifier<@ variableName @>"
'SemiColon<- ->'
<%
statement = new VariableDeclarationStatement(variableName, new TextRange(startOffset, Me.Token.EndOffset))
%>
)
| (
<%
' Variable statement with a value assignment
Dim variableName As Identifier = Nothing
Dim expression As Expression = Nothing
%>
'Var'
"Identifier<@ variableName @>"
'Assignment'
"Expression<@ expression @>"
'SemiColon<- ->'
<%
'statement = new AssignmentStatement(variableName, expression, new TextRange(startOffset, Me.Token.EndOffset))
%>
)
| (
<%
' Assignment statement
Dim variableName As Identifier = Nothing
Dim expression As Expression = Nothing
%>
"Identifier<@ variableName @>"
'Assignment'
"Expression<@ expression @>"
'SemiColon<- ->'
<%
statement = new AssignmentStatement(variableName, expression, new TextRange(startOffset, Me.Token.EndOffset))
%>
)
| (
<%
' Return statement
Dim expression As Expression = Nothing
%>
'Return'
"Expression<@ expression @>"
'SemiColon<- ->'
<%
statement = new ReturnStatement(expression, new TextRange(startOffset, Me.Token.EndOffset))
%>
)
]]></Production>
</NonTerminal>