jwajgelt / sernick Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Regex -> Regex<TAtom>
IDfa<TState> -> IDfa<TState, TAtom>
Implement type checking.
The inputs are the AST of the program, and the result of name resolution.
The result is a mapping Expression (ASTNode) -> Type
, defining the type for each expression.
The possible errors are:
Add the type checking step to the compiler frontend
Using the action table, Parser should compute a ParseTree for a sequence of token categories given as leaves on the input.
static Regex.Atom(char): Regex
static Regex.Union(IEnumerable<Regex>): Regex
static Regex.Concat(IEnumerable<Regex>): Regex
static Regex.Star(Regex): Regex)
X \cup X == X
X \cup Y == Y \cup X
(X \cup Y) \cup Z == X \cup (Y \cup Z)
\empty \cup X == X
\neg\empty \cup X == \neg\empty
(XY)Z == X(YZ)
\empty * X == X * \empty == \empty
\eps * X == X * \eps == X
X^^ == X^
\eps^ == \empty^ = \eps
\neg(\neg X) == X
Based on our Language notes in #1 , let's divide test into 8 roughly equal parts:
{}
and ()
, introducing new scope only by {}
-- @LukaszSelwaEach part/suite should contain not less than 5 good and 5 bad examples of code (remember, we use .ser
extension)
Implement Equals
and GetHashCode
methods for every class inheriting from Regex
class (AtomRegex, StarRegex, UnionRegex, ConcatRegex).
Methods assume that Regexes are normalized and compare them structurally.
Change IInput Interface
and change StringInput implementation,
IInput
proposition
public interface IInput
{
/// <summary>
/// Advances input to the next element.
/// Upon creation input is positioned on the Start location.
/// </summary>
/// <returns>
/// false if after execution input's location points to End;
/// true otherwise
/// </returns>
bool MoveNext();
void MoveTo(ILocation location);
ILocation CurrentLocation { get; }
/// <summary>
/// Returns the location of the first char in input.
/// </summary>
ILocation Start { get; }
/// <summary>
/// Returns location after the last character in input.
/// </summary>
ILocation End { get; }
}
The method takes a Grammar and prepares all data needed for the constructor call:
Provide implementation for visitor VariableAccessVisitor
, it should (based on AST) construct VariableAccessMap
which can:
Write integration tests checking the example sernick programs checking for:
Implement and test public methods of RegexDfa class.
RegexDfa should work as described in the first lecture (please see slides "Alternatywna Konstrukcja RE -> DFA")
Additionally, merge IDfaWithConfig into IDfa.
Create a skeleton hierarchy of the future AST nodes (e.g. Expression
, FunctionDefinition
, FunctionArgument
etc.). The base class is Parser.Ast.AstNode
Diagnostics
and Diagnostic
classes (+Severity
enum)ASTNode
base classGrammar<TSymbol>
and Production<TSymbol>
classesDfaGrammar<TSymbol, TState>
class.Nullable()
, .First()
, and .Follow()
/* comment */
const a = 5;
/* comment */
is being parsed as a single comment (from the first char till the last)
For each type NodeType
implementing ASTNode
, add a method public TResult visitNodeType(NodeType node, TParam param)
, with the default implementation delegating to visitNodeSuperType(node, param)
, where NodeSuperType
is the immediate supertype of NodeType
in the ASTNode
types' hierarchy.
While empty input produces a non-null parse tree, it is not clear what are Start
and End
of that tree, because there is nowhere to get them from
Test these three methods separately - i.e. for the test grammar
NULLABLE
manuallygrammar.Nullable()
generates a correct set of symbols (=NULLABLE
)FIRST(A)
manuallygrammar.First(NULLABLE)
generates a correct function of symbols (=FIRST(A)
)FOLLOW(A)
manuallygrammar.Follow(NULLABLE, FIRST)
generates a correct function of symbols (=FOLLOW(A)
)Implement FuctionPreprocessVisitor
which should construct a map from FunctionDefinition
s (AstNode
) to IFunctionContext
(in the future it will provide functionalities for generating function's code).
Consult StringToRegex API and create Regular Expressions for categories needed in Sernick.
Decide how we store categories (Enum or classes inhering from abstract category class).
We need categories for:
We will probably have to decide on categories priorities (eg, that keywords have bigger priority then identificators)
Inlcude more specific details (e.g. alternative next symbols)
Once implementations of Nullable
, First
and Follow
are completed, unskip all tests
Implement First
method in Grammar.Dfa.GrammarAnalysis
. It should return a Dict<Symbol, Set<Symbol>>
Details in 02-parsing.pdf
lecture slides
Consult and implement API of StringToRegex class
How to reproduce:
CompilerFrontendTest.cs
testsIssue:
Expression -> X1 -> X2 -> X3 -> Expression
Shift/reduce conflict between symbol Semicolon(;) and production X3 -> Expression | X3*BinaryOperatorPriority3*Expression
Implement and test methods ContainsEpsilon
and Derivative
for every class inheriting from Regex
Base abstract class Regex
(in Sernick.Compiler
namespace? take care of some initial folder structure as well please)
Prepare a hierarchy of CodeTree
nodes such that they represent all low level operations sufficient to represent sernick's functionality (without control flow).
LexicalError : IDiagnosticItem { Start, End: ILocation }
Lexer.Process()
so that it reports any error it finds to diagnostics
ReadFile
method in Utility.FileUtility
FakeDiagnostics
class, which makes checking if some specific error was reported easierIInput
, executes a frontend compilation pass, and returns a FakeDiagnostics
objectDiagnostics
classMain.cs
(mind that C# doesn't require explicit main() function)
IInput
Add mention about true/false
and Int literals
Test the implementation of Parser using simple grammars and inputs and compare the resulting ParseTree to what is expected.
Implement Follow
method in Grammar.Dfa.GrammarAnalysis
. It should return a Dict<Symbol, Set<Symbol>>
Details in 02-parsing.pdf
lecture slides
Prepare inputs that represent hard cases in AST - > CFG conversion.
For each use of a variable x
, we need to know where that variable was defined (either via a new variable binding var x
, or a function parameter binding fun f(x){...}
).
For each function call f()
we need to know where that function was defined.
The result of the name resolution are three mappings:
variable use -> variable declaration | function parameter
variable assignment -> variable declaration
function call -> function declaration
Note: the variable and function names live in the same namespace - new function declarations can shadow variable declarations from previous scopes, and the other way around. It's illegal to declare a function and a variable using the same identifier in a single scope.
Errors to be returned:
To be implemented using the ASTVisitor
, using the functional algorithm presented at the lecture.
Add the name resolution step to the compiler frontend.
Currently in our AST we have some of our variable declarations outside any function, which won't work well with our approach.
So, there is a need to somehow change AST so the whole body of the program will be treated as a function, my proposal:
Expression
into a FuctionDefinition
(probably named "" [empty string])FunctionDefinition
, and main FunctionCall
Tests for IDfa
need to be expanded to handle new methods
AcceptingStates
GetTransitionsFrom(state)
GetTransitionsTo(state)
Implement Nullable
method in Grammar.Dfa.GrammarAnalysis
. It should return a set of symbols
Details in 02-parsing.pdf
lecture slides
Provide implementation for CallGraphVisitor
so it extracts call graph from our AST
Implement public methods and constructor of StringInput class.
Write unit tests for StringInput class
Mention that in docs and in tests (if not yet present)
The private constructor should compute the action table for parser's processing.
Implement Lexer class
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.