From dffb119d3f4ca367365e1770327afe41e6edfa03 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Thu, 18 May 2017 15:25:35 -0700 Subject: [PATCH 01/24] Add files via upload NEW: A) The First and Follow methods in NonTerminals. B) TokenSet.cs C) Various changes implemented to help with A) and B) (marked with //SAM CHANGE for easy location) Notes: The newFromUnion() method in TokenSet.cs has two implementations: One, based on the C compiler, is the one currently in use. This one I believe to be more efficient. The other has been commented out. This one is more readable in my opinion. These changes should be ready to be committed into master. For now I will leave them in a separate branch for any desired review before that happens. --- NonTerminals.cs | 162 ++++++++++++++ Terminals.cs | 525 +++++++++++++++++++++++++++++++++++++++++++ TokenSet.cs | 578 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1265 insertions(+) create mode 100644 NonTerminals.cs create mode 100644 Terminals.cs create mode 100644 TokenSet.cs diff --git a/NonTerminals.cs b/NonTerminals.cs new file mode 100644 index 0000000..035822c --- /dev/null +++ b/NonTerminals.cs @@ -0,0 +1,162 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * NonTerminals.cs + * + * provides FIRST() and FOLLOW() sets for each non-terminal symbol //SAM CHANGE + * used by the parser class for syntax analysis + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +namespace org.m2sf.m2sharp { + + using System; + using System.Collections.Generic; + +public class NonTerminals : INonTerminals { + + public static Production firstConstParamDependent = Production.FormalType, + lastConstParamDependent = Production.AttribFormalParams, + firstNoVariantRecDependent = Production.TypeDeclarationTail, + lastNoVariantRecDependent = Production.TypeDeclarationTail, + firstOptionDependent = firstConstParamDependent, + lastOptionDependent = lastNoVariantRecDependent; + public static int alternateSetOffset = (int)lastOptionDependent - (int)firstOptionDependent + 1; + + /* -------------------------------------------------------------------------- + * method Count() -- Returns the number of productions + * ----------------------------------------------------------------------- */ //SAM CHANGE + + uint Count() { + uint total = 0; + foreach (String s in Enum.GetNames(typeof(Production))) { + total++; + } + return total; + } /* end Count */ + + + /* -------------------------------------------------------------------------- + * method IsOptionDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on any compiler option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsOptionDependent(Production p) { + return p >= firstOptionDependent; + } /* end IsOptionDependent */ + + + /* -------------------------------------------------------------------------- + * method IsConstParamDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on CONST parameter option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsConstParamDependent(Production p) + { + return p >= firstConstParamDependent && p <= lastConstParamDependent; + } /* end IsConstParamDependent */ + + + /* -------------------------------------------------------------------------- + * method IsVariantRecordDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on variant record type option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsVariantRecordDependent(Production p) { + return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; + } + + /* -------------------------------------------------------------------------- + * method FIRST(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FIRST set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FIRST(Production p) { + TokenSet tokenset = null; + + if (IsConstParamDependent(p)) + { + p += alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) + { + p += alternateSetOffset; + } /* end if */ + + return tokenset; + } /* end FIRST */ + + + /* -------------------------------------------------------------------------- + * method FOLLOW(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FOLLOW set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FOLLOW(Production p) { + TokenSet tokenset = null; + + if (IsConstParamDependent(p)) { + p += alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { + p += alternateSetOffset; + } /* end if */ + + return tokenset; + } /* end FOLLOW */ + + + /* -------------------------------------------------------------------------- + * method NameForProduction(p) + * -------------------------------------------------------------------------- + * Returns a string with a human readable name for production p. + * ----------------------------------------------------------------------- */ + + string NameForProduction(Production p); + + + +} /* NonTerminals */ + +} /* namespace */ \ No newline at end of file diff --git a/Terminals.cs b/Terminals.cs new file mode 100644 index 0000000..b8227ce --- /dev/null +++ b/Terminals.cs @@ -0,0 +1,525 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * Terminals.cs + * + * Terminal symbols' token and lexeme lookup. + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +namespace org.m2sf.m2sharp { + +public class Terminals : ITerminals { + +const Token FirstResWord = Token.AND; +const Token LastResWord = Token.WITH; + +const Token FirstLiteral = Token.StringLiteral; +const Token LastLiteral = Token.CharLiteral; + +const Token FirstMalformedLiteral = Token.MalformedString; +const Token LastMalformedLiteral = Token.MalformedReal; + +const Token FirstSpecialSymbol = Token.Plus; +const Token LastSpecialSymbol = Token.RightBrace; + +public const int tokenEndMark = (int)Token.EndOfFile + 1; //SAM CHANGE + + +/* --------------------------------------------------------------------------- + * method IsValid(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a valid token, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsValid (Token token) { + return (token != Token.Unknown) && !IsMalformedLiteral(token); +} /* end IsValid */ + + +/* --------------------------------------------------------------------------- + * method IsResword(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a reserved word, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsResword (Token token) { + return (token >= FirstResWord) && (token <= LastResWord); +} /* end IsResword */ + + +/* --------------------------------------------------------------------------- + * method IsLiteral(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a literal, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsLiteral (Token token) { + return (token >= FirstLiteral) && (token <= LastLiteral); +} /* end IsLiteral */ + + +/* --------------------------------------------------------------------------- + * method IsMalformedLiteral(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a malformed literal, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsMalformedLiteral (Token token) { + return (token >= FirstMalformedLiteral) && (token <= LastMalformedLiteral); +} /* end IsMalformedLiteral */ + + +/* --------------------------------------------------------------------------- + * method IsSpecialSymbol(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a special symbol, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsSpecialSymbol (Token token) { + return (token >= FirstSpecialSymbol) && (token <= LastSpecialSymbol); +} /* end IsSpecialSymbol */ + + +/* --------------------------------------------------------------------------- + * method TokenForResword(lexeme) + * --------------------------------------------------------------------------- + * Tests if the given lexeme represents a reserved word and returns the + * corresponding token or Unknown if it does not match a reserved word. + * ------------------------------------------------------------------------ */ + +public static Token TokenForResword (string lexeme) { + int length; + + /* check pre-conditions */ + if (lexeme == null) { + return Token.Unknown; + } /* end if */ + + length = lexeme.Length; + + if ((length < 2) || (length > 14)) { + return Token.Unknown; + } /* end if */ + + switch (length) { + case /* length = 2 */ 2 : + switch (lexeme[0]) { + + case 'B' : + /* BY */ + if (lexeme[1] == 'Y') { + return Token.BY; + } /* end if */ + break; + + case 'D' : + /* DO */ + if (lexeme[1] == 'O') { + return Token.DO; + } /* end if */ + break; + + case 'I' : + /* IF */ + if (lexeme[1] == 'F') { + return Token.IF; + } + + /* IN */ + else if (lexeme[1] == 'N') { + return Token.IN; + } /* end if */ + break; + + case 'O' : + /* OF */ + if (lexeme[1] == 'F') { + return Token.OF; + } + + /* OR */ + else if (lexeme[1] == 'R') { + return Token.OR; + } /* end if */ + break; + + case 'T' : + /* TO */ + if (lexeme[1] == 'O') { + return Token.TO; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 3 */ 3 : + switch (lexeme[0]) { + + case 'A' : + /* AND */ + if (string.CompareOrdinal(lexeme, "AND") == 0) { + return Token.AND; + } /* end if */ + break; + + case 'D' : + /* DIV */ + if (string.CompareOrdinal(lexeme, "DIV") == 0) { + return Token.DIV; + } /* end if */ + break; + + case 'E' : + /* END */ + if (string.CompareOrdinal(lexeme, "END") == 0) { + return Token.END; + } /* end if */ + break; + + case 'F' : + /* FOR */ + if (string.CompareOrdinal(lexeme, "FOR") == 0) { + return Token.FOR; + } /* end if */ + break; + + case 'M' : + /* MOD */ + if (string.CompareOrdinal(lexeme, "MOD") == 0) { + return Token.MOD; + } /* end if */ + break; + + case 'N' : + /* NOT */ + if (string.CompareOrdinal(lexeme, "NOT") == 0) { + return Token.NOT; + } /* end if */ + break; + + case 'S' : + /* SET */ + if (string.CompareOrdinal(lexeme, "SET") == 0) { + return Token.SET; + } /* end if */ + break; + + case 'V' : + /* VAR */ + if (string.CompareOrdinal(lexeme, "VAR") == 0) { + return Token.VAR; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 4 */ 4 : + switch (lexeme[1]) { + + case 'A' : + /* CASE */ + if (string.CompareOrdinal(lexeme, "CASE") == 0) { + return Token.CASE; + } /* end if */ + break; + + case 'H' : + /* THEN */ + if (string.CompareOrdinal(lexeme, "THEN") == 0) { + return Token.THEN; + } /* end if */ + break; + + case 'I' : + /* WITH */ + if (string.CompareOrdinal(lexeme, "WITH") == 0) { + return Token.WITH; + } /* end if */ + break; + + case 'L' : + /* ELSE */ + if (string.CompareOrdinal(lexeme, "ELSE") == 0) { + return Token.ELSE; + } /* end if */ + break; + + case 'O' : + /* LOOP */ + if (string.CompareOrdinal(lexeme, "LOOP") == 0) { + return Token.LOOP; + } /* end if */ + break; + + case 'R' : + /* FROM */ + if (string.CompareOrdinal(lexeme, "FROM") == 0) { + return Token.FROM; + } /* end if */ + break; + + case 'X' : + /* EXIT */ + if (string.CompareOrdinal(lexeme, "EXIT") == 0) { + return Token.EXIT; + } /* end if */ + break; + + case 'Y' : + /* TYPE */ + if (string.CompareOrdinal(lexeme, "TYPE") == 0) { + return Token.TYPE; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 5 */ 5 : + switch (lexeme[0]) { + + case 'A' : + /* ARRAY */ + if (string.CompareOrdinal(lexeme, "ARRAY") == 0) { + return Token.ARRAY; + } /* end if */ + break; + + case 'B' : + /* BEGIN */ + if (string.CompareOrdinal(lexeme, "BEGIN") == 0) { + return Token.BEGIN; + } /* end if */ + break; + + case 'C' : + /* CONST */ + if (string.CompareOrdinal(lexeme, "CONST") == 0) { + return Token.CONST; + } /* end if */ + break; + + case 'E' : + /* ELSIF */ + if (string.CompareOrdinal(lexeme, "ELSIF") == 0) { + return Token.ELSIF; + } /* end if */ + break; + + case 'U' : + /* UNTIL */ + if (string.CompareOrdinal(lexeme, "UNTIL") == 0) { + return Token.UNTIL; + } /* end if */ + break; + + case 'W' : + /* WHILE */ + if (string.CompareOrdinal(lexeme, "WHILE") == 0) { + return Token.WHILE; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length 6 */ 6 : + switch (lexeme[5]) { + + case 'E' : + /* MODULE */ + if (string.CompareOrdinal(lexeme, "MODULE") == 0) { + return Token.MODULE; + } /* end if */ + break; + + case 'D' : + /* RECORD */ + if (string.CompareOrdinal(lexeme, "RECORD") == 0) { + return Token.RECORD; + } /* end if */ + break; + + case 'N' : + /* RETURN */ + if (string.CompareOrdinal(lexeme, "RETURN") == 0) { + return Token.RETURN; + } /* end if */ + break; + + case 'T' : + switch (lexeme[0]) { + + case 'E' : + /* EXPORT */ + if (string.CompareOrdinal(lexeme, "EXPORT") == 0) { + return Token.EXPORT; + } /* end if */ + break; + + case 'I' : + /* IMPORT */ + if (string.CompareOrdinal(lexeme, "IMPORT") == 0) { + return Token.IMPORT; + } /* end if */ + break; + + case 'R' : + /* REPEAT */ + if (string.CompareOrdinal(lexeme, "REPEAT") == 0) { + return Token.REPEAT; + } /* end if */ + break; + + } /* end switch */ + break; + + } /* end switch */ + break; + + case /* length = 7 */ 7 : + switch (lexeme[0]) { + + case 'A' : + /* ARGLIST */ + if (string.CompareOrdinal(lexeme, "ARGLIST") == 0) { + return Token.ARGLIST; + } /* end if */ + break; + + case 'P' : + /* POINTER */ + if (string.CompareOrdinal(lexeme, "POINTER") == 0) { + return Token.POINTER; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 9 */ 9 : + switch (lexeme[0]) { + + case 'P' : + /* PROCEDURE */ + if (string.CompareOrdinal(lexeme, "PROCEDURE") == 0) { + return Token.PROCEDURE; + } /* end if */ + break; + + case 'Q' : + /* QUALIFIED */ + if (string.CompareOrdinal(lexeme, "QUALIFIED") == 0) { + return Token.QUALIFIED; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 10 */ 10 : + /* DEFINITION */ + if (string.CompareOrdinal(lexeme, "DEFINITION") == 0) { + return Token.DEFINITION; + } /* end if */ + break; + + case /* length = 14 */ 14 : + /* IMPLEMENTATION */ + if (string.CompareOrdinal(lexeme, "IMPLEMENTATION") == 0) { + return Token.IMPLEMENTATION; + } /* end if */ + break; + + } /* end switch (length) */ + + return Token.Unknown; +} /* end TokenForResword */ + + +/* --------------------------------------------------------------------------- + * method LexemeForResword(token) + * --------------------------------------------------------------------------- + * Returns a string with the lexeme for the reserved word represented by + * token. Returns null if the token does not represent a reserved word. + * ------------------------------------------------------------------------ */ + +public static string LexemeForResword (Token token) { + if (IsResword(token) == false) { + return null; + } /* end if */ + return token.ToString(); +} /* end LexemeForResword */ + + +/* --------------------------------------------------------------------------- + * method LexemeForSpecialSymbol(token) + * --------------------------------------------------------------------------- + * Returns a string with the lexeme for the special symbol represented by + * token. Returns null if the token does not represent a special symbol. + * ------------------------------------------------------------------------ */ + +public static string LexemeForSpecialSymbol (Token token) { + if (IsSpecialSymbol(token) == false) { + return null; + } /* end if */ + return ""; // TO DO +} /* end LexemeForSpecialSymbol */ + + +/* --------------------------------------------------------------------------- + * method NameForToken(token) + * --------------------------------------------------------------------------- + * Returns a string with a human readable name for token. Returns null if + * token is not a valid token. + * ------------------------------------------------------------------------ */ + +public static string NameForToken (Token token) { + return token.ToString(); +} /* NameForToken */ + + +} /* Terminals */ + +} /* namespace */ + +/* END OF FILE */ \ No newline at end of file diff --git a/TokenSet.cs b/TokenSet.cs new file mode 100644 index 0000000..9811db5 --- /dev/null +++ b/TokenSet.cs @@ -0,0 +1,578 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * TokenSet.cs + * + * A set of Token type variables which is used to pass First and Follow sets + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace org.m2sf.m2sharp +{ + + public class TokenSet : ITokenSet { + + /* Lexeme Table */ + public static string[] lexemeTable = { + /* Null Token */ + + "UNKNOWN", + + /* Reserved Words */ + + "AND", + "ARGLIST", + "ARRAY", + "BEGIN", + "BY", + "CASE", + "CONST", + "DEFINITION", + "DIV", + "DO", + "ELSE", + "ELSIF", + "END", + "EXIT", + "EXPORT", + "FOR", + "FROM", + "IF", + "IMPLEMENTATION", + "IMPORT", + "IN", + "LOOP", + "MOD", + "MODULE", + "NOT", + "OF", + "OR", + "POINTER", + "PROCEDURE", + "QUALIFIED", + "RECORD", + "REPEAT", + "RETURN", + "SET", + "THEN", + "TO", + "TYPE", + "UNTIL", + "VAR", + "WHILE", + "WITH", + + /* Identifiers */ + + "IDENTIFIER", + + /* Literals */ + + "STRING-LITERAL", + "INTEGER-LITERAL", + "REAL-LITERAL", + "CHAR-LITERAL", + + "MALFORMED-STRING", + "MALFORMED-INTEGER", + "MALFORMED-REAL", + + /* Pragmas */ + + "PRAGMA", + + /* Special Symbols */ + + "PLUS", + "MINUS", + "EQUAL", + "NOTEQUAL", + "LESS-THAN", + "LESS-OR-EQUAL", + "GREATER-THAN", + "GREATER-OR-EQUAL", + "ASTERISK", + "SOLIDUS", + "BACKSLASH", + "ASSIGNMENT", + "COMMA", + "PERIOD", + "COLON", + "SEMICOLON", + "RANGE", + "DEREF", + "VERTICAL-BAR", + "LEFT-PAREN", + "RIGHT-PAREN", + "LEFT-BRACKET", + "RIGHT-BRACKET", + "LEFT-BRACE", + "RIGHT-BRACE", + "END-OF-FILE", + + /* out-of-range guard */ + + "\0" + +}; /* end m2c_token_name_table */ + + public static int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; + + public struct opaque + { + public uint[] segments; + public uint elemCount; + } /* end struct */ + + opaque dataStored; + + /* --------------------------------------------------------------------------- + * private constructor TokenSet () + * --------------------------------------------------------------------------- + * Prevents clients from invoking the default constructor. + * ------------------------------------------------------------------------ */ + + private TokenSet() + { + // no operation + } /* end TokenSet */ + + /* -------------------------------------------------------------------------- + * constructor newFromList(token, ...) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object that includes the tokens passed + * as arguments of a variadic argument list. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromList(params Token[] tokenList) + { + TokenSet newSet = new TokenSet(); + uint bit, segmentIndex; + Token token; + + /* allocate new set */ + newSet.dataStored.segments = new uint[segmentCount]; + + /* initialise */ + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + newSet.dataStored.segments[segmentIndex] = 0; + } /* end For */ + + /* store tokens from list */ + token = tokenList[0]; + for (int i = 1; token != Token.Unknown; i++) + { + + if (token <= Token.EndOfFile) + { + segmentIndex = (uint)token / 32; + bit = (uint)token % 32; + newSet.dataStored.segments[segmentIndex] = (newSet.dataStored.segments[segmentIndex] | (uint)(1 << (int)bit)); + } /* end if */ + + /* get next token in list */ + token = tokenList[i]; + } /* end while */ + + /* update element counter */ + newSet.dataStored.elemCount = CountBits(newSet); + + return newSet; + } /* end newFromList */ + + + /* -------------------------------------------------------------------------- + * constructor newFromUnion(set, ...) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object that represents the set union of + * the tokensets passed as arguments of a non-empty variadic argument list. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromUnion(params TokenSet[] setList) + { + uint segmentIndex; + TokenSet set, + newSet = new TokenSet(); + + + /* initialise */ + newSet.dataStored.segments = new uint[segmentCount]; + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + newSet.dataStored.segments[segmentIndex] = 0; + } /* end for */ + + set = setList[0]; + /* calculate union with each set in list */ + for (int i = 0; set != null; i++) + { + /* for each segment ... */ + while (segmentIndex < segmentCount) + { + /* ... store union of corresponding segments */ + newSet.dataStored.segments[segmentIndex] = + newSet.dataStored.segments[segmentIndex] | newSet.dataStored.segments[segmentIndex]; + + /* next segment */ + segmentIndex++; + } /* end while */ + + /*get next set in list */ + if (i < setList.Length) + set = setList[i]; + else + set = null; + + } /* end for */ + + /* update element counter */ + newSet.dataStored.elemCount = CountBits(newSet); + + return newSet; + } /* end newFromUnion + +/* -------------------------------------------------------------------------- + * method Count() + * -------------------------------------------------------------------------- + * Returns the number of elements in the receiver. + * ----------------------------------------------------------------------- */ + + public uint Count() + { + + return this.dataStored.elemCount; + } /* end IsElement */ + + + /* -------------------------------------------------------------------------- + * method IsElement(token) + * -------------------------------------------------------------------------- + * Returns true if token is an element of the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsElement(Token token) + { + int segmentIndex, bit; + + if (token > Token.EndOfFile) + { + return false; + } /* end if */ + + segmentIndex = (int)token / 32; + bit = (int)token % 32; + + return (this.dataStored.segments[segmentIndex] & (1 << bit)) != 0; + } /* end IsElement */ + + + /* -------------------------------------------------------------------------- + * method IsSubset(set) + * -------------------------------------------------------------------------- + * Returns true if each element in set is also in the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsSubset(TokenSet set) + { + + for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + if (((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) + ^ this.dataStored.segments[segmentIndex]) != 0) + { + + return false; + + } /* end if */ + + } /* end for */ + + return true; + + } /* end IsSubset */ + + + /* -------------------------------------------------------------------------- + * method IsDisjunct(set) + * -------------------------------------------------------------------------- + * Returns true if set has no common elements with the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsDisjunct(TokenSet set) + { + + for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + if ((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) != 0) + { + + return false; + + } /* end if */ + + } /* end for */ + + return true; + + } /* end IsDisjunct */ + + /* -------------------------------------------------------------------------- + * method ElementList() + * -------------------------------------------------------------------------- + * Returns a token list of all elements in the receiver. + * ----------------------------------------------------------------------- */ + //TODO + + public List ElementList() + { + List allElements = new List(); + uint segmentIndex, count; + int bit; + Token token; + + if (this.dataStored.elemCount == 0) + { + return null; + } /* end if */ + + token = 0; + count = 0; + + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (int)token % 32; + + if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) + { + count++; + allElements.Add(token); + } /* end if */ + token++; + } /* end while */ + + return allElements; + + } /* end ElementList */ + + + /* -------------------------------------------------------------------------- + * method PrintSet(label) + * -------------------------------------------------------------------------- + * Prints a human readable representation of the receiver. + * Format: label = { comma-separated list of tokens }; + * ----------------------------------------------------------------------- */ + + public void PrintSet(string label) + { + uint segmentIndex, count; + int bit; + Token token; + + Console.Write(label + " = {"); + if (this.dataStored.elemCount == 0) + { + Console.Write(" "); + } /* end if */ + + token = 0; + count = 0; + + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (int)token % 32; + + if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) + { + count++; + + if (count <= this.dataStored.elemCount) + { + + Console.Write("\n {0},", lexemeTable[(uint)token]); + } + else + { + Console.WriteLine("\n {0}", lexemeTable[(uint)token]); + } /* end if */ + } /* end if */ + token++; + } /* end while */ + + Console.WriteLine("};"); + } /* end PrintSet */ + + + /* -------------------------------------------------------------------------- + * method PrintList() + * -------------------------------------------------------------------------- + * Prints a human readable list of tokens in the receiver. + * Format: first, second, third, ..., secondToLast or last + * ----------------------------------------------------------------------- */ + + public void PrintList() + { + uint bit, segmentIndex, count; + Token token; + + if (this.dataStored.elemCount == 0) + { + Console.WriteLine("(nil)"); + } + + count = 0; + token = 0; + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (uint)token % 32; + + if (((this.dataStored.segments[segmentIndex] & (1 << (int)bit)) != 0)) + { + count++; + if (count > 1) + { + if (count <= this.dataStored.elemCount) + { + Console.Write(", "); + } + else + { + Console.Write(" or "); + } /* end if */ + } /* end if */ + + Console.Write(lexemeTable[(uint)token]); + } + token++; + } + + Console.WriteLine("."); + } /* end PrintList */ + + + /* -------------------------------------------------------------------------- + * method PrintLiteralStruct(ident) + * -------------------------------------------------------------------------- + * Prints a struct definition for a tokenset literal for the receiver. + * Format: struct ident { uint s0; uint s1; uint s2; ...; uint n }; + * ----------------------------------------------------------------------- */ + + public void PrintLiteralStruct(string ident) + { + uint segmentIndex; + + Console.Write("struct {0} {{ uint s0", ident); + + for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) + { + Console.Write("; s" + segmentIndex); + } /* end for */ + + Console.WriteLine("; n };"); + Console.WriteLine("typedef struct {0} {0};", ident); + + } /* end PrintLiteralStruct */ + + + /* -------------------------------------------------------------------------- + * method PrintLiteral() + * -------------------------------------------------------------------------- + * Prints a sequence of hex values representing the bit pattern of receiver. + * Format: ( 0xHHHHHHHH, 0xHHHHHHHH, ..., count ); + * ----------------------------------------------------------------------- */ + + public void PrintLiteral() + { + uint segmentIndex; + + Console.Write("( /* bits: */ 0x" + this.dataStored.segments[0].ToString("x08")); + + for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) + { + + Console.Write(", 0x" + this.dataStored.segments[segmentIndex].ToString("x08")); + } /* end for */ + + Console.WriteLine(", /* counter: */ " + this.dataStored.elemCount + " );"); + } /* end PrintLiteral */ + + /* -------------------------------------------------------------------------- + * method CountBits() + * -------------------------------------------------------------------------- + * Returns the number of set bits in set. + * ----------------------------------------------------------------------- */ + + static private uint CountBits(TokenSet set) + { + int bit; + uint segmentIndex, + bitCount = 0; + + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + for (bit = 0; bit < 32; bit++) + { + + if ((set.dataStored.segments[segmentIndex] & (1 << bit)) != 0) + { + bitCount++; + } /* end if */ + + } /* end for */ + + } /* end for */ + + return bitCount; + } /* end CountBits */ + + } /* end TokenSet */ + +} /* end namespace */ From 918822bb006a8fdb038eba76798b1af57ceddeac Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Fri, 19 May 2017 15:16:39 -0700 Subject: [PATCH 02/24] Add files via upload From ee593edc5ff536c2cf6bd1c1aa81a47ed4419e8a Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Fri, 19 May 2017 15:25:25 -0700 Subject: [PATCH 03/24] Add files via upload --- NonTerminals.cs | 167 ++++++++++++++ Terminals.cs | 525 +++++++++++++++++++++++++++++++++++++++++++ TokenSet.cs | 574 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1266 insertions(+) create mode 100644 NonTerminals.cs create mode 100644 Terminals.cs create mode 100644 TokenSet.cs diff --git a/NonTerminals.cs b/NonTerminals.cs new file mode 100644 index 0000000..24f827a --- /dev/null +++ b/NonTerminals.cs @@ -0,0 +1,167 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * NonTerminals.cs + * + * provides FIRST() and FOLLOW() sets for each non-terminal symbol //SAM CHANGE + * used by the parser class for syntax analysis + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +namespace org.m2sf.m2sharp { + + using System; + using System.Collections.Generic; + +public class NonTerminals : INonTerminals { + + public static Production firstConstParamDependent = Production.FormalType, + lastConstParamDependent = Production.AttribFormalParams, + firstNoVariantRecDependent = Production.TypeDeclarationTail, + lastNoVariantRecDependent = Production.TypeDeclarationTail, + firstOptionDependent = firstConstParamDependent, + lastOptionDependent = lastNoVariantRecDependent; + public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; + + TokenSet[] followSet = new TokenSet[Count()]; + TokenSet[] firstSet = new TokenSet[Count()]; + + /* -------------------------------------------------------------------------- + * method Count() -- Returns the number of productions + * ----------------------------------------------------------------------- */ //SAM CHANGE + + static uint Count() { + return (uint)Enum.GetNames(typeof(Production)).Length; + } /* end Count */ + + + /* -------------------------------------------------------------------------- + * method IsOptionDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on any compiler option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsOptionDependent(Production p) { + return p >= firstOptionDependent; + } /* end IsOptionDependent */ + + + /* -------------------------------------------------------------------------- + * method IsConstParamDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on CONST parameter option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsConstParamDependent(Production p) + { + return p >= firstConstParamDependent && p <= lastConstParamDependent; + } /* end IsConstParamDependent */ + + + /* -------------------------------------------------------------------------- + * method IsVariantRecordDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on variant record type option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsVariantRecordDependent(Production p) { + return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; + } + + /* -------------------------------------------------------------------------- + * method FIRST(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FIRST set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FIRST(Production p) { + TokenSet tokenset = null; + uint index = 0; + + if (IsConstParamDependent(p)) + { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) + { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + + tokenset = firstSet[index]; + + return tokenset; + } /* end FIRST */ + + + /* -------------------------------------------------------------------------- + * method FOLLOW(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FOLLOW set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FOLLOW(Production p) { + TokenSet tokenset = null; + uint index = 0; + + if (IsConstParamDependent(p)) { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + + tokenset = followSet[index]; + + return tokenset; + } /* end FOLLOW */ + + + /* -------------------------------------------------------------------------- + * method NameForProduction(p) + * -------------------------------------------------------------------------- + * Returns a string with a human readable name for production p. + * ----------------------------------------------------------------------- */ + + string NameForProduction(Production p); + + + +} /* NonTerminals */ + +} /* namespace */ \ No newline at end of file diff --git a/Terminals.cs b/Terminals.cs new file mode 100644 index 0000000..b90861d --- /dev/null +++ b/Terminals.cs @@ -0,0 +1,525 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * Terminals.cs + * + * Terminal symbols' token and lexeme lookup. + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +namespace org.m2sf.m2sharp { + +public class Terminals : ITerminals { + +const Token FirstResWord = Token.AND; +const Token LastResWord = Token.WITH; + +const Token FirstLiteral = Token.StringLiteral; +const Token LastLiteral = Token.CharLiteral; + +const Token FirstMalformedLiteral = Token.MalformedString; +const Token LastMalformedLiteral = Token.MalformedReal; + +const Token FirstSpecialSymbol = Token.Plus; +const Token LastSpecialSymbol = Token.RightBrace; + +public const int tokenEndMark = (int)Token.EndOfFile + 1; //SAM CHANGE + + +/* --------------------------------------------------------------------------- + * method IsValid(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a valid token, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsValid (Token token) { + return (token != Token.Unknown) && !IsMalformedLiteral(token); +} /* end IsValid */ + + +/* --------------------------------------------------------------------------- + * method IsResword(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a reserved word, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsResword (Token token) { + return (token >= FirstResWord) && (token <= LastResWord); +} /* end IsResword */ + + +/* --------------------------------------------------------------------------- + * method IsLiteral(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a literal, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsLiteral (Token token) { + return (token >= FirstLiteral) && (token <= LastLiteral); +} /* end IsLiteral */ + + +/* --------------------------------------------------------------------------- + * method IsMalformedLiteral(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a malformed literal, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsMalformedLiteral (Token token) { + return (token >= FirstMalformedLiteral) && (token <= LastMalformedLiteral); +} /* end IsMalformedLiteral */ + + +/* --------------------------------------------------------------------------- + * method IsSpecialSymbol(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a special symbol, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsSpecialSymbol (Token token) { + return (token >= FirstSpecialSymbol) && (token <= LastSpecialSymbol); +} /* end IsSpecialSymbol */ + + +/* --------------------------------------------------------------------------- + * method TokenForResword(lexeme) + * --------------------------------------------------------------------------- + * Tests if the given lexeme represents a reserved word and returns the + * corresponding token or Unknown if it does not match a reserved word. + * ------------------------------------------------------------------------ */ + +public static Token TokenForResword (string lexeme) { + int length; + + /* check pre-conditions */ + if (lexeme == null) { + return Token.Unknown; + } /* end if */ + + length = lexeme.Length; + + if ((length < 2) || (length > 14)) { + return Token.Unknown; + } /* end if */ + + switch (length) { + case /* length = 2 */ 2 : + switch (lexeme[0]) { + + case 'B' : + /* BY */ + if (lexeme[1] == 'Y') { + return Token.BY; + } /* end if */ + break; + + case 'D' : + /* DO */ + if (lexeme[1] == 'O') { + return Token.DO; + } /* end if */ + break; + + case 'I' : + /* IF */ + if (lexeme[1] == 'F') { + return Token.IF; + } + + /* IN */ + else if (lexeme[1] == 'N') { + return Token.IN; + } /* end if */ + break; + + case 'O' : + /* OF */ + if (lexeme[1] == 'F') { + return Token.OF; + } + + /* OR */ + else if (lexeme[1] == 'R') { + return Token.OR; + } /* end if */ + break; + + case 'T' : + /* TO */ + if (lexeme[1] == 'O') { + return Token.TO; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 3 */ 3 : + switch (lexeme[0]) { + + case 'A' : + /* AND */ + if (string.CompareOrdinal(lexeme, "AND") == 0) { + return Token.AND; + } /* end if */ + break; + + case 'D' : + /* DIV */ + if (string.CompareOrdinal(lexeme, "DIV") == 0) { + return Token.DIV; + } /* end if */ + break; + + case 'E' : + /* END */ + if (string.CompareOrdinal(lexeme, "END") == 0) { + return Token.END; + } /* end if */ + break; + + case 'F' : + /* FOR */ + if (string.CompareOrdinal(lexeme, "FOR") == 0) { + return Token.FOR; + } /* end if */ + break; + + case 'M' : + /* MOD */ + if (string.CompareOrdinal(lexeme, "MOD") == 0) { + return Token.MOD; + } /* end if */ + break; + + case 'N' : + /* NOT */ + if (string.CompareOrdinal(lexeme, "NOT") == 0) { + return Token.NOT; + } /* end if */ + break; + + case 'S' : + /* SET */ + if (string.CompareOrdinal(lexeme, "SET") == 0) { + return Token.SET; + } /* end if */ + break; + + case 'V' : + /* VAR */ + if (string.CompareOrdinal(lexeme, "VAR") == 0) { + return Token.VAR; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 4 */ 4 : + switch (lexeme[1]) { + + case 'A' : + /* CASE */ + if (string.CompareOrdinal(lexeme, "CASE") == 0) { + return Token.CASE; + } /* end if */ + break; + + case 'H' : + /* THEN */ + if (string.CompareOrdinal(lexeme, "THEN") == 0) { + return Token.THEN; + } /* end if */ + break; + + case 'I' : + /* WITH */ + if (string.CompareOrdinal(lexeme, "WITH") == 0) { + return Token.WITH; + } /* end if */ + break; + + case 'L' : + /* ELSE */ + if (string.CompareOrdinal(lexeme, "ELSE") == 0) { + return Token.ELSE; + } /* end if */ + break; + + case 'O' : + /* LOOP */ + if (string.CompareOrdinal(lexeme, "LOOP") == 0) { + return Token.LOOP; + } /* end if */ + break; + + case 'R' : + /* FROM */ + if (string.CompareOrdinal(lexeme, "FROM") == 0) { + return Token.FROM; + } /* end if */ + break; + + case 'X' : + /* EXIT */ + if (string.CompareOrdinal(lexeme, "EXIT") == 0) { + return Token.EXIT; + } /* end if */ + break; + + case 'Y' : + /* TYPE */ + if (string.CompareOrdinal(lexeme, "TYPE") == 0) { + return Token.TYPE; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 5 */ 5 : + switch (lexeme[0]) { + + case 'A' : + /* ARRAY */ + if (string.CompareOrdinal(lexeme, "ARRAY") == 0) { + return Token.ARRAY; + } /* end if */ + break; + + case 'B' : + /* BEGIN */ + if (string.CompareOrdinal(lexeme, "BEGIN") == 0) { + return Token.BEGIN; + } /* end if */ + break; + + case 'C' : + /* CONST */ + if (string.CompareOrdinal(lexeme, "CONST") == 0) { + return Token.CONST; + } /* end if */ + break; + + case 'E' : + /* ELSIF */ + if (string.CompareOrdinal(lexeme, "ELSIF") == 0) { + return Token.ELSIF; + } /* end if */ + break; + + case 'U' : + /* UNTIL */ + if (string.CompareOrdinal(lexeme, "UNTIL") == 0) { + return Token.UNTIL; + } /* end if */ + break; + + case 'W' : + /* WHILE */ + if (string.CompareOrdinal(lexeme, "WHILE") == 0) { + return Token.WHILE; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length 6 */ 6 : + switch (lexeme[5]) { + + case 'E' : + /* MODULE */ + if (string.CompareOrdinal(lexeme, "MODULE") == 0) { + return Token.MODULE; + } /* end if */ + break; + + case 'D' : + /* RECORD */ + if (string.CompareOrdinal(lexeme, "RECORD") == 0) { + return Token.RECORD; + } /* end if */ + break; + + case 'N' : + /* RETURN */ + if (string.CompareOrdinal(lexeme, "RETURN") == 0) { + return Token.RETURN; + } /* end if */ + break; + + case 'T' : + switch (lexeme[0]) { + + case 'E' : + /* EXPORT */ + if (string.CompareOrdinal(lexeme, "EXPORT") == 0) { + return Token.EXPORT; + } /* end if */ + break; + + case 'I' : + /* IMPORT */ + if (string.CompareOrdinal(lexeme, "IMPORT") == 0) { + return Token.IMPORT; + } /* end if */ + break; + + case 'R' : + /* REPEAT */ + if (string.CompareOrdinal(lexeme, "REPEAT") == 0) { + return Token.REPEAT; + } /* end if */ + break; + + } /* end switch */ + break; + + } /* end switch */ + break; + + case /* length = 7 */ 7 : + switch (lexeme[0]) { + + case 'A' : + /* ARGLIST */ + if (string.CompareOrdinal(lexeme, "ARGLIST") == 0) { + return Token.ARGLIST; + } /* end if */ + break; + + case 'P' : + /* POINTER */ + if (string.CompareOrdinal(lexeme, "POINTER") == 0) { + return Token.POINTER; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 9 */ 9 : + switch (lexeme[0]) { + + case 'P' : + /* PROCEDURE */ + if (string.CompareOrdinal(lexeme, "PROCEDURE") == 0) { + return Token.PROCEDURE; + } /* end if */ + break; + + case 'Q' : + /* QUALIFIED */ + if (string.CompareOrdinal(lexeme, "QUALIFIED") == 0) { + return Token.QUALIFIED; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 10 */ 10 : + /* DEFINITION */ + if (string.CompareOrdinal(lexeme, "DEFINITION") == 0) { + return Token.DEFINITION; + } /* end if */ + break; + + case /* length = 14 */ 14 : + /* IMPLEMENTATION */ + if (string.CompareOrdinal(lexeme, "IMPLEMENTATION") == 0) { + return Token.IMPLEMENTATION; + } /* end if */ + break; + + } /* end switch (length) */ + + return Token.Unknown; +} /* end TokenForResword */ + + +/* --------------------------------------------------------------------------- + * method LexemeForResword(token) + * --------------------------------------------------------------------------- + * Returns a string with the lexeme for the reserved word represented by + * token. Returns null if the token does not represent a reserved word. + * ------------------------------------------------------------------------ */ + +public static string LexemeForResword (Token token) { + if (IsResword(token) == false) { + return null; + } /* end if */ + return TokenSet.lexemeTable[(uint)token]; +} /* end LexemeForResword */ + + +/* --------------------------------------------------------------------------- + * method LexemeForSpecialSymbol(token) + * --------------------------------------------------------------------------- + * Returns a string with the lexeme for the special symbol represented by + * token. Returns null if the token does not represent a special symbol. + * ------------------------------------------------------------------------ */ + +public static string LexemeForSpecialSymbol (Token token) { + if (IsSpecialSymbol(token) == false) { + return null; + } /* end if */ + return ""; // TO DO +} /* end LexemeForSpecialSymbol */ + + +/* --------------------------------------------------------------------------- + * method NameForToken(token) + * --------------------------------------------------------------------------- + * Returns a string with a human readable name for token. Returns null if + * token is not a valid token. + * ------------------------------------------------------------------------ */ + +public static string NameForToken (Token token) { + return token.ToString(); +} /* NameForToken */ + + +} /* Terminals */ + +} /* namespace */ + +/* END OF FILE */ \ No newline at end of file diff --git a/TokenSet.cs b/TokenSet.cs new file mode 100644 index 0000000..7490eb1 --- /dev/null +++ b/TokenSet.cs @@ -0,0 +1,574 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * TokenSet.cs + * + * A set of Token type variables which is used to pass First and Follow sets + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace org.m2sf.m2sharp +{ + + public class TokenSet : ITokenSet { + + /* Lexeme Table */ + public static string[] lexemeTable = { + /* Null Token */ + + "UNKNOWN", + + /* Reserved Words */ + + "AND", + "ARGLIST", + "ARRAY", + "BEGIN", + "BY", + "CASE", + "CONST", + "DEFINITION", + "DIV", + "DO", + "ELSE", + "ELSIF", + "END", + "EXIT", + "EXPORT", + "FOR", + "FROM", + "IF", + "IMPLEMENTATION", + "IMPORT", + "IN", + "LOOP", + "MOD", + "MODULE", + "NOT", + "OF", + "OR", + "POINTER", + "PROCEDURE", + "QUALIFIED", + "RECORD", + "REPEAT", + "RETURN", + "SET", + "THEN", + "TO", + "TYPE", + "UNTIL", + "VAR", + "WHILE", + "WITH", + + /* Identifiers */ + + "IDENTIFIER", + + /* Literals */ + + "STRING-LITERAL", + "INTEGER-LITERAL", + "REAL-LITERAL", + "CHAR-LITERAL", + + "MALFORMED-STRING", + "MALFORMED-INTEGER", + "MALFORMED-REAL", + + /* Pragmas */ + + "PRAGMA", + + /* Special Symbols */ + + "PLUS", + "MINUS", + "EQUAL", + "NOTEQUAL", + "LESS-THAN", + "LESS-OR-EQUAL", + "GREATER-THAN", + "GREATER-OR-EQUAL", + "ASTERISK", + "SOLIDUS", + "BACKSLASH", + "ASSIGNMENT", + "COMMA", + "PERIOD", + "COLON", + "SEMICOLON", + "RANGE", + "DEREF", + "VERTICAL-BAR", + "LEFT-PAREN", + "RIGHT-PAREN", + "LEFT-BRACKET", + "RIGHT-BRACKET", + "LEFT-BRACE", + "RIGHT-BRACE", + "END-OF-FILE" + +}; /* end m2c_token_name_table */ + + public static const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; + + public struct TokenSetBits + { + public uint[] segments = new uint[segmentCount]; + public uint elemCount; + } /* end struct */ + + TokenSetBits dataStored; + + /* --------------------------------------------------------------------------- + * private constructor TokenSet () + * --------------------------------------------------------------------------- + * Prevents clients from invoking the default constructor. + * ------------------------------------------------------------------------ */ + + private TokenSet() + { + // no operation + } /* end TokenSet */ + + /* -------------------------------------------------------------------------- + * constructor newFromList(token, ...) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object that includes the tokens passed + * as arguments of a variadic argument list. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromList(params Token[] tokenList) + { + TokenSet newSet = new TokenSet(); + uint bit, segmentIndex; + Token token; + + /* allocate new set */ + newSet.dataStored.segments = new uint[segmentCount]; + + /* initialise */ + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + newSet.dataStored.segments[segmentIndex] = 0; + } /* end For */ + + /* store tokens from list */ + token = tokenList[0]; + for (int i = 1; token != Token.Unknown; i++) + { + + if (token <= Token.EndOfFile) + { + segmentIndex = (uint)token / 32; + bit = (uint)token % 32; + newSet.dataStored.segments[segmentIndex] = (newSet.dataStored.segments[segmentIndex] | (uint)(1 << (int)bit)); + } /* end if */ + + /* get next token in list */ + token = tokenList[i]; + } /* end while */ + + /* update element counter */ + newSet.dataStored.elemCount = CountBits(newSet); + + return newSet; + } /* end newFromList */ + + + /* -------------------------------------------------------------------------- + * constructor newFromUnion(set, ...) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object that represents the set union of + * the tokensets passed as arguments of a non-empty variadic argument list. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromUnion(params TokenSet[] setList) + { + uint segmentIndex; + TokenSet set, + newSet = new TokenSet(); + + + /* initialise */ + newSet.dataStored.segments = new uint[segmentCount]; + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + newSet.dataStored.segments[segmentIndex] = 0; + } /* end for */ + + set = setList[0]; + /* calculate union with each set in list */ + for (int i = 0; set != null; i++) + { + /* for each segment ... */ + while (segmentIndex < segmentCount) + { + /* ... store union of corresponding segments */ + newSet.dataStored.segments[segmentIndex] = + newSet.dataStored.segments[segmentIndex] | newSet.dataStored.segments[segmentIndex]; + + /* next segment */ + segmentIndex++; + } /* end while */ + + /*get next set in list */ + if (i < setList.Length) + set = setList[i]; + else + set = null; + + } /* end for */ + + /* update element counter */ + newSet.dataStored.elemCount = CountBits(newSet); + + return newSet; + } /* end newFromUnion + +/* -------------------------------------------------------------------------- + * method Count() + * -------------------------------------------------------------------------- + * Returns the number of elements in the receiver. + * ----------------------------------------------------------------------- */ + + public uint Count() + { + + return this.dataStored.elemCount; + } /* end IsElement */ + + + /* -------------------------------------------------------------------------- + * method IsElement(token) + * -------------------------------------------------------------------------- + * Returns true if token is an element of the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsElement(Token token) + { + int segmentIndex, bit; + + if (token > Token.EndOfFile) + { + return false; + } /* end if */ + + segmentIndex = (int)token / 32; + bit = (int)token % 32; + + return (this.dataStored.segments[segmentIndex] & (1 << bit)) != 0; + } /* end IsElement */ + + + /* -------------------------------------------------------------------------- + * method IsSubset(set) + * -------------------------------------------------------------------------- + * Returns true if each element in set is also in the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsSubset(TokenSet set) + { + + for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + if (((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) + ^ this.dataStored.segments[segmentIndex]) != 0) + { + + return false; + + } /* end if */ + + } /* end for */ + + return true; + + } /* end IsSubset */ + + + /* -------------------------------------------------------------------------- + * method IsDisjunct(set) + * -------------------------------------------------------------------------- + * Returns true if set has no common elements with the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsDisjunct(TokenSet set) + { + + for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + if ((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) != 0) + { + + return false; + + } /* end if */ + + } /* end for */ + + return true; + + } /* end IsDisjunct */ + + /* -------------------------------------------------------------------------- + * method ElementList() + * -------------------------------------------------------------------------- + * Returns a token list of all elements in the receiver. + * ----------------------------------------------------------------------- */ + //TODO + + public List ElementList() + { + List allElements = new List(); + uint segmentIndex, count; + int bit; + Token token; + + if (this.dataStored.elemCount == 0) + { + return null; + } /* end if */ + + token = 0; + count = 0; + + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (int)token % 32; + + if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) + { + count++; + allElements.Add(token); + } /* end if */ + token++; + } /* end while */ + + return allElements; + + } /* end ElementList */ + + + /* -------------------------------------------------------------------------- + * method PrintSet(label) + * -------------------------------------------------------------------------- + * Prints a human readable representation of the receiver. + * Format: label = { comma-separated list of tokens }; + * ----------------------------------------------------------------------- */ + + public void PrintSet(string label) + { + uint segmentIndex, count; + int bit; + Token token; + + Console.Write(label + " = {"); + if (this.dataStored.elemCount == 0) + { + Console.Write(" "); + } /* end if */ + + token = 0; + count = 0; + + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (int)token % 32; + + if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) + { + count++; + + if (count <= this.dataStored.elemCount) + { + + Console.Write("\n {0},", lexemeTable[(uint)token]); + } + else + { + Console.WriteLine("\n {0}", lexemeTable[(uint)token]); + } /* end if */ + } /* end if */ + token++; + } /* end while */ + + Console.WriteLine("};"); + } /* end PrintSet */ + + + /* -------------------------------------------------------------------------- + * method PrintList() + * -------------------------------------------------------------------------- + * Prints a human readable list of tokens in the receiver. + * Format: first, second, third, ..., secondToLast or last + * ----------------------------------------------------------------------- */ + + public void PrintList() + { + uint bit, segmentIndex, count; + Token token; + + if (this.dataStored.elemCount == 0) + { + Console.WriteLine("(nil)"); + } + + count = 0; + token = 0; + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (uint)token % 32; + + if (((this.dataStored.segments[segmentIndex] & (1 << (int)bit)) != 0)) + { + count++; + if (count > 1) + { + if (count <= this.dataStored.elemCount) + { + Console.Write(", "); + } + else + { + Console.Write(" or "); + } /* end if */ + } /* end if */ + + Console.Write(lexemeTable[(uint)token]); + } + token++; + } + + Console.WriteLine("."); + } /* end PrintList */ + + + /* -------------------------------------------------------------------------- + * method PrintLiteralStruct(ident) + * -------------------------------------------------------------------------- + * Prints a struct definition for a tokenset literal for the receiver. + * Format: struct ident { uint s0; uint s1; uint s2; ...; uint n }; + * ----------------------------------------------------------------------- */ + + public void PrintLiteralStruct(string ident) + { + uint segmentIndex; + + Console.Write("struct {0} {{ uint s0", ident); + + for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) + { + Console.Write("; s" + segmentIndex); + } /* end for */ + + Console.WriteLine("; n };"); + Console.WriteLine("typedef struct {0} {0};", ident); + + } /* end PrintLiteralStruct */ + + + /* -------------------------------------------------------------------------- + * method PrintLiteral() + * -------------------------------------------------------------------------- + * Prints a sequence of hex values representing the bit pattern of receiver. + * Format: ( 0xHHHHHHHH, 0xHHHHHHHH, ..., count ); + * ----------------------------------------------------------------------- */ + + public void PrintLiteral() + { + uint segmentIndex; + + Console.Write("( /* bits: */ 0x" + this.dataStored.segments[0].ToString("x08")); + + for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) + { + + Console.Write(", 0x" + this.dataStored.segments[segmentIndex].ToString("x08")); + } /* end for */ + + Console.WriteLine(", /* counter: */ " + this.dataStored.elemCount + " );"); + } /* end PrintLiteral */ + + /* -------------------------------------------------------------------------- + * method CountBits() + * -------------------------------------------------------------------------- + * Returns the number of set bits in set. + * ----------------------------------------------------------------------- */ + + static private uint CountBits(TokenSet set) + { + int bit; + uint segmentIndex, + bitCount = 0; + + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + for (bit = 0; bit < 32; bit++) + { + + if ((set.dataStored.segments[segmentIndex] & (1 << bit)) != 0) + { + bitCount++; + } /* end if */ + + } /* end for */ + + } /* end for */ + + return bitCount; + } /* end CountBits */ + + } /* end TokenSet */ + +} /* end namespace */ From 8fcfa6606f3c89802ade5cced1a83179c95f550e Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Fri, 19 May 2017 15:30:47 -0700 Subject: [PATCH 04/24] Add files via upload --- NonTerminals.cs | 27 ++++++++++++++++----------- Terminals.cs | 2 +- TokenSet.cs | 14 +++++--------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/NonTerminals.cs b/NonTerminals.cs index 035822c..24f827a 100644 --- a/NonTerminals.cs +++ b/NonTerminals.cs @@ -57,18 +57,17 @@ public class NonTerminals : INonTerminals { lastNoVariantRecDependent = Production.TypeDeclarationTail, firstOptionDependent = firstConstParamDependent, lastOptionDependent = lastNoVariantRecDependent; - public static int alternateSetOffset = (int)lastOptionDependent - (int)firstOptionDependent + 1; + public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; + + TokenSet[] followSet = new TokenSet[Count()]; + TokenSet[] firstSet = new TokenSet[Count()]; /* -------------------------------------------------------------------------- * method Count() -- Returns the number of productions * ----------------------------------------------------------------------- */ //SAM CHANGE - uint Count() { - uint total = 0; - foreach (String s in Enum.GetNames(typeof(Production))) { - total++; - } - return total; + static uint Count() { + return (uint)Enum.GetNames(typeof(Production)).Length; } /* end Count */ @@ -113,16 +112,19 @@ bool IsVariantRecordDependent(Production p) { TokenSet FIRST(Production p) { TokenSet tokenset = null; + uint index = 0; if (IsConstParamDependent(p)) { - p += alternateSetOffset; + index = Convert.ToUInt32(p) + alternateSetOffset; } /* end if */ if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) { - p += alternateSetOffset; + index = Convert.ToUInt32(p) + alternateSetOffset; } /* end if */ + tokenset = firstSet[index]; + return tokenset; } /* end FIRST */ @@ -135,14 +137,17 @@ TokenSet FIRST(Production p) { TokenSet FOLLOW(Production p) { TokenSet tokenset = null; + uint index = 0; if (IsConstParamDependent(p)) { - p += alternateSetOffset; + index = Convert.ToUInt32(p) + alternateSetOffset; } /* end if */ if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { - p += alternateSetOffset; + index = Convert.ToUInt32(p) + alternateSetOffset; } /* end if */ + tokenset = followSet[index]; + return tokenset; } /* end FOLLOW */ diff --git a/Terminals.cs b/Terminals.cs index b8227ce..b90861d 100644 --- a/Terminals.cs +++ b/Terminals.cs @@ -487,7 +487,7 @@ public static string LexemeForResword (Token token) { if (IsResword(token) == false) { return null; } /* end if */ - return token.ToString(); + return TokenSet.lexemeTable[(uint)token]; } /* end LexemeForResword */ diff --git a/TokenSet.cs b/TokenSet.cs index 9811db5..7490eb1 100644 --- a/TokenSet.cs +++ b/TokenSet.cs @@ -150,23 +150,19 @@ public class TokenSet : ITokenSet { "RIGHT-BRACKET", "LEFT-BRACE", "RIGHT-BRACE", - "END-OF-FILE", - - /* out-of-range guard */ - - "\0" + "END-OF-FILE" }; /* end m2c_token_name_table */ - public static int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; + public static const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; - public struct opaque + public struct TokenSetBits { - public uint[] segments; + public uint[] segments = new uint[segmentCount]; public uint elemCount; } /* end struct */ - opaque dataStored; + TokenSetBits dataStored; /* --------------------------------------------------------------------------- * private constructor TokenSet () From 0920cbef68bde42edc6fdb8918f7365271d43cf6 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Fri, 19 May 2017 16:27:37 -0700 Subject: [PATCH 05/24] Add files via upload --- INonTerminals.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/INonTerminals.cs b/INonTerminals.cs index 9322e99..a217a5d 100644 --- a/INonTerminals.cs +++ b/INonTerminals.cs @@ -43,7 +43,7 @@ * NB: Components in the domain part of email addresses are in reverse order. */ -namespace M2SF.M2Sharp { +namespace org.m2sf.m2sharp { /* -------------------------------------------------------------------------- * type Production @@ -131,7 +131,7 @@ public enum Production { AttribFormalParams, /* attribFormalParams */ /* Dependent on option --no-variant-records */ - TypeDeclarationTail; /* typeDeclarationTail */ + TypeDeclarationTail /* typeDeclarationTail */ } /* Production */ @@ -178,7 +178,7 @@ interface INonTerminals { * Returns a tokenset with the FIRST set of production p. * ----------------------------------------------------------------------- */ -public EnumSet FIRST (Production p); +public TokenSet FIRST (Production p); /* -------------------------------------------------------------------------- @@ -187,7 +187,7 @@ interface INonTerminals { * Returns a tokenset with the FOLLOW set of production p. * ----------------------------------------------------------------------- */ -public EnumSet FOLLOW (Production p); +public TokenSet FOLLOW (Production p); /* -------------------------------------------------------------------------- From dfee09a1f7921baa0a56b8f3398daaec7c87958f Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Fri, 19 May 2017 16:28:38 -0700 Subject: [PATCH 06/24] Add files via upload --- imp/NonTerminals.cs | 167 +++++++++++++ imp/TokenSet.cs | 574 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 741 insertions(+) create mode 100644 imp/NonTerminals.cs create mode 100644 imp/TokenSet.cs diff --git a/imp/NonTerminals.cs b/imp/NonTerminals.cs new file mode 100644 index 0000000..24f827a --- /dev/null +++ b/imp/NonTerminals.cs @@ -0,0 +1,167 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * NonTerminals.cs + * + * provides FIRST() and FOLLOW() sets for each non-terminal symbol //SAM CHANGE + * used by the parser class for syntax analysis + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +namespace org.m2sf.m2sharp { + + using System; + using System.Collections.Generic; + +public class NonTerminals : INonTerminals { + + public static Production firstConstParamDependent = Production.FormalType, + lastConstParamDependent = Production.AttribFormalParams, + firstNoVariantRecDependent = Production.TypeDeclarationTail, + lastNoVariantRecDependent = Production.TypeDeclarationTail, + firstOptionDependent = firstConstParamDependent, + lastOptionDependent = lastNoVariantRecDependent; + public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; + + TokenSet[] followSet = new TokenSet[Count()]; + TokenSet[] firstSet = new TokenSet[Count()]; + + /* -------------------------------------------------------------------------- + * method Count() -- Returns the number of productions + * ----------------------------------------------------------------------- */ //SAM CHANGE + + static uint Count() { + return (uint)Enum.GetNames(typeof(Production)).Length; + } /* end Count */ + + + /* -------------------------------------------------------------------------- + * method IsOptionDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on any compiler option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsOptionDependent(Production p) { + return p >= firstOptionDependent; + } /* end IsOptionDependent */ + + + /* -------------------------------------------------------------------------- + * method IsConstParamDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on CONST parameter option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsConstParamDependent(Production p) + { + return p >= firstConstParamDependent && p <= lastConstParamDependent; + } /* end IsConstParamDependent */ + + + /* -------------------------------------------------------------------------- + * method IsVariantRecordDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on variant record type option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsVariantRecordDependent(Production p) { + return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; + } + + /* -------------------------------------------------------------------------- + * method FIRST(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FIRST set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FIRST(Production p) { + TokenSet tokenset = null; + uint index = 0; + + if (IsConstParamDependent(p)) + { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) + { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + + tokenset = firstSet[index]; + + return tokenset; + } /* end FIRST */ + + + /* -------------------------------------------------------------------------- + * method FOLLOW(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FOLLOW set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FOLLOW(Production p) { + TokenSet tokenset = null; + uint index = 0; + + if (IsConstParamDependent(p)) { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + + tokenset = followSet[index]; + + return tokenset; + } /* end FOLLOW */ + + + /* -------------------------------------------------------------------------- + * method NameForProduction(p) + * -------------------------------------------------------------------------- + * Returns a string with a human readable name for production p. + * ----------------------------------------------------------------------- */ + + string NameForProduction(Production p); + + + +} /* NonTerminals */ + +} /* namespace */ \ No newline at end of file diff --git a/imp/TokenSet.cs b/imp/TokenSet.cs new file mode 100644 index 0000000..7490eb1 --- /dev/null +++ b/imp/TokenSet.cs @@ -0,0 +1,574 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * TokenSet.cs + * + * A set of Token type variables which is used to pass First and Follow sets + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace org.m2sf.m2sharp +{ + + public class TokenSet : ITokenSet { + + /* Lexeme Table */ + public static string[] lexemeTable = { + /* Null Token */ + + "UNKNOWN", + + /* Reserved Words */ + + "AND", + "ARGLIST", + "ARRAY", + "BEGIN", + "BY", + "CASE", + "CONST", + "DEFINITION", + "DIV", + "DO", + "ELSE", + "ELSIF", + "END", + "EXIT", + "EXPORT", + "FOR", + "FROM", + "IF", + "IMPLEMENTATION", + "IMPORT", + "IN", + "LOOP", + "MOD", + "MODULE", + "NOT", + "OF", + "OR", + "POINTER", + "PROCEDURE", + "QUALIFIED", + "RECORD", + "REPEAT", + "RETURN", + "SET", + "THEN", + "TO", + "TYPE", + "UNTIL", + "VAR", + "WHILE", + "WITH", + + /* Identifiers */ + + "IDENTIFIER", + + /* Literals */ + + "STRING-LITERAL", + "INTEGER-LITERAL", + "REAL-LITERAL", + "CHAR-LITERAL", + + "MALFORMED-STRING", + "MALFORMED-INTEGER", + "MALFORMED-REAL", + + /* Pragmas */ + + "PRAGMA", + + /* Special Symbols */ + + "PLUS", + "MINUS", + "EQUAL", + "NOTEQUAL", + "LESS-THAN", + "LESS-OR-EQUAL", + "GREATER-THAN", + "GREATER-OR-EQUAL", + "ASTERISK", + "SOLIDUS", + "BACKSLASH", + "ASSIGNMENT", + "COMMA", + "PERIOD", + "COLON", + "SEMICOLON", + "RANGE", + "DEREF", + "VERTICAL-BAR", + "LEFT-PAREN", + "RIGHT-PAREN", + "LEFT-BRACKET", + "RIGHT-BRACKET", + "LEFT-BRACE", + "RIGHT-BRACE", + "END-OF-FILE" + +}; /* end m2c_token_name_table */ + + public static const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; + + public struct TokenSetBits + { + public uint[] segments = new uint[segmentCount]; + public uint elemCount; + } /* end struct */ + + TokenSetBits dataStored; + + /* --------------------------------------------------------------------------- + * private constructor TokenSet () + * --------------------------------------------------------------------------- + * Prevents clients from invoking the default constructor. + * ------------------------------------------------------------------------ */ + + private TokenSet() + { + // no operation + } /* end TokenSet */ + + /* -------------------------------------------------------------------------- + * constructor newFromList(token, ...) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object that includes the tokens passed + * as arguments of a variadic argument list. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromList(params Token[] tokenList) + { + TokenSet newSet = new TokenSet(); + uint bit, segmentIndex; + Token token; + + /* allocate new set */ + newSet.dataStored.segments = new uint[segmentCount]; + + /* initialise */ + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + newSet.dataStored.segments[segmentIndex] = 0; + } /* end For */ + + /* store tokens from list */ + token = tokenList[0]; + for (int i = 1; token != Token.Unknown; i++) + { + + if (token <= Token.EndOfFile) + { + segmentIndex = (uint)token / 32; + bit = (uint)token % 32; + newSet.dataStored.segments[segmentIndex] = (newSet.dataStored.segments[segmentIndex] | (uint)(1 << (int)bit)); + } /* end if */ + + /* get next token in list */ + token = tokenList[i]; + } /* end while */ + + /* update element counter */ + newSet.dataStored.elemCount = CountBits(newSet); + + return newSet; + } /* end newFromList */ + + + /* -------------------------------------------------------------------------- + * constructor newFromUnion(set, ...) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object that represents the set union of + * the tokensets passed as arguments of a non-empty variadic argument list. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromUnion(params TokenSet[] setList) + { + uint segmentIndex; + TokenSet set, + newSet = new TokenSet(); + + + /* initialise */ + newSet.dataStored.segments = new uint[segmentCount]; + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + newSet.dataStored.segments[segmentIndex] = 0; + } /* end for */ + + set = setList[0]; + /* calculate union with each set in list */ + for (int i = 0; set != null; i++) + { + /* for each segment ... */ + while (segmentIndex < segmentCount) + { + /* ... store union of corresponding segments */ + newSet.dataStored.segments[segmentIndex] = + newSet.dataStored.segments[segmentIndex] | newSet.dataStored.segments[segmentIndex]; + + /* next segment */ + segmentIndex++; + } /* end while */ + + /*get next set in list */ + if (i < setList.Length) + set = setList[i]; + else + set = null; + + } /* end for */ + + /* update element counter */ + newSet.dataStored.elemCount = CountBits(newSet); + + return newSet; + } /* end newFromUnion + +/* -------------------------------------------------------------------------- + * method Count() + * -------------------------------------------------------------------------- + * Returns the number of elements in the receiver. + * ----------------------------------------------------------------------- */ + + public uint Count() + { + + return this.dataStored.elemCount; + } /* end IsElement */ + + + /* -------------------------------------------------------------------------- + * method IsElement(token) + * -------------------------------------------------------------------------- + * Returns true if token is an element of the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsElement(Token token) + { + int segmentIndex, bit; + + if (token > Token.EndOfFile) + { + return false; + } /* end if */ + + segmentIndex = (int)token / 32; + bit = (int)token % 32; + + return (this.dataStored.segments[segmentIndex] & (1 << bit)) != 0; + } /* end IsElement */ + + + /* -------------------------------------------------------------------------- + * method IsSubset(set) + * -------------------------------------------------------------------------- + * Returns true if each element in set is also in the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsSubset(TokenSet set) + { + + for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + if (((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) + ^ this.dataStored.segments[segmentIndex]) != 0) + { + + return false; + + } /* end if */ + + } /* end for */ + + return true; + + } /* end IsSubset */ + + + /* -------------------------------------------------------------------------- + * method IsDisjunct(set) + * -------------------------------------------------------------------------- + * Returns true if set has no common elements with the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsDisjunct(TokenSet set) + { + + for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + if ((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) != 0) + { + + return false; + + } /* end if */ + + } /* end for */ + + return true; + + } /* end IsDisjunct */ + + /* -------------------------------------------------------------------------- + * method ElementList() + * -------------------------------------------------------------------------- + * Returns a token list of all elements in the receiver. + * ----------------------------------------------------------------------- */ + //TODO + + public List ElementList() + { + List allElements = new List(); + uint segmentIndex, count; + int bit; + Token token; + + if (this.dataStored.elemCount == 0) + { + return null; + } /* end if */ + + token = 0; + count = 0; + + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (int)token % 32; + + if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) + { + count++; + allElements.Add(token); + } /* end if */ + token++; + } /* end while */ + + return allElements; + + } /* end ElementList */ + + + /* -------------------------------------------------------------------------- + * method PrintSet(label) + * -------------------------------------------------------------------------- + * Prints a human readable representation of the receiver. + * Format: label = { comma-separated list of tokens }; + * ----------------------------------------------------------------------- */ + + public void PrintSet(string label) + { + uint segmentIndex, count; + int bit; + Token token; + + Console.Write(label + " = {"); + if (this.dataStored.elemCount == 0) + { + Console.Write(" "); + } /* end if */ + + token = 0; + count = 0; + + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (int)token % 32; + + if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) + { + count++; + + if (count <= this.dataStored.elemCount) + { + + Console.Write("\n {0},", lexemeTable[(uint)token]); + } + else + { + Console.WriteLine("\n {0}", lexemeTable[(uint)token]); + } /* end if */ + } /* end if */ + token++; + } /* end while */ + + Console.WriteLine("};"); + } /* end PrintSet */ + + + /* -------------------------------------------------------------------------- + * method PrintList() + * -------------------------------------------------------------------------- + * Prints a human readable list of tokens in the receiver. + * Format: first, second, third, ..., secondToLast or last + * ----------------------------------------------------------------------- */ + + public void PrintList() + { + uint bit, segmentIndex, count; + Token token; + + if (this.dataStored.elemCount == 0) + { + Console.WriteLine("(nil)"); + } + + count = 0; + token = 0; + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (uint)token % 32; + + if (((this.dataStored.segments[segmentIndex] & (1 << (int)bit)) != 0)) + { + count++; + if (count > 1) + { + if (count <= this.dataStored.elemCount) + { + Console.Write(", "); + } + else + { + Console.Write(" or "); + } /* end if */ + } /* end if */ + + Console.Write(lexemeTable[(uint)token]); + } + token++; + } + + Console.WriteLine("."); + } /* end PrintList */ + + + /* -------------------------------------------------------------------------- + * method PrintLiteralStruct(ident) + * -------------------------------------------------------------------------- + * Prints a struct definition for a tokenset literal for the receiver. + * Format: struct ident { uint s0; uint s1; uint s2; ...; uint n }; + * ----------------------------------------------------------------------- */ + + public void PrintLiteralStruct(string ident) + { + uint segmentIndex; + + Console.Write("struct {0} {{ uint s0", ident); + + for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) + { + Console.Write("; s" + segmentIndex); + } /* end for */ + + Console.WriteLine("; n };"); + Console.WriteLine("typedef struct {0} {0};", ident); + + } /* end PrintLiteralStruct */ + + + /* -------------------------------------------------------------------------- + * method PrintLiteral() + * -------------------------------------------------------------------------- + * Prints a sequence of hex values representing the bit pattern of receiver. + * Format: ( 0xHHHHHHHH, 0xHHHHHHHH, ..., count ); + * ----------------------------------------------------------------------- */ + + public void PrintLiteral() + { + uint segmentIndex; + + Console.Write("( /* bits: */ 0x" + this.dataStored.segments[0].ToString("x08")); + + for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) + { + + Console.Write(", 0x" + this.dataStored.segments[segmentIndex].ToString("x08")); + } /* end for */ + + Console.WriteLine(", /* counter: */ " + this.dataStored.elemCount + " );"); + } /* end PrintLiteral */ + + /* -------------------------------------------------------------------------- + * method CountBits() + * -------------------------------------------------------------------------- + * Returns the number of set bits in set. + * ----------------------------------------------------------------------- */ + + static private uint CountBits(TokenSet set) + { + int bit; + uint segmentIndex, + bitCount = 0; + + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + for (bit = 0; bit < 32; bit++) + { + + if ((set.dataStored.segments[segmentIndex] & (1 << bit)) != 0) + { + bitCount++; + } /* end if */ + + } /* end for */ + + } /* end for */ + + return bitCount; + } /* end CountBits */ + + } /* end TokenSet */ + +} /* end namespace */ From 3f81c9df185f1e50ce7df0eb21a2e164e328f6f4 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Fri, 19 May 2017 16:29:38 -0700 Subject: [PATCH 07/24] Delete TokenSet.cs --- TokenSet.cs | 574 ---------------------------------------------------- 1 file changed, 574 deletions(-) delete mode 100644 TokenSet.cs diff --git a/TokenSet.cs b/TokenSet.cs deleted file mode 100644 index 7490eb1..0000000 --- a/TokenSet.cs +++ /dev/null @@ -1,574 +0,0 @@ -/* M2Sharp -- Modula-2 to C# Translator & Compiler - * - * Copyright (c) 2016 The Modula-2 Software Foundation - * - * Author & Maintainer: Benjamin Kowarsch - * - * @synopsis - * - * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. - * It supports the dialects described in the 3rd and 4th editions of Niklaus - * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, - * and an extended mode with select features from the revised language by - * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). - * - * In translator mode, M2Sharp translates Modula-2 source to C# source files. - * In compiler mode, M2Sharp compiles Modula-2 source via C# source files - * to object code or executables using the host system's C# compiler. - * - * @repository - * - * https://github.com/m2sf/m2sharp - * - * @file - * - * TokenSet.cs - * - * A set of Token type variables which is used to pass First and Follow sets - * - * @license - * - * M2Sharp is free software: you can redistribute and/or modify it under the - * terms of the GNU Lesser General Public License (LGPL) either version 2.1 - * or at your choice version 3 as published by the Free Software Foundation. - * However, you may not alter the copyright, author and license information. - * - * M2Sharp is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with M2Sharp. If not, see . - * - * NB: Components in the domain part of email addresses are in reverse order. - */ - - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace org.m2sf.m2sharp -{ - - public class TokenSet : ITokenSet { - - /* Lexeme Table */ - public static string[] lexemeTable = { - /* Null Token */ - - "UNKNOWN", - - /* Reserved Words */ - - "AND", - "ARGLIST", - "ARRAY", - "BEGIN", - "BY", - "CASE", - "CONST", - "DEFINITION", - "DIV", - "DO", - "ELSE", - "ELSIF", - "END", - "EXIT", - "EXPORT", - "FOR", - "FROM", - "IF", - "IMPLEMENTATION", - "IMPORT", - "IN", - "LOOP", - "MOD", - "MODULE", - "NOT", - "OF", - "OR", - "POINTER", - "PROCEDURE", - "QUALIFIED", - "RECORD", - "REPEAT", - "RETURN", - "SET", - "THEN", - "TO", - "TYPE", - "UNTIL", - "VAR", - "WHILE", - "WITH", - - /* Identifiers */ - - "IDENTIFIER", - - /* Literals */ - - "STRING-LITERAL", - "INTEGER-LITERAL", - "REAL-LITERAL", - "CHAR-LITERAL", - - "MALFORMED-STRING", - "MALFORMED-INTEGER", - "MALFORMED-REAL", - - /* Pragmas */ - - "PRAGMA", - - /* Special Symbols */ - - "PLUS", - "MINUS", - "EQUAL", - "NOTEQUAL", - "LESS-THAN", - "LESS-OR-EQUAL", - "GREATER-THAN", - "GREATER-OR-EQUAL", - "ASTERISK", - "SOLIDUS", - "BACKSLASH", - "ASSIGNMENT", - "COMMA", - "PERIOD", - "COLON", - "SEMICOLON", - "RANGE", - "DEREF", - "VERTICAL-BAR", - "LEFT-PAREN", - "RIGHT-PAREN", - "LEFT-BRACKET", - "RIGHT-BRACKET", - "LEFT-BRACE", - "RIGHT-BRACE", - "END-OF-FILE" - -}; /* end m2c_token_name_table */ - - public static const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; - - public struct TokenSetBits - { - public uint[] segments = new uint[segmentCount]; - public uint elemCount; - } /* end struct */ - - TokenSetBits dataStored; - - /* --------------------------------------------------------------------------- - * private constructor TokenSet () - * --------------------------------------------------------------------------- - * Prevents clients from invoking the default constructor. - * ------------------------------------------------------------------------ */ - - private TokenSet() - { - // no operation - } /* end TokenSet */ - - /* -------------------------------------------------------------------------- - * constructor newFromList(token, ...) - * -------------------------------------------------------------------------- - * Returns a newly allocated tokenset object that includes the tokens passed - * as arguments of a variadic argument list. - * ----------------------------------------------------------------------- */ - - public static TokenSet newFromList(params Token[] tokenList) - { - TokenSet newSet = new TokenSet(); - uint bit, segmentIndex; - Token token; - - /* allocate new set */ - newSet.dataStored.segments = new uint[segmentCount]; - - /* initialise */ - for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - newSet.dataStored.segments[segmentIndex] = 0; - } /* end For */ - - /* store tokens from list */ - token = tokenList[0]; - for (int i = 1; token != Token.Unknown; i++) - { - - if (token <= Token.EndOfFile) - { - segmentIndex = (uint)token / 32; - bit = (uint)token % 32; - newSet.dataStored.segments[segmentIndex] = (newSet.dataStored.segments[segmentIndex] | (uint)(1 << (int)bit)); - } /* end if */ - - /* get next token in list */ - token = tokenList[i]; - } /* end while */ - - /* update element counter */ - newSet.dataStored.elemCount = CountBits(newSet); - - return newSet; - } /* end newFromList */ - - - /* -------------------------------------------------------------------------- - * constructor newFromUnion(set, ...) - * -------------------------------------------------------------------------- - * Returns a newly allocated tokenset object that represents the set union of - * the tokensets passed as arguments of a non-empty variadic argument list. - * ----------------------------------------------------------------------- */ - - public static TokenSet newFromUnion(params TokenSet[] setList) - { - uint segmentIndex; - TokenSet set, - newSet = new TokenSet(); - - - /* initialise */ - newSet.dataStored.segments = new uint[segmentCount]; - for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - newSet.dataStored.segments[segmentIndex] = 0; - } /* end for */ - - set = setList[0]; - /* calculate union with each set in list */ - for (int i = 0; set != null; i++) - { - /* for each segment ... */ - while (segmentIndex < segmentCount) - { - /* ... store union of corresponding segments */ - newSet.dataStored.segments[segmentIndex] = - newSet.dataStored.segments[segmentIndex] | newSet.dataStored.segments[segmentIndex]; - - /* next segment */ - segmentIndex++; - } /* end while */ - - /*get next set in list */ - if (i < setList.Length) - set = setList[i]; - else - set = null; - - } /* end for */ - - /* update element counter */ - newSet.dataStored.elemCount = CountBits(newSet); - - return newSet; - } /* end newFromUnion - -/* -------------------------------------------------------------------------- - * method Count() - * -------------------------------------------------------------------------- - * Returns the number of elements in the receiver. - * ----------------------------------------------------------------------- */ - - public uint Count() - { - - return this.dataStored.elemCount; - } /* end IsElement */ - - - /* -------------------------------------------------------------------------- - * method IsElement(token) - * -------------------------------------------------------------------------- - * Returns true if token is an element of the receiver, else false. - * ----------------------------------------------------------------------- */ - - public bool IsElement(Token token) - { - int segmentIndex, bit; - - if (token > Token.EndOfFile) - { - return false; - } /* end if */ - - segmentIndex = (int)token / 32; - bit = (int)token % 32; - - return (this.dataStored.segments[segmentIndex] & (1 << bit)) != 0; - } /* end IsElement */ - - - /* -------------------------------------------------------------------------- - * method IsSubset(set) - * -------------------------------------------------------------------------- - * Returns true if each element in set is also in the receiver, else false. - * ----------------------------------------------------------------------- */ - - public bool IsSubset(TokenSet set) - { - - for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - - if (((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) - ^ this.dataStored.segments[segmentIndex]) != 0) - { - - return false; - - } /* end if */ - - } /* end for */ - - return true; - - } /* end IsSubset */ - - - /* -------------------------------------------------------------------------- - * method IsDisjunct(set) - * -------------------------------------------------------------------------- - * Returns true if set has no common elements with the receiver, else false. - * ----------------------------------------------------------------------- */ - - public bool IsDisjunct(TokenSet set) - { - - for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - - if ((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) != 0) - { - - return false; - - } /* end if */ - - } /* end for */ - - return true; - - } /* end IsDisjunct */ - - /* -------------------------------------------------------------------------- - * method ElementList() - * -------------------------------------------------------------------------- - * Returns a token list of all elements in the receiver. - * ----------------------------------------------------------------------- */ - //TODO - - public List ElementList() - { - List allElements = new List(); - uint segmentIndex, count; - int bit; - Token token; - - if (this.dataStored.elemCount == 0) - { - return null; - } /* end if */ - - token = 0; - count = 0; - - while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) - { - segmentIndex = (uint)token / 32; - bit = (int)token % 32; - - if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) - { - count++; - allElements.Add(token); - } /* end if */ - token++; - } /* end while */ - - return allElements; - - } /* end ElementList */ - - - /* -------------------------------------------------------------------------- - * method PrintSet(label) - * -------------------------------------------------------------------------- - * Prints a human readable representation of the receiver. - * Format: label = { comma-separated list of tokens }; - * ----------------------------------------------------------------------- */ - - public void PrintSet(string label) - { - uint segmentIndex, count; - int bit; - Token token; - - Console.Write(label + " = {"); - if (this.dataStored.elemCount == 0) - { - Console.Write(" "); - } /* end if */ - - token = 0; - count = 0; - - while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) - { - segmentIndex = (uint)token / 32; - bit = (int)token % 32; - - if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) - { - count++; - - if (count <= this.dataStored.elemCount) - { - - Console.Write("\n {0},", lexemeTable[(uint)token]); - } - else - { - Console.WriteLine("\n {0}", lexemeTable[(uint)token]); - } /* end if */ - } /* end if */ - token++; - } /* end while */ - - Console.WriteLine("};"); - } /* end PrintSet */ - - - /* -------------------------------------------------------------------------- - * method PrintList() - * -------------------------------------------------------------------------- - * Prints a human readable list of tokens in the receiver. - * Format: first, second, third, ..., secondToLast or last - * ----------------------------------------------------------------------- */ - - public void PrintList() - { - uint bit, segmentIndex, count; - Token token; - - if (this.dataStored.elemCount == 0) - { - Console.WriteLine("(nil)"); - } - - count = 0; - token = 0; - while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) - { - segmentIndex = (uint)token / 32; - bit = (uint)token % 32; - - if (((this.dataStored.segments[segmentIndex] & (1 << (int)bit)) != 0)) - { - count++; - if (count > 1) - { - if (count <= this.dataStored.elemCount) - { - Console.Write(", "); - } - else - { - Console.Write(" or "); - } /* end if */ - } /* end if */ - - Console.Write(lexemeTable[(uint)token]); - } - token++; - } - - Console.WriteLine("."); - } /* end PrintList */ - - - /* -------------------------------------------------------------------------- - * method PrintLiteralStruct(ident) - * -------------------------------------------------------------------------- - * Prints a struct definition for a tokenset literal for the receiver. - * Format: struct ident { uint s0; uint s1; uint s2; ...; uint n }; - * ----------------------------------------------------------------------- */ - - public void PrintLiteralStruct(string ident) - { - uint segmentIndex; - - Console.Write("struct {0} {{ uint s0", ident); - - for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) - { - Console.Write("; s" + segmentIndex); - } /* end for */ - - Console.WriteLine("; n };"); - Console.WriteLine("typedef struct {0} {0};", ident); - - } /* end PrintLiteralStruct */ - - - /* -------------------------------------------------------------------------- - * method PrintLiteral() - * -------------------------------------------------------------------------- - * Prints a sequence of hex values representing the bit pattern of receiver. - * Format: ( 0xHHHHHHHH, 0xHHHHHHHH, ..., count ); - * ----------------------------------------------------------------------- */ - - public void PrintLiteral() - { - uint segmentIndex; - - Console.Write("( /* bits: */ 0x" + this.dataStored.segments[0].ToString("x08")); - - for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) - { - - Console.Write(", 0x" + this.dataStored.segments[segmentIndex].ToString("x08")); - } /* end for */ - - Console.WriteLine(", /* counter: */ " + this.dataStored.elemCount + " );"); - } /* end PrintLiteral */ - - /* -------------------------------------------------------------------------- - * method CountBits() - * -------------------------------------------------------------------------- - * Returns the number of set bits in set. - * ----------------------------------------------------------------------- */ - - static private uint CountBits(TokenSet set) - { - int bit; - uint segmentIndex, - bitCount = 0; - - for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - - for (bit = 0; bit < 32; bit++) - { - - if ((set.dataStored.segments[segmentIndex] & (1 << bit)) != 0) - { - bitCount++; - } /* end if */ - - } /* end for */ - - } /* end for */ - - return bitCount; - } /* end CountBits */ - - } /* end TokenSet */ - -} /* end namespace */ From 61a32f4c57f9b3f2ea76907de8550e58b512c73c Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Fri, 19 May 2017 16:29:52 -0700 Subject: [PATCH 08/24] Delete Terminals.cs --- Terminals.cs | 525 --------------------------------------------------- 1 file changed, 525 deletions(-) delete mode 100644 Terminals.cs diff --git a/Terminals.cs b/Terminals.cs deleted file mode 100644 index b90861d..0000000 --- a/Terminals.cs +++ /dev/null @@ -1,525 +0,0 @@ -/* M2Sharp -- Modula-2 to C# Translator & Compiler - * - * Copyright (c) 2016 The Modula-2 Software Foundation - * - * Author & Maintainer: Benjamin Kowarsch - * - * @synopsis - * - * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. - * It supports the dialects described in the 3rd and 4th editions of Niklaus - * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, - * and an extended mode with select features from the revised language by - * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). - * - * In translator mode, M2Sharp translates Modula-2 source to C# source files. - * In compiler mode, M2Sharp compiles Modula-2 source via C# source files - * to object code or executables using the host system's C# compiler. - * - * @repository - * - * https://github.com/m2sf/m2sharp - * - * @file - * - * Terminals.cs - * - * Terminal symbols' token and lexeme lookup. - * - * @license - * - * M2Sharp is free software: you can redistribute and/or modify it under the - * terms of the GNU Lesser General Public License (LGPL) either version 2.1 - * or at your choice version 3 as published by the Free Software Foundation. - * However, you may not alter the copyright, author and license information. - * - * M2Sharp is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with M2Sharp. If not, see . - * - * NB: Components in the domain part of email addresses are in reverse order. - */ - -namespace org.m2sf.m2sharp { - -public class Terminals : ITerminals { - -const Token FirstResWord = Token.AND; -const Token LastResWord = Token.WITH; - -const Token FirstLiteral = Token.StringLiteral; -const Token LastLiteral = Token.CharLiteral; - -const Token FirstMalformedLiteral = Token.MalformedString; -const Token LastMalformedLiteral = Token.MalformedReal; - -const Token FirstSpecialSymbol = Token.Plus; -const Token LastSpecialSymbol = Token.RightBrace; - -public const int tokenEndMark = (int)Token.EndOfFile + 1; //SAM CHANGE - - -/* --------------------------------------------------------------------------- - * method IsValid(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a valid token, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsValid (Token token) { - return (token != Token.Unknown) && !IsMalformedLiteral(token); -} /* end IsValid */ - - -/* --------------------------------------------------------------------------- - * method IsResword(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a reserved word, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsResword (Token token) { - return (token >= FirstResWord) && (token <= LastResWord); -} /* end IsResword */ - - -/* --------------------------------------------------------------------------- - * method IsLiteral(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a literal, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsLiteral (Token token) { - return (token >= FirstLiteral) && (token <= LastLiteral); -} /* end IsLiteral */ - - -/* --------------------------------------------------------------------------- - * method IsMalformedLiteral(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a malformed literal, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsMalformedLiteral (Token token) { - return (token >= FirstMalformedLiteral) && (token <= LastMalformedLiteral); -} /* end IsMalformedLiteral */ - - -/* --------------------------------------------------------------------------- - * method IsSpecialSymbol(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a special symbol, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsSpecialSymbol (Token token) { - return (token >= FirstSpecialSymbol) && (token <= LastSpecialSymbol); -} /* end IsSpecialSymbol */ - - -/* --------------------------------------------------------------------------- - * method TokenForResword(lexeme) - * --------------------------------------------------------------------------- - * Tests if the given lexeme represents a reserved word and returns the - * corresponding token or Unknown if it does not match a reserved word. - * ------------------------------------------------------------------------ */ - -public static Token TokenForResword (string lexeme) { - int length; - - /* check pre-conditions */ - if (lexeme == null) { - return Token.Unknown; - } /* end if */ - - length = lexeme.Length; - - if ((length < 2) || (length > 14)) { - return Token.Unknown; - } /* end if */ - - switch (length) { - case /* length = 2 */ 2 : - switch (lexeme[0]) { - - case 'B' : - /* BY */ - if (lexeme[1] == 'Y') { - return Token.BY; - } /* end if */ - break; - - case 'D' : - /* DO */ - if (lexeme[1] == 'O') { - return Token.DO; - } /* end if */ - break; - - case 'I' : - /* IF */ - if (lexeme[1] == 'F') { - return Token.IF; - } - - /* IN */ - else if (lexeme[1] == 'N') { - return Token.IN; - } /* end if */ - break; - - case 'O' : - /* OF */ - if (lexeme[1] == 'F') { - return Token.OF; - } - - /* OR */ - else if (lexeme[1] == 'R') { - return Token.OR; - } /* end if */ - break; - - case 'T' : - /* TO */ - if (lexeme[1] == 'O') { - return Token.TO; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 3 */ 3 : - switch (lexeme[0]) { - - case 'A' : - /* AND */ - if (string.CompareOrdinal(lexeme, "AND") == 0) { - return Token.AND; - } /* end if */ - break; - - case 'D' : - /* DIV */ - if (string.CompareOrdinal(lexeme, "DIV") == 0) { - return Token.DIV; - } /* end if */ - break; - - case 'E' : - /* END */ - if (string.CompareOrdinal(lexeme, "END") == 0) { - return Token.END; - } /* end if */ - break; - - case 'F' : - /* FOR */ - if (string.CompareOrdinal(lexeme, "FOR") == 0) { - return Token.FOR; - } /* end if */ - break; - - case 'M' : - /* MOD */ - if (string.CompareOrdinal(lexeme, "MOD") == 0) { - return Token.MOD; - } /* end if */ - break; - - case 'N' : - /* NOT */ - if (string.CompareOrdinal(lexeme, "NOT") == 0) { - return Token.NOT; - } /* end if */ - break; - - case 'S' : - /* SET */ - if (string.CompareOrdinal(lexeme, "SET") == 0) { - return Token.SET; - } /* end if */ - break; - - case 'V' : - /* VAR */ - if (string.CompareOrdinal(lexeme, "VAR") == 0) { - return Token.VAR; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 4 */ 4 : - switch (lexeme[1]) { - - case 'A' : - /* CASE */ - if (string.CompareOrdinal(lexeme, "CASE") == 0) { - return Token.CASE; - } /* end if */ - break; - - case 'H' : - /* THEN */ - if (string.CompareOrdinal(lexeme, "THEN") == 0) { - return Token.THEN; - } /* end if */ - break; - - case 'I' : - /* WITH */ - if (string.CompareOrdinal(lexeme, "WITH") == 0) { - return Token.WITH; - } /* end if */ - break; - - case 'L' : - /* ELSE */ - if (string.CompareOrdinal(lexeme, "ELSE") == 0) { - return Token.ELSE; - } /* end if */ - break; - - case 'O' : - /* LOOP */ - if (string.CompareOrdinal(lexeme, "LOOP") == 0) { - return Token.LOOP; - } /* end if */ - break; - - case 'R' : - /* FROM */ - if (string.CompareOrdinal(lexeme, "FROM") == 0) { - return Token.FROM; - } /* end if */ - break; - - case 'X' : - /* EXIT */ - if (string.CompareOrdinal(lexeme, "EXIT") == 0) { - return Token.EXIT; - } /* end if */ - break; - - case 'Y' : - /* TYPE */ - if (string.CompareOrdinal(lexeme, "TYPE") == 0) { - return Token.TYPE; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 5 */ 5 : - switch (lexeme[0]) { - - case 'A' : - /* ARRAY */ - if (string.CompareOrdinal(lexeme, "ARRAY") == 0) { - return Token.ARRAY; - } /* end if */ - break; - - case 'B' : - /* BEGIN */ - if (string.CompareOrdinal(lexeme, "BEGIN") == 0) { - return Token.BEGIN; - } /* end if */ - break; - - case 'C' : - /* CONST */ - if (string.CompareOrdinal(lexeme, "CONST") == 0) { - return Token.CONST; - } /* end if */ - break; - - case 'E' : - /* ELSIF */ - if (string.CompareOrdinal(lexeme, "ELSIF") == 0) { - return Token.ELSIF; - } /* end if */ - break; - - case 'U' : - /* UNTIL */ - if (string.CompareOrdinal(lexeme, "UNTIL") == 0) { - return Token.UNTIL; - } /* end if */ - break; - - case 'W' : - /* WHILE */ - if (string.CompareOrdinal(lexeme, "WHILE") == 0) { - return Token.WHILE; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length 6 */ 6 : - switch (lexeme[5]) { - - case 'E' : - /* MODULE */ - if (string.CompareOrdinal(lexeme, "MODULE") == 0) { - return Token.MODULE; - } /* end if */ - break; - - case 'D' : - /* RECORD */ - if (string.CompareOrdinal(lexeme, "RECORD") == 0) { - return Token.RECORD; - } /* end if */ - break; - - case 'N' : - /* RETURN */ - if (string.CompareOrdinal(lexeme, "RETURN") == 0) { - return Token.RETURN; - } /* end if */ - break; - - case 'T' : - switch (lexeme[0]) { - - case 'E' : - /* EXPORT */ - if (string.CompareOrdinal(lexeme, "EXPORT") == 0) { - return Token.EXPORT; - } /* end if */ - break; - - case 'I' : - /* IMPORT */ - if (string.CompareOrdinal(lexeme, "IMPORT") == 0) { - return Token.IMPORT; - } /* end if */ - break; - - case 'R' : - /* REPEAT */ - if (string.CompareOrdinal(lexeme, "REPEAT") == 0) { - return Token.REPEAT; - } /* end if */ - break; - - } /* end switch */ - break; - - } /* end switch */ - break; - - case /* length = 7 */ 7 : - switch (lexeme[0]) { - - case 'A' : - /* ARGLIST */ - if (string.CompareOrdinal(lexeme, "ARGLIST") == 0) { - return Token.ARGLIST; - } /* end if */ - break; - - case 'P' : - /* POINTER */ - if (string.CompareOrdinal(lexeme, "POINTER") == 0) { - return Token.POINTER; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 9 */ 9 : - switch (lexeme[0]) { - - case 'P' : - /* PROCEDURE */ - if (string.CompareOrdinal(lexeme, "PROCEDURE") == 0) { - return Token.PROCEDURE; - } /* end if */ - break; - - case 'Q' : - /* QUALIFIED */ - if (string.CompareOrdinal(lexeme, "QUALIFIED") == 0) { - return Token.QUALIFIED; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 10 */ 10 : - /* DEFINITION */ - if (string.CompareOrdinal(lexeme, "DEFINITION") == 0) { - return Token.DEFINITION; - } /* end if */ - break; - - case /* length = 14 */ 14 : - /* IMPLEMENTATION */ - if (string.CompareOrdinal(lexeme, "IMPLEMENTATION") == 0) { - return Token.IMPLEMENTATION; - } /* end if */ - break; - - } /* end switch (length) */ - - return Token.Unknown; -} /* end TokenForResword */ - - -/* --------------------------------------------------------------------------- - * method LexemeForResword(token) - * --------------------------------------------------------------------------- - * Returns a string with the lexeme for the reserved word represented by - * token. Returns null if the token does not represent a reserved word. - * ------------------------------------------------------------------------ */ - -public static string LexemeForResword (Token token) { - if (IsResword(token) == false) { - return null; - } /* end if */ - return TokenSet.lexemeTable[(uint)token]; -} /* end LexemeForResword */ - - -/* --------------------------------------------------------------------------- - * method LexemeForSpecialSymbol(token) - * --------------------------------------------------------------------------- - * Returns a string with the lexeme for the special symbol represented by - * token. Returns null if the token does not represent a special symbol. - * ------------------------------------------------------------------------ */ - -public static string LexemeForSpecialSymbol (Token token) { - if (IsSpecialSymbol(token) == false) { - return null; - } /* end if */ - return ""; // TO DO -} /* end LexemeForSpecialSymbol */ - - -/* --------------------------------------------------------------------------- - * method NameForToken(token) - * --------------------------------------------------------------------------- - * Returns a string with a human readable name for token. Returns null if - * token is not a valid token. - * ------------------------------------------------------------------------ */ - -public static string NameForToken (Token token) { - return token.ToString(); -} /* NameForToken */ - - -} /* Terminals */ - -} /* namespace */ - -/* END OF FILE */ \ No newline at end of file From 24a7263f2fc5e1b21d956a9579260332850ecf40 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Fri, 19 May 2017 16:30:01 -0700 Subject: [PATCH 09/24] Delete NonTerminals.cs --- NonTerminals.cs | 167 ------------------------------------------------ 1 file changed, 167 deletions(-) delete mode 100644 NonTerminals.cs diff --git a/NonTerminals.cs b/NonTerminals.cs deleted file mode 100644 index 24f827a..0000000 --- a/NonTerminals.cs +++ /dev/null @@ -1,167 +0,0 @@ -/* M2Sharp -- Modula-2 to C# Translator & Compiler - * - * Copyright (c) 2016 The Modula-2 Software Foundation - * - * Author & Maintainer: Benjamin Kowarsch - * - * @synopsis - * - * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. - * It supports the dialects described in the 3rd and 4th editions of Niklaus - * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, - * and an extended mode with select features from the revised language by - * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). - * - * In translator mode, M2Sharp translates Modula-2 source to C# source files. - * In compiler mode, M2Sharp compiles Modula-2 source via C# source files - * to object code or executables using the host system's C# compiler. - * - * @repository - * - * https://github.com/m2sf/m2sharp - * - * @file - * - * NonTerminals.cs - * - * provides FIRST() and FOLLOW() sets for each non-terminal symbol //SAM CHANGE - * used by the parser class for syntax analysis - * - * @license - * - * M2Sharp is free software: you can redistribute and/or modify it under the - * terms of the GNU Lesser General Public License (LGPL) either version 2.1 - * or at your choice version 3 as published by the Free Software Foundation. - * However, you may not alter the copyright, author and license information. - * - * M2Sharp is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with M2Sharp. If not, see . - * - * NB: Components in the domain part of email addresses are in reverse order. - */ - -namespace org.m2sf.m2sharp { - - using System; - using System.Collections.Generic; - -public class NonTerminals : INonTerminals { - - public static Production firstConstParamDependent = Production.FormalType, - lastConstParamDependent = Production.AttribFormalParams, - firstNoVariantRecDependent = Production.TypeDeclarationTail, - lastNoVariantRecDependent = Production.TypeDeclarationTail, - firstOptionDependent = firstConstParamDependent, - lastOptionDependent = lastNoVariantRecDependent; - public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; - - TokenSet[] followSet = new TokenSet[Count()]; - TokenSet[] firstSet = new TokenSet[Count()]; - - /* -------------------------------------------------------------------------- - * method Count() -- Returns the number of productions - * ----------------------------------------------------------------------- */ //SAM CHANGE - - static uint Count() { - return (uint)Enum.GetNames(typeof(Production)).Length; - } /* end Count */ - - - /* -------------------------------------------------------------------------- - * method IsOptionDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on any compiler option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE - - bool IsOptionDependent(Production p) { - return p >= firstOptionDependent; - } /* end IsOptionDependent */ - - - /* -------------------------------------------------------------------------- - * method IsConstParamDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on CONST parameter option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE - - bool IsConstParamDependent(Production p) - { - return p >= firstConstParamDependent && p <= lastConstParamDependent; - } /* end IsConstParamDependent */ - - - /* -------------------------------------------------------------------------- - * method IsVariantRecordDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on variant record type option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE - - bool IsVariantRecordDependent(Production p) { - return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; - } - - /* -------------------------------------------------------------------------- - * method FIRST(p) - * -------------------------------------------------------------------------- - * Returns a tokenset with the FIRST set of production p. - * ----------------------------------------------------------------------- */ - - TokenSet FIRST(Production p) { - TokenSet tokenset = null; - uint index = 0; - - if (IsConstParamDependent(p)) - { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) - { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - - tokenset = firstSet[index]; - - return tokenset; - } /* end FIRST */ - - - /* -------------------------------------------------------------------------- - * method FOLLOW(p) - * -------------------------------------------------------------------------- - * Returns a tokenset with the FOLLOW set of production p. - * ----------------------------------------------------------------------- */ - - TokenSet FOLLOW(Production p) { - TokenSet tokenset = null; - uint index = 0; - - if (IsConstParamDependent(p)) { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - - tokenset = followSet[index]; - - return tokenset; - } /* end FOLLOW */ - - - /* -------------------------------------------------------------------------- - * method NameForProduction(p) - * -------------------------------------------------------------------------- - * Returns a string with a human readable name for production p. - * ----------------------------------------------------------------------- */ - - string NameForProduction(Production p); - - - -} /* NonTerminals */ - -} /* namespace */ \ No newline at end of file From be294dcadbf30bdeeadd3d87e22c6baa16d8336e Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Tue, 23 May 2017 12:28:33 -0700 Subject: [PATCH 10/24] Add files via upload --- ITerminals.cs | 2 +- NonTerminals.cs | 306 +++++++++++++++++++++++++++++++++++++++++++++++- Terminals.cs | 117 +++++++++--------- 3 files changed, 362 insertions(+), 63 deletions(-) diff --git a/ITerminals.cs b/ITerminals.cs index 5227bec..8fbc95a 100644 --- a/ITerminals.cs +++ b/ITerminals.cs @@ -60,7 +60,7 @@ public enum Token { AND, ARGLIST, ARRAY, BEGIN, BY, CASE, CONST, DEFINITION, DIV, DO, ELSE, ELSIF, END, EXIT, EXPORT, FOR, FROM, IF, IMPLEMENTATION, IMPORT, IN, LOOP, - MOD, MODULE, NOT, OF, OR, POINTER, PROCEDURE, QUALIFIED, RECORD, REPEAT, + MOD, MODULE, NOT, OF, OPAQUE, OR, POINTER, PROCEDURE, QUALIFIED, RECORD, REPEAT, RETURN, SET, THEN, TO, TYPE, UNTIL, VAR, WHILE, WITH, /* Identifiers */ diff --git a/NonTerminals.cs b/NonTerminals.cs index 24f827a..3620d28 100644 --- a/NonTerminals.cs +++ b/NonTerminals.cs @@ -57,10 +57,304 @@ public class NonTerminals : INonTerminals { lastNoVariantRecDependent = Production.TypeDeclarationTail, firstOptionDependent = firstConstParamDependent, lastOptionDependent = lastNoVariantRecDependent; - public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; - - TokenSet[] followSet = new TokenSet[Count()]; - TokenSet[] firstSet = new TokenSet[Count()]; + public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; + + #region followSets + TokenSet[] followSets = { + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* definitionModule */ + + new TokenSet( /* bits: */ 0x108050C8, 0x00000050, 0x00000000, /* counter: */ 9 ), /* import */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* qualifiedImport */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* unqualifiedImport */ + + new TokenSet( /* bits: */ 0x00000000, 0x80000000, 0x00000021, /* counter: */ 3 ), /* identList */ + + new TokenSet( /* bits: */ 0x00001000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* constDefinition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDefinition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* type */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* derivedOrSubrangeType */ + + new TokenSet( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000037B, /* counter: */ 34 ), /* qualident */ + + new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* range */ + + new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* enumType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* setType */ + + new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* countableType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* arrayType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* extensibleRecordType */ + + new TokenSet( /* bits: */ 0x00001000, 0x00000040, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variantRecordType */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variantFieldListSeq */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFieldList */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFields */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variant */ + + new TokenSet( /* bits: */ 0x00000000, 0x80000000, 0x00000000, /* counter: */ 1 ), /* caseLabelList */ + + new TokenSet( /* bits: */ 0x00000000, 0xA0000000, 0x00000000, /* counter: */ 2 ), /* caseLabels */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* pointerType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureType */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* simpleFormalType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureHeader */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureSignature */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* simpleFormalParams */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* implementationModule */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* programModule */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* modulePriority */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* block */ + + new TokenSet( /* bits: */ 0x00001008, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* varSizeRecordType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variableDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* moduleDeclaration */ + + new TokenSet( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* export */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000008, /* counter: */ 5 ), /* statementSequence */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* statement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* assignmentOrProcCall */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* actualParameters */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* expressionList */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* returnStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* withStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* ifStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* caseStatement */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* case */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* loopStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* whileStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* repeatStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* forStatement */ + + new TokenSet( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000033B, /* counter: */ 33 ), /* designator */ + + new TokenSet( /* bits: */ 0x06501F12, 0x3FFC022C, 0x0000033B, /* counter: */ 34 ), /* selector */ + + new TokenSet( /* bits: */ 0x02001E10, 0x2000002C, 0x0000022B, /* counter: */ 15 ), /* expression */ + + new TokenSet( /* bits: */ 0x02101E10, 0x23F0002C, 0x0000022B, /* counter: */ 22 ), /* simpleExpression */ + + new TokenSet( /* bits: */ 0x06101E10, 0x23FC002C, 0x0000022B, /* counter: */ 25 ), /* term */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* simpleTerm */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* factor */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* designatorOrFuncCall */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* setValue */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000200, /* counter: */ 2 ), /* element */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* formalType */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* attributedFormalType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* formalParamList */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* formalParams */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* attribFormalParams */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclarationTail */ + }; + + #endregion + + #region firstSets + TokenSet[] firstSets = { + new TokenSet( /* bits: */ 0x00000080, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ + + new TokenSet( /* bits: */ 0x00090000, 0x00000000, 0x00000000, /* counter: */ 2 ), /* import */ + + new TokenSet( /* bits: */ 0x00080000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* qualifiedImport */ + + new TokenSet( /* bits: */ 0x00010000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* unqualifiedImport */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* identList */ + + new TokenSet( /* bits: */ 0x10000040, 0x00000050, 0x00000000, /* counter: */ 4 ), /* definition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* constDefinition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* typeDefinition */ + + new TokenSet( /* bits: */ 0x58000004, 0x00000202, 0x00000050, /* counter: */ 8 ), /* type */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000040, /* counter: */ 2 ), /* derivedOrSubrangeType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* qualident */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* range */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000010, /* counter: */ 1 ), /* enumType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000002, 0x00000000, /* counter: */ 1 ), /* setType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000050, /* counter: */ 3 ), /* countableType */ + + new TokenSet( /* bits: */ 0x00000004, 0x00000000, 0x00000000, /* counter: */ 1 ), /* arrayType */ + + new TokenSet( /* bits: */ 0x40000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* extensibleRecordType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* fieldListSequence */ + + new TokenSet( /* bits: */ 0x40000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantRecordType */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000200, 0x00000000, /* counter: */ 2 ), /* variantFieldListSeq */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000200, 0x00000000, /* counter: */ 2 ), /* variantFieldList */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantFields */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* variant */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* caseLabelList */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* caseLabels */ + + new TokenSet( /* bits: */ 0x08000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* pointerType */ + + new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureType */ + + new TokenSet( /* bits: */ 0x00000004, 0x00000200, 0x00000000, /* counter: */ 2 ), /* simpleFormalType */ + + new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureHeader */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* procedureSignature */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* simpleFormalParams */ + + new TokenSet( /* bits: */ 0x00040000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* implementationModule */ + + new TokenSet( /* bits: */ 0x00800000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* programModule */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* modulePriority */ + + new TokenSet( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* block */ + + new TokenSet( /* bits: */ 0x10800040, 0x00000050, 0x00000000, /* counter: */ 5 ), /* declaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* typeDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000040, 0x00000000, /* counter: */ 1 ), /* varSizeRecordType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* variableDeclaration */ + + new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureDeclaration */ + + new TokenSet( /* bits: */ 0x00800000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* moduleDeclaration */ + + new TokenSet( /* bits: */ 0x00004000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* export */ + + new TokenSet( /* bits: */ 0x8022A020, 0x00000381, 0x00000000, /* counter: */ 10 ), /* statementSequence */ + + new TokenSet( /* bits: */ 0x8022A020, 0x00000381, 0x00000000, /* counter: */ 10 ), /* statement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* assignmentOrProcCall */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000010, /* counter: */ 1 ), /* actualParameters */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* expressionList */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000001, 0x00000000, /* counter: */ 1 ), /* returnStatement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000100, 0x00000000, /* counter: */ 1 ), /* withStatement */ + + new TokenSet( /* bits: */ 0x00020000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* ifStatement */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000000, 0x00000000, /* counter: */ 1 ), /* caseStatement */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* case */ + + new TokenSet( /* bits: */ 0x00200000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* loopStatement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000080, 0x00000000, /* counter: */ 1 ), /* whileStatement */ + + new TokenSet( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* repeatStatement */ + + new TokenSet( /* bits: */ 0x00008000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* forStatement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* designator */ + + new TokenSet( /* bits: */ 0x00000000, 0x40000000, 0x00000044, /* counter: */ 3 ), /* selector */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* expression */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* simpleExpression */ + + new TokenSet( /* bits: */ 0x01000000, 0x00003E00, 0x00000110, /* counter: */ 8 ), /* term */ + + new TokenSet( /* bits: */ 0x01000000, 0x00003E00, 0x00000110, /* counter: */ 8 ), /* simpleTerm */ + + new TokenSet( /* bits: */ 0x00000000, 0x00003E00, 0x00000110, /* counter: */ 7 ), /* factor */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* designatorOrFuncCall */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* setValue */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* element */ + + new TokenSet( /* bits: */ 0x00000044, 0x00000240, 0x00000000, /* counter: */ 4 ), /* formalType */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000040, 0x00000000, /* counter: */ 2 ), /* attributedFormalType */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000240, 0x00000000, /* counter: */ 3 ), /* formalParamList */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000240, 0x00000000, /* counter: */ 3 ), /* formalParams */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000040, 0x00000000, /* counter: */ 2 ), /* attribFormalParams */ + + new TokenSet( /* bits: */ 0x58000004, 0x00000242, 0x00000050, /* counter: */ 9 ), /* typeDeclarationTail */ + }; + #endregion /* -------------------------------------------------------------------------- * method Count() -- Returns the number of productions @@ -123,7 +417,7 @@ TokenSet FIRST(Production p) { index = Convert.ToUInt32(p) + alternateSetOffset; } /* end if */ - tokenset = firstSet[index]; + tokenset = firstSets[index]; return tokenset; } /* end FIRST */ @@ -146,7 +440,7 @@ TokenSet FOLLOW(Production p) { index = Convert.ToUInt32(p) + alternateSetOffset; } /* end if */ - tokenset = followSet[index]; + tokenset = followSets[index]; return tokenset; } /* end FOLLOW */ diff --git a/Terminals.cs b/Terminals.cs index b90861d..70e015f 100644 --- a/Terminals.cs +++ b/Terminals.cs @@ -57,9 +57,7 @@ public class Terminals : ITerminals { const Token LastMalformedLiteral = Token.MalformedReal; const Token FirstSpecialSymbol = Token.Plus; -const Token LastSpecialSymbol = Token.RightBrace; - -public const int tokenEndMark = (int)Token.EndOfFile + 1; //SAM CHANGE +const Token LastSpecialSymbol = Token.RightBrace; /* --------------------------------------------------------------------------- @@ -363,58 +361,65 @@ public static Token TokenForResword (string lexeme) { break; case /* length 6 */ 6 : - switch (lexeme[5]) { - - case 'E' : - /* MODULE */ - if (string.CompareOrdinal(lexeme, "MODULE") == 0) { - return Token.MODULE; - } /* end if */ - break; - - case 'D' : - /* RECORD */ - if (string.CompareOrdinal(lexeme, "RECORD") == 0) { - return Token.RECORD; - } /* end if */ - break; - - case 'N' : - /* RETURN */ - if (string.CompareOrdinal(lexeme, "RETURN") == 0) { - return Token.RETURN; - } /* end if */ - break; - - case 'T' : - switch (lexeme[0]) { - - case 'E' : - /* EXPORT */ - if (string.CompareOrdinal(lexeme, "EXPORT") == 0) { - return Token.EXPORT; - } /* end if */ - break; - - case 'I' : - /* IMPORT */ - if (string.CompareOrdinal(lexeme, "IMPORT") == 0) { - return Token.IMPORT; - } /* end if */ - break; - - case 'R' : - /* REPEAT */ - if (string.CompareOrdinal(lexeme, "REPEAT") == 0) { - return Token.REPEAT; - } /* end if */ - break; - - } /* end switch */ - break; - - } /* end switch */ - break; + switch (lexeme[2]) { + + case 'D' : + /* MODULE */ + if (string.CompareOrdinal(lexeme, "MODULE") == 0) { + return Token.MODULE; + } /* end if */ + break; + + case 'A' : + /* OPAQUE */ + if (string.CompareOrdinal(lexeme, "OPAQUE") == 0) { + return Token.OPAQUE; + } /* end if */ + break; + + case 'C' : + /* RECORD */ + if (string.CompareOrdinal(lexeme, "RECORD") == 0) { + return Token.RECORD; + } /* end if */ + break; + + case 'T' : + /* RETURN */ + if (string.CompareOrdinal(lexeme, "RETURN") == 0) { + return Token.RETURN; + } /* end if */ + break; + + case 'P' : + switch (lexeme[0]) { + + case 'E' : + /* EXPORT */ + if (string.CompareOrdinal(lexeme, "EXPORT") == 0) { + return Token.EXPORT; + } /* end if */ + break; + + case 'I' : + /* IMPORT */ + if (string.CompareOrdinal(lexeme, "IMPORT") == 0) { + return Token.IMPORT; + } /* end if */ + break; + + case 'R' : + /* REPEAT */ + if (string.CompareOrdinal(lexeme, "REPEAT") == 0) { + return Token.REPEAT; + } /* end if */ + break; + + } /* end switch */ + break; + + } /* end switch */ +break; case /* length = 7 */ 7 : switch (lexeme[0]) { @@ -487,7 +492,7 @@ public static string LexemeForResword (Token token) { if (IsResword(token) == false) { return null; } /* end if */ - return TokenSet.lexemeTable[(uint)token]; + return token.ToString(); } /* end LexemeForResword */ From e9f9daa5bc2263a7f8fa6b5e2d9d9403e808f5fa Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Tue, 23 May 2017 12:54:21 -0700 Subject: [PATCH 11/24] Add files via upload --- NonTerminals.cs | 461 +++++++++++++++++++++++++++++++++++++ Terminals.cs | 530 +++++++++++++++++++++++++++++++++++++++++++ TokenSet.cs | 588 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1579 insertions(+) create mode 100644 NonTerminals.cs create mode 100644 Terminals.cs create mode 100644 TokenSet.cs diff --git a/NonTerminals.cs b/NonTerminals.cs new file mode 100644 index 0000000..3620d28 --- /dev/null +++ b/NonTerminals.cs @@ -0,0 +1,461 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * NonTerminals.cs + * + * provides FIRST() and FOLLOW() sets for each non-terminal symbol //SAM CHANGE + * used by the parser class for syntax analysis + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +namespace org.m2sf.m2sharp { + + using System; + using System.Collections.Generic; + +public class NonTerminals : INonTerminals { + + public static Production firstConstParamDependent = Production.FormalType, + lastConstParamDependent = Production.AttribFormalParams, + firstNoVariantRecDependent = Production.TypeDeclarationTail, + lastNoVariantRecDependent = Production.TypeDeclarationTail, + firstOptionDependent = firstConstParamDependent, + lastOptionDependent = lastNoVariantRecDependent; + public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; + + #region followSets + TokenSet[] followSets = { + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* definitionModule */ + + new TokenSet( /* bits: */ 0x108050C8, 0x00000050, 0x00000000, /* counter: */ 9 ), /* import */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* qualifiedImport */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* unqualifiedImport */ + + new TokenSet( /* bits: */ 0x00000000, 0x80000000, 0x00000021, /* counter: */ 3 ), /* identList */ + + new TokenSet( /* bits: */ 0x00001000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* constDefinition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDefinition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* type */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* derivedOrSubrangeType */ + + new TokenSet( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000037B, /* counter: */ 34 ), /* qualident */ + + new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* range */ + + new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* enumType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* setType */ + + new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* countableType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* arrayType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* extensibleRecordType */ + + new TokenSet( /* bits: */ 0x00001000, 0x00000040, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variantRecordType */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variantFieldListSeq */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFieldList */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFields */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variant */ + + new TokenSet( /* bits: */ 0x00000000, 0x80000000, 0x00000000, /* counter: */ 1 ), /* caseLabelList */ + + new TokenSet( /* bits: */ 0x00000000, 0xA0000000, 0x00000000, /* counter: */ 2 ), /* caseLabels */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* pointerType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureType */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* simpleFormalType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureHeader */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureSignature */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* simpleFormalParams */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* implementationModule */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* programModule */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* modulePriority */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* block */ + + new TokenSet( /* bits: */ 0x00001008, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* varSizeRecordType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variableDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* moduleDeclaration */ + + new TokenSet( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* export */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000008, /* counter: */ 5 ), /* statementSequence */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* statement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* assignmentOrProcCall */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* actualParameters */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* expressionList */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* returnStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* withStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* ifStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* caseStatement */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* case */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* loopStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* whileStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* repeatStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* forStatement */ + + new TokenSet( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000033B, /* counter: */ 33 ), /* designator */ + + new TokenSet( /* bits: */ 0x06501F12, 0x3FFC022C, 0x0000033B, /* counter: */ 34 ), /* selector */ + + new TokenSet( /* bits: */ 0x02001E10, 0x2000002C, 0x0000022B, /* counter: */ 15 ), /* expression */ + + new TokenSet( /* bits: */ 0x02101E10, 0x23F0002C, 0x0000022B, /* counter: */ 22 ), /* simpleExpression */ + + new TokenSet( /* bits: */ 0x06101E10, 0x23FC002C, 0x0000022B, /* counter: */ 25 ), /* term */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* simpleTerm */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* factor */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* designatorOrFuncCall */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* setValue */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000200, /* counter: */ 2 ), /* element */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* formalType */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* attributedFormalType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* formalParamList */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* formalParams */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* attribFormalParams */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclarationTail */ + }; + + #endregion + + #region firstSets + TokenSet[] firstSets = { + new TokenSet( /* bits: */ 0x00000080, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ + + new TokenSet( /* bits: */ 0x00090000, 0x00000000, 0x00000000, /* counter: */ 2 ), /* import */ + + new TokenSet( /* bits: */ 0x00080000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* qualifiedImport */ + + new TokenSet( /* bits: */ 0x00010000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* unqualifiedImport */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* identList */ + + new TokenSet( /* bits: */ 0x10000040, 0x00000050, 0x00000000, /* counter: */ 4 ), /* definition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* constDefinition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* typeDefinition */ + + new TokenSet( /* bits: */ 0x58000004, 0x00000202, 0x00000050, /* counter: */ 8 ), /* type */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000040, /* counter: */ 2 ), /* derivedOrSubrangeType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* qualident */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* range */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000010, /* counter: */ 1 ), /* enumType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000002, 0x00000000, /* counter: */ 1 ), /* setType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000050, /* counter: */ 3 ), /* countableType */ + + new TokenSet( /* bits: */ 0x00000004, 0x00000000, 0x00000000, /* counter: */ 1 ), /* arrayType */ + + new TokenSet( /* bits: */ 0x40000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* extensibleRecordType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* fieldListSequence */ + + new TokenSet( /* bits: */ 0x40000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantRecordType */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000200, 0x00000000, /* counter: */ 2 ), /* variantFieldListSeq */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000200, 0x00000000, /* counter: */ 2 ), /* variantFieldList */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantFields */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* variant */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* caseLabelList */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* caseLabels */ + + new TokenSet( /* bits: */ 0x08000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* pointerType */ + + new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureType */ + + new TokenSet( /* bits: */ 0x00000004, 0x00000200, 0x00000000, /* counter: */ 2 ), /* simpleFormalType */ + + new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureHeader */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* procedureSignature */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* simpleFormalParams */ + + new TokenSet( /* bits: */ 0x00040000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* implementationModule */ + + new TokenSet( /* bits: */ 0x00800000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* programModule */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* modulePriority */ + + new TokenSet( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* block */ + + new TokenSet( /* bits: */ 0x10800040, 0x00000050, 0x00000000, /* counter: */ 5 ), /* declaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* typeDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000040, 0x00000000, /* counter: */ 1 ), /* varSizeRecordType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* variableDeclaration */ + + new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureDeclaration */ + + new TokenSet( /* bits: */ 0x00800000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* moduleDeclaration */ + + new TokenSet( /* bits: */ 0x00004000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* export */ + + new TokenSet( /* bits: */ 0x8022A020, 0x00000381, 0x00000000, /* counter: */ 10 ), /* statementSequence */ + + new TokenSet( /* bits: */ 0x8022A020, 0x00000381, 0x00000000, /* counter: */ 10 ), /* statement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* assignmentOrProcCall */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000010, /* counter: */ 1 ), /* actualParameters */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* expressionList */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000001, 0x00000000, /* counter: */ 1 ), /* returnStatement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000100, 0x00000000, /* counter: */ 1 ), /* withStatement */ + + new TokenSet( /* bits: */ 0x00020000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* ifStatement */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000000, 0x00000000, /* counter: */ 1 ), /* caseStatement */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* case */ + + new TokenSet( /* bits: */ 0x00200000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* loopStatement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000080, 0x00000000, /* counter: */ 1 ), /* whileStatement */ + + new TokenSet( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* repeatStatement */ + + new TokenSet( /* bits: */ 0x00008000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* forStatement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* designator */ + + new TokenSet( /* bits: */ 0x00000000, 0x40000000, 0x00000044, /* counter: */ 3 ), /* selector */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* expression */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* simpleExpression */ + + new TokenSet( /* bits: */ 0x01000000, 0x00003E00, 0x00000110, /* counter: */ 8 ), /* term */ + + new TokenSet( /* bits: */ 0x01000000, 0x00003E00, 0x00000110, /* counter: */ 8 ), /* simpleTerm */ + + new TokenSet( /* bits: */ 0x00000000, 0x00003E00, 0x00000110, /* counter: */ 7 ), /* factor */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* designatorOrFuncCall */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* setValue */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* element */ + + new TokenSet( /* bits: */ 0x00000044, 0x00000240, 0x00000000, /* counter: */ 4 ), /* formalType */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000040, 0x00000000, /* counter: */ 2 ), /* attributedFormalType */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000240, 0x00000000, /* counter: */ 3 ), /* formalParamList */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000240, 0x00000000, /* counter: */ 3 ), /* formalParams */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000040, 0x00000000, /* counter: */ 2 ), /* attribFormalParams */ + + new TokenSet( /* bits: */ 0x58000004, 0x00000242, 0x00000050, /* counter: */ 9 ), /* typeDeclarationTail */ + }; + #endregion + + /* -------------------------------------------------------------------------- + * method Count() -- Returns the number of productions + * ----------------------------------------------------------------------- */ //SAM CHANGE + + static uint Count() { + return (uint)Enum.GetNames(typeof(Production)).Length; + } /* end Count */ + + + /* -------------------------------------------------------------------------- + * method IsOptionDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on any compiler option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsOptionDependent(Production p) { + return p >= firstOptionDependent; + } /* end IsOptionDependent */ + + + /* -------------------------------------------------------------------------- + * method IsConstParamDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on CONST parameter option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsConstParamDependent(Production p) + { + return p >= firstConstParamDependent && p <= lastConstParamDependent; + } /* end IsConstParamDependent */ + + + /* -------------------------------------------------------------------------- + * method IsVariantRecordDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on variant record type option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsVariantRecordDependent(Production p) { + return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; + } + + /* -------------------------------------------------------------------------- + * method FIRST(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FIRST set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FIRST(Production p) { + TokenSet tokenset = null; + uint index = 0; + + if (IsConstParamDependent(p)) + { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) + { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + + tokenset = firstSets[index]; + + return tokenset; + } /* end FIRST */ + + + /* -------------------------------------------------------------------------- + * method FOLLOW(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FOLLOW set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FOLLOW(Production p) { + TokenSet tokenset = null; + uint index = 0; + + if (IsConstParamDependent(p)) { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + + tokenset = followSets[index]; + + return tokenset; + } /* end FOLLOW */ + + + /* -------------------------------------------------------------------------- + * method NameForProduction(p) + * -------------------------------------------------------------------------- + * Returns a string with a human readable name for production p. + * ----------------------------------------------------------------------- */ + + string NameForProduction(Production p); + + + +} /* NonTerminals */ + +} /* namespace */ \ No newline at end of file diff --git a/Terminals.cs b/Terminals.cs new file mode 100644 index 0000000..70e015f --- /dev/null +++ b/Terminals.cs @@ -0,0 +1,530 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * Terminals.cs + * + * Terminal symbols' token and lexeme lookup. + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +namespace org.m2sf.m2sharp { + +public class Terminals : ITerminals { + +const Token FirstResWord = Token.AND; +const Token LastResWord = Token.WITH; + +const Token FirstLiteral = Token.StringLiteral; +const Token LastLiteral = Token.CharLiteral; + +const Token FirstMalformedLiteral = Token.MalformedString; +const Token LastMalformedLiteral = Token.MalformedReal; + +const Token FirstSpecialSymbol = Token.Plus; +const Token LastSpecialSymbol = Token.RightBrace; + + +/* --------------------------------------------------------------------------- + * method IsValid(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a valid token, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsValid (Token token) { + return (token != Token.Unknown) && !IsMalformedLiteral(token); +} /* end IsValid */ + + +/* --------------------------------------------------------------------------- + * method IsResword(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a reserved word, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsResword (Token token) { + return (token >= FirstResWord) && (token <= LastResWord); +} /* end IsResword */ + + +/* --------------------------------------------------------------------------- + * method IsLiteral(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a literal, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsLiteral (Token token) { + return (token >= FirstLiteral) && (token <= LastLiteral); +} /* end IsLiteral */ + + +/* --------------------------------------------------------------------------- + * method IsMalformedLiteral(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a malformed literal, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsMalformedLiteral (Token token) { + return (token >= FirstMalformedLiteral) && (token <= LastMalformedLiteral); +} /* end IsMalformedLiteral */ + + +/* --------------------------------------------------------------------------- + * method IsSpecialSymbol(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a special symbol, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsSpecialSymbol (Token token) { + return (token >= FirstSpecialSymbol) && (token <= LastSpecialSymbol); +} /* end IsSpecialSymbol */ + + +/* --------------------------------------------------------------------------- + * method TokenForResword(lexeme) + * --------------------------------------------------------------------------- + * Tests if the given lexeme represents a reserved word and returns the + * corresponding token or Unknown if it does not match a reserved word. + * ------------------------------------------------------------------------ */ + +public static Token TokenForResword (string lexeme) { + int length; + + /* check pre-conditions */ + if (lexeme == null) { + return Token.Unknown; + } /* end if */ + + length = lexeme.Length; + + if ((length < 2) || (length > 14)) { + return Token.Unknown; + } /* end if */ + + switch (length) { + case /* length = 2 */ 2 : + switch (lexeme[0]) { + + case 'B' : + /* BY */ + if (lexeme[1] == 'Y') { + return Token.BY; + } /* end if */ + break; + + case 'D' : + /* DO */ + if (lexeme[1] == 'O') { + return Token.DO; + } /* end if */ + break; + + case 'I' : + /* IF */ + if (lexeme[1] == 'F') { + return Token.IF; + } + + /* IN */ + else if (lexeme[1] == 'N') { + return Token.IN; + } /* end if */ + break; + + case 'O' : + /* OF */ + if (lexeme[1] == 'F') { + return Token.OF; + } + + /* OR */ + else if (lexeme[1] == 'R') { + return Token.OR; + } /* end if */ + break; + + case 'T' : + /* TO */ + if (lexeme[1] == 'O') { + return Token.TO; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 3 */ 3 : + switch (lexeme[0]) { + + case 'A' : + /* AND */ + if (string.CompareOrdinal(lexeme, "AND") == 0) { + return Token.AND; + } /* end if */ + break; + + case 'D' : + /* DIV */ + if (string.CompareOrdinal(lexeme, "DIV") == 0) { + return Token.DIV; + } /* end if */ + break; + + case 'E' : + /* END */ + if (string.CompareOrdinal(lexeme, "END") == 0) { + return Token.END; + } /* end if */ + break; + + case 'F' : + /* FOR */ + if (string.CompareOrdinal(lexeme, "FOR") == 0) { + return Token.FOR; + } /* end if */ + break; + + case 'M' : + /* MOD */ + if (string.CompareOrdinal(lexeme, "MOD") == 0) { + return Token.MOD; + } /* end if */ + break; + + case 'N' : + /* NOT */ + if (string.CompareOrdinal(lexeme, "NOT") == 0) { + return Token.NOT; + } /* end if */ + break; + + case 'S' : + /* SET */ + if (string.CompareOrdinal(lexeme, "SET") == 0) { + return Token.SET; + } /* end if */ + break; + + case 'V' : + /* VAR */ + if (string.CompareOrdinal(lexeme, "VAR") == 0) { + return Token.VAR; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 4 */ 4 : + switch (lexeme[1]) { + + case 'A' : + /* CASE */ + if (string.CompareOrdinal(lexeme, "CASE") == 0) { + return Token.CASE; + } /* end if */ + break; + + case 'H' : + /* THEN */ + if (string.CompareOrdinal(lexeme, "THEN") == 0) { + return Token.THEN; + } /* end if */ + break; + + case 'I' : + /* WITH */ + if (string.CompareOrdinal(lexeme, "WITH") == 0) { + return Token.WITH; + } /* end if */ + break; + + case 'L' : + /* ELSE */ + if (string.CompareOrdinal(lexeme, "ELSE") == 0) { + return Token.ELSE; + } /* end if */ + break; + + case 'O' : + /* LOOP */ + if (string.CompareOrdinal(lexeme, "LOOP") == 0) { + return Token.LOOP; + } /* end if */ + break; + + case 'R' : + /* FROM */ + if (string.CompareOrdinal(lexeme, "FROM") == 0) { + return Token.FROM; + } /* end if */ + break; + + case 'X' : + /* EXIT */ + if (string.CompareOrdinal(lexeme, "EXIT") == 0) { + return Token.EXIT; + } /* end if */ + break; + + case 'Y' : + /* TYPE */ + if (string.CompareOrdinal(lexeme, "TYPE") == 0) { + return Token.TYPE; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 5 */ 5 : + switch (lexeme[0]) { + + case 'A' : + /* ARRAY */ + if (string.CompareOrdinal(lexeme, "ARRAY") == 0) { + return Token.ARRAY; + } /* end if */ + break; + + case 'B' : + /* BEGIN */ + if (string.CompareOrdinal(lexeme, "BEGIN") == 0) { + return Token.BEGIN; + } /* end if */ + break; + + case 'C' : + /* CONST */ + if (string.CompareOrdinal(lexeme, "CONST") == 0) { + return Token.CONST; + } /* end if */ + break; + + case 'E' : + /* ELSIF */ + if (string.CompareOrdinal(lexeme, "ELSIF") == 0) { + return Token.ELSIF; + } /* end if */ + break; + + case 'U' : + /* UNTIL */ + if (string.CompareOrdinal(lexeme, "UNTIL") == 0) { + return Token.UNTIL; + } /* end if */ + break; + + case 'W' : + /* WHILE */ + if (string.CompareOrdinal(lexeme, "WHILE") == 0) { + return Token.WHILE; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length 6 */ 6 : + switch (lexeme[2]) { + + case 'D' : + /* MODULE */ + if (string.CompareOrdinal(lexeme, "MODULE") == 0) { + return Token.MODULE; + } /* end if */ + break; + + case 'A' : + /* OPAQUE */ + if (string.CompareOrdinal(lexeme, "OPAQUE") == 0) { + return Token.OPAQUE; + } /* end if */ + break; + + case 'C' : + /* RECORD */ + if (string.CompareOrdinal(lexeme, "RECORD") == 0) { + return Token.RECORD; + } /* end if */ + break; + + case 'T' : + /* RETURN */ + if (string.CompareOrdinal(lexeme, "RETURN") == 0) { + return Token.RETURN; + } /* end if */ + break; + + case 'P' : + switch (lexeme[0]) { + + case 'E' : + /* EXPORT */ + if (string.CompareOrdinal(lexeme, "EXPORT") == 0) { + return Token.EXPORT; + } /* end if */ + break; + + case 'I' : + /* IMPORT */ + if (string.CompareOrdinal(lexeme, "IMPORT") == 0) { + return Token.IMPORT; + } /* end if */ + break; + + case 'R' : + /* REPEAT */ + if (string.CompareOrdinal(lexeme, "REPEAT") == 0) { + return Token.REPEAT; + } /* end if */ + break; + + } /* end switch */ + break; + + } /* end switch */ +break; + + case /* length = 7 */ 7 : + switch (lexeme[0]) { + + case 'A' : + /* ARGLIST */ + if (string.CompareOrdinal(lexeme, "ARGLIST") == 0) { + return Token.ARGLIST; + } /* end if */ + break; + + case 'P' : + /* POINTER */ + if (string.CompareOrdinal(lexeme, "POINTER") == 0) { + return Token.POINTER; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 9 */ 9 : + switch (lexeme[0]) { + + case 'P' : + /* PROCEDURE */ + if (string.CompareOrdinal(lexeme, "PROCEDURE") == 0) { + return Token.PROCEDURE; + } /* end if */ + break; + + case 'Q' : + /* QUALIFIED */ + if (string.CompareOrdinal(lexeme, "QUALIFIED") == 0) { + return Token.QUALIFIED; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 10 */ 10 : + /* DEFINITION */ + if (string.CompareOrdinal(lexeme, "DEFINITION") == 0) { + return Token.DEFINITION; + } /* end if */ + break; + + case /* length = 14 */ 14 : + /* IMPLEMENTATION */ + if (string.CompareOrdinal(lexeme, "IMPLEMENTATION") == 0) { + return Token.IMPLEMENTATION; + } /* end if */ + break; + + } /* end switch (length) */ + + return Token.Unknown; +} /* end TokenForResword */ + + +/* --------------------------------------------------------------------------- + * method LexemeForResword(token) + * --------------------------------------------------------------------------- + * Returns a string with the lexeme for the reserved word represented by + * token. Returns null if the token does not represent a reserved word. + * ------------------------------------------------------------------------ */ + +public static string LexemeForResword (Token token) { + if (IsResword(token) == false) { + return null; + } /* end if */ + return token.ToString(); +} /* end LexemeForResword */ + + +/* --------------------------------------------------------------------------- + * method LexemeForSpecialSymbol(token) + * --------------------------------------------------------------------------- + * Returns a string with the lexeme for the special symbol represented by + * token. Returns null if the token does not represent a special symbol. + * ------------------------------------------------------------------------ */ + +public static string LexemeForSpecialSymbol (Token token) { + if (IsSpecialSymbol(token) == false) { + return null; + } /* end if */ + return ""; // TO DO +} /* end LexemeForSpecialSymbol */ + + +/* --------------------------------------------------------------------------- + * method NameForToken(token) + * --------------------------------------------------------------------------- + * Returns a string with a human readable name for token. Returns null if + * token is not a valid token. + * ------------------------------------------------------------------------ */ + +public static string NameForToken (Token token) { + return token.ToString(); +} /* NameForToken */ + + +} /* Terminals */ + +} /* namespace */ + +/* END OF FILE */ \ No newline at end of file diff --git a/TokenSet.cs b/TokenSet.cs new file mode 100644 index 0000000..1d84115 --- /dev/null +++ b/TokenSet.cs @@ -0,0 +1,588 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * TokenSet.cs + * + * A set of Token type variables which is used to pass First and Follow sets + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace org.m2sf.m2sharp +{ + + public class TokenSet : ITokenSet { + + /* Lexeme Table */ + public static string[] lexemeTable = { + /* Null Token */ + + "UNKNOWN", + + /* Reserved Words */ + + "AND", + "ARGLIST", + "ARRAY", + "BEGIN", + "BY", + "CASE", + "CONST", + "DEFINITION", + "DIV", + "DO", + "ELSE", + "ELSIF", + "END", + "EXIT", + "EXPORT", + "FOR", + "FROM", + "IF", + "IMPLEMENTATION", + "IMPORT", + "IN", + "LOOP", + "MOD", + "MODULE", + "NOT", + "OF", + "OR", + "POINTER", + "PROCEDURE", + "QUALIFIED", + "RECORD", + "REPEAT", + "RETURN", + "SET", + "THEN", + "TO", + "TYPE", + "UNTIL", + "VAR", + "WHILE", + "WITH", + + /* Identifiers */ + + "IDENTIFIER", + + /* Literals */ + + "STRING-LITERAL", + "INTEGER-LITERAL", + "REAL-LITERAL", + "CHAR-LITERAL", + + "MALFORMED-STRING", + "MALFORMED-INTEGER", + "MALFORMED-REAL", + + /* Pragmas */ + + "PRAGMA", + + /* Special Symbols */ + + "PLUS", + "MINUS", + "EQUAL", + "NOTEQUAL", + "LESS-THAN", + "LESS-OR-EQUAL", + "GREATER-THAN", + "GREATER-OR-EQUAL", + "ASTERISK", + "SOLIDUS", + "BACKSLASH", + "ASSIGNMENT", + "COMMA", + "PERIOD", + "COLON", + "SEMICOLON", + "RANGE", + "DEREF", + "VERTICAL-BAR", + "LEFT-PAREN", + "RIGHT-PAREN", + "LEFT-BRACKET", + "RIGHT-BRACKET", + "LEFT-BRACE", + "RIGHT-BRACE", + "END-OF-FILE" + +}; /* end m2c_token_name_table */ + + public static const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; + + public struct TokenSetBits + { + public uint[] segments = new uint[segmentCount]; + public uint elemCount; + } /* end struct */ + + TokenSetBits dataStored; + + /* --------------------------------------------------------------------------- + * private constructor TokenSet () + * --------------------------------------------------------------------------- + * Prevents clients from invoking the default constructor. + * ------------------------------------------------------------------------ */ + + private TokenSet() + { + // no operation + } /* end TokenSet */ + + /* --------------------------------------------------------------------------- + * private constructor TokenSet (uint[]) + * --------------------------------------------------------------------------- + * used to instantiate the prefabricated first and follow lists + * ------------------------------------------------------------------------ */ + + public TokenSet(params uint[] TSB) + { + dataStored.segments[0] = TSB[0]; + dataStored.segments[1] = TSB[1]; + dataStored.segments[2] = TSB[2]; + dataStored.elemCount = TSB[3]; + } + + /* -------------------------------------------------------------------------- + * constructor newFromList(token, ...) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object that includes the tokens passed + * as arguments of a variadic argument list. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromList(params Token[] tokenList) + { + TokenSet newSet = new TokenSet(); + uint bit, segmentIndex; + Token token; + + /* allocate new set */ + newSet.dataStored.segments = new uint[segmentCount]; + + /* initialise */ + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + newSet.dataStored.segments[segmentIndex] = 0; + } /* end For */ + + /* store tokens from list */ + token = tokenList[0]; + for (int i = 1; token != Token.Unknown; i++) + { + + if (token <= Token.EndOfFile) + { + segmentIndex = (uint)token / 32; + bit = (uint)token % 32; + newSet.dataStored.segments[segmentIndex] = (newSet.dataStored.segments[segmentIndex] | (uint)(1 << (int)bit)); + } /* end if */ + + /* get next token in list */ + token = tokenList[i]; + } /* end while */ + + /* update element counter */ + newSet.dataStored.elemCount = CountBits(newSet); + + return newSet; + } /* end newFromList */ + + + /* -------------------------------------------------------------------------- + * constructor newFromUnion(set, ...) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object that represents the set union of + * the tokensets passed as arguments of a non-empty variadic argument list. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromUnion(params TokenSet[] setList) + { + uint segmentIndex; + TokenSet set, + newSet = new TokenSet(); + + + /* initialise */ + newSet.dataStored.segments = new uint[segmentCount]; + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + newSet.dataStored.segments[segmentIndex] = 0; + } /* end for */ + + set = setList[0]; + /* calculate union with each set in list */ + for (int i = 0; set != null; i++) + { + /* for each segment ... */ + while (segmentIndex < segmentCount) + { + /* ... store union of corresponding segments */ + newSet.dataStored.segments[segmentIndex] = + newSet.dataStored.segments[segmentIndex] | newSet.dataStored.segments[segmentIndex]; + + /* next segment */ + segmentIndex++; + } /* end while */ + + /*get next set in list */ + if (i < setList.Length) + set = setList[i]; + else + set = null; + + } /* end for */ + + /* update element counter */ + newSet.dataStored.elemCount = CountBits(newSet); + + return newSet; + } /* end newFromUnion + +/* -------------------------------------------------------------------------- + * method Count() + * -------------------------------------------------------------------------- + * Returns the number of elements in the receiver. + * ----------------------------------------------------------------------- */ + + public uint Count() + { + + return this.dataStored.elemCount; + } /* end IsElement */ + + + /* -------------------------------------------------------------------------- + * method IsElement(token) + * -------------------------------------------------------------------------- + * Returns true if token is an element of the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsElement(Token token) + { + int segmentIndex, bit; + + if (token > Token.EndOfFile) + { + return false; + } /* end if */ + + segmentIndex = (int)token / 32; + bit = (int)token % 32; + + return (this.dataStored.segments[segmentIndex] & (1 << bit)) != 0; + } /* end IsElement */ + + + /* -------------------------------------------------------------------------- + * method IsSubset(set) + * -------------------------------------------------------------------------- + * Returns true if each element in set is also in the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsSubset(TokenSet set) + { + + for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + if (((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) + ^ this.dataStored.segments[segmentIndex]) != 0) + { + + return false; + + } /* end if */ + + } /* end for */ + + return true; + + } /* end IsSubset */ + + + /* -------------------------------------------------------------------------- + * method IsDisjunct(set) + * -------------------------------------------------------------------------- + * Returns true if set has no common elements with the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsDisjunct(TokenSet set) + { + + for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + if ((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) != 0) + { + + return false; + + } /* end if */ + + } /* end for */ + + return true; + + } /* end IsDisjunct */ + + /* -------------------------------------------------------------------------- + * method ElementList() + * -------------------------------------------------------------------------- + * Returns a token list of all elements in the receiver. + * ----------------------------------------------------------------------- */ + //TODO + + public List ElementList() + { + List allElements = new List(); + uint segmentIndex, count; + int bit; + Token token; + + if (this.dataStored.elemCount == 0) + { + return null; + } /* end if */ + + token = 0; + count = 0; + + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (int)token % 32; + + if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) + { + count++; + allElements.Add(token); + } /* end if */ + token++; + } /* end while */ + + return allElements; + + } /* end ElementList */ + + + /* -------------------------------------------------------------------------- + * method PrintSet(label) + * -------------------------------------------------------------------------- + * Prints a human readable representation of the receiver. + * Format: label = { comma-separated list of tokens }; + * ----------------------------------------------------------------------- */ + + public void PrintSet(string label) + { + uint segmentIndex, count; + int bit; + Token token; + + Console.Write(label + " = {"); + if (this.dataStored.elemCount == 0) + { + Console.Write(" "); + } /* end if */ + + token = 0; + count = 0; + + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (int)token % 32; + + if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) + { + count++; + + if (count <= this.dataStored.elemCount) + { + + Console.Write("\n {0},", lexemeTable[(uint)token]); + } + else + { + Console.WriteLine("\n {0}", lexemeTable[(uint)token]); + } /* end if */ + } /* end if */ + token++; + } /* end while */ + + Console.WriteLine("};"); + } /* end PrintSet */ + + + /* -------------------------------------------------------------------------- + * method PrintList() + * -------------------------------------------------------------------------- + * Prints a human readable list of tokens in the receiver. + * Format: first, second, third, ..., secondToLast or last + * ----------------------------------------------------------------------- */ + + public void PrintList() + { + uint bit, segmentIndex, count; + Token token; + + if (this.dataStored.elemCount == 0) + { + Console.WriteLine("(nil)"); + } + + count = 0; + token = 0; + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (uint)token % 32; + + if (((this.dataStored.segments[segmentIndex] & (1 << (int)bit)) != 0)) + { + count++; + if (count > 1) + { + if (count <= this.dataStored.elemCount) + { + Console.Write(", "); + } + else + { + Console.Write(" or "); + } /* end if */ + } /* end if */ + + Console.Write(lexemeTable[(uint)token]); + } + token++; + } + + Console.WriteLine("."); + } /* end PrintList */ + + + /* -------------------------------------------------------------------------- + * method PrintLiteralStruct(ident) + * -------------------------------------------------------------------------- + * Prints a struct definition for a tokenset literal for the receiver. + * Format: struct ident { uint s0; uint s1; uint s2; ...; uint n }; + * ----------------------------------------------------------------------- */ + + public void PrintLiteralStruct(string ident) + { + uint segmentIndex; + + Console.Write("struct {0} {{ uint s0", ident); + + for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) + { + Console.Write("; s" + segmentIndex); + } /* end for */ + + Console.WriteLine("; n };"); + Console.WriteLine("typedef struct {0} {0};", ident); + + } /* end PrintLiteralStruct */ + + + /* -------------------------------------------------------------------------- + * method PrintLiteral() + * -------------------------------------------------------------------------- + * Prints a sequence of hex values representing the bit pattern of receiver. + * Format: ( 0xHHHHHHHH, 0xHHHHHHHH, ..., count ); + * ----------------------------------------------------------------------- */ + + public void PrintLiteral() + { + uint segmentIndex; + + Console.Write("( /* bits: */ 0x" + this.dataStored.segments[0].ToString("x08")); + + for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) + { + + Console.Write(", 0x" + this.dataStored.segments[segmentIndex].ToString("x08")); + } /* end for */ + + Console.WriteLine(", /* counter: */ " + this.dataStored.elemCount + " );"); + } /* end PrintLiteral */ + + /* -------------------------------------------------------------------------- + * method CountBits() + * -------------------------------------------------------------------------- + * Returns the number of set bits in set. + * ----------------------------------------------------------------------- */ + + static private uint CountBits(TokenSet set) + { + int bit; + uint segmentIndex, + bitCount = 0; + + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + for (bit = 0; bit < 32; bit++) + { + + if ((set.dataStored.segments[segmentIndex] & (1 << bit)) != 0) + { + bitCount++; + } /* end if */ + + } /* end for */ + + } /* end for */ + + return bitCount; + } /* end CountBits */ + + } /* end TokenSet */ + +} /* end namespace */ From 5e2414512bb0539f83e1d2bc70a705712d0926e6 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Tue, 23 May 2017 12:56:49 -0700 Subject: [PATCH 12/24] Delete Terminals.cs --- imp/Terminals.cs | 523 ----------------------------------------------- 1 file changed, 523 deletions(-) delete mode 100644 imp/Terminals.cs diff --git a/imp/Terminals.cs b/imp/Terminals.cs deleted file mode 100644 index 01b6456..0000000 --- a/imp/Terminals.cs +++ /dev/null @@ -1,523 +0,0 @@ -/* M2Sharp -- Modula-2 to C# Translator & Compiler - * - * Copyright (c) 2016 The Modula-2 Software Foundation - * - * Author & Maintainer: Benjamin Kowarsch - * - * @synopsis - * - * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. - * It supports the dialects described in the 3rd and 4th editions of Niklaus - * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, - * and an extended mode with select features from the revised language by - * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). - * - * In translator mode, M2Sharp translates Modula-2 source to C# source files. - * In compiler mode, M2Sharp compiles Modula-2 source via C# source files - * to object code or executables using the host system's C# compiler. - * - * @repository - * - * https://github.com/m2sf/m2sharp - * - * @file - * - * Terminals.cs - * - * Terminal symbols' token and lexeme lookup. - * - * @license - * - * M2Sharp is free software: you can redistribute and/or modify it under the - * terms of the GNU Lesser General Public License (LGPL) either version 2.1 - * or at your choice version 3 as published by the Free Software Foundation. - * However, you may not alter the copyright, author and license information. - * - * M2Sharp is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with M2Sharp. If not, see . - * - * NB: Components in the domain part of email addresses are in reverse order. - */ - -namespace org.m2sf.m2sharp { - -public class Terminals : ITerminals { - -const Token FirstResWord = Token.AND; -const Token LastResWord = Token.WITH; - -const Token FirstLiteral = Token.StringLiteral; -const Token LastLiteral = Token.CharLiteral; - -const Token FirstMalformedLiteral = Token.MalformedString; -const Token LastMalformedLiteral = Token.MalformedReal; - -const Token FirstSpecialSymbol = Token.Plus; -const Token LastSpecialSymbol = Token.RightBrace; - - -/* --------------------------------------------------------------------------- - * method IsValid(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a valid token, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsValid (Token token) { - return (token != Token.Unknown) && !IsMalformedLiteral(token); -} /* end IsValid */ - - -/* --------------------------------------------------------------------------- - * method IsResword(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a reserved word, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsResword (Token token) { - return (token >= FirstResWord) && (token <= LastResWord); -} /* end IsResword */ - - -/* --------------------------------------------------------------------------- - * method IsLiteral(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a literal, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsLiteral (Token token) { - return (token >= FirstLiteral) && (token <= LastLiteral); -} /* end IsLiteral */ - - -/* --------------------------------------------------------------------------- - * method IsMalformedLiteral(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a malformed literal, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsMalformedLiteral (Token token) { - return (token >= FirstMalformedLiteral) && (token <= LastMalformedLiteral); -} /* end IsMalformedLiteral */ - - -/* --------------------------------------------------------------------------- - * method IsSpecialSymbol(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a special symbol, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsSpecialSymbol (Token token) { - return (token >= FirstSpecialSymbol) && (token <= LastSpecialSymbol); -} /* end IsSpecialSymbol */ - - -/* --------------------------------------------------------------------------- - * method TokenForResword(lexeme) - * --------------------------------------------------------------------------- - * Tests if the given lexeme represents a reserved word and returns the - * corresponding token or Unknown if it does not match a reserved word. - * ------------------------------------------------------------------------ */ - -public static Token TokenForResword (string lexeme) { - int length; - - /* check pre-conditions */ - if (lexeme == null) { - return Token.Unknown; - } /* end if */ - - length = lexeme.Length; - - if ((length < 2) || (length > 14)) { - return Token.Unknown; - } /* end if */ - - switch (length) { - case /* length = 2 */ 2 : - switch (lexeme[0]) { - - case 'B' : - /* BY */ - if (lexeme[1] == 'Y') { - return Token.BY; - } /* end if */ - break; - - case 'D' : - /* DO */ - if (lexeme[1] == 'O') { - return Token.DO; - } /* end if */ - break; - - case 'I' : - /* IF */ - if (lexeme[1] == 'F') { - return Token.IF; - } - - /* IN */ - else if (lexeme[1] == 'N') { - return Token.IN; - } /* end if */ - break; - - case 'O' : - /* OF */ - if (lexeme[1] == 'F') { - return Token.OF; - } - - /* OR */ - else if (lexeme[1] == 'R') { - return Token.OR; - } /* end if */ - break; - - case 'T' : - /* TO */ - if (lexeme[1] == 'O') { - return Token.TO; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 3 */ 3 : - switch (lexeme[0]) { - - case 'A' : - /* AND */ - if (string.CompareOrdinal(lexeme, "AND") == 0) { - return Token.AND; - } /* end if */ - break; - - case 'D' : - /* DIV */ - if (string.CompareOrdinal(lexeme, "DIV") == 0) { - return Token.DIV; - } /* end if */ - break; - - case 'E' : - /* END */ - if (string.CompareOrdinal(lexeme, "END") == 0) { - return Token.END; - } /* end if */ - break; - - case 'F' : - /* FOR */ - if (string.CompareOrdinal(lexeme, "FOR") == 0) { - return Token.FOR; - } /* end if */ - break; - - case 'M' : - /* MOD */ - if (string.CompareOrdinal(lexeme, "MOD") == 0) { - return Token.MOD; - } /* end if */ - break; - - case 'N' : - /* NOT */ - if (string.CompareOrdinal(lexeme, "NOT") == 0) { - return Token.NOT; - } /* end if */ - break; - - case 'S' : - /* SET */ - if (string.CompareOrdinal(lexeme, "SET") == 0) { - return Token.SET; - } /* end if */ - break; - - case 'V' : - /* VAR */ - if (string.CompareOrdinal(lexeme, "VAR") == 0) { - return Token.VAR; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 4 */ 4 : - switch (lexeme[1]) { - - case 'A' : - /* CASE */ - if (string.CompareOrdinal(lexeme, "CASE") == 0) { - return Token.CASE; - } /* end if */ - break; - - case 'H' : - /* THEN */ - if (string.CompareOrdinal(lexeme, "THEN") == 0) { - return Token.THEN; - } /* end if */ - break; - - case 'I' : - /* WITH */ - if (string.CompareOrdinal(lexeme, "WITH") == 0) { - return Token.WITH; - } /* end if */ - break; - - case 'L' : - /* ELSE */ - if (string.CompareOrdinal(lexeme, "ELSE") == 0) { - return Token.ELSE; - } /* end if */ - break; - - case 'O' : - /* LOOP */ - if (string.CompareOrdinal(lexeme, "LOOP") == 0) { - return Token.LOOP; - } /* end if */ - break; - - case 'R' : - /* FROM */ - if (string.CompareOrdinal(lexeme, "FROM") == 0) { - return Token.FROM; - } /* end if */ - break; - - case 'X' : - /* EXIT */ - if (string.CompareOrdinal(lexeme, "EXIT") == 0) { - return Token.EXIT; - } /* end if */ - break; - - case 'Y' : - /* TYPE */ - if (string.CompareOrdinal(lexeme, "TYPE") == 0) { - return Token.TYPE; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 5 */ 5 : - switch (lexeme[0]) { - - case 'A' : - /* ARRAY */ - if (string.CompareOrdinal(lexeme, "ARRAY") == 0) { - return Token.ARRAY; - } /* end if */ - break; - - case 'B' : - /* BEGIN */ - if (string.CompareOrdinal(lexeme, "BEGIN") == 0) { - return Token.BEGIN; - } /* end if */ - break; - - case 'C' : - /* CONST */ - if (string.CompareOrdinal(lexeme, "CONST") == 0) { - return Token.CONST; - } /* end if */ - break; - - case 'E' : - /* ELSIF */ - if (string.CompareOrdinal(lexeme, "ELSIF") == 0) { - return Token.ELSIF; - } /* end if */ - break; - - case 'U' : - /* UNTIL */ - if (string.CompareOrdinal(lexeme, "UNTIL") == 0) { - return Token.UNTIL; - } /* end if */ - break; - - case 'W' : - /* WHILE */ - if (string.CompareOrdinal(lexeme, "WHILE") == 0) { - return Token.WHILE; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length 6 */ 6 : - switch (lexeme[5]) { - - case 'E' : - /* MODULE */ - if (string.CompareOrdinal(lexeme, "MODULE") == 0) { - return Token.MODULE; - } /* end if */ - break; - - case 'D' : - /* RECORD */ - if (string.CompareOrdinal(lexeme, "RECORD") == 0) { - return Token.RECORD; - } /* end if */ - break; - - case 'N' : - /* RETURN */ - if (string.CompareOrdinal(lexeme, "RETURN") == 0) { - return Token.RETURN; - } /* end if */ - break; - - case 'T' : - switch (lexeme[0]) { - - case 'E' : - /* EXPORT */ - if (string.CompareOrdinal(lexeme, "EXPORT") == 0) { - return Token.EXPORT; - } /* end if */ - break; - - case 'I' : - /* IMPORT */ - if (string.CompareOrdinal(lexeme, "IMPORT") == 0) { - return Token.IMPORT; - } /* end if */ - break; - - case 'R' : - /* REPEAT */ - if (string.CompareOrdinal(lexeme, "REPEAT") == 0) { - return Token.REPEAT; - } /* end if */ - break; - - } /* end switch */ - break; - - } /* end switch */ - break; - - case /* length = 7 */ 7 : - switch (lexeme[0]) { - - case 'A' : - /* ARGLIST */ - if (string.CompareOrdinal(lexeme, "ARGLIST") == 0) { - return Token.ARGLIST; - } /* end if */ - break; - - case 'P' : - /* POINTER */ - if (string.CompareOrdinal(lexeme, "POINTER") == 0) { - return Token.POINTER; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 9 */ 9 : - switch (lexeme[0]) { - - case 'P' : - /* PROCEDURE */ - if (string.CompareOrdinal(lexeme, "PROCEDURE") == 0) { - return Token.PROCEDURE; - } /* end if */ - break; - - case 'Q' : - /* QUALIFIED */ - if (string.CompareOrdinal(lexeme, "QUALIFIED") == 0) { - return Token.QUALIFIED; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 10 */ 10 : - /* DEFINITION */ - if (string.CompareOrdinal(lexeme, "DEFINITION") == 0) { - return Token.DEFINITION; - } /* end if */ - break; - - case /* length = 14 */ 14 : - /* IMPLEMENTATION */ - if (string.CompareOrdinal(lexeme, "IMPLEMENTATION") == 0) { - return Token.IMPLEMENTATION; - } /* end if */ - break; - - } /* end switch (length) */ - - return Token.Unknown; -} /* end TokenForResword */ - - -/* --------------------------------------------------------------------------- - * method LexemeForResword(token) - * --------------------------------------------------------------------------- - * Returns a string with the lexeme for the reserved word represented by - * token. Returns null if the token does not represent a reserved word. - * ------------------------------------------------------------------------ */ - -public static string LexemeForResword (Token token) { - if (IsResword(token) == false) { - return null; - } /* end if */ - return token.ToString(); -} /* end LexemeForResword */ - - -/* --------------------------------------------------------------------------- - * method LexemeForSpecialSymbol(token) - * --------------------------------------------------------------------------- - * Returns a string with the lexeme for the special symbol represented by - * token. Returns null if the token does not represent a special symbol. - * ------------------------------------------------------------------------ */ - -public static string LexemeForSpecialSymbol (Token token) { - if (IsSpecialSymbol(token) == false) { - return null; - } /* end if */ - return ""; // TO DO -} /* end LexemeForSpecialSymbol */ - - -/* --------------------------------------------------------------------------- - * method NameForToken(token) - * --------------------------------------------------------------------------- - * Returns a string with a human readable name for token. Returns null if - * token is not a valid token. - * ------------------------------------------------------------------------ */ - -public static string NameForToken (Token token) { - return token.ToString(); -} /* NameForToken */ - - -} /* Terminals */ - -} /* namespace */ - -/* END OF FILE */ \ No newline at end of file From 64989634f2b6329940d3ae99d8d9723a74de239b Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Tue, 23 May 2017 12:57:02 -0700 Subject: [PATCH 13/24] Delete TokenSet.cs --- imp/TokenSet.cs | 574 ------------------------------------------------ 1 file changed, 574 deletions(-) delete mode 100644 imp/TokenSet.cs diff --git a/imp/TokenSet.cs b/imp/TokenSet.cs deleted file mode 100644 index 7490eb1..0000000 --- a/imp/TokenSet.cs +++ /dev/null @@ -1,574 +0,0 @@ -/* M2Sharp -- Modula-2 to C# Translator & Compiler - * - * Copyright (c) 2016 The Modula-2 Software Foundation - * - * Author & Maintainer: Benjamin Kowarsch - * - * @synopsis - * - * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. - * It supports the dialects described in the 3rd and 4th editions of Niklaus - * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, - * and an extended mode with select features from the revised language by - * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). - * - * In translator mode, M2Sharp translates Modula-2 source to C# source files. - * In compiler mode, M2Sharp compiles Modula-2 source via C# source files - * to object code or executables using the host system's C# compiler. - * - * @repository - * - * https://github.com/m2sf/m2sharp - * - * @file - * - * TokenSet.cs - * - * A set of Token type variables which is used to pass First and Follow sets - * - * @license - * - * M2Sharp is free software: you can redistribute and/or modify it under the - * terms of the GNU Lesser General Public License (LGPL) either version 2.1 - * or at your choice version 3 as published by the Free Software Foundation. - * However, you may not alter the copyright, author and license information. - * - * M2Sharp is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with M2Sharp. If not, see . - * - * NB: Components in the domain part of email addresses are in reverse order. - */ - - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace org.m2sf.m2sharp -{ - - public class TokenSet : ITokenSet { - - /* Lexeme Table */ - public static string[] lexemeTable = { - /* Null Token */ - - "UNKNOWN", - - /* Reserved Words */ - - "AND", - "ARGLIST", - "ARRAY", - "BEGIN", - "BY", - "CASE", - "CONST", - "DEFINITION", - "DIV", - "DO", - "ELSE", - "ELSIF", - "END", - "EXIT", - "EXPORT", - "FOR", - "FROM", - "IF", - "IMPLEMENTATION", - "IMPORT", - "IN", - "LOOP", - "MOD", - "MODULE", - "NOT", - "OF", - "OR", - "POINTER", - "PROCEDURE", - "QUALIFIED", - "RECORD", - "REPEAT", - "RETURN", - "SET", - "THEN", - "TO", - "TYPE", - "UNTIL", - "VAR", - "WHILE", - "WITH", - - /* Identifiers */ - - "IDENTIFIER", - - /* Literals */ - - "STRING-LITERAL", - "INTEGER-LITERAL", - "REAL-LITERAL", - "CHAR-LITERAL", - - "MALFORMED-STRING", - "MALFORMED-INTEGER", - "MALFORMED-REAL", - - /* Pragmas */ - - "PRAGMA", - - /* Special Symbols */ - - "PLUS", - "MINUS", - "EQUAL", - "NOTEQUAL", - "LESS-THAN", - "LESS-OR-EQUAL", - "GREATER-THAN", - "GREATER-OR-EQUAL", - "ASTERISK", - "SOLIDUS", - "BACKSLASH", - "ASSIGNMENT", - "COMMA", - "PERIOD", - "COLON", - "SEMICOLON", - "RANGE", - "DEREF", - "VERTICAL-BAR", - "LEFT-PAREN", - "RIGHT-PAREN", - "LEFT-BRACKET", - "RIGHT-BRACKET", - "LEFT-BRACE", - "RIGHT-BRACE", - "END-OF-FILE" - -}; /* end m2c_token_name_table */ - - public static const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; - - public struct TokenSetBits - { - public uint[] segments = new uint[segmentCount]; - public uint elemCount; - } /* end struct */ - - TokenSetBits dataStored; - - /* --------------------------------------------------------------------------- - * private constructor TokenSet () - * --------------------------------------------------------------------------- - * Prevents clients from invoking the default constructor. - * ------------------------------------------------------------------------ */ - - private TokenSet() - { - // no operation - } /* end TokenSet */ - - /* -------------------------------------------------------------------------- - * constructor newFromList(token, ...) - * -------------------------------------------------------------------------- - * Returns a newly allocated tokenset object that includes the tokens passed - * as arguments of a variadic argument list. - * ----------------------------------------------------------------------- */ - - public static TokenSet newFromList(params Token[] tokenList) - { - TokenSet newSet = new TokenSet(); - uint bit, segmentIndex; - Token token; - - /* allocate new set */ - newSet.dataStored.segments = new uint[segmentCount]; - - /* initialise */ - for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - newSet.dataStored.segments[segmentIndex] = 0; - } /* end For */ - - /* store tokens from list */ - token = tokenList[0]; - for (int i = 1; token != Token.Unknown; i++) - { - - if (token <= Token.EndOfFile) - { - segmentIndex = (uint)token / 32; - bit = (uint)token % 32; - newSet.dataStored.segments[segmentIndex] = (newSet.dataStored.segments[segmentIndex] | (uint)(1 << (int)bit)); - } /* end if */ - - /* get next token in list */ - token = tokenList[i]; - } /* end while */ - - /* update element counter */ - newSet.dataStored.elemCount = CountBits(newSet); - - return newSet; - } /* end newFromList */ - - - /* -------------------------------------------------------------------------- - * constructor newFromUnion(set, ...) - * -------------------------------------------------------------------------- - * Returns a newly allocated tokenset object that represents the set union of - * the tokensets passed as arguments of a non-empty variadic argument list. - * ----------------------------------------------------------------------- */ - - public static TokenSet newFromUnion(params TokenSet[] setList) - { - uint segmentIndex; - TokenSet set, - newSet = new TokenSet(); - - - /* initialise */ - newSet.dataStored.segments = new uint[segmentCount]; - for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - newSet.dataStored.segments[segmentIndex] = 0; - } /* end for */ - - set = setList[0]; - /* calculate union with each set in list */ - for (int i = 0; set != null; i++) - { - /* for each segment ... */ - while (segmentIndex < segmentCount) - { - /* ... store union of corresponding segments */ - newSet.dataStored.segments[segmentIndex] = - newSet.dataStored.segments[segmentIndex] | newSet.dataStored.segments[segmentIndex]; - - /* next segment */ - segmentIndex++; - } /* end while */ - - /*get next set in list */ - if (i < setList.Length) - set = setList[i]; - else - set = null; - - } /* end for */ - - /* update element counter */ - newSet.dataStored.elemCount = CountBits(newSet); - - return newSet; - } /* end newFromUnion - -/* -------------------------------------------------------------------------- - * method Count() - * -------------------------------------------------------------------------- - * Returns the number of elements in the receiver. - * ----------------------------------------------------------------------- */ - - public uint Count() - { - - return this.dataStored.elemCount; - } /* end IsElement */ - - - /* -------------------------------------------------------------------------- - * method IsElement(token) - * -------------------------------------------------------------------------- - * Returns true if token is an element of the receiver, else false. - * ----------------------------------------------------------------------- */ - - public bool IsElement(Token token) - { - int segmentIndex, bit; - - if (token > Token.EndOfFile) - { - return false; - } /* end if */ - - segmentIndex = (int)token / 32; - bit = (int)token % 32; - - return (this.dataStored.segments[segmentIndex] & (1 << bit)) != 0; - } /* end IsElement */ - - - /* -------------------------------------------------------------------------- - * method IsSubset(set) - * -------------------------------------------------------------------------- - * Returns true if each element in set is also in the receiver, else false. - * ----------------------------------------------------------------------- */ - - public bool IsSubset(TokenSet set) - { - - for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - - if (((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) - ^ this.dataStored.segments[segmentIndex]) != 0) - { - - return false; - - } /* end if */ - - } /* end for */ - - return true; - - } /* end IsSubset */ - - - /* -------------------------------------------------------------------------- - * method IsDisjunct(set) - * -------------------------------------------------------------------------- - * Returns true if set has no common elements with the receiver, else false. - * ----------------------------------------------------------------------- */ - - public bool IsDisjunct(TokenSet set) - { - - for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - - if ((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) != 0) - { - - return false; - - } /* end if */ - - } /* end for */ - - return true; - - } /* end IsDisjunct */ - - /* -------------------------------------------------------------------------- - * method ElementList() - * -------------------------------------------------------------------------- - * Returns a token list of all elements in the receiver. - * ----------------------------------------------------------------------- */ - //TODO - - public List ElementList() - { - List allElements = new List(); - uint segmentIndex, count; - int bit; - Token token; - - if (this.dataStored.elemCount == 0) - { - return null; - } /* end if */ - - token = 0; - count = 0; - - while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) - { - segmentIndex = (uint)token / 32; - bit = (int)token % 32; - - if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) - { - count++; - allElements.Add(token); - } /* end if */ - token++; - } /* end while */ - - return allElements; - - } /* end ElementList */ - - - /* -------------------------------------------------------------------------- - * method PrintSet(label) - * -------------------------------------------------------------------------- - * Prints a human readable representation of the receiver. - * Format: label = { comma-separated list of tokens }; - * ----------------------------------------------------------------------- */ - - public void PrintSet(string label) - { - uint segmentIndex, count; - int bit; - Token token; - - Console.Write(label + " = {"); - if (this.dataStored.elemCount == 0) - { - Console.Write(" "); - } /* end if */ - - token = 0; - count = 0; - - while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) - { - segmentIndex = (uint)token / 32; - bit = (int)token % 32; - - if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) - { - count++; - - if (count <= this.dataStored.elemCount) - { - - Console.Write("\n {0},", lexemeTable[(uint)token]); - } - else - { - Console.WriteLine("\n {0}", lexemeTable[(uint)token]); - } /* end if */ - } /* end if */ - token++; - } /* end while */ - - Console.WriteLine("};"); - } /* end PrintSet */ - - - /* -------------------------------------------------------------------------- - * method PrintList() - * -------------------------------------------------------------------------- - * Prints a human readable list of tokens in the receiver. - * Format: first, second, third, ..., secondToLast or last - * ----------------------------------------------------------------------- */ - - public void PrintList() - { - uint bit, segmentIndex, count; - Token token; - - if (this.dataStored.elemCount == 0) - { - Console.WriteLine("(nil)"); - } - - count = 0; - token = 0; - while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) - { - segmentIndex = (uint)token / 32; - bit = (uint)token % 32; - - if (((this.dataStored.segments[segmentIndex] & (1 << (int)bit)) != 0)) - { - count++; - if (count > 1) - { - if (count <= this.dataStored.elemCount) - { - Console.Write(", "); - } - else - { - Console.Write(" or "); - } /* end if */ - } /* end if */ - - Console.Write(lexemeTable[(uint)token]); - } - token++; - } - - Console.WriteLine("."); - } /* end PrintList */ - - - /* -------------------------------------------------------------------------- - * method PrintLiteralStruct(ident) - * -------------------------------------------------------------------------- - * Prints a struct definition for a tokenset literal for the receiver. - * Format: struct ident { uint s0; uint s1; uint s2; ...; uint n }; - * ----------------------------------------------------------------------- */ - - public void PrintLiteralStruct(string ident) - { - uint segmentIndex; - - Console.Write("struct {0} {{ uint s0", ident); - - for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) - { - Console.Write("; s" + segmentIndex); - } /* end for */ - - Console.WriteLine("; n };"); - Console.WriteLine("typedef struct {0} {0};", ident); - - } /* end PrintLiteralStruct */ - - - /* -------------------------------------------------------------------------- - * method PrintLiteral() - * -------------------------------------------------------------------------- - * Prints a sequence of hex values representing the bit pattern of receiver. - * Format: ( 0xHHHHHHHH, 0xHHHHHHHH, ..., count ); - * ----------------------------------------------------------------------- */ - - public void PrintLiteral() - { - uint segmentIndex; - - Console.Write("( /* bits: */ 0x" + this.dataStored.segments[0].ToString("x08")); - - for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) - { - - Console.Write(", 0x" + this.dataStored.segments[segmentIndex].ToString("x08")); - } /* end for */ - - Console.WriteLine(", /* counter: */ " + this.dataStored.elemCount + " );"); - } /* end PrintLiteral */ - - /* -------------------------------------------------------------------------- - * method CountBits() - * -------------------------------------------------------------------------- - * Returns the number of set bits in set. - * ----------------------------------------------------------------------- */ - - static private uint CountBits(TokenSet set) - { - int bit; - uint segmentIndex, - bitCount = 0; - - for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - - for (bit = 0; bit < 32; bit++) - { - - if ((set.dataStored.segments[segmentIndex] & (1 << bit)) != 0) - { - bitCount++; - } /* end if */ - - } /* end for */ - - } /* end for */ - - return bitCount; - } /* end CountBits */ - - } /* end TokenSet */ - -} /* end namespace */ From 8c2983c39ff26ce1ae3268b48dd92d9af8262c64 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Tue, 23 May 2017 12:57:13 -0700 Subject: [PATCH 14/24] Delete NonTerminals.cs --- imp/NonTerminals.cs | 167 -------------------------------------------- 1 file changed, 167 deletions(-) delete mode 100644 imp/NonTerminals.cs diff --git a/imp/NonTerminals.cs b/imp/NonTerminals.cs deleted file mode 100644 index 24f827a..0000000 --- a/imp/NonTerminals.cs +++ /dev/null @@ -1,167 +0,0 @@ -/* M2Sharp -- Modula-2 to C# Translator & Compiler - * - * Copyright (c) 2016 The Modula-2 Software Foundation - * - * Author & Maintainer: Benjamin Kowarsch - * - * @synopsis - * - * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. - * It supports the dialects described in the 3rd and 4th editions of Niklaus - * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, - * and an extended mode with select features from the revised language by - * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). - * - * In translator mode, M2Sharp translates Modula-2 source to C# source files. - * In compiler mode, M2Sharp compiles Modula-2 source via C# source files - * to object code or executables using the host system's C# compiler. - * - * @repository - * - * https://github.com/m2sf/m2sharp - * - * @file - * - * NonTerminals.cs - * - * provides FIRST() and FOLLOW() sets for each non-terminal symbol //SAM CHANGE - * used by the parser class for syntax analysis - * - * @license - * - * M2Sharp is free software: you can redistribute and/or modify it under the - * terms of the GNU Lesser General Public License (LGPL) either version 2.1 - * or at your choice version 3 as published by the Free Software Foundation. - * However, you may not alter the copyright, author and license information. - * - * M2Sharp is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with M2Sharp. If not, see . - * - * NB: Components in the domain part of email addresses are in reverse order. - */ - -namespace org.m2sf.m2sharp { - - using System; - using System.Collections.Generic; - -public class NonTerminals : INonTerminals { - - public static Production firstConstParamDependent = Production.FormalType, - lastConstParamDependent = Production.AttribFormalParams, - firstNoVariantRecDependent = Production.TypeDeclarationTail, - lastNoVariantRecDependent = Production.TypeDeclarationTail, - firstOptionDependent = firstConstParamDependent, - lastOptionDependent = lastNoVariantRecDependent; - public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; - - TokenSet[] followSet = new TokenSet[Count()]; - TokenSet[] firstSet = new TokenSet[Count()]; - - /* -------------------------------------------------------------------------- - * method Count() -- Returns the number of productions - * ----------------------------------------------------------------------- */ //SAM CHANGE - - static uint Count() { - return (uint)Enum.GetNames(typeof(Production)).Length; - } /* end Count */ - - - /* -------------------------------------------------------------------------- - * method IsOptionDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on any compiler option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE - - bool IsOptionDependent(Production p) { - return p >= firstOptionDependent; - } /* end IsOptionDependent */ - - - /* -------------------------------------------------------------------------- - * method IsConstParamDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on CONST parameter option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE - - bool IsConstParamDependent(Production p) - { - return p >= firstConstParamDependent && p <= lastConstParamDependent; - } /* end IsConstParamDependent */ - - - /* -------------------------------------------------------------------------- - * method IsVariantRecordDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on variant record type option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE - - bool IsVariantRecordDependent(Production p) { - return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; - } - - /* -------------------------------------------------------------------------- - * method FIRST(p) - * -------------------------------------------------------------------------- - * Returns a tokenset with the FIRST set of production p. - * ----------------------------------------------------------------------- */ - - TokenSet FIRST(Production p) { - TokenSet tokenset = null; - uint index = 0; - - if (IsConstParamDependent(p)) - { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) - { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - - tokenset = firstSet[index]; - - return tokenset; - } /* end FIRST */ - - - /* -------------------------------------------------------------------------- - * method FOLLOW(p) - * -------------------------------------------------------------------------- - * Returns a tokenset with the FOLLOW set of production p. - * ----------------------------------------------------------------------- */ - - TokenSet FOLLOW(Production p) { - TokenSet tokenset = null; - uint index = 0; - - if (IsConstParamDependent(p)) { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - - tokenset = followSet[index]; - - return tokenset; - } /* end FOLLOW */ - - - /* -------------------------------------------------------------------------- - * method NameForProduction(p) - * -------------------------------------------------------------------------- - * Returns a string with a human readable name for production p. - * ----------------------------------------------------------------------- */ - - string NameForProduction(Production p); - - - -} /* NonTerminals */ - -} /* namespace */ \ No newline at end of file From 95b4e53743979c983e2ebafa79e2fc3f09d8b7ac Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Tue, 23 May 2017 14:02:52 -0700 Subject: [PATCH 15/24] Add files via upload --- imp/NonTerminals.cs | 461 ++++++++++++++++++++++++++++++++++ imp/Terminals.cs | 530 +++++++++++++++++++++++++++++++++++++++ imp/TokenSet.cs | 588 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1579 insertions(+) create mode 100644 imp/NonTerminals.cs create mode 100644 imp/Terminals.cs create mode 100644 imp/TokenSet.cs diff --git a/imp/NonTerminals.cs b/imp/NonTerminals.cs new file mode 100644 index 0000000..3620d28 --- /dev/null +++ b/imp/NonTerminals.cs @@ -0,0 +1,461 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * NonTerminals.cs + * + * provides FIRST() and FOLLOW() sets for each non-terminal symbol //SAM CHANGE + * used by the parser class for syntax analysis + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +namespace org.m2sf.m2sharp { + + using System; + using System.Collections.Generic; + +public class NonTerminals : INonTerminals { + + public static Production firstConstParamDependent = Production.FormalType, + lastConstParamDependent = Production.AttribFormalParams, + firstNoVariantRecDependent = Production.TypeDeclarationTail, + lastNoVariantRecDependent = Production.TypeDeclarationTail, + firstOptionDependent = firstConstParamDependent, + lastOptionDependent = lastNoVariantRecDependent; + public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; + + #region followSets + TokenSet[] followSets = { + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* definitionModule */ + + new TokenSet( /* bits: */ 0x108050C8, 0x00000050, 0x00000000, /* counter: */ 9 ), /* import */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* qualifiedImport */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* unqualifiedImport */ + + new TokenSet( /* bits: */ 0x00000000, 0x80000000, 0x00000021, /* counter: */ 3 ), /* identList */ + + new TokenSet( /* bits: */ 0x00001000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* constDefinition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDefinition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* type */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* derivedOrSubrangeType */ + + new TokenSet( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000037B, /* counter: */ 34 ), /* qualident */ + + new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* range */ + + new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* enumType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* setType */ + + new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* countableType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* arrayType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* extensibleRecordType */ + + new TokenSet( /* bits: */ 0x00001000, 0x00000040, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variantRecordType */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variantFieldListSeq */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFieldList */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFields */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variant */ + + new TokenSet( /* bits: */ 0x00000000, 0x80000000, 0x00000000, /* counter: */ 1 ), /* caseLabelList */ + + new TokenSet( /* bits: */ 0x00000000, 0xA0000000, 0x00000000, /* counter: */ 2 ), /* caseLabels */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* pointerType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureType */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* simpleFormalType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureHeader */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureSignature */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* simpleFormalParams */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* implementationModule */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* programModule */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* modulePriority */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* block */ + + new TokenSet( /* bits: */ 0x00001008, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* varSizeRecordType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variableDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* moduleDeclaration */ + + new TokenSet( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* export */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000008, /* counter: */ 5 ), /* statementSequence */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* statement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* assignmentOrProcCall */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* actualParameters */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* expressionList */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* returnStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* withStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* ifStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* caseStatement */ + + new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* case */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* loopStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* whileStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* repeatStatement */ + + new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* forStatement */ + + new TokenSet( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000033B, /* counter: */ 33 ), /* designator */ + + new TokenSet( /* bits: */ 0x06501F12, 0x3FFC022C, 0x0000033B, /* counter: */ 34 ), /* selector */ + + new TokenSet( /* bits: */ 0x02001E10, 0x2000002C, 0x0000022B, /* counter: */ 15 ), /* expression */ + + new TokenSet( /* bits: */ 0x02101E10, 0x23F0002C, 0x0000022B, /* counter: */ 22 ), /* simpleExpression */ + + new TokenSet( /* bits: */ 0x06101E10, 0x23FC002C, 0x0000022B, /* counter: */ 25 ), /* term */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* simpleTerm */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* factor */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* designatorOrFuncCall */ + + new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* setValue */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000200, /* counter: */ 2 ), /* element */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* formalType */ + + new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* attributedFormalType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* formalParamList */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* formalParams */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* attribFormalParams */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclarationTail */ + }; + + #endregion + + #region firstSets + TokenSet[] firstSets = { + new TokenSet( /* bits: */ 0x00000080, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ + + new TokenSet( /* bits: */ 0x00090000, 0x00000000, 0x00000000, /* counter: */ 2 ), /* import */ + + new TokenSet( /* bits: */ 0x00080000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* qualifiedImport */ + + new TokenSet( /* bits: */ 0x00010000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* unqualifiedImport */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* identList */ + + new TokenSet( /* bits: */ 0x10000040, 0x00000050, 0x00000000, /* counter: */ 4 ), /* definition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* constDefinition */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* typeDefinition */ + + new TokenSet( /* bits: */ 0x58000004, 0x00000202, 0x00000050, /* counter: */ 8 ), /* type */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000040, /* counter: */ 2 ), /* derivedOrSubrangeType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* qualident */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* range */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000010, /* counter: */ 1 ), /* enumType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000002, 0x00000000, /* counter: */ 1 ), /* setType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000050, /* counter: */ 3 ), /* countableType */ + + new TokenSet( /* bits: */ 0x00000004, 0x00000000, 0x00000000, /* counter: */ 1 ), /* arrayType */ + + new TokenSet( /* bits: */ 0x40000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* extensibleRecordType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* fieldListSequence */ + + new TokenSet( /* bits: */ 0x40000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantRecordType */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000200, 0x00000000, /* counter: */ 2 ), /* variantFieldListSeq */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000200, 0x00000000, /* counter: */ 2 ), /* variantFieldList */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantFields */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* variant */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* caseLabelList */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* caseLabels */ + + new TokenSet( /* bits: */ 0x08000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* pointerType */ + + new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureType */ + + new TokenSet( /* bits: */ 0x00000004, 0x00000200, 0x00000000, /* counter: */ 2 ), /* simpleFormalType */ + + new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureHeader */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* procedureSignature */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* simpleFormalParams */ + + new TokenSet( /* bits: */ 0x00040000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* implementationModule */ + + new TokenSet( /* bits: */ 0x00800000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* programModule */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* modulePriority */ + + new TokenSet( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* block */ + + new TokenSet( /* bits: */ 0x10800040, 0x00000050, 0x00000000, /* counter: */ 5 ), /* declaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* typeDeclaration */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000040, 0x00000000, /* counter: */ 1 ), /* varSizeRecordType */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* variableDeclaration */ + + new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureDeclaration */ + + new TokenSet( /* bits: */ 0x00800000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* moduleDeclaration */ + + new TokenSet( /* bits: */ 0x00004000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* export */ + + new TokenSet( /* bits: */ 0x8022A020, 0x00000381, 0x00000000, /* counter: */ 10 ), /* statementSequence */ + + new TokenSet( /* bits: */ 0x8022A020, 0x00000381, 0x00000000, /* counter: */ 10 ), /* statement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* assignmentOrProcCall */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000010, /* counter: */ 1 ), /* actualParameters */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* expressionList */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000001, 0x00000000, /* counter: */ 1 ), /* returnStatement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000100, 0x00000000, /* counter: */ 1 ), /* withStatement */ + + new TokenSet( /* bits: */ 0x00020000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* ifStatement */ + + new TokenSet( /* bits: */ 0x00000020, 0x00000000, 0x00000000, /* counter: */ 1 ), /* caseStatement */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* case */ + + new TokenSet( /* bits: */ 0x00200000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* loopStatement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000080, 0x00000000, /* counter: */ 1 ), /* whileStatement */ + + new TokenSet( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* repeatStatement */ + + new TokenSet( /* bits: */ 0x00008000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* forStatement */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* designator */ + + new TokenSet( /* bits: */ 0x00000000, 0x40000000, 0x00000044, /* counter: */ 3 ), /* selector */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* expression */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* simpleExpression */ + + new TokenSet( /* bits: */ 0x01000000, 0x00003E00, 0x00000110, /* counter: */ 8 ), /* term */ + + new TokenSet( /* bits: */ 0x01000000, 0x00003E00, 0x00000110, /* counter: */ 8 ), /* simpleTerm */ + + new TokenSet( /* bits: */ 0x00000000, 0x00003E00, 0x00000110, /* counter: */ 7 ), /* factor */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* designatorOrFuncCall */ + + new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* setValue */ + + new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* element */ + + new TokenSet( /* bits: */ 0x00000044, 0x00000240, 0x00000000, /* counter: */ 4 ), /* formalType */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000040, 0x00000000, /* counter: */ 2 ), /* attributedFormalType */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000240, 0x00000000, /* counter: */ 3 ), /* formalParamList */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000240, 0x00000000, /* counter: */ 3 ), /* formalParams */ + + new TokenSet( /* bits: */ 0x00000040, 0x00000040, 0x00000000, /* counter: */ 2 ), /* attribFormalParams */ + + new TokenSet( /* bits: */ 0x58000004, 0x00000242, 0x00000050, /* counter: */ 9 ), /* typeDeclarationTail */ + }; + #endregion + + /* -------------------------------------------------------------------------- + * method Count() -- Returns the number of productions + * ----------------------------------------------------------------------- */ //SAM CHANGE + + static uint Count() { + return (uint)Enum.GetNames(typeof(Production)).Length; + } /* end Count */ + + + /* -------------------------------------------------------------------------- + * method IsOptionDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on any compiler option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsOptionDependent(Production p) { + return p >= firstOptionDependent; + } /* end IsOptionDependent */ + + + /* -------------------------------------------------------------------------- + * method IsConstParamDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on CONST parameter option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsConstParamDependent(Production p) + { + return p >= firstConstParamDependent && p <= lastConstParamDependent; + } /* end IsConstParamDependent */ + + + /* -------------------------------------------------------------------------- + * method IsVariantRecordDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on variant record type option, else false. + * ----------------------------------------------------------------------- */ //SAM CHANGE + + bool IsVariantRecordDependent(Production p) { + return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; + } + + /* -------------------------------------------------------------------------- + * method FIRST(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FIRST set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FIRST(Production p) { + TokenSet tokenset = null; + uint index = 0; + + if (IsConstParamDependent(p)) + { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) + { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + + tokenset = firstSets[index]; + + return tokenset; + } /* end FIRST */ + + + /* -------------------------------------------------------------------------- + * method FOLLOW(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FOLLOW set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FOLLOW(Production p) { + TokenSet tokenset = null; + uint index = 0; + + if (IsConstParamDependent(p)) { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + + tokenset = followSets[index]; + + return tokenset; + } /* end FOLLOW */ + + + /* -------------------------------------------------------------------------- + * method NameForProduction(p) + * -------------------------------------------------------------------------- + * Returns a string with a human readable name for production p. + * ----------------------------------------------------------------------- */ + + string NameForProduction(Production p); + + + +} /* NonTerminals */ + +} /* namespace */ \ No newline at end of file diff --git a/imp/Terminals.cs b/imp/Terminals.cs new file mode 100644 index 0000000..70e015f --- /dev/null +++ b/imp/Terminals.cs @@ -0,0 +1,530 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * Terminals.cs + * + * Terminal symbols' token and lexeme lookup. + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +namespace org.m2sf.m2sharp { + +public class Terminals : ITerminals { + +const Token FirstResWord = Token.AND; +const Token LastResWord = Token.WITH; + +const Token FirstLiteral = Token.StringLiteral; +const Token LastLiteral = Token.CharLiteral; + +const Token FirstMalformedLiteral = Token.MalformedString; +const Token LastMalformedLiteral = Token.MalformedReal; + +const Token FirstSpecialSymbol = Token.Plus; +const Token LastSpecialSymbol = Token.RightBrace; + + +/* --------------------------------------------------------------------------- + * method IsValid(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a valid token, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsValid (Token token) { + return (token != Token.Unknown) && !IsMalformedLiteral(token); +} /* end IsValid */ + + +/* --------------------------------------------------------------------------- + * method IsResword(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a reserved word, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsResword (Token token) { + return (token >= FirstResWord) && (token <= LastResWord); +} /* end IsResword */ + + +/* --------------------------------------------------------------------------- + * method IsLiteral(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a literal, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsLiteral (Token token) { + return (token >= FirstLiteral) && (token <= LastLiteral); +} /* end IsLiteral */ + + +/* --------------------------------------------------------------------------- + * method IsMalformedLiteral(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a malformed literal, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsMalformedLiteral (Token token) { + return (token >= FirstMalformedLiteral) && (token <= LastMalformedLiteral); +} /* end IsMalformedLiteral */ + + +/* --------------------------------------------------------------------------- + * method IsSpecialSymbol(token) + * --------------------------------------------------------------------------- + * Returns true if token represents a special symbol, otherwise false. + * ------------------------------------------------------------------------ */ + +public static bool IsSpecialSymbol (Token token) { + return (token >= FirstSpecialSymbol) && (token <= LastSpecialSymbol); +} /* end IsSpecialSymbol */ + + +/* --------------------------------------------------------------------------- + * method TokenForResword(lexeme) + * --------------------------------------------------------------------------- + * Tests if the given lexeme represents a reserved word and returns the + * corresponding token or Unknown if it does not match a reserved word. + * ------------------------------------------------------------------------ */ + +public static Token TokenForResword (string lexeme) { + int length; + + /* check pre-conditions */ + if (lexeme == null) { + return Token.Unknown; + } /* end if */ + + length = lexeme.Length; + + if ((length < 2) || (length > 14)) { + return Token.Unknown; + } /* end if */ + + switch (length) { + case /* length = 2 */ 2 : + switch (lexeme[0]) { + + case 'B' : + /* BY */ + if (lexeme[1] == 'Y') { + return Token.BY; + } /* end if */ + break; + + case 'D' : + /* DO */ + if (lexeme[1] == 'O') { + return Token.DO; + } /* end if */ + break; + + case 'I' : + /* IF */ + if (lexeme[1] == 'F') { + return Token.IF; + } + + /* IN */ + else if (lexeme[1] == 'N') { + return Token.IN; + } /* end if */ + break; + + case 'O' : + /* OF */ + if (lexeme[1] == 'F') { + return Token.OF; + } + + /* OR */ + else if (lexeme[1] == 'R') { + return Token.OR; + } /* end if */ + break; + + case 'T' : + /* TO */ + if (lexeme[1] == 'O') { + return Token.TO; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 3 */ 3 : + switch (lexeme[0]) { + + case 'A' : + /* AND */ + if (string.CompareOrdinal(lexeme, "AND") == 0) { + return Token.AND; + } /* end if */ + break; + + case 'D' : + /* DIV */ + if (string.CompareOrdinal(lexeme, "DIV") == 0) { + return Token.DIV; + } /* end if */ + break; + + case 'E' : + /* END */ + if (string.CompareOrdinal(lexeme, "END") == 0) { + return Token.END; + } /* end if */ + break; + + case 'F' : + /* FOR */ + if (string.CompareOrdinal(lexeme, "FOR") == 0) { + return Token.FOR; + } /* end if */ + break; + + case 'M' : + /* MOD */ + if (string.CompareOrdinal(lexeme, "MOD") == 0) { + return Token.MOD; + } /* end if */ + break; + + case 'N' : + /* NOT */ + if (string.CompareOrdinal(lexeme, "NOT") == 0) { + return Token.NOT; + } /* end if */ + break; + + case 'S' : + /* SET */ + if (string.CompareOrdinal(lexeme, "SET") == 0) { + return Token.SET; + } /* end if */ + break; + + case 'V' : + /* VAR */ + if (string.CompareOrdinal(lexeme, "VAR") == 0) { + return Token.VAR; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 4 */ 4 : + switch (lexeme[1]) { + + case 'A' : + /* CASE */ + if (string.CompareOrdinal(lexeme, "CASE") == 0) { + return Token.CASE; + } /* end if */ + break; + + case 'H' : + /* THEN */ + if (string.CompareOrdinal(lexeme, "THEN") == 0) { + return Token.THEN; + } /* end if */ + break; + + case 'I' : + /* WITH */ + if (string.CompareOrdinal(lexeme, "WITH") == 0) { + return Token.WITH; + } /* end if */ + break; + + case 'L' : + /* ELSE */ + if (string.CompareOrdinal(lexeme, "ELSE") == 0) { + return Token.ELSE; + } /* end if */ + break; + + case 'O' : + /* LOOP */ + if (string.CompareOrdinal(lexeme, "LOOP") == 0) { + return Token.LOOP; + } /* end if */ + break; + + case 'R' : + /* FROM */ + if (string.CompareOrdinal(lexeme, "FROM") == 0) { + return Token.FROM; + } /* end if */ + break; + + case 'X' : + /* EXIT */ + if (string.CompareOrdinal(lexeme, "EXIT") == 0) { + return Token.EXIT; + } /* end if */ + break; + + case 'Y' : + /* TYPE */ + if (string.CompareOrdinal(lexeme, "TYPE") == 0) { + return Token.TYPE; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 5 */ 5 : + switch (lexeme[0]) { + + case 'A' : + /* ARRAY */ + if (string.CompareOrdinal(lexeme, "ARRAY") == 0) { + return Token.ARRAY; + } /* end if */ + break; + + case 'B' : + /* BEGIN */ + if (string.CompareOrdinal(lexeme, "BEGIN") == 0) { + return Token.BEGIN; + } /* end if */ + break; + + case 'C' : + /* CONST */ + if (string.CompareOrdinal(lexeme, "CONST") == 0) { + return Token.CONST; + } /* end if */ + break; + + case 'E' : + /* ELSIF */ + if (string.CompareOrdinal(lexeme, "ELSIF") == 0) { + return Token.ELSIF; + } /* end if */ + break; + + case 'U' : + /* UNTIL */ + if (string.CompareOrdinal(lexeme, "UNTIL") == 0) { + return Token.UNTIL; + } /* end if */ + break; + + case 'W' : + /* WHILE */ + if (string.CompareOrdinal(lexeme, "WHILE") == 0) { + return Token.WHILE; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length 6 */ 6 : + switch (lexeme[2]) { + + case 'D' : + /* MODULE */ + if (string.CompareOrdinal(lexeme, "MODULE") == 0) { + return Token.MODULE; + } /* end if */ + break; + + case 'A' : + /* OPAQUE */ + if (string.CompareOrdinal(lexeme, "OPAQUE") == 0) { + return Token.OPAQUE; + } /* end if */ + break; + + case 'C' : + /* RECORD */ + if (string.CompareOrdinal(lexeme, "RECORD") == 0) { + return Token.RECORD; + } /* end if */ + break; + + case 'T' : + /* RETURN */ + if (string.CompareOrdinal(lexeme, "RETURN") == 0) { + return Token.RETURN; + } /* end if */ + break; + + case 'P' : + switch (lexeme[0]) { + + case 'E' : + /* EXPORT */ + if (string.CompareOrdinal(lexeme, "EXPORT") == 0) { + return Token.EXPORT; + } /* end if */ + break; + + case 'I' : + /* IMPORT */ + if (string.CompareOrdinal(lexeme, "IMPORT") == 0) { + return Token.IMPORT; + } /* end if */ + break; + + case 'R' : + /* REPEAT */ + if (string.CompareOrdinal(lexeme, "REPEAT") == 0) { + return Token.REPEAT; + } /* end if */ + break; + + } /* end switch */ + break; + + } /* end switch */ +break; + + case /* length = 7 */ 7 : + switch (lexeme[0]) { + + case 'A' : + /* ARGLIST */ + if (string.CompareOrdinal(lexeme, "ARGLIST") == 0) { + return Token.ARGLIST; + } /* end if */ + break; + + case 'P' : + /* POINTER */ + if (string.CompareOrdinal(lexeme, "POINTER") == 0) { + return Token.POINTER; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 9 */ 9 : + switch (lexeme[0]) { + + case 'P' : + /* PROCEDURE */ + if (string.CompareOrdinal(lexeme, "PROCEDURE") == 0) { + return Token.PROCEDURE; + } /* end if */ + break; + + case 'Q' : + /* QUALIFIED */ + if (string.CompareOrdinal(lexeme, "QUALIFIED") == 0) { + return Token.QUALIFIED; + } /* end if */ + break; + + } /* end switch */ + break; + + case /* length = 10 */ 10 : + /* DEFINITION */ + if (string.CompareOrdinal(lexeme, "DEFINITION") == 0) { + return Token.DEFINITION; + } /* end if */ + break; + + case /* length = 14 */ 14 : + /* IMPLEMENTATION */ + if (string.CompareOrdinal(lexeme, "IMPLEMENTATION") == 0) { + return Token.IMPLEMENTATION; + } /* end if */ + break; + + } /* end switch (length) */ + + return Token.Unknown; +} /* end TokenForResword */ + + +/* --------------------------------------------------------------------------- + * method LexemeForResword(token) + * --------------------------------------------------------------------------- + * Returns a string with the lexeme for the reserved word represented by + * token. Returns null if the token does not represent a reserved word. + * ------------------------------------------------------------------------ */ + +public static string LexemeForResword (Token token) { + if (IsResword(token) == false) { + return null; + } /* end if */ + return token.ToString(); +} /* end LexemeForResword */ + + +/* --------------------------------------------------------------------------- + * method LexemeForSpecialSymbol(token) + * --------------------------------------------------------------------------- + * Returns a string with the lexeme for the special symbol represented by + * token. Returns null if the token does not represent a special symbol. + * ------------------------------------------------------------------------ */ + +public static string LexemeForSpecialSymbol (Token token) { + if (IsSpecialSymbol(token) == false) { + return null; + } /* end if */ + return ""; // TO DO +} /* end LexemeForSpecialSymbol */ + + +/* --------------------------------------------------------------------------- + * method NameForToken(token) + * --------------------------------------------------------------------------- + * Returns a string with a human readable name for token. Returns null if + * token is not a valid token. + * ------------------------------------------------------------------------ */ + +public static string NameForToken (Token token) { + return token.ToString(); +} /* NameForToken */ + + +} /* Terminals */ + +} /* namespace */ + +/* END OF FILE */ \ No newline at end of file diff --git a/imp/TokenSet.cs b/imp/TokenSet.cs new file mode 100644 index 0000000..1d84115 --- /dev/null +++ b/imp/TokenSet.cs @@ -0,0 +1,588 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * TokenSet.cs + * + * A set of Token type variables which is used to pass First and Follow sets + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace org.m2sf.m2sharp +{ + + public class TokenSet : ITokenSet { + + /* Lexeme Table */ + public static string[] lexemeTable = { + /* Null Token */ + + "UNKNOWN", + + /* Reserved Words */ + + "AND", + "ARGLIST", + "ARRAY", + "BEGIN", + "BY", + "CASE", + "CONST", + "DEFINITION", + "DIV", + "DO", + "ELSE", + "ELSIF", + "END", + "EXIT", + "EXPORT", + "FOR", + "FROM", + "IF", + "IMPLEMENTATION", + "IMPORT", + "IN", + "LOOP", + "MOD", + "MODULE", + "NOT", + "OF", + "OR", + "POINTER", + "PROCEDURE", + "QUALIFIED", + "RECORD", + "REPEAT", + "RETURN", + "SET", + "THEN", + "TO", + "TYPE", + "UNTIL", + "VAR", + "WHILE", + "WITH", + + /* Identifiers */ + + "IDENTIFIER", + + /* Literals */ + + "STRING-LITERAL", + "INTEGER-LITERAL", + "REAL-LITERAL", + "CHAR-LITERAL", + + "MALFORMED-STRING", + "MALFORMED-INTEGER", + "MALFORMED-REAL", + + /* Pragmas */ + + "PRAGMA", + + /* Special Symbols */ + + "PLUS", + "MINUS", + "EQUAL", + "NOTEQUAL", + "LESS-THAN", + "LESS-OR-EQUAL", + "GREATER-THAN", + "GREATER-OR-EQUAL", + "ASTERISK", + "SOLIDUS", + "BACKSLASH", + "ASSIGNMENT", + "COMMA", + "PERIOD", + "COLON", + "SEMICOLON", + "RANGE", + "DEREF", + "VERTICAL-BAR", + "LEFT-PAREN", + "RIGHT-PAREN", + "LEFT-BRACKET", + "RIGHT-BRACKET", + "LEFT-BRACE", + "RIGHT-BRACE", + "END-OF-FILE" + +}; /* end m2c_token_name_table */ + + public static const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; + + public struct TokenSetBits + { + public uint[] segments = new uint[segmentCount]; + public uint elemCount; + } /* end struct */ + + TokenSetBits dataStored; + + /* --------------------------------------------------------------------------- + * private constructor TokenSet () + * --------------------------------------------------------------------------- + * Prevents clients from invoking the default constructor. + * ------------------------------------------------------------------------ */ + + private TokenSet() + { + // no operation + } /* end TokenSet */ + + /* --------------------------------------------------------------------------- + * private constructor TokenSet (uint[]) + * --------------------------------------------------------------------------- + * used to instantiate the prefabricated first and follow lists + * ------------------------------------------------------------------------ */ + + public TokenSet(params uint[] TSB) + { + dataStored.segments[0] = TSB[0]; + dataStored.segments[1] = TSB[1]; + dataStored.segments[2] = TSB[2]; + dataStored.elemCount = TSB[3]; + } + + /* -------------------------------------------------------------------------- + * constructor newFromList(token, ...) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object that includes the tokens passed + * as arguments of a variadic argument list. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromList(params Token[] tokenList) + { + TokenSet newSet = new TokenSet(); + uint bit, segmentIndex; + Token token; + + /* allocate new set */ + newSet.dataStored.segments = new uint[segmentCount]; + + /* initialise */ + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + newSet.dataStored.segments[segmentIndex] = 0; + } /* end For */ + + /* store tokens from list */ + token = tokenList[0]; + for (int i = 1; token != Token.Unknown; i++) + { + + if (token <= Token.EndOfFile) + { + segmentIndex = (uint)token / 32; + bit = (uint)token % 32; + newSet.dataStored.segments[segmentIndex] = (newSet.dataStored.segments[segmentIndex] | (uint)(1 << (int)bit)); + } /* end if */ + + /* get next token in list */ + token = tokenList[i]; + } /* end while */ + + /* update element counter */ + newSet.dataStored.elemCount = CountBits(newSet); + + return newSet; + } /* end newFromList */ + + + /* -------------------------------------------------------------------------- + * constructor newFromUnion(set, ...) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object that represents the set union of + * the tokensets passed as arguments of a non-empty variadic argument list. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromUnion(params TokenSet[] setList) + { + uint segmentIndex; + TokenSet set, + newSet = new TokenSet(); + + + /* initialise */ + newSet.dataStored.segments = new uint[segmentCount]; + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + newSet.dataStored.segments[segmentIndex] = 0; + } /* end for */ + + set = setList[0]; + /* calculate union with each set in list */ + for (int i = 0; set != null; i++) + { + /* for each segment ... */ + while (segmentIndex < segmentCount) + { + /* ... store union of corresponding segments */ + newSet.dataStored.segments[segmentIndex] = + newSet.dataStored.segments[segmentIndex] | newSet.dataStored.segments[segmentIndex]; + + /* next segment */ + segmentIndex++; + } /* end while */ + + /*get next set in list */ + if (i < setList.Length) + set = setList[i]; + else + set = null; + + } /* end for */ + + /* update element counter */ + newSet.dataStored.elemCount = CountBits(newSet); + + return newSet; + } /* end newFromUnion + +/* -------------------------------------------------------------------------- + * method Count() + * -------------------------------------------------------------------------- + * Returns the number of elements in the receiver. + * ----------------------------------------------------------------------- */ + + public uint Count() + { + + return this.dataStored.elemCount; + } /* end IsElement */ + + + /* -------------------------------------------------------------------------- + * method IsElement(token) + * -------------------------------------------------------------------------- + * Returns true if token is an element of the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsElement(Token token) + { + int segmentIndex, bit; + + if (token > Token.EndOfFile) + { + return false; + } /* end if */ + + segmentIndex = (int)token / 32; + bit = (int)token % 32; + + return (this.dataStored.segments[segmentIndex] & (1 << bit)) != 0; + } /* end IsElement */ + + + /* -------------------------------------------------------------------------- + * method IsSubset(set) + * -------------------------------------------------------------------------- + * Returns true if each element in set is also in the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsSubset(TokenSet set) + { + + for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + if (((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) + ^ this.dataStored.segments[segmentIndex]) != 0) + { + + return false; + + } /* end if */ + + } /* end for */ + + return true; + + } /* end IsSubset */ + + + /* -------------------------------------------------------------------------- + * method IsDisjunct(set) + * -------------------------------------------------------------------------- + * Returns true if set has no common elements with the receiver, else false. + * ----------------------------------------------------------------------- */ + + public bool IsDisjunct(TokenSet set) + { + + for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + if ((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) != 0) + { + + return false; + + } /* end if */ + + } /* end for */ + + return true; + + } /* end IsDisjunct */ + + /* -------------------------------------------------------------------------- + * method ElementList() + * -------------------------------------------------------------------------- + * Returns a token list of all elements in the receiver. + * ----------------------------------------------------------------------- */ + //TODO + + public List ElementList() + { + List allElements = new List(); + uint segmentIndex, count; + int bit; + Token token; + + if (this.dataStored.elemCount == 0) + { + return null; + } /* end if */ + + token = 0; + count = 0; + + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (int)token % 32; + + if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) + { + count++; + allElements.Add(token); + } /* end if */ + token++; + } /* end while */ + + return allElements; + + } /* end ElementList */ + + + /* -------------------------------------------------------------------------- + * method PrintSet(label) + * -------------------------------------------------------------------------- + * Prints a human readable representation of the receiver. + * Format: label = { comma-separated list of tokens }; + * ----------------------------------------------------------------------- */ + + public void PrintSet(string label) + { + uint segmentIndex, count; + int bit; + Token token; + + Console.Write(label + " = {"); + if (this.dataStored.elemCount == 0) + { + Console.Write(" "); + } /* end if */ + + token = 0; + count = 0; + + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (int)token % 32; + + if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) + { + count++; + + if (count <= this.dataStored.elemCount) + { + + Console.Write("\n {0},", lexemeTable[(uint)token]); + } + else + { + Console.WriteLine("\n {0}", lexemeTable[(uint)token]); + } /* end if */ + } /* end if */ + token++; + } /* end while */ + + Console.WriteLine("};"); + } /* end PrintSet */ + + + /* -------------------------------------------------------------------------- + * method PrintList() + * -------------------------------------------------------------------------- + * Prints a human readable list of tokens in the receiver. + * Format: first, second, third, ..., secondToLast or last + * ----------------------------------------------------------------------- */ + + public void PrintList() + { + uint bit, segmentIndex, count; + Token token; + + if (this.dataStored.elemCount == 0) + { + Console.WriteLine("(nil)"); + } + + count = 0; + token = 0; + while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) + { + segmentIndex = (uint)token / 32; + bit = (uint)token % 32; + + if (((this.dataStored.segments[segmentIndex] & (1 << (int)bit)) != 0)) + { + count++; + if (count > 1) + { + if (count <= this.dataStored.elemCount) + { + Console.Write(", "); + } + else + { + Console.Write(" or "); + } /* end if */ + } /* end if */ + + Console.Write(lexemeTable[(uint)token]); + } + token++; + } + + Console.WriteLine("."); + } /* end PrintList */ + + + /* -------------------------------------------------------------------------- + * method PrintLiteralStruct(ident) + * -------------------------------------------------------------------------- + * Prints a struct definition for a tokenset literal for the receiver. + * Format: struct ident { uint s0; uint s1; uint s2; ...; uint n }; + * ----------------------------------------------------------------------- */ + + public void PrintLiteralStruct(string ident) + { + uint segmentIndex; + + Console.Write("struct {0} {{ uint s0", ident); + + for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) + { + Console.Write("; s" + segmentIndex); + } /* end for */ + + Console.WriteLine("; n };"); + Console.WriteLine("typedef struct {0} {0};", ident); + + } /* end PrintLiteralStruct */ + + + /* -------------------------------------------------------------------------- + * method PrintLiteral() + * -------------------------------------------------------------------------- + * Prints a sequence of hex values representing the bit pattern of receiver. + * Format: ( 0xHHHHHHHH, 0xHHHHHHHH, ..., count ); + * ----------------------------------------------------------------------- */ + + public void PrintLiteral() + { + uint segmentIndex; + + Console.Write("( /* bits: */ 0x" + this.dataStored.segments[0].ToString("x08")); + + for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) + { + + Console.Write(", 0x" + this.dataStored.segments[segmentIndex].ToString("x08")); + } /* end for */ + + Console.WriteLine(", /* counter: */ " + this.dataStored.elemCount + " );"); + } /* end PrintLiteral */ + + /* -------------------------------------------------------------------------- + * method CountBits() + * -------------------------------------------------------------------------- + * Returns the number of set bits in set. + * ----------------------------------------------------------------------- */ + + static private uint CountBits(TokenSet set) + { + int bit; + uint segmentIndex, + bitCount = 0; + + for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) + { + + for (bit = 0; bit < 32; bit++) + { + + if ((set.dataStored.segments[segmentIndex] & (1 << bit)) != 0) + { + bitCount++; + } /* end if */ + + } /* end for */ + + } /* end for */ + + return bitCount; + } /* end CountBits */ + + } /* end TokenSet */ + +} /* end namespace */ From 1bb9c75f304da6071c27ce56ac68f642477e2271 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Tue, 23 May 2017 14:04:18 -0700 Subject: [PATCH 16/24] Delete NonTerminals.cs --- NonTerminals.cs | 461 ------------------------------------------------ 1 file changed, 461 deletions(-) delete mode 100644 NonTerminals.cs diff --git a/NonTerminals.cs b/NonTerminals.cs deleted file mode 100644 index 3620d28..0000000 --- a/NonTerminals.cs +++ /dev/null @@ -1,461 +0,0 @@ -/* M2Sharp -- Modula-2 to C# Translator & Compiler - * - * Copyright (c) 2016 The Modula-2 Software Foundation - * - * Author & Maintainer: Benjamin Kowarsch - * - * @synopsis - * - * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. - * It supports the dialects described in the 3rd and 4th editions of Niklaus - * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, - * and an extended mode with select features from the revised language by - * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). - * - * In translator mode, M2Sharp translates Modula-2 source to C# source files. - * In compiler mode, M2Sharp compiles Modula-2 source via C# source files - * to object code or executables using the host system's C# compiler. - * - * @repository - * - * https://github.com/m2sf/m2sharp - * - * @file - * - * NonTerminals.cs - * - * provides FIRST() and FOLLOW() sets for each non-terminal symbol //SAM CHANGE - * used by the parser class for syntax analysis - * - * @license - * - * M2Sharp is free software: you can redistribute and/or modify it under the - * terms of the GNU Lesser General Public License (LGPL) either version 2.1 - * or at your choice version 3 as published by the Free Software Foundation. - * However, you may not alter the copyright, author and license information. - * - * M2Sharp is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with M2Sharp. If not, see . - * - * NB: Components in the domain part of email addresses are in reverse order. - */ - -namespace org.m2sf.m2sharp { - - using System; - using System.Collections.Generic; - -public class NonTerminals : INonTerminals { - - public static Production firstConstParamDependent = Production.FormalType, - lastConstParamDependent = Production.AttribFormalParams, - firstNoVariantRecDependent = Production.TypeDeclarationTail, - lastNoVariantRecDependent = Production.TypeDeclarationTail, - firstOptionDependent = firstConstParamDependent, - lastOptionDependent = lastNoVariantRecDependent; - public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; - - #region followSets - TokenSet[] followSets = { - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* definitionModule */ - - new TokenSet( /* bits: */ 0x108050C8, 0x00000050, 0x00000000, /* counter: */ 9 ), /* import */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* qualifiedImport */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* unqualifiedImport */ - - new TokenSet( /* bits: */ 0x00000000, 0x80000000, 0x00000021, /* counter: */ 3 ), /* identList */ - - new TokenSet( /* bits: */ 0x00001000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* constDefinition */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDefinition */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* type */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* derivedOrSubrangeType */ - - new TokenSet( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000037B, /* counter: */ 34 ), /* qualident */ - - new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* range */ - - new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* enumType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* setType */ - - new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* countableType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* arrayType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* extensibleRecordType */ - - new TokenSet( /* bits: */ 0x00001000, 0x00000040, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variantRecordType */ - - new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variantFieldListSeq */ - - new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFieldList */ - - new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFields */ - - new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variant */ - - new TokenSet( /* bits: */ 0x00000000, 0x80000000, 0x00000000, /* counter: */ 1 ), /* caseLabelList */ - - new TokenSet( /* bits: */ 0x00000000, 0xA0000000, 0x00000000, /* counter: */ 2 ), /* caseLabels */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* pointerType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureType */ - - new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* simpleFormalType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureHeader */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureSignature */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* simpleFormalParams */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* implementationModule */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* programModule */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* modulePriority */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* block */ - - new TokenSet( /* bits: */ 0x00001008, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclaration */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* varSizeRecordType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variableDeclaration */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureDeclaration */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* moduleDeclaration */ - - new TokenSet( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* export */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000008, /* counter: */ 5 ), /* statementSequence */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* statement */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* assignmentOrProcCall */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* actualParameters */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* expressionList */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* returnStatement */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* withStatement */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* ifStatement */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* caseStatement */ - - new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* case */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* loopStatement */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* whileStatement */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* repeatStatement */ - - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* forStatement */ - - new TokenSet( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000033B, /* counter: */ 33 ), /* designator */ - - new TokenSet( /* bits: */ 0x06501F12, 0x3FFC022C, 0x0000033B, /* counter: */ 34 ), /* selector */ - - new TokenSet( /* bits: */ 0x02001E10, 0x2000002C, 0x0000022B, /* counter: */ 15 ), /* expression */ - - new TokenSet( /* bits: */ 0x02101E10, 0x23F0002C, 0x0000022B, /* counter: */ 22 ), /* simpleExpression */ - - new TokenSet( /* bits: */ 0x06101E10, 0x23FC002C, 0x0000022B, /* counter: */ 25 ), /* term */ - - new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* simpleTerm */ - - new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* factor */ - - new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* designatorOrFuncCall */ - - new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* setValue */ - - new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000200, /* counter: */ 2 ), /* element */ - - new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* formalType */ - - new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* attributedFormalType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* formalParamList */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* formalParams */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* attribFormalParams */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclarationTail */ - }; - - #endregion - - #region firstSets - TokenSet[] firstSets = { - new TokenSet( /* bits: */ 0x00000080, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ - - new TokenSet( /* bits: */ 0x00090000, 0x00000000, 0x00000000, /* counter: */ 2 ), /* import */ - - new TokenSet( /* bits: */ 0x00080000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* qualifiedImport */ - - new TokenSet( /* bits: */ 0x00010000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* unqualifiedImport */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* identList */ - - new TokenSet( /* bits: */ 0x10000040, 0x00000050, 0x00000000, /* counter: */ 4 ), /* definition */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* constDefinition */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* typeDefinition */ - - new TokenSet( /* bits: */ 0x58000004, 0x00000202, 0x00000050, /* counter: */ 8 ), /* type */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000040, /* counter: */ 2 ), /* derivedOrSubrangeType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* qualident */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* range */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000010, /* counter: */ 1 ), /* enumType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000002, 0x00000000, /* counter: */ 1 ), /* setType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000050, /* counter: */ 3 ), /* countableType */ - - new TokenSet( /* bits: */ 0x00000004, 0x00000000, 0x00000000, /* counter: */ 1 ), /* arrayType */ - - new TokenSet( /* bits: */ 0x40000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* extensibleRecordType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* fieldListSequence */ - - new TokenSet( /* bits: */ 0x40000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantRecordType */ - - new TokenSet( /* bits: */ 0x00000020, 0x00000200, 0x00000000, /* counter: */ 2 ), /* variantFieldListSeq */ - - new TokenSet( /* bits: */ 0x00000020, 0x00000200, 0x00000000, /* counter: */ 2 ), /* variantFieldList */ - - new TokenSet( /* bits: */ 0x00000020, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantFields */ - - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* variant */ - - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* caseLabelList */ - - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* caseLabels */ - - new TokenSet( /* bits: */ 0x08000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* pointerType */ - - new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureType */ - - new TokenSet( /* bits: */ 0x00000004, 0x00000200, 0x00000000, /* counter: */ 2 ), /* simpleFormalType */ - - new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureHeader */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* procedureSignature */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* simpleFormalParams */ - - new TokenSet( /* bits: */ 0x00040000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* implementationModule */ - - new TokenSet( /* bits: */ 0x00800000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* programModule */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* modulePriority */ - - new TokenSet( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* block */ - - new TokenSet( /* bits: */ 0x10800040, 0x00000050, 0x00000000, /* counter: */ 5 ), /* declaration */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* typeDeclaration */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000040, 0x00000000, /* counter: */ 1 ), /* varSizeRecordType */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* variableDeclaration */ - - new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureDeclaration */ - - new TokenSet( /* bits: */ 0x00800000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* moduleDeclaration */ - - new TokenSet( /* bits: */ 0x00004000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* export */ - - new TokenSet( /* bits: */ 0x8022A020, 0x00000381, 0x00000000, /* counter: */ 10 ), /* statementSequence */ - - new TokenSet( /* bits: */ 0x8022A020, 0x00000381, 0x00000000, /* counter: */ 10 ), /* statement */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* assignmentOrProcCall */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000010, /* counter: */ 1 ), /* actualParameters */ - - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* expressionList */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000001, 0x00000000, /* counter: */ 1 ), /* returnStatement */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000100, 0x00000000, /* counter: */ 1 ), /* withStatement */ - - new TokenSet( /* bits: */ 0x00020000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* ifStatement */ - - new TokenSet( /* bits: */ 0x00000020, 0x00000000, 0x00000000, /* counter: */ 1 ), /* caseStatement */ - - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* case */ - - new TokenSet( /* bits: */ 0x00200000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* loopStatement */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000080, 0x00000000, /* counter: */ 1 ), /* whileStatement */ - - new TokenSet( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* repeatStatement */ - - new TokenSet( /* bits: */ 0x00008000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* forStatement */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* designator */ - - new TokenSet( /* bits: */ 0x00000000, 0x40000000, 0x00000044, /* counter: */ 3 ), /* selector */ - - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* expression */ - - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* simpleExpression */ - - new TokenSet( /* bits: */ 0x01000000, 0x00003E00, 0x00000110, /* counter: */ 8 ), /* term */ - - new TokenSet( /* bits: */ 0x01000000, 0x00003E00, 0x00000110, /* counter: */ 8 ), /* simpleTerm */ - - new TokenSet( /* bits: */ 0x00000000, 0x00003E00, 0x00000110, /* counter: */ 7 ), /* factor */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* designatorOrFuncCall */ - - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* setValue */ - - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* element */ - - new TokenSet( /* bits: */ 0x00000044, 0x00000240, 0x00000000, /* counter: */ 4 ), /* formalType */ - - new TokenSet( /* bits: */ 0x00000040, 0x00000040, 0x00000000, /* counter: */ 2 ), /* attributedFormalType */ - - new TokenSet( /* bits: */ 0x00000040, 0x00000240, 0x00000000, /* counter: */ 3 ), /* formalParamList */ - - new TokenSet( /* bits: */ 0x00000040, 0x00000240, 0x00000000, /* counter: */ 3 ), /* formalParams */ - - new TokenSet( /* bits: */ 0x00000040, 0x00000040, 0x00000000, /* counter: */ 2 ), /* attribFormalParams */ - - new TokenSet( /* bits: */ 0x58000004, 0x00000242, 0x00000050, /* counter: */ 9 ), /* typeDeclarationTail */ - }; - #endregion - - /* -------------------------------------------------------------------------- - * method Count() -- Returns the number of productions - * ----------------------------------------------------------------------- */ //SAM CHANGE - - static uint Count() { - return (uint)Enum.GetNames(typeof(Production)).Length; - } /* end Count */ - - - /* -------------------------------------------------------------------------- - * method IsOptionDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on any compiler option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE - - bool IsOptionDependent(Production p) { - return p >= firstOptionDependent; - } /* end IsOptionDependent */ - - - /* -------------------------------------------------------------------------- - * method IsConstParamDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on CONST parameter option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE - - bool IsConstParamDependent(Production p) - { - return p >= firstConstParamDependent && p <= lastConstParamDependent; - } /* end IsConstParamDependent */ - - - /* -------------------------------------------------------------------------- - * method IsVariantRecordDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on variant record type option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE - - bool IsVariantRecordDependent(Production p) { - return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; - } - - /* -------------------------------------------------------------------------- - * method FIRST(p) - * -------------------------------------------------------------------------- - * Returns a tokenset with the FIRST set of production p. - * ----------------------------------------------------------------------- */ - - TokenSet FIRST(Production p) { - TokenSet tokenset = null; - uint index = 0; - - if (IsConstParamDependent(p)) - { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) - { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - - tokenset = firstSets[index]; - - return tokenset; - } /* end FIRST */ - - - /* -------------------------------------------------------------------------- - * method FOLLOW(p) - * -------------------------------------------------------------------------- - * Returns a tokenset with the FOLLOW set of production p. - * ----------------------------------------------------------------------- */ - - TokenSet FOLLOW(Production p) { - TokenSet tokenset = null; - uint index = 0; - - if (IsConstParamDependent(p)) { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - - tokenset = followSets[index]; - - return tokenset; - } /* end FOLLOW */ - - - /* -------------------------------------------------------------------------- - * method NameForProduction(p) - * -------------------------------------------------------------------------- - * Returns a string with a human readable name for production p. - * ----------------------------------------------------------------------- */ - - string NameForProduction(Production p); - - - -} /* NonTerminals */ - -} /* namespace */ \ No newline at end of file From 174cb31a4e7f4c2c9534679311f4ca06bf0d0047 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Tue, 23 May 2017 14:04:33 -0700 Subject: [PATCH 17/24] Delete Terminals.cs --- Terminals.cs | 530 --------------------------------------------------- 1 file changed, 530 deletions(-) delete mode 100644 Terminals.cs diff --git a/Terminals.cs b/Terminals.cs deleted file mode 100644 index 70e015f..0000000 --- a/Terminals.cs +++ /dev/null @@ -1,530 +0,0 @@ -/* M2Sharp -- Modula-2 to C# Translator & Compiler - * - * Copyright (c) 2016 The Modula-2 Software Foundation - * - * Author & Maintainer: Benjamin Kowarsch - * - * @synopsis - * - * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. - * It supports the dialects described in the 3rd and 4th editions of Niklaus - * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, - * and an extended mode with select features from the revised language by - * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). - * - * In translator mode, M2Sharp translates Modula-2 source to C# source files. - * In compiler mode, M2Sharp compiles Modula-2 source via C# source files - * to object code or executables using the host system's C# compiler. - * - * @repository - * - * https://github.com/m2sf/m2sharp - * - * @file - * - * Terminals.cs - * - * Terminal symbols' token and lexeme lookup. - * - * @license - * - * M2Sharp is free software: you can redistribute and/or modify it under the - * terms of the GNU Lesser General Public License (LGPL) either version 2.1 - * or at your choice version 3 as published by the Free Software Foundation. - * However, you may not alter the copyright, author and license information. - * - * M2Sharp is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with M2Sharp. If not, see . - * - * NB: Components in the domain part of email addresses are in reverse order. - */ - -namespace org.m2sf.m2sharp { - -public class Terminals : ITerminals { - -const Token FirstResWord = Token.AND; -const Token LastResWord = Token.WITH; - -const Token FirstLiteral = Token.StringLiteral; -const Token LastLiteral = Token.CharLiteral; - -const Token FirstMalformedLiteral = Token.MalformedString; -const Token LastMalformedLiteral = Token.MalformedReal; - -const Token FirstSpecialSymbol = Token.Plus; -const Token LastSpecialSymbol = Token.RightBrace; - - -/* --------------------------------------------------------------------------- - * method IsValid(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a valid token, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsValid (Token token) { - return (token != Token.Unknown) && !IsMalformedLiteral(token); -} /* end IsValid */ - - -/* --------------------------------------------------------------------------- - * method IsResword(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a reserved word, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsResword (Token token) { - return (token >= FirstResWord) && (token <= LastResWord); -} /* end IsResword */ - - -/* --------------------------------------------------------------------------- - * method IsLiteral(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a literal, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsLiteral (Token token) { - return (token >= FirstLiteral) && (token <= LastLiteral); -} /* end IsLiteral */ - - -/* --------------------------------------------------------------------------- - * method IsMalformedLiteral(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a malformed literal, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsMalformedLiteral (Token token) { - return (token >= FirstMalformedLiteral) && (token <= LastMalformedLiteral); -} /* end IsMalformedLiteral */ - - -/* --------------------------------------------------------------------------- - * method IsSpecialSymbol(token) - * --------------------------------------------------------------------------- - * Returns true if token represents a special symbol, otherwise false. - * ------------------------------------------------------------------------ */ - -public static bool IsSpecialSymbol (Token token) { - return (token >= FirstSpecialSymbol) && (token <= LastSpecialSymbol); -} /* end IsSpecialSymbol */ - - -/* --------------------------------------------------------------------------- - * method TokenForResword(lexeme) - * --------------------------------------------------------------------------- - * Tests if the given lexeme represents a reserved word and returns the - * corresponding token or Unknown if it does not match a reserved word. - * ------------------------------------------------------------------------ */ - -public static Token TokenForResword (string lexeme) { - int length; - - /* check pre-conditions */ - if (lexeme == null) { - return Token.Unknown; - } /* end if */ - - length = lexeme.Length; - - if ((length < 2) || (length > 14)) { - return Token.Unknown; - } /* end if */ - - switch (length) { - case /* length = 2 */ 2 : - switch (lexeme[0]) { - - case 'B' : - /* BY */ - if (lexeme[1] == 'Y') { - return Token.BY; - } /* end if */ - break; - - case 'D' : - /* DO */ - if (lexeme[1] == 'O') { - return Token.DO; - } /* end if */ - break; - - case 'I' : - /* IF */ - if (lexeme[1] == 'F') { - return Token.IF; - } - - /* IN */ - else if (lexeme[1] == 'N') { - return Token.IN; - } /* end if */ - break; - - case 'O' : - /* OF */ - if (lexeme[1] == 'F') { - return Token.OF; - } - - /* OR */ - else if (lexeme[1] == 'R') { - return Token.OR; - } /* end if */ - break; - - case 'T' : - /* TO */ - if (lexeme[1] == 'O') { - return Token.TO; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 3 */ 3 : - switch (lexeme[0]) { - - case 'A' : - /* AND */ - if (string.CompareOrdinal(lexeme, "AND") == 0) { - return Token.AND; - } /* end if */ - break; - - case 'D' : - /* DIV */ - if (string.CompareOrdinal(lexeme, "DIV") == 0) { - return Token.DIV; - } /* end if */ - break; - - case 'E' : - /* END */ - if (string.CompareOrdinal(lexeme, "END") == 0) { - return Token.END; - } /* end if */ - break; - - case 'F' : - /* FOR */ - if (string.CompareOrdinal(lexeme, "FOR") == 0) { - return Token.FOR; - } /* end if */ - break; - - case 'M' : - /* MOD */ - if (string.CompareOrdinal(lexeme, "MOD") == 0) { - return Token.MOD; - } /* end if */ - break; - - case 'N' : - /* NOT */ - if (string.CompareOrdinal(lexeme, "NOT") == 0) { - return Token.NOT; - } /* end if */ - break; - - case 'S' : - /* SET */ - if (string.CompareOrdinal(lexeme, "SET") == 0) { - return Token.SET; - } /* end if */ - break; - - case 'V' : - /* VAR */ - if (string.CompareOrdinal(lexeme, "VAR") == 0) { - return Token.VAR; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 4 */ 4 : - switch (lexeme[1]) { - - case 'A' : - /* CASE */ - if (string.CompareOrdinal(lexeme, "CASE") == 0) { - return Token.CASE; - } /* end if */ - break; - - case 'H' : - /* THEN */ - if (string.CompareOrdinal(lexeme, "THEN") == 0) { - return Token.THEN; - } /* end if */ - break; - - case 'I' : - /* WITH */ - if (string.CompareOrdinal(lexeme, "WITH") == 0) { - return Token.WITH; - } /* end if */ - break; - - case 'L' : - /* ELSE */ - if (string.CompareOrdinal(lexeme, "ELSE") == 0) { - return Token.ELSE; - } /* end if */ - break; - - case 'O' : - /* LOOP */ - if (string.CompareOrdinal(lexeme, "LOOP") == 0) { - return Token.LOOP; - } /* end if */ - break; - - case 'R' : - /* FROM */ - if (string.CompareOrdinal(lexeme, "FROM") == 0) { - return Token.FROM; - } /* end if */ - break; - - case 'X' : - /* EXIT */ - if (string.CompareOrdinal(lexeme, "EXIT") == 0) { - return Token.EXIT; - } /* end if */ - break; - - case 'Y' : - /* TYPE */ - if (string.CompareOrdinal(lexeme, "TYPE") == 0) { - return Token.TYPE; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 5 */ 5 : - switch (lexeme[0]) { - - case 'A' : - /* ARRAY */ - if (string.CompareOrdinal(lexeme, "ARRAY") == 0) { - return Token.ARRAY; - } /* end if */ - break; - - case 'B' : - /* BEGIN */ - if (string.CompareOrdinal(lexeme, "BEGIN") == 0) { - return Token.BEGIN; - } /* end if */ - break; - - case 'C' : - /* CONST */ - if (string.CompareOrdinal(lexeme, "CONST") == 0) { - return Token.CONST; - } /* end if */ - break; - - case 'E' : - /* ELSIF */ - if (string.CompareOrdinal(lexeme, "ELSIF") == 0) { - return Token.ELSIF; - } /* end if */ - break; - - case 'U' : - /* UNTIL */ - if (string.CompareOrdinal(lexeme, "UNTIL") == 0) { - return Token.UNTIL; - } /* end if */ - break; - - case 'W' : - /* WHILE */ - if (string.CompareOrdinal(lexeme, "WHILE") == 0) { - return Token.WHILE; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length 6 */ 6 : - switch (lexeme[2]) { - - case 'D' : - /* MODULE */ - if (string.CompareOrdinal(lexeme, "MODULE") == 0) { - return Token.MODULE; - } /* end if */ - break; - - case 'A' : - /* OPAQUE */ - if (string.CompareOrdinal(lexeme, "OPAQUE") == 0) { - return Token.OPAQUE; - } /* end if */ - break; - - case 'C' : - /* RECORD */ - if (string.CompareOrdinal(lexeme, "RECORD") == 0) { - return Token.RECORD; - } /* end if */ - break; - - case 'T' : - /* RETURN */ - if (string.CompareOrdinal(lexeme, "RETURN") == 0) { - return Token.RETURN; - } /* end if */ - break; - - case 'P' : - switch (lexeme[0]) { - - case 'E' : - /* EXPORT */ - if (string.CompareOrdinal(lexeme, "EXPORT") == 0) { - return Token.EXPORT; - } /* end if */ - break; - - case 'I' : - /* IMPORT */ - if (string.CompareOrdinal(lexeme, "IMPORT") == 0) { - return Token.IMPORT; - } /* end if */ - break; - - case 'R' : - /* REPEAT */ - if (string.CompareOrdinal(lexeme, "REPEAT") == 0) { - return Token.REPEAT; - } /* end if */ - break; - - } /* end switch */ - break; - - } /* end switch */ -break; - - case /* length = 7 */ 7 : - switch (lexeme[0]) { - - case 'A' : - /* ARGLIST */ - if (string.CompareOrdinal(lexeme, "ARGLIST") == 0) { - return Token.ARGLIST; - } /* end if */ - break; - - case 'P' : - /* POINTER */ - if (string.CompareOrdinal(lexeme, "POINTER") == 0) { - return Token.POINTER; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 9 */ 9 : - switch (lexeme[0]) { - - case 'P' : - /* PROCEDURE */ - if (string.CompareOrdinal(lexeme, "PROCEDURE") == 0) { - return Token.PROCEDURE; - } /* end if */ - break; - - case 'Q' : - /* QUALIFIED */ - if (string.CompareOrdinal(lexeme, "QUALIFIED") == 0) { - return Token.QUALIFIED; - } /* end if */ - break; - - } /* end switch */ - break; - - case /* length = 10 */ 10 : - /* DEFINITION */ - if (string.CompareOrdinal(lexeme, "DEFINITION") == 0) { - return Token.DEFINITION; - } /* end if */ - break; - - case /* length = 14 */ 14 : - /* IMPLEMENTATION */ - if (string.CompareOrdinal(lexeme, "IMPLEMENTATION") == 0) { - return Token.IMPLEMENTATION; - } /* end if */ - break; - - } /* end switch (length) */ - - return Token.Unknown; -} /* end TokenForResword */ - - -/* --------------------------------------------------------------------------- - * method LexemeForResword(token) - * --------------------------------------------------------------------------- - * Returns a string with the lexeme for the reserved word represented by - * token. Returns null if the token does not represent a reserved word. - * ------------------------------------------------------------------------ */ - -public static string LexemeForResword (Token token) { - if (IsResword(token) == false) { - return null; - } /* end if */ - return token.ToString(); -} /* end LexemeForResword */ - - -/* --------------------------------------------------------------------------- - * method LexemeForSpecialSymbol(token) - * --------------------------------------------------------------------------- - * Returns a string with the lexeme for the special symbol represented by - * token. Returns null if the token does not represent a special symbol. - * ------------------------------------------------------------------------ */ - -public static string LexemeForSpecialSymbol (Token token) { - if (IsSpecialSymbol(token) == false) { - return null; - } /* end if */ - return ""; // TO DO -} /* end LexemeForSpecialSymbol */ - - -/* --------------------------------------------------------------------------- - * method NameForToken(token) - * --------------------------------------------------------------------------- - * Returns a string with a human readable name for token. Returns null if - * token is not a valid token. - * ------------------------------------------------------------------------ */ - -public static string NameForToken (Token token) { - return token.ToString(); -} /* NameForToken */ - - -} /* Terminals */ - -} /* namespace */ - -/* END OF FILE */ \ No newline at end of file From 39198dd74e0ca00c3879bfa832c217a2860d9817 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Tue, 23 May 2017 14:04:43 -0700 Subject: [PATCH 18/24] Delete TokenSet.cs --- TokenSet.cs | 588 ---------------------------------------------------- 1 file changed, 588 deletions(-) delete mode 100644 TokenSet.cs diff --git a/TokenSet.cs b/TokenSet.cs deleted file mode 100644 index 1d84115..0000000 --- a/TokenSet.cs +++ /dev/null @@ -1,588 +0,0 @@ -/* M2Sharp -- Modula-2 to C# Translator & Compiler - * - * Copyright (c) 2016 The Modula-2 Software Foundation - * - * Author & Maintainer: Benjamin Kowarsch - * - * @synopsis - * - * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. - * It supports the dialects described in the 3rd and 4th editions of Niklaus - * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, - * and an extended mode with select features from the revised language by - * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). - * - * In translator mode, M2Sharp translates Modula-2 source to C# source files. - * In compiler mode, M2Sharp compiles Modula-2 source via C# source files - * to object code or executables using the host system's C# compiler. - * - * @repository - * - * https://github.com/m2sf/m2sharp - * - * @file - * - * TokenSet.cs - * - * A set of Token type variables which is used to pass First and Follow sets - * - * @license - * - * M2Sharp is free software: you can redistribute and/or modify it under the - * terms of the GNU Lesser General Public License (LGPL) either version 2.1 - * or at your choice version 3 as published by the Free Software Foundation. - * However, you may not alter the copyright, author and license information. - * - * M2Sharp is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with M2Sharp. If not, see . - * - * NB: Components in the domain part of email addresses are in reverse order. - */ - - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace org.m2sf.m2sharp -{ - - public class TokenSet : ITokenSet { - - /* Lexeme Table */ - public static string[] lexemeTable = { - /* Null Token */ - - "UNKNOWN", - - /* Reserved Words */ - - "AND", - "ARGLIST", - "ARRAY", - "BEGIN", - "BY", - "CASE", - "CONST", - "DEFINITION", - "DIV", - "DO", - "ELSE", - "ELSIF", - "END", - "EXIT", - "EXPORT", - "FOR", - "FROM", - "IF", - "IMPLEMENTATION", - "IMPORT", - "IN", - "LOOP", - "MOD", - "MODULE", - "NOT", - "OF", - "OR", - "POINTER", - "PROCEDURE", - "QUALIFIED", - "RECORD", - "REPEAT", - "RETURN", - "SET", - "THEN", - "TO", - "TYPE", - "UNTIL", - "VAR", - "WHILE", - "WITH", - - /* Identifiers */ - - "IDENTIFIER", - - /* Literals */ - - "STRING-LITERAL", - "INTEGER-LITERAL", - "REAL-LITERAL", - "CHAR-LITERAL", - - "MALFORMED-STRING", - "MALFORMED-INTEGER", - "MALFORMED-REAL", - - /* Pragmas */ - - "PRAGMA", - - /* Special Symbols */ - - "PLUS", - "MINUS", - "EQUAL", - "NOTEQUAL", - "LESS-THAN", - "LESS-OR-EQUAL", - "GREATER-THAN", - "GREATER-OR-EQUAL", - "ASTERISK", - "SOLIDUS", - "BACKSLASH", - "ASSIGNMENT", - "COMMA", - "PERIOD", - "COLON", - "SEMICOLON", - "RANGE", - "DEREF", - "VERTICAL-BAR", - "LEFT-PAREN", - "RIGHT-PAREN", - "LEFT-BRACKET", - "RIGHT-BRACKET", - "LEFT-BRACE", - "RIGHT-BRACE", - "END-OF-FILE" - -}; /* end m2c_token_name_table */ - - public static const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; - - public struct TokenSetBits - { - public uint[] segments = new uint[segmentCount]; - public uint elemCount; - } /* end struct */ - - TokenSetBits dataStored; - - /* --------------------------------------------------------------------------- - * private constructor TokenSet () - * --------------------------------------------------------------------------- - * Prevents clients from invoking the default constructor. - * ------------------------------------------------------------------------ */ - - private TokenSet() - { - // no operation - } /* end TokenSet */ - - /* --------------------------------------------------------------------------- - * private constructor TokenSet (uint[]) - * --------------------------------------------------------------------------- - * used to instantiate the prefabricated first and follow lists - * ------------------------------------------------------------------------ */ - - public TokenSet(params uint[] TSB) - { - dataStored.segments[0] = TSB[0]; - dataStored.segments[1] = TSB[1]; - dataStored.segments[2] = TSB[2]; - dataStored.elemCount = TSB[3]; - } - - /* -------------------------------------------------------------------------- - * constructor newFromList(token, ...) - * -------------------------------------------------------------------------- - * Returns a newly allocated tokenset object that includes the tokens passed - * as arguments of a variadic argument list. - * ----------------------------------------------------------------------- */ - - public static TokenSet newFromList(params Token[] tokenList) - { - TokenSet newSet = new TokenSet(); - uint bit, segmentIndex; - Token token; - - /* allocate new set */ - newSet.dataStored.segments = new uint[segmentCount]; - - /* initialise */ - for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - newSet.dataStored.segments[segmentIndex] = 0; - } /* end For */ - - /* store tokens from list */ - token = tokenList[0]; - for (int i = 1; token != Token.Unknown; i++) - { - - if (token <= Token.EndOfFile) - { - segmentIndex = (uint)token / 32; - bit = (uint)token % 32; - newSet.dataStored.segments[segmentIndex] = (newSet.dataStored.segments[segmentIndex] | (uint)(1 << (int)bit)); - } /* end if */ - - /* get next token in list */ - token = tokenList[i]; - } /* end while */ - - /* update element counter */ - newSet.dataStored.elemCount = CountBits(newSet); - - return newSet; - } /* end newFromList */ - - - /* -------------------------------------------------------------------------- - * constructor newFromUnion(set, ...) - * -------------------------------------------------------------------------- - * Returns a newly allocated tokenset object that represents the set union of - * the tokensets passed as arguments of a non-empty variadic argument list. - * ----------------------------------------------------------------------- */ - - public static TokenSet newFromUnion(params TokenSet[] setList) - { - uint segmentIndex; - TokenSet set, - newSet = new TokenSet(); - - - /* initialise */ - newSet.dataStored.segments = new uint[segmentCount]; - for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - newSet.dataStored.segments[segmentIndex] = 0; - } /* end for */ - - set = setList[0]; - /* calculate union with each set in list */ - for (int i = 0; set != null; i++) - { - /* for each segment ... */ - while (segmentIndex < segmentCount) - { - /* ... store union of corresponding segments */ - newSet.dataStored.segments[segmentIndex] = - newSet.dataStored.segments[segmentIndex] | newSet.dataStored.segments[segmentIndex]; - - /* next segment */ - segmentIndex++; - } /* end while */ - - /*get next set in list */ - if (i < setList.Length) - set = setList[i]; - else - set = null; - - } /* end for */ - - /* update element counter */ - newSet.dataStored.elemCount = CountBits(newSet); - - return newSet; - } /* end newFromUnion - -/* -------------------------------------------------------------------------- - * method Count() - * -------------------------------------------------------------------------- - * Returns the number of elements in the receiver. - * ----------------------------------------------------------------------- */ - - public uint Count() - { - - return this.dataStored.elemCount; - } /* end IsElement */ - - - /* -------------------------------------------------------------------------- - * method IsElement(token) - * -------------------------------------------------------------------------- - * Returns true if token is an element of the receiver, else false. - * ----------------------------------------------------------------------- */ - - public bool IsElement(Token token) - { - int segmentIndex, bit; - - if (token > Token.EndOfFile) - { - return false; - } /* end if */ - - segmentIndex = (int)token / 32; - bit = (int)token % 32; - - return (this.dataStored.segments[segmentIndex] & (1 << bit)) != 0; - } /* end IsElement */ - - - /* -------------------------------------------------------------------------- - * method IsSubset(set) - * -------------------------------------------------------------------------- - * Returns true if each element in set is also in the receiver, else false. - * ----------------------------------------------------------------------- */ - - public bool IsSubset(TokenSet set) - { - - for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - - if (((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) - ^ this.dataStored.segments[segmentIndex]) != 0) - { - - return false; - - } /* end if */ - - } /* end for */ - - return true; - - } /* end IsSubset */ - - - /* -------------------------------------------------------------------------- - * method IsDisjunct(set) - * -------------------------------------------------------------------------- - * Returns true if set has no common elements with the receiver, else false. - * ----------------------------------------------------------------------- */ - - public bool IsDisjunct(TokenSet set) - { - - for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - - if ((set.dataStored.segments[segmentIndex] & this.dataStored.segments[segmentIndex]) != 0) - { - - return false; - - } /* end if */ - - } /* end for */ - - return true; - - } /* end IsDisjunct */ - - /* -------------------------------------------------------------------------- - * method ElementList() - * -------------------------------------------------------------------------- - * Returns a token list of all elements in the receiver. - * ----------------------------------------------------------------------- */ - //TODO - - public List ElementList() - { - List allElements = new List(); - uint segmentIndex, count; - int bit; - Token token; - - if (this.dataStored.elemCount == 0) - { - return null; - } /* end if */ - - token = 0; - count = 0; - - while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) - { - segmentIndex = (uint)token / 32; - bit = (int)token % 32; - - if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) - { - count++; - allElements.Add(token); - } /* end if */ - token++; - } /* end while */ - - return allElements; - - } /* end ElementList */ - - - /* -------------------------------------------------------------------------- - * method PrintSet(label) - * -------------------------------------------------------------------------- - * Prints a human readable representation of the receiver. - * Format: label = { comma-separated list of tokens }; - * ----------------------------------------------------------------------- */ - - public void PrintSet(string label) - { - uint segmentIndex, count; - int bit; - Token token; - - Console.Write(label + " = {"); - if (this.dataStored.elemCount == 0) - { - Console.Write(" "); - } /* end if */ - - token = 0; - count = 0; - - while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) - { - segmentIndex = (uint)token / 32; - bit = (int)token % 32; - - if (((this.dataStored.segments[segmentIndex]) & (1 << (int)bit)) != 0) - { - count++; - - if (count <= this.dataStored.elemCount) - { - - Console.Write("\n {0},", lexemeTable[(uint)token]); - } - else - { - Console.WriteLine("\n {0}", lexemeTable[(uint)token]); - } /* end if */ - } /* end if */ - token++; - } /* end while */ - - Console.WriteLine("};"); - } /* end PrintSet */ - - - /* -------------------------------------------------------------------------- - * method PrintList() - * -------------------------------------------------------------------------- - * Prints a human readable list of tokens in the receiver. - * Format: first, second, third, ..., secondToLast or last - * ----------------------------------------------------------------------- */ - - public void PrintList() - { - uint bit, segmentIndex, count; - Token token; - - if (this.dataStored.elemCount == 0) - { - Console.WriteLine("(nil)"); - } - - count = 0; - token = 0; - while ((count <= this.dataStored.elemCount) && (token <= Token.EndOfFile)) - { - segmentIndex = (uint)token / 32; - bit = (uint)token % 32; - - if (((this.dataStored.segments[segmentIndex] & (1 << (int)bit)) != 0)) - { - count++; - if (count > 1) - { - if (count <= this.dataStored.elemCount) - { - Console.Write(", "); - } - else - { - Console.Write(" or "); - } /* end if */ - } /* end if */ - - Console.Write(lexemeTable[(uint)token]); - } - token++; - } - - Console.WriteLine("."); - } /* end PrintList */ - - - /* -------------------------------------------------------------------------- - * method PrintLiteralStruct(ident) - * -------------------------------------------------------------------------- - * Prints a struct definition for a tokenset literal for the receiver. - * Format: struct ident { uint s0; uint s1; uint s2; ...; uint n }; - * ----------------------------------------------------------------------- */ - - public void PrintLiteralStruct(string ident) - { - uint segmentIndex; - - Console.Write("struct {0} {{ uint s0", ident); - - for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) - { - Console.Write("; s" + segmentIndex); - } /* end for */ - - Console.WriteLine("; n };"); - Console.WriteLine("typedef struct {0} {0};", ident); - - } /* end PrintLiteralStruct */ - - - /* -------------------------------------------------------------------------- - * method PrintLiteral() - * -------------------------------------------------------------------------- - * Prints a sequence of hex values representing the bit pattern of receiver. - * Format: ( 0xHHHHHHHH, 0xHHHHHHHH, ..., count ); - * ----------------------------------------------------------------------- */ - - public void PrintLiteral() - { - uint segmentIndex; - - Console.Write("( /* bits: */ 0x" + this.dataStored.segments[0].ToString("x08")); - - for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) - { - - Console.Write(", 0x" + this.dataStored.segments[segmentIndex].ToString("x08")); - } /* end for */ - - Console.WriteLine(", /* counter: */ " + this.dataStored.elemCount + " );"); - } /* end PrintLiteral */ - - /* -------------------------------------------------------------------------- - * method CountBits() - * -------------------------------------------------------------------------- - * Returns the number of set bits in set. - * ----------------------------------------------------------------------- */ - - static private uint CountBits(TokenSet set) - { - int bit; - uint segmentIndex, - bitCount = 0; - - for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) - { - - for (bit = 0; bit < 32; bit++) - { - - if ((set.dataStored.segments[segmentIndex] & (1 << bit)) != 0) - { - bitCount++; - } /* end if */ - - } /* end for */ - - } /* end for */ - - return bitCount; - } /* end CountBits */ - - } /* end TokenSet */ - -} /* end namespace */ From e04144b34a2683a3e93cff4ddc0f3896c51cacab Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Wed, 24 May 2017 18:55:37 -0700 Subject: [PATCH 19/24] Add files via upload --- imp/NonTerminals.cs | 288 ++++++++++++++++++++++---------------------- imp/TokenSet.cs | 38 ++++-- 2 files changed, 172 insertions(+), 154 deletions(-) diff --git a/imp/NonTerminals.cs b/imp/NonTerminals.cs index 3620d28..8ac690f 100644 --- a/imp/NonTerminals.cs +++ b/imp/NonTerminals.cs @@ -61,298 +61,298 @@ public class NonTerminals : INonTerminals { #region followSets TokenSet[] followSets = { - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* definitionModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* definitionModule */ - new TokenSet( /* bits: */ 0x108050C8, 0x00000050, 0x00000000, /* counter: */ 9 ), /* import */ + TokenSet.newFromRawData( /* bits: */ 0x108050C8, 0x00000050, 0x00000000, /* counter: */ 9 ), /* import */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* qualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* qualifiedImport */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* unqualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* unqualifiedImport */ - new TokenSet( /* bits: */ 0x00000000, 0x80000000, 0x00000021, /* counter: */ 3 ), /* identList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000021, /* counter: */ 3 ), /* identList */ - new TokenSet( /* bits: */ 0x00001000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ + TokenSet.newFromRawData( /* bits: */ 0x00001000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* constDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* constDefinition */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDefinition */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* type */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* type */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* derivedOrSubrangeType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* derivedOrSubrangeType */ - new TokenSet( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000037B, /* counter: */ 34 ), /* qualident */ + TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000037B, /* counter: */ 34 ), /* qualident */ - new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* range */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* range */ - new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* enumType */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* enumType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* setType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* setType */ - new TokenSet( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* countableType */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* countableType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* arrayType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* arrayType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* extensibleRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* extensibleRecordType */ - new TokenSet( /* bits: */ 0x00001000, 0x00000040, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00001000, 0x00000040, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variantRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variantRecordType */ - new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variantFieldListSeq */ + TokenSet.newFromRawData( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variantFieldListSeq */ - new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFieldList */ + TokenSet.newFromRawData( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFieldList */ - new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFields */ + TokenSet.newFromRawData( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFields */ - new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variant */ + TokenSet.newFromRawData( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variant */ - new TokenSet( /* bits: */ 0x00000000, 0x80000000, 0x00000000, /* counter: */ 1 ), /* caseLabelList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000000, /* counter: */ 1 ), /* caseLabelList */ - new TokenSet( /* bits: */ 0x00000000, 0xA0000000, 0x00000000, /* counter: */ 2 ), /* caseLabels */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0xA0000000, 0x00000000, /* counter: */ 2 ), /* caseLabels */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* pointerType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* pointerType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureType */ - new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* simpleFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* simpleFormalType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureHeader */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureHeader */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureSignature */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureSignature */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* simpleFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* simpleFormalParams */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* implementationModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* implementationModule */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* programModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* programModule */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* modulePriority */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* modulePriority */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* block */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* block */ - new TokenSet( /* bits: */ 0x00001008, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ + TokenSet.newFromRawData( /* bits: */ 0x00001008, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclaration */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* varSizeRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* varSizeRecordType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variableDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variableDeclaration */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureDeclaration */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* moduleDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* moduleDeclaration */ - new TokenSet( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* export */ + TokenSet.newFromRawData( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* export */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000008, /* counter: */ 5 ), /* statementSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000008, /* counter: */ 5 ), /* statementSequence */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* statement */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* statement */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* assignmentOrProcCall */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* assignmentOrProcCall */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* actualParameters */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* actualParameters */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* expressionList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* expressionList */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* returnStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* returnStatement */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* withStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* withStatement */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* ifStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* ifStatement */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* caseStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* caseStatement */ - new TokenSet( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* case */ + TokenSet.newFromRawData( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* case */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* loopStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* loopStatement */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* whileStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* whileStatement */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* repeatStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* repeatStatement */ - new TokenSet( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* forStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* forStatement */ - new TokenSet( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000033B, /* counter: */ 33 ), /* designator */ + TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000033B, /* counter: */ 33 ), /* designator */ - new TokenSet( /* bits: */ 0x06501F12, 0x3FFC022C, 0x0000033B, /* counter: */ 34 ), /* selector */ + TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x3FFC022C, 0x0000033B, /* counter: */ 34 ), /* selector */ - new TokenSet( /* bits: */ 0x02001E10, 0x2000002C, 0x0000022B, /* counter: */ 15 ), /* expression */ + TokenSet.newFromRawData( /* bits: */ 0x02001E10, 0x2000002C, 0x0000022B, /* counter: */ 15 ), /* expression */ - new TokenSet( /* bits: */ 0x02101E10, 0x23F0002C, 0x0000022B, /* counter: */ 22 ), /* simpleExpression */ + TokenSet.newFromRawData( /* bits: */ 0x02101E10, 0x23F0002C, 0x0000022B, /* counter: */ 22 ), /* simpleExpression */ - new TokenSet( /* bits: */ 0x06101E10, 0x23FC002C, 0x0000022B, /* counter: */ 25 ), /* term */ + TokenSet.newFromRawData( /* bits: */ 0x06101E10, 0x23FC002C, 0x0000022B, /* counter: */ 25 ), /* term */ - new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* simpleTerm */ + TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* simpleTerm */ - new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* factor */ + TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* factor */ - new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* designatorOrFuncCall */ + TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* designatorOrFuncCall */ - new TokenSet( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* setValue */ + TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* setValue */ - new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000200, /* counter: */ 2 ), /* element */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x20000000, 0x00000200, /* counter: */ 2 ), /* element */ - new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* formalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* formalType */ - new TokenSet( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* attributedFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* attributedFormalType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* formalParamList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* formalParamList */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* formalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* formalParams */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* attribFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* attribFormalParams */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclarationTail */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclarationTail */ }; #endregion #region firstSets TokenSet[] firstSets = { - new TokenSet( /* bits: */ 0x00000080, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000100, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ - new TokenSet( /* bits: */ 0x00090000, 0x00000000, 0x00000000, /* counter: */ 2 ), /* import */ + TokenSet.newFromRawData( /* bits: */ 0x00120000, 0x00000000, 0x00000000, /* counter: */ 2 ), /* import */ - new TokenSet( /* bits: */ 0x00080000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* qualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00100000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* qualifiedImport */ - new TokenSet( /* bits: */ 0x00010000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* unqualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00020000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* unqualifiedImport */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* identList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* identList */ - new TokenSet( /* bits: */ 0x10000040, 0x00000050, 0x00000000, /* counter: */ 4 ), /* definition */ + TokenSet.newFromRawData( /* bits: */ 0x20000080, 0x000000a0, 0x00000000, /* counter: */ 4 ), /* definition */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* constDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* constDefinition */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* typeDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* typeDefinition */ - new TokenSet( /* bits: */ 0x58000004, 0x00000202, 0x00000050, /* counter: */ 8 ), /* type */ + TokenSet.newFromRawData( /* bits: */ 0xb0000008, 0x00000404, 0x00000140, /* counter: */ 8 ), /* type */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000040, /* counter: */ 2 ), /* derivedOrSubrangeType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000100, /* counter: */ 2 ), /* derivedOrSubrangeType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* qualident */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* qualident */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* range */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* range */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000010, /* counter: */ 1 ), /* enumType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* enumType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000002, 0x00000000, /* counter: */ 1 ), /* setType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000004, 0x00000000, /* counter: */ 1 ), /* setType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000050, /* counter: */ 3 ), /* countableType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000140, /* counter: */ 3 ), /* countableType */ - new TokenSet( /* bits: */ 0x00000004, 0x00000000, 0x00000000, /* counter: */ 1 ), /* arrayType */ + TokenSet.newFromRawData( /* bits: */ 0x00000008, 0x00000000, 0x00000000, /* counter: */ 1 ), /* arrayType */ - new TokenSet( /* bits: */ 0x40000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* extensibleRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* extensibleRecordType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* fieldListSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* fieldListSequence */ - new TokenSet( /* bits: */ 0x40000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantRecordType */ - new TokenSet( /* bits: */ 0x00000020, 0x00000200, 0x00000000, /* counter: */ 2 ), /* variantFieldListSeq */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000400, 0x00000000, /* counter: */ 2 ), /* variantFieldListSeq */ - new TokenSet( /* bits: */ 0x00000020, 0x00000200, 0x00000000, /* counter: */ 2 ), /* variantFieldList */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000400, 0x00000000, /* counter: */ 2 ), /* variantFieldList */ - new TokenSet( /* bits: */ 0x00000020, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantFields */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantFields */ - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* variant */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* variant */ - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* caseLabelList */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* caseLabelList */ - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* caseLabels */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* caseLabels */ - new TokenSet( /* bits: */ 0x08000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* pointerType */ + TokenSet.newFromRawData( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* pointerType */ - new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureType */ + TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureType */ - new TokenSet( /* bits: */ 0x00000004, 0x00000200, 0x00000000, /* counter: */ 2 ), /* simpleFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000008, 0x00000400, 0x00000000, /* counter: */ 2 ), /* simpleFormalType */ - new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureHeader */ + TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureHeader */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* procedureSignature */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* procedureSignature */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* simpleFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* simpleFormalParams */ - new TokenSet( /* bits: */ 0x00040000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* implementationModule */ + TokenSet.newFromRawData( /* bits: */ 0x00080000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* implementationModule */ - new TokenSet( /* bits: */ 0x00800000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* programModule */ + TokenSet.newFromRawData( /* bits: */ 0x01000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* programModule */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* modulePriority */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* modulePriority */ - new TokenSet( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* block */ + TokenSet.newFromRawData( /* bits: */ 0x21002090, 0x000000a0, 0x00000000, /* counter: */ 7 ), /* block */ - new TokenSet( /* bits: */ 0x10800040, 0x00000050, 0x00000000, /* counter: */ 5 ), /* declaration */ + TokenSet.newFromRawData( /* bits: */ 0x21000080, 0x000000a0, 0x00000000, /* counter: */ 5 ), /* declaration */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* typeDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* typeDeclaration */ - new TokenSet( /* bits: */ 0x00000000, 0x00000040, 0x00000000, /* counter: */ 1 ), /* varSizeRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000080, 0x00000000, /* counter: */ 1 ), /* varSizeRecordType */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* variableDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* variableDeclaration */ - new TokenSet( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureDeclaration */ - new TokenSet( /* bits: */ 0x00800000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* moduleDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x01000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* moduleDeclaration */ - new TokenSet( /* bits: */ 0x00004000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* export */ + TokenSet.newFromRawData( /* bits: */ 0x00008000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* export */ - new TokenSet( /* bits: */ 0x8022A020, 0x00000381, 0x00000000, /* counter: */ 10 ), /* statementSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00454040, 0x00000703, 0x00000000, /* counter: */ 10 ), /* statementSequence */ - new TokenSet( /* bits: */ 0x8022A020, 0x00000381, 0x00000000, /* counter: */ 10 ), /* statement */ + TokenSet.newFromRawData( /* bits: */ 0x00454040, 0x00000703, 0x00000000, /* counter: */ 10 ), /* statement */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* assignmentOrProcCall */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* assignmentOrProcCall */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000010, /* counter: */ 1 ), /* actualParameters */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* actualParameters */ - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* expressionList */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* expressionList */ - new TokenSet( /* bits: */ 0x00000000, 0x00000001, 0x00000000, /* counter: */ 1 ), /* returnStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000002, 0x00000000, /* counter: */ 1 ), /* returnStatement */ - new TokenSet( /* bits: */ 0x00000000, 0x00000100, 0x00000000, /* counter: */ 1 ), /* withStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* withStatement */ - new TokenSet( /* bits: */ 0x00020000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* ifStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00040000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* ifStatement */ - new TokenSet( /* bits: */ 0x00000020, 0x00000000, 0x00000000, /* counter: */ 1 ), /* caseStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000000, 0x00000000, /* counter: */ 1 ), /* caseStatement */ - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* case */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* case */ - new TokenSet( /* bits: */ 0x00200000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* loopStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00400000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* loopStatement */ - new TokenSet( /* bits: */ 0x00000000, 0x00000080, 0x00000000, /* counter: */ 1 ), /* whileStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000100, 0x00000000, /* counter: */ 1 ), /* whileStatement */ - new TokenSet( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* repeatStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000001, 0x00000000, /* counter: */ 1 ), /* repeatStatement */ - new TokenSet( /* bits: */ 0x00008000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* forStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00010000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* forStatement */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* designator */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* designator */ - new TokenSet( /* bits: */ 0x00000000, 0x40000000, 0x00000044, /* counter: */ 3 ), /* selector */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000111, /* counter: */ 3 ), /* selector */ - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* expression */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* expression */ - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* simpleExpression */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* simpleExpression */ - new TokenSet( /* bits: */ 0x01000000, 0x00003E00, 0x00000110, /* counter: */ 8 ), /* term */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00007c00, 0x00000440, /* counter: */ 8 ), /* term */ - new TokenSet( /* bits: */ 0x01000000, 0x00003E00, 0x00000110, /* counter: */ 8 ), /* simpleTerm */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00007c00, 0x00000440, /* counter: */ 8 ), /* simpleTerm */ - new TokenSet( /* bits: */ 0x00000000, 0x00003E00, 0x00000110, /* counter: */ 7 ), /* factor */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00007c00, 0x00000440, /* counter: */ 7 ), /* factor */ - new TokenSet( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* designatorOrFuncCall */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* designatorOrFuncCall */ - new TokenSet( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* setValue */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* setValue */ - new TokenSet( /* bits: */ 0x01000000, 0x000C3E00, 0x00000110, /* counter: */ 10 ), /* element */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* element */ - new TokenSet( /* bits: */ 0x00000044, 0x00000240, 0x00000000, /* counter: */ 4 ), /* formalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000088, 0x00000480, 0x00000000, /* counter: */ 4 ), /* formalType */ - new TokenSet( /* bits: */ 0x00000040, 0x00000040, 0x00000000, /* counter: */ 2 ), /* attributedFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000080, 0x00000000, /* counter: */ 2 ), /* attributedFormalType */ - new TokenSet( /* bits: */ 0x00000040, 0x00000240, 0x00000000, /* counter: */ 3 ), /* formalParamList */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000480, 0x00000000, /* counter: */ 3 ), /* formalParamList */ - new TokenSet( /* bits: */ 0x00000040, 0x00000240, 0x00000000, /* counter: */ 3 ), /* formalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000480, 0x00000000, /* counter: */ 3 ), /* formalParams */ - new TokenSet( /* bits: */ 0x00000040, 0x00000040, 0x00000000, /* counter: */ 2 ), /* attribFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000080, 0x00000000, /* counter: */ 2 ), /* attribFormalParams */ - new TokenSet( /* bits: */ 0x58000004, 0x00000242, 0x00000050, /* counter: */ 9 ), /* typeDeclarationTail */ + TokenSet.newFromRawData( /* bits: */ 0xb0000008, 0x00000484, 0x00000140, /* counter: */ 9 ), /* typeDeclarationTail */ }; #endregion diff --git a/imp/TokenSet.cs b/imp/TokenSet.cs index 1d84115..f047590 100644 --- a/imp/TokenSet.cs +++ b/imp/TokenSet.cs @@ -154,7 +154,7 @@ public class TokenSet : ITokenSet { }; /* end m2c_token_name_table */ - public static const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; + public const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; public struct TokenSetBits { @@ -176,18 +176,36 @@ private TokenSet() } /* end TokenSet */ /* --------------------------------------------------------------------------- - * private constructor TokenSet (uint[]) - * --------------------------------------------------------------------------- - * used to instantiate the prefabricated first and follow lists + * private TokenSet newFromRawData(uint[]) + * --------------------------------------------------------------------------- + * Used to instantiate the prefabricated first and follow lists. + * Expects TSB[segmentCount] to be the number of tokens, and returns null if + * the count does not match. * ------------------------------------------------------------------------ */ - public TokenSet(params uint[] TSB) + public static TokenSet newFromRawData(params uint[] TSB) { - dataStored.segments[0] = TSB[0]; - dataStored.segments[1] = TSB[1]; - dataStored.segments[2] = TSB[2]; - dataStored.elemCount = TSB[3]; - } + TokenSet newSet = new TokenSet(); + uint counter = 0; + + for (int i = 0; i < segmentCount; i++) { + + for (int j = 0; j < 32; j++) { + if ((TSB[i] & (1 << j)) == (1 << j)) + counter++; + } /* end for */ + + newSet.dataStored.segments[i] = TSB[i]; + } /* end for */ + + if (counter != TSB[segmentCount]) { + return null; + } /* end if */ + + newSet.dataStored.elemCount = TSB[segmentCount]; + + return newSet; + } /* end newFromData */ /* -------------------------------------------------------------------------- * constructor newFromList(token, ...) From 26f5b850a76c7b43c1e5ce761c694bd8271b5de4 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Fri, 26 May 2017 17:43:20 -0700 Subject: [PATCH 20/24] Add files via upload --- utils/GenFirstSets.cs | 672 +++++++++++++++++++++++++++++++++++++ utils/GenFollowSets.cs | 740 +++++++++++++++++++++++++++++++++++++++++ utils/GenResyncSets.cs | 286 ++++++++++++++++ 3 files changed, 1698 insertions(+) create mode 100644 utils/GenFirstSets.cs create mode 100644 utils/GenFollowSets.cs create mode 100644 utils/GenResyncSets.cs diff --git a/utils/GenFirstSets.cs b/utils/GenFirstSets.cs new file mode 100644 index 0000000..24a2403 --- /dev/null +++ b/utils/GenFirstSets.cs @@ -0,0 +1,672 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * GenFirstSets.cs + * + * A class dedicated to producing representations of the first sets used by the parser. + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace org.m2sf.m2sharp { + + class GenFirstSets { + + public static List genSets() { + + List lines = new List(); + TokenSet set; + + /* * * headline * * */ + + lines.Add("/* M2sharp FIRST set initialisers" + + " -- generated by GenFirstSets.cs */\n\n"); + + /* definitionModule */ + set = TokenSet.newFromList(Token.DEFINITION, 0); + lines.Add("Creating First Set for: DEFINITION MODULE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* import */ + set = TokenSet.newFromList(Token.IMPORT, Token.FROM, 0); + lines.Add("Creating First Set for: IMPORT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* qualfiedImport */ + set = TokenSet.newFromList(Token.IMPORT, 0); + lines.Add("Creating First Set for: QUALIFIED IMPORT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* unqualfiedImport */ + set = TokenSet.newFromList(Token.FROM, 0); + lines.Add("Creating First Set for: UNQUALIFIED IMPORT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* identList */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: IDENT LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* definition */ + set = TokenSet.newFromList + (Token.CONST, Token.TYPE, Token.VAR, Token.PROCEDURE, 0); + lines.Add("Creating First Set for: DEFINITION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* constDefinition */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: CONST DEFINITION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* typeDefinition */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: TYPE DEFINITION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* type */ + set = TokenSet.newFromList + (Token.Identifier, Token.LeftBracket, Token.LeftParen, + Token.SET, Token.ARRAY, Token.RECORD, Token.POINTER, Token.PROCEDURE, 0); + lines.Add("Creating First Set for: TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* derivedOrSubRangeType */ + set = TokenSet.newFromList(Token.Identifier, Token.LeftBracket, 0); + lines.Add("Creating First Set for: DERIVED OR SUBRange TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* qualident */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: QUALIDENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Range */ + set = TokenSet.newFromList(Token.LeftBracket, 0); + lines.Add("Creating First Set for: Range \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* enumType */ + set = TokenSet.newFromList(Token.LeftParen, 0); + lines.Add("Creating First Set for: ENUM TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* setType */ + set = TokenSet.newFromList(Token.SET, 0); + lines.Add("Creating First Set for: SET TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* countableType */ + set = TokenSet.newFromList + (Token.LeftBracket, Token.LeftParen, Token.Identifier, 0); + lines.Add("Creating First Set for: COUNTABLE TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* arrayType */ + set = TokenSet.newFromList(Token.ARRAY, 0); + lines.Add("Creating First Set for: ARRAY TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* extensibleRecordType */ + set = TokenSet.newFromList(Token.RECORD, 0); + lines.Add("Creating First Set for: EXTENSIBLE RECORD TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* fieldListSequence */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: FIELD LIST SEQUENCE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variantRecordType */ + set = TokenSet.newFromList(Token.RECORD, 0); + lines.Add("Creating First Set for: VARIANT RECORD TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variantFieldListSeq */ + set = TokenSet.newFromList(Token.Identifier, Token.CASE, 0); + lines.Add("Creating First Set for: VARIANT FIELD LIST SEQ \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variantFieldList */ + set = TokenSet.newFromList(Token.Identifier, Token.CASE, 0); + lines.Add("Creating First Set for: VARIANT FIELD LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variantFields */ + set = TokenSet.newFromList(Token.CASE, 0); + lines.Add("Creating First Set for: VARIANT FIELDS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variant */ + set = TokenSet.newFromList + (Token.Plus, Token.Minus, Token.NOT, Token.IntLiteral, Token.RealLiteral, + Token.CharLiteral, Token.StringLiteral, Token.LeftBrace, Token.LeftParen, + Token.Identifier, 0); + lines.Add("Creating First Set for: VARIANT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* caseLabelList */ + set = TokenSet.newFromList + (Token.Plus, Token.Minus, Token.NOT, Token.IntLiteral, Token.RealLiteral, + Token.CharLiteral, Token.StringLiteral, Token.LeftBrace, Token.LeftParen, + Token.Identifier, 0); + lines.Add("Creating First Set for: CASE LABEL LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* caseLabels */ + set = TokenSet.newFromList + (Token.Plus, Token.Minus, Token.NOT, Token.IntLiteral, Token.RealLiteral, + Token.CharLiteral, Token.StringLiteral, Token.LeftBrace, Token.LeftParen, + Token.Identifier, 0); + lines.Add("Creating First Set for: CASE LABELS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* pointerType */ + set = TokenSet.newFromList(Token.POINTER, 0); + lines.Add("Creating First Set for: POINTER TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* procedureType */ + set = TokenSet.newFromList(Token.PROCEDURE, 0); + lines.Add("Creating First Set for: PROCEDURE TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* simpleFormalType */ + set = TokenSet.newFromList(Token.ARRAY, Token.Identifier, 0); + lines.Add("Creating First Set for: SIMPLE FORMAL TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* procedureHeader */ + set = TokenSet.newFromList(Token.PROCEDURE, 0); + lines.Add("Creating First Set for: PROCEDURE HEADER \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* procedureSignature */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: PROCEDURE SIGNATURE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* simpleFormalParams */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: SIMPLE FORMAL PARAMS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* implementationModule */ + set = TokenSet.newFromList(Token.IMPLEMENTATION, 0); + lines.Add("Creating First Set for: IMPLEMENTATION MODULE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* programModule */ + set = TokenSet.newFromList(Token.MODULE, 0); + lines.Add("Creating First Set for: PROGRAM MODULE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* modulePriority */ + set = TokenSet.newFromList(Token.LeftBracket, 0); + lines.Add("Creating First Set for: MODULE PRIORITY \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* block */ + set = TokenSet.newFromList + (Token.CONST, Token.TYPE, Token.VAR, Token.PROCEDURE, Token.MODULE, + Token.BEGIN, Token.END, 0); + lines.Add("Creating First Set for: BLOCK \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* declaration */ + set = TokenSet.newFromList + (Token.CONST, Token.TYPE, Token.VAR, Token.PROCEDURE, Token.MODULE, 0); + lines.Add("Creating First Set for: DECLARATION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* typeDeclaration */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: TYPE DECLARATION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* varSizeRecordType */ + set = TokenSet.newFromList(Token.VAR, 0); + lines.Add("Creating First Set for: VAR SIZE RECORD TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variableDeclaration */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: VARIABLE DECLARATION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* procedureDeclaration */ + set = TokenSet.newFromList(Token.PROCEDURE, 0); + lines.Add("Creating First Set for: PROCEDURE DECLARATION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* moduleDeclaration */ + set = TokenSet.newFromList(Token.MODULE, 0); + lines.Add("Creating First Set for: MODULE DECLARATION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* export */ + set = TokenSet.newFromList(Token.EXPORT, 0); + lines.Add("Creating First Set for: EXPORT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* statementSequence */ + set = TokenSet.newFromList + (Token.Identifier, Token.RETURN, Token.WITH, Token.IF, Token.CASE, + Token.LOOP, Token.WHILE, Token.REPEAT, Token.FOR, Token.EXIT, 0); + lines.Add("Creating First Set for: STATEMENT SEQUENCE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* statement */ + set = TokenSet.newFromList + (Token.Identifier, Token.RETURN, Token.WITH, Token.IF, Token.CASE, + Token.LOOP, Token.WHILE, Token.REPEAT, Token.FOR, Token.EXIT, 0); + lines.Add("Creating First Set for: STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* AssignmentOrProcCall */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: AssignMENT OR PROC CALL \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* actualParameters */ + set = TokenSet.newFromList(Token.LeftParen, 0); + lines.Add("Creating First Set for: ACTUAL PARAMETERS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* expressionList */ + set = TokenSet.newFromList + (Token.Plus, Token.Minus, Token.NOT, Token.IntLiteral, Token.RealLiteral, + Token.CharLiteral, Token.StringLiteral, Token.LeftBrace, Token.LeftParen, + Token.Identifier, 0); + lines.Add("Creating First Set for: EXPRESSION LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* returnStatement */ + set = TokenSet.newFromList(Token.RETURN, 0); + lines.Add("Creating First Set for: RETURN STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* withStatement */ + set = TokenSet.newFromList(Token.WITH, 0); + lines.Add("Creating First Set for: WITH STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* ifStatement */ + set = TokenSet.newFromList(Token.IF, 0); + lines.Add("Creating First Set for: IF STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* caseStatement */ + set = TokenSet.newFromList(Token.CASE, 0); + lines.Add("Creating First Set for: CASE STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* case */ + set = TokenSet.newFromList + (Token.Plus, Token.Minus, Token.NOT, Token.IntLiteral, Token.RealLiteral, + Token.CharLiteral, Token.StringLiteral, Token.LeftBrace, Token.LeftParen, + Token.Identifier, 0); + lines.Add("Creating First Set for: CASE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* loopStatement */ + set = TokenSet.newFromList(Token.LOOP, 0); + lines.Add("Creating First Set for: LOOP STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* whileStatement */ + set = TokenSet.newFromList(Token.WHILE, 0); + lines.Add("Creating First Set for: WHILE STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* repeatStatement */ + set = TokenSet.newFromList(Token.REPEAT, 0); + lines.Add("Creating First Set for: REPEAT STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* forStatement */ + set = TokenSet.newFromList(Token.FOR, 0); + lines.Add("Creating First Set for: FOR STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* designator */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: DESIGNATOR \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* selector */ + set = TokenSet.newFromList + (Token.Deref, Token.Period, Token.LeftBracket, 0); + lines.Add("Creating First Set for: SELECTOR \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* expression */ + set = TokenSet.newFromList + (Token.Plus, Token.Minus, Token.NOT, Token.IntLiteral, Token.RealLiteral, + Token.CharLiteral, Token.StringLiteral, Token.LeftBrace, Token.LeftParen, + Token.Identifier, 0); + lines.Add("Creating First Set for: EXPRESSION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* simpleExpression */ + set = TokenSet.newFromList + (Token.Plus, Token.Minus, Token.NOT, Token.IntLiteral, Token.RealLiteral, + Token.CharLiteral, Token.StringLiteral, Token.LeftBrace, Token.LeftParen, + Token.Identifier, 0); + lines.Add("Creating First Set for: SIMPLE EXPRESSION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* term */ + set = TokenSet.newFromList + (Token.NOT, Token.IntLiteral, Token.RealLiteral, Token.CharLiteral, Token.StringLiteral, + Token.LeftBrace, Token.LeftParen, Token.Identifier, 0); + lines.Add("Creating First Set for: TERM \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* simpleTerm */ + set = TokenSet.newFromList + (Token.NOT, Token.IntLiteral, Token.RealLiteral, Token.CharLiteral, Token.StringLiteral, + Token.LeftBrace, Token.LeftParen, Token.Identifier, 0); + lines.Add("Creating First Set for: SIMPLE TERM \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* factor */ + set = TokenSet.newFromList + (Token.IntLiteral, Token.RealLiteral, Token.CharLiteral, Token.StringLiteral, + Token.LeftBrace, Token.LeftParen, Token.Identifier, 0); + lines.Add("Creating First Set for: FACTOR \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* designatorOrFuncCall */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating First Set for: DESIGNATOR OR FUNC CALL \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* setValue */ + set = TokenSet.newFromList(Token.LeftBrace, 0); + lines.Add("Creating First Set for: SET VALUE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* element */ + set = TokenSet.newFromList + (Token.Plus, Token.Minus, Token.NOT, Token.IntLiteral, Token.RealLiteral, + Token.CharLiteral, Token.StringLiteral, Token.LeftBrace, Token.LeftParen, + Token.Identifier, 0); + lines.Add("Creating First Set for: ELEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Option dependent FIRST sets */ + + /* formalType */ + set = TokenSet.newFromList + (Token.ARRAY, Token.CONST, Token.VAR, Token.Identifier, 0); + lines.Add("Creating First Set for: FORMAL TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* attributedFormalType */ + set = TokenSet.newFromList(Token.CONST, Token.VAR, 0); + lines.Add("Creating First Set for: ATTRIBUTED FORMAL TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* formalParamList */ + set = TokenSet.newFromList + (Token.Identifier, Token.CONST, Token.VAR, 0); + lines.Add("Creating First Set for: FORMAL PARAM LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* formalParams */ + set = TokenSet.newFromList + (Token.Identifier, Token.CONST, Token.VAR, 0); + lines.Add("Creating First Set for: FORMAL PARAMS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* attribFormalParams */ + set = TokenSet.newFromList(Token.CONST, Token.VAR, 0); + lines.Add("Creating First Set for: ATTRIB FORMAL PARAMS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* typeDeclarationTail */ + set = TokenSet.newFromList + (Token.VAR, Token.Identifier, Token.LeftBracket, Token.LeftParen, + Token.SET, Token.ARRAY, Token.RECORD, Token.POINTER, Token.PROCEDURE, 0); + lines.Add("Creating First Set for: TYPE DECLARATION TAIL \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative FIRST sets */ + + /* Alternative formalType */ + set = TokenSet.newFromList + (Token.ARRAY, Token.VAR, Token.Identifier, 0); + lines.Add("Creating First Set for: ALT FORMAL TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative attributedFormalType */ + set = TokenSet.newFromList(Token.VAR, 0); + lines.Add("Creating First Set for: ALT ATTRIB FORMAL TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative formalParamList */ + set = TokenSet.newFromList(Token.Identifier, Token.VAR, 0); + lines.Add("Creating First Set for: ALT FORMAL PARAM LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative formalParams */ + set = TokenSet.newFromList(Token.Identifier, Token.VAR, 0); + lines.Add("Creating First Set for: ALT FORMAL PARAMS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative attribFormalParams */ + set = TokenSet.newFromList(Token.VAR, 0); + lines.Add("Creating First Set for: ALT ATTRIB FORMAL PARAMS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative typeDeclarationTail */ + set = TokenSet.newFromList + (Token.Identifier, Token.LeftBracket, Token.LeftParen, + Token.SET, Token.ARRAY, Token.RECORD, Token.POINTER, Token.PROCEDURE, 0); + lines.Add("Creating First Set for: ALT TYPE DECL TAIL \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + return lines; + + } /* end genSets */ + + } /* end GenFirstSets */ + +} /* end namespace */ diff --git a/utils/GenFollowSets.cs b/utils/GenFollowSets.cs new file mode 100644 index 0000000..2fcefcb --- /dev/null +++ b/utils/GenFollowSets.cs @@ -0,0 +1,740 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * GenFollowSets.cs + * + * A class dedicated to producing representations of the follow sets used by the parser. + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace org.m2sf.m2sharp +{ + + class GenFollowSets { + + public static List genSets() { + + + List lines = new List(); + TokenSet set; + + lines.Add("/* M2sharp FOLLOW Set initialisers" + + " -- generated by GenFirstSets.cs */\n\n"); + + /* definitionModule */ + set = TokenSet.newFromList(Token.DEFINITION, 0); + lines.Add("Creating Follow Set for: DEFINITION MODULE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* import */ + set = TokenSet.newFromList + (Token.DEFINITION, Token.BEGIN, Token.CONST, Token.END, Token.MODULE, + Token.PROCEDURE, Token.TYPE, Token.VAR, Token.EXPORT, 0); + lines.Add("Creating Follow Set for: IMPORT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* qualfiedImport */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: QUALIFIED IMPORT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* unqualfiedImport */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: UNQUALIFIED IMPORT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* identList */ + set = TokenSet.newFromList + (Token.Semicolon, Token.Colon, Token.RightParen, 0); + lines.Add("Creating Follow Set for: IDENT LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* definition */ + set = TokenSet.newFromList(Token.END, 0); + lines.Add("Creating Follow Set for: DEFINITION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* constDefinition */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: CONST DEFINITION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* typeDefinition */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: TYPE DEFINITION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* type */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* derivedOrSubRangeType */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: DERIVED OR SUBRange TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* qualident */ + set = TokenSet.newFromList + (Token.Semicolon, Token.LeftBracket, Token.Comma, Token.OF, + Token.RightParen, Token.Assign, Token.LeftParen, Token.END, + Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, Token.LeftBrace, + Token.Asterisk, Token.Solidus, Token.DIV, Token.MOD, Token.AND, + Token.Plus, Token.Minus, Token.OR, Token.Equal, Token.NotEqual, + Token.Less, Token.LessEqual, Token.Greater, Token.GreaterEqual, + Token.IN, Token.THEN, Token.DO, Token.TO, Token.BY, + Token.Range, Token.RightBrace, 0); + lines.Add("Creating Follow Set for: QUALIDENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Range */ + set = TokenSet.newFromList + (Token.Semicolon, Token.Comma, Token.OF, 0); + lines.Add("Creating Follow Set for: Range \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* enumType */ + set = TokenSet.newFromList + (Token.Semicolon, Token.Comma, Token.OF, 0); + lines.Add("Creating Follow Set for: ENUM TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* setType */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: SET TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* countableType */ + set = TokenSet.newFromList + (Token.Semicolon, Token.Comma, Token.OF, 0); + lines.Add("Creating Follow Set for: COUNTABLE TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* arrayType */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: ARRAY TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* extensibleRecordType */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: EXTENSIBLE RECORD TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* fieldListSequence */ + set = TokenSet.newFromList(Token.END, Token.VAR, 0); + lines.Add("Creating Follow Set for: FIELD LIST SEQUENCE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variantRecordType */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: VARIANT RECORD TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variantFieldListSeq */ + set = TokenSet.newFromList + (Token.Bar, Token.ELSE, Token.END, 0); + lines.Add("Creating Follow Set for: VARIANT FIELD LIST SEQ \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variantFieldList */ + set = TokenSet.newFromList + (Token.Semicolon, Token.Bar, Token.ELSE, Token.END, 0); + lines.Add("Creating Follow Set for: VARIANT FIELD LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variantFields */ + set = TokenSet.newFromList + (Token.Semicolon, Token.Bar, Token.ELSE, Token.END, 0); + lines.Add("Creating Follow Set for: VARIANT FIELDS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variant */ + set = TokenSet.newFromList + (Token.Bar, Token.ELSE, Token.END, 0); + lines.Add("Creating Follow Set for: VARIANT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* caseLabelList */ + set = TokenSet.newFromList(Token.Colon, 0); + lines.Add("Creating Follow Set for: CASE LABEL LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* caseLabels */ + set = TokenSet.newFromList + (Token.Comma, Token.Colon, 0); + lines.Add("Creating Follow Set for: CASE LABELS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* pointerType */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: POINTER TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* procedureType */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: PROCEDURE TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* simpleFormalType */ + set = TokenSet.newFromList + (Token.Comma, Token.RightParen, 0); + lines.Add("Creating Follow Set for: SIMPLE FORMAL TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* procedureHeader */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: PROCEDURE HEADER \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* procedureSignature */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: PROCEDURE SIGNATURE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* simpleFormalParams */ + set = TokenSet.newFromList + (Token.Semicolon, Token.RightParen, 0); + lines.Add("Creating Follow Set for: SIMPLE FORMAL PARAMS \\\n "); + lines.Add(set.PrintLiteral()); + lines.Add("\n"); + + /* implementationModule */ + set = TokenSet.newFromList(Token.EndOfFile, 0); + lines.Add("Creating Follow Set for: IMPLEMENTATION MODULE \\\n "); + lines.Add(set.PrintLiteral()); + lines.Add("\n"); + + /* programModule */ + set = TokenSet.newFromList(Token.EndOfFile, 0); + lines.Add("Creating Follow Set for: PROGRAM MODULE \\\n "); + lines.Add(set.PrintLiteral()); + lines.Add("\n"); + + /* modulePriority */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: MODULE PRIORITY \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* block */ + set = TokenSet.newFromList(Token.Identifier, 0); + lines.Add("Creating Follow Set for: BLOCK \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* declaration */ + set = TokenSet.newFromList(Token.BEGIN, Token.END, 0); + lines.Add("Creating Follow Set for: DECLARATION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* typeDeclaration */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: TYPE DECLARATION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* varSizeRecordType */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: VAR SIZE RECORD TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* variableDeclaration */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: VARIABLE DECLARATION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* procedureDeclaration */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: PROCEDURE DECLARATION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* moduleDeclaration */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: MODULE DECLARATION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* export */ + set = TokenSet.newFromList + (Token.CONST, Token.TYPE, Token.VAR, Token.PROCEDURE, Token.MODULE, + Token.BEGIN, Token.END, 0); + lines.Add("Creating Follow Set for: EXPORT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* statementSequence */ + set = TokenSet.newFromList + (Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: STATEMENT SEQUENCE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* statement */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* AssignmentOrProcCall */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: AssignMENT OR PROC CALL \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* actualParameters */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: ACTUAL PARAMETERS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* expressionList */ + set = TokenSet.newFromList(Token.RightParen, 0); + lines.Add("Creating Follow Set for: EXPRESSION LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* returnStatement */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: RETURN STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* withStatement */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: WITH STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* ifStatement */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: IF STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* caseStatement */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: CASE STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* case */ + set = TokenSet.newFromList + (Token.Bar, Token.ELSE, Token.END, 0); + lines.Add("Creating Follow Set for: CASE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* loopStatement */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: LOOP STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* whileStatement */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: WHILE STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* repeatStatement */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: REPEAT STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* forStatement */ + set = TokenSet.newFromList + (Token.Semicolon, + Token.END, Token.ELSIF, Token.ELSE, Token.Bar, Token.UNTIL, 0); + lines.Add("Creating Follow Set for: FOR STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* designator */ + set = TokenSet.newFromList + (Token.Assign, Token.LeftParen, Token.LeftBrace, + Token.Semicolon, Token.END, Token.ELSIF, Token.ELSE, Token.Bar, + Token.UNTIL, Token.Asterisk, Token.Solidus, Token.DIV, Token.MOD, + Token.AND, Token.Plus, Token.Minus, Token.OR, Token.Equal, + Token.NotEqual, Token.Less, Token.LessEqual, Token.Greater, + Token.GreaterEqual, Token.IN, Token.Comma, Token.RightParen, + Token.THEN, Token.OF, Token.DO, Token.TO, Token.BY, Token.Range, + Token.RightBrace, 0); + lines.Add("Creating Follow Set for: DESIGNATOR \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* selector */ + set = TokenSet.newFromList + (Token.Identifier, + Token.Assign, Token.LeftParen, Token.LeftBrace, + Token.Semicolon, Token.END, Token.ELSIF, Token.ELSE, Token.Bar, + Token.UNTIL, Token.Asterisk, Token.Solidus, Token.DIV, Token.MOD, + Token.AND, Token.Plus, Token.Minus, Token.OR, Token.Equal, + Token.NotEqual, Token.Less, Token.LessEqual, Token.Greater, + Token.GreaterEqual, Token.IN, Token.Comma, Token.RightParen, + Token.THEN, Token.OF, Token.DO, Token.TO, Token.BY, Token.Range, + Token.RightBrace, 0); + lines.Add("Creating Follow Set for: SELECTOR \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* expression */ + set = TokenSet.newFromList + (Token.Semicolon, Token.END, Token.ELSIF, Token.ELSE, Token.Bar, + Token.UNTIL, Token.Comma, Token.RightParen, Token.THEN, + Token.OF, Token.DO, Token.TO, Token.BY, Token.Range, + Token.RightBrace, 0); + lines.Add("Creating Follow Set for: EXPRESSION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* simpleExpression */ + set = TokenSet.newFromList + (Token.Equal, Token.NotEqual, Token.Less, Token.LessEqual, + Token.Greater, Token.GreaterEqual, Token.IN, + Token.Semicolon, Token.END, Token.ELSIF, Token.ELSE, Token.Bar, + Token.UNTIL, Token.Comma, Token.RightParen, Token.THEN, + Token.OF, Token.DO, Token.TO, Token.BY, Token.Range, + Token.RightBrace, 0); + lines.Add("Creating Follow Set for: SIMPLE EXPRESSION \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* term */ + set = TokenSet.newFromList + (Token.Plus, Token.Minus, Token.OR, + Token.Equal, Token.NotEqual, Token.Less, Token.LessEqual, + Token.Greater, Token.GreaterEqual, Token.IN, + Token.Semicolon, Token.END, Token.ELSIF, Token.ELSE, Token.Bar, + Token.UNTIL, Token.Comma, Token.RightParen, Token.THEN, + Token.OF, Token.DO, Token.TO, Token.BY, Token.Range, + Token.RightBrace, 0); + lines.Add("Creating Follow Set for: TERM \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* simpleTerm */ + set = TokenSet.newFromList + (Token.Asterisk, Token.Solidus, Token.DIV, Token.MOD, Token.AND, + Token.Plus, Token.Minus, Token.OR, + Token.Equal, Token.NotEqual, Token.Less, Token.LessEqual, + Token.Greater, Token.GreaterEqual, Token.IN, + Token.Semicolon, Token.END, Token.ELSIF, Token.ELSE, Token.Bar, + Token.UNTIL, Token.Comma, Token.RightParen, Token.THEN, + Token.OF, Token.DO, Token.TO, Token.BY, Token.Range, + Token.RightBrace, 0); + lines.Add("Creating Follow Set for: SIMPLE TERM \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* factor */ + set = TokenSet.newFromList + (Token.Asterisk, Token.Solidus, Token.DIV, Token.MOD, Token.AND, + Token.Plus, Token.Minus, Token.OR, + Token.Equal, Token.NotEqual, Token.Less, Token.LessEqual, + Token.Greater, Token.GreaterEqual, Token.IN, + Token.Semicolon, Token.END, Token.ELSIF, Token.ELSE, Token.Bar, + Token.UNTIL, Token.Comma, Token.RightParen, Token.THEN, + Token.OF, Token.DO, Token.TO, Token.BY, Token.Range, + Token.RightBrace, 0); + lines.Add("Creating Follow Set for: FACTOR \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* designatorOrFuncCall */ + set = TokenSet.newFromList + (Token.Asterisk, Token.Solidus, Token.DIV, Token.MOD, Token.AND, + Token.Plus, Token.Minus, Token.OR, + Token.Equal, Token.NotEqual, Token.Less, Token.LessEqual, + Token.Greater, Token.GreaterEqual, Token.IN, + Token.Semicolon, Token.END, Token.ELSIF, Token.ELSE, Token.Bar, + Token.UNTIL, Token.Comma, Token.RightParen, Token.THEN, + Token.OF, Token.DO, Token.TO, Token.BY, Token.Range, + Token.RightBrace, 0); + lines.Add("Creating Follow Set for: DESIGNATOR OR FUNC CALL \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* setValue */ + set = TokenSet.newFromList + (Token.Asterisk, Token.Solidus, Token.DIV, Token.MOD, Token.AND, + Token.Plus, Token.Minus, Token.OR, + Token.Equal, Token.NotEqual, Token.Less, Token.LessEqual, + Token.Greater, Token.GreaterEqual, Token.IN, + Token.Semicolon, Token.END, Token.ELSIF, Token.ELSE, Token.Bar, + Token.UNTIL, Token.Comma, Token.RightParen, Token.THEN, + Token.OF, Token.DO, Token.TO, Token.BY, Token.Range, + Token.RightBrace, 0); + lines.Add("Creating Follow Set for: SET VALUE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* element */ + set = TokenSet.newFromList + (Token.Comma, Token.RightBrace, 0); + lines.Add("Creating Follow Set for: ELEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Option dependent FOLLOW sets */ + + /* formalType */ + set = TokenSet.newFromList + (Token.Comma, Token.RightParen, 0); + lines.Add("Creating Follow Set for: FORMAL TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* attributedFormalType */ + set = TokenSet.newFromList + (Token.Comma, Token.RightParen, 0); + lines.Add("Creating Follow Set for: ATTRIBUTED FORMAL TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* formalParamList */ + set = TokenSet.newFromList(Token.RightParen, 0); + lines.Add("Creating Follow Set for: FORMAL PARAM LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* formalParams */ + set = TokenSet.newFromList + (Token.Semicolon, Token.RightParen, 0); + lines.Add("Creating Follow Set for: FORMAL PARAMS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* attribFormalParams */ + set = TokenSet.newFromList + (Token.Semicolon, Token.RightParen, 0); + lines.Add("Creating Follow Set for: ATTRIB FORMAL PARAMS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* typeDeclarationTail */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: TYPE DECLARATION TAIL \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative FOLLOW sets */ + + /* Alternative formalType */ + set = TokenSet.newFromList + (Token.Comma, Token.RightParen, 0); + lines.Add("Creating Follow Set for: ALT FORMAL TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative attributedFormalType */ + set = TokenSet.newFromList + (Token.Comma, Token.RightParen, 0); + lines.Add("Creating Follow Set for: ALT ATTRIB FORMAL TYPE \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative formalParamList */ + set = TokenSet.newFromList(Token.RightParen, 0); + lines.Add("Creating Follow Set for: ALT FORMAL PARAM LIST \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative formalParams */ + set = TokenSet.newFromList + (Token.Semicolon, Token.RightParen, 0); + lines.Add("Creating Follow Set for: ALT FORMAL PARAMS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative attribFormalParams */ + set = TokenSet.newFromList + (Token.Semicolon, Token.RightParen, 0); + lines.Add("Creating Follow Set for: ALT ATTRIB FORMAL PARAMS \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Alternative typeDeclarationTail */ + set = TokenSet.newFromList(Token.Semicolon, 0); + lines.Add("Creating Follow Set for: ALT TYPE DECL TAIL \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + return lines; + } /* end genSets */ + + } /* end GenFollowSets */ + +} /* end namespace */ diff --git a/utils/GenResyncSets.cs b/utils/GenResyncSets.cs new file mode 100644 index 0000000..149877e --- /dev/null +++ b/utils/GenResyncSets.cs @@ -0,0 +1,286 @@ +/* M2Sharp -- Modula-2 to C# Translator & Compiler + * + * Copyright (c) 2016 The Modula-2 Software Foundation + * + * Author & Maintainer: Benjamin Kowarsch + * + * @synopsis + * + * M2Sharp is a multi-dialect Modula-2 to C# translator and via-C# compiler. + * It supports the dialects described in the 3rd and 4th editions of Niklaus + * Wirth's book "Programming in Modula-2" (PIM) published by Springer Verlag, + * and an extended mode with select features from the revised language by + * B.Kowarsch and R.Sutcliffe "Modula-2 Revision 2010" (M2R10). + * + * In translator mode, M2Sharp translates Modula-2 source to C# source files. + * In compiler mode, M2Sharp compiles Modula-2 source via C# source files + * to object code or executables using the host system's C# compiler. + * + * @repository + * + * https://github.com/m2sf/m2sharp + * + * @file + * + * GenResyncSets.cs + * + * A class dedicated to producing representations of the skip sets used by the parser. + * + * @license + * + * M2Sharp is free software: you can redistribute and/or modify it under the + * terms of the GNU Lesser General Public License (LGPL) either version 2.1 + * or at your choice version 3 as published by the Free Software Foundation. + * However, you may not alter the copyright, author and license information. + * + * M2Sharp is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. Read the license for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with M2Sharp. If not, see . + * + * NB: Components in the domain part of email addresses are in reverse order. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace org.m2sf.m2sharp +{ + class GenResyncSets + { + public static List genSets() + { + + TokenSet set; + List lines = new List(); + + lines.Add("/* M2C resync set initialisers" + + " -- generated by gen resync sets.c */\n\n"); + + /* Resync to Resync(import) or Resync(definition) or END */ + + set = TokenSet.newFromList + (/* Resync(import) */ + Token.IMPORT, Token.FROM, + /* Resync(definition) */ + Token.CONST, Token.TYPE, Token.VAR, Token.PROCEDURE, + /* END */ + Token.END, + /* EOF */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: IMPORT OR DEFINITON OR END \\\n "); + lines.Add(set.PrintLiteral()); + lines.Add("\n"); + + /* Resync to IMPORT or Ident or Semicolon */ + + set = TokenSet.newFromList + (Token.IMPORT, Token.Identifier, Token.Semicolon, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: IMPORT OR IDENT OR Semicolon \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Ident or Semicolon */ + + set = TokenSet.newFromList + (Token.Identifier, Token.Semicolon, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: IDENT OR Semicolon \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Comma or Semicolon */ + + set = TokenSet.newFromList + (Token.Comma, Token.Semicolon, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: Comma OR Semicolon \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Resync(definition) or Ident or Semicolon */ + + set = TokenSet.newFromList + (/* Resync(definition) */ + Token.CONST, Token.TYPE, Token.VAR, Token.PROCEDURE, + /* Ident or Semicolon */ + Token.Identifier, Token.Semicolon, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: DEFINITION OR IDENT OR Semicolon \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Resync(definition) or Semicolon */ + + set = TokenSet.newFromList + (/* Resync(definition) */ + Token.CONST, Token.TYPE, Token.VAR, Token.PROCEDURE, + /* Semicolon */ + Token.Semicolon, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: DEFINITION OR Semicolon \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Resync(type) or Comma or OF */ + + set = TokenSet.newFromList + (/* Resync(type) */ + Token.ARRAY, Token.POINTER, Token.PROCEDURE, Token.RECORD, Token.SET, + Token.Identifier, Token.LeftParen, Token.LeftBracket, + /* Comma or OF */ + Token.Comma, Token.OF, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: TYPE OR Comma OR OF \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Semicolon or END */ + + set = TokenSet.newFromList + (Token.Semicolon, Token.END, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: Semicolon OR END \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to ELSE or END */ + + set = TokenSet.newFromList + (Token.ELSE, Token.END, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: ELSE OR END \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Comma or RightParen */ + + set = TokenSet.newFromList + (Token.Comma, Token.RightParen, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating " + + "Resync Set: Comma OR RightParen \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Colon or Semicolon */ + + set = TokenSet.newFromList + (Token.Colon, Token.Semicolon, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: Colon OR Semicolon \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Resync(import) or Resync(block) */ + + set = TokenSet.newFromList + (/* Resync(import) */ + Token.IMPORT, Token.FROM, + /* Resync(block) */ + Token.CONST, Token.TYPE, Token.VAR, Token.PROCEDURE, Token.MODULE, + Token.BEGIN, Token.END, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: IMPORT OR BLOCK \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Resync(declaration) or Ident or Semicolon */ + + set = TokenSet.newFromList + (/* Resync(declaration) */ + Token.CONST, Token.TYPE, Token.VAR, Token.PROCEDURE, Token.MODULE, + /* Ident or Semicolon */ + Token.Identifier, Token.Semicolon, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: DECLARATION OR IDENT OR Semicolon \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Resync(declaration) or Semicolon */ + + set = TokenSet.newFromList + (/* Resync(declaration) */ + Token.CONST, Token.TYPE, Token.VAR, Token.PROCEDURE, Token.MODULE, + /* Semicolon */ + Token.Semicolon, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: DECLARATION OR Semicolon \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to Resync(statement) or FOLLOW(statement) */ + + set = TokenSet.newFromList + (/* Resync(statement) */ + Token.Identifier, Token.RETURN, Token.WITH, Token.IF, Token.CASE, + Token.LOOP, Token.WHILE, Token.REPEAT, Token.FOR, Token.EXIT, + /* FOLLOW(statement) */ + Token.Semicolon, Token.END, Token.ELSIF, Token.ELSE, Token.Bar, + Token.UNTIL, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: FIRST OR FOLLOW OF STATEMENT \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to ELSIF or ELSE or END */ + + set = TokenSet.newFromList + (Token.ELSIF, Token.ELSE, Token.END, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: ELSIF OR ELSE OR END \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + /* Resync to DO in FOR loop */ + + set = TokenSet.newFromList + (Token.DO, + /* EOF -- in case nothing else matches */ + Token.EndOfFile, 0); + lines.Add("Creating Resync Set: FOR LOOP BODY \\\n "); + lines.Add(set.PrintLiteral()); + + lines.Add("\n"); + + return lines; + } + + } +} From a14c66c585c3dbee556debb77569f983241bd0e4 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Mon, 29 May 2017 09:43:08 -0700 Subject: [PATCH 21/24] Add files via upload --- imp/NonTerminals.cs | 247 ++++++++++++++++++++++++++++++-------------- imp/TokenSet.cs | 61 +++++++---- 2 files changed, 208 insertions(+), 100 deletions(-) diff --git a/imp/NonTerminals.cs b/imp/NonTerminals.cs index 8ac690f..6856b49 100644 --- a/imp/NonTerminals.cs +++ b/imp/NonTerminals.cs @@ -24,7 +24,7 @@ * * NonTerminals.cs * - * provides FIRST() and FOLLOW() sets for each non-terminal symbol //SAM CHANGE + * provides FIRST() and FOLLOW() sets for each non-terminal symbol * used by the parser class for syntax analysis * * @license @@ -59,156 +59,174 @@ public class NonTerminals : INonTerminals { lastOptionDependent = lastNoVariantRecDependent; public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; - #region followSets + /* *************************************************************************** + WARNING: This code section has been auto-generated by utility GenFollowSets + *************************************************************************** + DO NOT MODIFY THIS CODE MANUALLY -- In the event that changes are necessary + use the GenFirstSet utility to regenerate this code section and paste it. + ***************************************************************************/ + + #region follow sets TokenSet[] followSets = { - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* definitionModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* definitionModule */ - TokenSet.newFromRawData( /* bits: */ 0x108050C8, 0x00000050, 0x00000000, /* counter: */ 9 ), /* import */ + TokenSet.newFromRawData( /* bits: */ 0x2100a190, 0x000000a0, 0x00000000, /* counter: */ 9 ), /* import */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* qualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* qualifiedImport */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* unqualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* unqualifiedImport */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000021, /* counter: */ 3 ), /* identList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000086, /* counter: */ 3 ), /* identList */ - TokenSet.newFromRawData( /* bits: */ 0x00001000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ + TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* constDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* constDefinition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDefinition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* type */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* type */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* derivedOrSubrangeType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* derivedOrSubrangeType */ - TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000037B, /* counter: */ 34 ), /* qualident */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80058, 0x00000dec, /* counter: */ 34 ), /* qualident */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* range */ + TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* range */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* enumType */ + TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* enumType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* setType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* setType */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x20000000, 0x00000001, /* counter: */ 3 ), /* countableType */ + TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* countableType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* arrayType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* arrayType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* extensibleRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* extensibleRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00001000, 0x00000040, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000080, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variantRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* variantRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variantFieldListSeq */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* variantFieldListSeq */ - TokenSet.newFromRawData( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFieldList */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000024, /* counter: */ 4 ), /* variantFieldList */ - TokenSet.newFromRawData( /* bits: */ 0x00001400, 0x00000000, 0x00000009, /* counter: */ 4 ), /* variantFields */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000024, /* counter: */ 4 ), /* variantFields */ - TokenSet.newFromRawData( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* variant */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* variant */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000000, /* counter: */ 1 ), /* caseLabelList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000002, /* counter: */ 1 ), /* caseLabelList */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0xA0000000, 0x00000000, /* counter: */ 2 ), /* caseLabels */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000002, /* counter: */ 2 ), /* caseLabels */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* pointerType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* pointerType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* simpleFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* simpleFormalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureHeader */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureHeader */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureSignature */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureSignature */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* simpleFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* simpleFormalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* implementationModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* implementationModule */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* programModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* programModule */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* modulePriority */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* modulePriority */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* block */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* block */ - TokenSet.newFromRawData( /* bits: */ 0x00001008, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ + TokenSet.newFromRawData( /* bits: */ 0x00002010, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* varSizeRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* varSizeRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* variableDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* variableDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* procedureDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* moduleDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* moduleDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x10801048, 0x00000050, 0x00000000, /* counter: */ 7 ), /* export */ + TokenSet.newFromRawData( /* bits: */ 0x21002090, 0x000000a0, 0x00000000, /* counter: */ 7 ), /* export */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000008, /* counter: */ 5 ), /* statementSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000020, /* counter: */ 5 ), /* statementSequence */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* statement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* statement */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* assignmentOrProcCall */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* assignmentOrProcCall */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* actualParameters */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* actualParameters */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* expressionList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000080, /* counter: */ 1 ), /* expressionList */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* returnStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* returnStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* withStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* withStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* ifStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* ifStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* caseStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* caseStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00001400, 0x00000000, 0x00000008, /* counter: */ 3 ), /* case */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* case */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* loopStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* loopStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* whileStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* whileStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* repeatStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* repeatStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00001C00, 0x00000020, 0x00000009, /* counter: */ 6 ), /* forStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* forStatement */ - TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x3FFC002C, 0x0000033B, /* counter: */ 33 ), /* designator */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80058, 0x00000cec, /* counter: */ 33 ), /* designator */ - TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x3FFC022C, 0x0000033B, /* counter: */ 34 ), /* selector */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80458, 0x00000cec, /* counter: */ 34 ), /* selector */ - TokenSet.newFromRawData( /* bits: */ 0x02001E10, 0x2000002C, 0x0000022B, /* counter: */ 15 ), /* expression */ + TokenSet.newFromRawData( /* bits: */ 0x04003c20, 0x80000058, 0x000008ac, /* counter: */ 15 ), /* expression */ - TokenSet.newFromRawData( /* bits: */ 0x02101E10, 0x23F0002C, 0x0000022B, /* counter: */ 22 ), /* simpleExpression */ + TokenSet.newFromRawData( /* bits: */ 0x04203c20, 0x87e00058, 0x000008ac, /* counter: */ 22 ), /* simpleExpression */ - TokenSet.newFromRawData( /* bits: */ 0x06101E10, 0x23FC002C, 0x0000022B, /* counter: */ 25 ), /* term */ + TokenSet.newFromRawData( /* bits: */ 0x0c203c20, 0x87f80058, 0x000008ac, /* counter: */ 25 ), /* term */ - TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* simpleTerm */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* simpleTerm */ - TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* factor */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* factor */ - TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* designatorOrFuncCall */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* designatorOrFuncCall */ - TokenSet.newFromRawData( /* bits: */ 0x06501F12, 0x2FFC002C, 0x0000022B, /* counter: */ 30 ), /* setValue */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* setValue */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x20000000, 0x00000200, /* counter: */ 2 ), /* element */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000800, /* counter: */ 2 ), /* element */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* formalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* formalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x20000000, 0x00000020, /* counter: */ 2 ), /* attributedFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* attributedFormalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000020, /* counter: */ 1 ), /* formalParamList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000080, /* counter: */ 1 ), /* formalParamList */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* formalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* formalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000021, /* counter: */ 2 ), /* attribFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* attribFormalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000001, /* counter: */ 1 ), /* typeDeclarationTail */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDeclarationTail */ }; #endregion - #region firstSets + /* *************************************************************************** + END of code auto-generated by GenFollowSets + ***************************************************************************/ + + /* *************************************************************************** + WARNING: This code section has been auto-generated by utility GenFirstSets + *************************************************************************** + DO NOT MODIFY THIS CODE MANUALLY -- In the event that changes are necessary + use the GenFirstSet utility to regenerate this code section and paste it. + ***************************************************************************/ + + #region first sets TokenSet[] firstSets = { TokenSet.newFromRawData( /* bits: */ 0x00000100, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ @@ -356,9 +374,80 @@ public class NonTerminals : INonTerminals { }; #endregion + /* *************************************************************************** + END of code auto-generated by GenFirstSets + ***************************************************************************/ + + /* *************************************************************************** + WARNING: This code section has been auto-generated by utility GenResyncSets + *************************************************************************** + DO NOT MODIFY THIS CODE MANUALLY -- In the event that changes are necessary + use the GenFirstSet utility to regenerate this code section and paste it. + ***************************************************************************/ + + #region skip sets + TokenSet[] skipSets = { + /* Skip to: IMPORT OR DEFINITON OR END */ + TokenSet.newFromRawData( /* bits: */ 0x20122080, 0x000000a0, 0x00001000, /* counter: */ 8 ), + + /* Skip to: IMPORT OR IDENT OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x00100000, 0x00000400, 0x00001004, /* counter: */ 4 ), + + /* Skip to: IDENT OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00001004, /* counter: */ 3 ), + + /* Skip to: COMMA OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00001004, /* counter: */ 3 ), + + /* Skip to: DEFINITION OR IDENT OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x20000080, 0x000004a0, 0x00001004, /* counter: */ 7 ), + + /* Skip to: DEFINITION OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x20000080, 0x000000a0, 0x00001004, /* counter: */ 6 ), + + /* Skip to: TYPE OR COMMA OR OF */ + TokenSet.newFromRawData( /* bits: */ 0xb4000008, 0x80000404, 0x00001140, /* counter: */ 11 ), + + /* Skip to: SEMICOLON OR END */ + TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000000, 0x00001004, /* counter: */ 3 ), + + /* Skip to: ELSE OR END */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00001000, /* counter: */ 3 ), + + /* Skip to: COMMA OR RIGHT PAREN */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00001080, /* counter: */ 3 ), + + /* Skip to: COLON OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001006, /* counter: */ 3 ), + + /* Skip to: IMPORT OR BLOCK */ + TokenSet.newFromRawData( /* bits: */ 0x21122090, 0x000000a0, 0x00001000, /* counter: */ 10 ), + + /* Skip to: DECLARATION OR IDENT OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x21000080, 0x000004a0, 0x00001004, /* counter: */ 8 ), + + /* Skip to: DECLARATION OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x21000080, 0x000000a0, 0x00001004, /* counter: */ 7 ), + + /* Skip to: FIRST OR FOLLOW OF STATEMENT */ + TokenSet.newFromRawData( /* bits: */ 0x00457840, 0x00000743, 0x00001024, /* counter: */ 17 ), + + /* Skip to: ELSIF OR ELSE OR END */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000000, 0x00001000, /* counter: */ 4 ), + + /* Skip to: FOR LOOP BODY */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000000, 0x00001000, /* counter: */ 2 ) + + }; + #endregion + + /* *************************************************************************** + END of code auto-generated by GenResyncSets + ***************************************************************************/ + /* -------------------------------------------------------------------------- * method Count() -- Returns the number of productions - * ----------------------------------------------------------------------- */ //SAM CHANGE + * ----------------------------------------------------------------------- */ static uint Count() { return (uint)Enum.GetNames(typeof(Production)).Length; @@ -369,7 +458,7 @@ static uint Count() { * method IsOptionDependent(p) * -------------------------------------------------------------------------- * Returns true if p is dependent on any compiler option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE + * ----------------------------------------------------------------------- */ bool IsOptionDependent(Production p) { return p >= firstOptionDependent; @@ -380,7 +469,7 @@ bool IsOptionDependent(Production p) { * method IsConstParamDependent(p) * -------------------------------------------------------------------------- * Returns true if p is dependent on CONST parameter option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE + * ----------------------------------------------------------------------- */ bool IsConstParamDependent(Production p) { @@ -392,7 +481,7 @@ bool IsConstParamDependent(Production p) * method IsVariantRecordDependent(p) * -------------------------------------------------------------------------- * Returns true if p is dependent on variant record type option, else false. - * ----------------------------------------------------------------------- */ //SAM CHANGE + * ----------------------------------------------------------------------- */ bool IsVariantRecordDependent(Production p) { return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; diff --git a/imp/TokenSet.cs b/imp/TokenSet.cs index f047590..e8b6458 100644 --- a/imp/TokenSet.cs +++ b/imp/TokenSet.cs @@ -52,7 +52,8 @@ namespace org.m2sf.m2sharp { - public class TokenSet : ITokenSet { + public class TokenSet //: ITokenSet + { /* Lexeme Table */ public static string[] lexemeTable = { @@ -154,11 +155,11 @@ public class TokenSet : ITokenSet { }; /* end m2c_token_name_table */ - public const int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; + private static readonly int segmentCount = (Enum.GetNames(typeof(Token)).Length / 32) + 1; public struct TokenSetBits { - public uint[] segments = new uint[segmentCount]; + public uint[] segments; public uint elemCount; } /* end struct */ @@ -168,41 +169,54 @@ public struct TokenSetBits * private constructor TokenSet () * --------------------------------------------------------------------------- * Prevents clients from invoking the default constructor. + * Sets the length of dataStored.segments. * ------------------------------------------------------------------------ */ private TokenSet() { - // no operation + this.dataStored.segments = new uint[segmentCount]; } /* end TokenSet */ - /* --------------------------------------------------------------------------- - * private TokenSet newFromRawData(uint[]) - * --------------------------------------------------------------------------- - * Used to instantiate the prefabricated first and follow lists. - * Expects TSB[segmentCount] to be the number of tokens, and returns null if - * the count does not match. - * ------------------------------------------------------------------------ */ - public static TokenSet newFromRawData(params uint[] TSB) - { + + /* -------------------------------------------------------------------------- + * constructor newFromRawData( bits95to64, bits63to32, bits31to0, counter ) + * -------------------------------------------------------------------------- + * Returns a newly allocated tokenset object from raw data passed in as + * three data segments of 32 bits from highest to lowest, followed by a bit + * counter. Returns null if the input data is inconsistent. + * ----------------------------------------------------------------------- */ + + public static TokenSet newFromRawData(params uint[] args) { + TokenSet newSet = new TokenSet(); uint counter = 0; - for (int i = 0; i < segmentCount; i++) { + if (args.Length != segmentCount + 1) { + return null; + } /* end if */ + + if (args[segmentCount] > segmentCount * 32) { + return null; + } /* end if */ + + for (int segmentIndex = args.Length - 2; segmentIndex >= 0; segmentIndex--) { - for (int j = 0; j < 32; j++) { - if ((TSB[i] & (1 << j)) == (1 << j)) + for (int bitIndex = 0; bitIndex < 32; bitIndex++) { + + if ((args[segmentIndex] & (1 << bitIndex)) == (1 << bitIndex)) counter++; } /* end for */ - newSet.dataStored.segments[i] = TSB[i]; + newSet.dataStored.segments[segmentIndex] = args[segmentIndex]; } /* end for */ - if (counter != TSB[segmentCount]) { + if (counter != args[segmentCount]) + { return null; } /* end if */ - newSet.dataStored.elemCount = TSB[segmentCount]; + newSet.dataStored.elemCount = args[segmentCount]; return newSet; } /* end newFromData */ @@ -556,19 +570,24 @@ public void PrintLiteralStruct(string ident) * Format: ( 0xHHHHHHHH, 0xHHHHHHHH, ..., count ); * ----------------------------------------------------------------------- */ - public void PrintLiteral() + public String PrintLiteral() { uint segmentIndex; + String returnVal; + returnVal = "( /* bits: */ 0x" + this.dataStored.segments[0].ToString("x08"); Console.Write("( /* bits: */ 0x" + this.dataStored.segments[0].ToString("x08")); for (segmentIndex = 1; segmentIndex < segmentCount; segmentIndex++) { - + returnVal += ", 0x" + this.dataStored.segments[segmentIndex].ToString("x08"); Console.Write(", 0x" + this.dataStored.segments[segmentIndex].ToString("x08")); } /* end for */ + returnVal += ", /* counter: */ " + this.dataStored.elemCount + " );"; Console.WriteLine(", /* counter: */ " + this.dataStored.elemCount + " );"); + + return returnVal; } /* end PrintLiteral */ /* -------------------------------------------------------------------------- From 4c63fa4bf6f3291d71899288d457d80013015fd8 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Mon, 29 May 2017 11:36:25 -0700 Subject: [PATCH 22/24] Add files via upload --- ITerminals.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ITerminals.cs b/ITerminals.cs index 6a15375..8fbc95a 100644 --- a/ITerminals.cs +++ b/ITerminals.cs @@ -60,8 +60,8 @@ public enum Token { AND, ARGLIST, ARRAY, BEGIN, BY, CASE, CONST, DEFINITION, DIV, DO, ELSE, ELSIF, END, EXIT, EXPORT, FOR, FROM, IF, IMPLEMENTATION, IMPORT, IN, LOOP, - MOD, MODULE, NOT, OF, OPAQUE, OR, POINTER, PROCEDURE, QUALIFIED, RECORD, - REPEAT, RETURN, SET, THEN, TO, TYPE, UNTIL, VAR, WHILE, WITH, + MOD, MODULE, NOT, OF, OPAQUE, OR, POINTER, PROCEDURE, QUALIFIED, RECORD, REPEAT, + RETURN, SET, THEN, TO, TYPE, UNTIL, VAR, WHILE, WITH, /* Identifiers */ @@ -216,4 +216,4 @@ interface ITerminals { } /* namespace */ -/* END OF FILE */ +/* END OF FILE */ \ No newline at end of file From 27bbaf756848d1d372cd8c8ea961ec9c111dfe41 Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Mon, 29 May 2017 13:47:32 -0700 Subject: [PATCH 23/24] Add files via upload --- imp/NonTerminals.cs | 585 ++++++++++++++++++++++---------------------- 1 file changed, 292 insertions(+), 293 deletions(-) diff --git a/imp/NonTerminals.cs b/imp/NonTerminals.cs index 6856b49..f11409c 100644 --- a/imp/NonTerminals.cs +++ b/imp/NonTerminals.cs @@ -51,334 +51,337 @@ namespace org.m2sf.m2sharp { public class NonTerminals : INonTerminals { - public static Production firstConstParamDependent = Production.FormalType, - lastConstParamDependent = Production.AttribFormalParams, - firstNoVariantRecDependent = Production.TypeDeclarationTail, - lastNoVariantRecDependent = Production.TypeDeclarationTail, - firstOptionDependent = firstConstParamDependent, - lastOptionDependent = lastNoVariantRecDependent; - public static uint alternateSetOffset = (uint)lastOptionDependent - (uint)firstOptionDependent + 1; - - /* *************************************************************************** - WARNING: This code section has been auto-generated by utility GenFollowSets + public static Production firstConstParamDependent = Production.FormalType, + lastConstParamDependent = Production.AttribFormalParams, + firstNoVariantRecDependent = Production.TypeDeclarationTail, + lastNoVariantRecDependent = Production.TypeDeclarationTail, + firstOptionDependent = firstConstParamDependent, + lastOptionDependent = lastNoVariantRecDependent; + + public static uint alternateSetOffset = + (uint)lastOptionDependent - (uint)firstOptionDependent + 1; + +/* *************************************************************************** + WARNING: This code section has been auto-generated by utility GenFirstSets + * when I type stuff now it should wrap exactly where it's supposed to I think *************************************************************************** DO NOT MODIFY THIS CODE MANUALLY -- In the event that changes are necessary use the GenFirstSet utility to regenerate this code section and paste it. - ***************************************************************************/ + ***************************************************************************/ - #region follow sets - TokenSet[] followSets = { - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* definitionModule */ + #region first sets + TokenSet[] firstSets = { + TokenSet.newFromRawData( /* bits: */ 0x00000100, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ - TokenSet.newFromRawData( /* bits: */ 0x2100a190, 0x000000a0, 0x00000000, /* counter: */ 9 ), /* import */ + TokenSet.newFromRawData( /* bits: */ 0x00120000, 0x00000000, 0x00000000, /* counter: */ 2 ), /* import */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* qualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00100000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* qualifiedImport */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* unqualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00020000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* unqualifiedImport */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000086, /* counter: */ 3 ), /* identList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* identList */ - TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ + TokenSet.newFromRawData( /* bits: */ 0x20000080, 0x000000a0, 0x00000000, /* counter: */ 4 ), /* definition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* constDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* constDefinition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* typeDefinition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* type */ + TokenSet.newFromRawData( /* bits: */ 0xb0000008, 0x00000404, 0x00000140, /* counter: */ 8 ), /* type */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* derivedOrSubrangeType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000100, /* counter: */ 2 ), /* derivedOrSubrangeType */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80058, 0x00000dec, /* counter: */ 34 ), /* qualident */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* qualident */ - TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* range */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* range */ - TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* enumType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* enumType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* setType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000004, 0x00000000, /* counter: */ 1 ), /* setType */ - TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* countableType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000140, /* counter: */ 3 ), /* countableType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* arrayType */ + TokenSet.newFromRawData( /* bits: */ 0x00000008, 0x00000000, 0x00000000, /* counter: */ 1 ), /* arrayType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* extensibleRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* extensibleRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000080, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* fieldListSequence */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* variantRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* variantFieldListSeq */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000400, 0x00000000, /* counter: */ 2 ), /* variantFieldListSeq */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000024, /* counter: */ 4 ), /* variantFieldList */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000400, 0x00000000, /* counter: */ 2 ), /* variantFieldList */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000024, /* counter: */ 4 ), /* variantFields */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantFields */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* variant */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* variant */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000002, /* counter: */ 1 ), /* caseLabelList */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* caseLabelList */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000002, /* counter: */ 2 ), /* caseLabels */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* caseLabels */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* pointerType */ + TokenSet.newFromRawData( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* pointerType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureType */ + TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* simpleFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000008, 0x00000400, 0x00000000, /* counter: */ 2 ), /* simpleFormalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureHeader */ + TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureHeader */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureSignature */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* procedureSignature */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* simpleFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* simpleFormalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* implementationModule */ + TokenSet.newFromRawData( /* bits: */ 0x00080000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* implementationModule */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* programModule */ + TokenSet.newFromRawData( /* bits: */ 0x01000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* programModule */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* modulePriority */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* modulePriority */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* block */ + TokenSet.newFromRawData( /* bits: */ 0x21002090, 0x000000a0, 0x00000000, /* counter: */ 7 ), /* block */ - TokenSet.newFromRawData( /* bits: */ 0x00002010, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ + TokenSet.newFromRawData( /* bits: */ 0x21000080, 0x000000a0, 0x00000000, /* counter: */ 5 ), /* declaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* typeDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* varSizeRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000080, 0x00000000, /* counter: */ 1 ), /* varSizeRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* variableDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* variableDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* moduleDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x01000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* moduleDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x21002090, 0x000000a0, 0x00000000, /* counter: */ 7 ), /* export */ + TokenSet.newFromRawData( /* bits: */ 0x00008000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* export */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000020, /* counter: */ 5 ), /* statementSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00454040, 0x00000703, 0x00000000, /* counter: */ 10 ), /* statementSequence */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* statement */ + TokenSet.newFromRawData( /* bits: */ 0x00454040, 0x00000703, 0x00000000, /* counter: */ 10 ), /* statement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* assignmentOrProcCall */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* assignmentOrProcCall */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* actualParameters */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* actualParameters */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000080, /* counter: */ 1 ), /* expressionList */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* expressionList */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* returnStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000002, 0x00000000, /* counter: */ 1 ), /* returnStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* withStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* withStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* ifStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00040000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* ifStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* caseStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000000, 0x00000000, /* counter: */ 1 ), /* caseStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* case */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* case */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* loopStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00400000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* loopStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* whileStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000100, 0x00000000, /* counter: */ 1 ), /* whileStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* repeatStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000001, 0x00000000, /* counter: */ 1 ), /* repeatStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* forStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00010000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* forStatement */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80058, 0x00000cec, /* counter: */ 33 ), /* designator */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* designator */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80458, 0x00000cec, /* counter: */ 34 ), /* selector */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000111, /* counter: */ 3 ), /* selector */ - TokenSet.newFromRawData( /* bits: */ 0x04003c20, 0x80000058, 0x000008ac, /* counter: */ 15 ), /* expression */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* expression */ - TokenSet.newFromRawData( /* bits: */ 0x04203c20, 0x87e00058, 0x000008ac, /* counter: */ 22 ), /* simpleExpression */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* simpleExpression */ - TokenSet.newFromRawData( /* bits: */ 0x0c203c20, 0x87f80058, 0x000008ac, /* counter: */ 25 ), /* term */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00007c00, 0x00000440, /* counter: */ 8 ), /* term */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* simpleTerm */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00007c00, 0x00000440, /* counter: */ 8 ), /* simpleTerm */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* factor */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00007c00, 0x00000440, /* counter: */ 7 ), /* factor */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* designatorOrFuncCall */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* designatorOrFuncCall */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* setValue */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* setValue */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000800, /* counter: */ 2 ), /* element */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* element */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* formalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000088, 0x00000480, 0x00000000, /* counter: */ 4 ), /* formalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* attributedFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000080, 0x00000000, /* counter: */ 2 ), /* attributedFormalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000080, /* counter: */ 1 ), /* formalParamList */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000480, 0x00000000, /* counter: */ 3 ), /* formalParamList */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* formalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000480, 0x00000000, /* counter: */ 3 ), /* formalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* attribFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000080, 0x00000000, /* counter: */ 2 ), /* attribFormalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDeclarationTail */ - }; - + TokenSet.newFromRawData( /* bits: */ 0xb0000008, 0x00000484, 0x00000140, /* counter: */ 9 ), /* typeDeclarationTail */ + }; #endregion - /* *************************************************************************** - END of code auto-generated by GenFollowSets +/* *************************************************************************** + END of code auto-generated by GenFirstSets ***************************************************************************/ - /* *************************************************************************** - WARNING: This code section has been auto-generated by utility GenFirstSets +/* *************************************************************************** + WARNING: This code section has been auto-generated by utility GenFollowSets *************************************************************************** DO NOT MODIFY THIS CODE MANUALLY -- In the event that changes are necessary use the GenFirstSet utility to regenerate this code section and paste it. ***************************************************************************/ - #region first sets - TokenSet[] firstSets = { - TokenSet.newFromRawData( /* bits: */ 0x00000100, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ + #region follow sets + TokenSet[] followSets = { + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* definitionModule */ - TokenSet.newFromRawData( /* bits: */ 0x00120000, 0x00000000, 0x00000000, /* counter: */ 2 ), /* import */ + TokenSet.newFromRawData( /* bits: */ 0x2100a190, 0x000000a0, 0x00000000, /* counter: */ 9 ), /* import */ - TokenSet.newFromRawData( /* bits: */ 0x00100000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* qualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* qualifiedImport */ - TokenSet.newFromRawData( /* bits: */ 0x00020000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* unqualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* unqualifiedImport */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* identList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000086, /* counter: */ 3 ), /* identList */ - TokenSet.newFromRawData( /* bits: */ 0x20000080, 0x000000a0, 0x00000000, /* counter: */ 4 ), /* definition */ + TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* constDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* constDefinition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* typeDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDefinition */ - TokenSet.newFromRawData( /* bits: */ 0xb0000008, 0x00000404, 0x00000140, /* counter: */ 8 ), /* type */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* type */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000100, /* counter: */ 2 ), /* derivedOrSubrangeType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* derivedOrSubrangeType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* qualident */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80058, 0x00000dec, /* counter: */ 34 ), /* qualident */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* range */ + TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* range */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* enumType */ + TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* enumType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000004, 0x00000000, /* counter: */ 1 ), /* setType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* setType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000140, /* counter: */ 3 ), /* countableType */ + TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* countableType */ - TokenSet.newFromRawData( /* bits: */ 0x00000008, 0x00000000, 0x00000000, /* counter: */ 1 ), /* arrayType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* arrayType */ - TokenSet.newFromRawData( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* extensibleRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* extensibleRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* fieldListSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000080, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ - TokenSet.newFromRawData( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* variantRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000400, 0x00000000, /* counter: */ 2 ), /* variantFieldListSeq */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* variantFieldListSeq */ - TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000400, 0x00000000, /* counter: */ 2 ), /* variantFieldList */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000024, /* counter: */ 4 ), /* variantFieldList */ - TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantFields */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000024, /* counter: */ 4 ), /* variantFields */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* variant */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* variant */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* caseLabelList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000002, /* counter: */ 1 ), /* caseLabelList */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* caseLabels */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000002, /* counter: */ 2 ), /* caseLabels */ - TokenSet.newFromRawData( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* pointerType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* pointerType */ - TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureType */ - TokenSet.newFromRawData( /* bits: */ 0x00000008, 0x00000400, 0x00000000, /* counter: */ 2 ), /* simpleFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* simpleFormalType */ - TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureHeader */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureHeader */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* procedureSignature */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureSignature */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* simpleFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* simpleFormalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00080000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* implementationModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* implementationModule */ - TokenSet.newFromRawData( /* bits: */ 0x01000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* programModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* programModule */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* modulePriority */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* modulePriority */ - TokenSet.newFromRawData( /* bits: */ 0x21002090, 0x000000a0, 0x00000000, /* counter: */ 7 ), /* block */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* block */ - TokenSet.newFromRawData( /* bits: */ 0x21000080, 0x000000a0, 0x00000000, /* counter: */ 5 ), /* declaration */ + TokenSet.newFromRawData( /* bits: */ 0x00002010, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* typeDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000080, 0x00000000, /* counter: */ 1 ), /* varSizeRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* varSizeRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* variableDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* variableDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x01000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* moduleDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* moduleDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00008000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* export */ + TokenSet.newFromRawData( /* bits: */ 0x21002090, 0x000000a0, 0x00000000, /* counter: */ 7 ), /* export */ - TokenSet.newFromRawData( /* bits: */ 0x00454040, 0x00000703, 0x00000000, /* counter: */ 10 ), /* statementSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000020, /* counter: */ 5 ), /* statementSequence */ - TokenSet.newFromRawData( /* bits: */ 0x00454040, 0x00000703, 0x00000000, /* counter: */ 10 ), /* statement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* statement */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* assignmentOrProcCall */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* assignmentOrProcCall */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* actualParameters */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* actualParameters */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* expressionList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000080, /* counter: */ 1 ), /* expressionList */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000002, 0x00000000, /* counter: */ 1 ), /* returnStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* returnStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* withStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* withStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00040000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* ifStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* ifStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000000, 0x00000000, /* counter: */ 1 ), /* caseStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* caseStatement */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* case */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* case */ - TokenSet.newFromRawData( /* bits: */ 0x00400000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* loopStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* loopStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000100, 0x00000000, /* counter: */ 1 ), /* whileStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* whileStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000001, 0x00000000, /* counter: */ 1 ), /* repeatStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* repeatStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00010000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* forStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* forStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* designator */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80058, 0x00000cec, /* counter: */ 33 ), /* designator */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000111, /* counter: */ 3 ), /* selector */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80458, 0x00000cec, /* counter: */ 34 ), /* selector */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* expression */ + TokenSet.newFromRawData( /* bits: */ 0x04003c20, 0x80000058, 0x000008ac, /* counter: */ 15 ), /* expression */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* simpleExpression */ + TokenSet.newFromRawData( /* bits: */ 0x04203c20, 0x87e00058, 0x000008ac, /* counter: */ 22 ), /* simpleExpression */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00007c00, 0x00000440, /* counter: */ 8 ), /* term */ + TokenSet.newFromRawData( /* bits: */ 0x0c203c20, 0x87f80058, 0x000008ac, /* counter: */ 25 ), /* term */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00007c00, 0x00000440, /* counter: */ 8 ), /* simpleTerm */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* simpleTerm */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00007c00, 0x00000440, /* counter: */ 7 ), /* factor */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* factor */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* designatorOrFuncCall */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* designatorOrFuncCall */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* setValue */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* setValue */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* element */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000800, /* counter: */ 2 ), /* element */ - TokenSet.newFromRawData( /* bits: */ 0x00000088, 0x00000480, 0x00000000, /* counter: */ 4 ), /* formalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* formalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000080, 0x00000000, /* counter: */ 2 ), /* attributedFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* attributedFormalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000480, 0x00000000, /* counter: */ 3 ), /* formalParamList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000080, /* counter: */ 1 ), /* formalParamList */ - TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000480, 0x00000000, /* counter: */ 3 ), /* formalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* formalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000080, 0x00000000, /* counter: */ 2 ), /* attribFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* attribFormalParams */ - TokenSet.newFromRawData( /* bits: */ 0xb0000008, 0x00000484, 0x00000140, /* counter: */ 9 ), /* typeDeclarationTail */ - }; + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDeclarationTail */ + }; + #endregion - /* *************************************************************************** - END of code auto-generated by GenFirstSets +/* *************************************************************************** + END of code auto-generated by GenFollowSets ***************************************************************************/ - /* *************************************************************************** +/* *************************************************************************** WARNING: This code section has been auto-generated by utility GenResyncSets *************************************************************************** DO NOT MODIFY THIS CODE MANUALLY -- In the event that changes are necessary @@ -386,162 +389,158 @@ use the GenFirstSet utility to regenerate this code section and paste it. ***************************************************************************/ #region skip sets - TokenSet[] skipSets = { - /* Skip to: IMPORT OR DEFINITON OR END */ - TokenSet.newFromRawData( /* bits: */ 0x20122080, 0x000000a0, 0x00001000, /* counter: */ 8 ), + TokenSet[] skipSets = { + /* Skip to: IMPORT OR DEFINITON OR END */ + TokenSet.newFromRawData( /* bits: */ 0x20122080, 0x000000a0, 0x00001000, /* counter: */ 8 ), - /* Skip to: IMPORT OR IDENT OR SEMICOLON */ - TokenSet.newFromRawData( /* bits: */ 0x00100000, 0x00000400, 0x00001004, /* counter: */ 4 ), + /* Skip to: IMPORT OR IDENT OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x00100000, 0x00000400, 0x00001004, /* counter: */ 4 ), - /* Skip to: IDENT OR SEMICOLON */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00001004, /* counter: */ 3 ), + /* Skip to: IDENT OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00001004, /* counter: */ 3 ), - /* Skip to: COMMA OR SEMICOLON */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00001004, /* counter: */ 3 ), + /* Skip to: COMMA OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00001004, /* counter: */ 3 ), - /* Skip to: DEFINITION OR IDENT OR SEMICOLON */ - TokenSet.newFromRawData( /* bits: */ 0x20000080, 0x000004a0, 0x00001004, /* counter: */ 7 ), + /* Skip to: DEFINITION OR IDENT OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x20000080, 0x000004a0, 0x00001004, /* counter: */ 7 ), - /* Skip to: DEFINITION OR SEMICOLON */ - TokenSet.newFromRawData( /* bits: */ 0x20000080, 0x000000a0, 0x00001004, /* counter: */ 6 ), + /* Skip to: DEFINITION OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x20000080, 0x000000a0, 0x00001004, /* counter: */ 6 ), - /* Skip to: TYPE OR COMMA OR OF */ - TokenSet.newFromRawData( /* bits: */ 0xb4000008, 0x80000404, 0x00001140, /* counter: */ 11 ), + /* Skip to: TYPE OR COMMA OR OF */ + TokenSet.newFromRawData( /* bits: */ 0xb4000008, 0x80000404, 0x00001140, /* counter: */ 11 ), - /* Skip to: SEMICOLON OR END */ - TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000000, 0x00001004, /* counter: */ 3 ), + /* Skip to: SEMICOLON OR END */ + TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000000, 0x00001004, /* counter: */ 3 ), - /* Skip to: ELSE OR END */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00001000, /* counter: */ 3 ), + /* Skip to: ELSE OR END */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00001000, /* counter: */ 3 ), - /* Skip to: COMMA OR RIGHT PAREN */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00001080, /* counter: */ 3 ), + /* Skip to: COMMA OR RIGHT PAREN */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00001080, /* counter: */ 3 ), - /* Skip to: COLON OR SEMICOLON */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001006, /* counter: */ 3 ), + /* Skip to: COLON OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001006, /* counter: */ 3 ), - /* Skip to: IMPORT OR BLOCK */ - TokenSet.newFromRawData( /* bits: */ 0x21122090, 0x000000a0, 0x00001000, /* counter: */ 10 ), + /* Skip to: IMPORT OR BLOCK */ + TokenSet.newFromRawData( /* bits: */ 0x21122090, 0x000000a0, 0x00001000, /* counter: */ 10 ), - /* Skip to: DECLARATION OR IDENT OR SEMICOLON */ - TokenSet.newFromRawData( /* bits: */ 0x21000080, 0x000004a0, 0x00001004, /* counter: */ 8 ), + /* Skip to: DECLARATION OR IDENT OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x21000080, 0x000004a0, 0x00001004, /* counter: */ 8 ), - /* Skip to: DECLARATION OR SEMICOLON */ - TokenSet.newFromRawData( /* bits: */ 0x21000080, 0x000000a0, 0x00001004, /* counter: */ 7 ), + /* Skip to: DECLARATION OR SEMICOLON */ + TokenSet.newFromRawData( /* bits: */ 0x21000080, 0x000000a0, 0x00001004, /* counter: */ 7 ), - /* Skip to: FIRST OR FOLLOW OF STATEMENT */ - TokenSet.newFromRawData( /* bits: */ 0x00457840, 0x00000743, 0x00001024, /* counter: */ 17 ), + /* Skip to: FIRST OR FOLLOW OF STATEMENT */ + TokenSet.newFromRawData( /* bits: */ 0x00457840, 0x00000743, 0x00001024, /* counter: */ 17 ), + + /* Skip to: ELSIF OR ELSE OR END */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000000, 0x00001000, /* counter: */ 4 ), - /* Skip to: ELSIF OR ELSE OR END */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000000, 0x00001000, /* counter: */ 4 ), - - /* Skip to: FOR LOOP BODY */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000000, 0x00001000, /* counter: */ 2 ) + /* Skip to: FOR LOOP BODY */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000000, 0x00001000, /* counter: */ 2 ) }; #endregion - /* *************************************************************************** +/* *************************************************************************** END of code auto-generated by GenResyncSets ***************************************************************************/ - /* -------------------------------------------------------------------------- - * method Count() -- Returns the number of productions - * ----------------------------------------------------------------------- */ - - static uint Count() { - return (uint)Enum.GetNames(typeof(Production)).Length; - } /* end Count */ - - - /* -------------------------------------------------------------------------- - * method IsOptionDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on any compiler option, else false. - * ----------------------------------------------------------------------- */ - - bool IsOptionDependent(Production p) { - return p >= firstOptionDependent; - } /* end IsOptionDependent */ - - - /* -------------------------------------------------------------------------- - * method IsConstParamDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on CONST parameter option, else false. - * ----------------------------------------------------------------------- */ - - bool IsConstParamDependent(Production p) +/* -------------------------------------------------------------------------- + * method Count() -- Returns the number of productions + * ----------------------------------------------------------------------- */ + + static uint Count() { + return (uint)Enum.GetNames(typeof(Production)).Length; + } /* end Count */ + + +/* -------------------------------------------------------------------------- + * method IsOptionDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on any compiler option, else false. + * ----------------------------------------------------------------------- */ + bool IsOptionDependent(Production p) { + return p >= firstOptionDependent; + } /* end IsOptionDependent */ + + +/* -------------------------------------------------------------------------- + * method IsConstParamDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on CONST parameter option, else false. + * ----------------------------------------------------------------------- */ + + bool IsConstParamDependent(Production p) + { + return p >= firstConstParamDependent && p <= lastConstParamDependent; + } /* end IsConstParamDependent */ + + +/* -------------------------------------------------------------------------- + * method IsVariantRecordDependent(p) + * -------------------------------------------------------------------------- + * Returns true if p is dependent on variant record type option, else false. + * ----------------------------------------------------------------------- */ + + bool IsVariantRecordDependent(Production p) { + return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; + } + +/* -------------------------------------------------------------------------- + * method FIRST(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FIRST set of production p. + * ----------------------------------------------------------------------- */ + + TokenSet FIRST(Production p) { + TokenSet tokenset = null; + uint index = 0; + if (IsConstParamDependent(p)) { - return p >= firstConstParamDependent && p <= lastConstParamDependent; - } /* end IsConstParamDependent */ - - - /* -------------------------------------------------------------------------- - * method IsVariantRecordDependent(p) - * -------------------------------------------------------------------------- - * Returns true if p is dependent on variant record type option, else false. - * ----------------------------------------------------------------------- */ - - bool IsVariantRecordDependent(Production p) { - return p >= firstNoVariantRecDependent && p <= lastNoVariantRecDependent; - } - - /* -------------------------------------------------------------------------- - * method FIRST(p) - * -------------------------------------------------------------------------- - * Returns a tokenset with the FIRST set of production p. - * ----------------------------------------------------------------------- */ - - TokenSet FIRST(Production p) { - TokenSet tokenset = null; - uint index = 0; - - if (IsConstParamDependent(p)) - { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) - { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - - tokenset = firstSets[index]; - - return tokenset; - } /* end FIRST */ + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && CompilerOptions.VariantRecords()) + { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + tokenset = firstSets[index]; + return tokenset; + } /* end FIRST */ - /* -------------------------------------------------------------------------- - * method FOLLOW(p) - * -------------------------------------------------------------------------- - * Returns a tokenset with the FOLLOW set of production p. - * ----------------------------------------------------------------------- */ - TokenSet FOLLOW(Production p) { - TokenSet tokenset = null; - uint index = 0; +/* -------------------------------------------------------------------------- + * method FOLLOW(p) + * -------------------------------------------------------------------------- + * Returns a tokenset with the FOLLOW set of production p. + * ----------------------------------------------------------------------- */ - if (IsConstParamDependent(p)) { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ - if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { - index = Convert.ToUInt32(p) + alternateSetOffset; - } /* end if */ + TokenSet FOLLOW(Production p) { + TokenSet tokenset = null; + uint index = 0; - tokenset = followSets[index]; + if (IsConstParamDependent(p)) { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ + if (IsVariantRecordDependent(p) && !CompilerOptions.VariantRecords()) { + index = Convert.ToUInt32(p) + alternateSetOffset; + } /* end if */ - return tokenset; - } /* end FOLLOW */ + tokenset = followSets[index]; + return tokenset; + } /* end FOLLOW */ - /* -------------------------------------------------------------------------- - * method NameForProduction(p) - * -------------------------------------------------------------------------- - * Returns a string with a human readable name for production p. - * ----------------------------------------------------------------------- */ - string NameForProduction(Production p); +/* -------------------------------------------------------------------------- + * method NameForProduction(p) + * -------------------------------------------------------------------------- + * Returns a string with a human readable name for production p. + * ----------------------------------------------------------------------- */ + string NameForProduction(Production p); From f2c61fc71323887775abf886eb74c4246bada37d Mon Sep 17 00:00:00 2001 From: SamDelaney Date: Mon, 29 May 2017 14:11:44 -0700 Subject: [PATCH 24/24] Add files via upload --- imp/NonTerminals.cs | 432 +++++++++++++++++++++++++++++--------------- 1 file changed, 288 insertions(+), 144 deletions(-) diff --git a/imp/NonTerminals.cs b/imp/NonTerminals.cs index f11409c..5ddf9a2 100644 --- a/imp/NonTerminals.cs +++ b/imp/NonTerminals.cs @@ -71,149 +71,221 @@ use the GenFirstSet utility to regenerate this code section and paste it. #region first sets TokenSet[] firstSets = { - TokenSet.newFromRawData( /* bits: */ 0x00000100, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000100, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* definitionModule */ - TokenSet.newFromRawData( /* bits: */ 0x00120000, 0x00000000, 0x00000000, /* counter: */ 2 ), /* import */ + TokenSet.newFromRawData( /* bits: */ 0x00120000, + 0x00000000, 0x00000000, /* counter: */ 2 ), /* import */ - TokenSet.newFromRawData( /* bits: */ 0x00100000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* qualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00100000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* qualifiedImport */ - TokenSet.newFromRawData( /* bits: */ 0x00020000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* unqualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00020000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* unqualifiedImport */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* identList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* identList */ - TokenSet.newFromRawData( /* bits: */ 0x20000080, 0x000000a0, 0x00000000, /* counter: */ 4 ), /* definition */ + TokenSet.newFromRawData( /* bits: */ 0x20000080, + 0x000000a0, 0x00000000, /* counter: */ 4 ), /* definition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* constDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* constDefinition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* typeDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* typeDefinition */ - TokenSet.newFromRawData( /* bits: */ 0xb0000008, 0x00000404, 0x00000140, /* counter: */ 8 ), /* type */ + TokenSet.newFromRawData( /* bits: */ 0xb0000008, + 0x00000404, 0x00000140, /* counter: */ 8 ), /* type */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000100, /* counter: */ 2 ), /* derivedOrSubrangeType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000100, /* counter: */ 2 ), /* derivedOrSubrangeType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* qualident */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* qualident */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* range */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000100, /* counter: */ 1 ), /* range */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* enumType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000040, /* counter: */ 1 ), /* enumType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000004, 0x00000000, /* counter: */ 1 ), /* setType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000004, 0x00000000, /* counter: */ 1 ), /* setType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000140, /* counter: */ 3 ), /* countableType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000140, /* counter: */ 3 ), /* countableType */ - TokenSet.newFromRawData( /* bits: */ 0x00000008, 0x00000000, 0x00000000, /* counter: */ 1 ), /* arrayType */ + TokenSet.newFromRawData( /* bits: */ 0x00000008, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* arrayType */ - TokenSet.newFromRawData( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* extensibleRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x80000000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* extensibleRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* fieldListSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* fieldListSequence */ - TokenSet.newFromRawData( /* bits: */ 0x80000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x80000000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000400, 0x00000000, /* counter: */ 2 ), /* variantFieldListSeq */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, + 0x00000400, 0x00000000, /* counter: */ 2 ), /* variantFieldListSeq */ - TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000400, 0x00000000, /* counter: */ 2 ), /* variantFieldList */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, + 0x00000400, 0x00000000, /* counter: */ 2 ), /* variantFieldList */ - TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantFields */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* variantFields */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* variant */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, + 0x00187c00, 0x00000440, /* counter: */ 10 ), /* variant */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* caseLabelList */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, + 0x00187c00, 0x00000440, /* counter: */ 10 ), /* caseLabelList */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* caseLabels */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, + 0x00187c00, 0x00000440, /* counter: */ 10 ), /* caseLabels */ - TokenSet.newFromRawData( /* bits: */ 0x10000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* pointerType */ + TokenSet.newFromRawData( /* bits: */ 0x10000000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* pointerType */ - TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureType */ + TokenSet.newFromRawData( /* bits: */ 0x20000000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureType */ - TokenSet.newFromRawData( /* bits: */ 0x00000008, 0x00000400, 0x00000000, /* counter: */ 2 ), /* simpleFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000008, + 0x00000400, 0x00000000, /* counter: */ 2 ), /* simpleFormalType */ - TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureHeader */ + TokenSet.newFromRawData( /* bits: */ 0x20000000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureHeader */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* procedureSignature */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* procedureSignature */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* simpleFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* simpleFormalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00080000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* implementationModule */ + TokenSet.newFromRawData( /* bits: */ 0x00080000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* implementationModule */ - TokenSet.newFromRawData( /* bits: */ 0x01000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* programModule */ + TokenSet.newFromRawData( /* bits: */ 0x01000000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* programModule */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000100, /* counter: */ 1 ), /* modulePriority */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000100, /* counter: */ 1 ), /* modulePriority */ - TokenSet.newFromRawData( /* bits: */ 0x21002090, 0x000000a0, 0x00000000, /* counter: */ 7 ), /* block */ + TokenSet.newFromRawData( /* bits: */ 0x21002090, + 0x000000a0, 0x00000000, /* counter: */ 7 ), /* block */ - TokenSet.newFromRawData( /* bits: */ 0x21000080, 0x000000a0, 0x00000000, /* counter: */ 5 ), /* declaration */ + TokenSet.newFromRawData( /* bits: */ 0x21000080, + 0x000000a0, 0x00000000, /* counter: */ 5 ), /* declaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* typeDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* typeDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000080, 0x00000000, /* counter: */ 1 ), /* varSizeRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000080, 0x00000000, /* counter: */ 1 ), /* varSizeRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* variableDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* variableDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x20000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x20000000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* procedureDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x01000000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* moduleDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x01000000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* moduleDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00008000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* export */ + TokenSet.newFromRawData( /* bits: */ 0x00008000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* export */ - TokenSet.newFromRawData( /* bits: */ 0x00454040, 0x00000703, 0x00000000, /* counter: */ 10 ), /* statementSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00454040, + 0x00000703, 0x00000000, /* counter: */ 10 ), /* statementSequence */ - TokenSet.newFromRawData( /* bits: */ 0x00454040, 0x00000703, 0x00000000, /* counter: */ 10 ), /* statement */ + TokenSet.newFromRawData( /* bits: */ 0x00454040, + 0x00000703, 0x00000000, /* counter: */ 10 ), /* statement */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* assignmentOrProcCall */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* assignmentOrProcCall */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000040, /* counter: */ 1 ), /* actualParameters */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000040, /* counter: */ 1 ), /* actualParameters */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* expressionList */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, + 0x00187c00, 0x00000440, /* counter: */ 10 ), /* expressionList */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000002, 0x00000000, /* counter: */ 1 ), /* returnStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000002, 0x00000000, /* counter: */ 1 ), /* returnStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000200, 0x00000000, /* counter: */ 1 ), /* withStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000200, 0x00000000, /* counter: */ 1 ), /* withStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00040000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* ifStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00040000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* ifStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00000040, 0x00000000, 0x00000000, /* counter: */ 1 ), /* caseStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000040, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* caseStatement */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* case */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, + 0x00187c00, 0x00000440, /* counter: */ 10 ), /* case */ - TokenSet.newFromRawData( /* bits: */ 0x00400000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* loopStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00400000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* loopStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000100, 0x00000000, /* counter: */ 1 ), /* whileStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000100, 0x00000000, /* counter: */ 1 ), /* whileStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000001, 0x00000000, /* counter: */ 1 ), /* repeatStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000001, 0x00000000, /* counter: */ 1 ), /* repeatStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00010000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* forStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00010000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* forStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* designator */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* designator */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000111, /* counter: */ 3 ), /* selector */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000111, /* counter: */ 3 ), /* selector */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* expression */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, + 0x00187c00, 0x00000440, /* counter: */ 10 ), /* expression */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* simpleExpression */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, + 0x00187c00, 0x00000440, /* counter: */ 10 ), /* simpleExpression */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00007c00, 0x00000440, /* counter: */ 8 ), /* term */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, + 0x00007c00, 0x00000440, /* counter: */ 8 ), /* term */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00007c00, 0x00000440, /* counter: */ 8 ), /* simpleTerm */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, + 0x00007c00, 0x00000440, /* counter: */ 8 ), /* simpleTerm */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00007c00, 0x00000440, /* counter: */ 7 ), /* factor */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00007c00, 0x00000440, /* counter: */ 7 ), /* factor */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* designatorOrFuncCall */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* designatorOrFuncCall */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000400, /* counter: */ 1 ), /* setValue */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000400, /* counter: */ 1 ), /* setValue */ - TokenSet.newFromRawData( /* bits: */ 0x02000000, 0x00187c00, 0x00000440, /* counter: */ 10 ), /* element */ + TokenSet.newFromRawData( /* bits: */ 0x02000000, + 0x00187c00, 0x00000440, /* counter: */ 10 ), /* element */ - TokenSet.newFromRawData( /* bits: */ 0x00000088, 0x00000480, 0x00000000, /* counter: */ 4 ), /* formalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000088, + 0x00000480, 0x00000000, /* counter: */ 4 ), /* formalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000080, 0x00000000, /* counter: */ 2 ), /* attributedFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, + 0x00000080, 0x00000000, /* counter: */ 2 ), /* attributedFormalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000480, 0x00000000, /* counter: */ 3 ), /* formalParamList */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, + 0x00000480, 0x00000000, /* counter: */ 3 ), /* formalParamList */ - TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000480, 0x00000000, /* counter: */ 3 ), /* formalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, + 0x00000480, 0x00000000, /* counter: */ 3 ), /* formalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000080, 0x00000080, 0x00000000, /* counter: */ 2 ), /* attribFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000080, + 0x00000080, 0x00000000, /* counter: */ 2 ), /* attribFormalParams */ - TokenSet.newFromRawData( /* bits: */ 0xb0000008, 0x00000484, 0x00000140, /* counter: */ 9 ), /* typeDeclarationTail */ + TokenSet.newFromRawData( /* bits: */ 0xb0000008, + 0x00000484, 0x00000140, /* counter: */ 9 ), /* typeDeclarationTail */ }; #endregion @@ -230,149 +302,221 @@ use the GenFirstSet utility to regenerate this code section and paste it. #region follow sets TokenSet[] followSets = { - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* definitionModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00001000, /* counter: */ 1 ), /* definitionModule */ - TokenSet.newFromRawData( /* bits: */ 0x2100a190, 0x000000a0, 0x00000000, /* counter: */ 9 ), /* import */ + TokenSet.newFromRawData( /* bits: */ 0x2100a190, + 0x000000a0, 0x00000000, /* counter: */ 9 ), /* import */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* qualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* qualifiedImport */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* unqualifiedImport */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* unqualifiedImport */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000086, /* counter: */ 3 ), /* identList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000086, /* counter: */ 3 ), /* identList */ - TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ + TokenSet.newFromRawData( /* bits: */ 0x00002000, + 0x00000000, 0x00000000, /* counter: */ 1 ), /* definition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* constDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* constDefinition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDefinition */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDefinition */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* type */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* type */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* derivedOrSubrangeType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* derivedOrSubrangeType */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80058, 0x00000dec, /* counter: */ 34 ), /* qualident */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, + 0xdff80058, 0x00000dec, /* counter: */ 34 ), /* qualident */ - TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* range */ + TokenSet.newFromRawData( /* bits: */ 0x04000000, + 0x80000000, 0x00000004, /* counter: */ 3 ), /* range */ - TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* enumType */ + TokenSet.newFromRawData( /* bits: */ 0x04000000, + 0x80000000, 0x00000004, /* counter: */ 3 ), /* enumType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* setType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* setType */ - TokenSet.newFromRawData( /* bits: */ 0x04000000, 0x80000000, 0x00000004, /* counter: */ 3 ), /* countableType */ + TokenSet.newFromRawData( /* bits: */ 0x04000000, + 0x80000000, 0x00000004, /* counter: */ 3 ), /* countableType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* arrayType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* arrayType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* extensibleRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* extensibleRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00002000, 0x00000080, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00002000, + 0x00000080, 0x00000000, /* counter: */ 2 ), /* fieldListSequence */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* variantRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* variantRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* variantFieldListSeq */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, + 0x00000000, 0x00000020, /* counter: */ 3 ), /* variantFieldListSeq */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000024, /* counter: */ 4 ), /* variantFieldList */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, + 0x00000000, 0x00000024, /* counter: */ 4 ), /* variantFieldList */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000024, /* counter: */ 4 ), /* variantFields */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, + 0x00000000, 0x00000024, /* counter: */ 4 ), /* variantFields */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* variant */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, + 0x00000000, 0x00000020, /* counter: */ 3 ), /* variant */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000002, /* counter: */ 1 ), /* caseLabelList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000002, /* counter: */ 1 ), /* caseLabelList */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000002, /* counter: */ 2 ), /* caseLabels */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x80000000, 0x00000002, /* counter: */ 2 ), /* caseLabels */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* pointerType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* pointerType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* simpleFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x80000000, 0x00000080, /* counter: */ 2 ), /* simpleFormalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureHeader */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureHeader */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureSignature */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureSignature */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* simpleFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000084, /* counter: */ 2 ), /* simpleFormalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* implementationModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00001000, /* counter: */ 1 ), /* implementationModule */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00001000, /* counter: */ 1 ), /* programModule */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00001000, /* counter: */ 1 ), /* programModule */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* modulePriority */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* modulePriority */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000400, 0x00000000, /* counter: */ 1 ), /* block */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000400, 0x00000000, /* counter: */ 1 ), /* block */ - TokenSet.newFromRawData( /* bits: */ 0x00002010, 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ + TokenSet.newFromRawData( /* bits: */ 0x00002010, + 0x00000000, 0x00000000, /* counter: */ 2 ), /* declaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* varSizeRecordType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* varSizeRecordType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* variableDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* variableDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* procedureDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* moduleDeclaration */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* moduleDeclaration */ - TokenSet.newFromRawData( /* bits: */ 0x21002090, 0x000000a0, 0x00000000, /* counter: */ 7 ), /* export */ + TokenSet.newFromRawData( /* bits: */ 0x21002090, + 0x000000a0, 0x00000000, /* counter: */ 7 ), /* export */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000020, /* counter: */ 5 ), /* statementSequence */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000020, /* counter: */ 5 ), /* statementSequence */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* statement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* statement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* assignmentOrProcCall */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* assignmentOrProcCall */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* actualParameters */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* actualParameters */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000080, /* counter: */ 1 ), /* expressionList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000080, /* counter: */ 1 ), /* expressionList */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* returnStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* returnStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* withStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* withStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* ifStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* ifStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* caseStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* caseStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00002800, 0x00000000, 0x00000020, /* counter: */ 3 ), /* case */ + TokenSet.newFromRawData( /* bits: */ 0x00002800, + 0x00000000, 0x00000020, /* counter: */ 3 ), /* case */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* loopStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* loopStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* whileStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* whileStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* repeatStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* repeatStatement */ - TokenSet.newFromRawData( /* bits: */ 0x00003800, 0x00000040, 0x00000024, /* counter: */ 6 ), /* forStatement */ + TokenSet.newFromRawData( /* bits: */ 0x00003800, + 0x00000040, 0x00000024, /* counter: */ 6 ), /* forStatement */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80058, 0x00000cec, /* counter: */ 33 ), /* designator */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, + 0xdff80058, 0x00000cec, /* counter: */ 33 ), /* designator */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0xdff80458, 0x00000cec, /* counter: */ 34 ), /* selector */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, + 0xdff80458, 0x00000cec, /* counter: */ 34 ), /* selector */ - TokenSet.newFromRawData( /* bits: */ 0x04003c20, 0x80000058, 0x000008ac, /* counter: */ 15 ), /* expression */ + TokenSet.newFromRawData( /* bits: */ 0x04003c20, + 0x80000058, 0x000008ac, /* counter: */ 15 ), /* expression */ - TokenSet.newFromRawData( /* bits: */ 0x04203c20, 0x87e00058, 0x000008ac, /* counter: */ 22 ), /* simpleExpression */ + TokenSet.newFromRawData( /* bits: */ 0x04203c20, + 0x87e00058, 0x000008ac, /* counter: */ 22 ), /* simpleExpression */ - TokenSet.newFromRawData( /* bits: */ 0x0c203c20, 0x87f80058, 0x000008ac, /* counter: */ 25 ), /* term */ + TokenSet.newFromRawData( /* bits: */ 0x0c203c20, + 0x87f80058, 0x000008ac, /* counter: */ 25 ), /* term */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* simpleTerm */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, + 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* simpleTerm */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* factor */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, + 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* factor */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* designatorOrFuncCall */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, + 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* designatorOrFuncCall */ - TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* setValue */ + TokenSet.newFromRawData( /* bits: */ 0x0ca03e22, + 0x9ff80058, 0x000008ac, /* counter: */ 30 ), /* setValue */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000800, /* counter: */ 2 ), /* element */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x80000000, 0x00000800, /* counter: */ 2 ), /* element */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* formalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x80000000, 0x00000080, /* counter: */ 2 ), /* formalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x80000000, 0x00000080, /* counter: */ 2 ), /* attributedFormalType */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x80000000, 0x00000080, /* counter: */ 2 ), /* attributedFormalType */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000080, /* counter: */ 1 ), /* formalParamList */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000080, /* counter: */ 1 ), /* formalParamList */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* formalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000084, /* counter: */ 2 ), /* formalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000084, /* counter: */ 2 ), /* attribFormalParams */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000084, /* counter: */ 2 ), /* attribFormalParams */ - TokenSet.newFromRawData( /* bits: */ 0x00000000, 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDeclarationTail */ + TokenSet.newFromRawData( /* bits: */ 0x00000000, + 0x00000000, 0x00000004, /* counter: */ 1 ), /* typeDeclarationTail */ }; #endregion