|
#region License
/* **********************************************************************************
* Copyright (c) Roman Ivantsov
* This source code is subject to terms and conditions of the MIT License
* for Irony. A copy of the license can be found in the License.txt file
* at the root of this distribution.
* By using this source code in any fashion, you are agreeing to be bound by the terms of the
* MIT License.
* You must not remove this notice from this software.
* **********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Irony.Compiler;
namespace Irony.Samples {
//Sample grammar for lookaheads calculation
// The grammar is from example 4.46 in Dragon book, p 241
// LALR(1) items set for this grammar is provided in fig. 4.45 on page 245.
// Note that the table in the book contains kernel-only items for each state,
// while we print out all items
class GrammarEx446 : Irony.Compiler.Grammar {
public GrammarEx446() {
// A' is augmented root
NonTerminal S = new NonTerminal("S");
NonTerminal L = new NonTerminal("L");
NonTerminal R = new NonTerminal("R");
Terminal id = new Terminal("id");
S.Expression = L + "=" + R | R;
L.Expression = "*" + R | id;
R.Expression = L;
this.Root = S;
}//method
//Expected state set:
/*
State I0
[S' -> �S , <EOF> ]
[S -> �L = R , <EOF> ]
[S -> �R , <EOF> ]
[L -> �* R , = ]
[L -> �id , = ]
[R -> �L , <EOF> ]
State I1
[S' -> S � , <EOF> ]
State I2
[S -> L �= R , <EOF> ]
[R -> L � , <EOF> ]
State I3
[S -> R � , <EOF> ]
State I4
[L -> * �R , =/<EOF> ]
[R -> �L , =/<EOF> ]
[L -> �* R , =/<EOF> ]
[L -> �id , =/<EOF> ]
State I5
[L -> id � , =/<EOF> ]
State I6
[S -> L = �R , <EOF> ]
[R -> �L , <EOF> ]
[L -> �* R , <EOF> ]
[L -> �id , <EOF> ]
State I7
[L -> * R � , =/<EOF> ]
State I8
[R -> L � , =/<EOF> ]
State I9
[S -> L = R � , <EOF> ]
*/
}
}//namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
25 years of professional experience. .NET/c#, databases, security.
Currently Senior Security Engineer, Cloud Security, Microsoft