public Node Proc() { var result = new ProcDeclaration() { AnchorToken = Expect(TokenCategory.PROC) }; result.Add(new Identifier() { AnchorToken = Expect(TokenCategory.IDENTIFIER) }); Expect(TokenCategory.PARENTHESIS_OPEN); var param = new ProcParam(); while (CurrentToken == TokenCategory.IDENTIFIER) { param.Add(ParamDeclaration()); } Expect(TokenCategory.PARENTHESIS_CLOSE); result.Add(param); var type = new ProcType(); if (CurrentToken == TokenCategory.TWOPOINTS) { Expect(TokenCategory.TWOPOINTS); type.Add(ChimeraType()); } result.Add(type); var con = new ProcConst(); Expect(TokenCategory.SEMICOL); if (CurrentToken == TokenCategory.CONST) { con.Add(Const()); } result.Add(con); var va = new ProcVar(); if (CurrentToken == TokenCategory.VAR) { va.Add(Var()); } result.Add(va); var procStatement = new ProcStatement() { AnchorToken = Expect(TokenCategory.BEGIN) }; while (firstOfStatement.Contains(CurrentToken)) { procStatement.Add(Statement()); } Expect(TokenCategory.END); Expect(TokenCategory.SEMICOL); result.Add(procStatement); return(result); }
public override object VisitAsmline(Z80AsmParser.AsmlineContext context) { CurrentLabel = null; CurrentLabelColon = false; CurrentComment = null; LabelSpan = null; KeywordSpan = null; CommentSpan = null; IssueToEmit = null; IsFieldAssignment = false; NumberSpans = null; IdentifierSpans = null; StringSpans = null; FunctionSpans = null; SemiVarSpans = null; MacroParamSpans = null; MacroParamNames = null; SemiVarSpans = null; StatementSpans = null; OperandSpans = null; MnemonicSpans = null; if (context?.Start == null || context.Stop == null) { return(null); } var startIndex = context.start.StartIndex; var stopIndex = context.stop.StopIndex; CurrentSourceText = InputStream.GetText(new Interval(startIndex, stopIndex)); CurrentSourceLine = context.Start.Line; FirstColumn = context.Start.Column; FirstPosition = context.Start.StartIndex; LastPosition = context.Stop.StopIndex; object mainInstructionPart = null; // --- Obtain label var labelCtx = context.label(); if (labelCtx != null) { CurrentLabel = labelCtx.GetChild(0).NormalizeToken(); CurrentLabelColon = labelCtx.COLON() != null; LabelSpan = new TextSpan(labelCtx.Start.StartIndex, labelCtx.Start.StopIndex + 1); } // --- Obtain line body/directive var lineBodyCtx = context.lineBody(); if (lineBodyCtx != null) { // --- Special case, when a macro parameters is used as the main line LastInstructionPos = lineBodyCtx.Stop.StopIndex; var macroParamCtx = lineBodyCtx.macroParam(); if (macroParamCtx != null) { VisitMacroParam(macroParamCtx); mainInstructionPart = new MacroParamLine(macroParamCtx.IDENTIFIER()?.NormalizeToken()); } else { mainInstructionPart = VisitLineBody(context.lineBody()); } } else if (context.directive() != null) { mainInstructionPart = VisitDirective(context.directive()); } // --- Obtain comment if (context.comment() != null) { var commentCtx = context.comment(); CurrentComment = commentCtx.GetText(); CommentSpan = new TextSpan(commentCtx.Start.StartIndex, commentCtx.Stop.StopIndex + 1); } // --- Now, we have every part of the line, and create some special main instruction part if (context.exception != null) { mainInstructionPart = new ParserErrorLine(); } else if (mainInstructionPart == null && (CurrentLabel != null || CurrentComment != null)) { mainInstructionPart = new NoInstructionLine(); if (CurrentLabel != null && !CurrentLabelColon) { var statementFound = true; switch (CurrentLabel.ToLower()) { case "continue": mainInstructionPart = new ContinueStatement(); break; case "break": mainInstructionPart = new BreakStatement(); break; case "endm": case "mend": mainInstructionPart = new MacroEndStatement(); break; case "endl": case "lend": mainInstructionPart = new LoopEndStatement(); break; case "proc": mainInstructionPart = new ProcStatement(); break; case "endp": case "pend": mainInstructionPart = new ProcEndStatement(); break; case "repeat": mainInstructionPart = new RepeatStatement(); break; case "endw": case "wend": mainInstructionPart = new WhileEndStatement(); break; case "ends": mainInstructionPart = new StructEndStatement(); break; case "else": mainInstructionPart = new ElseStatement(); break; case "endif": mainInstructionPart = new IfEndStatement(); break; default: statementFound = false; break; } if (statementFound) { KeywordSpan = new TextSpan(context.Start.StartIndex, context.Start.StopIndex + 1); CurrentLabel = null; } } } return(mainInstructionPart is SourceLineBase sourceLine ? AddLine(sourceLine, context) : mainInstructionPart); }
public Type Visit(ProcStatement node) { VisitChildren(node); return(Type.VOID); }
public string Visit(ProcStatement node) { return(VisitChildren(node)); }