示例#1
0
/* --------------------------------------------------------------------------
 * 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 */
示例#2
0
        } /* end IsSubset */

/* --------------------------------------------------------------------------
 * method IsDisjunct(set)
 * --------------------------------------------------------------------------
 * Returns true if set has no common elements with the receiver, else false.
 * ----------------------------------------------------------------------- */

        public bool IsDisjunct(TokenSet set)
        {
            /* steps through each segment */
            for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
            {
                /* checks if the corresponding  segments of two sets are disjunct */
                if ((set.dataStored.segments[segmentIndex]
                     & this.dataStored.segments[segmentIndex]) != 0)
                {
                    return(false);
                } /* end if */
            }     /* end for */

            return(true);
        } /* end IsDisjunct */
示例#3
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)
        {
            /* steps through each segment */
            for (uint segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
            {
                /* checks if a segment is a subset of the reciever's same segment */
                if (((set.dataStored.segments[segmentIndex]
                      & this.dataStored.segments[segmentIndex]
                      ^ this.dataStored.segments[segmentIndex]) != 0))
                {
                    return(false);
                } /* end if */
            }     /* end for */

            return(true);
        } /* end IsSubset */
示例#4
0
        } /* 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();

            /* allocate new set */
            newSet.dataStored.segments = new uint[segmentCount];

            /* initialise */
            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
示例#5
0
        /* end TokenSet */



/* --------------------------------------------------------------------------
 * 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();

            /* allocate new set */
            newSet.dataStored.segments = new uint[segmentCount];

            /* initialise */
            uint counter = 0;

            /* check against invalid input */
            if (args.Length != segmentCount + 1)
            {
                return(null);
            } /* end if */

            if (args[segmentCount] > segmentCount * 32)
            {
                return(null);
            } /* end if */

            /* count elements */
            for (int segmentIndex = args.Length - 2;
                 segmentIndex >= 0; segmentIndex--)
            {
                for (int bitIndex = 0; bitIndex < 32; bitIndex++)
                {
                    if ((args[segmentIndex] & (1 << bitIndex)) == (1 << bitIndex))
                    {
                        counter++;
                    }
                } /* end for */

                newSet.dataStored.segments[segmentIndex] = args[segmentIndex];
            } /* end for */

            /* check against inconsistent counter */
            if (counter != args[segmentCount])
            {
                return(null);
            } /* end if */

            /* update element counter */
            newSet.dataStored.elemCount = args[segmentCount];

            return(newSet);
        } /* end newFromData */
示例#6
0
        } /* end PrintLiteral */

/* --------------------------------------------------------------------------
 * method CountBits()
 * --------------------------------------------------------------------------
 * Returns the number of set bits in set.
 * ----------------------------------------------------------------------- */

        static private uint CountBits(TokenSet set)
        {
            int  bit;
            uint segmentIndex,
                 bitCount = 0;

            /* step through each segement */
            for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
            {
                /* count bits in the segment */
                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 */
示例#7
0
        } /* end newFromData */

/* --------------------------------------------------------------------------
 * 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 */
示例#8
0
        public static List <String> genSets()
        {
            List <String> lines = new List <String>();
            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 */
示例#9
0
        public static List <String> genSets()
        {
            TokenSet      set;
            List <String> lines = new List <String>();

            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);
        }