This project has moved and is read-only. For the latest updates, please go here.

Syntax analysis.

Mar 19, 2014 at 1:32 PM
Edited Mar 19, 2014 at 1:33 PM
Hello. I have been messing with Irony for a little while and I managed to define my language's grammar.

It seems to work nicely. Generating ParseTree takes literally 20ms at lowest point. I have kept the grammar pretty simple(no semantic considerations). I integrated it with VisualStudio and it works.

Now I have that part down, however I am now ready to move in to semantic analysis. I want to do this analysis in VisualStudio.

1) I want to see if the declared identifiers are valid(scope analysis)
2) I want to see if declarations and their types match(type analysis)
3) Are flow-control statements being used in correct places? (You can use "continue" only in for() statement.
4) And more fun stuff.

This is what I thought:

In languageService ParseRequest.Check I construct ParseTree on keystroke(which is fast - 20ms at worst). If there are NO errors, I build AST tree and start analysing that.

There is only one problem: AST tree generation takes literally 8 seconds on my powerful machine(170 lines of DSL code).

I have attached my non-terminals:
            #region NonTerminals.

            var binaryOperators = new NonTerminal("binary-operators"); // transient
            var unaryOperators = new NonTerminal("unary-operators"); // transient

            var statements = new NonTerminal("statements", typeof(StatementsNode));
            var statement = new NonTerminal("statement"); // transient

            var functionCall = new NonTerminal("function-call", typeof(FunctionCallNode));

            var declaration = new NonTerminal("declaration"); // transient

            var simpleDeclaration = new NonTerminal("simple-declaration", typeof(DeclarationNode));
            var simpleAssignment = new NonTerminal("simple-assignment", typeof(AssignmentNode));

            var arguments = new NonTerminal("arguments", typeof(ArgumentsNode));

            var variableType = new NonTerminal("variable-type", typeof(TypeIndicatorNode));

            var expression = new NonTerminal("expression"); // transient
            var binaryExpression = new NonTerminal("binary-expression", typeof(BinaryExpressionNode));
            var unaryExpression = new NonTerminal("unary-expression", typeof(UnaryExpressionNode));

            var braceBlock = new NonTerminal("brace-block"); // transient
            var parenExprBlock = new NonTerminal("parenheised-expression-block"); // transient

            var ifStatement = new NonTerminal("if-statement", typeof(IfNode));
            var forStatement = new NonTerminal("for-statement", typeof(ForNode));
            var whileStatement = new NonTerminal("while-statement", typeof(WhileNode));
            var doStatement = new NonTerminal("do-statement", typeof(DoNode));
            var switchStatement = new NonTerminal("switch-statement", typeof(SwitchNode));
            var flowControlStatement = new NonTerminal("flow-control-statement", typeof(FlowControlNode));

            var caseBlocks = new NonTerminal("case-blocks", typeof(CaseBlocksNode));
            var caseBlock = new NonTerminal("case-block", typeof(CaseBlock));

            var optionalBraceBlock = new NonTerminal("optional-brace-block"); // transient
            var optionalIfBraceBlock = new NonTerminal("optional-if-brace-block"); // transient

            var variableIdentifier = new NonTerminal("variable-identifier", typeof(VariableNode));

I don't do anything in my *Nodes. They are just empty shells, Such as VariableNode : AstNode,
and my Grammar inherits from InterpretedLanguageGrammar.

Why is AST generation so slow?
Mar 19, 2014 at 3:06 PM
Silly me. I had set "Release" mode, but I pressed F5 instead of Ctrl+F5. Now the parsing takes 0ms(AST generation included)!
Nice work Roman & anyone who contributed.