From 9c2313b34ddd646537f6085cd13114275cc716b6 Mon Sep 17 00:00:00 2001 From: Stephen Johnson Date: Mon, 5 Feb 2024 11:43:52 -0600 Subject: [PATCH] Removed old parser. --- Src/Core/API/Base/Factory.cs | 50 +- Src/Core/API/Parser/Parser.cs | 1391 ----------------------- Src/Core/API/Parser/lexer.g.cs | 1833 ------------------------------- Src/Core/API/Parser/lexer.lex | 226 ---- Src/Core/API/Parser/parser.g.cs | 1529 -------------------------- Src/Core/API/Parser/parser.y | 821 -------------- 6 files changed, 8 insertions(+), 5842 deletions(-) delete mode 100644 Src/Core/API/Parser/Parser.cs delete mode 100644 Src/Core/API/Parser/lexer.g.cs delete mode 100644 Src/Core/API/Parser/lexer.lex delete mode 100644 Src/Core/API/Parser/parser.g.cs delete mode 100644 Src/Core/API/Parser/parser.y diff --git a/Src/Core/API/Base/Factory.cs b/Src/Core/API/Base/Factory.cs index 26a42cc..3493b99 100644 --- a/Src/Core/API/Base/Factory.cs +++ b/Src/Core/API/Base/Factory.cs @@ -17,8 +17,6 @@ public sealed class Factory private static readonly char[] Whitespaces = new char[] { ' ', '\t', '\n' }; - private static bool USE_ANTLR = true; - public static Factory Instance { get { return instance; } @@ -1368,16 +1366,8 @@ internal AST AddProgram(AST folder, AST program) return Task.Factory.StartNew(() => { ParseResult pr; - if (USE_ANTLR) - { - var parser = new FormulaVisitor(); - parser.ParseFile(name, null, default(Span), cancelToken, out pr); - } - else - { - var parser = new Parser(envParams); - parser.ParseFile(name, null, default(Span), cancelToken, out pr); - } + var parser = new FormulaVisitor(); + parser.ParseFile(name, null, default(Span), cancelToken, out pr); return pr; }); @@ -1393,16 +1383,8 @@ internal AST AddProgram(AST folder, AST program) return Task.Factory.StartNew(() => { ParseResult pr; - if (USE_ANTLR) - { - var parser = new FormulaVisitor(); - parser.ParseText(name, programText, default(Span), cancelToken, out pr); - } - else - { - var parser = new Parser(envParams); - parser.ParseText(name, programText, default(Span), cancelToken, out pr); - } + var parser = new FormulaVisitor(); + parser.ParseText(name, programText, default(Span), cancelToken, out pr); return pr; }); @@ -1418,16 +1400,8 @@ internal AST AddProgram(AST folder, AST program) return Task.Factory.StartNew(() => { ParseResult pr; - if (USE_ANTLR) - { - var parser = new FormulaVisitor(); - parser.ParseFile(name, referrer, location, cancelToken, out pr); - } - else - { - var parser = new Parser(envParams); - parser.ParseFile(name, referrer, location, cancelToken, out pr); - } + var parser = new FormulaVisitor(); + parser.ParseFile(name, referrer, location, cancelToken, out pr); return pr; }); } @@ -1437,16 +1411,8 @@ public AST ParseDataTerm(string text, out ImmutableCollection flags, Contract.Requires(text != null); ParseResult pr; AST result = null; - if (USE_ANTLR) - { - var parser = new FormulaVisitor(); - result = parser.ParseFuncTerm(text, out pr); - } - else - { - var parser = new Parser(envParams); - result = parser.ParseFuncTerm(text, out pr); - } + var parser = new FormulaVisitor(); + result = parser.ParseFuncTerm(text, out pr); pr.Program.Root.GetNodeHash(); flags = pr.Flags; diff --git a/Src/Core/API/Parser/Parser.cs b/Src/Core/API/Parser/Parser.cs deleted file mode 100644 index 75c7666..0000000 --- a/Src/Core/API/Parser/Parser.cs +++ /dev/null @@ -1,1391 +0,0 @@ -namespace Microsoft.Formula.API -{ - using System; - using System.Collections.Generic; - using System.Diagnostics.Contracts; - using System.Linq; - using Microsoft.Formula.API.Nodes; - using Microsoft.Formula.Common; - using QUT.Gppg; - - internal partial class Parser : ShiftReduceParser - { - private enum ModRefState - { - None, ModApply, Input, Output, Other - }; - - private ParseResult parseResult; - private Node currentModule = null; - - /******* State for building terms ********/ - private Stack appStack = new Stack(); - private Stack argStack = new Stack(); - private Stack quoteStack = new Stack(); - /*****************************************/ - - /******* State for building rules, contracts, and comprehensions ********/ - private Nodes.Rule crntRule = null; - private ContractItem crntContract = null; - private Body crntBody = null; - /*****************************************/ - - /******* State for building types and type declarations ********/ - private string crntTypeDeclName = null; - private Span crntTypeDeclSpan = default(Span); - private Node crntTypeDecl = null; - private Node crntTypeTerm = null; - private Nodes.Enum currentEnum = null; - /*****************************************/ - - /******* State for ModRefs, steps, and updates ********/ - private ModRef crntModRef = null; - private Step crntStep = null; - private Update crntUpdate = null; - private ModRefState crntModRefState = ModRefState.None; - /*************************************/ - - /******* State for sentence configs ********/ - private Config crntSentConf = null; - /*************************************/ - - /****** Additional parameters *************/ - private EnvParams envParams; - /*************************************/ - - /****** Additional parameters *************/ - private System.Text.StringBuilder stringBuffer = new System.Text.StringBuilder(); - private Span stringStart; - private Span stringEnd; - /*************************************/ - - private bool IsBuildingNext - { - get; - set; - } - - private bool IsBuildingUpdate - { - get; - set; - } - - private bool IsBuildingCod - { - get; - set; - } - - public Parser(EnvParams envParams = null) - : base(new Scanner()) - { - this.envParams = envParams; - } - - internal AST ParseFuncTerm(string text, out ParseResult pr) - { - parseResult = new ParseResult(); - pr = parseResult; - text = string.Format("domain Dummy {{ dummy({0}). }}", text); - - var str = new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes(text)); - ((Scanner)Scanner).SetSource(str); - ((Scanner)Scanner).ParseResult = parseResult; - ResetState(); - var result = Parse(default(System.Threading.CancellationToken)); - str.Close(); - - if (!result) - { - parseResult.Program.Node.GetNodeHash(); - return null; - } - - parseResult.Program.Node.GetNodeHash(); - return Factory.Instance.ToAST(((FuncTerm)((Domain)parseResult.Program.Node.Modules.First()).Rules.First().Heads.First()).Args.First()); - } - - internal bool ParseFile(ProgramName name, string referrer, Span location, System.Threading.CancellationToken ctok, out ParseResult pr) - { - parseResult = new ParseResult(new Program(name)); - pr = parseResult; - bool result; - - try - { - var unescapedPath = Uri.UnescapeDataString(name.Uri.AbsolutePath); - var fi = new System.IO.FileInfo(unescapedPath); - if (!fi.Exists) - { - var badFile = new Flag( - SeverityKind.Error, - default(Span), - referrer == null ? - Constants.BadFile.ToString(string.Format("The file {0} does not exist", name.ToString(envParams))) : - Constants.BadFile.ToString(string.Format("The file {0} referred to in {1} ({2}, {3}) does not exist", name.ToString(envParams), referrer, location.StartLine, location.StartCol)), - Constants.BadFile.Code, - parseResult.Program.Node.Name); - parseResult.AddFlag(badFile); - parseResult.Program.Node.GetNodeHash(); - return false; - } - - var str = new System.IO.FileStream(unescapedPath, System.IO.FileMode.Open, System.IO.FileAccess.Read); - ((Scanner)Scanner).SetSource(str); - ((Scanner)Scanner).ParseResult = parseResult; - ResetState(); - - result = Parse(ctok); - str.Close(); - } - catch (Exception e) - { - var badFile = new Flag( - SeverityKind.Error, - default(Span), - referrer == null ? - Constants.BadFile.ToString(e.Message) : - Constants.BadFile.ToString(string.Format("{0} referred to in {1} ({2}, {3})", e.Message, referrer, location.StartLine, location.StartCol)), - Constants.BadFile.Code, - parseResult.Program.Node.Name); - parseResult.AddFlag(badFile); - parseResult.Program.Node.GetNodeHash(); - return false; - } - - if (ctok.IsCancellationRequested) - { - var badFile = new Flag( - SeverityKind.Error, - default(Span), - referrer == null ? - Constants.OpCancelled.ToString(string.Format("Cancelled parsing of {0}", name.ToString(envParams))) : - Constants.OpCancelled.ToString(string.Format("Cancelled parsing of {0} referred to in {1} ({2}, {3})", name.ToString(envParams), referrer, location.StartLine, location.StartCol)), - Constants.OpCancelled.Code, - parseResult.Program.Node.Name); - parseResult.AddFlag(badFile); - parseResult.Program.Node.GetNodeHash(); - return false; - } - - parseResult.Program.Node.GetNodeHash(); - return result; - } - - internal bool ParseText(ProgramName name, string programText, Span location, System.Threading.CancellationToken ctok, out ParseResult pr) - { - parseResult = new ParseResult(new Program(name)); - pr = parseResult; - bool result; - - try - { - var str = new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes(programText)); - ((Scanner)Scanner).SetSource(str); - ((Scanner)Scanner).ParseResult = parseResult; - ResetState(); - - result = Parse(ctok); - str.Close(); - } - catch (Exception e) - { - var badFile = new Flag( - SeverityKind.Error, - default(Span), - Constants.BadFile.ToString(e.Message), - Constants.BadFile.Code, - parseResult.Program.Node.Name); - parseResult.AddFlag(badFile); - parseResult.Program.Node.GetNodeHash(); - return false; - } - - if (ctok.IsCancellationRequested) - { - var badFile = new Flag( - SeverityKind.Error, - default(Span), - Constants.OpCancelled.ToString(string.Format("Cancelled parsing of {0}", name.ToString(envParams))), - Constants.OpCancelled.Code, - parseResult.Program.Node.Name); - parseResult.AddFlag(badFile); - parseResult.Program.Node.GetNodeHash(); - return false; - } - - parseResult.Program.Node.GetNodeHash(); - return result; - } - - #region Helpers - private Span ToSpan(LexLocation loc) - { - return new Span(loc.StartLine, loc.StartColumn + 1, loc.EndLine, loc.EndColumn + 1, ((Scanner)this.Scanner).ParseResult.Name); - } - - private void ResetState() - { - currentModule = null; - parseResult.ClearFlags(); - /******* State for building terms ********/ - appStack.Clear(); - argStack.Clear(); - quoteStack.Clear(); - /*****************************************/ - - /******* State for building rules, contracts, and comprehensions ********/ - crntRule = null; - crntContract = null; - crntBody = null; - /*****************************************/ - - /******* State for building types and type declarations ********/ - crntTypeDeclName = null; - crntTypeDeclSpan = default(Span); - crntTypeDecl = null; - crntTypeTerm = null; - currentEnum = null; - /*****************************************/ - - /******* State for ModRefs, steps, and updates ********/ - crntModRef = null; - crntStep = null; - crntUpdate = null; - crntModRefState = ModRefState.None; - /*************************************/ - - /******* State for sentence configs ********/ - crntSentConf = null; - /*************************************/ - - IsBuildingNext = false; - IsBuildingUpdate = false; - IsBuildingCod = false; - } - - /***********************************************************/ - /**************** Parse *******************/ - /***********************************************************/ - private Rational ParseNumeric(string str, Span span = default(Span)) - { - Contract.Requires(!string.IsNullOrEmpty(str)); - Rational numVal; - if (!Rational.TryParseDecimal(str, out numVal)) - { - var dummy = new Cnst(span, Rational.Zero); - var flag = new Flag( - SeverityKind.Error, - span, - Constants.BadNumeric.ToString(str), - Constants.BadNumeric.Code, - parseResult.Program.Node.Name); - parseResult.AddFlag(flag); - return Rational.Zero; - } - - return numVal; - } - - private int ParseInt(string str, Span span = default(Span)) - { - Contract.Requires(!string.IsNullOrEmpty(str)); - int numVal; - if (!int.TryParse(str, out numVal)) - { - var dummy = new Cnst(span, Rational.Zero); - var flag = new Flag( - SeverityKind.Error, - span, - Constants.BadNumeric.ToString(str), - Constants.BadNumeric.Code, - parseResult.Program.Node.Name); - parseResult.AddFlag(flag); - return 0; - } - - return numVal; - } - - private Cnst GetString() - { - return new Cnst( - new Span(stringStart.StartLine, stringStart.StartCol, stringEnd.EndLine, stringEnd.EndCol, stringStart.Program), - stringBuffer.ToString()); - - } - - private Cnst ParseNumeric(string str, bool isFraction, Span span = default(Span)) - { - Contract.Requires(!string.IsNullOrEmpty(str)); - Rational numVal; - bool result; - if (isFraction) - { - result = Rational.TryParseFraction(str, out numVal); - } - else - { - result = Rational.TryParseDecimal(str, out numVal); - } - - Contract.Assert(result); - return new Cnst(span, numVal); - } - - private string GetStringValue() - { - return stringBuffer.ToString(); - } - #endregion - - #region Term and Constraint Building - private void StartString(Span span) - { - stringBuffer.Clear(); - stringStart = span; - } - - private void EndString(Span span) - { - stringEnd = span; - } - - private void AppendString(string s) - { - stringBuffer.Append(s); - } - - private void AppendSingleEscape(string s) - { - var c = s[1]; - switch (c) - { - case 'r': - stringBuffer.Append('\r'); - break; - case 'n': - stringBuffer.Append('\n'); - break; - case 't': - stringBuffer.Append('\t'); - break; - default: - stringBuffer.Append(c); - break; - } - } - - private void AppendMultiEscape(string s) - { - if (s == "\'\'\"\"") - { - stringBuffer.Append("\'\""); - } - else if (s == "\"\"\'\'") - { - stringBuffer.Append("\"\'"); - } - else - { - throw new NotImplementedException(); - } - } - - private void PushSymbol() - { - Contract.Requires(argStack.Count > 0); - - var funcName = argStack.Pop(); - - Contract.Assert(funcName.NodeKind == NodeKind.Id); - - appStack.Push(new FuncApplyInfo((Id)funcName)); - } - - private void PushSymbol(OpKind opcode, Span span) - { - appStack.Push(new FuncApplyInfo(opcode, span)); - } - - private void PushSymbol(RelKind opcode, Span span) - { - appStack.Push(new RelApplyInfo(opcode, span)); - } - - private void PushComprSymbol(Span span) - { - appStack.Push(new ComprApplyInfo(new Compr(span))); - } - - private void PushArg(Node n) - { - argStack.Push(n); - } - - private void IncArity() - { - if (appStack.Count == 0) - { - return; - } - - var peek = appStack.Peek(); - peek.IncArity(); - } - - private void AppendQuoteRun(string s, Span span) - { - Contract.Requires(quoteStack.Count > 0); - quoteStack.Peek().AddItem(new QuoteRun(span, s)); - } - - private void AppendQuoteEscape(string s, Span span) - { - Contract.Requires(quoteStack.Count > 0 && s.Length == 2); - quoteStack.Peek().AddItem(new QuoteRun(span, new string(new char[] { s[1] }))); - } - - private void AppendUnquote() - { - Contract.Requires(quoteStack.Count > 0); - Contract.Requires(argStack.Count > 0 && argStack.Peek().IsFuncOrAtom); - quoteStack.Peek().AddItem(argStack.Pop()); - } - - private void PushQuote(Span span) - { - quoteStack.Push(new Quote(span)); - } - - private void EndComprHeads() - { - Contract.Requires(appStack.Count > 0 && appStack.Peek() is ComprApplyInfo); - Contract.Requires(argStack.Count > 0); - - var comprInfo = (ComprApplyInfo)appStack.Peek(); - Contract.Assert(argStack.Count >= comprInfo.Arity); - for (int i = 0; i < comprInfo.Arity; ++i) - { - comprInfo.Comprehension.AddHead(argStack.Pop(), false); - } - } - - private Quote PopQuote() - { - Contract.Requires(quoteStack.Count > 0); - return quoteStack.Pop(); - } - - private Node MkTerm(int arity = -1) - { - Contract.Requires(appStack.Count > 0); - var funcInfo = appStack.Pop() as FuncApplyInfo; - arity = arity < 0 ? funcInfo.Arity : arity; - - Contract.Assert(funcInfo != null); - Contract.Assert(argStack.Count >= arity); - FuncTerm data; - - if (funcInfo.FuncName is OpKind) - { - data = new FuncTerm(funcInfo.Span, (OpKind)funcInfo.FuncName); - } - else - { - data = new FuncTerm(funcInfo.Span, (Id)funcInfo.FuncName); - } - - for (int i = 0; i < arity; ++i) - { - data.AddArg(argStack.Pop(), false); - } - - return data; - } - - private Compr MkCompr() - { - Contract.Requires(appStack.Count > 0 && appStack.Peek() is ComprApplyInfo); - return ((ComprApplyInfo)appStack.Pop()).Comprehension; - } - - private ModApply MkModApply() - { - Contract.Requires(appStack.Count > 0 && appStack.Peek() is ModApplyInfo); - var modInfo = (ModApplyInfo)appStack.Pop(); - var modApp = new ModApply(modInfo.Span, modInfo.ModRef); - for (int i = 0; i < modInfo.Arity; ++i) - { - modApp.AddArg(argStack.Pop(), false); - } - - return modApp; - } - #endregion - - #region Type Term and Declaration Building - private void StartEnum(Span span) - { - Contract.Requires(currentEnum == null); - currentEnum = new Nodes.Enum(span); - } - - private void AppendEnum(Node n) - { - Contract.Requires(currentEnum != null); - Contract.Requires(n != null); - currentEnum.AddElement(n); - } - - private void AppendUnion(Node n) - { - Contract.Requires(n != null); - if (crntTypeTerm == null) - { - crntTypeTerm = n; - } - else if (crntTypeTerm.NodeKind == NodeKind.Union) - { - ((Union)crntTypeTerm).AddComponent(n); - } - else - { - var unn = new Union(crntTypeTerm.Span); - unn.AddComponent(crntTypeTerm); - unn.AddComponent(n); - crntTypeTerm = unn; - } - } - - private void EndEnum() - { - Contract.Requires(currentEnum != null); - Contract.Ensures(currentEnum == null); - - if (crntTypeTerm == null) - { - crntTypeTerm = currentEnum; - } - else if (crntTypeTerm.NodeKind == NodeKind.Union) - { - ((Union)crntTypeTerm).AddComponent(currentEnum); - } - else - { - var unn = new Union(crntTypeTerm.Span); - unn.AddComponent(crntTypeTerm); - unn.AddComponent(currentEnum); - crntTypeTerm = unn; - } - - currentEnum = null; - } - - private void SaveTypeDeclName(string name, Span span) - { - crntTypeDeclName = name; - crntTypeDeclSpan = span; - } - - private void EndUnnDecl() - { - Contract.Requires(currentModule != null && currentModule.IsDomOrTrans); - var unnDecl = new UnnDecl(crntTypeDeclSpan, crntTypeDeclName, crntTypeTerm); - crntTypeTerm = null; - crntTypeDeclName = null; - crntTypeDeclSpan = default(Span); - - switch (currentModule.NodeKind) - { - case NodeKind.Domain: - ((Domain)currentModule).AddTypeDecl(unnDecl); - break; - case NodeKind.Transform: - ((Transform)currentModule).AddTypeDecl(unnDecl); - break; - default: - throw new NotImplementedException(); - } - - if (crntSentConf != null) - { - unnDecl.SetConfig(crntSentConf); - crntSentConf = null; - } - } - - private void StartConDecl(bool isNew, bool isSub) - { - Contract.Requires(currentModule != null && currentModule.IsDomOrTrans); - Contract.Requires(crntTypeDecl == null); - crntTypeDecl = new ConDecl(crntTypeDeclSpan, crntTypeDeclName, isNew, isSub); - if (crntSentConf != null) - { - ((ConDecl)crntTypeDecl).SetConfig(crntSentConf); - crntSentConf = null; - } - } - - private void StartMapDecl(MapKind kind) - { - Contract.Requires(currentModule != null && currentModule.IsDomOrTrans); - Contract.Requires(crntTypeDecl == null); - crntTypeDecl = new MapDecl(crntTypeDeclSpan, crntTypeDeclName, kind, true); - if (crntSentConf != null) - { - ((MapDecl)crntTypeDecl).SetConfig(crntSentConf); - crntSentConf = null; - } - } - - private void EndTypeDecl() - { - Contract.Requires(currentModule != null && currentModule.IsDomOrTrans); - Contract.Requires(crntTypeDecl != null); - switch (currentModule.NodeKind) - { - case NodeKind.Domain: - ((Domain)currentModule).AddTypeDecl(crntTypeDecl); - break; - case NodeKind.Transform: - ((Transform)currentModule).AddTypeDecl(crntTypeDecl); - break; - default: - throw new NotImplementedException(); - } - - IsBuildingCod = false; - crntTypeDecl = null; - } - - private void SaveMapPartiality(bool isPartial) - { - Contract.Requires(crntTypeDecl != null && crntTypeDecl.NodeKind == NodeKind.MapDecl); - ((MapDecl)crntTypeDecl).ChangePartiality(isPartial); - IsBuildingCod = true; - } - - private void SetModRefState(ModRefState state) - { - crntModRefState = state; - } - - private void AppendField(string name, bool isAny, Span span) - { - Contract.Requires(crntTypeDecl != null); - Contract.Requires(crntTypeTerm != null); - var fld = new Field(span, name, crntTypeTerm, isAny); - crntTypeTerm = null; - switch (crntTypeDecl.NodeKind) - { - case NodeKind.ConDecl: - ((ConDecl)crntTypeDecl).AddField(fld); - break; - case NodeKind.MapDecl: - if (IsBuildingCod) - { - ((MapDecl)crntTypeDecl).AddCodField(fld); - } - else - { - ((MapDecl)crntTypeDecl).AddDomField(fld); - } - break; - default: - throw new NotImplementedException(); - } - } - - private static ContractKind ToContractKind(string s) - { - switch (s) - { - case "some": - return ContractKind.RequiresSome; - case "atleast": - return ContractKind.RequiresAtLeast; - case "atmost": - return ContractKind.RequiresAtMost; - default: - throw new NotImplementedException(); - } - } - #endregion - - #region Rule, Contract, Step, and Update Building - private void AppendBody() - { - if (appStack.Count > 0 && appStack.Peek() is ComprApplyInfo) - { - var appInfo = (ComprApplyInfo)appStack.Peek(); - Contract.Assert(appInfo.CurrentBody != null); - appInfo.Comprehension.AddBody(appInfo.CurrentBody); - appInfo.CurrentBody = null; - } - else if (crntRule != null) - { - Contract.Assert(crntBody != null); - crntRule.AddBody(crntBody); - crntBody = null; - } - else if (crntContract != null) - { - Contract.Assert(crntBody != null); - crntContract.AddSpecification(crntBody); - crntBody = null; - } - } - - private void AppendConstraint(Node n) - { - Contract.Requires(n != null && n.IsConstraint); - if (appStack.Count > 0 && appStack.Peek() is ComprApplyInfo) - { - var cmprInfo = (ComprApplyInfo)appStack.Peek(); - if (cmprInfo.CurrentBody == null) - { - cmprInfo.CurrentBody = new Body(n.Span); - } - - cmprInfo.CurrentBody.AddConstr(n); - } - else - { - if (crntBody == null) - { - crntBody = new Body(n.Span); - } - - crntBody.AddConstr(n); - } - } - - private Find MkFind(bool isBound, Span span) - { - Contract.Requires(isBound ? argStack.Count > 1 : argStack.Count >= 1); - var match = argStack.Pop(); - var binding = isBound ? (Id)argStack.Pop() : null; - return new Find(span, binding, match); - } - - private ModelFact MkFact(bool isBound, Span span) - { - Contract.Requires(isBound ? argStack.Count > 1 : argStack.Count >= 1); - var match = argStack.Pop(); - var binding = isBound ? (Id)argStack.Pop() : null; - var mf = new ModelFact(span, binding, match); - if (crntSentConf != null) - { - mf.SetConfig(crntSentConf); - crntSentConf = null; - } - - return mf; - } - - private RelConstr MkRelConstr(bool isNo = false) - { - Contract.Requires(argStack.Count > 1 && appStack.Count > 0); - var app = appStack.Pop() as RelApplyInfo; - Contract.Assert(app != null); - var arg2 = argStack.Pop(); - var arg1 = argStack.Pop(); - return new RelConstr(app.Span, app.Opcode, arg1, arg2); - } - - private RelConstr MkNoConstr(Span span) - { - Contract.Requires(argStack.Count > 0); - return new RelConstr(span, RelKind.No, argStack.Pop()); - } - - private RelConstr MkNoConstr(Span span, bool hasBinding) - { - Contract.Requires(hasBinding ? argStack.Count > 1 : argStack.Count > 0); - var compr = new Compr(span); - var body = new Body(span); - Node arg; - Id binding; - if (hasBinding) - { - arg = argStack.Pop(); - binding = (Id)argStack.Pop(); - } - else - { - binding = null; - arg = argStack.Pop(); - } - - body.AddConstr(new Find(span, binding, arg)); - compr.AddBody(body); - compr.AddHead(new Id(span, ASTQueries.ASTSchema.Instance.ConstNameTrue)); - return new RelConstr(span, RelKind.No, compr); - } - - private void EndHeads(Span span) - { - Contract.Requires(argStack.Count > 0); - Contract.Requires(crntRule == null); - crntRule = new Nodes.Rule(span); - while (argStack.Count > 0) - { - crntRule.AddHead(argStack.Pop(), false); - } - - if (crntSentConf != null) - { - crntRule.SetConfig(crntSentConf); - crntSentConf = null; - } - } - - private void AppendRule() - { - Contract.Requires(currentModule != null && currentModule.IsDomOrTrans); - switch (currentModule.NodeKind) - { - case NodeKind.Domain: - ((Domain)currentModule).AddRule(crntRule); - break; - case NodeKind.Transform: - ((Transform)currentModule).AddRule(crntRule); - break; - default: - throw new NotImplementedException(); - } - - crntRule = null; - } - - private void StartPropContract(ContractKind kind, Span span) - { - Contract.Requires(currentModule != null); - Contract.Requires(currentModule.CanHaveContract(kind)); - Contract.Requires(kind != ContractKind.RequiresSome && kind != ContractKind.RequiresAtLeast && kind != ContractKind.RequiresAtMost); - - crntContract = new ContractItem(span, kind); - - switch (currentModule.NodeKind) - { - case NodeKind.Model: - ((Model)currentModule).AddContract(crntContract); - break; - case NodeKind.Transform: - ((Transform)currentModule).AddContract(crntContract); - break; - case NodeKind.Domain: - ((Domain)currentModule).AddConforms(crntContract); - break; - default: - throw new NotImplementedException(); - } - - if (crntSentConf != null) - { - crntContract.SetConfig(crntSentConf); - crntSentConf = null; - } - } - - private void AppendCardContract(string kind, int cardinality, Span span) - { - Contract.Requires(currentModule != null && currentModule.NodeKind == NodeKind.Model); - Contract.Requires(argStack.Count > 0 && argStack.Peek().NodeKind == NodeKind.Id); - - if (cardinality < 0) - { - var flag = new Flag( - SeverityKind.Error, - span, - Constants.BadNumeric.ToString(cardinality), - Constants.BadNumeric.Code, - parseResult.Program.Node.Name); - parseResult.AddFlag(flag); - cardinality = 0; - } - - var ci = new ContractItem(span, ToContractKind(kind)); - ci.AddSpecification(new CardPair(span, (Id)argStack.Pop(), cardinality)); - - switch (currentModule.NodeKind) - { - case NodeKind.Model: - ((Model)currentModule).AddContract(ci); - break; - default: - throw new NotImplementedException(); - } - - if (crntSentConf != null) - { - ci.SetConfig(crntSentConf); - crntSentConf = null; - } - } - - private void AppendProperty(string name, Span span) - { - Contract.Requires(currentModule.NodeKind == NodeKind.Machine); - Contract.Requires(argStack.Count > 0 && argStack.Peek().IsFuncOrAtom); - - var prop = new Property(span, name, argStack.Pop()); - ((Machine)currentModule).AddProperty(prop); - if (crntSentConf != null) - { - prop.SetConfig(crntSentConf); - crntSentConf = null; - } - } - - private void AppendFact(ModelFact p) - { - Contract.Requires(currentModule is Model); - ((Model)currentModule).AddFact(p); - } - - private void AppendUpdate() - { - Contract.Requires(crntUpdate != null); - Contract.Requires(currentModule != null && currentModule.NodeKind == NodeKind.Machine); - if (IsBuildingNext) - { - ((Machine)currentModule).AddUpdate(crntUpdate, false); - } - else - { - ((Machine)currentModule).AddUpdate(crntUpdate, true); - } - - crntUpdate = null; - } - - private void AppendStep() - { - Contract.Requires(currentModule != null); - Contract.Requires(argStack.Count > 0 && argStack.Peek().NodeKind == NodeKind.ModApply); - crntStep.SetRhs((ModApply)argStack.Pop()); - switch (currentModule.NodeKind) - { - case NodeKind.TSystem: - ((TSystem)currentModule).AddStep(crntStep); - break; - case NodeKind.Machine: - ((Machine)currentModule).AddBootStep(crntStep); - break; - default: - throw new NotImplementedException(); - } - - crntStep = null; - } - - private void AppendChoice() - { - Contract.Requires(crntUpdate != null); - Contract.Requires(argStack.Count > 0 && argStack.Peek().NodeKind == NodeKind.ModApply); - crntUpdate.AddChoice((ModApply)argStack.Pop()); - } - - private void AppendLHS() - { - Contract.Requires(argStack.Count > 0 && argStack.Peek().NodeKind == NodeKind.Id); - var id = (Id)argStack.Pop(); - - if (IsBuildingUpdate) - { - if (crntUpdate == null) - { - crntUpdate = new Update(id.Span); - if (crntSentConf != null) - { - crntUpdate.SetConfig(crntSentConf); - crntSentConf = null; - } - } - - crntUpdate.AddState(id); - } - else - { - if (crntStep == null) - { - crntStep = new Step(id.Span); - if (crntSentConf != null) - { - crntStep.SetConfig(crntSentConf); - crntSentConf = null; - } - } - - crntStep.AddLhs(id); - } - } - #endregion - - #region Module Building - private void SetCompose(ComposeKind kind) - { - Contract.Requires(currentModule != null); - Contract.Requires(currentModule.NodeKind == NodeKind.Model); - ((Model)currentModule).SetCompose(kind); - } - - private void AppendModRef(ModRef modRef) - { - Contract.Requires(currentModule != null); - Contract.Requires(modRef != null); - Contract.Requires(crntModRefState != ModRefState.None); - crntModRef = modRef; - switch (crntModRefState) - { - case ModRefState.Input: - switch (currentModule.NodeKind) - { - case NodeKind.Transform: - ((Transform)currentModule).AddInput(new Param(modRef.Span, null, modRef)); - break; - case NodeKind.TSystem: - ((TSystem)currentModule).AddInput(new Param(modRef.Span, null, modRef)); - break; - case NodeKind.Machine: - ((Machine)currentModule).AddInput(new Param(modRef.Span, null, modRef)); - break; - case NodeKind.Model: - ((Model)currentModule).AddCompose(modRef); - break; - default: - throw new NotImplementedException(); - } - break; - case ModRefState.Output: - switch (currentModule.NodeKind) - { - case NodeKind.Transform: - ((Transform)currentModule).AddOutput(new Param(modRef.Span, null, modRef)); - break; - case NodeKind.TSystem: - ((TSystem)currentModule).AddOutput(new Param(modRef.Span, null, modRef)); - break; - default: - throw new NotImplementedException(); - } - break; - case ModRefState.Other: - switch (currentModule.NodeKind) - { - case NodeKind.Domain: - ((Domain)currentModule).AddCompose(modRef); - break; - case NodeKind.Model: - ((Model)currentModule).SetDomain(modRef); - break; - case NodeKind.Machine: - ((Machine)currentModule).AddStateDomain(modRef); - break; - default: - throw new NotImplementedException(); - } - break; - case ModRefState.ModApply: - appStack.Push(new ModApplyInfo(modRef)); - break; - } - } - - private void AppendParam(string name, Span span) - { - Contract.Requires(currentModule != null); - Contract.Requires(crntTypeTerm != null); - Contract.Requires(crntModRefState == ModRefState.Input || crntModRefState == ModRefState.Output); - switch (crntModRefState) - { - case ModRefState.Input: - switch (currentModule.NodeKind) - { - case NodeKind.Transform: - ((Transform)currentModule).AddInput(new Param(span, name, crntTypeTerm)); - break; - case NodeKind.TSystem: - ((TSystem)currentModule).AddInput(new Param(span, name, crntTypeTerm)); - break; - case NodeKind.Machine: - ((Machine)currentModule).AddInput(new Param(span, name, crntTypeTerm)); - break; - default: - throw new NotImplementedException(); - } - break; - case ModRefState.Output: - switch (currentModule.NodeKind) - { - case NodeKind.Transform: - ((Transform)currentModule).AddOutput(new Param(span, name, crntTypeTerm)); - break; - case NodeKind.TSystem: - ((TSystem)currentModule).AddOutput(new Param(span, name, crntTypeTerm)); - break; - default: - throw new NotImplementedException(); - } - break; - default: - throw new NotImplementedException(); - } - - crntTypeTerm = null; - } - - private void StartDomain(string name, ComposeKind kind, Span span) - { - Contract.Requires(currentModule == null); - var dom = new Domain(span, name, kind); - parseResult.Program.Node.AddModule(dom); - currentModule = dom; - crntModRefState = ModRefState.Other; - } - - private void EndModule() - { - Contract.Requires(currentModule != null); - currentModule = null; - crntModRefState = ModRefState.None; - } - - private void StartTransform(string name, Span span) - { - Contract.Requires(currentModule == null); - var trans = new Transform(span, name); - parseResult.Program.Node.AddModule(trans); - crntModRefState = ModRefState.Input; - currentModule = trans; - } - - private void StartTSystem(string name, Span span) - { - Contract.Requires(currentModule == null); - var tsys = new TSystem(span, name); - parseResult.Program.Node.AddModule(tsys); - crntModRefState = ModRefState.Input; - currentModule = tsys; - } - - private void StartModel(string name, bool isPartial, Span span) - { - Contract.Requires(currentModule == null); - currentModule = new Model(span, name, isPartial); - parseResult.Program.Node.AddModule(currentModule); - crntModRefState = ModRefState.Other; - } - - private void StartMachine(string name, Span span) - { - Contract.Requires(currentModule == null); - var mach = new Machine(span, name); - parseResult.Program.Node.AddModule(mach); - currentModule = mach; - crntModRefState = ModRefState.Input; - } - #endregion - - #region Configs and Settings - private void StartSentenceConfig(Span span) - { - Contract.Requires(crntSentConf == null); - crntSentConf = new Config(span); - } - - private void AppendSetting() - { - Contract.Requires(argStack.Count >= 2 && argStack.Peek().NodeKind == NodeKind.Cnst); - var value = (Cnst)argStack.Pop(); - Contract.Assert(argStack.Peek().NodeKind == NodeKind.Id); - var setting = (Id)argStack.Pop(); - - if (currentModule == null) - { - Contract.Assert(crntSentConf == null); - parseResult.Program.Node.Config.AddSetting(new Setting(setting.Span, setting, value)); - return; - } - else if (crntSentConf != null) - { - crntSentConf.AddSetting(new Setting(setting.Span, setting, value)); - return; - } - - switch (currentModule.NodeKind) - { - case NodeKind.Model: - ((Model)currentModule).Config.AddSetting(new Setting(setting.Span, setting, value)); - break; - case NodeKind.Domain: - ((Domain)currentModule).Config.AddSetting(new Setting(setting.Span, setting, value)); - break; - case NodeKind.Transform: - ((Transform)currentModule).Config.AddSetting(new Setting(setting.Span, setting, value)); - break; - case NodeKind.TSystem: - ((TSystem)currentModule).Config.AddSetting(new Setting(setting.Span, setting, value)); - break; - case NodeKind.Machine: - ((Machine)currentModule).Config.AddSetting(new Setting(setting.Span, setting, value)); - break; - default: - throw new NotImplementedException(); - } - } - #endregion - - #region Apply Info classes - private abstract class ApplyInfo - { - public NodeKind AppKind - { - get; - private set; - } - - public Span Span - { - get; - private set; - } - - public abstract int Arity - { - get; - } - - public abstract void IncArity(); - - public ApplyInfo(NodeKind appKind, Span span) - { - AppKind = appKind; - Span = span; - } - } - - private class FuncApplyInfo : ApplyInfo - { - private int arity = 0; - - public override int Arity - { - get { return arity; } - } - - public object FuncName - { - get; - private set; - } - - public override void IncArity() - { - ++arity; - } - - public FuncApplyInfo(Id id) - : base(NodeKind.FuncTerm, id.Span) - { - FuncName = id; - } - - public FuncApplyInfo(OpKind kind, Span span) - : base(NodeKind.FuncTerm, span) - { - FuncName = kind; - } - } - - private class RelApplyInfo : ApplyInfo - { - public RelKind Opcode - { - get; - private set; - } - - public override int Arity - { - get { return 2; } - } - - public override void IncArity() - { - throw new InvalidOperationException(); - } - - public RelApplyInfo(RelKind opcode, Span span) - : base(NodeKind.RelConstr, span) - { - Opcode = opcode; - } - } - - private class ComprApplyInfo : ApplyInfo - { - private int arity = 0; - - public override int Arity - { - get { return arity; } - } - - public Compr Comprehension - { - get; - private set; - } - - public Body CurrentBody - { - get; - set; - } - - public override void IncArity() - { - ++arity; - } - - public ComprApplyInfo(Compr compr) - : base(NodeKind.Compr, compr.Span) - { - Comprehension = compr; - } - } - - private class ModApplyInfo : ApplyInfo - { - private int arity = 0; - - public override int Arity - { - get { return arity; } - } - - public override void IncArity() - { - ++arity; - } - - public ModRef ModRef - { - get; - private set; - } - - public ModApplyInfo(ModRef modRef) - : base(NodeKind.ModApply, modRef.Span) - { - ModRef = modRef; - } - } - - #endregion - } -} diff --git a/Src/Core/API/Parser/lexer.g.cs b/Src/Core/API/Parser/lexer.g.cs deleted file mode 100644 index b84b289..0000000 --- a/Src/Core/API/Parser/lexer.g.cs +++ /dev/null @@ -1,1833 +0,0 @@ -// -// This CSharp output file generated by Gardens Point LEX -// Version: 1.2.1b -// Machine: DESKTOP-KOAEGEQ -// DateTime: 10/2/2019 3:16:04 PM -// UserName: daniel -// GPLEX input file -// GPLEX frame file -// -// Option settings: unicode, parser, minimize -// Option settings: classes, compressMap, compressNext, persistBuffer, embedbuffers -// Fallback code page: Target machine default -// - -// -// Revised backup code -// Version 1.2.1 of 24-June-2013 -// -// -#define BACKUP -#define BABEL -#define PERSIST - -using System; -using System.IO; -using System.Text; -using System.Globalization; -using System.Collections.Generic; -using System.Runtime.Serialization; -using System.Diagnostics.CodeAnalysis; - - -namespace Microsoft.Formula.API -{ - /// - /// Summary Canonical example of GPLEX automaton - /// - -#if STANDALONE - // - // These are the dummy declarations for stand-alone GPLEX applications - // normally these declarations would come from the parser. - // If you declare /noparser, or %option noparser then you get this. - // - - internal enum Tokens - { - EOF = 0, maxParseToken = int.MaxValue - // must have at least these two, values are almost arbitrary - } - - internal abstract class ScanBase - { - [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "yylex")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "yylex")] - public abstract int yylex(); - - [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "yywrap")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "yywrap")] - protected virtual bool yywrap() { return true; } - -#if BABEL - protected abstract int CurrentSc { get; set; } - // EolState is the 32-bit of state data persisted at - // the end of each line for Visual Studio colorization. - // The default is to return CurrentSc. You must override - // this if you want more complicated behavior. - public virtual int EolState { - get { return CurrentSc; } - set { CurrentSc = value; } - } - } - - internal interface IColorScan - { - void SetSource(string source, int offset); - int GetNext(ref int state, out int start, out int end); -#endif // BABEL - } - -#endif // STANDALONE - - // If the compiler can't find the scanner base class maybe you - // need to run GPPG with the /gplex option, or GPLEX with /noparser -#if BABEL - internal sealed partial class Scanner : ScanBase, IColorScan - { - private ScanBuff buffer; - int currentScOrd; // start condition ordinal - - protected override int CurrentSc - { - // The current start state is a property - // to try to avoid the user error of setting - // scState but forgetting to update the FSA - // start state "currentStart" - // - get { return currentScOrd; } // i.e. return YY_START; - set { currentScOrd = value; // i.e. BEGIN(value); - currentStart = startState[value]; } - } -#else // BABEL - internal sealed partial class Scanner : ScanBase - { - private ScanBuff buffer; - int currentScOrd; // start condition ordinal -#endif // BABEL - - /// - /// The input buffer for this scanner. - /// - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - public ScanBuff Buffer { get { return buffer; } } - - private static int GetMaxParseToken() { - System.Reflection.FieldInfo f = typeof(Tokens).GetField("maxParseToken"); - return (f == null ? int.MaxValue : (int)f.GetValue(null)); - } - - static int parserMax = GetMaxParseToken(); - - enum Result {accept, noMatch, contextFound}; - - const int maxAccept = 73; - const int initial = 74; - const int eofNum = 0; - const int goStart = -1; - const int INITIAL = 0; - const int COMMENT = 1; - const int QUOTE = 2; - const int STRING_SINGLE = 3; - const int STRING_MULTI = 4; - const int UNQUOTE = 5; - -#region user code -private Dictionary keywords = null; - - internal int QuotingDepth - { - get; - set; - } - - internal ParseResult ParseResult - { - get; - set; - } - - override public void yyerror(string message, params object[] args) - { - if (ParseResult == null) - { - throw new Exception("Bad scanner state"); - } - - var errFlag = new Flag( - SeverityKind.Error, - new Span(yylloc.StartLine, yylloc.StartColumn, yylloc.EndLine, yylloc.StartColumn + yyleng, ParseResult.Name), - Constants.BadSyntax.ToString(string.Format(message, args)), - Constants.BadSyntax.Code, - ParseResult.Program.Node.Name); - - ParseResult.AddFlag(errFlag); - } - - private void MkKeywords() - { - if (keywords != null) - { - return; - } - - keywords = new Dictionary(28); - - keywords.Add("domain", (int)Tokens.DOMAIN); - keywords.Add("model", (int)Tokens.MODEL); - keywords.Add("transform", (int)Tokens.TRANSFORM); - keywords.Add("system", (int)Tokens.SYSTEM); - - keywords.Add("includes", (int)Tokens.INCLUDES); - keywords.Add("extends", (int)Tokens.EXTENDS); - keywords.Add("of", (int)Tokens.OF); - keywords.Add("returns", (int)Tokens.RETURNS); - keywords.Add("at", (int)Tokens.AT); - keywords.Add("machine", (int)Tokens.MACHINE); - - keywords.Add("is", (int)Tokens.IS); - keywords.Add("no", (int)Tokens.NO); - - keywords.Add("new", (int)Tokens.NEW); - keywords.Add("fun", (int)Tokens.FUN); - keywords.Add("inj", (int)Tokens.INJ); - keywords.Add("bij", (int)Tokens.BIJ); - keywords.Add("sur", (int)Tokens.SUR); - keywords.Add("any", (int)Tokens.ANY); - keywords.Add("sub", (int)Tokens.SUB); - - keywords.Add("ensures", (int)Tokens.ENSURES); - keywords.Add("requires", (int)Tokens.REQUIRES); - keywords.Add("conforms", (int)Tokens.CONFORMS); - keywords.Add("some", (int)Tokens.SOME); - keywords.Add("atleast", (int)Tokens.ATLEAST); - keywords.Add("atmost", (int)Tokens.ATMOST); - keywords.Add("partial", (int)Tokens.PARTIAL); - keywords.Add("initially", (int)Tokens.INITIALLY); - keywords.Add("next", (int)Tokens.NEXT); - keywords.Add("property", (int)Tokens.PROPERTY); - keywords.Add("boot", (int)Tokens.BOOT); - } - - int GetIdToken(string txt) - { - MkKeywords(); - - int tokId; - if (keywords.TryGetValue(txt, out tokId)) - { - return tokId; - } - - if (txt.Contains(".")) - { - if (!txt.EndsWith(".")) - { - return (int)Tokens.QUALID; - } - else - { - return (int)Tokens.LEX_ERROR; - } - } - else - { - return (int)Tokens.BAREID; - } - } - - internal void LoadYylval() - { - // Trigger lazy evaluation of yytext - int dummy = yytext.Length; - - yylval.str = tokTxt; - yylloc = new QUT.Gppg.LexLocation(tokLin, tokCol, tokELin, tokECol); - } -#endregion user code - - int state; - int currentStart = startState[0]; - int code; // last code read - int cCol; // column number of code - int lNum; // current line number - // - // The following instance variables are used, among other - // things, for constructing the yylloc location objects. - // - int tokPos; // buffer position at start of token - int tokCol; // zero-based column number at start of token - int tokLin; // line number at start of token - int tokEPos; // buffer position at end of token - int tokECol; // column number at end of token - int tokELin; // line number at end of token - string tokTxt; // lazily constructed text of token -#if STACK - private Stack scStack = new Stack(); -#endif // STACK - -#region ScannerTables - struct Table { - public int min; public int rng; public int dflt; - public sbyte[] nxt; - public Table(int m, int x, int d, sbyte[] n) { - min = m; rng = x; dflt = d; nxt = n; - } - }; - - static int[] startState = new int[] {74, 48, 52, 59, 65, 89, - 0}; - -#region CompressedCharacterMap - // - // There are 32 equivalence classes - // There are 2 character sequence regions - // There are 1 tables, 181 entries - // There are 1 runs, 0 singletons - // Decision tree depth is 1 - // - static sbyte[] mapC0 = new sbyte[181] { -/* '\0' */ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0, 30, 30, 0, 30, 30, -/* '\x10' */ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, -/* '\x20' */ 30, 20, 27, 8, 28, 11, 30, 7, 25, 26, 3, 12, 18, 17, 4, 1, -/* '0' */ 13, 6, 6, 6, 6, 6, 6, 6, 6, 6, 15, 19, 21, 16, 22, 30, -/* '@' */ 30, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, -/* 'P' */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 9, 2, 10, 31, 5, -/* '`' */ 29, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, -/* 'p' */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 23, 14, 24, 31, 30, -/* '\x80' */ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, -/* '\x90' */ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, -/* '\xA0' */ 30, 30, 30, 30, 30, 30, 30, 31, 30, 30, 30, 30, 30, 30, 30, 30, -/* '\xB0' */ 30, 30, 30, 30, 31 }; - - static sbyte MapC(int code) - { // '\0' <= code <= '\U0010FFFF' - if (code < 181) // '\0' <= code <= '\xB4' - return mapC0[code - 0]; - else // '\xB5' <= code <= '\U0010FFFF' - return (sbyte)30; - } -#endregion - - static Table[] NxS = new Table[90] { -/* NxS[ 0] */ new Table(0, 0, 0, null), -/* NxS[ 1] */ new Table(1, 3, -1, new sbyte[] {45, -1, 46}), -/* NxS[ 2] */ new Table(0, 0, -1, null), -/* NxS[ 3] */ new Table(0, 0, -1, null), -/* NxS[ 4] */ new Table(4, 1, -1, new sbyte[] {44}), -/* NxS[ 5] */ new Table(4, 10, -1, new sbyte[] {81, 5, 5, 43, -1, -1, - -1, -1, -1, 5}), -/* NxS[ 6] */ new Table(1, 13, -1, new sbyte[] {78, -1, -1, 79, -1, 6, - -1, -1, -1, -1, -1, -1, 6}), -/* NxS[ 7] */ new Table(27, 1, -1, new sbyte[] {40}), -/* NxS[ 8] */ new Table(5, 1, -1, new sbyte[] {37}), -/* NxS[ 9] */ new Table(0, 0, -1, null), -/* NxS[ 10] */ new Table(0, 0, -1, null), -/* NxS[ 11] */ new Table(5, 1, -1, new sbyte[] {35}), -/* NxS[ 12] */ new Table(6, 8, -1, new sbyte[] {6, -1, -1, -1, -1, -1, - -1, 6}), -/* NxS[ 13] */ new Table(0, 0, -1, null), -/* NxS[ 14] */ new Table(15, 3, -1, new sbyte[] {32, -1, 33}), -/* NxS[ 15] */ new Table(22, 1, -1, new sbyte[] {31}), -/* NxS[ 16] */ new Table(6, 17, -1, new sbyte[] {6, -1, -1, -1, -1, -1, - -1, 6, -1, -1, -1, -1, -1, -1, -1, -1, 30}), -/* NxS[ 17] */ new Table(0, 0, -1, null), -/* NxS[ 18] */ new Table(0, 0, -1, null), -/* NxS[ 19] */ new Table(16, 1, -1, new sbyte[] {28}), -/* NxS[ 20] */ new Table(16, 1, -1, new sbyte[] {27}), -/* NxS[ 21] */ new Table(0, 0, -1, null), -/* NxS[ 22] */ new Table(0, 0, -1, null), -/* NxS[ 23] */ new Table(0, 0, -1, null), -/* NxS[ 24] */ new Table(0, 0, -1, null), -/* NxS[ 25] */ new Table(0, 0, -1, null), -/* NxS[ 26] */ new Table(0, 0, -1, null), -/* NxS[ 27] */ new Table(0, 0, -1, null), -/* NxS[ 28] */ new Table(0, 0, -1, null), -/* NxS[ 29] */ new Table(0, 0, -1, null), -/* NxS[ 30] */ new Table(0, 0, -1, null), -/* NxS[ 31] */ new Table(0, 0, -1, null), -/* NxS[ 32] */ new Table(16, 1, -1, new sbyte[] {34}), -/* NxS[ 33] */ new Table(0, 0, -1, null), -/* NxS[ 34] */ new Table(0, 0, -1, null), -/* NxS[ 35] */ new Table(4, 10, -1, new sbyte[] {83, 35, 35, 36, -1, -1, - -1, -1, -1, 35}), -/* NxS[ 36] */ new Table(4, 4, -1, new sbyte[] {83, -1, -1, 36}), -/* NxS[ 37] */ new Table(5, 9, -1, new sbyte[] {37, 37, 38, -1, 76, -1, - -1, -1, 37}), -/* NxS[ 38] */ new Table(7, 3, -1, new sbyte[] {38, -1, 76}), -/* NxS[ 39] */ new Table(0, 0, -1, null), -/* NxS[ 40] */ new Table(0, 0, -1, null), -/* NxS[ 41] */ new Table(6, 8, -1, new sbyte[] {41, -1, -1, -1, -1, -1, - -1, 41}), -/* NxS[ 42] */ new Table(6, 8, -1, new sbyte[] {42, -1, -1, -1, -1, -1, - -1, 42}), -/* NxS[ 43] */ new Table(4, 4, -1, new sbyte[] {81, -1, -1, 43}), -/* NxS[ 44] */ new Table(0, 0, -1, null), -/* NxS[ 45] */ new Table(0, 1, 45, new sbyte[] {47}), -/* NxS[ 46] */ new Table(0, 0, -1, null), -/* NxS[ 47] */ new Table(0, 0, -1, null), -/* NxS[ 48] */ new Table(0, 5, -1, new sbyte[] {49, -1, -1, 84, 50}), -/* NxS[ 49] */ new Table(0, 0, -1, null), -/* NxS[ 50] */ new Table(0, 5, -1, new sbyte[] {49, -1, -1, -1, 50}), -/* NxS[ 51] */ new Table(0, 0, -1, null), -/* NxS[ 52] */ new Table(28, 5, 54, new sbyte[] {55, 56, 54, 54, 53}), -/* NxS[ 53] */ new Table(0, 0, -1, null), -/* NxS[ 54] */ new Table(28, 5, 54, new sbyte[] {-1, -1, 54, 54, 53}), -/* NxS[ 55] */ new Table(28, 1, -1, new sbyte[] {58}), -/* NxS[ 56] */ new Table(29, 1, -1, new sbyte[] {57}), -/* NxS[ 57] */ new Table(0, 0, -1, null), -/* NxS[ 58] */ new Table(0, 0, -1, null), -/* NxS[ 59] */ new Table(27, 8, 61, new sbyte[] {63, 61, 61, 61, 61, 60, - 61, 62}), -/* NxS[ 60] */ new Table(0, 0, -1, null), -/* NxS[ 61] */ new Table(27, 8, 61, new sbyte[] {-1, 61, 61, 61, 61, -1, - 61, -1}), -/* NxS[ 62] */ new Table(0, 1, 64, new sbyte[] {-1}), -/* NxS[ 63] */ new Table(0, 0, -1, null), -/* NxS[ 64] */ new Table(0, 0, -1, null), -/* NxS[ 65] */ new Table(27, 13, 67, new sbyte[] {69, 67, 67, 67, 67, 66, - 67, 67, 67, 67, 67, 67, 68}), -/* NxS[ 66] */ new Table(0, 0, -1, null), -/* NxS[ 67] */ new Table(27, 13, 67, new sbyte[] {-1, 67, 67, 67, 67, 66, - 67, 67, 67, 67, 67, 67, -1}), -/* NxS[ 68] */ new Table(7, 1, -1, new sbyte[] {87}), -/* NxS[ 69] */ new Table(27, 13, -1, new sbyte[] {85, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 70}), -/* NxS[ 70] */ new Table(0, 0, -1, null), -/* NxS[ 71] */ new Table(0, 0, -1, null), -/* NxS[ 72] */ new Table(0, 0, -1, null), -/* NxS[ 73] */ new Table(0, 0, -1, null), -/* NxS[ 74] */ new Table(1, 31, -1, new sbyte[] {1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 6, 13, 14, 15, 16, 17, 18, 75, 19, 20, - 21, 22, 23, 24, 25, 2, 26, -1, 2}), -/* NxS[ 75] */ new Table(16, 1, -1, new sbyte[] {29}), -/* NxS[ 76] */ new Table(6, 8, -1, new sbyte[] {77, -1, -1, -1, -1, -1, - -1, 77}), -/* NxS[ 77] */ new Table(6, 8, -1, new sbyte[] {77, -1, -1, -1, 39, -1, - -1, 77}), -/* NxS[ 78] */ new Table(6, 12, -1, new sbyte[] {42, -1, -1, -1, -1, -1, - 80, 80, -1, -1, -1, 80}), -/* NxS[ 79] */ new Table(6, 8, -1, new sbyte[] {41, -1, -1, -1, -1, -1, - -1, 41}), -/* NxS[ 80] */ new Table(6, 8, -1, new sbyte[] {42, -1, -1, -1, -1, -1, - -1, 80}), -/* NxS[ 81] */ new Table(5, 7, -1, new sbyte[] {5, -1, -1, 82, -1, -1, - 83}), -/* NxS[ 82] */ new Table(5, 1, -1, new sbyte[] {37}), -/* NxS[ 83] */ new Table(5, 1, -1, new sbyte[] {35}), -/* NxS[ 84] */ new Table(1, 1, -1, new sbyte[] {51}), -/* NxS[ 85] */ new Table(7, 1, -1, new sbyte[] {86}), -/* NxS[ 86] */ new Table(7, 1, -1, new sbyte[] {71}), -/* NxS[ 87] */ new Table(27, 1, -1, new sbyte[] {88}), -/* NxS[ 88] */ new Table(27, 1, -1, new sbyte[] {72}), -/* NxS[ 89] */ new Table(1, 31, -1, new sbyte[] {1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 6, 13, 14, 15, 16, 17, 18, 75, 19, 20, - 21, 22, 23, 24, 25, 73, 26, -1, 2}), - }; - -int NextState() { - if (code == ScanBuff.EndOfFile) - return eofNum; - else - unchecked { - int rslt; - int idx = MapC(code) - NxS[state].min; - if (idx < 0) idx += 32; - if ((uint)idx >= (uint)NxS[state].rng) rslt = NxS[state].dflt; - else rslt = NxS[state].nxt[idx]; - return rslt; - } -} - -#endregion - - -#if BACKUP - // ============================================================== - // == Nested struct used for backup in automata that do backup == - // ============================================================== - - struct Context // class used for automaton backup. - { - public int bPos; - public int rPos; // scanner.readPos saved value - public int cCol; - public int lNum; // Need this in case of backup over EOL. - public int state; - public int cChr; - } - - private Context ctx = new Context(); -#endif // BACKUP - - // ============================================================== - // ==== Nested struct to support input switching in scanners ==== - // ============================================================== - - struct BufferContext { - internal ScanBuff buffSv; - internal int chrSv; - internal int cColSv; - internal int lNumSv; - } - - // ============================================================== - // ===== Private methods to save and restore buffer contexts ==== - // ============================================================== - - /// - /// This method creates a buffer context record from - /// the current buffer object, together with some - /// scanner state values. - /// - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - BufferContext MkBuffCtx() - { - BufferContext rslt; - rslt.buffSv = this.buffer; - rslt.chrSv = this.code; - rslt.cColSv = this.cCol; - rslt.lNumSv = this.lNum; - return rslt; - } - - /// - /// This method restores the buffer value and allied - /// scanner state from the given context record value. - /// - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - void RestoreBuffCtx(BufferContext value) - { - this.buffer = value.buffSv; - this.code = value.chrSv; - this.cCol = value.cColSv; - this.lNum = value.lNumSv; - } - // =================== End Nested classes ======================= - -#if !NOFILES - internal Scanner(Stream file) { - SetSource(file, 0); // unicode option - } - - public Scanner(Stream file, string codepage) { - SetSource(file, CodePageHandling.GetCodePage(codepage)); - } -#endif // !NOFILES - - internal Scanner() { } - - private int readPos; - - void GetCode() - { - if (code == '\n') // This needs to be fixed for other conventions - // i.e. [\r\n\205\u2028\u2029] - { - cCol = -1; - lNum++; - } - readPos = buffer.Pos; - - // Now read new codepoint. - code = buffer.Read(); - if (code > ScanBuff.EndOfFile) - { -#if (!BYTEMODE) - if (code >= 0xD800 && code <= 0xDBFF) - { - int next = buffer.Read(); - if (next < 0xDC00 || next > 0xDFFF) - code = ScanBuff.UnicodeReplacementChar; - else - code = (0x10000 + ((code & 0x3FF) << 10) + (next & 0x3FF)); - } -#endif - cCol++; - } - } - - void MarkToken() - { -#if (!PERSIST) - buffer.Mark(); -#endif - tokPos = readPos; - tokLin = lNum; - tokCol = cCol; - } - - void MarkEnd() - { - tokTxt = null; - tokEPos = readPos; - tokELin = lNum; - tokECol = cCol; - } - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - int Peek() - { - int rslt, codeSv = code, cColSv = cCol, lNumSv = lNum, bPosSv = buffer.Pos; - GetCode(); rslt = code; - lNum = lNumSv; cCol = cColSv; code = codeSv; buffer.Pos = bPosSv; - return rslt; - } - - // ============================================================== - // ===== Initialization of string-based input buffers ==== - // ============================================================== - - /// - /// Create and initialize a StringBuff buffer object for this scanner - /// - /// the input string - /// starting offset in the string - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - public void SetSource(string source, int offset) - { - this.buffer = ScanBuff.GetBuffer(source); - this.buffer.Pos = offset; - this.lNum = 0; - this.code = '\n'; // to initialize yyline, yycol and lineStart - GetCode(); - } - - // ================ LineBuffer Initialization =================== - /// - /// Create and initialize a LineBuff buffer object for this scanner - /// - /// the list of input strings - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - public void SetSource(IList source) - { - this.buffer = ScanBuff.GetBuffer(source); - this.code = '\n'; // to initialize yyline, yycol and lineStart - this.lNum = 0; - GetCode(); - } - -#if !NOFILES - // =============== StreamBuffer Initialization ================== - - /// - /// Create and initialize a StreamBuff buffer object for this scanner. - /// StreamBuff is buffer for 8-bit byte files. - /// - /// the input byte stream - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - public void SetSource(Stream source) - { - this.buffer = ScanBuff.GetBuffer(source); - this.lNum = 0; - this.code = '\n'; // to initialize yyline, yycol and lineStart - GetCode(); - } - -#if !BYTEMODE - // ================ TextBuffer Initialization =================== - - /// - /// Create and initialize a TextBuff buffer object for this scanner. - /// TextBuff is a buffer for encoded unicode files. - /// - /// the input text file - /// Code page to use if file has - /// no BOM. For 0, use machine default; for -1, 8-bit binary - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - public void SetSource(Stream source, int fallbackCodePage) - { - this.buffer = ScanBuff.GetBuffer(source, fallbackCodePage); - this.lNum = 0; - this.code = '\n'; // to initialize yyline, yycol and lineStart - GetCode(); - } -#endif // !BYTEMODE -#endif // !NOFILES - - // ============================================================== - -#if BABEL - // - // Get the next token for Visual Studio - // - // "state" is the inout mode variable that maintains scanner - // state between calls, using the EolState property. In principle, - // if the calls of EolState are costly set could be called once - // only per line, at the start; and get called only at the end - // of the line. This needs more infrastructure ... - // - public int GetNext(ref int state, out int start, out int end) - { - Tokens next; - int s, e; - s = state; // state at start - EolState = state; - next = (Tokens)Scan(); - state = EolState; - e = state; // state at end; - start = tokPos; - end = tokEPos - 1; // end is the index of last char. - return (int)next; - } -#endif // BABEL - - // ======== AbstractScanner<> Implementation ========= - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "yylex")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "yylex")] - public override int yylex() - { - // parserMax is set by reflecting on the Tokens - // enumeration. If maxParseToken is defined - // that is used, otherwise int.MaxValue is used. - int next; - do { next = Scan(); } while (next >= parserMax); - return next; - } - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - int yypos { get { return tokPos; } } - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - int yyline { get { return tokLin; } } - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - int yycol { get { return tokCol; } } - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "yytext")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "yytext")] - public string yytext - { - get - { - if (tokTxt == null) - tokTxt = buffer.GetString(tokPos, tokEPos); - return tokTxt; - } - } - - /// - /// Discards all but the first "n" codepoints in the recognized pattern. - /// Resets the buffer position so that only n codepoints have been consumed; - /// yytext is also re-evaluated. - /// - /// The number of codepoints to consume - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - void yyless(int n) - { - buffer.Pos = tokPos; - // Must read at least one char, so set before start. - cCol = tokCol - 1; - GetCode(); - // Now ensure that line counting is correct. - lNum = tokLin; - // And count the rest of the text. - for (int i = 0; i < n; i++) GetCode(); - MarkEnd(); - } - - // - // It would be nice to count backward in the text - // but it does not seem possible to re-establish - // the correct column counts except by going forward. - // - /// - /// Removes the last "n" code points from the pattern. - /// - /// The number to remove - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - void _yytrunc(int n) { yyless(yyleng - n); } - - // - // This is painful, but we no longer count - // codepoints. For the overwhelming majority - // of cases the single line code is fast, for - // the others, well, at least it is all in the - // buffer so no files are touched. Note that we - // can't use (tokEPos - tokPos) because of the - // possibility of surrogate pairs in the token. - // - /// - /// The length of the pattern in codepoints (not the same as - /// string-length if the pattern contains any surrogate pairs). - /// - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "yyleng")] - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "yyleng")] - public int yyleng - { - get { - if (tokELin == tokLin) - return tokECol - tokCol; - else -#if BYTEMODE - return tokEPos - tokPos; -#else - { - int ch; - int count = 0; - int save = buffer.Pos; - buffer.Pos = tokPos; - do { - ch = buffer.Read(); - if (!char.IsHighSurrogate((char)ch)) count++; - } while (buffer.Pos < tokEPos && ch != ScanBuff.EndOfFile); - buffer.Pos = save; - return count; - } -#endif // BYTEMODE - } - } - - // ============ methods available in actions ============== - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal int YY_START { - get { return currentScOrd; } - set { currentScOrd = value; - currentStart = startState[value]; - } - } - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal void BEGIN(int next) { - currentScOrd = next; - currentStart = startState[next]; - } - - // ============== The main tokenizer code ================= - - int Scan() { - try { - for (; ; ) { - int next; // next state to enter - bool contextSaved = false; -#if LEFTANCHORS - for (;;) { - // Discard characters that do not start any pattern. - // Must check the left anchor condition after *every* GetCode! - state = ((cCol == 0) ? anchorState[currentScOrd] : currentStart); - if ((next = NextState()) != goStart) break; // LOOP EXIT HERE... - GetCode(); - } - -#else // !LEFTANCHORS - state = currentStart; - while ((next = NextState()) == goStart) { - // At this point, the current character has no - // transition from the current state. We discard - // the "no-match" char. In traditional LEX such - // characters are echoed to the console. - GetCode(); - } -#endif // LEFTANCHORS - // At last, a valid transition ... - MarkToken(); - state = next; - GetCode(); -#if BACKUP - while ((next = NextState()) > eofNum) { // Exit for goStart AND for eofNum - if (state <= maxAccept && next > maxAccept) { // need to prepare backup data - // Store data for the *latest* accept state that was found. - SaveStateAndPos( ref ctx ); - contextSaved = true; - } - state = next; - GetCode(); - } - if (state > maxAccept && contextSaved) - RestoreStateAndPos( ref ctx ); -#else // BACKUP - while ((next = NextState()) > eofNum) { // Exit for goStart AND for eofNum - state = next; - GetCode(); - } -#endif // BACKUP - if (state <= maxAccept) { - MarkEnd(); -#region ActionSwitch -#pragma warning disable 162, 1522 - switch (state) - { - case eofNum: - switch (currentStart) { - case 59: -return (int)Tokens.RUNAWAYSTRING; - break; - case 65: -return (int)Tokens.RUNAWAYSTRING; - break; - } - if (yywrap()) - return (int)Tokens.EOF; - break; - case 1: -return (int)Tokens.DIV; - break; - case 2: - case 7: - case 8: -return (int)Tokens.ALIENCHAR; - break; - case 3: -return (int)Tokens.MUL; - break; - case 4: -return (int)Tokens.DOT; - break; - case 5: - case 35: - case 36: - case 37: - case 38: - case 39: - case 43: -return GetIdToken(yytext); - break; - case 6: -return (int)Tokens.DIGITS; - break; - case 9: -return (int)Tokens.LSBRACE; - break; - case 10: -return (int)Tokens.RSBRACE; - break; - case 11: -return (int)Tokens.MOD; - break; - case 12: -return (int)Tokens.PLUS; - break; - case 13: -return (int)Tokens.PIPE; - break; - case 14: -return (int)Tokens.COLON; - break; - case 15: -return (int)Tokens.EQ; - break; - case 16: -return (int)Tokens.MINUS; - break; - case 17: -return (int)Tokens.COMMA; - break; - case 18: -return (int)Tokens.SEMICOLON; - break; - case 19: -return (int)Tokens.LT; - break; - case 20: -return (int)Tokens.GT; - break; - case 21: -return (int)Tokens.LCBRACE; - break; - case 22: -return (int)Tokens.RCBRACE; - break; - case 23: -return (int)Tokens.LPAREN; - break; - case 24: -return (int)Tokens.RPAREN; - break; - case 25: -BEGIN(STRING_SINGLE); return (int)Tokens.STRSNGSTART; - break; - case 26: -++QuotingDepth; BEGIN(QUOTE); return (int)Tokens.QSTART; - break; - case 27: -return (int)Tokens.GE; - break; - case 28: -return (int)Tokens.LE; - break; - case 29: -return (int)Tokens.NE; - break; - case 30: -return (int)Tokens.WEAKARROW; - break; - case 31: -return (int)Tokens.STRONGARROW; - break; - case 32: -return (int)Tokens.RENAMES; - break; - case 33: -return (int)Tokens.RULE; - break; - case 34: -return (int)Tokens.TYPEDEF; - break; - case 40: -BEGIN(STRING_MULTI); return (int)Tokens.STRMULSTART; - break; - case 41: -return (int)Tokens.REAL; - break; - case 42: -return (int)Tokens.FRAC; - break; - case 44: -return (int)Tokens.RANGE; - break; - case 45: -return (int)Tokens.LEX_COMMENT; - break; - case 46: -BEGIN(COMMENT); return (int)Tokens.LEX_COMMENT; - break; - case 47: -return (int)Tokens.LEX_COMMENT; - break; - case 48: - case 50: -return (int)Tokens.LEX_COMMENT; - break; - case 49: -return (int)Tokens.LEX_COMMENT; - break; - case 51: -if (QuotingDepth == 0) BEGIN(INITIAL); else BEGIN(UNQUOTE); return (int)Tokens.LEX_COMMENT; - break; - case 52: - case 54: -return (int)Tokens.QUOTERUN; - break; - case 53: -return (int)Tokens.QUOTERUN; - break; - case 55: -BEGIN(UNQUOTE); return (int)Tokens.UQSTART; - break; - case 56: ---QuotingDepth; if (QuotingDepth == 0) BEGIN(INITIAL); else BEGIN(UNQUOTE); return (int)Tokens.QEND; - break; - case 57: -return (int)Tokens.QUOTEESCAPE; - break; - case 58: -return (int)Tokens.QUOTEESCAPE; - break; - case 59: - case 61: -return (int)Tokens.STRSNG; - break; - case 60: - case 62: -return (int)Tokens.RUNAWAYSTRING; - break; - case 63: -if (QuotingDepth == 0) BEGIN(INITIAL); else BEGIN(UNQUOTE); return (int)Tokens.STRSNGEND; - break; - case 64: -return (int)Tokens.STRSNGESC; - break; - case 65: - case 67: -return (int)Tokens.STRMUL; - break; - case 66: -return (int)Tokens.STRMUL; - break; - case 68: - case 69: -return (int)Tokens.STRMUL; - break; - case 70: -if (QuotingDepth == 0) BEGIN(INITIAL); else BEGIN(UNQUOTE); return (int)Tokens.STRMULEND; - break; - case 71: -return (int)Tokens.STRMULESC; - break; - case 72: -return (int)Tokens.STRMULESC; - break; - case 73: -BEGIN(QUOTE); return (int)Tokens.UQEND; - break; - default: - break; - } -#pragma warning restore 162, 1522 -#endregion - } - } - } // end try - finally { -// User-specified epilog to scan() -LoadYylval(); -// End, user-specified epilog - } // end finally - } - -#if BACKUP - void SaveStateAndPos(ref Context ctx) { - ctx.bPos = buffer.Pos; - ctx.rPos = readPos; - ctx.cCol = cCol; - ctx.lNum = lNum; - ctx.state = state; - ctx.cChr = code; - } - - void RestoreStateAndPos(ref Context ctx) { - buffer.Pos = ctx.bPos; - readPos = ctx.rPos; - cCol = ctx.cCol; - lNum = ctx.lNum; - state = ctx.state; - code = ctx.cChr; - } -#endif // BACKUP - - // ============= End of the tokenizer code ================ - -#if STACK - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal void yy_clear_stack() { scStack.Clear(); } - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal int yy_top_state() { return scStack.Peek(); } - - internal void yy_push_state(int state) - { - scStack.Push(currentScOrd); - BEGIN(state); - } - - internal void yy_pop_state() - { - // Protect against input errors that pop too far ... - if (scStack.Count > 0) { - int newSc = scStack.Pop(); - BEGIN(newSc); - } // Otherwise leave stack unchanged. - } - #endif // STACK - - [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal void ECHO() { Console.Out.Write(yytext); } - - } // end class $Scanner - -// ============================================================== -// -// This code automatically produced from an embedded resource. -// Do not edit this file, or it will become incompatible with -// the specification from which it was generated. -// -// ============================================================== - -// Code copied from GPLEX embedded resource - [Serializable] - public class BufferException : Exception - { - public BufferException() { } - public BufferException(string message) : base(message) { } - public BufferException(string message, Exception innerException) - : base(message, innerException) { } - protected BufferException(SerializationInfo info, StreamingContext context) - : base(info, context) { } - } - - public abstract class ScanBuff - { - private string fileNm; - - public const int EndOfFile = -1; - public const int UnicodeReplacementChar = 0xFFFD; - - public bool IsFile { get { return (fileNm != null); } } - public string FileName { get { return fileNm; } set { fileNm = value; } } - - public abstract int Pos { get; set; } - public abstract int Read(); - public virtual void Mark() { } - - public abstract string GetString(int begin, int limit); - - public static ScanBuff GetBuffer(string source) - { - return new StringBuffer(source); - } - - public static ScanBuff GetBuffer(IList source) - { - return new LineBuffer(source); - } - -#if (!NOFILES) - public static ScanBuff GetBuffer(Stream source) - { - return new BuildBuffer(source); - } - -#if (!BYTEMODE) - public static ScanBuff GetBuffer(Stream source, int fallbackCodePage) - { - return new BuildBuffer(source, fallbackCodePage); - } -#endif // !BYTEMODE -#endif // !NOFILES - } - - #region Buffer classes - - // ============================================================== - // ===== Definitions for various ScanBuff derived classes ==== - // ============================================================== - // =============== String input ================ - // ============================================================== - - /// - /// This class reads characters from a single string as - /// required, for example, by Visual Studio language services - /// - sealed class StringBuffer : ScanBuff - { - string str; // input buffer - int bPos; // current position in buffer - int sLen; - - public StringBuffer(string source) - { - this.str = source; - this.sLen = source.Length; - this.FileName = null; - } - - public override int Read() - { - if (bPos < sLen) return str[bPos++]; - else if (bPos == sLen) { bPos++; return '\n'; } // one strike, see new line - else { bPos++; return EndOfFile; } // two strikes and you're out! - } - - public override string GetString(int begin, int limit) - { - // "limit" can be greater than sLen with the BABEL - // option set. Read returns a "virtual" EOL if - // an attempt is made to read past the end of the - // string buffer. Without the guard any attempt - // to fetch yytext for a token that includes the - // EOL will throw an index exception. - if (limit > sLen) limit = sLen; - if (limit <= begin) return ""; - else return str.Substring(begin, limit - begin); - } - - public override int Pos - { - get { return bPos; } - set { bPos = value; } - } - - public override string ToString() { return "StringBuffer"; } - } - - // ============================================================== - // The LineBuff class contributed by Nigel Horspool, - // nigelh@cs.uvic.cs - // ============================================================== - - sealed class LineBuffer : ScanBuff - { - IList line; // list of source lines from a file - int numLines; // number of strings in line list - string curLine; // current line in that list - int cLine; // index of current line in the list - int curLen; // length of current line - int curLineStart; // position of line start in whole file - int curLineEnd; // position of line end in whole file - int maxPos; // max position ever visited in whole file - int cPos; // ordinal number of code in source - - // Constructed from a list of strings, one per source line. - // The lines have had trailing '\n' characters removed. - public LineBuffer(IList lineList) - { - line = lineList; - numLines = line.Count; - cPos = curLineStart = 0; - curLine = (numLines > 0 ? line[0] : ""); - maxPos = curLineEnd = curLen = curLine.Length; - cLine = 1; - FileName = null; - } - - public override int Read() - { - if (cPos < curLineEnd) - return curLine[cPos++ - curLineStart]; - if (cPos++ == curLineEnd) - return '\n'; - if (cLine >= numLines) - return EndOfFile; - curLine = line[cLine]; - curLen = curLine.Length; - curLineStart = curLineEnd + 1; - curLineEnd = curLineStart + curLen; - if (curLineEnd > maxPos) - maxPos = curLineEnd; - cLine++; - return curLen > 0 ? curLine[0] : '\n'; - } - - // To speed up searches for the line containing a position - private int cachedPosition; - private int cachedIxdex; - private int cachedLineStart; - - // Given a position pos within the entire source, the results are - // ix -- the index of the containing line - // lstart -- the position of the first character on that line - private void findIndex(int pos, out int ix, out int lstart) - { - if (pos >= cachedPosition) - { - ix = cachedIxdex; lstart = cachedLineStart; - } - else - { - ix = lstart = 0; - } - while (ix < numLines) - { - int len = line[ix].Length + 1; - if (pos < lstart + len) break; - lstart += len; - ix++; - } - cachedPosition = pos; - cachedIxdex = ix; - cachedLineStart = lstart; - } - - public override string GetString(int begin, int limit) - { - if (begin >= maxPos || limit <= begin) return ""; - int endIx, begIx, endLineStart, begLineStart; - findIndex(begin, out begIx, out begLineStart); - int begCol = begin - begLineStart; - findIndex(limit, out endIx, out endLineStart); - int endCol = limit - endLineStart; - string s = line[begIx]; - if (begIx == endIx) - { - // the usual case, substring all on one line - return (endCol <= s.Length) ? - s.Substring(begCol, endCol - begCol) - : s.Substring(begCol) + "\n"; - } - // the string spans multiple lines, yuk! - StringBuilder sb = new StringBuilder(); - if (begCol < s.Length) - sb.Append(s.Substring(begCol)); - for (; ; ) - { - sb.Append("\n"); - s = line[++begIx]; - if (begIx >= endIx) break; - sb.Append(s); - } - if (endCol <= s.Length) - { - sb.Append(s.Substring(0, endCol)); - } - else - { - sb.Append(s); - sb.Append("\n"); - } - return sb.ToString(); - } - - public override int Pos - { - get { return cPos; } - set - { - cPos = value; - findIndex(cPos, out cLine, out curLineStart); - // cLine should be the *next* line after curLine. - curLine = (cLine < numLines ? line[cLine++] : ""); - curLineEnd = curLineStart + curLine.Length; - } - } - - public override string ToString() { return "LineBuffer"; } - } - -#if (!NOFILES) - // ============================================================== - // ===== class BuildBuff : for unicode text files ======== - // ============================================================== - - class BuildBuffer : ScanBuff - { - // Double buffer for char stream. - class BufferElement - { - StringBuilder bldr = new StringBuilder(); - StringBuilder next = new StringBuilder(); - int minIx; - int maxIx; - int brkIx; - bool appendToNext; - - internal BufferElement() { } - - internal int MaxIndex { get { return maxIx; } } - // internal int MinIndex { get { return minIx; } } - - internal char this[int index] - { - get - { - if (index < minIx || index >= maxIx) - throw new BufferException("Index was outside data buffer"); - else if (index < brkIx) - return bldr[index - minIx]; - else - return next[index - brkIx]; - } - } - - internal void Append(char[] block, int count) - { - maxIx += count; - if (appendToNext) - this.next.Append(block, 0, count); - else - { - this.bldr.Append(block, 0, count); - brkIx = maxIx; - appendToNext = true; - } - } - - internal string GetString(int start, int limit) - { - if (limit <= start) - return ""; - if (start >= minIx && limit <= maxIx) - if (limit < brkIx) // String entirely in bldr builder - return bldr.ToString(start - minIx, limit - start); - else if (start >= brkIx) // String entirely in next builder - return next.ToString(start - brkIx, limit - start); - else // Must do a string-concatenation - return - bldr.ToString(start - minIx, brkIx - start) + - next.ToString(0, limit - brkIx); - else - throw new BufferException("String was outside data buffer"); - } - - internal void Mark(int limit) - { - if (limit > brkIx + 16) // Rotate blocks - { - StringBuilder temp = bldr; - bldr = next; - next = temp; - next.Length = 0; - minIx = brkIx; - brkIx = maxIx; - } - } - } - - BufferElement data = new BufferElement(); - - int bPos; // Postion index in the StringBuilder - BlockReader NextBlk; // Delegate that serves char-arrays; - - private string EncodingName - { - get - { - StreamReader rdr = NextBlk.Target as StreamReader; - return (rdr == null ? "raw-bytes" : rdr.CurrentEncoding.BodyName); - } - } - - public BuildBuffer(Stream stream) - { - FileStream fStrm = (stream as FileStream); - if (fStrm != null) FileName = fStrm.Name; - NextBlk = BlockReaderFactory.Raw(stream); - } - -#if (!BYTEMODE) - public BuildBuffer(Stream stream, int fallbackCodePage) - { - FileStream fStrm = (stream as FileStream); - if (fStrm != null) FileName = fStrm.Name; - NextBlk = BlockReaderFactory.Get(stream, fallbackCodePage); - } -#endif - - /// - /// Marks a conservative lower bound for the buffer, - /// allowing space to be reclaimed. If an application - /// needs to call GetString at arbitrary past locations - /// in the input stream, Mark() is not called. - /// - public override void Mark() { data.Mark(bPos - 2); } - - public override int Pos - { - get { return bPos; } - set { bPos = value; } - } - - - /// - /// Read returns the ordinal number of the next char, or - /// EOF (-1) for an end of stream. Note that the next - /// code point may require *two* calls of Read(). - /// - /// - public override int Read() - { - // - // Characters at positions - // [data.offset, data.offset + data.bldr.Length) - // are available in data.bldr. - // - if (bPos < data.MaxIndex) - { - // ch0 cannot be EOF - return (int)data[bPos++]; - } - else // Read from underlying stream - { - // Experimental code, blocks of page size - char[] chrs = new char[4096]; - int count = NextBlk(chrs, 0, 4096); - if (count == 0) - return EndOfFile; - else - { - data.Append(chrs, count); - return (int)data[bPos++]; - } - } - } - - public override string GetString(int begin, int limit) - { - return data.GetString(begin, limit); - } - - public override string ToString() - { - return "StringBuilder buffer, encoding: " + this.EncodingName; - } - } - - // =============== End ScanBuff-derived classes ================== - - public delegate int BlockReader(char[] block, int index, int number); - - // A delegate factory, serving up a delegate that - // reads a block of characters from the underlying - // encoded stream, via a StreamReader object. - // - public static class BlockReaderFactory - { - public static BlockReader Raw(Stream stream) - { - return delegate(char[] block, int index, int number) - { - byte[] b = new byte[number]; - int count = stream.Read(b, 0, number); - int i = 0; - int j = index; - for (; i < count; i++, j++) - block[j] = (char)b[i]; - return count; - }; - } - -#if (!BYTEMODE) - public static BlockReader Get(Stream stream, int fallbackCodePage) - { - Encoding encoding; - int preamble = Preamble(stream); - - if (preamble != 0) // There is a valid BOM here! - encoding = Encoding.GetEncoding(preamble); - else if (fallbackCodePage == -1) // Fallback is "raw" bytes - return Raw(stream); - else if (fallbackCodePage != -2) // Anything but "guess" - encoding = Encoding.GetEncoding(fallbackCodePage); - else // This is the "guess" option - { - int guess = new Guesser(stream).GuessCodePage(); - stream.Seek(0, SeekOrigin.Begin); - if (guess == -1) // ==> this is a 7-bit file - encoding = Encoding.ASCII; - else if (guess == 65001) - encoding = Encoding.UTF8; - else // ==> use the machine default - encoding = Encoding.Default; - } - StreamReader reader = new StreamReader(stream, encoding); - return reader.Read; - } - - static int Preamble(Stream stream) - { - int b0 = stream.ReadByte(); - int b1 = stream.ReadByte(); - - if (b0 == 0xfe && b1 == 0xff) - return 1201; // UTF16BE - if (b0 == 0xff && b1 == 0xfe) - return 1200; // UTF16LE - - int b2 = stream.ReadByte(); - if (b0 == 0xef && b1 == 0xbb && b2 == 0xbf) - return 65001; // UTF8 - // - // There is no unicode preamble, so we - // return denoter for the machine default. - // - stream.Seek(0, SeekOrigin.Begin); - return 0; - } -#endif // !BYTEMODE - } -#endif // !NOFILES - #endregion Buffer classes - - // ============================================================== - // ============ class CodePageHandling ============= - // ============================================================== -#if (!NOFILES) - public static class CodePageHandling - { - public static int GetCodePage(string option) - { - string command = option.ToUpperInvariant(); - if (command.StartsWith("CodePage:", StringComparison.OrdinalIgnoreCase)) - command = command.Substring(9); - try - { - if (command.Equals("RAW")) - return -1; - else if (command.Equals("GUESS")) - return -2; - else if (command.Equals("DEFAULT")) - return 0; - else if (char.IsDigit(command[0])) - return int.Parse(command, CultureInfo.InvariantCulture); - else - { - Encoding enc = Encoding.GetEncoding(command); - return enc.CodePage; - } - } - catch (FormatException) - { - Console.Error.WriteLine( - "Invalid format \"{0}\", using machine default", option); - } - catch (ArgumentException) - { - Console.Error.WriteLine( - "Unknown code page \"{0}\", using machine default", option); - } - return 0; - } - } -#region guesser -#if (!BYTEMODE) - // ============================================================== - // ============ Encoding Guesser ============= - // ============================================================== - - /// - /// This class provides a simple finite state automaton that - /// scans the file looking for (1) valid UTF-8 byte patterns, - /// (2) bytes >= 0x80 which are not part of a UTF-8 sequence. - /// The method then guesses whether it is UTF-8 or maybe some - /// local machine default encoding. This works well for the - /// various Latin encodings. - /// - internal class Guesser - { - ScanBuff buffer; - - public int GuessCodePage() { return Scan(); } - - const int maxAccept = 10; - const int initial = 0; - const int eofNum = 0; - const int goStart = -1; - const int INITIAL = 0; - const int EndToken = 0; - - #region user code - /* - * Reads the bytes of a file to determine if it is - * UTF-8 or a single-byte code page file. - */ - public long utfX; - public long uppr; - #endregion user code - - int state; - int currentStart = startState[0]; - int code; - - #region ScannerTables - static int[] startState = new int[] { 11, 0 }; - - #region CharacterMap - static sbyte[] map = new sbyte[256] { -/* '\0' */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* '\x10' */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* '\x20' */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* '0' */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* '@' */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 'P' */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* '`' */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 'p' */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* '\x80' */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -/* '\x90' */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -/* '\xA0' */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -/* '\xB0' */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -/* '\xC0' */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -/* '\xD0' */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -/* '\xE0' */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, -/* '\xF0' */ 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5 }; - #endregion - - static sbyte[][] nextState = new sbyte[][] { - new sbyte[] {0, 0, 0, 0, 0, 0}, - new sbyte[] {-1, -1, 10, -1, -1, -1}, - new sbyte[] {-1, -1, -1, -1, -1, -1}, - new sbyte[] {-1, -1, 8, -1, -1, -1}, - new sbyte[] {-1, -1, 5, -1, -1, -1}, - new sbyte[] {-1, -1, 6, -1, -1, -1}, - new sbyte[] {-1, -1, 7, -1, -1, -1}, - null, - new sbyte[] {-1, -1, 9, -1, -1, -1}, - null, - null, - new sbyte[] {-1, 1, 2, 3, 4, 2} - }; - - - [SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")] - // Reason for suppression: cannot have self-reference in array initializer. - static Guesser() - { - nextState[7] = nextState[2]; - nextState[9] = nextState[2]; - nextState[10] = nextState[2]; - } - - int NextState() - { - if (code == ScanBuff.EndOfFile) - return eofNum; - else - return nextState[state][map[code]]; - } - #endregion - - public Guesser(System.IO.Stream file) { SetSource(file); } - - public void SetSource(System.IO.Stream source) - { - this.buffer = new BuildBuffer(source); - code = buffer.Read(); - } - - int Scan() - { - for (; ; ) - { - int next; - state = currentStart; - while ((next = NextState()) == goStart) - code = buffer.Read(); - - state = next; - code = buffer.Read(); - - while ((next = NextState()) > eofNum) - { - state = next; - code = buffer.Read(); - } - if (state <= maxAccept) - { - #region ActionSwitch -#pragma warning disable 162 - switch (state) - { - case eofNum: - switch (currentStart) - { - case 11: - if (utfX == 0 && uppr == 0) return -1; /* raw ascii */ - else if (uppr * 10 > utfX) return 0; /* default code page */ - else return 65001; /* UTF-8 encoding */ - break; - } - return EndToken; - case 1: // Recognized '{Upper128}', Shortest string "\xC0" - case 2: // Recognized '{Upper128}', Shortest string "\x80" - case 3: // Recognized '{Upper128}', Shortest string "\xE0" - case 4: // Recognized '{Upper128}', Shortest string "\xF0" - uppr++; - break; - case 5: // Recognized '{Utf8pfx4}{Utf8cont}', Shortest string "\xF0\x80" - uppr += 2; - break; - case 6: // Recognized '{Utf8pfx4}{Utf8cont}{2}', Shortest string "\xF0\x80\x80" - uppr += 3; - break; - case 7: // Recognized '{Utf8pfx4}{Utf8cont}{3}', Shortest string "\xF0\x80\x80\x80" - utfX += 3; - break; - case 8: // Recognized '{Utf8pfx3}{Utf8cont}', Shortest string "\xE0\x80" - uppr += 2; - break; - case 9: // Recognized '{Utf8pfx3}{Utf8cont}{2}', Shortest string "\xE0\x80\x80" - utfX += 2; - break; - case 10: // Recognized '{Utf8pfx2}{Utf8cont}', Shortest string "\xC0\x80" - utfX++; - break; - default: - break; - } -#pragma warning restore 162 - #endregion - } - } - } - } // end class Guesser - -#endif // !BYTEMODE -#endregion -#endif // !NOFILES - -// End of code copied from embedded resource - -} // end namespace diff --git a/Src/Core/API/Parser/lexer.lex b/Src/Core/API/Parser/lexer.lex deleted file mode 100644 index 3b7a8a6..0000000 --- a/Src/Core/API/Parser/lexer.lex +++ /dev/null @@ -1,226 +0,0 @@ -%namespace Microsoft.Formula.API -%visibility internal - -%x COMMENT -%x QUOTE -%x STRING_SINGLE -%x STRING_MULTI -%s UNQUOTE - -%{ - private Dictionary keywords = null; - - internal int QuotingDepth - { - get; - set; - } - - internal ParseResult ParseResult - { - get; - set; - } - - override public void yyerror(string message, params object[] args) - { - if (ParseResult == null) - { - throw new Exception("Bad scanner state"); - } - - var errFlag = new Flag( - SeverityKind.Error, - new Span(yylloc.StartLine, yylloc.StartColumn, yylloc.EndLine, yylloc.StartColumn + yyleng, ParseResult.Name), - Constants.BadSyntax.ToString(string.Format(message, args)), - Constants.BadSyntax.Code, - ParseResult.Program.Node.Name); - - ParseResult.AddFlag(errFlag); - } - - private void MkKeywords() - { - if (keywords != null) - { - return; - } - - keywords = new Dictionary(28); - - keywords.Add("domain", (int)Tokens.DOMAIN); - keywords.Add("model", (int)Tokens.MODEL); - keywords.Add("transform", (int)Tokens.TRANSFORM); - keywords.Add("system", (int)Tokens.SYSTEM); - - keywords.Add("includes", (int)Tokens.INCLUDES); - keywords.Add("extends", (int)Tokens.EXTENDS); - keywords.Add("of", (int)Tokens.OF); - keywords.Add("returns", (int)Tokens.RETURNS); - keywords.Add("at", (int)Tokens.AT); - keywords.Add("machine", (int)Tokens.MACHINE); - - keywords.Add("is", (int)Tokens.IS); - keywords.Add("no", (int)Tokens.NO); - - keywords.Add("new", (int)Tokens.NEW); - keywords.Add("fun", (int)Tokens.FUN); - keywords.Add("inj", (int)Tokens.INJ); - keywords.Add("bij", (int)Tokens.BIJ); - keywords.Add("sur", (int)Tokens.SUR); - keywords.Add("any", (int)Tokens.ANY); - keywords.Add("sub", (int)Tokens.SUB); - - keywords.Add("ensures", (int)Tokens.ENSURES); - keywords.Add("requires", (int)Tokens.REQUIRES); - keywords.Add("conforms", (int)Tokens.CONFORMS); - keywords.Add("some", (int)Tokens.SOME); - keywords.Add("atleast", (int)Tokens.ATLEAST); - keywords.Add("atmost", (int)Tokens.ATMOST); - keywords.Add("partial", (int)Tokens.PARTIAL); - keywords.Add("initially", (int)Tokens.INITIALLY); - keywords.Add("next", (int)Tokens.NEXT); - keywords.Add("property", (int)Tokens.PROPERTY); - keywords.Add("boot", (int)Tokens.BOOT); - } - - int GetIdToken(string txt) - { - MkKeywords(); - - int tokId; - if (keywords.TryGetValue(txt, out tokId)) - { - return tokId; - } - - if (txt.Contains(".")) - { - if (!txt.EndsWith(".")) - { - return (int)Tokens.QUALID; - } - else - { - return (int)Tokens.LEX_ERROR; - } - } - else - { - return (int)Tokens.BAREID; - } - } - - internal void LoadYylval() - { - // Trigger lazy evaluation of yytext - int dummy = yytext.Length; - - yylval.str = tokTxt; - yylloc = new QUT.Gppg.LexLocation(tokLin, tokCol, tokELin, tokECol); - } -%} - -CmntStart \/\* -CmntEnd \*\/ -CmntStartAlt \/\/ -LF [\n\r] -NonLF [^\n\r]* - -White0 [ \t\r\f\v] -White {White0}|\n -NonQCntrChars [^`$\n\r]* -NonSMCntrChars [^\'\"\n\r]* - -BId [A-Za-z_]([A-Za-z_0-9]*[']*) -TId [#]{BId}([\[][0-9]+[\]])? -SId [\%]{BId}([\.]{BId})* - -%% - -{CmntStartAlt}{NonLF}{LF} { return (int)Tokens.LEX_COMMENT; } -{CmntStartAlt}{NonLF} { return (int)Tokens.LEX_COMMENT; } -{CmntStart} { BEGIN(COMMENT); return (int)Tokens.LEX_COMMENT; } -{CmntEnd} { if (QuotingDepth == 0) BEGIN(INITIAL); else BEGIN(UNQUOTE); return (int)Tokens.LEX_COMMENT; } -[.]*{LF} { return (int)Tokens.LEX_COMMENT; } -[.]* { return (int)Tokens.LEX_COMMENT; } - -({BId}[\.])*({BId}|{TId}|{SId}) { return GetIdToken(yytext); } -[\-+]?[0-9]+ { return (int)Tokens.DIGITS; } -[\-+]?[0-9]+[\.][0-9]+ { return (int)Tokens.REAL; } -[\-+]?[0-9]+[\/][\-+]?[0]*[1-9][0-9]* { return (int)Tokens.FRAC; } - -[\|] { return (int)Tokens.PIPE; } -"::=" { return (int)Tokens.TYPEDEF; } -":-" { return (int)Tokens.RULE; } -"::" { return (int)Tokens.RENAMES; } -".." { return (int)Tokens.RANGE; } -[\.] { return (int)Tokens.DOT; } -[:] { return (int)Tokens.COLON; } - -[,] { return (int)Tokens.COMMA; } -[;] { return (int)Tokens.SEMICOLON; } - -[=] { return (int)Tokens.EQ; } -"!=" { return (int)Tokens.NE; } -"<=" { return (int)Tokens.LE; } -">=" { return (int)Tokens.GE; } -[<] { return (int)Tokens.LT; } -[>] { return (int)Tokens.GT; } - -[+] { return (int)Tokens.PLUS; } -[\-] { return (int)Tokens.MINUS; } -[*] { return (int)Tokens.MUL; } -[\/] { return (int)Tokens.DIV; } -[%] { return (int)Tokens.MOD; } - -"=>" { return (int)Tokens.STRONGARROW; } -"->" { return (int)Tokens.WEAKARROW; } - -[{] { return (int)Tokens.LCBRACE; } -[}] { return (int)Tokens.RCBRACE; } -[\[] { return (int)Tokens.LSBRACE; } -[\]] { return (int)Tokens.RSBRACE; } -[(] { return (int)Tokens.LPAREN; } -[)] { return (int)Tokens.RPAREN; } - -[\"] { BEGIN(STRING_SINGLE); return (int)Tokens.STRSNGSTART; } -{ -[^\"\n\r\\]* { return (int)Tokens.STRSNG; } -[\\][^\n\r] { return (int)Tokens.STRSNGESC; } -[\"] { if (QuotingDepth == 0) BEGIN(INITIAL); else BEGIN(UNQUOTE); return (int)Tokens.STRSNGEND; } -{LF} | [\\] | <> { return (int)Tokens.RUNAWAYSTRING; } -} - -"\'\"" { BEGIN(STRING_MULTI); return (int)Tokens.STRMULSTART; } -{ -{NonSMCntrChars}{LF} { return (int)Tokens.STRMUL; } -{NonSMCntrChars} { return (int)Tokens.STRMUL; } -"\'\'\"\"" { return (int)Tokens.STRMULESC; } -"\"\"\'\'" { return (int)Tokens.STRMULESC; } -"\"\'" { if (QuotingDepth == 0) BEGIN(INITIAL); else BEGIN(UNQUOTE); return (int)Tokens.STRMULEND; } -[\"\'] { return (int)Tokens.STRMUL; } -<> { return (int)Tokens.RUNAWAYSTRING; } -} - -[`] { ++QuotingDepth; BEGIN(QUOTE); return (int)Tokens.QSTART; } -{ -{NonQCntrChars}{LF} { return (int)Tokens.QUOTERUN; } -{NonQCntrChars} { return (int)Tokens.QUOTERUN; } -"``" { return (int)Tokens.QUOTEESCAPE; } -"$$" { return (int)Tokens.QUOTEESCAPE; } -[`] { --QuotingDepth; if (QuotingDepth == 0) BEGIN(INITIAL); else BEGIN(UNQUOTE); return (int)Tokens.QEND; } -[$] { BEGIN(UNQUOTE); return (int)Tokens.UQSTART; } -} - -{ -[$] { BEGIN(QUOTE); return (int)Tokens.UQEND; } -} - -['#^´\\§$~] { return (int)Tokens.ALIENCHAR; } - -%{ - LoadYylval(); -%} - -%% diff --git a/Src/Core/API/Parser/parser.g.cs b/Src/Core/API/Parser/parser.g.cs deleted file mode 100644 index 3994709..0000000 --- a/Src/Core/API/Parser/parser.g.cs +++ /dev/null @@ -1,1529 +0,0 @@ -// This code was generated by the Gardens Point Parser Generator -// Copyright (c) Wayne Kelly, QUT 2005-2010 -// (see accompanying GPPGcopyright.rtf) - -// GPPG version 1.5.1 -// Machine: DESKTOP-KOAEGEQ -// DateTime: 10/2/2019 3:16:04 PM -// UserName: daniel -// Input file - -// options: babel conflicts lines diagnose & report gplex conflicts - -using System; -using System.Collections.Generic; -using System.CodeDom.Compiler; -using System.Globalization; -using System.Text; -using QUT.Gppg; - -namespace Microsoft.Formula.API -{ -internal enum Tokens { - error=1,EOF=2,DOMAIN=3,MODEL=4,TRANSFORM=5,SYSTEM=6, - MACHINE=7,PARTIAL=8,ENSURES=9,REQUIRES=10,CONFORMS=11,LCBRACE=12, - RCBRACE=13,LPAREN=14,RPAREN=15,LSBRACE=16,RSBRACE=17,INCLUDES=18, - EXTENDS=19,OF=20,RETURNS=21,AT=22,COLON=23,RENAMES=24, - RANGE=25,SOME=26,ATLEAST=27,ATMOST=28,INITIALLY=29,NEXT=30, - PROPERTY=31,BOOT=32,EQ=33,TYPEDEF=34,RULE=35,PIPE=36, - DOT=37,SEMICOLON=38,COMMA=39,NO=40,IS=41,WEAKARROW=42, - STRONGARROW=43,NEW=44,INJ=45,BIJ=46,SUR=47,FUN=48, - ANY=49,SUB=50,BAREID=51,QUALID=52,DIGITS=53,REAL=54, - FRAC=55,STRSNGSTART=56,STRSNG=57,STRSNGESC=58,STRSNGEND=59,STRMULSTART=60, - STRMUL=61,STRMULESC=62,STRMULEND=63,NE=64,LT=65,GT=66, - GE=67,LE=68,PLUS=69,MINUS=70,MOD=71,DIV=72, - MUL=73,UMINUS=74,QSTART=75,QEND=76,UQSTART=77,UQEND=78, - QUOTERUN=79,QUOTEESCAPE=80,RUNAWAYSTRING=81,ALIENCHAR=82,maxParseToken=83,LEX_WHITE=84, - LEX_COMMENT=85,LEX_ERROR=86}; - -internal partial struct LexValue -#line 7 "API\Parser\parser.y" - { - public string str; -} -#line default -// Abstract base class for GPLEX scanners -[GeneratedCodeAttribute( "Gardens Point Parser Generator", "1.5.1")] -internal abstract class ScanBase : AbstractScanner { - private LexLocation __yylloc = new LexLocation(); - public override LexLocation yylloc { get { return __yylloc; } set { __yylloc = value; } } - protected virtual bool yywrap() { return true; } - - protected abstract int CurrentSc { get; set; } - // - // Override the virtual EolState property if the scanner state is more - // complicated then a simple copy of the current start state ordinal - // - public virtual int EolState { get { return CurrentSc; } set { CurrentSc = value; } } -} - -// Interface class for 'colorizing' scanners -public interface IColorScan { - void SetSource(string source, int offset); - int GetNext(ref int state, out int start, out int end); -} - -// Utility class for encapsulating token information -[GeneratedCodeAttribute( "Gardens Point Parser Generator", "1.5.1")] -internal class ScanObj { - public int token; - public LexValue yylval; - public LexLocation yylloc; - public ScanObj( int t, LexValue val, LexLocation loc ) { - this.token = t; this.yylval = val; this.yylloc = loc; - } -} - -[GeneratedCodeAttribute( "Gardens Point Parser Generator", "1.5.1")] -internal partial class Parser: ShiftReduceParser -{ -#pragma warning disable 649 - private static Dictionary aliasses; -#pragma warning restore 649 - private static Rule[] rules = new Rule[265]; - private static State[] states = new State[425]; - private static string[] nonTerms = new string[] { - "Program", "$accept", "Config", "ModuleList", "Module", "Anon@1", "Domain", - "Model", "Transform", "TSystem", "Machine", "MachineSigConfig", "Anon@2", - "MachineBody", "MachineSentenceConf", "MachineSentence", "SentenceConfig", - "MachineProp", "Anon@3", "Step", "Anon@4", "Update", "Anon@5", "FuncTerm", - "MachineSig", "Anon@6", "Anon@7", "MachineSigIn", "Anon@8", "ModRefs", - "VoMParamList", "ModelSigConfig", "ModelBody", "ModelSentence", "ModelFactList", - "ModelContractConf", "ModelContract", "Anon@9", "BodyList", "Anon@10", - "CardSpec", "Id", "Anon@11", "ModelFact", "Anon@12", "ModelSig", "Anon@13", - "ModelIntro", "Anon@14", "Anon@15", "Anon@16", "ModRef", "Anon@17", "Anon@18", - "TSystemRest", "TransformSigConfig", "Anon@19", "TransSteps", "TransStepConfig", - "Anon@20", "TransformRest", "TransBody", "TransSentenceConfig", "TransSentence", - "Rule", "TypeDecl", "Anon@21", "Anon@22", "TransformSig", "Anon@23", "TransSigIn", - "Anon@24", "ModelParamList", "DomainSigConfig", "DomSentences", "DomSentenceConfig", - "DomSentence", "Anon@25", "DomainSig", "Anon@26", "Anon@27", "Anon@28", - "SettingList", "Anon@29", "Setting", "Constant", "ModRefRename", "ValOrModelParam", - "UnnBody", "StepOrUpdateLHS", "ChoiceList", "ModApply", "Anon@30", "ModArgList", - "ModAppArg", "Anon@31", "String", "Anon@32", "ModRefNoRename", "Anon@33", - "TypeDeclBody", "Anon@34", "Fields", "Anon@35", "Anon@36", "FunDecl", "MapArrow", - "Field", "UnnCmp", "TypeId", "Anon@37", "EnumList", "EnumCnst", "FuncTermList", - "Anon@38", "Anon@39", "Compr", "Anon@40", "ComprRest", "Anon@41", "Body", - "Anon@42", "Constraint", "RelOp", "FuncOrCompr", "Anon@43", "Atom", "UnOp", - "BinOp", "Anon@44", "Anon@45", "QuoteList", "QuoteItem", "StrStart", "StrBodyList", - "StrEnd", "StrBody", }; - - static Parser() { - states[0] = new State(new int[]{2,3,16,202,3,205,4,278,8,283,5,290,7,413},new int[]{-1,1,-3,4,-4,424,-5,6,-7,9,-74,10,-79,199,-8,225,-32,226,-46,268,-48,271,-9,289,-10,374,-11,375,-12,376,-25,410}); - states[1] = new State(new int[]{2,2}); - states[2] = new State(-1); - states[3] = new State(-2); - states[4] = new State(new int[]{3,205,4,278,8,283,5,290,7,413,2,-3},new int[]{-4,5,-5,6,-7,9,-74,10,-79,199,-8,225,-32,226,-46,268,-48,271,-9,289,-10,374,-11,375,-12,376,-25,410}); - states[5] = new State(-5); - states[6] = new State(new int[]{2,-6,3,-7,4,-7,8,-7,5,-7,7,-7},new int[]{-6,7}); - states[7] = new State(new int[]{3,205,4,278,8,283,5,290,7,413},new int[]{-4,8,-5,6,-7,9,-74,10,-79,199,-8,225,-32,226,-46,268,-48,271,-9,289,-10,374,-11,375,-12,376,-25,410}); - states[8] = new State(-8); - states[9] = new State(-9); - states[10] = new State(new int[]{12,11}); - states[11] = new State(new int[]{13,12,51,118,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,12,91,11,183,16,189},new int[]{-75,13,-76,15,-77,17,-65,18,-114,19,-125,47,-24,51,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-117,90,-66,182,-17,187}); - states[12] = new State(-103); - states[13] = new State(new int[]{13,14}); - states[14] = new State(-104); - states[15] = new State(new int[]{51,118,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,12,91,11,183,16,189,13,-105},new int[]{-75,16,-76,15,-77,17,-65,18,-114,19,-125,47,-24,51,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-117,90,-66,182,-17,187}); - states[16] = new State(-106); - states[17] = new State(-107); - states[18] = new State(-109); - states[19] = new State(new int[]{35,22,37,-194},new int[]{-115,20}); - states[20] = new State(new int[]{37,21}); - states[21] = new State(-195); - states[22] = new State(-196,new int[]{-116,23}); - states[23] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,40,103},new int[]{-39,24,-121,26,-123,30,-24,33,-127,41,-42,100,-86,54,-97,58,-134,59,-128,73}); - states[24] = new State(new int[]{37,25}); - states[25] = new State(-197); - states[26] = new State(new int[]{37,-203,13,-203,38,-204},new int[]{-122,27}); - states[27] = new State(new int[]{38,28}); - states[28] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,40,103},new int[]{-39,29,-121,26,-123,30,-24,33,-127,41,-42,100,-86,54,-97,58,-134,59,-128,73}); - states[29] = new State(-205); - states[30] = new State(new int[]{39,31,38,-206,37,-206,13,-206}); - states[31] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,40,103},new int[]{-121,32,-123,30,-24,33,-127,41,-42,100,-86,54,-97,58,-134,59,-128,73}); - states[32] = new State(-207); - states[33] = new State(new int[]{73,36,72,37,71,38,69,39,70,40,33,111,64,112,65,113,68,114,66,115,67,116,23,117,39,-208,38,-208,37,-208,13,-208},new int[]{-129,34,-124,109}); - states[34] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-24,35,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[35] = new State(new int[]{73,36,72,37,71,38,69,39,70,40,39,-221,35,-221,37,-221,33,-221,64,-221,65,-221,68,-221,66,-221,67,-221,23,-221,38,-221,13,-221,15,-221,36,-221,78,-221},new int[]{-129,34}); - states[36] = new State(-241); - states[37] = new State(-242); - states[38] = new State(-243); - states[39] = new State(-244); - states[40] = new State(-245); - states[41] = new State(-219); - states[42] = new State(new int[]{14,43,73,-232,72,-232,71,-232,69,-232,70,-232,39,-232,35,-232,37,-232,33,-232,64,-232,65,-232,68,-232,66,-232,67,-232,23,-232,38,-232,13,-232,15,-232,36,-232,78,-232}); - states[43] = new State(-222,new int[]{-130,44}); - states[44] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,12,91},new int[]{-114,45,-125,47,-24,51,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-117,90}); - states[45] = new State(new int[]{15,46}); - states[46] = new State(-223); - states[47] = new State(new int[]{35,-214,37,-214,15,-214,13,-214,36,-214,39,-215},new int[]{-126,48}); - states[48] = new State(new int[]{39,49}); - states[49] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,12,91},new int[]{-114,50,-125,47,-24,51,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-117,90}); - states[50] = new State(-216); - states[51] = new State(new int[]{73,36,72,37,71,38,69,39,70,40,39,-217,35,-217,37,-217,15,-217,13,-217,36,-217},new int[]{-129,34}); - states[52] = new State(-234); - states[53] = new State(-235); - states[54] = new State(-233); - states[55] = new State(-236); - states[56] = new State(-237); - states[57] = new State(-238); - states[58] = new State(-239); - states[59] = new State(new int[]{57,67,58,68,61,69,62,70,59,62,63,63},new int[]{-135,60,-136,64,-137,65}); - states[60] = new State(new int[]{59,62,63,63},new int[]{-136,61}); - states[61] = new State(-253); - states[62] = new State(-263); - states[63] = new State(-264); - states[64] = new State(-254); - states[65] = new State(new int[]{57,67,58,68,61,69,62,70,59,-257,63,-257},new int[]{-135,66,-137,65}); - states[66] = new State(-258); - states[67] = new State(-259); - states[68] = new State(-260); - states[69] = new State(-261); - states[70] = new State(-262); - states[71] = new State(-255); - states[72] = new State(-256); - states[73] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-24,74,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[74] = new State(-220,new int[]{-129,34}); - states[75] = new State(-240); - states[76] = new State(-224,new int[]{-131,77}); - states[77] = new State(new int[]{79,82,80,83,77,84},new int[]{-132,78,-133,80}); - states[78] = new State(new int[]{76,79}); - states[79] = new State(-225); - states[80] = new State(new int[]{79,82,80,83,77,84,76,-227},new int[]{-132,81,-133,80}); - states[81] = new State(-228); - states[82] = new State(-229); - states[83] = new State(-230); - states[84] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-24,85,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[85] = new State(new int[]{78,86,73,36,72,37,71,38,69,39,70,40},new int[]{-129,34}); - states[86] = new State(-231); - states[87] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-24,88,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[88] = new State(new int[]{15,89,73,36,72,37,71,38,69,39,70,40},new int[]{-129,34}); - states[89] = new State(-226); - states[90] = new State(-218); - states[91] = new State(-198,new int[]{-118,92}); - states[92] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,12,91},new int[]{-114,93,-125,47,-24,51,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-117,90}); - states[93] = new State(new int[]{13,95,36,96},new int[]{-119,94}); - states[94] = new State(-199); - states[95] = new State(-200); - states[96] = new State(-201,new int[]{-120,97}); - states[97] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,40,103},new int[]{-39,98,-121,26,-123,30,-24,33,-127,41,-42,100,-86,54,-97,58,-134,59,-128,73}); - states[98] = new State(new int[]{13,99}); - states[99] = new State(-202); - states[100] = new State(new int[]{14,43,41,101,73,-232,72,-232,71,-232,69,-232,70,-232,33,-232,64,-232,65,-232,68,-232,66,-232,67,-232,23,-232,39,-232,38,-232,37,-232,13,-232}); - states[101] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-24,102,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[102] = new State(new int[]{73,36,72,37,71,38,69,39,70,40,39,-209,38,-209,37,-209,13,-209},new int[]{-129,34}); - states[103] = new State(new int[]{12,91,51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-117,104,-24,105,-42,106,-127,41,-86,54,-97,58,-134,59,-128,73}); - states[104] = new State(-210); - states[105] = new State(new int[]{73,36,72,37,71,38,69,39,70,40,39,-211,38,-211,37,-211,13,-211},new int[]{-129,34}); - states[106] = new State(new int[]{41,107,14,43,73,-232,72,-232,71,-232,69,-232,70,-232,39,-232,38,-232,37,-232,13,-232}); - states[107] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-24,108,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[108] = new State(new int[]{73,36,72,37,71,38,69,39,70,40,39,-212,38,-212,37,-212,13,-212},new int[]{-129,34}); - states[109] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-24,110,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[110] = new State(new int[]{73,36,72,37,71,38,69,39,70,40,39,-213,38,-213,37,-213,13,-213},new int[]{-129,34}); - states[111] = new State(-246); - states[112] = new State(-247); - states[113] = new State(-248); - states[114] = new State(-249); - states[115] = new State(-250); - states[116] = new State(-251); - states[117] = new State(-252); - states[118] = new State(new int[]{14,-234,73,-234,72,-234,71,-234,69,-234,70,-234,39,-234,35,-234,37,-234,34,-156},new int[]{-100,119}); - states[119] = new State(new int[]{34,120}); - states[120] = new State(new int[]{51,128,52,129,12,130,14,145,50,160,44,165,45,178,46,179,47,180,48,181},new int[]{-101,121,-89,123,-109,124,-110,127,-106,170}); - states[121] = new State(new int[]{37,122}); - states[122] = new State(-157); - states[123] = new State(-158); - states[124] = new State(new int[]{69,125,37,-178,39,-178,15,-178,42,-178,43,-178}); - states[125] = new State(new int[]{51,128,52,129,12,130},new int[]{-89,126,-109,124,-110,127}); - states[126] = new State(-179); - states[127] = new State(-180); - states[128] = new State(-183); - states[129] = new State(-184); - states[130] = new State(-181,new int[]{-111,131}); - states[131] = new State(new int[]{53,137,54,140,55,141,56,71,60,72,51,143,52,144},new int[]{-112,132,-113,134,-97,142,-134,59}); - states[132] = new State(new int[]{13,133}); - states[133] = new State(-182); - states[134] = new State(new int[]{39,135,13,-185}); - states[135] = new State(new int[]{53,137,54,140,55,141,56,71,60,72,51,143,52,144},new int[]{-112,136,-113,134,-97,142,-134,59}); - states[136] = new State(-186); - states[137] = new State(new int[]{25,138,39,-187,13,-187}); - states[138] = new State(new int[]{53,139}); - states[139] = new State(-193); - states[140] = new State(-188); - states[141] = new State(-189); - states[142] = new State(-190); - states[143] = new State(-191); - states[144] = new State(-192); - states[145] = new State(-159,new int[]{-102,146}); - states[146] = new State(new int[]{51,153,52,129,12,130,49,158},new int[]{-103,147,-108,149,-89,152,-109,124,-110,127}); - states[147] = new State(new int[]{15,148}); - states[148] = new State(-160); - states[149] = new State(new int[]{39,150,15,-170,42,-170,43,-170}); - states[150] = new State(new int[]{51,153,52,129,12,130,49,158},new int[]{-103,151,-108,149,-89,152,-109,124,-110,127}); - states[151] = new State(-171); - states[152] = new State(-172); - states[153] = new State(new int[]{23,154,69,-183,39,-183,15,-183,42,-183,43,-183}); - states[154] = new State(new int[]{49,156,51,128,52,129,12,130},new int[]{-89,155,-109,124,-110,127}); - states[155] = new State(-174); - states[156] = new State(new int[]{51,128,52,129,12,130},new int[]{-89,157,-109,124,-110,127}); - states[157] = new State(-175); - states[158] = new State(new int[]{51,128,52,129,12,130},new int[]{-89,159,-109,124,-110,127}); - states[159] = new State(-173); - states[160] = new State(-161,new int[]{-104,161}); - states[161] = new State(new int[]{14,162}); - states[162] = new State(new int[]{51,153,52,129,12,130,49,158},new int[]{-103,163,-108,149,-89,152,-109,124,-110,127}); - states[163] = new State(new int[]{15,164}); - states[164] = new State(-162); - states[165] = new State(-163,new int[]{-105,166}); - states[166] = new State(new int[]{14,167}); - states[167] = new State(new int[]{51,153,52,129,12,130,49,158},new int[]{-103,168,-108,149,-89,152,-109,124,-110,127}); - states[168] = new State(new int[]{15,169}); - states[169] = new State(-164); - states[170] = new State(new int[]{14,171}); - states[171] = new State(new int[]{51,153,52,129,12,130,49,158},new int[]{-103,172,-108,149,-89,152,-109,124,-110,127}); - states[172] = new State(new int[]{42,176,43,177},new int[]{-107,173}); - states[173] = new State(new int[]{51,153,52,129,12,130,49,158},new int[]{-103,174,-108,149,-89,152,-109,124,-110,127}); - states[174] = new State(new int[]{15,175}); - states[175] = new State(-165); - states[176] = new State(-176); - states[177] = new State(-177); - states[178] = new State(-166); - states[179] = new State(-167); - states[180] = new State(-168); - states[181] = new State(-169); - states[182] = new State(-110); - states[183] = new State(-111,new int[]{-78,184}); - states[184] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,40,103},new int[]{-39,185,-121,26,-123,30,-24,33,-127,41,-42,100,-86,54,-97,58,-134,59,-128,73}); - states[185] = new State(new int[]{37,186}); - states[186] = new State(-112); - states[187] = new State(new int[]{51,118,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,12,91,11,183},new int[]{-77,188,-65,18,-114,19,-125,47,-24,51,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-117,90,-66,182}); - states[188] = new State(-108); - states[189] = new State(-122,new int[]{-84,190}); - states[190] = new State(new int[]{51,52,52,53},new int[]{-83,191,-85,193,-42,196}); - states[191] = new State(new int[]{17,192}); - states[192] = new State(-123); - states[193] = new State(new int[]{39,194,17,-124}); - states[194] = new State(new int[]{51,52,52,53},new int[]{-83,195,-85,193,-42,196}); - states[195] = new State(-125); - states[196] = new State(new int[]{33,197}); - states[197] = new State(new int[]{53,55,54,56,55,57,56,71,60,72},new int[]{-86,198,-97,58,-134,59}); - states[198] = new State(-126); - states[199] = new State(new int[]{12,-113,16,-114},new int[]{-80,200}); - states[200] = new State(new int[]{16,202},new int[]{-3,201}); - states[201] = new State(-115); - states[202] = new State(new int[]{51,52,52,53},new int[]{-83,203,-85,193,-42,196}); - states[203] = new State(new int[]{17,204}); - states[204] = new State(-121); - states[205] = new State(new int[]{51,206}); - states[206] = new State(new int[]{19,207,18,222,16,-116,12,-116}); - states[207] = new State(-117,new int[]{-81,208}); - states[208] = new State(new int[]{51,214},new int[]{-30,209,-52,210,-87,213,-99,221}); - states[209] = new State(-118); - states[210] = new State(new int[]{39,211,16,-148,12,-148}); - states[211] = new State(new int[]{51,214},new int[]{-30,212,-52,210,-87,213,-99,221}); - states[212] = new State(-149); - states[213] = new State(-150); - states[214] = new State(new int[]{24,215,22,219,39,-154,16,-154,12,-154,18,-154,19,-154,14,-154}); - states[215] = new State(new int[]{51,216}); - states[216] = new State(new int[]{22,217,39,-152,16,-152,12,-152,18,-152,19,-152,15,-152,14,-152}); - states[217] = new State(new int[]{56,71,60,72},new int[]{-97,218,-134,59}); - states[218] = new State(-153); - states[219] = new State(new int[]{56,71,60,72},new int[]{-97,220,-134,59}); - states[220] = new State(-155); - states[221] = new State(-151); - states[222] = new State(-119,new int[]{-82,223}); - states[223] = new State(new int[]{51,214},new int[]{-30,224,-52,210,-87,213,-99,221}); - states[224] = new State(-120); - states[225] = new State(-10); - states[226] = new State(new int[]{12,227}); - states[227] = new State(new int[]{13,228,51,239,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,16,189,9,250,10,254},new int[]{-33,229,-34,231,-35,233,-44,234,-24,238,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-17,248,-36,266,-37,267}); - states[228] = new State(-37); - states[229] = new State(new int[]{13,230}); - states[230] = new State(-38); - states[231] = new State(new int[]{51,239,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,16,189,9,250,10,254,13,-39},new int[]{-33,232,-34,231,-35,233,-44,234,-24,238,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-17,248,-36,266,-37,267}); - states[232] = new State(-40); - states[233] = new State(-41); - states[234] = new State(new int[]{37,235,39,236}); - states[235] = new State(-51); - states[236] = new State(new int[]{51,239,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,16,189},new int[]{-35,237,-44,234,-24,238,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-17,243}); - states[237] = new State(-53); - states[238] = new State(new int[]{73,36,72,37,71,38,69,39,70,40,37,-55,39,-55},new int[]{-129,34}); - states[239] = new State(new int[]{41,240,14,-234,73,-234,72,-234,71,-234,69,-234,70,-234,37,-234,39,-234}); - states[240] = new State(-56,new int[]{-45,241}); - states[241] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-24,242,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[242] = new State(new int[]{73,36,72,37,71,38,69,39,70,40,37,-57,39,-57},new int[]{-129,34}); - states[243] = new State(new int[]{51,239,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-44,244,-24,238,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[244] = new State(new int[]{37,245,39,246}); - states[245] = new State(-52); - states[246] = new State(new int[]{51,239,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,16,189},new int[]{-35,247,-44,234,-24,238,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-17,243}); - states[247] = new State(-54); - states[248] = new State(new int[]{51,239,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,9,250,10,254},new int[]{-44,244,-37,249,-24,238,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[249] = new State(-44); - states[250] = new State(-45,new int[]{-38,251}); - states[251] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,40,103},new int[]{-39,252,-121,26,-123,30,-24,33,-127,41,-42,100,-86,54,-97,58,-134,59,-128,73}); - states[252] = new State(new int[]{37,253}); - states[253] = new State(-46); - states[254] = new State(new int[]{26,263,28,264,27,265,51,-47,52,-47,53,-47,54,-47,55,-47,56,-47,60,-47,70,-47,75,-47,14,-47,40,-47},new int[]{-40,255,-41,258}); - states[255] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,40,103},new int[]{-39,256,-121,26,-123,30,-24,33,-127,41,-42,100,-86,54,-97,58,-134,59,-128,73}); - states[256] = new State(new int[]{37,257}); - states[257] = new State(-48); - states[258] = new State(new int[]{53,259}); - states[259] = new State(new int[]{51,52,52,53},new int[]{-42,260}); - states[260] = new State(-49,new int[]{-43,261}); - states[261] = new State(new int[]{37,262}); - states[262] = new State(-50); - states[263] = new State(-58); - states[264] = new State(-59); - states[265] = new State(-60); - states[266] = new State(-42); - states[267] = new State(-43); - states[268] = new State(new int[]{12,-61,16,-62},new int[]{-47,269}); - states[269] = new State(new int[]{16,202},new int[]{-3,270}); - states[270] = new State(-63); - states[271] = new State(new int[]{18,272,19,275,16,-64,12,-64}); - states[272] = new State(-65,new int[]{-49,273}); - states[273] = new State(new int[]{51,214},new int[]{-30,274,-52,210,-87,213,-99,221}); - states[274] = new State(-66); - states[275] = new State(-67,new int[]{-50,276}); - states[276] = new State(new int[]{51,214},new int[]{-30,277,-52,210,-87,213,-99,221}); - states[277] = new State(-68); - states[278] = new State(new int[]{51,279}); - states[279] = new State(-69,new int[]{-51,280}); - states[280] = new State(new int[]{20,281}); - states[281] = new State(new int[]{51,214},new int[]{-52,282,-87,213,-99,221}); - states[282] = new State(-70); - states[283] = new State(new int[]{4,284}); - states[284] = new State(new int[]{51,285}); - states[285] = new State(-71,new int[]{-53,286}); - states[286] = new State(new int[]{20,287}); - states[287] = new State(new int[]{51,214},new int[]{-52,288,-87,213,-99,221}); - states[288] = new State(-72); - states[289] = new State(-11); - states[290] = new State(new int[]{51,291,6,338}); - states[291] = new State(-82,new int[]{-60,292}); - states[292] = new State(new int[]{14,327},new int[]{-61,293,-56,294,-69,314,-71,317}); - states[293] = new State(-83); - states[294] = new State(new int[]{12,295}); - states[295] = new State(new int[]{13,296,51,118,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,12,91,9,304,10,308,16,189},new int[]{-62,297,-63,299,-64,301,-65,302,-114,19,-125,47,-24,51,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-117,90,-66,303,-17,312}); - states[296] = new State(-84); - states[297] = new State(new int[]{13,298}); - states[298] = new State(-85); - states[299] = new State(new int[]{51,118,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,12,91,9,304,10,308,16,189,13,-86},new int[]{-62,300,-63,299,-64,301,-65,302,-114,19,-125,47,-24,51,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-117,90,-66,303,-17,312}); - states[300] = new State(-87); - states[301] = new State(-88); - states[302] = new State(-90); - states[303] = new State(-91); - states[304] = new State(-92,new int[]{-67,305}); - states[305] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,40,103},new int[]{-39,306,-121,26,-123,30,-24,33,-127,41,-42,100,-86,54,-97,58,-134,59,-128,73}); - states[306] = new State(new int[]{37,307}); - states[307] = new State(-93); - states[308] = new State(-94,new int[]{-68,309}); - states[309] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,40,103},new int[]{-39,310,-121,26,-123,30,-24,33,-127,41,-42,100,-86,54,-97,58,-134,59,-128,73}); - states[310] = new State(new int[]{37,311}); - states[311] = new State(-95); - states[312] = new State(new int[]{51,118,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87,12,91,9,304,10,308},new int[]{-64,313,-65,302,-114,19,-125,47,-24,51,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73,-117,90,-66,303}); - states[313] = new State(-89); - states[314] = new State(new int[]{12,-96,16,-97},new int[]{-70,315}); - states[315] = new State(new int[]{16,202},new int[]{-3,316}); - states[316] = new State(-98); - states[317] = new State(new int[]{21,318}); - states[318] = new State(new int[]{14,319}); - states[319] = new State(-99,new int[]{-72,320}); - states[320] = new State(new int[]{51,326},new int[]{-73,321,-87,323}); - states[321] = new State(new int[]{15,322}); - states[322] = new State(-100); - states[323] = new State(new int[]{39,324,15,-127}); - states[324] = new State(new int[]{51,326},new int[]{-73,325,-87,323}); - states[325] = new State(-128); - states[326] = new State(new int[]{24,215}); - states[327] = new State(new int[]{15,328,51,334},new int[]{-31,329,-88,331,-87,337}); - states[328] = new State(-101); - states[329] = new State(new int[]{15,330}); - states[330] = new State(-102); - states[331] = new State(new int[]{39,332,15,-131}); - states[332] = new State(new int[]{51,334},new int[]{-31,333,-88,331,-87,337}); - states[333] = new State(-132); - states[334] = new State(new int[]{23,335,24,215}); - states[335] = new State(new int[]{51,128,52,129,12,130},new int[]{-89,336,-109,124,-110,127}); - states[336] = new State(-129); - states[337] = new State(-130); - states[338] = new State(new int[]{51,339}); - states[339] = new State(-73,new int[]{-54,340}); - states[340] = new State(new int[]{14,327},new int[]{-55,341,-56,342,-69,314,-71,317}); - states[341] = new State(-74); - states[342] = new State(new int[]{12,343}); - states[343] = new State(new int[]{13,344,51,-76,52,-76,16,-76},new int[]{-57,345}); - states[344] = new State(-75); - states[345] = new State(new int[]{51,52,52,53,16,189},new int[]{-58,346,-59,348,-20,350,-90,351,-42,368,-17,372}); - states[346] = new State(new int[]{13,347}); - states[347] = new State(-77); - states[348] = new State(new int[]{51,52,52,53,16,189,13,-78},new int[]{-58,349,-59,348,-20,350,-90,351,-42,368,-17,372}); - states[349] = new State(-79); - states[350] = new State(-80); - states[351] = new State(new int[]{33,352}); - states[352] = new State(new int[]{51,214},new int[]{-92,353,-52,355,-87,213,-99,221}); - states[353] = new State(new int[]{37,354}); - states[354] = new State(-134); - states[355] = new State(new int[]{14,356}); - states[356] = new State(new int[]{15,357,51,365,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-94,358,-95,360,-24,364,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[357] = new State(-138); - states[358] = new State(new int[]{15,359}); - states[359] = new State(-139); - states[360] = new State(new int[]{15,-140,39,-141},new int[]{-96,361}); - states[361] = new State(new int[]{39,362}); - states[362] = new State(new int[]{51,365,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-94,363,-95,360,-24,364,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[363] = new State(-142); - states[364] = new State(new int[]{73,36,72,37,71,38,69,39,70,40,39,-143,15,-143},new int[]{-129,34}); - states[365] = new State(new int[]{22,366,14,-234,73,-234,72,-234,71,-234,69,-234,70,-234,39,-234,15,-234}); - states[366] = new State(new int[]{56,71,60,72},new int[]{-97,367,-134,59}); - states[367] = new State(-144); - states[368] = new State(new int[]{33,-145,39,-146},new int[]{-98,369}); - states[369] = new State(new int[]{39,370}); - states[370] = new State(new int[]{51,52,52,53},new int[]{-90,371,-42,368}); - states[371] = new State(-147); - states[372] = new State(new int[]{51,52,52,53},new int[]{-20,373,-90,351,-42,368}); - states[373] = new State(-81); - states[374] = new State(-12); - states[375] = new State(-13); - states[376] = new State(new int[]{12,377}); - states[377] = new State(new int[]{13,378,31,-15,32,-15,29,-15,30,-15,16,-15},new int[]{-13,379}); - states[378] = new State(-14); - states[379] = new State(new int[]{31,386,32,391,29,394,30,405,16,189},new int[]{-14,380,-15,382,-16,384,-18,385,-17,408}); - states[380] = new State(new int[]{13,381}); - states[381] = new State(-16); - states[382] = new State(new int[]{31,386,32,391,29,394,30,405,16,189,13,-17},new int[]{-14,383,-15,382,-16,384,-18,385,-17,408}); - states[383] = new State(-18); - states[384] = new State(-19); - states[385] = new State(-21); - states[386] = new State(new int[]{51,387}); - states[387] = new State(new int[]{33,388}); - states[388] = new State(new int[]{51,52,52,53,53,55,54,56,55,57,56,71,60,72,70,75,75,76,14,87},new int[]{-24,389,-127,41,-42,42,-86,54,-97,58,-134,59,-128,73}); - states[389] = new State(new int[]{37,390,73,36,72,37,71,38,69,39,70,40},new int[]{-129,34}); - states[390] = new State(-28); - states[391] = new State(-22,new int[]{-19,392}); - states[392] = new State(new int[]{51,52,52,53},new int[]{-20,393,-90,351,-42,368}); - states[393] = new State(-23); - states[394] = new State(-24,new int[]{-21,395}); - states[395] = new State(new int[]{51,52,52,53},new int[]{-22,396,-90,397,-42,368}); - states[396] = new State(-25); - states[397] = new State(new int[]{33,398}); - states[398] = new State(new int[]{51,214},new int[]{-91,399,-92,401,-52,355,-87,213,-99,221}); - states[399] = new State(new int[]{37,400}); - states[400] = new State(-133); - states[401] = new State(new int[]{37,-135,38,-136},new int[]{-93,402}); - states[402] = new State(new int[]{38,403}); - states[403] = new State(new int[]{51,214},new int[]{-91,404,-92,401,-52,355,-87,213,-99,221}); - states[404] = new State(-137); - states[405] = new State(-26,new int[]{-23,406}); - states[406] = new State(new int[]{51,52,52,53},new int[]{-22,407,-90,397,-42,368}); - states[407] = new State(-27); - states[408] = new State(new int[]{31,386,32,391,29,394,30,405},new int[]{-16,409,-18,385}); - states[409] = new State(-20); - states[410] = new State(new int[]{12,-29,16,-30},new int[]{-26,411}); - states[411] = new State(new int[]{16,202},new int[]{-3,412}); - states[412] = new State(-31); - states[413] = new State(new int[]{51,414}); - states[414] = new State(-32,new int[]{-27,415}); - states[415] = new State(new int[]{14,420},new int[]{-28,416}); - states[416] = new State(new int[]{20,417}); - states[417] = new State(-33,new int[]{-29,418}); - states[418] = new State(new int[]{51,214},new int[]{-30,419,-52,210,-87,213,-99,221}); - states[419] = new State(-34); - states[420] = new State(new int[]{15,421,51,334},new int[]{-31,422,-88,331,-87,337}); - states[421] = new State(-35); - states[422] = new State(new int[]{15,423}); - states[423] = new State(-36); - states[424] = new State(-4); - - for (int sNo = 0; sNo < states.Length; sNo++) states[sNo].number = sNo; - - rules[1] = new Rule(-2, new int[]{-1,2}); - rules[2] = new Rule(-1, new int[]{2}); - rules[3] = new Rule(-1, new int[]{-3}); - rules[4] = new Rule(-1, new int[]{-4}); - rules[5] = new Rule(-1, new int[]{-3,-4}); - rules[6] = new Rule(-4, new int[]{-5}); - rules[7] = new Rule(-6, new int[]{}); - rules[8] = new Rule(-4, new int[]{-5,-6,-4}); - rules[9] = new Rule(-5, new int[]{-7}); - rules[10] = new Rule(-5, new int[]{-8}); - rules[11] = new Rule(-5, new int[]{-9}); - rules[12] = new Rule(-5, new int[]{-10}); - rules[13] = new Rule(-5, new int[]{-11}); - rules[14] = new Rule(-11, new int[]{-12,12,13}); - rules[15] = new Rule(-13, new int[]{}); - rules[16] = new Rule(-11, new int[]{-12,12,-13,-14,13}); - rules[17] = new Rule(-14, new int[]{-15}); - rules[18] = new Rule(-14, new int[]{-15,-14}); - rules[19] = new Rule(-15, new int[]{-16}); - rules[20] = new Rule(-15, new int[]{-17,-16}); - rules[21] = new Rule(-16, new int[]{-18}); - rules[22] = new Rule(-19, new int[]{}); - rules[23] = new Rule(-16, new int[]{32,-19,-20}); - rules[24] = new Rule(-21, new int[]{}); - rules[25] = new Rule(-16, new int[]{29,-21,-22}); - rules[26] = new Rule(-23, new int[]{}); - rules[27] = new Rule(-16, new int[]{30,-23,-22}); - rules[28] = new Rule(-18, new int[]{31,51,33,-24,37}); - rules[29] = new Rule(-12, new int[]{-25}); - rules[30] = new Rule(-26, new int[]{}); - rules[31] = new Rule(-12, new int[]{-25,-26,-3}); - rules[32] = new Rule(-27, new int[]{}); - rules[33] = new Rule(-29, new int[]{}); - rules[34] = new Rule(-25, new int[]{7,51,-27,-28,20,-29,-30}); - rules[35] = new Rule(-28, new int[]{14,15}); - rules[36] = new Rule(-28, new int[]{14,-31,15}); - rules[37] = new Rule(-8, new int[]{-32,12,13}); - rules[38] = new Rule(-8, new int[]{-32,12,-33,13}); - rules[39] = new Rule(-33, new int[]{-34}); - rules[40] = new Rule(-33, new int[]{-34,-33}); - rules[41] = new Rule(-34, new int[]{-35}); - rules[42] = new Rule(-34, new int[]{-36}); - rules[43] = new Rule(-36, new int[]{-37}); - rules[44] = new Rule(-36, new int[]{-17,-37}); - rules[45] = new Rule(-38, new int[]{}); - rules[46] = new Rule(-37, new int[]{9,-38,-39,37}); - rules[47] = new Rule(-40, new int[]{}); - rules[48] = new Rule(-37, new int[]{10,-40,-39,37}); - rules[49] = new Rule(-43, new int[]{}); - rules[50] = new Rule(-37, new int[]{10,-41,53,-42,-43,37}); - rules[51] = new Rule(-35, new int[]{-44,37}); - rules[52] = new Rule(-35, new int[]{-17,-44,37}); - rules[53] = new Rule(-35, new int[]{-44,39,-35}); - rules[54] = new Rule(-35, new int[]{-17,-44,39,-35}); - rules[55] = new Rule(-44, new int[]{-24}); - rules[56] = new Rule(-45, new int[]{}); - rules[57] = new Rule(-44, new int[]{51,41,-45,-24}); - rules[58] = new Rule(-41, new int[]{26}); - rules[59] = new Rule(-41, new int[]{28}); - rules[60] = new Rule(-41, new int[]{27}); - rules[61] = new Rule(-32, new int[]{-46}); - rules[62] = new Rule(-47, new int[]{}); - rules[63] = new Rule(-32, new int[]{-46,-47,-3}); - rules[64] = new Rule(-46, new int[]{-48}); - rules[65] = new Rule(-49, new int[]{}); - rules[66] = new Rule(-46, new int[]{-48,18,-49,-30}); - rules[67] = new Rule(-50, new int[]{}); - rules[68] = new Rule(-46, new int[]{-48,19,-50,-30}); - rules[69] = new Rule(-51, new int[]{}); - rules[70] = new Rule(-48, new int[]{4,51,-51,20,-52}); - rules[71] = new Rule(-53, new int[]{}); - rules[72] = new Rule(-48, new int[]{8,4,51,-53,20,-52}); - rules[73] = new Rule(-54, new int[]{}); - rules[74] = new Rule(-10, new int[]{5,6,51,-54,-55}); - rules[75] = new Rule(-55, new int[]{-56,12,13}); - rules[76] = new Rule(-57, new int[]{}); - rules[77] = new Rule(-55, new int[]{-56,12,-57,-58,13}); - rules[78] = new Rule(-58, new int[]{-59}); - rules[79] = new Rule(-58, new int[]{-59,-58}); - rules[80] = new Rule(-59, new int[]{-20}); - rules[81] = new Rule(-59, new int[]{-17,-20}); - rules[82] = new Rule(-60, new int[]{}); - rules[83] = new Rule(-9, new int[]{5,51,-60,-61}); - rules[84] = new Rule(-61, new int[]{-56,12,13}); - rules[85] = new Rule(-61, new int[]{-56,12,-62,13}); - rules[86] = new Rule(-62, new int[]{-63}); - rules[87] = new Rule(-62, new int[]{-63,-62}); - rules[88] = new Rule(-63, new int[]{-64}); - rules[89] = new Rule(-63, new int[]{-17,-64}); - rules[90] = new Rule(-64, new int[]{-65}); - rules[91] = new Rule(-64, new int[]{-66}); - rules[92] = new Rule(-67, new int[]{}); - rules[93] = new Rule(-64, new int[]{9,-67,-39,37}); - rules[94] = new Rule(-68, new int[]{}); - rules[95] = new Rule(-64, new int[]{10,-68,-39,37}); - rules[96] = new Rule(-56, new int[]{-69}); - rules[97] = new Rule(-70, new int[]{}); - rules[98] = new Rule(-56, new int[]{-69,-70,-3}); - rules[99] = new Rule(-72, new int[]{}); - rules[100] = new Rule(-69, new int[]{-71,21,14,-72,-73,15}); - rules[101] = new Rule(-71, new int[]{14,15}); - rules[102] = new Rule(-71, new int[]{14,-31,15}); - rules[103] = new Rule(-7, new int[]{-74,12,13}); - rules[104] = new Rule(-7, new int[]{-74,12,-75,13}); - rules[105] = new Rule(-75, new int[]{-76}); - rules[106] = new Rule(-75, new int[]{-76,-75}); - rules[107] = new Rule(-76, new int[]{-77}); - rules[108] = new Rule(-76, new int[]{-17,-77}); - rules[109] = new Rule(-77, new int[]{-65}); - rules[110] = new Rule(-77, new int[]{-66}); - rules[111] = new Rule(-78, new int[]{}); - rules[112] = new Rule(-77, new int[]{11,-78,-39,37}); - rules[113] = new Rule(-74, new int[]{-79}); - rules[114] = new Rule(-80, new int[]{}); - rules[115] = new Rule(-74, new int[]{-79,-80,-3}); - rules[116] = new Rule(-79, new int[]{3,51}); - rules[117] = new Rule(-81, new int[]{}); - rules[118] = new Rule(-79, new int[]{3,51,19,-81,-30}); - rules[119] = new Rule(-82, new int[]{}); - rules[120] = new Rule(-79, new int[]{3,51,18,-82,-30}); - rules[121] = new Rule(-3, new int[]{16,-83,17}); - rules[122] = new Rule(-84, new int[]{}); - rules[123] = new Rule(-17, new int[]{16,-84,-83,17}); - rules[124] = new Rule(-83, new int[]{-85}); - rules[125] = new Rule(-83, new int[]{-85,39,-83}); - rules[126] = new Rule(-85, new int[]{-42,33,-86}); - rules[127] = new Rule(-73, new int[]{-87}); - rules[128] = new Rule(-73, new int[]{-87,39,-73}); - rules[129] = new Rule(-88, new int[]{51,23,-89}); - rules[130] = new Rule(-88, new int[]{-87}); - rules[131] = new Rule(-31, new int[]{-88}); - rules[132] = new Rule(-31, new int[]{-88,39,-31}); - rules[133] = new Rule(-22, new int[]{-90,33,-91,37}); - rules[134] = new Rule(-20, new int[]{-90,33,-92,37}); - rules[135] = new Rule(-91, new int[]{-92}); - rules[136] = new Rule(-93, new int[]{}); - rules[137] = new Rule(-91, new int[]{-92,-93,38,-91}); - rules[138] = new Rule(-92, new int[]{-52,14,15}); - rules[139] = new Rule(-92, new int[]{-52,14,-94,15}); - rules[140] = new Rule(-94, new int[]{-95}); - rules[141] = new Rule(-96, new int[]{}); - rules[142] = new Rule(-94, new int[]{-95,-96,39,-94}); - rules[143] = new Rule(-95, new int[]{-24}); - rules[144] = new Rule(-95, new int[]{51,22,-97}); - rules[145] = new Rule(-90, new int[]{-42}); - rules[146] = new Rule(-98, new int[]{}); - rules[147] = new Rule(-90, new int[]{-42,-98,39,-90}); - rules[148] = new Rule(-30, new int[]{-52}); - rules[149] = new Rule(-30, new int[]{-52,39,-30}); - rules[150] = new Rule(-52, new int[]{-87}); - rules[151] = new Rule(-52, new int[]{-99}); - rules[152] = new Rule(-87, new int[]{51,24,51}); - rules[153] = new Rule(-87, new int[]{51,24,51,22,-97}); - rules[154] = new Rule(-99, new int[]{51}); - rules[155] = new Rule(-99, new int[]{51,22,-97}); - rules[156] = new Rule(-100, new int[]{}); - rules[157] = new Rule(-66, new int[]{51,-100,34,-101,37}); - rules[158] = new Rule(-101, new int[]{-89}); - rules[159] = new Rule(-102, new int[]{}); - rules[160] = new Rule(-101, new int[]{14,-102,-103,15}); - rules[161] = new Rule(-104, new int[]{}); - rules[162] = new Rule(-101, new int[]{50,-104,14,-103,15}); - rules[163] = new Rule(-105, new int[]{}); - rules[164] = new Rule(-101, new int[]{44,-105,14,-103,15}); - rules[165] = new Rule(-101, new int[]{-106,14,-103,-107,-103,15}); - rules[166] = new Rule(-106, new int[]{45}); - rules[167] = new Rule(-106, new int[]{46}); - rules[168] = new Rule(-106, new int[]{47}); - rules[169] = new Rule(-106, new int[]{48}); - rules[170] = new Rule(-103, new int[]{-108}); - rules[171] = new Rule(-103, new int[]{-108,39,-103}); - rules[172] = new Rule(-108, new int[]{-89}); - rules[173] = new Rule(-108, new int[]{49,-89}); - rules[174] = new Rule(-108, new int[]{51,23,-89}); - rules[175] = new Rule(-108, new int[]{51,23,49,-89}); - rules[176] = new Rule(-107, new int[]{42}); - rules[177] = new Rule(-107, new int[]{43}); - rules[178] = new Rule(-89, new int[]{-109}); - rules[179] = new Rule(-89, new int[]{-109,69,-89}); - rules[180] = new Rule(-109, new int[]{-110}); - rules[181] = new Rule(-111, new int[]{}); - rules[182] = new Rule(-109, new int[]{12,-111,-112,13}); - rules[183] = new Rule(-110, new int[]{51}); - rules[184] = new Rule(-110, new int[]{52}); - rules[185] = new Rule(-112, new int[]{-113}); - rules[186] = new Rule(-112, new int[]{-113,39,-112}); - rules[187] = new Rule(-113, new int[]{53}); - rules[188] = new Rule(-113, new int[]{54}); - rules[189] = new Rule(-113, new int[]{55}); - rules[190] = new Rule(-113, new int[]{-97}); - rules[191] = new Rule(-113, new int[]{51}); - rules[192] = new Rule(-113, new int[]{52}); - rules[193] = new Rule(-113, new int[]{53,25,53}); - rules[194] = new Rule(-115, new int[]{}); - rules[195] = new Rule(-65, new int[]{-114,-115,37}); - rules[196] = new Rule(-116, new int[]{}); - rules[197] = new Rule(-65, new int[]{-114,35,-116,-39,37}); - rules[198] = new Rule(-118, new int[]{}); - rules[199] = new Rule(-117, new int[]{12,-118,-114,-119}); - rules[200] = new Rule(-119, new int[]{13}); - rules[201] = new Rule(-120, new int[]{}); - rules[202] = new Rule(-119, new int[]{36,-120,-39,13}); - rules[203] = new Rule(-39, new int[]{-121}); - rules[204] = new Rule(-122, new int[]{}); - rules[205] = new Rule(-39, new int[]{-121,-122,38,-39}); - rules[206] = new Rule(-121, new int[]{-123}); - rules[207] = new Rule(-121, new int[]{-123,39,-121}); - rules[208] = new Rule(-123, new int[]{-24}); - rules[209] = new Rule(-123, new int[]{-42,41,-24}); - rules[210] = new Rule(-123, new int[]{40,-117}); - rules[211] = new Rule(-123, new int[]{40,-24}); - rules[212] = new Rule(-123, new int[]{40,-42,41,-24}); - rules[213] = new Rule(-123, new int[]{-24,-124,-24}); - rules[214] = new Rule(-114, new int[]{-125}); - rules[215] = new Rule(-126, new int[]{}); - rules[216] = new Rule(-114, new int[]{-125,-126,39,-114}); - rules[217] = new Rule(-125, new int[]{-24}); - rules[218] = new Rule(-125, new int[]{-117}); - rules[219] = new Rule(-24, new int[]{-127}); - rules[220] = new Rule(-24, new int[]{-128,-24}); - rules[221] = new Rule(-24, new int[]{-24,-129,-24}); - rules[222] = new Rule(-130, new int[]{}); - rules[223] = new Rule(-24, new int[]{-42,14,-130,-114,15}); - rules[224] = new Rule(-131, new int[]{}); - rules[225] = new Rule(-24, new int[]{75,-131,-132,76}); - rules[226] = new Rule(-24, new int[]{14,-24,15}); - rules[227] = new Rule(-132, new int[]{-133}); - rules[228] = new Rule(-132, new int[]{-133,-132}); - rules[229] = new Rule(-133, new int[]{79}); - rules[230] = new Rule(-133, new int[]{80}); - rules[231] = new Rule(-133, new int[]{77,-24,78}); - rules[232] = new Rule(-127, new int[]{-42}); - rules[233] = new Rule(-127, new int[]{-86}); - rules[234] = new Rule(-42, new int[]{51}); - rules[235] = new Rule(-42, new int[]{52}); - rules[236] = new Rule(-86, new int[]{53}); - rules[237] = new Rule(-86, new int[]{54}); - rules[238] = new Rule(-86, new int[]{55}); - rules[239] = new Rule(-86, new int[]{-97}); - rules[240] = new Rule(-128, new int[]{70}); - rules[241] = new Rule(-129, new int[]{73}); - rules[242] = new Rule(-129, new int[]{72}); - rules[243] = new Rule(-129, new int[]{71}); - rules[244] = new Rule(-129, new int[]{69}); - rules[245] = new Rule(-129, new int[]{70}); - rules[246] = new Rule(-124, new int[]{33}); - rules[247] = new Rule(-124, new int[]{64}); - rules[248] = new Rule(-124, new int[]{65}); - rules[249] = new Rule(-124, new int[]{68}); - rules[250] = new Rule(-124, new int[]{66}); - rules[251] = new Rule(-124, new int[]{67}); - rules[252] = new Rule(-124, new int[]{23}); - rules[253] = new Rule(-97, new int[]{-134,-135,-136}); - rules[254] = new Rule(-97, new int[]{-134,-136}); - rules[255] = new Rule(-134, new int[]{56}); - rules[256] = new Rule(-134, new int[]{60}); - rules[257] = new Rule(-135, new int[]{-137}); - rules[258] = new Rule(-135, new int[]{-137,-135}); - rules[259] = new Rule(-137, new int[]{57}); - rules[260] = new Rule(-137, new int[]{58}); - rules[261] = new Rule(-137, new int[]{61}); - rules[262] = new Rule(-137, new int[]{62}); - rules[263] = new Rule(-136, new int[]{59}); - rules[264] = new Rule(-136, new int[]{63}); - } - - protected override void Initialize() { - this.InitSpecialTokens((int)Tokens.error, (int)Tokens.EOF); - this.InitStates(states); - this.InitRules(rules); - this.InitNonTerminals(nonTerms); - } - - protected override void DoAction(int action) - { -#pragma warning disable 162, 1522 - switch (action) - { - case 6: // ModuleList -> Module -#line 58 "API\Parser\parser.y" - { EndModule(); } -#line default - break; - case 7: // Anon@1 -> /* empty */ -#line 59 "API\Parser\parser.y" - { EndModule(); } -#line default - break; - case 15: // Anon@2 -> /* empty */ -#line 79 "API\Parser\parser.y" - { SetModRefState(ModRefState.ModApply); } -#line default - break; - case 22: // Anon@3 -> /* empty */ -#line 98 "API\Parser\parser.y" - { IsBuildingUpdate = false; } -#line default - break; - case 24: // Anon@4 -> /* empty */ -#line 100 "API\Parser\parser.y" - { IsBuildingNext = false; IsBuildingUpdate = true; } -#line default - break; - case 26: // Anon@5 -> /* empty */ -#line 102 "API\Parser\parser.y" - { IsBuildingNext = true; IsBuildingUpdate = true; } -#line default - break; - case 28: // MachineProp -> PROPERTY, BAREID, EQ, FuncTerm, DOT -#line 111 "API\Parser\parser.y" - { AppendProperty(ValueStack[ValueStack.Depth-4].str, ToSpan(LocationStack[LocationStack.Depth-5])); } -#line default - break; - case 29: // MachineSigConfig -> MachineSig -#line 117 "API\Parser\parser.y" - { SetModRefState(ModRefState.None); } -#line default - break; - case 30: // Anon@6 -> /* empty */ -#line 118 "API\Parser\parser.y" - { SetModRefState(ModRefState.None); } -#line default - break; - case 32: // Anon@7 -> /* empty */ -#line 124 "API\Parser\parser.y" - { StartMachine(ValueStack[ValueStack.Depth-1].str, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 33: // Anon@8 -> /* empty */ -#line 126 "API\Parser\parser.y" - { SetModRefState(ModRefState.Other); } -#line default - break; - case 45: // Anon@9 -> /* empty */ -#line 169 "API\Parser\parser.y" - { StartPropContract(ContractKind.EnsuresProp, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 47: // Anon@10 -> /* empty */ -#line 173 "API\Parser\parser.y" - { StartPropContract(ContractKind.RequiresProp, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 49: // Anon@11 -> /* empty */ -#line 180 "API\Parser\parser.y" - { AppendCardContract(ValueStack[ValueStack.Depth-3].str, ParseInt(ValueStack[ValueStack.Depth-2].str, ToSpan(LocationStack[LocationStack.Depth-2])), ToSpan(LocationStack[LocationStack.Depth-4])); } -#line default - break; - case 55: // ModelFact -> FuncTerm -#line 203 "API\Parser\parser.y" - { AppendFact(MkFact(false, ToSpan(LocationStack[LocationStack.Depth-1]))); } -#line default - break; - case 56: // Anon@12 -> /* empty */ -#line 205 "API\Parser\parser.y" - { PushArg(new Nodes.Id(ToSpan(LocationStack[LocationStack.Depth-2]), ValueStack[ValueStack.Depth-2].str)); } -#line default - break; - case 57: // ModelFact -> BAREID, IS, Anon@12, FuncTerm -#line 206 "API\Parser\parser.y" - { AppendFact(MkFact(true, ToSpan(LocationStack[LocationStack.Depth-4]))); } -#line default - break; - case 61: // ModelSigConfig -> ModelSig -#line 218 "API\Parser\parser.y" - { SetModRefState(ModRefState.None); } -#line default - break; - case 62: // Anon@13 -> /* empty */ -#line 219 "API\Parser\parser.y" - { SetModRefState(ModRefState.None); } -#line default - break; - case 65: // Anon@14 -> /* empty */ -#line 226 "API\Parser\parser.y" - { SetCompose(ComposeKind.Includes); SetModRefState(ModRefState.Input); } -#line default - break; - case 67: // Anon@15 -> /* empty */ -#line 229 "API\Parser\parser.y" - { SetCompose(ComposeKind.Extends); SetModRefState(ModRefState.Input); } -#line default - break; - case 69: // Anon@16 -> /* empty */ -#line 235 "API\Parser\parser.y" - { StartModel(ValueStack[ValueStack.Depth-1].str, false, ToSpan(LocationStack[LocationStack.Depth-2])); } -#line default - break; - case 71: // Anon@17 -> /* empty */ -#line 241 "API\Parser\parser.y" - { StartModel(ValueStack[ValueStack.Depth-1].str, true, ToSpan(LocationStack[LocationStack.Depth-3])); } -#line default - break; - case 73: // Anon@18 -> /* empty */ -#line 251 "API\Parser\parser.y" - { StartTSystem(ValueStack[ValueStack.Depth-1].str, ToSpan(LocationStack[LocationStack.Depth-3])); } -#line default - break; - case 76: // Anon@19 -> /* empty */ -#line 261 "API\Parser\parser.y" - { IsBuildingUpdate = false; SetModRefState(ModRefState.ModApply); } -#line default - break; - case 82: // Anon@20 -> /* empty */ -#line 282 "API\Parser\parser.y" - { StartTransform(ValueStack[ValueStack.Depth-1].str, ToSpan(LocationStack[LocationStack.Depth-2])); } -#line default - break; - case 92: // Anon@21 -> /* empty */ -#line 312 "API\Parser\parser.y" - { StartPropContract(ContractKind.EnsuresProp, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 94: // Anon@22 -> /* empty */ -#line 315 "API\Parser\parser.y" - { StartPropContract(ContractKind.RequiresProp, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 96: // TransformSigConfig -> TransformSig -#line 323 "API\Parser\parser.y" - { SetModRefState(ModRefState.None); } -#line default - break; - case 97: // Anon@23 -> /* empty */ -#line 324 "API\Parser\parser.y" - { SetModRefState(ModRefState.None); } -#line default - break; - case 99: // Anon@24 -> /* empty */ -#line 331 "API\Parser\parser.y" - { SetModRefState(ModRefState.Output); } -#line default - break; - case 111: // Anon@25 -> /* empty */ -#line 372 "API\Parser\parser.y" - { StartPropContract(ContractKind.ConformsProp, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 113: // DomainSigConfig -> DomainSig -#line 380 "API\Parser\parser.y" - { SetModRefState(ModRefState.None); } -#line default - break; - case 114: // Anon@26 -> /* empty */ -#line 381 "API\Parser\parser.y" - { SetModRefState(ModRefState.None); } -#line default - break; - case 116: // DomainSig -> DOMAIN, BAREID -#line 387 "API\Parser\parser.y" - { StartDomain(ValueStack[ValueStack.Depth-1].str, ComposeKind.None, ToSpan(LocationStack[LocationStack.Depth-2])); } -#line default - break; - case 117: // Anon@27 -> /* empty */ -#line 391 "API\Parser\parser.y" - { StartDomain(ValueStack[ValueStack.Depth-2].str, ComposeKind.Extends, ToSpan(LocationStack[LocationStack.Depth-3])); } -#line default - break; - case 119: // Anon@28 -> /* empty */ -#line 396 "API\Parser\parser.y" - { StartDomain(ValueStack[ValueStack.Depth-2].str, ComposeKind.Includes, ToSpan(LocationStack[LocationStack.Depth-3])); } -#line default - break; - case 122: // Anon@29 -> /* empty */ -#line 409 "API\Parser\parser.y" - { StartSentenceConfig(ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 126: // Setting -> Id, EQ, Constant -#line 424 "API\Parser\parser.y" - { AppendSetting(); } -#line default - break; - case 129: // ValOrModelParam -> BAREID, COLON, UnnBody -#line 439 "API\Parser\parser.y" - { AppendParam(ValueStack[ValueStack.Depth-3].str, ToSpan(LocationStack[LocationStack.Depth-3])); } -#line default - break; - case 133: // Update -> StepOrUpdateLHS, EQ, ChoiceList, DOT -#line 456 "API\Parser\parser.y" - { AppendUpdate(); } -#line default - break; - case 134: // Step -> StepOrUpdateLHS, EQ, ModApply, DOT -#line 463 "API\Parser\parser.y" - { AppendStep(); } -#line default - break; - case 135: // ChoiceList -> ModApply -#line 467 "API\Parser\parser.y" - { AppendChoice(); } -#line default - break; - case 136: // Anon@30 -> /* empty */ -#line 468 "API\Parser\parser.y" - { AppendChoice(); } -#line default - break; - case 138: // ModApply -> ModRef, LPAREN, RPAREN -#line 476 "API\Parser\parser.y" - { PushArg(MkModApply()); } -#line default - break; - case 139: // ModApply -> ModRef, LPAREN, ModArgList, RPAREN -#line 481 "API\Parser\parser.y" - { PushArg(MkModApply()); } -#line default - break; - case 140: // ModArgList -> ModAppArg -#line 485 "API\Parser\parser.y" - { IncArity(); } -#line default - break; - case 141: // Anon@31 -> /* empty */ -#line 486 "API\Parser\parser.y" - { IncArity(); } -#line default - break; - case 144: // ModAppArg -> BAREID, AT, String -#line 495 "API\Parser\parser.y" - { PushArg(new Nodes.ModRef(ToSpan(LocationStack[LocationStack.Depth-3]), ValueStack[ValueStack.Depth-3].str, null, GetStringValue())); } -#line default - break; - case 145: // StepOrUpdateLHS -> Id -#line 499 "API\Parser\parser.y" - { AppendLHS(); } -#line default - break; - case 146: // Anon@32 -> /* empty */ -#line 500 "API\Parser\parser.y" - { AppendLHS(); } -#line default - break; - case 152: // ModRefRename -> BAREID, RENAMES, BAREID -#line 522 "API\Parser\parser.y" - { AppendModRef(new Nodes.ModRef(ToSpan(LocationStack[LocationStack.Depth-3]), ValueStack[ValueStack.Depth-1].str, ValueStack[ValueStack.Depth-3].str, null)); } -#line default - break; - case 153: // ModRefRename -> BAREID, RENAMES, BAREID, AT, String -#line 528 "API\Parser\parser.y" - { AppendModRef(new Nodes.ModRef(ToSpan(LocationStack[LocationStack.Depth-5]), ValueStack[ValueStack.Depth-3].str, ValueStack[ValueStack.Depth-5].str, GetStringValue())); } -#line default - break; - case 154: // ModRefNoRename -> BAREID -#line 532 "API\Parser\parser.y" - { AppendModRef(new Nodes.ModRef(ToSpan(LocationStack[LocationStack.Depth-1]), ValueStack[ValueStack.Depth-1].str, null, null)); } -#line default - break; - case 155: // ModRefNoRename -> BAREID, AT, String -#line 535 "API\Parser\parser.y" - { AppendModRef(new Nodes.ModRef(ToSpan(LocationStack[LocationStack.Depth-3]), ValueStack[ValueStack.Depth-3].str, null, GetStringValue())); } -#line default - break; - case 156: // Anon@33 -> /* empty */ -#line 541 "API\Parser\parser.y" - { SaveTypeDeclName(ValueStack[ValueStack.Depth-1].str, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 158: // TypeDeclBody -> UnnBody -#line 548 "API\Parser\parser.y" - { EndUnnDecl(); } -#line default - break; - case 159: // Anon@34 -> /* empty */ -#line 550 "API\Parser\parser.y" - { StartConDecl(false, false); } -#line default - break; - case 160: // TypeDeclBody -> LPAREN, Anon@34, Fields, RPAREN -#line 552 "API\Parser\parser.y" - { EndTypeDecl(); } -#line default - break; - case 161: // Anon@35 -> /* empty */ -#line 554 "API\Parser\parser.y" - { StartConDecl(false, true); } -#line default - break; - case 162: // TypeDeclBody -> SUB, Anon@35, LPAREN, Fields, RPAREN -#line 557 "API\Parser\parser.y" - { EndTypeDecl(); } -#line default - break; - case 163: // Anon@36 -> /* empty */ -#line 559 "API\Parser\parser.y" - { StartConDecl(true, false); } -#line default - break; - case 164: // TypeDeclBody -> NEW, Anon@36, LPAREN, Fields, RPAREN -#line 562 "API\Parser\parser.y" - { EndTypeDecl(); } -#line default - break; - case 165: // TypeDeclBody -> FunDecl, LPAREN, Fields, MapArrow, Fields, RPAREN -#line 569 "API\Parser\parser.y" - { EndTypeDecl(); } -#line default - break; - case 166: // FunDecl -> INJ -#line 573 "API\Parser\parser.y" - { StartMapDecl(MapKind.Inj); } -#line default - break; - case 167: // FunDecl -> BIJ -#line 574 "API\Parser\parser.y" - { StartMapDecl(MapKind.Bij); } -#line default - break; - case 168: // FunDecl -> SUR -#line 575 "API\Parser\parser.y" - { StartMapDecl(MapKind.Sur); } -#line default - break; - case 169: // FunDecl -> FUN -#line 576 "API\Parser\parser.y" - { StartMapDecl(MapKind.Fun); } -#line default - break; - case 172: // Field -> UnnBody -#line 587 "API\Parser\parser.y" - { AppendField(null, false, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 173: // Field -> ANY, UnnBody -#line 589 "API\Parser\parser.y" - { AppendField(null, true, ToSpan(LocationStack[LocationStack.Depth-2])); } -#line default - break; - case 174: // Field -> BAREID, COLON, UnnBody -#line 592 "API\Parser\parser.y" - { AppendField(ValueStack[ValueStack.Depth-3].str, false, ToSpan(LocationStack[LocationStack.Depth-3])); } -#line default - break; - case 175: // Field -> BAREID, COLON, ANY, UnnBody -#line 596 "API\Parser\parser.y" - { AppendField(ValueStack[ValueStack.Depth-4].str, true, ToSpan(LocationStack[LocationStack.Depth-4])); } -#line default - break; - case 176: // MapArrow -> WEAKARROW -#line 600 "API\Parser\parser.y" - { SaveMapPartiality(true); } -#line default - break; - case 177: // MapArrow -> STRONGARROW -#line 601 "API\Parser\parser.y" - { SaveMapPartiality(false); } -#line default - break; - case 181: // Anon@37 -> /* empty */ -#line 615 "API\Parser\parser.y" - { StartEnum(ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 182: // UnnCmp -> LCBRACE, Anon@37, EnumList, RCBRACE -#line 617 "API\Parser\parser.y" - { EndEnum(); } -#line default - break; - case 183: // TypeId -> BAREID -#line 621 "API\Parser\parser.y" - { AppendUnion(new Nodes.Id(ToSpan(LocationStack[LocationStack.Depth-1]), ValueStack[ValueStack.Depth-1].str)); } -#line default - break; - case 184: // TypeId -> QUALID -#line 622 "API\Parser\parser.y" - { AppendUnion(new Nodes.Id(ToSpan(LocationStack[LocationStack.Depth-1]), ValueStack[ValueStack.Depth-1].str)); } -#line default - break; - case 187: // EnumCnst -> DIGITS -#line 633 "API\Parser\parser.y" - { AppendEnum(ParseNumeric(ValueStack[ValueStack.Depth-1].str, false, ToSpan(LocationStack[LocationStack.Depth-1]))); } -#line default - break; - case 188: // EnumCnst -> REAL -#line 634 "API\Parser\parser.y" - { AppendEnum(ParseNumeric(ValueStack[ValueStack.Depth-1].str, false, ToSpan(LocationStack[LocationStack.Depth-1]))); } -#line default - break; - case 189: // EnumCnst -> FRAC -#line 635 "API\Parser\parser.y" - { AppendEnum(ParseNumeric(ValueStack[ValueStack.Depth-1].str, true, ToSpan(LocationStack[LocationStack.Depth-1]))); } -#line default - break; - case 190: // EnumCnst -> String -#line 636 "API\Parser\parser.y" - { AppendEnum(GetString()); } -#line default - break; - case 191: // EnumCnst -> BAREID -#line 637 "API\Parser\parser.y" - { AppendEnum(new Nodes.Id(ToSpan(LocationStack[LocationStack.Depth-1]), ValueStack[ValueStack.Depth-1].str)); } -#line default - break; - case 192: // EnumCnst -> QUALID -#line 638 "API\Parser\parser.y" - { AppendEnum(new Nodes.Id(ToSpan(LocationStack[LocationStack.Depth-1]), ValueStack[ValueStack.Depth-1].str)); } -#line default - break; - case 193: // EnumCnst -> DIGITS, RANGE, DIGITS -#line 641 "API\Parser\parser.y" - { AppendEnum(new Nodes.Range(ToSpan(LocationStack[LocationStack.Depth-3]), ParseNumeric(ValueStack[ValueStack.Depth-3].str), ParseNumeric(ValueStack[ValueStack.Depth-1].str))); } -#line default - break; - case 194: // Anon@38 -> /* empty */ -#line 647 "API\Parser\parser.y" - { EndHeads(ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 195: // Rule -> FuncTermList, Anon@38, DOT -#line 648 "API\Parser\parser.y" - { AppendRule(); } -#line default - break; - case 196: // Anon@39 -> /* empty */ -#line 650 "API\Parser\parser.y" - { EndHeads(ToSpan(LocationStack[LocationStack.Depth-2])); } -#line default - break; - case 197: // Rule -> FuncTermList, RULE, Anon@39, BodyList, DOT -#line 652 "API\Parser\parser.y" - { AppendRule(); } -#line default - break; - case 198: // Anon@40 -> /* empty */ -#line 656 "API\Parser\parser.y" - { PushComprSymbol(ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 200: // ComprRest -> RCBRACE -#line 662 "API\Parser\parser.y" - { EndComprHeads(); PushArg(MkCompr()); } -#line default - break; - case 201: // Anon@41 -> /* empty */ -#line 663 "API\Parser\parser.y" - { EndComprHeads(); } -#line default - break; - case 202: // ComprRest -> PIPE, Anon@41, BodyList, RCBRACE -#line 665 "API\Parser\parser.y" - { PushArg(MkCompr()); } -#line default - break; - case 203: // BodyList -> Body -#line 669 "API\Parser\parser.y" - { AppendBody(); } -#line default - break; - case 204: // Anon@42 -> /* empty */ -#line 670 "API\Parser\parser.y" - { AppendBody(); } -#line default - break; - case 208: // Constraint -> FuncTerm -#line 685 "API\Parser\parser.y" - { AppendConstraint(MkFind(false, ToSpan(LocationStack[LocationStack.Depth-1]))); } -#line default - break; - case 209: // Constraint -> Id, IS, FuncTerm -#line 689 "API\Parser\parser.y" - { AppendConstraint(MkFind(true, ToSpan(LocationStack[LocationStack.Depth-3]))); } -#line default - break; - case 210: // Constraint -> NO, Compr -#line 692 "API\Parser\parser.y" - { AppendConstraint(MkNoConstr(ToSpan(LocationStack[LocationStack.Depth-2]))); } -#line default - break; - case 211: // Constraint -> NO, FuncTerm -#line 695 "API\Parser\parser.y" - { AppendConstraint(MkNoConstr(ToSpan(LocationStack[LocationStack.Depth-2]), false)); } -#line default - break; - case 212: // Constraint -> NO, Id, IS, FuncTerm -#line 700 "API\Parser\parser.y" - { AppendConstraint(MkNoConstr(ToSpan(LocationStack[LocationStack.Depth-4]), true)); } -#line default - break; - case 213: // Constraint -> FuncTerm, RelOp, FuncTerm -#line 704 "API\Parser\parser.y" - { AppendConstraint(MkRelConstr()); } -#line default - break; - case 214: // FuncTermList -> FuncOrCompr -#line 708 "API\Parser\parser.y" - { IncArity(); } -#line default - break; - case 215: // Anon@43 -> /* empty */ -#line 709 "API\Parser\parser.y" - { IncArity(); } -#line default - break; - case 220: // FuncTerm -> UnOp, FuncTerm -#line 723 "API\Parser\parser.y" - { PushArg(MkTerm(1)); } -#line default - break; - case 221: // FuncTerm -> FuncTerm, BinOp, FuncTerm -#line 727 "API\Parser\parser.y" - { PushArg(MkTerm(2)); } -#line default - break; - case 222: // Anon@44 -> /* empty */ -#line 730 "API\Parser\parser.y" - { PushSymbol(); } -#line default - break; - case 223: // FuncTerm -> Id, LPAREN, Anon@44, FuncTermList, RPAREN -#line 732 "API\Parser\parser.y" - { PushArg(MkTerm()); } -#line default - break; - case 224: // Anon@45 -> /* empty */ -#line 734 "API\Parser\parser.y" - { PushQuote(ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 225: // FuncTerm -> QSTART, Anon@45, QuoteList, QEND -#line 736 "API\Parser\parser.y" - { PushArg(PopQuote()); } -#line default - break; - case 229: // QuoteItem -> QUOTERUN -#line 750 "API\Parser\parser.y" - { AppendQuoteRun(ValueStack[ValueStack.Depth-1].str, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 230: // QuoteItem -> QUOTEESCAPE -#line 751 "API\Parser\parser.y" - { AppendQuoteEscape(ValueStack[ValueStack.Depth-1].str, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 231: // QuoteItem -> UQSTART, FuncTerm, UQEND -#line 754 "API\Parser\parser.y" - { AppendUnquote(); } -#line default - break; - case 234: // Id -> BAREID -#line 763 "API\Parser\parser.y" - { PushArg(new Nodes.Id(ToSpan(LocationStack[LocationStack.Depth-1]), ValueStack[ValueStack.Depth-1].str)); } -#line default - break; - case 235: // Id -> QUALID -#line 764 "API\Parser\parser.y" - { PushArg(new Nodes.Id(ToSpan(LocationStack[LocationStack.Depth-1]), ValueStack[ValueStack.Depth-1].str)); } -#line default - break; - case 236: // Constant -> DIGITS -#line 768 "API\Parser\parser.y" - { PushArg(ParseNumeric(ValueStack[ValueStack.Depth-1].str, false, ToSpan(LocationStack[LocationStack.Depth-1]))); } -#line default - break; - case 237: // Constant -> REAL -#line 769 "API\Parser\parser.y" - { PushArg(ParseNumeric(ValueStack[ValueStack.Depth-1].str, false, ToSpan(LocationStack[LocationStack.Depth-1]))); } -#line default - break; - case 238: // Constant -> FRAC -#line 770 "API\Parser\parser.y" - { PushArg(ParseNumeric(ValueStack[ValueStack.Depth-1].str, true, ToSpan(LocationStack[LocationStack.Depth-1]))); } -#line default - break; - case 239: // Constant -> String -#line 771 "API\Parser\parser.y" - { PushArg(GetString()); } -#line default - break; - case 240: // UnOp -> MINUS -#line 775 "API\Parser\parser.y" - { PushSymbol(OpKind.Neg, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 241: // BinOp -> MUL -#line 779 "API\Parser\parser.y" - { PushSymbol(OpKind.Mul, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 242: // BinOp -> DIV -#line 780 "API\Parser\parser.y" - { PushSymbol(OpKind.Div, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 243: // BinOp -> MOD -#line 781 "API\Parser\parser.y" - { PushSymbol(OpKind.Mod, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 244: // BinOp -> PLUS -#line 782 "API\Parser\parser.y" - { PushSymbol(OpKind.Add, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 245: // BinOp -> MINUS -#line 783 "API\Parser\parser.y" - { PushSymbol(OpKind.Sub, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 246: // RelOp -> EQ -#line 786 "API\Parser\parser.y" - { PushSymbol(RelKind.Eq, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 247: // RelOp -> NE -#line 787 "API\Parser\parser.y" - { PushSymbol(RelKind.Neq, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 248: // RelOp -> LT -#line 788 "API\Parser\parser.y" - { PushSymbol(RelKind.Lt, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 249: // RelOp -> LE -#line 789 "API\Parser\parser.y" - { PushSymbol(RelKind.Le, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 250: // RelOp -> GT -#line 790 "API\Parser\parser.y" - { PushSymbol(RelKind.Gt, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 251: // RelOp -> GE -#line 791 "API\Parser\parser.y" - { PushSymbol(RelKind.Ge, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 252: // RelOp -> COLON -#line 792 "API\Parser\parser.y" - { PushSymbol(RelKind.Typ, ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 255: // StrStart -> STRSNGSTART -#line 802 "API\Parser\parser.y" - { StartString(ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 256: // StrStart -> STRMULSTART -#line 803 "API\Parser\parser.y" - { StartString(ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 259: // StrBody -> STRSNG -#line 812 "API\Parser\parser.y" - { AppendString(ValueStack[ValueStack.Depth-1].str); } -#line default - break; - case 260: // StrBody -> STRSNGESC -#line 813 "API\Parser\parser.y" - { AppendSingleEscape(ValueStack[ValueStack.Depth-1].str); } -#line default - break; - case 261: // StrBody -> STRMUL -#line 814 "API\Parser\parser.y" - { AppendString(ValueStack[ValueStack.Depth-1].str); } -#line default - break; - case 262: // StrBody -> STRMULESC -#line 815 "API\Parser\parser.y" - { AppendMultiEscape(ValueStack[ValueStack.Depth-1].str); } -#line default - break; - case 263: // StrEnd -> STRSNGEND -#line 818 "API\Parser\parser.y" - { EndString(ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - case 264: // StrEnd -> STRMULEND -#line 819 "API\Parser\parser.y" - { EndString(ToSpan(LocationStack[LocationStack.Depth-1])); } -#line default - break; - } -#pragma warning restore 162, 1522 - } - - protected override string TerminalToString(int terminal) - { - if (aliasses != null && aliasses.ContainsKey(terminal)) - return aliasses[terminal]; - else if (((Tokens)terminal).ToString() != terminal.ToString(CultureInfo.InvariantCulture)) - return ((Tokens)terminal).ToString(); - else - return CharToString((char)terminal); - } - -#line 822 "API\Parser\parser.y" -#line default -} -} diff --git a/Src/Core/API/Parser/parser.y b/Src/Core/API/Parser/parser.y deleted file mode 100644 index 6fa365c..0000000 --- a/Src/Core/API/Parser/parser.y +++ /dev/null @@ -1,821 +0,0 @@ -%namespace Microsoft.Formula.API -%visibility internal - -%YYSTYPE LexValue -%partial - -%union { - public string str; -} - -%token DOMAIN MODEL TRANSFORM SYSTEM MACHINE PARTIAL -%token ENSURES REQUIRES CONFORMS -%token LCBRACE RCBRACE -%token LPAREN RPAREN -%token LSBRACE RSBRACE - -%token INCLUDES EXTENDS OF RETURNS -%token AT COLON -%token RENAMES RANGE -%token SOME ATLEAST ATMOST INITIALLY NEXT PROPERTY BOOT - -%token EQ TYPEDEF RULE PIPE -%token DOT -%token SEMICOLON -%token COMMA - -%token NO IS WEAKARROW STRONGARROW -%token NEW INJ BIJ SUR FUN ANY SUB -%token BAREID QUALID DIGITS REAL FRAC -%token STRSNGSTART STRSNG STRSNGESC STRSNGEND -%token STRMULSTART STRMUL STRMULESC STRMULEND -%token NE LT GT GE LE - -%left PLUS MINUS -%left MOD -%left DIV -%left MUL -%left UMINUS - -%token QSTART QEND UQSTART UQEND QUOTERUN QUOTEESCAPE - -%token RUNAWAYSTRING -%token ALIENCHAR -%token maxParseToken -%token LEX_WHITE LEX_COMMENT LEX_ERROR - -%% - -Program - : EOF - | Config - | ModuleList - | Config - ModuleList - ; - -ModuleList - : Module { EndModule(); } - | Module { EndModule(); } - ModuleList - ; - -Module - : Domain - | Model - | Transform - | TSystem - | Machine - ; - -/************** Machines ************/ - -Machine - : MachineSigConfig - LCBRACE - RCBRACE - - | MachineSigConfig - LCBRACE { SetModRefState(ModRefState.ModApply); } - MachineBody - RCBRACE - ; - -MachineBody - : MachineSentenceConf - | MachineSentenceConf - MachineBody - ; - -MachineSentenceConf - : MachineSentence - | SentenceConfig - MachineSentence - ; - -MachineSentence - : MachineProp - | BOOT { IsBuildingUpdate = false; } - Step - | INITIALLY { IsBuildingNext = false; IsBuildingUpdate = true; } - Update - | NEXT { IsBuildingNext = true; IsBuildingUpdate = true; } - Update - ; - -MachineProp - : PROPERTY - BAREID - EQ - FuncTerm - DOT { AppendProperty($2.str, ToSpan(@1)); } - ; - -/************** Machine Signature ************/ - -MachineSigConfig - : MachineSig { SetModRefState(ModRefState.None); } - | MachineSig { SetModRefState(ModRefState.None); } - Config - ; - -MachineSig - : MACHINE - BAREID { StartMachine($2.str, ToSpan(@2)); } - MachineSigIn - OF { SetModRefState(ModRefState.Other); } - ModRefs - ; - -MachineSigIn - : LPAREN - RPAREN - | LPAREN - VoMParamList - RPAREN - ; - -/************** Models ************/ - -Model - : ModelSigConfig - LCBRACE - RCBRACE - - | ModelSigConfig - LCBRACE - ModelBody - RCBRACE - ; - -ModelBody - : ModelSentence - | ModelSentence - ModelBody - ; - -ModelSentence - : ModelFactList - | ModelContractConf - ; - -ModelContractConf - : ModelContract - | SentenceConfig - ModelContract - ; - -ModelContract - : ENSURES { StartPropContract(ContractKind.EnsuresProp, ToSpan(@1)); } - BodyList - DOT - - | REQUIRES { StartPropContract(ContractKind.RequiresProp, ToSpan(@1)); } - BodyList - DOT - - | REQUIRES - CardSpec - DIGITS - Id { AppendCardContract($2.str, ParseInt($3.str, ToSpan(@3)), ToSpan(@1)); } - DOT - ; - -ModelFactList - : ModelFact - DOT - - | SentenceConfig - ModelFact - DOT - - | ModelFact - COMMA - ModelFactList - - | SentenceConfig - ModelFact - COMMA - ModelFactList - ; - -ModelFact - : FuncTerm { AppendFact(MkFact(false, ToSpan(@1))); } - | BAREID - IS { PushArg(new Nodes.Id(ToSpan(@1), $1.str)); } - FuncTerm { AppendFact(MkFact(true, ToSpan(@1))); } - ; - -CardSpec - : SOME - | ATMOST - | ATLEAST - ; - -/************** Model Signatures ************/ - -ModelSigConfig - : ModelSig { SetModRefState(ModRefState.None); } - | ModelSig { SetModRefState(ModRefState.None); } - Config - ; - -ModelSig - : ModelIntro - | ModelIntro - INCLUDES { SetCompose(ComposeKind.Includes); SetModRefState(ModRefState.Input); } - ModRefs - | ModelIntro - EXTENDS { SetCompose(ComposeKind.Extends); SetModRefState(ModRefState.Input); } - ModRefs - ; - -ModelIntro - : MODEL - BAREID { StartModel($2.str, false, ToSpan(@1)); } - OF - ModRef - - | PARTIAL - MODEL - BAREID { StartModel($3.str, true, ToSpan(@1)); } - OF - ModRef - ; - -/************** Transform Systems ************/ - -TSystem - : TRANSFORM - SYSTEM - BAREID { StartTSystem($3.str, ToSpan(@1)); } - TSystemRest - ; - -TSystemRest - : TransformSigConfig - LCBRACE - RCBRACE - - | TransformSigConfig - LCBRACE { IsBuildingUpdate = false; SetModRefState(ModRefState.ModApply); } - TransSteps - RCBRACE - ; - -TransSteps - : TransStepConfig - | TransStepConfig - TransSteps - ; - -TransStepConfig - : Step - | SentenceConfig - Step - ; - -/************** Transforms ************/ - -Transform - : TRANSFORM - BAREID { StartTransform($2.str, ToSpan(@1)); } - TransformRest - ; - -TransformRest - : TransformSigConfig - LCBRACE - RCBRACE - - | TransformSigConfig - LCBRACE - TransBody - RCBRACE - ; - -TransBody - : TransSentenceConfig - | TransSentenceConfig - TransBody - ; - -TransSentenceConfig - : TransSentence - | SentenceConfig - TransSentence - ; - -TransSentence - : Rule - | TypeDecl - | ENSURES { StartPropContract(ContractKind.EnsuresProp, ToSpan(@1)); } - BodyList - DOT - | REQUIRES { StartPropContract(ContractKind.RequiresProp, ToSpan(@1)); } - BodyList - DOT - ; - -/************** Transform Signatures ************/ - -TransformSigConfig - : TransformSig { SetModRefState(ModRefState.None); } - | TransformSig { SetModRefState(ModRefState.None); } - Config - ; - -TransformSig - : TransSigIn - RETURNS - LPAREN { SetModRefState(ModRefState.Output); } - ModelParamList - RPAREN - ; - -TransSigIn - : LPAREN - RPAREN - | LPAREN - VoMParamList - RPAREN - ; - -/************** Domains ************/ - -Domain - : DomainSigConfig - LCBRACE - RCBRACE - - | DomainSigConfig - LCBRACE - DomSentences - RCBRACE - ; - -DomSentences - : DomSentenceConfig - | DomSentenceConfig - DomSentences - ; - -DomSentenceConfig - : DomSentence - | SentenceConfig - DomSentence - ; - -DomSentence - : Rule - | TypeDecl - | CONFORMS { StartPropContract(ContractKind.ConformsProp, ToSpan(@1)); } - BodyList - DOT - ; - -/*************** Domain Signature ***************/ - -DomainSigConfig - : DomainSig { SetModRefState(ModRefState.None); } - | DomainSig { SetModRefState(ModRefState.None); } - Config - ; - -DomainSig - : DOMAIN - BAREID { StartDomain($2.str, ComposeKind.None, ToSpan(@1)); } - - | DOMAIN - BAREID - EXTENDS { StartDomain($2.str, ComposeKind.Extends, ToSpan(@1)); } - ModRefs - - | DOMAIN - BAREID - INCLUDES { StartDomain($2.str, ComposeKind.Includes, ToSpan(@1)); } - ModRefs - ; - -/************** Configurations ************/ - -Config - : LSBRACE - SettingList - RSBRACE - ; - -SentenceConfig - : LSBRACE { StartSentenceConfig(ToSpan(@1)); } - SettingList - RSBRACE - ; - -SettingList - : Setting - | Setting - COMMA - SettingList - ; - -Setting - : Id - EQ - Constant { AppendSetting(); } - ; - -/************** Parameters ************/ - -ModelParamList - : ModRefRename - | ModRefRename - COMMA - ModelParamList - ; - -ValOrModelParam - : BAREID - COLON - UnnBody { AppendParam($1.str, ToSpan(@1)); } - | ModRefRename - ; - -VoMParamList - : ValOrModelParam - | ValOrModelParam - COMMA - VoMParamList - ; - -/************** Steps and Updates ************/ - -Update - : StepOrUpdateLHS - EQ - ChoiceList - DOT { AppendUpdate(); } - ; - -Step - : StepOrUpdateLHS - EQ - ModApply - DOT { AppendStep(); } - ; - -ChoiceList - : ModApply { AppendChoice(); } - | ModApply { AppendChoice(); } - SEMICOLON - ChoiceList - ; - -ModApply - : ModRef - LPAREN - RPAREN { PushArg(MkModApply()); } - - | ModRef - LPAREN - ModArgList - RPAREN { PushArg(MkModApply()); } - ; - -ModArgList - : ModAppArg { IncArity(); } - | ModAppArg { IncArity(); } - COMMA - ModArgList - ; - -ModAppArg - : FuncTerm - | BAREID - AT - String { PushArg(new Nodes.ModRef(ToSpan(@1), $1.str, null, GetStringValue())); } - ; - -StepOrUpdateLHS - : Id { AppendLHS(); } - | Id { AppendLHS(); } - COMMA - StepOrUpdateLHS - ; - -/************** Module References ************/ - -ModRefs - : ModRef - | ModRef - COMMA - ModRefs - ; - -ModRef - : ModRefRename - | ModRefNoRename - ; - -ModRefRename - : BAREID - RENAMES - BAREID { AppendModRef(new Nodes.ModRef(ToSpan(@1), $3.str, $1.str, null)); } - - | BAREID - RENAMES - BAREID - AT - String { AppendModRef(new Nodes.ModRef(ToSpan(@1), $3.str, $1.str, GetStringValue())); } - ; - -ModRefNoRename - : BAREID { AppendModRef(new Nodes.ModRef(ToSpan(@1), $1.str, null, null)); } - | BAREID - AT - String { AppendModRef(new Nodes.ModRef(ToSpan(@1), $1.str, null, GetStringValue())); } - ; - -/**************** Type Decls *****************/ - -TypeDecl - : BAREID { SaveTypeDeclName($1.str, ToSpan(@1)); } - TYPEDEF - TypeDeclBody - DOT - ; - -TypeDeclBody - : UnnBody { EndUnnDecl(); } - - | LPAREN { StartConDecl(false, false); } - Fields - RPAREN { EndTypeDecl(); } - - | SUB { StartConDecl(false, true); } - LPAREN - Fields - RPAREN { EndTypeDecl(); } - - | NEW { StartConDecl(true, false); } - LPAREN - Fields - RPAREN { EndTypeDecl(); } - - | FunDecl - LPAREN - Fields - MapArrow - Fields - RPAREN { EndTypeDecl(); } - ; - -FunDecl - : INJ { StartMapDecl(MapKind.Inj); } - | BIJ { StartMapDecl(MapKind.Bij); } - | SUR { StartMapDecl(MapKind.Sur); } - | FUN { StartMapDecl(MapKind.Fun); } - ; - -Fields - : Field - | Field - COMMA - Fields - ; - -Field - : UnnBody { AppendField(null, false, ToSpan(@1)); } - | ANY - UnnBody { AppendField(null, true, ToSpan(@1)); } - | BAREID - COLON - UnnBody { AppendField($1.str, false, ToSpan(@1)); } - | BAREID - COLON - ANY - UnnBody { AppendField($1.str, true, ToSpan(@1)); } - ; - -MapArrow - : WEAKARROW { SaveMapPartiality(true); } - | STRONGARROW { SaveMapPartiality(false); } - ; - -/**************** Type Terms *****************/ - -UnnBody - : UnnCmp - | UnnCmp - PLUS - UnnBody - ; - -UnnCmp - : TypeId - | LCBRACE { StartEnum(ToSpan(@1)); } - EnumList - RCBRACE { EndEnum(); } - ; - -TypeId - : BAREID { AppendUnion(new Nodes.Id(ToSpan(@1), $1.str)); } - | QUALID { AppendUnion(new Nodes.Id(ToSpan(@1), $1.str)); } - ; - -EnumList - : EnumCnst - | EnumCnst - COMMA - EnumList - ; - -EnumCnst - : DIGITS { AppendEnum(ParseNumeric($1.str, false, ToSpan(@1))); } - | REAL { AppendEnum(ParseNumeric($1.str, false, ToSpan(@1))); } - | FRAC { AppendEnum(ParseNumeric($1.str, true, ToSpan(@1))); } - | String { AppendEnum(GetString()); } - | BAREID { AppendEnum(new Nodes.Id(ToSpan(@1), $1.str)); } - | QUALID { AppendEnum(new Nodes.Id(ToSpan(@1), $1.str)); } - | DIGITS - RANGE - DIGITS { AppendEnum(new Nodes.Range(ToSpan(@1), ParseNumeric($1.str), ParseNumeric($3.str))); } - ; - -/************* Facts, Rules, and Comprehensions **************/ - -Rule - : FuncTermList { EndHeads(ToSpan(@1)); } - DOT { AppendRule(); } - | FuncTermList - RULE { EndHeads(ToSpan(@1)); } - BodyList - DOT { AppendRule(); } - ; - -Compr - : LCBRACE { PushComprSymbol(ToSpan(@1)); } - FuncTermList - ComprRest - ; - -ComprRest - : RCBRACE { EndComprHeads(); PushArg(MkCompr()); } - | PIPE { EndComprHeads(); } - BodyList - RCBRACE { PushArg(MkCompr()); } - ; - -BodyList - : Body { AppendBody(); } - | Body { AppendBody(); } - SEMICOLON - BodyList - ; - -Body - : Constraint - | Constraint - COMMA - Body - ; - -/******************* Terms and Constraints *******************/ - -Constraint - : FuncTerm { AppendConstraint(MkFind(false, ToSpan(@1))); } - - | Id - IS - FuncTerm { AppendConstraint(MkFind(true, ToSpan(@1))); } - - | NO - Compr { AppendConstraint(MkNoConstr(ToSpan(@1))); } - - | NO - FuncTerm { AppendConstraint(MkNoConstr(ToSpan(@1), false)); } - - | NO - Id - IS - FuncTerm { AppendConstraint(MkNoConstr(ToSpan(@1), true)); } - - | FuncTerm - RelOp - FuncTerm { AppendConstraint(MkRelConstr()); } - ; - -FuncTermList - : FuncOrCompr { IncArity(); } - | FuncOrCompr { IncArity(); } - COMMA - FuncTermList - ; - -FuncOrCompr - : FuncTerm - | Compr - ; - -FuncTerm - : Atom - - | UnOp - FuncTerm %prec UMINUS { PushArg(MkTerm(1)); } - - | FuncTerm - BinOp - FuncTerm { PushArg(MkTerm(2)); } - - | Id - LPAREN { PushSymbol(); } - FuncTermList - RPAREN { PushArg(MkTerm()); } - - | QSTART { PushQuote(ToSpan(@1)); } - QuoteList - QEND { PushArg(PopQuote()); } - - | LPAREN - FuncTerm - RPAREN - ; - -QuoteList - : QuoteItem - | QuoteItem - QuoteList - ; - -QuoteItem - : QUOTERUN { AppendQuoteRun($1.str, ToSpan(@1)); } - | QUOTEESCAPE { AppendQuoteEscape($1.str, ToSpan(@1)); } - | UQSTART - FuncTerm - UQEND { AppendUnquote(); } - ; - -Atom - : Id - | Constant - ; - -Id - : BAREID { PushArg(new Nodes.Id(ToSpan(@1), $1.str)); } - | QUALID { PushArg(new Nodes.Id(ToSpan(@1), $1.str)); } - ; - -Constant - : DIGITS { PushArg(ParseNumeric($1.str, false, ToSpan(@1))); } - | REAL { PushArg(ParseNumeric($1.str, false, ToSpan(@1))); } - | FRAC { PushArg(ParseNumeric($1.str, true, ToSpan(@1))); } - | String { PushArg(GetString()); } - ; - -UnOp - : MINUS { PushSymbol(OpKind.Neg, ToSpan(@1)); } - ; - -BinOp - : MUL { PushSymbol(OpKind.Mul, ToSpan(@1)); } - | DIV { PushSymbol(OpKind.Div, ToSpan(@1)); } - | MOD { PushSymbol(OpKind.Mod, ToSpan(@1)); } - | PLUS { PushSymbol(OpKind.Add, ToSpan(@1)); } - | MINUS { PushSymbol(OpKind.Sub, ToSpan(@1)); } - ; - -RelOp : EQ { PushSymbol(RelKind.Eq, ToSpan(@1)); } - | NE { PushSymbol(RelKind.Neq, ToSpan(@1)); } - | LT { PushSymbol(RelKind.Lt, ToSpan(@1)); } - | LE { PushSymbol(RelKind.Le, ToSpan(@1)); } - | GT { PushSymbol(RelKind.Gt, ToSpan(@1)); } - | GE { PushSymbol(RelKind.Ge, ToSpan(@1)); } - | COLON { PushSymbol(RelKind.Typ, ToSpan(@1)); } - ; - -String : StrStart - StrBodyList - StrEnd - | StrStart - StrEnd - ; - -StrStart : STRSNGSTART { StartString(ToSpan(@1)); } - | STRMULSTART { StartString(ToSpan(@1)); } - ; - -StrBodyList - : StrBody - | StrBody - StrBodyList - ; - -StrBody : STRSNG { AppendString($1.str); } - | STRSNGESC { AppendSingleEscape($1.str); } - | STRMUL { AppendString($1.str); } - | STRMULESC { AppendMultiEscape($1.str); } - ; - -StrEnd : STRSNGEND { EndString(ToSpan(@1)); } - | STRMULEND { EndString(ToSpan(@1)); } - ; -%%