-
Notifications
You must be signed in to change notification settings - Fork 3
TokenSet, First(), Follow() #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SamDelaney
wants to merge
26
commits into
m2sf:master
Choose a base branch
from
SamDelaney:SamDelaney-TokenSet_Final
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
dffb119
Add files via upload
SamDelaney 918822b
Add files via upload
SamDelaney ee593ed
Add files via upload
SamDelaney 8fcfa66
Add files via upload
SamDelaney 0920cbe
Add files via upload
SamDelaney dfee09a
Add files via upload
SamDelaney 3f81c9d
Delete TokenSet.cs
SamDelaney 61a32f4
Delete Terminals.cs
SamDelaney 24a7263
Delete NonTerminals.cs
SamDelaney be294dc
Add files via upload
SamDelaney e9f9daa
Add files via upload
SamDelaney 5e24145
Delete Terminals.cs
SamDelaney 6498963
Delete TokenSet.cs
SamDelaney 8c2983c
Delete NonTerminals.cs
SamDelaney 95b4e53
Add files via upload
SamDelaney 1bb9c75
Delete NonTerminals.cs
SamDelaney 174cb31
Delete Terminals.cs
SamDelaney 39198dd
Delete TokenSet.cs
SamDelaney 914bc6d
Merge branch 'master' into SamDelaney-TokenSet_Final
SamDelaney e04144b
Add files via upload
SamDelaney 26f5b85
Add files via upload
SamDelaney a14c66c
Add files via upload
SamDelaney 4c63fa4
Add files via upload
SamDelaney eb26eb0
Merge pull request #1 from SamDelaney/master
SamDelaney 27bbaf7
Add files via upload
SamDelaney f2c61fc
Add files via upload
SamDelaney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| /* M2Sharp -- Modula-2 to C# Translator & Compiler | ||
| * | ||
| * Copyright (c) 2016 The Modula-2 Software Foundation | ||
| * | ||
| * Author & Maintainer: Benjamin Kowarsch <trijezdci@org.m2sf> | ||
| * | ||
| * @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 <https://www.gnu.org/copyleft/lesser.html>. | ||
| * | ||
| * 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 */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove all the
//SAM CHANGEcomments. They have no documentary value for users and maintainers. For any temporary comments during review, we can use Github annotation features.