private void PrintAction(IReportData data, SymbolBase symbol, StreamWriter output, ParserAction action) { if (action == null || action.Kind == ParserActionKind.Fail) { return; } output.Write(Indent); output.Write(symbol.Name); output.Write(" "); switch (action.Kind) { case ParserActionKind.Shift: output.Write("shift and go to state "); output.Write(action.State); break; case ParserActionKind.Reduce: output.Write("reduce using rule "); output.Write(action.ProductionId); break; case ParserActionKind.ShiftReduce: output.Write("shift-reduce using rule "); output.Write(action.ProductionId); break; case ParserActionKind.Accept: output.WriteLine("accept"); break; } output.WriteLine(); }
public static bool NeedCallThis(SymbolBase symbol) { if (symbol is SymbolLocalVar) { return(false); } else if (symbol is SymbolArg) { return(false); } else if (symbol is SymbolDefProperty) { SymbolDefProperty symbol2 = (symbol as SymbolDefProperty); return(symbol2.IsStatic == false); } else if (symbol is SymbolDefField) { SymbolDefField symbol2 = (symbol as SymbolDefField); return(symbol2.IsStatic == false); } else if (symbol is SymbolRefStaticMember) { return(false); } else { throw new CompileException(); } }
public static void EmitStorm(ILGenerator il, SymbolBase symbol) { if (symbol is SymbolLocalVar) { var symbolVar = symbol as SymbolLocalVar; EmitHelper.StormVar(il, symbolVar.VarBuilder); } else if (symbol is SymbolArg) { SymbolArg argsymbol = (symbol as SymbolArg); EmitHelper.StormArg(il, argsymbol.ArgIndex); } else if (symbol is SymbolDefProperty) { SymbolDefProperty symbol2 = (symbol as SymbolDefProperty); MethodInfo setMethod = symbol2.Property.GetSetMethod(); EmitHelper.CallDynamic(il, setMethod); } else if (symbol is SymbolDefField) { SymbolDefField symbol2 = (symbol as SymbolDefField); EmitHelper.StormField(il, symbol2.Field); } else if (symbol is SymbolRefStaticMember) { EmitStorm(il, symbol as SymbolRefStaticMember); } else { throw new CompileException(); } }
private string SymbolToHtml(SymbolBase symbol) { var result = HttpUtility.HtmlEncode(symbol.Name); result = result.Replace("{", "{"); result = result.Replace("}", "}"); return(result); }
protected SymbolBaseSurrogate(SymbolBase symbol) { Path = symbol.Path.ToString(); Name = symbol.Name; FullName = symbol.FullName; Type = symbol.Type; Location = symbol.Location; }
public void AddSymbol(SymbolBase symbol) { if (mSymbols == null) { mSymbols = new SymbolCollection(); } mSymbols.Add(symbol); ShowSymbol(symbol); }
public Exp AnalyDim() { SymbolLocalVar localVarSymbol = new SymbolLocalVar(VarName, RetType); localVarSymbol.LoacalVarIndex = this.ExpContext.ProcContext.CreateLocalVarIndex(VarName); this.ProcContext.Symbols.Add(localVarSymbol); VarSymbol = localVarSymbol; WordInfo word = new WordInfo(VarName, WordKind.VarName, this); this.ExpContext.ProcContext.ProcVarWordDictionary.Add(word); return(this); }
/// <summary> /// This method is used to handle instructions targeted at the assembler itself. /// </summary> static bool HandleAssemblyInstruction(string opField, string addressField, SymbolBase symbol, ParsingStatus status) { IValue expression; status.LineSection = LineSection.AddressField; switch (opField) { case "EQU": // set value of the instruction symbol (first field) to the value of the expression that is in the address field if (symbol != null) { expression = WValue.ParseValue(addressField, 0, status); if (!expression.IsValueDefined(status.LocationCounter)) { status.ReportParsingError(0, addressField.Length, "expression value is undefined"); return(true); } symbol.SetValue(expression.GetSign(status.LocationCounter), expression.GetMagnitude(status.LocationCounter)); } return(true); case "ORIG": // set the location counter to the value of the expression that is in the address field expression = WValue.ParseValue(addressField, 0, status); if (!expression.IsValueDefined(status.LocationCounter)) { status.ReportParsingError(0, addressField.Length, "expression value is undefined"); return(true); } status.LocationCounter = (int)expression.GetValue(status.LocationCounter); return(true); case "CON": case "ALF": // these instructions set the value of the memory word at the location counter, which is actually a loader instruction. // However, during assembly these memory words must be skipped, which is why we increase the location counter. status.LocationCounter++; return(true); } return(false); }
public override Exp Analy( ) { var symbols = this.ProcContext.Symbols; VarSymbol = symbols.Get(VarName); if (VarSymbol == null) { ErrorE(this.Postion, "'{0}'不存在", VarName); } else { RetType = VarSymbol.SymbolZType; } return(this); }
void MSetButton_Click(object sender, EventArgs e) { if (mSymbols == null) { mSymbols = new SymbolCollection(); } string symbolName = mSymbolNameTextBox.Text; long symbolMagnitude = mSymbolValueTextBox.Magnitude; Word.Signs symbolSign = mSymbolValueTextBox.Sign; SymbolBase symbol = mSymbols[symbolName]; ValueSymbol valueSymbol = null; if (symbol != null) { valueSymbol = symbol as ValueSymbol; if (valueSymbol == null) { return; } valueSymbol.SetValue(symbolSign, symbolMagnitude); var valueText = symbolMagnitude.ToString(); if (symbolSign.IsNegative()) { valueText = '-' + valueText; } mListView.Items[symbolName].SubItems[valueFieldIndex].Text = valueText; } else { valueSymbol = ValueSymbol.ParseDefinition(symbolName) as ValueSymbol; if (valueSymbol == null) { return; } valueSymbol.SetValue(symbolSign, symbolMagnitude); mSymbols.Add(valueSymbol); ShowSymbol(valueSymbol); } SetEnabledStates(); }
void ShowSymbol(SymbolBase symbol) { if (symbol is ValueSymbol valueSymbol) { var valueText = valueSymbol.Magnitude.ToString(); if (valueSymbol.Sign.IsNegative()) { valueText = '-' + valueText; } var viewItem = new ListViewItem(new string[] { valueSymbol.Name, valueText }) { Name = valueSymbol.Name }; mListView.Items.Add(viewItem); } }
private string OptimizeContent(SymbolBase <HtmlSymbolType> sym, HtmlSymbolType previousType) { Debug.Assert(sym != null); string content; if (sym.Type == HtmlSymbolType.WhiteSpace && previousType == HtmlSymbolType.NewLine) { // Si le symbole n'est constitué que d'espace blancs et le symbole // précédent est un retour à la ligne, on peut vider son contenu. content = String.Empty; } else { content = BustWhiteSpaces(sym.Content); } return(content); }
public void RegisterAction(Matcher matcher) { SymbolBase outcome = matcher.Outcome; AmbiguousSymbol ambiguous; Symbol deterministic; if (outcome == null) { actionToTokenProducer[matcher.Index] = new TokenProducerInfo { MainTokenId = -1, Disambiguation = matcher.Disambiguation, RealActions = SparseIntSetType.Instance.Of(matcher.Index), PossibleTokens = tokenSetType.Empty }; } else if ((ambiguous = outcome as AmbiguousSymbol) != null) { actionToTokenProducer[matcher.Index] = new TokenProducerInfo { MainTokenId = ambiguous.MainToken, Disambiguation = matcher.Disambiguation, RealActions = SparseIntSetType.Instance.Of(matcher.Index), PossibleTokens = tokenSetType.Of(ambiguous.Tokens) }; } else if ((deterministic = outcome as Symbol) != null) { actionToTokenProducer[matcher.Index] = new TokenProducerInfo { MainTokenId = deterministic.Index, Disambiguation = matcher.Disambiguation, RealActions = SparseIntSetType.Instance.Of(matcher.Index), PossibleTokens = tokenSetType.Of(deterministic.Index) }; } }
public override void Emit() { lambdaExp.Emit(); LocalBuilder lanmbdaLocalBuilder = IL.DeclareLocal(lambdaExp.NestedClassContext.EmitContext.ClassBuilder); IL.Emit(OpCodes.Newobj, lambdaExp.NewBuilder); EmitHelper.StormVar(IL, lanmbdaLocalBuilder); int i = 0; if (this.ExpContext.ClassContext.IsStaticClass == false) { SymbolDefField fieldSymbol = lambdaExp.FieldSymbols[0]; EmitHelper.LoadVar(IL, lanmbdaLocalBuilder); EmitHelper.EmitThis(IL, false); IL.Emit(OpCodes.Stfld, fieldSymbol.Field); i++; } for (; i < this.BodySymbolVars.Count; i++) { SymbolBase thisSymbol = this.BodySymbolVars[i]; SymbolDefField fieldSymbol = lambdaExp.FieldSymbols[i]; EmitHelper.LoadVar(IL, lanmbdaLocalBuilder); //SymbolInfo inMethodSymbol = symbols.Get(field); //EmitHelper.EmitSymbolGet(IL, thisSymbol); if (EmitSymbolHelper.NeedCallThis(thisSymbol)) { EmitHelper.Emit_LoadThis(IL); } EmitSymbolHelper.EmitLoad(IL, thisSymbol); IL.Emit(OpCodes.Stfld, fieldSymbol.Field); } EmitHelper.LoadVar(IL, lanmbdaLocalBuilder); IL.Emit(OpCodes.Ldftn, lambdaExp.ProcBuilder);//.EmitContext.CurrentMethodBuilder); ConstructorInfo[] constructorInfos = lambdaExp.FnRetType.SharpType.GetConstructors(); IL.Emit(OpCodes.Newobj, constructorInfos[0]); base.EmitConv(); }
private string SymbolToHtml(SymbolBase symbol) { var result = HttpUtility.HtmlEncode(symbol.Name); result = result.Replace("{", "{"); result = result.Replace("}", "}"); return result; }
public TokenTypeValue F() { TokenTypeValue tokenFound = new TokenTypeValue(DataTypeDefinition.TYPE_VOID, null); switch (scanner.CurrentToken.TokenTypeDefinition) { case TokenTypeDefinition.TK_ID: { SymbolBase searchedSymVar = SymbolTable.FirstOrDefault(p => p.Name == scanner.CurrentToken.Value); if (searchedSymVar != null) { //get the type of variable if (searchedSymVar.GetType() == typeof(SymbolVariable)) { SymbolVariable symVar = (SymbolVariable)searchedSymVar; tokenFound = new TokenTypeValue(symVar.DataTypeDefinition, symVar.Address); tokenFound.isAddress = true; switch (symVar.DataTypeDefinition) { case DataTypeDefinition.TYPE_BOOL: case DataTypeDefinition.TYPE_CHAR: { GenerateOperation(OperationTypeDefinition.op_fetch); //does a push of the value onto the stack gen4(symVar.Address); break; } case DataTypeDefinition.TYPE_INT: { GenerateOperation(OperationTypeDefinition.op_fetchi); gen4(symVar.Address); break; } case DataTypeDefinition.TYPE_FLOAT: { GenerateOperation(OperationTypeDefinition.op_fetchf); gen4(symVar.Address); break; } } } else if (searchedSymVar.GetType() == typeof(SymbolProcedure)) { //store where to return to in the stack before the parameters GenerateOperation(OperationTypeDefinition.op_pushi); int hole = ip; gen4(0); int count = 0; SymbolProcedure symVar = (SymbolProcedure)searchedSymVar; scanner.Match(TokenTypeDefinition.TK_ID); scanner.Match(TokenTypeDefinition.TK_LBRACE); while (scanner.CurrentToken.TokenTypeDefinition != TokenTypeDefinition.TK_RBRACE && scanner.ErrorLog.Count == 0) { count++; switch (scanner.CurrentToken.TokenTypeDefinition) { case TokenTypeDefinition.TK_BOOLLIT: case TokenTypeDefinition.TK_CHARLIT: { GenerateOperation(OperationTypeDefinition.op_push); //does a push of the value onto the stack gen1(scanner.CurrentToken.Value[0]); break; } case TokenTypeDefinition.TK_INTLIT: { GenerateOperation(OperationTypeDefinition.op_pushi); gen4(Convert.ToInt32(scanner.CurrentToken.Value)); break; } case TokenTypeDefinition.TK_REALLIT: { GenerateOperation(OperationTypeDefinition.op_pushf); gen8(Convert.ToSingle(scanner.CurrentToken.Value)); break; } } scanner.Match(scanner.CurrentToken.TokenTypeDefinition); if (scanner.CurrentToken.TokenTypeDefinition == TokenTypeDefinition.TK_COMMA) { scanner.Match(scanner.CurrentToken.TokenTypeDefinition); } } gen_Address(ip, hole); //push where to return to the bottom of the parameters scanner.Match(TokenTypeDefinition.TK_SEMI); if (count != symVar.Arguments.Count) { scanner.LogErrorToken(new Token(TokenCategory.Literal, TokenTypeDefinition.TK_INVALID_NUMBER_OF_ARGUMENTS, "")); } } } break; } case TokenTypeDefinition.TK_INTLIT: { GenerateOperation(OperationTypeDefinition.op_pushi); gen4(Convert.ToInt32(scanner.CurrentToken.Value)); tokenFound = new TokenTypeValue(DataTypeDefinition.TYPE_INT, Convert.ToInt32(scanner.CurrentToken.Value)); break; } case TokenTypeDefinition.TK_REALLIT: { GenerateOperation(OperationTypeDefinition.op_pushf); gen8(Convert.ToInt32(scanner.CurrentToken.Value)); tokenFound = new TokenTypeValue(DataTypeDefinition.TYPE_FLOAT, Convert.ToSingle(scanner.CurrentToken.Value)); break; } case TokenTypeDefinition.TK_BOOLLIT: { GenerateOperation(OperationTypeDefinition.op_push); gen1(Convert.ToBoolean(scanner.CurrentToken.Value) ? '1' : '0'); tokenFound = new TokenTypeValue(DataTypeDefinition.TYPE_BOOL, Convert.ToBoolean(scanner.CurrentToken.Value)); break; } case TokenTypeDefinition.TK_CHARLIT: { GenerateOperation(OperationTypeDefinition.op_push); gen1(scanner.CurrentToken.Value[0]); tokenFound = new TokenTypeValue(DataTypeDefinition.TYPE_CHAR, scanner.CurrentToken.Value); break; } } scanner.Advance(); return(tokenFound); }
private static Grammar BuildGrammar(CilGrammar definition) { var result = new Grammar(); InitContextProvider( result, definition.GlobalContextProvider, result.GlobalContextProvider); var symbolResolver = definition.SymbolResolver; // Define grammar tokens foreach (var cilSymbol in symbolResolver.Definitions) { Symbol symbol; if (cilSymbol.Type == typeof(Exception)) { cilSymbol.Symbol = symbol = (Symbol)result.Symbols[PredefinedTokens.Error]; symbol.Joint.Add( new CilSymbol { Type = typeof(Exception), Symbol = symbol, Categories = SymbolCategory.DoNotDelete | SymbolCategory.DoNotInsert }); } else { symbol = new Symbol(cilSymbol.Name) { Categories = cilSymbol.Categories, Joint = { cilSymbol } }; result.Symbols.Add(symbol); cilSymbol.Symbol = symbol; } } foreach (CilSymbolFeature <Precedence> feature in definition.Precedence) { var symbol = symbolResolver.GetSymbol(feature.SymbolRef); symbol.Precedence = feature.Value; } foreach (CilSymbolFeature <CilContextProvider> feature in definition.LocalContextProviders) { var symbol = symbolResolver.GetSymbol(feature.SymbolRef); if (symbol != null) { InitContextProvider(result, feature.Value, symbol.LocalContextProvider); } } result.Start = symbolResolver.GetSymbol(definition.Start); // Define grammar rules foreach (var cilProduction in definition.Productions) { Symbol outcome = symbolResolver.GetSymbol(cilProduction.Outcome); var pattern = Array.ConvertAll(cilProduction.Pattern, symbolResolver.GetSymbol); // Try to find existing rules whith same token-signature Production production; if (result.Productions.FindOrAdd(outcome, pattern, out production)) { ForeignContextRef contextRef = CreateActionContextRef(cilProduction.Context); production.Actions.Add(new ForeignAction(pattern.Length, contextRef)); } var action = production.Actions[0]; action.Joint.Add(cilProduction); production.ExplicitPrecedence = cilProduction.Precedence; } // Create conditions to allow referencing them from matchers foreach (CilCondition cilCondition in definition.Conditions) { var cond = CreateCondtion(result, cilCondition); result.Conditions.Add(cond); } // Create matchers foreach (CilCondition cilCondition in definition.Conditions) { var condition = ConditionFromType(result, cilCondition.ConditionType); foreach (var cilMatcher in cilCondition.Matchers) { SymbolBase outcome = GetMatcherOutcomeSymbol(result, symbolResolver, cilMatcher.MainOutcome, cilMatcher.AllOutcomes); var matcher = new Matcher( cilMatcher.Pattern, outcome, #if false context: CreateActionContextRef(cilMatcher.Context), #endif nextCondition: ConditionFromType(result, cilMatcher.NextConditionType), disambiguation: cilMatcher.Disambiguation); matcher.Joint.Add(cilMatcher); condition.Matchers.Add(matcher); } } foreach (var cilMerger in definition.Mergers) { var symbol = symbolResolver.GetSymbol(cilMerger.Symbol); var merger = new Merger(symbol) { Joint = { cilMerger } }; result.Mergers.Add(merger); } foreach (var report in definition.Reports) { result.Reports.Add(report); } return(result); }
private static string Name(SymbolBase symbol) { return symbol == null ? "$skip" : symbol.Name; }