From 76d7c2bc62932af69c8c8ae05169f3daea67f821 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Wed, 9 Oct 2019 13:52:42 -0700 Subject: [PATCH] added more VCD grammar rules --- bin/build.js | 58 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/bin/build.js b/bin/build.js index 8099184..628c5bd 100755 --- a/bin/build.js +++ b/bin/build.js @@ -9,20 +9,58 @@ const prj = 'vcd_parser'; const p = new llparse.LLParse(prj); -const start = p.node('start'); -const stop = p.node('stop'); +const declaration = p.node('declaration'); +const inDeclaration = p.node('inDeclaration'); +const enddefinitions = p.node('inDeclarationEnd'); +const simulation = p.node('simulation'); +const inSimulation = p.node('inSimulation'); -start - .match('stop', stop) - .otherwise(p.error(1, 'Expected start')); +// Add custom uint8_t property to the state +p.property('i8', 'declaration'); +p.property('i8', 'simulation'); -stop - .match('start', start) - .otherwise(p.error(2, 'Expected start')); +// Store method inside a custom property +const onDeclaration = p.invoke(p.code.store('declaration'), inDeclaration); +const onSimulation = p.invoke(p.code.store('simulation'), inSimulation); + +declaration + .select({ + '$comment': 0, + '$date': 1, + '$scope': 2, + '$timescale': 3, + '$upscope': 4, + '$var': 5, + '$version': 6 + }, onDeclaration) + .match('$enddefinitions', enddefinitions) + .otherwise(p.error(1, 'Expected declaration')); + +inDeclaration + .match('$end', declaration) + .otherwise(p.error(2, 'Expected end of declaration')); + +enddefinitions + .match('$end', simulation) + .otherwise(p.error(3, 'Expected end of all declaration')); + +simulation + .select({ + '$dumpall': 0, + '$dumpoff': 1, + '$dumpon': 2, + '$dumpvars': 3, + '$comment': 4 + }, onSimulation) + .otherwise(p.error(4, 'Expected simulation command')); + +inSimulation + .match('$end', simulation) + .otherwise(p.error(5, 'Expected end simulation command')); // Build -const artifacts = p.build(start); +const artifacts = p.build(declaration); fs.writeFileSync(prj + '.h', artifacts.header); // fs.writeFileSync('verilog_preprocessor.bc', artifacts.bitcode); @@ -30,6 +68,6 @@ fs.writeFileSync(prj + '.c', artifacts.c); const dot = new llparseDot.Dot(); -fs.writeFileSync(prj + '.dot', dot.build(start)); +fs.writeFileSync(prj + '.dot', dot.build(declaration)); /* eslint camelcase: 0 */