void AddToLabelList(Symbol s) { if (codegen.CurrentSection == SectionType.InitializedData) { labelList_ID.Add(s); } else if (codegen.CurrentSection == SectionType.UninitializedData) { labelList_UD.Add(s); } }
int GetTerm(out Symbol x) { Token op; int n; Symbol y; n = GetFactor(out x); while (sym == Token.Times || sym == Token.Slash || sym == Token.And) { op = sym; scanner.Get(out sym); if (op == Token.Times) { n *= GetFactor(out y); } else if (op == Token.Slash) { n /= GetFactor(out y); } else { n &= GetFactor(out y); } if (x != null || y != null) scanner.Mark(ErrorType.InvalidOperationForRelocatableSymbol); } return n; }
int GetFactor(out Symbol x) { int n; uint w; Symbol y; string id; x = null; if (sym == Token.Not) { scanner.Get(out sym); n = ~GetFactor(out x); } else if (sym == Token.Number) { unchecked { n = (int)scanner.Number; } scanner.Get(out sym); } else if (sym == Token.Ident) { id = scanner.Name.ToUpper(); if (id == "LO" || id == "HI") { scanner.Get(out sym); if (sym != Token.Lparen) { scanner.Mark(ErrorType.LeftParenExpected); n = 0; } scanner.Get(out sym); w = (uint)GetExpression(out y); if (sym != Token.Rparen) scanner.Mark(ErrorType.RightParenExpected); else scanner.Get(out sym); if (y != null) scanner.Mark(ErrorType.InvalidOperationForRelocatableSymbol); if (id == "HI") n = (int)CodeGen.GetHighPart(w); else n = (int)CodeGen.GetLowPart(w); } else { y = symtab.Find(scanner.Name); if (y == null) { scanner.Mark(ErrorType.UndefinedIdentifier); n = 0; } else { if ((y.type == SymbolType.Label || y.type == SymbolType.Import)) { x = y; } scanner.Get(out sym); n = (int)y.val; } } } else if (sym == Token.Lparen) { scanner.Get(out sym); n = GetExpression(out y); if (sym != Token.Rparen) scanner.Mark(ErrorType.RightParenExpected); else scanner.Get(out sym); } else { scanner.Mark(ErrorType.IllegalExpression); n = 0; } return n; }
int GetExpression(out Symbol x) { bool neg; Token op; int n; Symbol y; neg = false; if (sym == Token.Plus) scanner.Get(out sym); else if (sym == Token.Minus) { neg = true; scanner.Get(out sym); } n = GetTerm(out x); if (neg) { n = -n; if (x != null) scanner.Mark(ErrorType.InvalidOperationForRelocatableSymbol); } while (sym == Token.Plus || sym == Token.Minus || sym == Token.Or) { op = sym; scanner.Get(out sym); if (op == Token.Plus) { n += GetTerm(out y); if (x == null) x = y; else if (y != null) scanner.Mark(ErrorType.InvalidOperationBetweenRelocatableSymbols); } else if (op == Token.Minus) { n -= GetTerm(out y); if (y != null) { if (x == null) scanner.Mark(ErrorType.InvalidOperationForRelocatableSymbol); else if (x.type == SymbolType.Import || y.type == SymbolType.Import) scanner.Mark(ErrorType.InvalidOperationBetweenRelocatableSymbols); else x = null; } } else { n |= GetTerm(out y); if (x != null || y != null) scanner.Mark(ErrorType.InvalidOperationForRelocatableSymbol); } } return n; }
public Symbol InsertLabel(string name, uint val, SectionType st) { Symbol s; if (tab.ContainsKey(name)) { s = tab[name]; if (s.type == SymbolType.Pending) { s.type = SymbolType.Label; s.sectType = st; s.val = val; } else { s = null; scanner.Mark(ErrorType.DuplicatedDefinition); } } else { s = new Symbol(SymbolType.Label, name, val, st); tab.Add(name, s); } return s; }
public void InsertImport(string name) { Symbol s; if (tab.ContainsKey(name)) { scanner.Mark(ErrorType.DuplicatedDefinition); } else { s = new Symbol(SymbolType.Import, name, 0, SectionType.Null); tab.Add(name, s); } }