Make ANTLR parser run simulations end-to-end - #113
Merged
Conversation
The ANTLR parser (antlr/nec_parse) already dispatched all 21 program cards into the necpp engine, and RP/XQ already called simulate(). Five bugs stopped those simulations from running correctly and visibly: 1. Lifecycle (nec_visitor.h): calc_prepare() was called *after* the visitor walk, but RP/XQ trigger simulate() *during* the walk, and simulate() indexes current_vector which calc_prepare() allocates. Moved calc_prepare() into visitGeCard, mirroring the geometry-only visitor and the production driver's order. 2. Field mapping (nec_visitor.h): dispatch_labeled's comment claimed ANTLR removes labelled tokens from ctx->INT() -- false; getTokens() returns all tokens including labels. The mode integer (EX/GN/LD/NT/ RP type) was consumed twice, shifting tag/seg and corrupting every labelled card. Skip N leading tokens of rest_ints equal to the label count. 3. Grammar (NECFull.g4): EX type-0/5 voltage-source branch mandated both real and imaginary voltage, rejecting valid minimal inputs like 'EX 0 0 4 0 1.' where trailing blanks default to 0 in NEC-2. Made the imaginary voltage optional (fnum fnum -> fnum fnum?). 4. Output sink (nec_test.cpp): nec_output_file was never connected, so set_output cached a null FILE* and all simulation output was silently dropped. Added s_output.set_file(stdout) -- uses FILE* not a stream because nec_printf/integer/real_out short-circuit on null m_output_fp. 5. Results emission (nec_test.cpp): added context.write_results() after the walk so computed radiation patterns / impedances / near fields are emitted (nec_results::write clears each flag, so one call is idempotent). Removed the now-redundant post-walk calc_prepare(). Also: build_in_docker.sh now generates ../build/simple/config.h (NECPP_VERSION/NECPP_BUILD_DATE) so the antlr build does not depend on a prior top-level make. Added an end-to-end simulation smoke test (FR/EX/RP/EN) to antlr/Makefile asserting radiation-pattern and power-budget tables are present. Verified: example1.nec simulates and its near-E field values match the production nec2++ output numerically.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The ANTLR parser (
antlr/nec_parse) already dispatched all 21 program cards into the necpp engine, andRP/XQalready calledsimulate(). Five bugs stopped those simulations from running correctly and visibly. This PR fixes them so the parser actually performs simulations and emits their results.Changes
antlr/nec_visitor.hnec->calc_prepare()invisitGeCardsimulate()indexes (current_vector) were sized after the walk, butRP/XQfiresimulate()during it. Mirrors the geometry-only visitor and production driver order.antlr/nec_visitor.hdispatch_labeledto skip N leading tokens ofrest_intsctx->INT()— false;getTokens()returns all tokens including labels. The mode integer (EX/GN/LD/NT/RP type) was consumed twice, shifting tag/seg and corrupting every labelled card.antlr/NECFull.g4fnum fnum→fnum fnum?)EX 0 0 4 0 1.(trailing blanks default to 0 in NEC-2).antlr/nec_test.cpps_output.set_file(stdout)beforeset_outputset_outputcached a nullFILE*and all simulation output was silently discarded. Usesset_file(notset_stream) becausenec_printf/integer/real_outshort-circuit on nullm_output_fp.antlr/nec_test.cppcalc_prepare(); addedcontext.write_results(std::cout)calc_preparenow runs invisitGeCard;write_resultsemits the structured result tables (radiation patterns, impedances, near fields) accumulated byRP/XQ/NE.antlr/Makefiletest:only checked parsing/geometry, never a real simulation.antlr/build_in_docker.sh../build/simple/config.h(NECPP_VERSION/NECPP_BUILD_DATE)make.No changes to
src/— the engine and the sharednec_card_parser.hdispatch table were already the correct integration surface.Verification
example1.nec(EX + XQ + NE) simulates; near-E field values match productionnec2++numerically (e.g.INPUT POWER = 4.4773E-03 Watts, near-E field5.5442E+01 -66.31at0.0179 m).make testpasses: geometry, all card types, and the new simulating case (6249 bytes output, both tables present).CHECK DATAerror — confirmed it isNT 0 1 0 0 …with a placeholder second-port segment of 0, which productionnec2++rejects identically (invalid input data, not a parser defect). That test tolerates it via|| true.Out of scope
CLI flags (
-i/-o/-s),NXmulti-job looping,PLfilename handling, fullnec2++drop-in parity.